Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Prediction?  (Read 5334 times)
0 Members and 1 Guest are viewing this topic.
Offline epicbo

Senior Newbie





« Posted 2012-02-04 12:11:01 »

Hi everyone, first post here.

Im working on a top-down multiplayer shooter game. Right now im working on the network code (using kryonet). This is my first multiplayer project so my networking knowledge is limited.

The first version of the networking code consisted of the server sending a packet containing information about the world every frame. I quickly realised that sending 60 big packets every second to every player is too much, so i set a limit on how often the server would send packets. Now, since the clients were no longer getting an update every frame, the game started to lag and stutter. I solved this by adding interpolation and now the problem is gone. Well, except that now I have input delay to deal with.

If I get it right, I understand that I must implement client side prediction. I don't know how to do it thought, and thats why I made this thread. It would be much appriceated if you could explain how I should implement prediction.  Smiley
Offline tom
« Reply #1 - Posted 2012-02-04 13:09:03 »

I did a little test application that does this a couple of weeks ago:
http://www.java-gaming.org/topics/client-side-prediction-and-delayed-interpolation/25446/view.html

Offline theagentd
« Reply #2 - Posted 2012-02-04 14:12:27 »

The best solution is to reduce the amount of data you send to the server each frame. Depending on how interactive your game world is (physics, dynamic objects) it might be enough for each player to simply send their current position and velocity and you simply extrapolate from those values. That's only 4 floats -> 16 bytes per frame -> about a kilobyte of data per second. EDIT: Okay, you would also need the direction the player is facing at and possibly other values, but it's still way below what most Internet connections can handle...

 - Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?

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

Senior Newbie





« Reply #3 - Posted 2012-02-04 15:17:38 »

I did a little test application that does this a couple of weeks ago:
http://www.java-gaming.org/topics/client-side-prediction-and-delayed-interpolation/25446/view.html

Thanks, ill check that out.

- Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?

Server/Client model. Currently using UDP, which I believe is the best choise for this project since I want to reduce latency as much as possible. But like I said, my experience is limited. If some thinks using TCP instead would be better, then I can change.

Offline theagentd
« Reply #4 - Posted 2012-02-04 16:43:12 »

Almost all action games use a peer-to-peer network model. This is to avoid the latency of having to communicate with a server which then broadcasts the changes. I believe this is your main problem...

Myomyomyo.
Offline lesto

Senior Newbie





« Reply #5 - Posted 2012-02-04 16:57:56 »

The best solution is to reduce the amount of data you send to the server each frame. Depending on how interactive your game world is (physics, dynamic objects) it might be enough for each player to simply send their current position and velocity and you simply extrapolate from those values. That's only 4 floats -> 16 bytes per frame -> about a kilobyte of data per second. EDIT: Okay, you would also need the direction the player is facing at and possibly other values, but it's still way below what most Internet connections can handle...

 - Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?

you aren't counting the TCP or UPD(and alla the ISO/OSI below) header!!! that will be very much more than your data!
Offline lesto

Senior Newbie





« Reply #6 - Posted 2012-02-04 16:59:58 »


- Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?

Server/Client model. Currently using UDP, which I believe is the best choise for this project since I want to reduce latency as much as possible. But like I said, my experience is limited. If some thinks using TCP instead would be better, then I can change.



if you paln to base the thiongs on interpolation, then TCPO is better because you cannot lose action ar apply them in the wrong order

Quote
Insert Quote
Almost all action games use a peer-to-peer network model. This is to avoid the latency of having to communicate with a server which then broadcasts the changes. I believe this is your main problem...

that's a nice input, thx
Offline theagentd
« Reply #7 - Posted 2012-02-04 17:36:30 »

- Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?
Server/Client model. Currently using UDP, which I believe is the best choise for this project since I want to reduce latency as much as possible. But like I said, my experience is limited. If some thinks using TCP instead would be better, then I can change.
if you paln to base the thiongs on interpolation, then TCPO is better because you cannot lose action ar apply them in the wrong order
... at the cost of throughput. For the lowest delay use UDP, a peer-to-peer model and send as little as possible. There's a reason all (yes, all) major shooters out there today use this.

Myomyomyo.
Offline epicbo

Senior Newbie





« Reply #8 - Posted 2012-02-04 17:42:50 »

... at the cost of throughput. For the lowest delay use UDP, a peer-to-peer model and send as little as possible. There's a reason all (yes, all) major shooters out there today use this.

I know I shouldn't really argue with you about this since my knowledge is low, but I'm pretty sure lots of major shooter games use the client/server model. I could be wrong though.

Either way, if you say I should use p2p, then I probably should. It going to be a pain to re-write all my network code though. :/
Offline theagentd
« Reply #9 - Posted 2012-02-04 18:14:54 »

Almost all action games either designates one of the peers as "server" (games with matchmaking) or has a dedicated "server" (most PC games). However these "servers" only keep track of the game score, maybe some basic game state, ban-lists, e.t.c. All clients are still connected to each other, and the data does not pass through the server as that would essentially double the latency. The server might also act like a tie-breaker, for example if two people shoot each other which in this example is impossible the server could decide who actually died and who survived (because you can't shoot when you're dead).

I'm no pro here,I've only done basic networking), but I do play lots of shooter games and I'm interested in the theory. xd

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

Senior Newbie





« Reply #10 - Posted 2012-02-04 20:42:56 »

All clients are still connected to each other, and the data does not pass through the server as that would essentially double the latency.

True for latency, but false the sentence. never had to open door on NAT to play TF2 or any other shooter game. MAYBE if your door are open the game will use it for doing p2p, but I think this is a secondary improvement, the real communication system relay on client/server architecture
Offline epicbo

Senior Newbie





« Reply #11 - Posted 2012-02-04 20:56:58 »

If by shooters you mean first person shooters, then Im pretty sure alot of them only use client/server. For example all games made with the Source Engine. Sorry if it seems like Im trying to disprove you or something. I've always thought most action games used client/server so when someone tells me the complete opposite I have the right to sceptical. Tongue

Edit:

Heres a link that I found interesting, it describes the networking that the source engine use:

https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
Offline theagentd
« Reply #12 - Posted 2012-02-04 21:44:50 »

 - The Source engine is pretty old.
 - It supports advanced physics (Havok). I said that peer-to-peer is better when you have very little data to transmit, and physics also needs to be synchronized between computers. Having a server and using determinism is kind of necessary in this case.
 - There's UPNP for opening ports in routers. There's also some tricks you can use to get through routers and NATs using a 3rd server host.

Still I may very well be wrong. >_>

Myomyomyo.
Offline lesto

Senior Newbie





« Reply #13 - Posted 2012-02-04 23:53:47 »

determinism help a lot, jbox2d's source can be modded to be deterministic, but this mod limit the power of float calculation, because it use an old standard.
also UPD+determinism is not a good idea, because if you lose an action or (in some case) apply action in wrong order you will break it. So you have to implement a sort of TCP over UDP... and it's hard to do.
so, if you want use determinism, you lose some CPU but you gain bandwidth (no need to sync all entity position sometime)

UPNP it's a pain. many router doesn't support it, and many times support it in a buggy way (take a look at some UPNP project to get an idea of what i'm talking about). I support the idea of p2p, with the server action only as "controller", but I think you should have a fall-back system that relay on server-client

Using a 3th part host is not a good solution: is just like use client-server architecture. Yes you can use the server as 3th host.

Actually i'm writing a game witch use deterministic jbox2d and TCP(nio package), hope you will soon test out how it work  Smiley
Offline theagentd
« Reply #14 - Posted 2012-02-05 00:00:59 »

Using a 3th part host is not a good solution: is just like use client-server architecture. Yes you can use the server as 3th host.
This is what I meant. The clients just connect to the server so that your router starts forwarding packets on the random port generated for outgoing connections. You can then disconnect that connection and use it to accept new connections.

Myomyomyo.
Offline lesto

Senior Newbie





« Reply #15 - Posted 2012-02-05 00:15:59 »

Using a 3th part host is not a good solution: is just like use client-server architecture. Yes you can use the server as 3th host.
This is what I meant. The clients just connect to the server so that your router starts forwarding packets on the random port generated for outgoing connections. You can then disconnect that connection and use it to accept new connections.

nice trick!
Offline msiggy

Senior Newbie





« Reply #16 - Posted 2012-03-14 02:57:42 »

We just finished networking and client side prediction in our game. Here is the set of articles we based our framework on.

http://www.gabrielgambetta.com/?p=11

http://www.gabrielgambetta.com/?p=22

http://www.gabrielgambetta.com/?p=63

If you have any questions with a particular part of the implementation feel free to ask. I just spent a month implementing this and could definitely help you out.
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.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!