Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  How the structure of a multiplayer game should look like?  (Read 2039 times)
0 Members and 1 Guest are viewing this topic.
Offline israelg99

Junior Devvie





« Posted 2014-05-15 11:44:27 »

Hello, i am creating a 2D fighting game, (3vs3) (4vs4)...

I learned KryoNet, and tested it out, i know the concept pretty well.
Now my question is how the structure of a multiplayer game like i do should look like?

I think of a structure like this -
The client will send packets when he input something. (like when the client clicks W, A, S or D it will send packet depends on what the client has pressed).
The server will send the game data, (position of every player, what side the every player is looking and the input of every player).

The client will only render the game with the data the server sends.

---------------------------------------------------------------------------

Its a good idea?
And how often the server should send the game data?

P.S - Because the server sends every player's input, the client can easily predict and interpolate every player's actions till the server sends the next game data packet, so the game doesn't lag.

I hope you understand what i am talking about.. lol well actually what am i thinking?! i read some genius articles in this forum, you should understand it very well Wink
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #1 - Posted 2014-05-15 14:01:28 »

Quote
P.S - Because the server sends every player's input, the client can easily predict till the server sends the next game data packet, so the game doesn't lag.
What did you think of there? Cheesy if you think the game data packet might cause lag in the game what makes you think sending every player's input to the clients would stop the game from lagging?

Quote
And how often the server should send the game data?
well i do it in 50 ms steps, every 50 ms it sends the game data to each client (makes 20 times per second)

Quote
The client will only render the game with the data the server sends.
that's the thing which makes the client look like it's lagging, client should interpolate the data it got from the server to get a more precise data, which might be a bit misscalculated but it will still be better than just rendering the data from the server Smiley
Offline Oskuro

JGO Knight


Medals: 40
Exp: 6 years


Coding in Style


« Reply #2 - Posted 2014-05-15 14:24:09 »

I'm talking out of my ass, but don't some games use a form of "prediction" on the client side? For example, if a remote player is walking, and it hits a wall, the client will draw the player stopping at the wall (guess more complex approaches could use bot ai to attempt and predict remote player reaction).

What you do see quite often (it can be hilarious in, for example, BF1942) is the client predicting remote player position, but making no updates to their status/attributes (health for example), so you will clearly see, for example, a plane crash into the ground and bounce back up intact, only for the server update to reveal the remote player actually avoided crashing.... Or not.

From that point of view, rather than sending the actual player input, the server should send the player's avatar "intentions" (it is walking, it took damage, etc...).

Again, just speculating.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Gibbo3771
« Reply #3 - Posted 2014-05-15 14:39:15 »

I'm talking out of my ass, but don't some games use a form of "prediction" on the client side? For example, if a remote player is walking, and it hits a wall, the client will draw the player stopping at the wall (guess more complex approaches could use bot ai to attempt and predict remote player reaction).

What you do see quite often (it can be hilarious in, for example, BF1942) is the client predicting remote player position, but making no updates to their status/attributes (health for example), so you will clearly see, for example, a plane crash into the ground and bounce back up intact, only for the server update to reveal the remote player actually avoided crashing.... Or not.

From that point of view, rather than sending the actual player input, the server should send the player's avatar "intentions" (it is walking, it took damage, etc...).

Again, just speculating.

Yes you are right, however this is for complex games that's send a lot of data.

For instance if the player is in a moving forward state, the game tells the server right he is moving forward, do the server goes "let's just tell the client to take it from here until he does something different".

Obviously this is a simple example.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Cero
« Reply #4 - Posted 2014-05-15 14:43:39 »

wow 2D fighting games online huh

those need to have the fastest connection of any games by definition, since people wanna do frame perfect combos and everything

might be hard if youre not excellent in network programming and have a reliable server

Offline israelg99

Junior Devvie





« Reply #5 - Posted 2014-05-15 17:48:45 »

Quote
P.S - Because the server sends every player's input, the client can easily predict till the server sends the next game data packet, so the game doesn't lag.
What did you think of there? Cheesy if you think the game data packet might cause lag in the game what makes you think sending every player's input to the clients would stop the game from lagging?

Its simple, if the server will send every player's input, the client will easily interpolate every player's action. For example, if the client will see that one player pressing D, it will predict that this player is going to the right, and will make him walking to the right until the next game data packet.

I hope its clear. if not, ask me.

Quote
And how often the server should send the game data?
well i do it in 50 ms steps, every 50 ms it sends the game data to each client (makes 20 times per second)

I will make it in 50 ms steps too, it looks like a good number, thanks!

Quote
The client will only render the game with the data the server sends.
that's the thing which makes the client look like it's lagging, client should interpolate the data it got from the server to get a more precise data, which might be a bit misscalculated but it will still be better than just rendering the data from the server Smiley

You just said here exactly what i meant when i said the server will send every player's input, because the client will easily predict and interpolate every player's action because it will know their input, for example if one player pressed A, it will predict he is walking to the left, and the client will render him walking to the left until it gets another game data packet from the server.

I hope its clear now, if not, as i said ask me.

EDIT : Changed the text color from red to black, especially for gibbo
Offline Gibbo3771
« Reply #6 - Posted 2014-05-15 17:57:01 »

My eyes!

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline israelg99

Junior Devvie





« Reply #7 - Posted 2014-05-15 18:01:19 »

wow 2D fighting games online huh

those need to have the fastest connection of any games by definition, since people wanna do frame perfect combos and everything

might be hard if youre not excellent in network programming and have a reliable server

That's why i do it, i want to be excellent in network programming Wink
If you want to help, you can tell how the structure of a multiplayer game like this should look like, or perhaps look at the structure that i wrote and tell if its good.
Offline israelg99

Junior Devvie





« Reply #8 - Posted 2014-05-15 18:04:02 »

My eyes!

Are you ok man? you have sensitivity to red text or something? cause if you do, u should definitely tell us.. you know.. it affects us.

And by the way, if you really want to be nice, get over your sensitivity and perhaps comment on the multiplayer structure and tell me if its good and where can i improve it?

Thanks Wink

EDIT - i can change the text color, if it really bothers you.
Offline 65K
« Reply #9 - Posted 2014-05-15 18:36:51 »

Its simple, if the server will send every player's input, the client will easily interpolate every player's action.
In an ideal world with zero latency it might be simple, but if your game is supposed to run on the internet and is 2D as Cero remarked and you need to take multiple latency values into account and need to prevent ugly position snapping, then it is very ambigous.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline saucymeatman
« Reply #10 - Posted 2014-05-15 19:24:23 »

And by the way, if you really want to be nice, get over your sensitivity and perhaps comment on my multiplayer structure and tell me if its good and where can i improve it?
Cranky

Also, I just wanted to point out there are alot of great topics exactly like this one of which to draw conclusions about your network structure. Probably a lot of great tutorials online also.
Offline israelg99

Junior Devvie





« Reply #11 - Posted 2014-05-15 20:10:08 »

Its simple, if the server will send every player's input, the client will easily interpolate every player's action.
In an ideal world with zero latency it might be simple, but if your game is supposed to run on the internet and is 2D as Cero remarked and you need to take multiple latency values into account and need to prevent ugly position snapping, then it is very ambigous.
I think you didn't get my idea..

Here are the steps -
1. The server is sending the game data packet.
2. The client renders the world with the game data packet that the server sent, additionally, the client uses that data to predict / interpolate the game.
For example, the client knows that Player A pressed (or still pressing) the D key, the client will render Player A walking right until the client will get another game data packet to update the current game.

Of course if the client has serious latency issues, the players will be teleporting a bit. But what can you do?

I hope you understand it now, if not. please let me know.
Offline delt0r

JGO Knight


Medals: 29
Exp: 18 years


Computers can do that?


« Reply #12 - Posted 2014-05-16 07:12:25 »

No amount of networking magic will eliminate latency. For a signal traveling at the speed of light to get to where i am to NZ and back (say playing against my brother) takes 133ms. Actual pings are about 320-350ms.

The trick is have game play that is not sensitive to that sort of latency (see for example Eve online) or make sure people are much more local to each other. But even with the same ISP it is hard to do better than about 40-50ms because of network setup most ISPs use.

For most games that is not a problem and our primitive monkey brains adapt pretty well. But that sort of latency would make games like Marvel Super Heroes almost unplayable. At 60FPS  you have 16.6ms between frames. Basically i can't see such a game working outside a lan.

Of course you could change the networking to be higher level. ie packets say what combo you just did. Not individual movements or key presses. You could change the game play to be a little slower placed.

I would tend to use a peer to peer lock step networking model for a game like this. But with only loose lockstep. ie let slower clients fall behind the faster ones.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline israelg99

Junior Devvie





« Reply #13 - Posted 2014-05-16 11:12:56 »

No amount of networking magic will eliminate latency. For a signal traveling at the speed of light to get to where i am to NZ and back (say playing against my brother) takes 133ms. Actual pings are about 320-350ms.

The trick is have game play that is not sensitive to that sort of latency (see for example Eve online) or make sure people are much more local to each other. But even with the same ISP it is hard to do better than about 40-50ms because of network setup most ISPs use.

For most games that is not a problem and our primitive monkey brains adapt pretty well. But that sort of latency would make games like Marvel Super Heroes almost unplayable. At 60FPS  you have 16.6ms between frames. Basically i can't see such a game working outside a lan.

Of course you could change the networking to be higher level. ie packets say what combo you just did. Not individual movements or key presses. You could change the game play to be a little slower placed.

I would tend to use a peer to peer lock step networking model for a game like this. But with only loose lockstep. ie let slower clients fall behind the faster ones.

The client predicts every player's actions, until it gets the next game data packet from the server. so the game will look smooth even with 120ms ping, honestly i even think the game will be nice at 160ms ping either.. but above that the game will start lagging.
But lets say the game will have separate server for Europe for European players, so european players will have ping mostly between 60 - 200ms ping, which means the game will be smooth for them, right?

The game won't just pause until the client will get the next game data packet, the game will predict what the players are doing ( please read what i said in the comments ).

Thanks Wink

Offline Gibbo3771
« Reply #14 - Posted 2014-05-16 11:27:11 »

My eyes!

Are you ok man? you have sensitivity to red text or something? cause if you do, u should definitely tell us.. you know.. it affects us.

And by the way, if you really want to be nice, get over your sensitivity and perhaps comment on my multiplayer structure and tell me if its good and where can i improve it?

Thanks Wink

EDIT - i can change the text color, if it really bothers you.

Just don't see the point in putting a bright red font on a bright white background. Some peoples eyes are not perfect, trying to read shit like that ain't helping them.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline israelg99

Junior Devvie





« Reply #15 - Posted 2014-05-16 13:51:52 »

My eyes!

Are you ok man? you have sensitivity to red text or something? cause if you do, u should definitely tell us.. you know.. it affects us.

And by the way, if you really want to be nice, get over your sensitivity and perhaps comment on my multiplayer structure and tell me if its good and where can i improve it?

Thanks Wink

EDIT - i can change the text color, if it really bothers you.

Just don't see the point in putting a bright red font on a bright white background. Some peoples eyes are not perfect, trying to read shit like that ain't helping them.

Changed the text color for you  Wink
lol don't call this shit shit.
Offline JESTERRRRRR

Senior Devvie


Medals: 7
Exp: 1 year



« Reply #16 - Posted 2014-05-23 04:19:31 »

Ok so you have 2 players, A and B. Both have 200ping. Player A kicks player B, at exactly the same time player B kicks player A. Each kick is enough to kill the other player.

With 200 ping, player A see's  on his own PC himself kick and kill the enemy (player B), and does not receive the player B kick untill player B is already dead. Dead players cannot kick.

Player B see's EXACTLY the same thing. They both think they won. How does your system deal with this?
Offline Rayvolution

« JGO Spiffy Duke »


Medals: 222
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #17 - Posted 2014-05-23 04:47:30 »

Ok so you have 2 players, A and B. Both have 200ping. Player A kicks player B, at exactly the same time player B kicks player A. Each kick is enough to kill the other player.

With 200 ping, player A see's  on his own PC himself kick and kill the enemy (player B), and does not receive the player B kick untill player B is already dead. Dead players cannot kick.

Player B see's EXACTLY the same thing. They both think they won. How does your system deal with this?

What the player actually sees it irrelevant, whoever sent the signal to kick first wins, even if the difference is in the nanoseconds. All the player sees is what the server tells him is there, regardless of the actual situation.

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline Oskuro

JGO Knight


Medals: 40
Exp: 6 years


Coding in Style


« Reply #18 - Posted 2014-05-23 09:45:14 »

They both think they won. How does your system deal with this?

Another BF1942 example (yes, I love that game), I was dueling a friend of mine on the Desert Combat mod, both piloting modern jets. At a point I had him in my sights, fired a missile, and even though he attempted to evade, the missile hit his plane right in the middle.... And nothing happened.

He then shot me down, of course.

What happened there was that, even though in my client the missile hit, in the server it missed by a few milliseconds (or manybe even nano).

So my client showed the missile explosion, but since it didn't get confirmation that the other plane had exploded, it didn't show it (This may be due to it being possibly more efficient to have individual clients compute the visual effects of projectiles, rather than wait for server updates).

Funny thing? This happened over a LAN. So yes, even in very small latency scenarios you will get this.

Funnier thing? My friend's client was acting as the server, so he had a very noticeable advantage over everyone else. From that day forward, even on LAN games, we'd set up a dedicated server to host games.


As has been mentioned, the way to solve latency issues falls more on game mechanics than actual network implementation. Think how the gameplay can be modified to diminish the impact of high latency (even with good overall latency you can get lag spikes that screw things up).

For combat games I guess a technique would be to move away from one-hit-kill type scenarios, and rely on say long combos, or high health, so players have a chance to react to an incoming attack despite lag.

Offline JESTERRRRRR

Senior Devvie


Medals: 7
Exp: 1 year



« Reply #19 - Posted 2014-05-24 05:09:13 »

Ok just a quick point; I was trying to get him to think about what else he will need in his system to deal with common issues like this.

Quote
All the player sees is what the server tells him is there, regardless of the actual situation.
When you are showing what you have done immediatly on the screen so as to hide lag for your client (unlike the original doom type setup) the player will often see what has not happened. The number of times I have shot someone on css only to find in the demo I never fired at all. The anger. Many server setups have to rewind the game state to see if the player was aiming at someone, and you end up dying even though you're now round a corner.
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.

Gibbo3771 (12 views)
2014-11-24 19:59:16

trollwarrior1 (35 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!