Road Fighter

Road Fighter is an arcade racing video game developed by Konami and released as an arcade machine on December 7, 1984. Later, versions were released for MSX1 computers (1985) and the Nintendo Entertainment System (1985 in Japan, 1991 in Europe).

In 2003, Retro Remakes organized a “remake competition,” where participants were challenged to recreate a game from scratch in a short time. The team Brain Games decided to participate with a remake of Road Fighter for MSX.

What I did

The source code of the game was available on the Brain Games website, which I used. I informed the original clone author about my work – amusingly, he was happy and said he was looking forward to the web version.

First, I did a small code refactoring to make the game compile with a modern compiler using the “modern” version of SDL 1.2. Then I performed a larger code refactoring – dividing the code into logical parts and making it readable (here, my favorite VIM and clang-format were very helpful). Next, I had to make fixes to the sge library code required by the game.

After that, I ported the game to Linux and macOS, and six months later, I finally completed the port to Web.

Main challenges

The Web version was the most troublesome. At first, the game wouldn’t run at all – this was because the main loop needs to be slightly different for Emscripten (and generally for any properly designed architecture).

The next issue was clearing the screen (or filling it with black). You can’t just use zero; the zero must have an alpha of 0xff.

Later, the game seemed to freeze when loading a level – it turned out it wasn’t frozen, just very slow to load. I had to make many optimizations, mainly related to direct access to SDL surfaces. I solved this by removing Lock/Unlock calls from the main loops.

Another problem appeared when the car spins after a collision and skid marks must be drawn. Drawing lines was extremely slow, and they were never cleared even when off-screen. Moving the lock outside the loop and clearing the line list solved the issue.

I also improved file system handling, video and audio initialization, and music and sound loading. There were many changes – too many to remember. Anyone interested can compare the original game (the first commit) with the current master branch.

I might eventually add save-state support for the Web version. It’s not hard – synchronizing the “local” file system before reading is sufficient. IDBFS is perfect for this, but I haven’t gotten around to it yet.

Links