More server control

Planning and Development

After some more thinking about it and a little bit of testing I decided to see how complicated it would be to have the server completely control the movement of the boars.  This involved a couple of steps.  I installed THREE.js and a PNG library called PNGJS on the server using NPM.  Then I had the server load in the height map for Penrith Forest and create a PlaneGeometry object with the geometry’s y values corresponding to the y values of the height map, i.e. a terrain.  Then I moved over the function to calculate the terrain height at each boar’s x, z location and called it at each boar position update, then took the code that calculated the terrain height out of the client piece (to make sure updates were coming from the server) and just set each boar’s y value to whatever the server sends at each update.  It works and makes sense.

This wasn’t a ton of work necessarily, but it was a big shift in thinking from the way the game has been coded up to this point.  I think this is the way to go with the rest of the game, but I will definitely need to be careful to optimize the server side code because once the world gets very big at all sending updates for dozens or hundreds of entities to dozens or hundreds of connected clients multiple times per second is going to get very expensive in terms of bandwidth and just processing power on the server.  It’s entirely possible that these issues will make the creation of a game in this fashion impossible from a practical standpoint, but I won’t know that until I get there so I see no alternative but to push forward and try to tackle challenges as they arise.

Next I’m going to try and smooth out the movement of the boars between server updates.

Leave a Reply

Your email address will not be published. Required fields are marked *