Wilden Dawn

Stats websocket server

By Robin Dowling · 3 months ago

The evolution simulation generates a constant stream of data: births, deaths, species counts, population dynamics. This data was always available inside the simulation, but visitors to the site had to enter the full interactive experience to see any of it.

I wanted visitors to see the simulation's state on the webpage, before deciding whether to jump in. So I built a dedicated WebSocket server that broadcasts simulation statistics to the front page in real time.

The stats server is lightweight and separate from the main state server that handles game clients. It connects to the simulation engine, receives stats every 5 seconds, compresses the data, and broadcasts it to all connected clients. When a new visitor opens the homepage, they immediately receive the current stats without waiting for the next broadcast cycle.

On the client side, a stats display component cycles through different formatted views of the data. Total organisms with animal/plant breakdown. Births, deaths, concurrent generations. Species count. Dominant species for both animals and plants. The display fades smoothly between stats every 4 seconds.

The architecture keeps everything decoupled. Stats clients and game clients don't interfere with each other—they connect to separate endpoints. The stats broadcast logic is isolated from game state logic, making both easier to reason about and scale independently.

The result is a homepage that feels alive. Visitors see the simulation evolving in real time, species appearing and disappearing, populations rising and falling, without needing to enter the world themselves. It gives immediate context about what's happening inside before deciding to explore further.