How do you keep track of the positions of the players in a MMORPG? I read that you can use either a database or you can store the coordinates in files. I tried using a database but it was slow. How can files be used to keep track of players positions?
Answer
How can files be used to keep track of players positions?
You write the player position to the file. For example, if you identify every player with a unique number (or a GUID), you could use that as the file name. In the file, simply write the position data out in a format you can parse later. For example, 467239.txt
might contain 20, 3, 19
if player #467239 is at that (x, y, z) location.
This is not that different from what you would do with a database, however -- a database should not be "slow" at this operation, it should be very fast (probably faster than files, because you have more disk IO overhead or IO locking contention -- if you stored multiple positions per file -- in a filesystem-based approach).
Perhaps you were trying to use the DB or filesystem to store the player position at runtime? You should not do this at all.
At runtime, in your server, player positions should be kept in-memory and updated there, as you would do with any other kind of game. Periodically they can be saved to disk or other persistent storage -- for example, when the player rests, saves, or logs out.
But writing every players position to storage every update is unnecessary and extremely inefficient; it will never be fast enough to handle anything resembling "massive" player scales.
No comments:
Post a Comment