?
Solved

Synchronizing movement in a server based online game

Posted on 2004-08-23
4
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For those of you searching for a fun but also medium paced MMORPG game I would highly suggest Ragnarok Online. This MMORPG is a bit older than World of Warcraft and in a way is extremely different. Compared to WoW's 3D environment and massive wor…
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 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