Why Doom?

Doom gives a database a serious workout. Every game tick updates a world in motion, and every frame brings together geometry, textures, lighting and sprites. Move, open a door or fire a weapon, and the database has to keep up. A slow query becomes a frame you have to wait for. That's what made it such a compelling challenge for ASQL, our in-memory SQL database with vectorized execution and JIT compilation.

The game runs through stored functions in ASQL. Each game tick takes the player's input and updates the world: movement, collisions, weapon fire, doors and monster behaviour. Those changes are written back to the game tables, which the renderer queries to produce the next view.

We got Doom running inside ASQL, our database, at the original 35 frames per second. The levels, textures, monsters and game rules live in tables and SQL, with stored functions driving the game.

That was the starting point. Once it was running, we wanted to see how much further we could take it: higher resolution, modern lighting, 3D models and rendering beyond the original frame rate.

Doom's first room, E1M1, in the original 320 by 200 look with the status bar
E1M1 as Doom drew it in 1993: 320 by 200, with the status bar. Every pixel of this picture comes out of one SQL statement.

A frame drawn by one SQL statement

In classic mode, every pixel on screen comes from a single SQL statement. It brings together the level geometry, textures, lighting and sprites to draw Doom's original 320 by 200 view.

The wall textures alone occupy more than 1.2 million rows, one per texture pixel. Movement, shooting, doors and monster behaviour are handled by stored functions. The database holds the world and advances it as you play.

The nukage pool room in E1M1: green slime, brown ledges and a pair of lamps, in the classic 320 by 200 view
The nukage room in classic mode. The SQL renderer combines wall textures, floors and sprites into the finished frame.

Even the colour changes come from the game data. When you get hit, a query derives the red screen tint from the palettes in the WAD. The mountain sky is a texture stored in a table, just like the walls.

An outdoor wall in E1M1 with a mountain sky behind it, classic view
The sky, walls and game state all live in ASQL.

From keyboard input to a frame

A loader reads the level and assets from doom1.wad into ASQL and installs the stored functions. During play, a client passes your input to those functions and displays the result. ASQL maintains the game state and runs the rules; the client handles input and display.

Beyond the original 35 FPS

Getting Doom running at its original 35 FPS answered the first question. The next was how far we could push the presentation while keeping the game in ASQL.

We added a modern rendering mode. ASQL produces the scene geometry: walls, floors, ceilings and sprites in world space, along with lighting data. A native rasterizer draws a 1280 by 960 true-colour frame. The weapon is a 3D model, lit by the room and its own muzzle flash.

The game still advances at Doom's 35-tic rate. Rendering runs separately, interpolating between updates for smoother movement without changing the pace of the game. The modern monsters also use data held in ASQL: skeletons, meshes and animation channels stored in tables.

The first room in the modern 3D view: sharper textures, a hex-tiled floor and a pistol model in the foreground
Modern mode, 1280 by 960. Same level, same database.
The first room lit up warm by a pistol's muzzle flash, with the pistol in the foreground
Firing the pistol lights the room. The flash is one of the dynamic lights the scene query hands to the rasterizer.

Want to explore ASQL? Download it here.