Solved

Synchronizing movement in a server based online game

Posted on 2004-08-23
4
346 Views
Last Modified: 2013-12-04
Right now my basic game architecture is as follows:
I have an input manager that simply waits for the user to input something, decides what that input does, and fires the appropriate event.

The client class is the class that communicates with the server.  It does two things:  First of all, it waits for packets from the server, parses them, and fires the appropriate event.  Next, it waits for events that are fired by the avatar (main players model), and if they are not cancelled, packs them up and sends them to the server.

The model manager is the class (self referencing singleton) that manages all the actions of the models.  It subscribes to all the events fired by the client and the input manager, and calls the appropriate methods on all the models in the game.

I also have the main window, which pretty much just acts as the device context for rendering (although for now it handles the camera).

So I have finished the basic implementation of this architecture, but am running into some thread sync (I think) issues.  The first problem i have run in to is coming up with an effective way to handle movement.  Right now, whenever the avatar moves, it fires an event that the client subscribes to and sends to the server.  The problem is that whenever someone hits the "w" key, which starts moving the model, that event will be fired many times per second.  So to fix this just as a temporary fix, I made it so that the move event is only sent to the server once every 10 times.  For some reason, the movement is only updated once on other players' machines.
Now, it could just be a bug in my code (which i can fix), or i can be doing something that is wrong in a broader sense.  Any suggestions?
0
Comment
Question by:davidastle
  • 3
4 Comments
 
LVL 2

Author Comment

by:davidastle
ID: 11872005
One thing i forgot to mention is that the movement is only updated whenever the scene is rendered.  In my old system, in the OnPaint method, I just updated the movement, found the current location, and sent it to the server.  This worked well enough (I don't care much about latency yet).  However, in my new system, i still update the movement on the OnPaint method.  This will fire the Move event in the avatar class, which the client is subscribed to.  The event just passes in the ID of the object that moved.  The server then grabs the object from the modelmanager, and sends this out in a new event.  I know that this method seems sloppy (the fact that the client is accessing the modelmanager to grab the model, and the fact that the model isn't initially sent in the Move event in the model), but I decided that it is more flexible if the client can somehow send out the object that moved in all of its events.  This is because if the client just sent out the ID, every class that subscribes to the events would have to get the model from the model manager anyway.  Is this perhaps my threading issue, that the server has to get the model from the modelmanager every time the move event is fired?  I am locking the model manager class when i get the model, and am locking the list of models when i render them.
0
 
LVL 2

Author Comment

by:davidastle
ID: 11872063
Also note that the avatar always moves perfectly fine on the clients computer, but the other players' models only move once and then stop!
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 11900039
>I made it so that the move event is only sent to the server once every 10 times.  For some reason, the
>movement is only updated once on other players' machines.
Once every 300-500 ms might be a better idea ... What if key was pressed 9 times and then player stopped moving it further ?
The nature of the symptoms indicates that there sould be a problem with your code.
-Are the events generated by other players being correctly sent?
-Are the events generated by other players being correctly received?
-Are these events being processed correctly, in terms of updating data structures, rendering etc?

Try eliminating these possibilities one by one
0
 
LVL 2

Author Comment

by:davidastle
ID: 11909894
Well this was a stupid question to ask in the first place.  I found the problem (wasn't locking correctly).  Sorry, ill give some points for trying to help me out - and in the future hopefully i won't ask stupid questions.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Joseph
CONTENTS I.      What is a MOBA?   a. Definition   b. Origin   c. Current Generation II. The New Games   a. League of Legends   b. Heroes of Newerth   c. Dota 2   d. Smite III. Comparison IV. Conclusion ------------------------…
If you are interested in the gaming world and want to try World of Warcraft, I'd recommend this basic set of add-ons to get you started.  All add-ons are available either by Google search or on Curse.com. For the person who doesn't want to get in…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now