How do I synchronize the same client and server side object in a client / server application? Is a small messaging system good for the job?

I am making a game engine in C ++ and python. I use OGRE for 3D rendering, OpenAL for sound, ODE for physics, OIS for input, HawkNL for networking, and boost.python for the built-in python interpreter. Each subsystem (library) is wrapped in a class manager and each manager is a singleton. Now I have a class - Object - this can be every visible object in the game world. This is a kind of mix, the object has a graphical representation (entity) and a representation in a physical simulator (solid state). These two are the most important here. The Object class is just a pure abstract base class - an interface. I decided to implement Object on the client side as ObjectClientSide - this implementation has an object, and on the server side - ObjectServerSide - this implementation is solid. The physics simulator works only on the server,and rendering is done only on the client, of course. An object can only exist when both implementations work together. Each object has a unique identifier, and both client and server side instances of the same object have the same identifier.

So, after this short background, my first question is, is this design good? How can I make it better? And the main question is: how do I synchronize these objects?

Then both implementations have the same interface, but part of it is implemented on the server side and partly on the client side. So, for example, if a player wants to advance his character, he must send a request for an object on the server. The server then makes changes to the simulation and sends the updated position to the client. For this reason, I created a small message structure. There is a Message, Router, Rule class and rules inherited from the rule. When a message arrives, the router checks it against the rules and sends it to its destination. So when I call myObjectInstanceOnClientSide-> setPosition (x, y, z), this object creates a Message, its content is a function and parameters, and the destination is an object with the same ID on the server.When an object with the same server-side identifier receives this message, it calls this function with the given arguments. Thus, when a function cannot be implemented on one side, it creates a message and sends it to the object on the other side. I think this can be very useful in scripting. The scripts can be very clean if the script needs to, for example, enable animations on clients, I only need to call this function on the server's local object, the rest is in the background.enable animation on clients, I only need to call this function on the server local object, the rest is in the background.enable animation on clients, i only need to call this function on the server local object, the rest is in the background.

So is this ok? Am I wrong? Is this a general solution?

+1


source to share


1 answer


It looks like you are sending a lot of tiny messages. The UDP and IP headers will add 28 bytes of overhead (20 bytes for the IPv4 header or 40 for IPv6 plus 8 bytes for the UDP header). So, I would suggest combining several messages to be sent along with the periodopia.

You can also read these other questions and answers:



I added a bunch of useful links to the DevMaster.net Wiki years ago that are still maintained:

I suggest you start reading Glenn Fiedler's blog . He has done incredible work with network physics, including the recent release of The Network for Game Programmers .

+7


source







All Articles