Web workers in 3D web applications

In my game engine I currently employ workers for 2 main purposes:

  1. building terrain geometry and metadata, terrain is split into chunks, you send a heightmap along with some metadata to a worker and it sends you back tile geometry and spatial idnex for said geometry.
  2. Compression. Game save data used to be quite large, so I added a compressor, it runs in a worker thread. Not much to say, compression can take a while.

Beyond that I wrote a custom threading engine in JS, most of my long-running tasks are executed using that engine. It implements dependency graphs and is basically a stripped down version of time-sharing scheduler that you’d find in an OS. Main reason I wrote that thing is the sheer convenience of being able to pass data around without having to implement additional communication interfaces. I am very satisfied with it and pretty much everything that takes more than a couple of milliseconds runs on that engine. To make a few things:

  • level loading
  • AI solvers
  • enemy group generator

I also have a WebWorker interface on top of Ammo.js in my engine, but it’s disabled for this game, as physics is not used in this title.

In my experience it only makes sense to put into a worker things which require relatively little communication compared to amount of computation they do. #CaptainObvious :policewoman:

6 Likes