GameDev 2019 Week 38: New Network Protocol
Network Protocol, Game Flow, Pathfinding13.11.2019 - 21:02
Network Protocol Rework
With the release build from a few weeks ago I tested the game with two friends and while the game itself was functioning, there were some desync issues where a client believed it was eliminated, while the server still thought the client was alive. I thought I had fixed that issue, but apparently it could still happen and there were also other aspects of the multiplayer system I didn't like.
Therefore I decided it was time to completely change the way the network protocol of the game works. Originally I wanted to have the option to have a game instance running on the server and simulate the game on the server to verify whether the clients results are within some margin of error. But during the last months I strayed away from that idea further and further. The server would accept the wave results from the clients and didn't even simulate the waves anymore. But it still had a game running which had a lot of overhead that the server really didn't need anymore.
So I removed the game instance from the server. This took some time to get everything working again without it. The server now only stores the core game state, and just syncs player changes to all clients. Every client simulates its own game, but only the results for the client player count, e.g. only the client player can decide it is eliminated. As an additional benefit the server needs a lot less resources to be run and by removing the game code and its dependencies, the server code is a lot cleaner.
When testing the game with more than one human, there were some game flow issues that became apparent, mainly having to wait for other people to chose. After each wave all players get to chose a reward and then the next wave. Previously all players had to complete each step for the game to advance to the next game state, which felt really bad when playing. So I used the opportunity of rewriting the network protocol to also change the flow of the game. I changed it so every client advances to the next game state immediatly - only the start of the wave is syncronoized for all clients. So if one person choses faster than the others, he can already start building while the others still chose.
One of the first things a friend tried was to completely obstruct a waypoint to see what would happen. I had thought of that and the player would just automatically lose the lives of the wave when there was no valid path for the enemies. However, this doesn't really feel that fair and could be improved. Therefore I changed the path finder to try to find a path without visiting that waypoint if it is obstructed. In most cases having the mobs not visit a waypoint will result in a shorter path so it is still a punishment (There may be a special edge case on a weird map where blocking a waypoint is benefitial, but I can't think of one at the moment). However, if the player blocks the last waypoint, which is the finish, he will still automatically lose the lives. If the mobs cannot get to their finish at all, the player deserves to lose lives. I also fixed a bug where a player would only ever lose 1 life no matter how many lives he should lose according to the current wave.
I also changed a lot of minor things this week, here are some of them:
- When clicking the ready after building button, the button will now disappear and a (Ready) text will show up in its place while waiting for others to also be ready. Previously there was zero feedback when clicking that button, which would cause a lot of confusion.
- The reward selection and wave selection uis will not appear anymore if a player is eliminated and is only spectating the game.
- Fixed the game complete condition with the new network protocol.
- When a player is eliminated the player is grayed out in the multiplayer stats ui.
- The building buttons will not do anything anymore when a player is eliminated.
- Fixed some disconnecting issues and disconnected players are also grayed out in the multiplayer stats ui
- The server will shut itself down automatically if no player is connected anymore.
- The server will shut itself down automatically after 5 minutes when the game is complete.
I also reinstalled Codeblocks on my laptop after upgrading to the newst ubuntu version and got all projects compiling again. However, as expected, they don't run on the server anymore. We have been thinking about upgrading the server to a newer debian version too, which would break the build system again, so until we have upgraded the server I probably won't fix the server builds.
by Christian - 13.11.2019 - 21:02