Solved

Synchronizing movement in a server based online game

Posted on 2004-08-23
4
349 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Computer use secret parental monitoring 14 94
best gaming system configuration 6 85
Battlefield 4 PC or PS4 2 138
How would I do a website like this? 5 89
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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