Summary:
My 50% complete 2D scroller with Box2D as a physics engine should have multi-user support in the final version. However, the current code is just a one-player game.
- What should I do now?
- And more importantly, how do I implement multiplayer and combine it with singleplayer?
- Is it a good idea to encode singleplayer mode, separate from multiplayer mode (e.g. Notch did this with Minecraft)?
Performance in a single player should be as good as possible (simulating physics using a loopback server to implement singleplayer mode would be a problem)
Full background / questions:
I am working on a relatively large 2D game project in C ++, with physics as its main element. (I use Box2D for this)
The finished game should have full support for the multiplayer game, however I made a mistake that I did not plan the network part correctly and basically worked on the single-player game so far.
I thought that multiplayer support could be added to an almost finished single-player game relatively easily and clearly, but from what I read it seems to be wrong.
I even read that a multiplayer game should be programmed as one from the very beginning, and singleplayer mode actually consists only of hosting an invisible local server and connecting to it via loopback. (I found that most FPS engines do it this way, as an example, Source)
So here I am, with my half-finished 2D scrolling, and I really don't know how to do this.
Just continuing to work on singleplayer / client is now useless for me now, as I will have to transcode and reorganize even later.
Firstly, a general question for anyone who is in this situation:
Then, more specific - I tried to figure out how I can approach the network part for my game:
- Invisible / loopback server for single player
This will have the advantage that, in principle, there is no difference between singleplayer mode and multiplayer mode. No additional code required.
Big flaw: performance and other limitations in a single player. There will be two physics simulators. One for the client and one for the loopback server.
Even if you work by providing a direct path for data from the loopback server, through direct switching by streams, for example, a single player will be limited.
This is a problem because people need to be allowed to play with masses of objects at the same time.
- Split single player / multiplayer mode
In single player mode, there will be no server.
I'm not sure how this will work. But at least I think that there will be a lot of extra work, because all singleplayer functions need to be reimplemented or glued to multi-user mode.
- Multiplayer mode as a module for a single player
This is just a quick thought. Multiplayer can consist of a single-player game, with an additional network module loaded and connected to a server that sends and receives data and updates the world with one player.
In retrospect, I regret that I had not planned a multiplayer mode before. I am really stuck at this point, and I hope someone here can help me!