Merging multiplayer code with single player code using a local host

Started by
4 comments, last by oliii 10 years, 1 month ago
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?

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.
Advertisement

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.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

isn't this how Minecraft works?

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.

That tradition goes a long way back. Original Quake did that, too, and I'd be surprised if it was the first. It's a good practice.

enum Bool { True, False, FileNotFound };

Quake, Quake 3, Unreal Engine games, Crytek's, even some source games, these work on the principle of a single player game on a loop-back / virtual local network.

Usually, the client / server separation is very strong. Quake 3 is an example of that. The server part is basically a renderless dedicated server, the client part handling the rendering, audio and inputs. Both completely separate contexts, if you will (code-wise, two seperate projects / dll / libraries). It also means, seperate contexts for each entity types, server-side entities that handles logic, and client side entities that handles audio and graphics with virtually no logic of their own (apart for stuff like client-side prediction and particle physics). Plus the networking, messaging and serialsation gubbins in the middle mediating between the two.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement