Hacker News new | ask | show | jobs
by aaronm14 2832 days ago
Was this inspired by a custom map on Warcraft 3? Name is escaping me right now.. Been such a long time since I played it!

Would love to know about some of the tech you used to build it

1 comments

Yes, it was based on Warlock, the WarCraft 3 map! I had many fun Friday night LAN parties playing that map and wanted to recreated it!

It's TypeScript, canvas, React (for the UI elements), NodeJS and socket.io on the server. The entire simulation is run on the client. It is deterministic so it is just replaying the action stream identically to all the other clients to stay synced. The server is running a pretty simple loop really, every 32 milliseconds it collects all the actions and broadcasts them to all the clients. If there is anything else you want to know, feel free to ask, I'm happy to talk about it :).

Did you use any server or client game or rendering framework? eg. Phaser, pixi or the like. And when you say the simulation is running on the client, do you mean it is client authoritative and the server just acts as relay? What sort of actions do you send?
The only thing I'm using is Planck.js as the physics engine, besides that it's just raw canvas. I did spend quite a bit of time deciding whether I should go for WebGL or Canvas, but Canvas was just easier and it performs well enough.

There are actually 5 canvases stacked on top of each other - background, glows, objects, interface, cursor. The glows layer has a CSS blur property on it, which lets it be done on the GPU. Initially I just used the canvas shadowBlur everywhere but it was horribly slow, so this was one of the biggest performance boosts. The other layers are just there because they're invalidated/refreshed at different rates for performance reasons. The interface layer is particularly slow to update as its got to draw all the button icon paths, so it only ever rerenders the parts as they change, as opposed to some of the other layers which rerender every frame.

That was it! Man completely forgot about that game! This is a great take on it, I was able to quickly have fun, especially once I was able to recognize the concept. I love that you can mod via JSON as well. Do you have the code open sourced anywhere?
Thanks! I'm not open sourcing the game at this time, maybe in the future I might consider it.