Server Side Terrain Generation!
Exciting news in the Entity world today – I’ve successfully sent terrain over the internet!
I’ll give a quick rundown as to how this became possible. Bear in mind this is a prototype, and the process will likely change in future iterations of the game.
Technology
We have chosen to offload terrain generation to a webserver in order to help keep our client snappy. We’ve chosen to use node.js for the server for several reasons. Firstly, our client is running on Three.js. This gives node two benefits.We can code both client and server in one language, JavaScript. As well, Three.js loads meshes in the JSON format, which means a server based in JavaScript is ideal. Node.js plays really well with WebSockets, using the Socket.IO framework. This allows us to have a reliable real-time connection between our client and server, which is a requirement for our project.
Process
Now that the tech is out of the way, this is how the whole thing actually works. Our terrain is broken down into “Chunks” measuring 50m by 50m, so we’re not transmitting giant data blobs. The server is in charge of generating and sending out the data, and the client is in charge of figuring out when it needs new land, and requesting it. On page load, the client and the server say ‘hi’, and the client requests the first batch of chunks, measuring 600mx600m total. Each time the player moves to a new chunk, the client sends an event to the server letting it know the new position. Since the server is the one doing the heavy lifting, it keeps a wider radius of chunks loaded than the client. This means, when the client asks for a chunk, the server should have already generated it awhile ago.
We’ve got it working with our game engine, which is a very exciting step for our project! You can check it out here: http://entity.ryanbottriell.com/game/0.00283/