Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I started an MMORPG game, and I can already make a character move around the map and see other characters. But I have doubts about my architecture.

I have a loop which, every x milliseconds, request from the database the actual position of all characters around the main character. After that, I remove all the objects from the screen and redraw them based on the data retrived from database. Is this reasonable, or is there a better solution?

share|improve this question
    
thanks for well editing :P –  Seva Oct 16 '11 at 0:30
    
Your approach seems flawed... have a look at gamedev.stackexchange.com/questions/18069/… –  Coyote Oct 16 '11 at 19:51
add comment

1 Answer 1

up vote 5 down vote accepted

I wouldn't consider that a good, scalable solution, no. The client should not directly query the database on the server, because that will overload the server/database with requests as you increase in scale. You also should not rely entirely on the server for position information as it will create an unpleasant experience for the client.

Multiplayer games in general typically employ client-side prediction to cope with the latter situation. This involves having the client maintain a local copy of its simulation state. When a player issues a command to the client, the client transforms that into a request for action which it sends to the server.

While the client waits for the server to confirm that the action is legal, it assumes the server will say yes, and updates its local state accordingly. This local state is used to render and subsequently is what a player will base subsequent input on. This allows for a responsive-feeling client (if you are constantly waiting for the server before moving at all, the client will feel sluggish and laggy even under ideal network conditions).

Eventually the server will get the request, process it, and can send a response to the client in the form of updated game state or some such -- the client, when it receives this, simply updates its local state to match, since the server is the authority. You will probably also want to employ smoothing between state updates to help hide unpleasant latency effects this can cause.

You can find lots of resources for client-side prediction and smoothing via Google or your favorite search engine.

As for the former issue... neither the client nor the server in an MMO should read data from the database constantly. It should keep the data and the game state in RAM locally, and push to the DB in intervals so as to avoid flooding it. See this related question for more information.

share|improve this answer
    
I understand what you said. Thanks for sharing your knowledge. But there is a thing that shouldnt work using your strategy. If I keep moving around the map without sending instantly the message to the database, then how can I know if someone is walking behind me, or even worse, how can I know that someone is attacking my character? –  Seva Oct 16 '11 at 1:37
    
The server will tell you what is behind you and what is attacking you. It has that information, as well as information about your position and everything else's position, in RAM. Accessing that information is much faster and more scalable than reading it from a database. –  Josh Petrie Oct 16 '11 at 2:07
    
I dont get you. –  Seva Oct 16 '11 at 2:33
    
What specifically? The server tells the client about the current, correct state of the game, including what is nearby the active player. If you have follow-up questions about what that might mean, you should post a new question or perhaps ask in chat, to avoid letting this comment thread get too chatty. –  Josh Petrie Oct 16 '11 at 2:43
    
It's harder to understand by not talking face to face, but I think I understood you. Thanks. –  Seva Oct 16 '11 at 3:09
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.