frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: The Simpsons Hit and Run Running in the Browser (WASM/WebGL)

https://shar-wasm.cjoseph.workers.dev/?skipmovie
4•calebj0seph•1h ago

Comments

calebj0seph•1h ago
Back in 2021, the source code for The Simpsons Hit & Run leaked online. As someone who does a lot of WebGL for work, my first thought seeing the leak was "it'd be cool to get this running in a browser". So that's exactly what I did (for fun and science).

I did a full port of PC version of the game to WASM and WebGL. It runs at native resolution, fetches game data on-demand over the network, and comes with extra features from the Xbox version like lens flares, widescreen support, and the refraction effect on Frink's hover car.

Haven't done a full write-up on the process yet, but I'd say the hardest parts in order were:

1. Audio

The game models sound as many individual tracks with properties like gain and pan, and either a static or streaming buffer containing the raw audio samples. It expects a synchronous-style audio API from the host, e.g. if it tells a sound to play, then it expects to be able to immediately query the state of the track to see that it is playing and how many audio samples have elapsed.

In order to accurately match the mixing logic of the game, we need full control over the audio samples being played and for this to be done with low-latency. The Web Audio API gives you AudioWorklets to achieve this. They are called very frequently (a few hundred times per second) to deliver the next batch of samples. This means they need to return very quickly to avoid stalling the audio stream. They are also run on a separate thread, so it's up to you to figure out how to provide them with the data they need.

So I had to build a small set of lock-free shared memory structures (locks would be able to stall the audio) to transfer the constantly updating track descriptors (e.g. gain, pan) and their PCM data to the worklet. For example, for the track descriptors I used a double buffer in shared memory with an atomic flag to indicate which buffer is 'live'. When the main thread needs to write, it writes to the non-live side and flips the flag. When the worklet reads, it reads the flag and the data, then reads the flag again to make sure it didn't change in the middle of reading.

This was coupled with a bunch of state management needed so the game would see the current state of each track even if the worklet hadn't picked the changes up yet. Overall, audio was quite fiddly and hard to debug!

2. File I/O

The game has a lot of small assets read as whole files (e.g. 3D models, scripts), but also larger archives which it reads small slices from (e.g. sound). The former is easy to do with a simple fetch, but the latter would require either loading the whole ~500 MB file or using a Range header which doesn't cache very well. I also needed to serve all the assets somewhere where they'll load fast and not cost me a fortune in bandwidth.

I ended up going with Cloudflare R2 for its free egress, and wrote a Cloudflare worker in front to provide an interface to fetch assets in 1MB chunks thus avoiding the use of a Range header. This provides the ability to load assets on-demand with full caching.

Safari was also a huge pain here. The game does some blocking I/O for things like save data. I originally implemented this by performing the IndexedDB operations n a worker thread, with a short spin lock on the main thread (since Atomics.wait() can't be used on the main thread). This works in Chrome and Firefox but causes a deadlock in Safari - I assume because it proxies the actual work to the main thread. So I had to rework all of the places where the game touches save and config data to poll every frame for completion which was a pain.

3. Graphics

The game is built around a DirectX 8-era fixed-function rendering pipeline, so emulating it with 'modern' WebGL 2 wasn't too difficult. I built a single uber shader that takes all the fixed-function inputs like bone weights, a fixed light array, flat shading toggle, etc. Modern GPUs handle branching pretty well when all shader units take the same path, so this kept the rendering simple without needing to manage dozens of shader permutations.

The main performance issue I ran into was CPU overhead from the number of WebGL calls I was making per frame. This was mostly solved by keeping track of the last set WebGL state to avoid making redundant calls (e.g. rendering particle effects might call gl.disable(GL_DEPTH_TEST) several times) and writing all the shader uniforms with a uniform buffer instead of thousands of gl.uniform*() calls per frame.

Lens flares were interesting to port from the Xbox version as they use occlusion queries which allow you to check if any pixels from a mesh are visible on the screen. The game assumed occlusion queries would be available to read on the next frame, but it can actually take longer, so I had to rework that. The refraction effect for the hover car was also fun to wire up, since it's the only thing in the game which requires access to the framebuffer as a texture.

Oh and for FMVs, I just converted them to H264 MP4s and play them with a HTML <video> overlay. Nice and simple.

Have fun! It should run well on most hardware. Runs great on my Pixel 10 as an example (but a physical keyboard is needed). Firefox on macOS is quite stuttery - if there's a Mozilla engineer here I'd love for you to tell me why!

Show HN: Experimental app for remixing and sharing Wikipedia content

https://testflight.apple.com/join/TcuN9rry
1•brokensegue•44s ago•0 comments

Pay Transparency in the EU (2026)

https://www.consilium.europa.eu/en/policies/pay-transparency/
1•andrewstetsenko•1m ago•0 comments

You can now suggest RSS feeds on Rawfeed.social

https://rawfeed.social/blog/rss-feed-suggestions
1•iozguradem•1m ago•0 comments

Claude Code can now do your job overnight

https://thenewstack.io/claude-code-can-now-do-your-job-overnight/
1•Brajeshwar•6m ago•0 comments

How to notify users about privacy policy changes without spamming everyone

https://www.openpolicy.sh/blog/building-update-flows
1•jamie_davenport•6m ago•0 comments

Ask HN: Are your product managers sending PRs?

1•subw00f•9m ago•0 comments

Reverse-enginnering a bluethoot termal printer (2021)

https://werwolv.net/posts/cat_printer/
1•Muhammad523•12m ago•0 comments

Show HN: Unseal.link – Paste a URL, set a price, let buyers unseal it via Stripe

https://unseal.link
1•beharefe•12m ago•1 comments

NoteSide

https://dylblake.dev/
1•dylblake03•13m ago•1 comments

PTEcorepractice – Free PTE Core Practice Platform for Canada PR Applicants

https://ptecorepractice.com
1•zzx•14m ago•0 comments

One Interface, Every Protocol

https://openbindings.com/blog/one-interface-every-protocol
2•clevengermatt•15m ago•1 comments

Sumida Aquarium Posts 2026 Penguin Relationship Chart, with Drama and Breakups

https://www.sumida-aquarium.com/special/sokanzu/en/2026/
2•Lwrless•15m ago•0 comments

LinkedIn data shows AI isn't to blame for hiring decline yet

https://techcrunch.com/2026/04/15/linkedin-data-shows-ai-isnt-to-blame-for-hiring-decline-yet/
2•caisah•16m ago•0 comments

Blueprinting the System: An Interview on Event Modeling

https://docs.eventsourcingdb.io/blog/2026/04/16/blueprinting-the-system-an-interview-on-event-mod...
2•goloroden•16m ago•0 comments

Bazooka Theory: Why Korea's birth crisis won't be solved by incremental reform

https://upwarding.substack.com/p/the-bazooka-theory-what-korea-taught
1•Ckawaja•17m ago•1 comments

Language models transmit behavioural traits through hidden signals in data

https://www.nature.com/articles/s41586-026-10319-8
4•armcat•18m ago•2 comments

The Permission System

https://www.nurbaysal.com/the-permission-system/
1•kieloo•18m ago•0 comments

Ask HN: How far will the neo-Luddites go in their attempts to stop AI progress?

1•adinhitlore•18m ago•0 comments

Stop building agents, start harnessing Goose

https://maxamillion.sh/blog/stop-building-agents-start-harnessing-goose/
2•speckx•19m ago•0 comments

The Weight of Wheat

https://www.omu.ac.jp/en/info/research-news/entry-108581.html
1•t-3•19m ago•0 comments

Adaptations enable activity at sub-freezing temperatures in the snow fly

https://www.cell.com/current-biology/fulltext/S0960-9822(26)00247-2
1•PaulHoule•22m ago•0 comments

NASA's Parker Solar Probe Finds Explosive Surprises on Sun

https://science.nasa.gov/blogs/science-news/2026/04/15/science-nasa-gov-parker-solar-probe-finds-...
2•ZunarJ5•23m ago•0 comments

Six death sentences in 35 years, and consulting keeps walking out

https://albertcmikkelsen.substack.com/p/six-eulogies-so-far-but-the-corpse
1•merqurio•23m ago•0 comments

In the last 30 years, the number of public companies has been cut in half

https://twitter.com/ToddZywicki/status/2044167534681936085
4•MrBuddyCasino•24m ago•0 comments

Ukraine captures enemy Russian position using only robots

https://nypost.com/2026/04/15/world-news/ukraine-captures-enemy-russian-position-using-only-robot...
2•noworld•24m ago•0 comments

Scientists discover "cleaner ants" that groom giant ants in Arizona desert

https://www.sciencedaily.com/releases/2026/04/260414075641.htm
1•t-3•25m ago•0 comments

Show HN: CalcPocket – simple online calculators with no clutter

https://calcpocket.com
1•calcpocket•25m ago•1 comments

PiCore - Raspberry Pi Port of Tiny Core Linux

http://tinycorelinux.net/5.x/armv6/releases/README
2•gregsadetsky•26m ago•0 comments

Show HN: AI support chatbot with RAG and citations – one back end file, no infra

https://github.com/oncellai/oncell-support-agent
8•anupsing_ai•26m ago•0 comments

Icons and Counting

https://blog.jimmac.eu/posts/app-icon-requests/
2•birdculture•26m ago•0 comments