How a voxel sandbox game works in 62k lines of x86-64 assembly - no compiler, no C runtime, no asset files
Author here. A few things I find most interesting in the code:
Lighting
Lighting is a BFS over a 5x5 window of chunks with positions packed into one dword (wx | wz<<7 | y<<14 | value<<21), so a neighbour step is a single add and crossing a chunk border is a pointer swap.
Meshing
The mesher copies the 3x3 neighbouring chunks into an 18^3 padded volume so every neighbour lookup is one movzx at a constant offset (+1, +18, +324).
ABI Checks
The ABI is checked by machine:
- sentinel values in every nonvolatile register
- plus a counter for calls made with a misaligned stack
Explosions
Explosions cast 1352 rays (the surface cells of a 16^3 grid: no trig) and dedupe hits in a hash set that is "cleared" by bumping a generation stamp.
Repo + download: https://github.com/BaramiDev/MineAssembly
Comments
No comments yet. Start the discussion.