How do demomakers attain ultra small filesizes?
assembly, c++, code-size, demoscene, filesize
Solution
I'm one of the coder of Felix's Workshop and Immersion (64k intros by Ctrl-Alt-Test). Most 64k intros nowadays use C++ (exception: Logicoma uses Rust). Assembly may make sense for 4k intros (although most of them actually use C++), but not for 64k intros.
Here are the two most important things:
- Compile without the standard library (in particular, the STL could make the binary quite large).
- Compress your binary (kkrunchy for 64k intros on Windows, Crinkler for 4k intros on Windows).
Now, you can write a ton of code before filling the 64kB. How to use them? Procedural generation.
- For music, music sheet is compressed. Instruments are generated with a soft synth. A popular option, although a bit outdated, is to use v2 by Farbrausch.
- If you need textures, generate them.
- If you need 3d models, generate them.
- Animations and effects are procedural.
- For the camera, save some key positions and interpolate.
- Shaders are heavily used in modern graphics. Minifying the shaders can save quite a lot of space.
Want to hear more about procedural generation and other techniques? Check IQ's articles.
If you want to further optimise your code, here are some additional tricks:
- You probably use lots of floats. Try to truncate the mantissa of your floats (it can save many kB).
- Disable function inlining (it saved me 2kB).
- Try the fastcall calling convention (it saved me 0.7kB).
- Disable support for exceptions. You don't need them.
- If you use classes, avoid inheritance.
- Be careful if you use templates.
In a typical 4k intro, the C++ code is used for the music and the initialisation. Graphics are done in a shader.
Problem
When I watch demoscene videos on youtube the author's often boast of how their filesizes are 64kb or less, some as few as just 4kb. When I compile even a very basic program in C++ the executable is always at least 90kb or so. Are these demos written entirely in assembly? it was my understanding that demomakers used c/c++ as well.