Name: Making singleplayer a special case of multiplayer
Summary: Make singleplayer be in the background a headless server + client.
Scope: Engine
Current Goal: Making singleplayer a special case of multiplayer
Phase: Design
Curator: Florian
Related: -
The idea is to make singleplayer a special case of multiplayer by letting it be single player be
a client that connects to "headless server" started in the background.
Advantages:
Disadvantages:
Get rid of all static variables including the CoreRegistory by replacing it with dependency injection.
In rare cases we can expose a "Context" object that provides a method for registering objects that will then be injected via dependency injection. It may also offer a method injectAll that fills all annotated fields of the object that got passed as argument. Also we may want to have it have a get method to get objects in case they are only available after construction.
Summary: Make singleplayer be in the background a headless server + client.
Scope: Engine
Current Goal: Making singleplayer a special case of multiplayer
Phase: Design
Curator: Florian
Related: -
The idea is to make singleplayer a special case of multiplayer by letting it be single player be
a client that connects to "headless server" started in the background.
Advantages:
- Reduces effort for manually testing it, as currently you have to test singleplayer, non headless server + client, headless server + client.
- It enforces code that seperates clearly between "client" and "server", which makes the code better understandable. There is just one possible setup (client+server) not multiple which have to consider while reading the code.
- It will promote the reduction of non server components from the headless server.
- It will promote the reduction of non client components from the client.
- It simplifies the introduction of client predictions that make games appear less laggy even if the network connection is bad.
Since the client has it's own game state, it can be temporarly modified to show for example a block placement or inventory modfication before the server has confirmed it. Currently we have no block preview and the inventory prediction has some bugs.
- It is possible to debug both server and client in one VM. You can stop both at once for easier debugging.
- Future code developed for singleplayer will "auto magically" work on a headless server with one client - as there is no difference. Currently there are still a few things that don't work with a headless server.
- It has the potential of providing a huge framerate boost. Currently any code that works with entities can't run in parallel. If the server and client have each their seperate entity manager than for example the rendering of entities can run concurrent to some server only calculations like pathfinding or enemy spawn location searches.
Disadvantages:
- The game will need more memory. However the memory need will NOT be doubled!
For example the periodic saving requires a lot of memory and is server only. Everything related to rendering isn't requried on the server. Assets can be shared between server and client if they are read only. Potentially we could even share chunk data. - CPU usage in singleplayer will be higher, as some calculations are done redundantly. A higher CPU usage doesn't however mean a FPS drop.Also the amount of stuff both client and server calculate redundantly should be small.
Get rid of all static variables including the CoreRegistory by replacing it with dependency injection.
In rare cases we can expose a "Context" object that provides a method for registering objects that will then be injected via dependency injection. It may also offer a method injectAll that fills all annotated fields of the object that got passed as argument. Also we may want to have it have a get method to get objects in case they are only available after construction.