GGEngine
Engine: C++20, built by a team of nine
- My part
- Tech lead, networking
- Team
- 9 people
- When
- Sep 2025 to Apr 2026
- Games on it
- Order N Chaos
- Made with
- C++20, Winsock, UDP, LuaJIT, OpenGL 4.5, CMake, Steamworks

What it is
GGEngine is a custom C++20 game engine that our team of nine built at DigiPen. I was the tech lead and I wrote the networking. Order N Chaos is the game we shipped on it, and a port of it can be played on that page.
The engine is made up of five parts:
| Part | What it is |
|---|---|
| GGMath | A header-only math library |
| GGNetworking | Sockets, reliability, fragmentation, checksums |
| GGEngine | The entity-component world, the client and server, RPC, Lua bindings |
| GGEditor | The editor, which is also the game itself in a shipping build |
| GGProjects | The game’s assets and Lua scripts |
GGNetworking doesn’t depend on the rest of the engine, so it can be built on its own.
The three layers
flowchart LR
lua["Lua scripts<br/>lobbies, turn phases,<br/>abilities"]
eng["GGEngine<br/>GameClient, GameServer,<br/>RPC routing"]
net["GGNetworking<br/>reliability, fragments,<br/>checksums, I/O thread"]
os["Winsock,<br/>or Steam"]
lua -- "RPC.call(...)" --> eng
eng -- "messages" --> net
net -- "packets" --> os
Each layer only knows about the one below it. A gameplay programmer writing Lua never touches a socket, which was the goal, since I wanted the rest of the team to be able to build multiplayer features without going through me.
The wire protocol
UDP doesn’t guarantee anything, a packet might arrive, might not, or might arrive twice, so everything beyond that has to be built on top.
Every packet starts with a 9-byte header: a sequence number, the payload size, a checksum and a packet type. Every data packet gets its own acknowledgement, and if no acknowledgement comes back the packet is sent again.
sequenceDiagram
participant S as Sender
participant R as Receiver
S->>R: packet 12
R-->>S: ack 12
S-xR: packet 13 (lost on the way)
Note over S: no ack, so wait one timeout
S->>R: packet 13 again
R-->>S: ack 13
S->>R: packet 14 (arrives corrupt)
R-->>S: nak 14
S->>R: packet 14 again, straight away
R-->>S: ack 14
The main question is how long to wait before resending. Each connection measures its own round-trip time and sets its timeout from that:
EstimatedRTT = 0.875 * EstimatedRTT + 0.125 * sample
DevRTT = 0.75 * DevRTT + 0.25 * |sample - EstimatedRTT|
timeout = EstimatedRTT + 4 * DevRTT (between 20 ms and 1 s)
Only packets that were never resent give a sample, because an acknowledgement for a resent packet could belong to either copy. The timeout doubles every time it fires, and the sender gives up after 25 attempts.
Messages that are too large for one packet, which is about 1,400 bytes, are split into fragments and reassembled on the other side, up to 16 KB. For liveness, a client pings every 2 seconds and the server drops a client that it hasn’t heard from in 10.
Threading
One I/O thread owns the socket, and it handles receiving, acknowledging, reassembling and resending. Completed messages go into a queue.
The game thread never blocks on the network. Once per frame it swaps that queue with an empty one, releases the lock, and processes the messages it took.
RPC from Lua
This is the part that the rest of the team used. A gameplay programmer declares a global Lua function with a prefix, and the engine picks it up.
-- on a client
RPC.call("ServerRPC_OnSubmitActions",
NetworkedGameClient_instance.assignedClientID,
gm.localMoveSupportQueue,
gm.localAttackQueue
)
-- on the server
function ServerRPC_OnSubmitActions(clientID, moveSupportQueue, attackQueue)
-- check the plan, then wait for the other player
end
Arguments can be numbers, strings, booleans, entity handles, arrays and nested tables. This is how one turn of Order N Chaos runs on top of it:
sequenceDiagram
participant A as Order player
participant S as Server
participant B as Chaos player
Note over A,B: 90 seconds to plan, neither sees the other's plan
A->>S: my moves and attacks
B->>S: my moves and attacks
Note over S: check action points, then resolve the whole turn
S-->>A: the full result
S-->>B: the full result
Note over A,B: both clients play it out as animation
The server is the authority. It resolves the whole turn, and the clients only play out the result.
What I got wrong
Any packet could call any Lua function. The first version of the RPC system read a function name from the packet and called the Lua global with that name. This is the comment I left on the fix:
A network peer must never be able to name an arbitrary Lua global: doing so puts loadstring, dofile, require and every engine binding one packet away from remote invocation.
Handlers are now registered in an allowlist. The engine also checks the direction of the call, the number of arguments, and that the client ID in the call matches the connection it arrived on, and each client is rate-limited.
A fixed one-second resend timer. One second is either far too long or not long enough depending on the connection, which is why it was replaced by the adaptive timeout above. The 20 ms floor exists because one thread serves every client, so an acknowledgement can be late for reasons that have nothing to do with the network.
The checksum only covered the header. A packet with a valid header and a corrupted payload would pass. The checksum covers both now.
Fragments are not resent. They go out on the unreliable path, so losing one fragment loses the whole message. This is still the case.
Two decisions I would keep
The transport is chosen at runtime. When I added Steam, I put an interface under the reliability layer with a Winsock implementation and a Steam one, and which one runs is decided when the game starts. This kept the plain socket path available for testing without a Steam login, and it also meant that if the Steam integration wasn’t working by the deadline, I could force the Winsock transport and still ship a LAN build.
My reliability layer still runs under Steam. Steam has its own reliable channel, which would probably resend sooner than mine over a relay. I left it off by default because the custom reliability layer was graded work and would no longer run on that path, but it’s a single switch to turn on.
Where it ended
Order N Chaos shipped as version 1.0 with an installer. It’s always 1v1, either on one machine or online through Steam lobbies.
The header of my reliability layer describes it as an academic implementation, and says that a production game should use an established library, which is fair. It has no protocol version and no reconnect support, and on plain sockets a player is identified only by their address and port.
How it evolved
Sep to Oct 2025
Engine core
The entity-component world and the Lua scripting were built first, along with the first versions of the client, the server and the RPC bindings.
Milestone 3
Local play
A pass-and-play prototype with two units per side and no turn timer. Online play was listed as future scope at this point.
Milestone 4
First connection
A feature test script made the first RPC connection from Lua.
Milestone 5
The game goes online
Lobbies, turn phases and turn resolution were written in Lua by our gameplay programmers, and I wrote the networking document.
Mar 2026
Reliability rework
The fixed one-second resend timer became an adaptive one, corrupt packets started being reported immediately, and the checksum was extended to cover the payload.
Apr 2026
Shipped
Order N Chaos 1.0, with a tutorial and an installer.
Aug 2026
After submission
I fixed the RPC dispatch, added a transport interface under the reliability layer, and added Steam networking and lobbies behind it.


