How to set up an architecture and a strategy allowing the persistence of the data of a MUD in a relational database?
Type of game:
My question relates to the design of a Multi User Dungeon (MUD).
A MUD is a textual online game, considered today as the ancestor of the MMORPG. Players create characters and then control them in a completely text-based world using commands. For example, they can move from room to room, kill monsters, collect items, equip themselves with armour and weapons, solve quests, etc.
From a technical point of view, it is simply a server written in C++. Players connect using MUD clients or directly via the telnet protocol.
I would like to ensure the persistence of the game using a relational database.
For performance purposes, I do not intend to load and save my data from the database in real time.
I plan to:
- load all my data in memory at the launch of the MUD
- save only objects that will be modified during runtime at regular intervals of time (every minute for example)
If possible, I would obviously like the code that ensures the persistence of the data to be completely independent of the game data.
I have a hard time knowing which architecture to set up.
For instance, I do not know how to manage the dependencies of the objects between them. For example:
- an object of type Character has a pointer to an object of type Room
- this object of type Room itself has a list of pointers of Objects placed on the ground
- these Objects themselves have a pointer to their Prototype (a prototype corresponds to the model of the object)
How do I do to load all these dependencies properly? I could obviously hack a code that does it. However, I do not see how to do it cleanly. Is there a relatively simple way to do it, without coding an entire ORM for that?
All the examples that I find on the internet mention the different Design Patterns put in place by the ORMs. It looks complex. It must be a lot of code to write!
Or they give answers that do not seem satisfactory. For example:
“You may have objects that point to too many other objects for them to be loaded immediately. Sometimes linked objects will link to other objects further increasing the amount of data to be loaded if you want to load all dependencies at once. It may even happen that you encounter endless reference loops leading to stack overflows or script timeouts. This means that most of the time we need to make a judgment where to cut off the dependency chains.”
I don’t want to cut the dependency chains. I just want my entire object graph. Not less. Not more!
The problem I encounter, however, seems relatively basic. It had to be solved millions of times. However, I can not find examples or solutions that are clear and relatively simple.
My first approach:
I could maybe:
- load all my objects without any dependency
- once all my objects are loaded and accessible in memory, some methods might have the task of solving all these dependencies and recreating all the links between the objects
In this case, does that mean that I will have to store the Primary Keys of the different objects directly in the objects? It would break the total independence of my game objects and the way I persist my data.
My question would be:
In the case of an online game and since my different game objects will be strongly linked to each other, what would be a possible strategy and architecture allowing the saving and the loading of these data in a relational database, while managing the dependencies of the objects between them?
How do people usually solve this problem?