The engineer who created the FPS '.kkrieger' that runs on an executable file of only 96KB looks back on those days



Fabian Giesen, a member of the production group, wrote on his blog about the memories of creating an FPS game ``.kkrieger'' with a capacity of only 96 KB.

Metaprogramming for madmen |
https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for-madmen/


.theprodukkt
https://web.archive.org/web/20120204065621/http://www.theprodukkt.com/kkrieger


From 2003 to 2010, a demo scene party called Breakpoint was held, and '.kkrieger' was created as a work for the 96KB game competition in 2004.

About two weeks before the release date, the .kkrieger size was around 70KB to 80KB. However, it was still necessary to add content before completion, and Mr. Giesen and others had to perform two tasks at the same time: ``put all the content and complete the game'' and ``reduce the capacity to 96KB''. . According to Giesen, the method to keep the code small is as follows.

◆1: Architecture
You should design your code to be smaller by keeping it modular, using the right algorithms, storing data in the right way, and so on. Please note that this work takes time, so it should be completed at least two weeks before release.

◆ 2: Removal of 'weight'
Delete unused parts of your code. Of course, if you are not using a torus, you don't need the code to generate the torus. If you are only using one torus, you may be able to reduce the amount of code by replacing the code for generation with something else. If you have basic statistical information about the content, this step is very easy, and you can get a large result of about several kilobytes in a short time of less than an hour.

◆3: Detailed work
It's a cumbersome task of gathering data about all the functions in your code and finding those functions that are likely to be larger or smaller than necessary. Browsing disassembly listings to find out where and why the compiler is generating large code, or looking for shortcuts to make certain intros smaller, slowly 300-400 bytes per day. It is said that the speed has been improved.

When .kkrieger became playable, the capacity of the executable file was 120KB. It was down to 102KB when we fixed the architecture and removed the weight, but it was still far from 96KB, and there were problems such as some content was not included yet. As of a week before the release, it was 100 KB, but Mr. Giessen said that he felt that ``this will not work''.

Giessen and his colleagues tried a different approach. Within the executable, all content is procedurally generated from a single data file, so if you don't edit or replace the data file, remove all the code you don't use when using that data file. no problem. Since doing this analysis manually is tedious and prone to mistakes, Mr. Giesen and others decided to create an analysis tool called 'lekktor'.

lekktor is a tool that tracks code usage and deletes unused code. to do. The problem with creating this lekktor was the need to analyze the C++ code.

Analysis of C++ code does not need to analyze the entire syntax, only 'if', 'else', 'for', 'while', 'do', '&&', '||', and '?:' related to the flow of the program. is detected. Mr. Giesen and his colleagues checked various analysis libraries, but could not find a suitable library, so they had no choice but to create their own parser.

It took me three days to write the parser, but luckily it worked. Assign a unique ID to each location in your code and count each time the program passes through that location to eliminate unnecessary parts, or eliminate places where IF statements can only evaluate to ``true'' or ``false''. I was able to discover it. After that, we continued optimizing, and completed the intro-less version within 96KB two hours before the contest started. After 30 minutes, including the intro, it was able to fit within 96KB.

The completed .kkrieger won first place in the competition. You can check the actual gameplay in the movie below.

.KKRIEGER-A Truly Remarkable Game that Squeezes a Fully Functional Sci-Fi FPS Into Just 96kb!-YouTube


.kkrieger-The FPS Game in 96KB (Full Gameplay)-YouTube


Also, the source code of .kkrieger is published on GitHub together with other products, so please check it out if you are interested.

in Software,   Video, Posted by log1d_ts