Original Post
Hey!
I've been lurking here for quite a few years now, but this is my first post.
I'm currently working on a multiplayer 2D-shooter using C++ and RakNet and lately I've been thinking about making some major changes to how I handle the procedure of receiving data, both client- and serverside.
In the past I've actually finished (sort of anyway) a project very much like this one, at least in a networking sense, but I feel that how I did certain things then that, while they worked alright for that project, were not very scalable.
The way I currently handle the received data is by having a pretty sizable switch-statement for the first byte of the packet and from there I redirect received data to other parts of the program as needed.
I feel that when I start to get tens, if not hundreds of different packet types, it's inevitable that this switch statement will get quite huge and I'm currently looking to split it up somehow, or deal with it in some other way.
At the moment I actually have individual packet handlers for each game state in the client, but I'm starting to think that, while this does make the switch statement(s) more manageble in size, quite a few of the packets I received should actually be handled in just the same way regardless of which state the client application is currently in, so there will be quite a bit of the same code in the packet handlers of the different game states.
One way to do it could be to have one handler for the application as a whole, which handles the packets that are always to be handled in the same way, and then also use game state specific handlers for packets that should be handled in different ways depending on game state, which gets passed these packets from the main handler.
Any suggestions or hints would be greatly appreciated.
I've been lurking here for quite a few years now, but this is my first post.
I'm currently working on a multiplayer 2D-shooter using C++ and RakNet and lately I've been thinking about making some major changes to how I handle the procedure of receiving data, both client- and serverside.
In the past I've actually finished (sort of anyway) a project very much like this one, at least in a networking sense, but I feel that how I did certain things then that, while they worked alright for that project, were not very scalable.
The way I currently handle the received data is by having a pretty sizable switch-statement for the first byte of the packet and from there I redirect received data to other parts of the program as needed.
I feel that when I start to get tens, if not hundreds of different packet types, it's inevitable that this switch statement will get quite huge and I'm currently looking to split it up somehow, or deal with it in some other way.
At the moment I actually have individual packet handlers for each game state in the client, but I'm starting to think that, while this does make the switch statement(s) more manageble in size, quite a few of the packets I received should actually be handled in just the same way regardless of which state the client application is currently in, so there will be quite a bit of the same code in the packet handlers of the different game states.
One way to do it could be to have one handler for the application as a whole, which handles the packets that are always to be handled in the same way, and then also use game state specific handlers for packets that should be handled in different ways depending on game state, which gets passed these packets from the main handler.
Any suggestions or hints would be greatly appreciated.