views:

419

answers:

1

Hi,

I'm making a game engine in c++ and python. I'm using OGRE for 3D rendering, OpenAL for sound, ODE for physics, OIS for input, HawkNL for networking and boost.python for embedded python interpreter. Every subsystem (library) is wrapped by a class - manager and every manager is singleton. Now, I have a class - Object - this could be every visible object in game world. This is some kind of mix, object has graphics representation (entity) and representation in physics simulator (solid). These two are most important here. Class Object is just pure abstract base class - interface. I've decided to implement Object on client side as ObjectClientSide - this implementation has the entity, and on server side as ObjectServerSide - this implementation has the solid. Physics simulator runs only on server, and rendering is done only on client of course. The object can exist only when both implementations are working together. Every object has unique id and both instances of the same object on client and server side have the same id.

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

Next, both implementations have the same interface, but part of it is implemented on server side and part on client side. So, for example, if player wants to move forward his character he should send a request to object on server. The server then makes changes to simulation and sends updated position to client. For that reason, I've created small messages framework. There is a Message class, Router, Rule and rules inherited from Rule. When message arrives, Router checks it against the rules and sends it to destination. So, when I call myObjectInstanceOnClientSide->setPosition(x,y,z) this object creates Message, its content is function and parameters and destination is object with the same id on server. When object with the same id on server side gets this message it calls this function with given arguments. So, when a function can't be implemented on one side it creates a message and sends it to object on the other side. I think this can be very useful in scripts. Scripts can be very clean, if script needs for example turn on animation on clients, I only need to call this function on server's local object - the rest is in background.

So, is this ok? Am I wrong about this? It this common solution?

+6  A: 

It sounds like you would be 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 multiple messages to be dispatched together at a perioidic rate.

You may also want to read these other questions and answers:

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

I'd suggest starting to read Glenn Fiedler's blog. He's done some incredibly work with networked physics including the recent Mercenaries 2 release. He started a series of articles called Networking for Game Programmers.

Judge Maygarden
+1: Don't reinvent the wheel.
S.Lott
The choice between UDP and TCP is not as simple as "use UDP." Many successful online games (including World of Warcraft, which uses UDP only for voice chat) use TCP exclusively and get by fine. Choose the right solution for your game; don't default to UDP because ten year old action games used it.
Joe Ludwig
He already chose UDP whether he knows it or not (see HawkNL).
Judge Maygarden
Also, I've never played WoW, but it doesn't strike me as a platform that would requrie networked physics. All particle effects are probably done client-side with no need for synchronization.
Judge Maygarden