[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Synchronizing movement in a server based online game

Posted on 2004-08-23
4
Medium Priority
?
354 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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 …
Programming  of  forecasting lottery numbers for self use  on Turbo C++ is done by use of random number generator code by a program algorithm logic. Random numbers usually generates numbers between definite interval. Therefore, when entering the c…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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