How to approach networked ogre game

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

How to approach networked ogre game

Post by Walta69 »

So I know this doesn't fully relate to ogre but here goes :). This is the first time I have attempted making a networked 3D game and I am just wondering if I am on the right track.

Basically I am using a TCP server to communicate with all game clients. The way I am thinking of running it is:

* When a player starts moving, notify server with direction (server then tells all other clients)

* When a player changes direction (via mouse) notify server with new direction

Client PCs then independently calculate the movement of other players via this information gained from the server. (There is a global movement speed for all units)

I can't think of a better way :/ any suggestions would be helpful :D :D :D
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: How to approach networked ogre game

Post by Klaim »

You have to separate the model of the game from the view of the game. The model is the data that represents what is happening inside the game. The view is the data that is used to generate graphics, audio and gather input.
As soon as you have these separated, you can put the model either in the server or in both server and client, or in peer to peer mesh. In any way, there should be one source of truth, and other "views" of that truth.

In any way, it is not related to Ogre. Ogre will do rendering, so the challenge for you will be to write code that will make Ogre render the right thing at the right time. Basically you need networking in place, decide if it's client/server or another kind of setup, and decide how much the clients will know about the game's state/model.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: How to approach networked ogre game

Post by Kojack »

TCP is generally not recommended for gaming.
TCP is a reliable protocol. If you send a packet, it will get through (assuming your connection isn't dead). That may sound like a good thing, but it's really not. In games, lots of data (like current positions of entities) overwrites previous data. TCP will try to send data that is ok to miss, causing everything else to be delayed.

UDP is only as reliable as your engine makes it be (you have to do it manually). But this means you can choose which kind of packets are reliable and which are ok to miss (because a later packet will provide the info).

Have a look at Raknet. It handles all that stuff (and much more) for you, and now that Oculus has bought out Raknet, it's free and open source.

The problem with client pcs calculating movement of other clients is that they may get out of sync. Different cpus can mean slight floating point variations (even if they are all supposed to follow the same ieee standard). You can do it for short periods of prediction (if you lose packets, then you make entities continue moving in the same speed and direction until you get a new packet), but it's better to have the server send absolute positions of everything at regular intervals so nothing can get out of sync for more than a second or so.

Have a look at Glenn Fiedler's series of articles on game networking. Very useful read. http://gafferongames.com/networking-for ... rogrammers
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

Re: How to approach networked ogre game

Post by Walta69 »

Thanks a lot for the info guys :) helped loads! will spend some time looking into those points :)
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: How to approach networked ogre game

Post by Crashy »

I'd suggest you to have a look at enet, this is what we've used in BOMB, and it is easy to use. It basically does "tcp over udp", meaning you can tell the lib to send reliable packets without using TCP protocol.
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: How to approach networked ogre game

Post by Klaim »

By the way Crashy, did you have to add a lot of layers for security?
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

Re: How to approach networked ogre game

Post by Walta69 »

Crashy wrote:I'd suggest you to have a look at enet, this is what we've used in BOMB, and it is easy to use. It basically does "tcp over udp", meaning you can tell the lib to send reliable packets without using TCP protocol.
It looks awesome! But excuse my ignorance, how do I get it to build for Visual Studio 2010? :/ I did look at the "tutorial" on its website but it is very unclear :P
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: How to approach networked ogre game

Post by amartin »

To handle input what you want to do is make the calculation on the client immediately when the user presses a button. You also send that information to the server. The server then does the calculation and then sends the result back to the client. The client should then adjust their result to match the server's result. This allows the input to appear fairly seemless to the user while allowing the server to correct for people making modifications to allow their program to do things it shouldn't.

If you are doing online multiplayer I would suggest that you also add some testing features to the message system. You want the ability to simulate a latency of 150-400ms and the ability to set the system to drop packets randomly and disconnect for short periods. It will make your life easier when trying to sort those sort of issues out when you can create them on demand. Design around loosing packets not even TCP can guarantee you that everything gets delivered.
Post Reply