S
S
SKEPTIC2019-09-24 09:42:34
C++ / C#
SKEPTIC, 2019-09-24 09:42:34

Data in online games?

I decided to write a simple toy.
Players enter the server and everyone plays for a square, can move it in all directions, collide with other players, etc.
The client is written in Python and the server in C#.
And so: for writing of the server understanding of one thing is not enough.
The server itself in C# in the Main method catches connections, receives information and gives the task to an asynchronous method (suppose a change in the position of the player).
What is the best way to store player coordinate data? The update happens 10 times per second.
If you store data in an array, then is it possible to access the array created in the Main method in an asynchronous method?
Or do I need to use some kind of database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shai_hulud, 2019-09-24
@shai_hulud

I have not yet seen a live game server that operates data via DB. All (and this is not an exaggeration) multiplayer game servers operate on data in memory, after which it is dumped into the DB / File System for permanent storage. Those. DB / FS is just a garbage dump where game data is thrown in the background, and at startup they are taken from there.
You need to decide how you will provide access to the game state from multiple threads. Even the worst of the options (this is an exclusive lock on the entire state) will be faster than accessing the DB :)
And there are many good options, their choice depends on what state and how it will change. Start with Mutex for any access. And at your leisure, look at Art of Multiprocessor Programming (although this is with examples in Java, it is suitable for all PLs).
Regarding the storage of coordinates, a structure with two / three fields lying in an array will do. In the future, it will be necessary to choose how to organize the game data. ECS is a good option. Or you can just file your hierarchy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question