Explosion by Musk
- E X P L O S I O N - by musk at Function 2022 - T E C H N I Q U E - It's a 3D particle system simulation. Each particle eats 32 bytes of RAM. I've hardcoded 400 particles. No FPU is used, it's all integer math using 16 signed integers. No buffering, pixels are drawn and cleared directly to the screen. There are 4 simulation ticks per frame and each pixel drawn persists for 2 frames. This creates an ultra smooth motion blur effect. I tried adding sound but I couln't make it sound good, as good so it does not distract from the visuals. So I decided to not have sound. The color intensity is actually a 4th dimension which is simulated the same way as the XYZ coordiantes. - O P T I M I Z A T I O N - I got a solid simulation with 192 bytes I used the rest of the space to add color and variation. I passed the 256 byte limit a few times but I managed to optimize it back under 256 byte. There is a single loop that handles both updates and initialization for each particle. The update loop is so large that it uses less space to call it as a function instead of inlining because the main loop is transformed into a short jump. Because of subframes I have multiple jumps that go back. The biggest optimization I did is to treat each coordinate axis uniformly this allows to do the whole simulation on all axes with the same code. Further optimization is still possible with a memory reogranization and by applying more hacks. I didn't apply any advanced size optimization hacks. - C O D E - For this one I decided to lean more heavily onto nasm macros. My initial goal was to have the assembly code a bit more readable and maybe I end up with a few reusable components. But the most useful thing was that it allowed me to easily reorganize the code. In the end it was an easy process to inline most function calls. The source code should be in the release, maybe someone can learn something from it.
[ back to the prod ]