Synchronizing movement in a server based online game
Posted on 2004-08-23
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?