Spaghetti Graveyard 2027

08/10/2026 A New Beginning: 

Before starting Spaghetti Graveyard, I first implemented its core networking architecture for a Pong game to prove that it could work. Just as lessons were learned implementing Pong, working on Spaghetti Graveyard 2026 has exposed new opportunities to design a more complete and modern game.

I usually start from a blank state about once a year. My thoughts on what the game engine should do have gotten ahead of what my current code can do. Going in and patching a whole new architecture to the working game would just be painful.

Lets talk architecture.

 All of the data for the game is stored in a global hierarchy, but I don't like the way its been thrown together.

The new hierarchy will look like:

home:
    global_data* global; //timekeeping, networking,inter-thread communication etc
    map_data* maps[];
    player_data* players[];



map_data:
    core_app* core;           //machinery for rollback and re-simulation
    ECS_app* ECS;             //entity containment system for buildings and units
    UI_app* UI;               //widgets (buttons, textboxes, etc), mouse
    viewport_app* viewport;   //graphics objects like buildings and units as seen by the graphics thread
    graphics_app* graphics    //data and code needed to draw anything to the screen

    
The map data is made up of apps. Each app inherits from a system that lives inside a library, but contains added data used by the runtime.

core_app:
     bbCore core;             //bbCore is a structure provided by the core library
     bbClockHandle clock;     //bbClockHandle is part of the clock library
     ...


graphics_app:
    bbTextures* textures;           // png files uploaded from hard drive
    bbSprites* sprites;             // individual images of units
    bbAnimations* animations;       //collections of sprites
    bbDrawfunctions* drawfunctions; //code required to draw an asset to the screen

//arrays of sprites/animations/compositions each paired with a drawfunction
    bbCompositions* compositions;   
    bbFonts* fonts;

//final pass for graphics calls, ensuring they’re in painter’s algorithm order.
//Contains functions that call shaders to do the actual rendering  

    bbDrawBufferFunctions* drawBufferFunctions; 

 
 The point is, the app can be extended by the runtime. The library supplies a data structure that it knows how to deal with, and the runtime injects callbacks that operate on the extra data.

That being said, I'd like to keep my options open. A different option would be to give every system a void* extra_data. This would make it easy to extend systems without having to recompile anything. I think I'll do both.

Hard Core Rock:

The core is the central kernel of the game engine. It is responsible for the deterministic simulation of the game world. It does this by creating instructions that are pushed to different stacks. An instruction is popped from one of these stacks and then the instruction's callback function is executed. There is one stack for instructions to execute during regular gameplay. One stack contains instructions needed to roll back those instructions. The third stack contains instructions needed to resimulate the game state after it has been rolled back.

I had implemented these stacks with a segmented pool and intrusive list, but after switching to using a segmented deque I've had a 6 times speedup on a rollback heavy workload. The tradeoff is that the order of adding and removing instructions to the stacks is crucial.

The rollback machinery has a purpose. When a player takes an action, a request is send to the server and back. When the message is received back it creates a timed event for the players character to interpret. The message is broadcast to every connected client, and if the act_time of the timed event is before the clients current simulation state the game does a rollback and rewinds the game state to before the event was supposed to be enacted. The game is then run forward normally, as if the event had been created after the core's simulation_time.

There are a few things I'd like to change. There will be multiple maps loaded and one core per map in the global data hierarchy, so the core and it's instructions will need to be aware of which map they belong to. Currently the core isn't even aware of the core_app, so if code needs data from there it has to include the entire data hierarchy. I'd like to avoid reaching into the data hierarchy because I consider the data hierarchy game-specific code and the core is an engine library.

I would like to be able to enact timed events speculatively. When the player takes an action, the request is still sent to the server, but then the client acts on the event immediately. If the message from the server denies or modifies the request, then a rollback is triggered and the game is restored to the state it would have been in if the client hadn't acted on the event.

Modding:

I'm not an artist and I couldn't hope to design an entire AAA game. I'd like to focus on engine features that will attract other developers. One idea I've been floating is graphics packs.

There is a lot of overlap between the RTS and RPG games I've been thinking about for my engine, what applies to RTS civilisations could apply to RPG monsters and characters. One idea I've had is letting the player install graphics packs. There would be a base context for graphics and a graphics context per player. At the start of the game, the game would load a graphics pack based on the theme of the map such as forest/ jungle/winter. It would then load a graphics pack for each player's civilisation. After that the player is free to upload their own graphics packs.

Loading a graphics pack just adds some extra data to a shared graphics pool and adds some extra entries into the relevant context/dictionary. When a unit is spawned, the game just searches the player's context/dictionary for the specific asset, and then if that fails it searches the base context. 

Scripting:

It would be nice for players to modify game behavior without the possibility injecting malicious C code, and without having to write their own simulate/rollback instruction pairs. I propose a scripting language built on top of the deterministic, rollback-able core. 

The script would be implemented with three classes: listeners, nodes and variables.

Listeners wait for events such as events coming from outside the scripting system, timers, or changes to variables. When a listener receives an event, it notifies a node. The node runs a script then modifies variables. When a variable is modified, more listeners can be alerted. 

When a script is loaded is sets up:

Static Variables: shared between nodes in within the script

Input Variables: Interface coming in from other scripts

Output Variables: interface exposed to other scripts

Nodes: Nodes can contain their own local data, or shared data between similar nodes

Listeners: clocks, external events, variable changes

Scripts can be uploaded to namespaces and contexts, for example:

Import archer.bb as archer to players[player1] 

If one event is received by multiple listeners, listeners will need to be alerted in a deterministic order, but I haven't decided on what that ordering should look like. Loading scripts should probably be done in a deterministic order as well so maybe listeners are ordered by file then line number of the script that spawned them.

It will be interesting to make a kind of linker to link input and output variables between scripts.

There exists a global context and one for each player/AI bot. The global context can contain things like game rules, map-specific rules, victory conditions etc. A player context would be for things like tech tree and user interface. An AI bot would have scripts loaded for the tech tree, macro management and micro management.

The goal for Spaghetti Graveyard 2027 isn't simply to make a better version of the game. It's to build an engine where deterministic simulation, rollback, graphics, modding and scripting can be composed without the engine needing to know about the particular game being built.

Boston. 

Update 08/10/2026

Graphics:

I've been experimenting with representing 12 units as a single entity in my entity component system. I was able to simulate a 768 vs 768 soldier battle with very little CPU usage. The deterministic, rollback-able, simulation thread publishes the positions of each group and then the graphics thread expands those coordinates into individual sprites sent to the graphics card. 

I'm pretty happy with the way groups of 12 soldiers and also groups of 12 trees look on the screen, with one caveat. Soldiers from different groups tend to clip through each other. This could be an easy fix. I could calculate soldier's desired position in the group of 12 and then shift apart the soldiers based on how much they overlap.

With the impressive number of soldiers on-screen, I was able to render at 30 frames per second. The bottle neck appears to be the amount of data streamed to the graphics card. If I could publish the group positions to the graphics card and let it sort out the positions of individual soldiers I could probably do even better. That sounds like hard work and I'm open to letting someone else more experienced with GPU programming handle it.

There are a few new features I world like to implement when it comes to graphics.  Firstly I would like the simulation to be independent of the graphics. For each map, the simulation runs as long as one player is active on the map, otherwise that map's simulation is paused. There might be more than one map currently executing but the player only sees one map. 

Possibly the player can see from one map into another. That would require some tricky programming and having multiple graphics contexts running at the same time. I believe modern games have large full maps joined by smaller bridging maps. Time spent in the small bridging map gives the next large map time to load. I could even keep some graphics from the previous map to be used in the next map. The graphics app would just discard graphics that it doesn't need from the last map and load graphics that it needs for the next map. This could work well with my global and local graphics contexts.

I'd like to be able to zoom in and out on the map. All of my 2d coordinate transforms can be done with an added scale factor, and I can easily change the scale of 2d sprites. Right now that would mean going through a table of all available sprites and adjusting their scale in CSFML, the graphics library that the game is built around. A skilled GPU programmer would be able to do this just by changing one variable.

There is a little bug that annoys me. The game has a curved ground surface with nicely rendered hill shading. If a unit goes behind a hill, the unit's legs are still drawn as if they were in front of the hill. I would like to implement a depth buffer that prevents pixels from the unit's sprite from being drawn if the ground surface is closer than to the screen than the sprite. This could also be useful for buildings so that the ground surface clips to the foundation of the building.

As well as a ground depth buffer, I would like to implement a scene depth buffer. The scene depth would contain the distance to whatever is nearest to the screen for every pixel. This would be nice for effects like fog or rain or snow. There could even be things like autumn leaves or petals as an overlay with different translucency based on depth. 

I had an idea about units garrisoning in towers and vehicles. Archers standing on the deck of a boat could visibly shoot arrows at enemy units. Instead of drawing the archers when it comes time to draw their group on the screen, the archers are drawn as part of the boat's graphics pass. First the hull of the boat would be drawn, then the units on the deck of the boat, then the boat's sails.

 The draw buffer does a final pass at sorting sprites before they're drawn to the screen. Further away sprites are drawn first and then closer sprites are drawn over them. To do the hull/deck/sails sorting the draw buffer would first sort by the position of the vehicle, then by the layer, and finally by the unit's individual positions, which are locked relative to the boat.

Since the interface between the simulation thread and the graphics thread is well contained, the game engine could be adapted to use full 3d graphics, but I'm not a big fan. Furthermore, movement in the game is just an ECS system that uses snapshots for rollback instead of using rollback instructions. This could be swapped out for a rollback-aware 3d physics simulation. The engine could even be used for a first person shooter. An FPS would be an interesting use case because instead of having thousands of units updated at a moderate pace, there would be dozens of units updated at a higher frequency.

All in all this project is looking hopeful and there will be plenty of work for me to do in future. 

Boston. 

Update 09/10/2026

The current iteration of Spaghetti Graveyard does movement and avoidance between units pretty well. The movement system consists of an array of 1000 structs. The position of every struct is compared with the position of every other struct, a repelling force is calculated, an attractive force is added and then the position of each entity is recalculated. For smoothness this is done in 12 passes instead of one per simulation frame. Using a double buffer technique prevents reading and writing to the same data within a single pass.

I shouldn't say forces because that implies acceleration. Nearby units give each other a nudge to their velocity.

In 2027 I'll design a new system. Data will be divided into map squares, and within those squares data will be stored in a struct of arrays. That way positions of objects will be stored in contiguous buffers, improving memory locality and possible vectorisation.

The engine will batch jobs to helper threads. 12 times per simulation frame, a batch of jobs will be spawned to the helper threads. Each job will take all of the objects in one terrain square and compare each of their positions to objects in nearby squares, then use the position data to calculate forces.

I've also implemented avoidance in the graphics thread. If two graphics objects try to occupy the same space, they give each other a nudge in the other's position. The effect is that soldiers jostle for position in a large crowd and look more like individuals than units in a groups of 12.

 

Update 11/10/2026 Character Animation

Character animations work pretty well in Spaghetti Graveyard 2026. A group of 12 can be idle, walking, fighting or dead/dying. If the unit is walking too slowly it shows the idle animation.  If the group of 12 soldiers are fighting, only the front row fights and the rest stand idle.

What I would like to see is different animations for slow movement/walking/running/sprinting. I'd like to reflect these states in the movement system: A group of soldiers would walk around, charge at the enemy, get bogged down in battle but still try to push forward.

One other thing I would like is for soldiers in a group to have different skins. I could implement this now, I just have to get hold of multiple sets of spritesheets. Soldiers should vary in appearance and animation while still being the same underlying type.

I put together a battle between 768 hoplites vs 768 legions:

 


All for now,

Boston 

 

Comments

Popular posts from this blog

Maths Game / Engine

Fossicking

Diablo II Hell Bovine Figurines