Deerstalker

A four-player online brawler where you knock each other off a construction site, using hats that grant special abilities.

๐Ÿ‘ฅ
7
Team Size
โฑ๏ธ
10 weeks
Development Time
๐Ÿ’ป
10,804
Lines of Code
๐Ÿ”ง
8
Technologies

About the Project

CSE 125 at UC San Diego is a ten-week capstone where a team builds a networked 3D game from scratch, with no game engine. Our team of seven was Team Deerstalker. The game went by "Rag Cage" on our team site and "Super Awesome Hat Attack Mania Wars" at the class showcase, and the pitch was simple: mysterious hats with great power have started showing up all over the world, so prove you're the true hat master in a last-one-standing brawl.

Four players start on a construction-site stage with three lives each. Fall off and you lose a life; the last player with lives left wins. Hats drop onto the middle of the stage every ten seconds or so, and each one gives you two abilities for as long as you wear it. The idea started as a four-person "pseudo wrestling" game with rag-doll fighting, and the hats were the hook from the very first design doc.

We split into a graphics and modeling sub-team and a networking and game-logic sub-team, and I was on the second. I wrote the server and the networking: the game loop, the protobuf protocol, the Bullet physics world, the character controller, all the combat and hat logic, the client's input and message handling, and the FMOD sound engine. By git blame, about 88% of the server code is mine. The rest of the team built the skeletal animation system and its ten character animations, the HUD and text rendering, the camera, skybox and cloud floor, and the art (modeling, rigging and animating the characters, the stage and five hats), and wrote server pieces I built on or merged: the first server skeleton, the config loader, item drops, respawning and shooting.

๐ŸŽฏ

Objective

Knock the others off the stage; three lives each, last one standing wins

๐ŸŽฉ

Hats

Five hats, each with a primary (RB) and a secondary (LB) ability

๐ŸŒ

Multiplayer

Four clients over TCP; the match starts once all four press ready

โšก

Physics

One Bullet world on the server; clients only render what it sends

How It Works

Deerstalker system architecture: four clients talk to one authoritative server over TCP CLIENT ยท ONE PER PLAYER, ร—4 SERVER ยท AUTHORITATIVE TCP length-prefixed protobuf frames INPUT Controls Xbox controller via GLFW, or keyboard NETWORK THREAD Boost.Asio reader parses frames into a locked queue MAIN THREAD Message handler applies each snapshot to the scene GRAPHICS OpenGL scene graph, GLSL AUDIO FMOD music, 3D effects NETWORK THREAD Boost.Asio sessions one session per playerTCP_NODELAY, 1 MB receive bufferinput goes on a locked queue MAIN THREAD ยท 30 HZ Game loop all the rules: hats, combat, lives PHYSICS Bullet world rigid bodies, controllers, rays SHARED UTIL LIBRARY (CLIENT + SERVER) Protos.proto messages ยท length-prefixed framing ยท HatType enum ยท .ini config input events snapshot + events queued input broadcast step, read transforms Input Networking Game logic Physics Graphics Audio Shared code
Four clients, one authoritative server. Clients send what the player wants to do; the server decides what happens and tells everyone.

The server owns everything. Clients never simulate anything. The server runs Boost.Asio on one thread to accept connections and read messages, and pushes every incoming message onto a mutex-protected queue. The main thread runs a fixed 30 Hz loop: drain the queue and apply each input event, step the Bullet world, expire mangoes and hats, update stun and respawn timers, then broadcast the result. Each tick advances Bullet by 1/15 s in four 1/60 s substeps, so the physics runs at double speed. We sped it up in week 8 because the game felt more natural that way.

One server tick: reset, apply input, match flow, simulate, resolve, broadcast; repeated 30 times a second ONE SERVER TICK ยท EVERY 33 MS 1 Reset turn off hold-to-use abilities:zero gravity, invisible, bear 2 Apply input drain the queue: move, jump,punch, grab, equip, hats 3 Match flow start when all four are ready,respawn anyone with lives left 4 Simulate Bullet advances 1/15 s infour 1/60 s substeps (2ร— speed) 5 Resolve expire mangoes and hats, stunat zero health, revive players 6 Broadcast a snapshot of every object,plus events, to all four sleep out the rest of the 33 ms ยท a new hat every 10 s
The server's main loop. Input from all four players is applied before the physics step, so everyone's actions land in the same tick.

What goes over the wire. Both directions use one protobuf Message, framed as a 6-character ASCII length followed by the serialized bytes, over TCP with Nagle's algorithm turned off. The header started at 4 digits and had to grow once snapshots passed 9,999 bytes. Clients send intents: a direction from the stick (8 directions, read digitally at a 0.5 tilt threshold) plus the camera's facing vector, or jump, punch, grab, equip, and the two hat buttons. Every tick the server answers with a full snapshot: for every player, hat and mango, its 4x4 world matrix as 16 doubles, plus each player's health, lives, current hat, animation state, visibility and hat timer. Alongside that come events for things clients should react to once: sounds, deletions, ready/start, win and game over.

Message format: a 6-digit length header followed by a protobuf Message; what clients send and what the server sends back EVERY MESSAGE, IN BOTH DIRECTIONS โฃ โฃ 1 3 4 2 protobuf Message { messageType, event[], gameObject[] } 6 ASCII digits: body length serialized bytes CLIENT โ†’ SERVER When you press something MOVE 8-way direction + camera facing JUMP ยท PUNCH ยท GRAB one-shot actions EQUIP pick up or throw away a hat HATR ยท HATL hat abilities, sent while held READY from the lobby SERVER โ†’ CLIENT Every tick, 30 times a second GameObject ร— N every player, hat and mango matrix 4ร—4 transform, 16 doubles state health, lives, hat, timer animation one of 13 animations Events player ID, ready, start, sounds, music, win, game over intent truth
One message type in both directions. Clients only ever send intent, and the server only ever sends the truth.

The client is a renderer. A background Asio thread parses snapshots into a queue; the render loop drains it each frame, creates scene-graph nodes for new IDs, and sets each node's matrix straight from the server. There is no prediction or interpolation. The server also decides which animation each player is in, and the client keeps a preloaded skinned model per animation and just shows the right one. FMOD plays sound effects in 3D at the position of the player or object involved, with the listener on your own player.

Client screens from loading to spectating, and the four steps the client runs every frame SCREENS Loading Title Lobby Ready Match Spectating first frame press Start press A, sends READY server sends START_GAME out of lives game over: back to the lobby EVERY FRAME, ON THE MAIN THREAD 1 Read input gamepad and keys becomeevents, sent straightto the server 2 Update audio FMOD tick: music forthe screen, 3D effectsheard from your player 3 Draw scene graph, skinnedmodels, skybox, clouds,HUD, following camera 4 Handle messages drain the snapshotqueue, update everynodeโ€™s matrix
The client's screens and its frame loop. Once you're out of lives, the camera switches to another player until the match ends.

Movement. Players are dynamic rigid bodies with rotation locked off, driven by a controller adapted from the dynamic character controller in Bullet's old demos. Each substep it casts a short ray down to decide whether you're on the ground and a few rays forward to find punch, ram and wrench targets. A move event turns you toward the camera-relative direction and applies a force; a jump is an upward impulse that only fires when the down ray hits something.

Hold-to-use abilities with no state. At the start of every tick the server switches off zero gravity, invisibility and bear mode. The client sends a hat event every frame the bumper is held, which switches them back on. Holding the button keeps the ability on, and letting go ends it within one tick, without any timers or "is active" flags:

// Runs at the start of every server tick
void Game::loopReset() {
    gravityController_->deactivate();
    clearAnimations();

    for (auto pair : playerMap_) {
        pair.second->setVisible(true);
        pair.second->setLinearFactor(btVector3(1,1,1));
        pair.second->setBearMode(false);
    }
}

The Hats

Y picks up a hat within reach or throws yours away. A hat vanishes two minutes after it spawns, even on your head, and the HUD counts that down. When your health hits zero you're stunned for ten seconds and drop your hat.

๐Ÿ‘Š Bare hands (any time)

X punches: 10 damage and a knockback up and away. B grabs a stunned player within reach and carries them over your head; press B again to throw them.

๐Ÿง™ Wizard hat

Primary: fire a mango that lives for two seconds. It does no damage, but it shoves whoever it hits.

Secondary: hold to heal.

๐Ÿš Propeller hat

Primary: hold to fly up.

Secondary: hold to push yourself down.

โ›‘๏ธ Hard hat

Primary: a long-reach wrench swing that does 100 damage, so a hit stuns at once.

Secondary: a ground slam. Players standing within range take 10 damage and are pushed outward; loose hats nearby scatter.

๐Ÿป Bear hat

Primary: hold to switch off gravity for every player (you too) while different music plays.

Secondary: hold to turn into a bear. You're rooted in place and take no damage.

๐Ÿ•ต๏ธ Deerstalker

Primary: hold to be invisible to everyone else.

Secondary: charge forward as a giant ram. Three rays, straight ahead and 60ยฐ to each side, find the target, which takes 20 damage and a bigger knockback than a punch or wrench hit.

Development Progress Videos

Development Gallery

Technology Stack

๐ŸŽจ

Client-Side

๐ŸŽจ

ASSIMP

Loads the OBJ, FBX and .X models, including the skeletal animations

๐Ÿ–ผ๏ธ

OpenGL

GLSL 3.3 shaders, GPU skinning, a cubemap skybox and instanced clouds (with GLFW, GLEW, GLM, SOIL)

๐Ÿ”Š

FMOD

Streamed music plus 3D sound effects, with the listener placed on your player

๐Ÿ“

FreeType

Text for the HUD hat timer and the WINNER! banner

โš™๏ธ

Server-Side

โšก

Bullet Physics

Bullet 2.83; the whole simulation runs on the server only

๐Ÿ”—

Shared

๐Ÿ“ฆ

Protocol Buffers

One Message type both ways: input events up, world snapshots and events down

๐Ÿ”—

Boost.Asio

Async TCP on both ends with length-prefixed frames

โš™๏ธ

C++

Visual Studio 2015 solution: client, server and a shared util library

Week by Week

My side of the project, from my weekly status reports and the commit log. The mood is the 1-10 morale score I gave each week.

  • โ–ธStarted from the Boost.Asio echo example and turned it into a server that broadcasts to every connected client
  • โ–ธMade the client read from its socket asynchronously and merged it with the graphics team's first renderer
  • โ–ธReplaced raw key-press messages with a Protocol Buffers schema for game events
  • โ–ธMade the server the source of truth: it runs the game loop and the only Bullet world, and clients just draw
  • โ–ธDisabled Nagle's algorithm on server sockets to fix the network
  • โ–ธAdded Xbox controller input through GLFW's joystick API
  • โ–ธLoaded collision shapes exported from Maya's Bullet plugin, starting with a compound rigid body for the mango
  • โ–ธHelped debug the camera and skybox and merged them in
  • โ–ธWorked on item spawning in Bullet and integrated the mango shooting
  • โ–ธBullet's kinematic character controller didn't work for us, so we turned to a dynamic (rigid-body) one
  • โ–ธBuilt out item interaction and game logic on the server
  • โ–ธFinished fixing message framing after world snapshots outgrew the original 4-digit length header
  • โ–ธWrote the dynamic character controller: ray casts for ground checks, movement relative to the camera
  • โ–ธMerged the respawn, equipping, throwing and shooting work and added the client side for it
  • โ–ธFixed several server-client bugs that came out of the merge
  • โ–ธSplit every hat into a primary and secondary ability, with one HatType enum shared by client and server
  • โ–ธBuilt the propeller hat and the wizard hat's mango shot, aimed from the player's rotation quaternion
  • โ–ธMoved client message handling out of the window code into a state-based MessageHandler
  • โ–ธSped up the physics simulation and moved character movement back to forces, which made the game feel much better
  • โ–ธPunching with a forward ray cast and knockback impulses; health sent to clients
  • โ–ธCapped the server at four clients with stable IDs 1-4, fixed spawn points and random hat spawns
  • โ–ธMoved animation-state decisions to the server and set up the FMOD sound engine
  • โ–ธBear hat gravity kill and deerstalker invisibility
  • โ–ธRamming, bear mode, stun, grabbing and throwing, the wrench hit and the shockwave
  • โ–ธ3D positional sound effects and the zero-gravity music
  • โ–ธLives with delayed respawn, a spectator camera once you are out, and the lobby to match to lobby loop

Problems I Ran Into

๐ŸŽฎ Character controller

Problem: Bullet's kinematic character controller has known issues, and it didn't work for us.

Fix: Players became ordinary rigid bodies with rotation locked, moved by forces, with ray casts for ground checks and attack targets.

๐ŸŒ Framing and latency

Problem: The game's many small TCP messages didn't behave until Nagle's algorithm was off, and later the snapshots outgrew the 4-digit length header.

Fix: TCP_NODELAY on every server socket, a 6-digit header, and a 1 MB receive buffer.

๐Ÿงต Two threads, one game

Problem: Network callbacks and the game loop run on different threads.

Fix: Callbacks only enqueue messages, and the game loop owns all game state, so the only locks are on the message queues.

๐Ÿคผ Grabbing

Problem: Carrying a player who is also a physics body.

Fix: The grabbed player's linear motion is zeroed out and each substep their transform is pinned above and behind the grabber, rotated to lie flat. Releasing them restores physics and launches them as a projectile in the direction the grabber is facing.

Looking Back

๐Ÿ’ก

Pin down gameplay early

The hat brawler idea never changed, but the actual gameplay wasn't settled until late in the quarter, and most of the hat abilities went in during the final two weeks.

๐Ÿ”Œ

Networking first

My advice in our final report was to get networking working early and make sure client and server can talk correctly at scale. With the server-authoritative loop in place by week 3, most later features were server logic plus a new field or event in the protocol.

๐ŸŽฏ

Sub-teams worked

Splitting into a networking/game-engine team and a graphics team let both move in parallel, with weekly meetings for the big decisions.

๐Ÿ“š

From scratch

Building the engine ourselves is the point of the course, and I liked it: it's how you learn what a game engine actually does. For a game I just wanted to make, I'd reach for an engine like Unity and spend the time on gameplay instead.