Merging multiplayer code with single player code using a local host
Members - Reputation: 114
Posted 28 January 2014 - 04:16 AM
Gameplay is supposed to be the same for both instances. So I'm essentially thinking I could program multiplayer and also get single player. I figured this might be a way of reducing workload and killing two birds with one stone.
Crossbones+ - Reputation: 2754
Posted 28 January 2014 - 05:39 AM
Is it bad practice to merge single player code with multiplayer code by making single player a client connecting to a private, automatically started, local server?
Afaik its standard practice. Coding a single player game from the start and then turning it into multi player is really hard, on the other hand, going from multi player to a single player game (in the way you proposed) would be easier to do.
My journal: Making a Terrain Generator
Members - Reputation: 496
Posted 28 January 2014 - 07:47 AM
Minecraft indeed does that since one of the more recent versions afaiu. It's great to structure your game around multiplayer if you intend to have it. It is a good thing to abstract the networking logic in such a way so that you can bypass it when in single player. For example, instead of sending a packet over UDP to yourself, receiving it and passing it on to the game logic, you should try to pass it directly to the game logic when in single player mode. Otherwise it may alert firewalls and stuff that can be annoying to the user.