GPWiki.org
GPWiki.org
It is currently Thu May 23, 2013 12:20 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Networking like a boss
PostPosted: Thu Feb 02, 2012 4:35 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1551
Location: burrowed
I'm currently trying to implement networking (thanks jimbo for mentioning lidgren :) ). I'm a hell of a lot confused with the whole process.
I understand the basic concepts, like sending delta positions from the client to the server, which distributes it to every other client.
In fact you wouldn't even want to send positions as these might be compromised, but i will not care about this for now.

I am trying to implement it into my engine and ran into multiple obstacles.

Quick rundown of how my engine is structured wrote:
Game class - most underlying object, initializes opengl, the window, manages timing and calling the respective methods in the scene
Scene class - only one Scene can be attached to the Game class at a time, it provides Load() Update() Render() and such
GameObject class - the Scene can hold an arbitrary amount of GameObjects. The GameObjects can have an arbitrary amount of GameObjects


1. If i have a dedicated host running, i generally don't want any rendering to happen. Finding all references to OpenGL, rendering or anything in that respect and adding
Code:
if(DedicatedServer)
seems a bit unconventional to say the least. So what i think makes most sense in my case is creating a seperate Game class (GameServer) that only provides timing and Load() and Update() to the attached Scene, so the rendering doesn't happen. There's still calls to GL though when initializing VBO's in Load(), or changing uniforms in Update() for instance. This seems like a major set back to use this method in the current state.

2. If i have a listen server running, i simply have one player acting as a host, redirecting the position (etc) to other players. I don't see the downsides of this, except not having a dedicated server running instead of locally hosting.

3. Having a server that simply receives data, and redirects it, without simulation and processing. This probably is the least favorable to use. I would guess you will end up with out of sync gameplay pretty quick, depending on the packages being lost or discarded, difference in framerate and updates.

I will for now stick to 2. and will try to get basic server client communication going by the end of the week, walking, shooting, dying etc.

What is your take on this? How did you model your networking, or what am i possibly missing here?

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Thu Feb 02, 2012 9:42 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Quote:
What is your take on this? How did you model your networking, or what am i possibly missing here?


What you're describing sounds like a peer-to-peer setup. Tankz uses a Client/Server model. That is; the Client and Server are two completely seperate executables. The server is a dedicated server, and therefore does all the position/event distribution, hit detection, AI processing, etc. It doesnt load any graphics or anything like that. All the clients do is receive data from the server and interpret it.. display tanks, explosions, etc.

In your case, I wouldn't do if (DedicatedServer) .. partially because it's not a dedicated server, but something more like:

Code:

GameLoop()
{
switch Network Job

case Host:

//host gamelogic here... render all your stuff, generate/receive/distribute packets, etc.

case Client:

// Client gamelogic.. render stuff, receive packets from server, send packets to server, etc.

}


Quote:
3. Having a server that simply receives data, and redirects it, without simulation and processing. This probably is the least favorable to use. I would guess you will end up with out of sync gameplay pretty quick, depending on the packages being lost or discarded, difference in framerate and updates.


It wouldn't go out of sync in a UDP protocol because since position updates are being sent MANY times per second, even if you lose a packet or two here and there it doesn't matter because there's already a newer(and therefore more relevant) packet on it's way. The only way to be out of sync would be with some obscenely high ping times/improper implementation of Prediction.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
PostPosted: Thu Feb 02, 2012 10:32 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1551
Location: burrowed
What you described, seperating client and and host code, is something that seems kinda counterproductive to me, since both the server and the client has basically the same happening, only the source if the input is either through the servers redirection or the input directly. I'm still thinking how i could tackle this without rewriting a bunch of code for the same use, or switching cases in every other class.

The second point i described isn't meant to be peer to peer though. One player hosts the listening server and has the authority over all data. Collision, physics etc happening on the host is both server and client data. I think this is how listen servers were done before in games if you remember the zero-ping for hosts in halflife and quake for instance.


I found this article which seems like a pretty decent rundown on the whole issue. It gave me a lot of insight on the topic.
http://trac.bookofhook.com/bookofhook/t ... rogramming

I will get my laptop to test tomorrow so i can finally create a test case and work from there on.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group