Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Server game loop and syncronization questions  (Read 4995 times)
0 Members and 1 Guest are viewing this topic.
Offline Lucasmontec

Senior Newbie


Medals: 1



« Posted 2013-11-12 15:54:29 »

Hello! I'm studying how to make multiplayer games and I came across something I don't understand how to do correctly: The game loop on the server side.
I'm thinking about a space top down shooter now, just to limit the scope. In my case, it is a kryonet application with LIBGDX. What I have planned for the multiplayer follows:
Client sends spawn message TCP.
Server handles the message, spawning the client ship.
Server responds the message with a snapshot TCP.

--> if there are more than two players
Server sends a start game message TCP (for UI) and starts the game (spawning of aliens).
During game:
Client streams player input through UDP.
Server process the input simulating all players.
Server sends snapshots TCP/UDP? to players each server tick.

--> if game over condition is met
Server sends end game message TCP.

I have several questions though....
Q1 - How will the server run by it self? I though of making a separate thread that calls the methods for sending stuff to the client (the snapshots).
Q2 - How much time a server tick should have? Wouldn't this depend on the clients game loop delay?
Q3 - I currently sync the spawning of bullets to the ship firing animation... is that going to be a problem since the rendering is client side?
Q4 - Valve's article says in source that object positions are processed both locally and server side, with interpolation to always use the server over the client. Can that be
applied to shooting?
Q5 - Should the player send a input message each game loop tick? Or should I sample the input with time intervals?
Q6 - Should the server snapshots be sent over UDP or TCP?
Q7 - What calls the server update loop? Won't the server simulation run without sync with the client?

Thanks so much for taking your time to read all this!
If there is any good article about this, or a example game, even books, send me the names! =)
Offline jmguillemette
« Reply #1 - Posted 2013-11-12 16:42:53 »

My suggestions below..


Q1 - How will the server run by it self? I though of making a separate thread that calls the methods for sending stuff to the client (the snapshots).

The server should be written in a manner that it can run entirely in a seperate thread or JVM than the client.
Its game loop is all about calculating updates and publishing data to the clients that will keep the client in sync.


Q2 - How much time a server tick should have? Wouldn't this depend on the clients game loop delay?

The servers game loop should not be driven by the client but rather based on real world lapsed time.



Q3 - I currently sync the spawning of bullets to the ship firing animation... is that going to be a problem since the rendering is client side?

I would need more details to be this specific. Consider telling the server your firing and having the server tell the client back look theirs bullets here. When they bullet event from the server first arrives.. your ship fires.


Q4 - Valve's article says in source that object positions are processed both locally and server side, with interpolation to always use the server over the client. Can that be
applied to shooting?

yes. But the server deciding a hit has occured should always win over
any local calculation.


Q5 - Should the player send a input message each game loop tick? Or should I sample the input with time intervals?


The player should only send data to the server when it needs to push new information to it. No need to send needless network traffic.
Dending on how your doing your client data updates the client may poll the server for updates or the server will push updates to the client.. there are pros and cons to both approaches.

Q6 - Should the server snapshots be sent over UDP or TCP?
if you want the server to be able to reside outside the users local network then TCP. UDP is great for service discovery on a local network.

Q7 - What calls the server update loop? Won't the server simulation run without sync with the client?
see response to Q2

-=Like a post.. give the author a medal!=-
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #2 - Posted 2013-11-12 17:21:38 »

Many thanks!!

Let me see if I got it:
The server will have its own thread, that run endlesly.
The server will then have its own FPS.
The player should send messages like "mouseButton1Down" "mouseButton1Up" and only when the state changes.
All messaging will be TCP.

If that is good then I'm a happy dev and you deserve TONs of good coffe, with cookies.

The server snapshots have a timestamp?
The thing that stills bother me is that the server have its own fps...
imagine that the client is running at a framerate of 60, and the ship travels 100 pixels,
then the server sends an update, but there the fps is 200 and the ship travelled 350.2 pixels...
(I compute the position using RK4 integrations but still... this sync thing is hard to grasp)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #3 - Posted 2013-11-12 17:34:39 »

Something like this?

Offline jmguillemette
« Reply #4 - Posted 2013-11-12 17:37:01 »

I think your relating the client game loop too closely to the server one.

lets try a different approach to explain what i would recommend.

The game client is responsible for drawing and interacting with the user.

the game server is responsible for managing game assets that need to be kept in sync across game clients.

When we talk about the server's game loop.. loop may not be the best term.
I personally use a scheduled thread that runs every 0.x seconds (.3 for my current game)

Example from my current game:

The server starts..
A scheduled thread is created that runs every .3 seconds.
When this thread executes it will :
-run a routine to update any calculated modifications to the models its managing.

outside this loop the server provides the following operations that can be invoked by clients

getCoordsList(); - return a list of game coords for the assets being managed by the server

getModelData(id) - as my game is 3d if a model is in the coords list but the client doesnt have a local copy of this model it can ask for the data needed to make it.

addModelData(ModelData) - the client add a new model to the server to manage from this point forward. Other clients will find out about via the combination of the two other methods. (getCoordsList and getModelData)

Note: Nothing on the server is ever related to FPS.

The server threading is based on real world time.

So if your client is slow.. and another is fast.. the objects managed by the server dont react differently.


hope this helps Smiley





-=Like a post.. give the author a medal!=-
Offline jmguillemette
« Reply #5 - Posted 2013-11-12 17:44:55 »

in your diagram.. when a user presses a button.. dont make the server interpret what to do.. thats the clients apps job. But do tell the server about what it needs to track.

so if LeftClick = fire gun.. then yes there is likely a call to the server to fire weapon.. but the server should have no idea this was caused because the user left clicked. Smiley


-=Like a post.. give the author a medal!=-
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #6 - Posted 2013-11-12 19:58:00 »

I see now!  Grin
So in your game the client pull server updates... I think I'm going for the server pushing snapshots.
I also understood that the messages of input should be "fireShip" instead of "mouseButton1".
nice.

I'll try to sync a throw-away prototype that I have...
Offline jmguillemette
« Reply #7 - Posted 2013-11-12 20:25:09 »

an alternative that matches what you want is each time the server runs its update thread it ends with broadcasting out to all clients the updated data.

If the message is lost in the network so be it.. youll get it next update. Smiley

this work perfectly fine.

one tip in this approach.. bake a timestamp in the packet before sending it to clients.
the client will only accept new data that is newer than previously processed.

Otherwise you WILL get a situation where the sever sends packets A B C
and your client will receive them as A C B and youll get a stutter effect in your game.

-=Like a post.. give the author a medal!=-
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #8 - Posted 2013-11-13 00:06:07 »

ORGASM.
<a href="http://www.youtube.com/v/oZai73uc4g8?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/oZai73uc4g8?version=3&amp;hl=en_US&amp;start=</a>

Success! Now I can proceed to implement a framework XD.
Online opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2013-11-13 00:54:53 »

Huh... That's an interesting game idea Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kyperbelt

Junior Member


Medals: 1



« Reply #10 - Posted 2013-11-13 04:02:09 »

ORGASM.
<a href="http://www.youtube.com/v/oZai73uc4g8?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/oZai73uc4g8?version=3&amp;hl=en_US&amp;start=</a>

Success! Now I can proceed to implement a framework XD.

lol looks like your multiple cock textures need some good ol alpha blending
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #11 - Posted 2013-11-13 04:06:29 »

My 'artist' friend doesn't know the meaning of .png
Online opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2013-11-13 04:07:26 »

Well, your artist has obviously never done anything with computer graphics before then.

Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #13 - Posted 2013-11-13 04:56:45 »

Yeah, that or he just want to stick with paint tool sai forever, and will never touch photoshop =P

Well, thanks for the help. I'll code a framework for this kind of sync and if everything goes ok, I'll post and teach about it XD
Offline jmguillemette
« Reply #14 - Posted 2013-11-13 15:56:03 »

unfortunately im at work and thus cant see your video/image right now.. but gratz on getting it working!

j.

-=Like a post.. give the author a medal!=-
Offline Lucasmontec

Senior Newbie


Medals: 1



« Reply #15 - Posted 2013-11-15 22:36:53 »

I'm back here just to say thanks again. Seeing this working is a total dream of mine.
Multiplayer means much to me..
I've added the rest of the game to the server now and it is just amazing seeing that I've coded
that and it is not crashing nor flickering nor nothing actually. Is just amazing.
I'll study now how to generalize this architecture a bit and try to provide either a tutorial or
library (on top of kryonet) to make that super easy for people starting into games. Just like the libs I'm using
made that easy for me.
Something like 'extends LiveEntity' with a few '@ID and @Sync' annotations, a 'client.processLastSnapshot()'....
<a href="http://www.youtube.com/v/pA_sJwbLeoA?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/pA_sJwbLeoA?version=3&amp;hl=en_US&amp;start=</a>
Offline Kyperbelt

Junior Member


Medals: 1



« Reply #16 - Posted 2013-11-18 09:00:43 »

Lol you should make it so that they are shooting something more appropriate ..... like unfertilized eggs and instead of having them blow up they turn into a fetus and fly away lol
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52

SHC (70 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!