Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Syncronization problems, what do others do?

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Mar 2017 14:13
Hello I am making a multiplayer game. It is action, top down and the playfield is 1280x720 pixels single screen. I am having a problem with speed. I have an i5 3.4GHz (Machine 1), and my friend has an 1.8GHz single core crap CPU (machine 2). If I set the sync rate to 30 and limit the controller input or the keyboard input timer to 20 milliseconds, machine 1 is slightly faster (we do a run test where we run simultaneous from one end of the playfield to the other) and machine 1 gets a little bit ahead machine 2. If I set the sync rate to 60 and limit the controller input or keyboard input to 33 milliseconds, then machine 2 (the crap one) is noticeable faster than machine 1. Is it possible to get them to be almost precise to each others speed? How do others control the syncronization between clients in AGK2 Tier 1?
13/0
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Mar 2017 16:18
Normally, the players will send their inputs to the server, who will then send the new locations back to each client., thus ensuring that the same machine calculates new positions for all players. Solving the issue of one machine moving at a slightly different speed.
Signature removed by mod because it's larger than 600x120... please resize and try again.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Mar 2017 18:45
just 2 players, should be done with time based movement.
one step something like x=x+10.0*GetFrameTime ()
Timer()
AGK (Steam) V2017.02.28 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Mar 2017 20:12
There are usually at least the factors used together to keep things reasonably synchronized:

Time based movement (dont forget communications latency) distance = speed * time

Authoritative host/server: manages and communicates the 'official' position of each player

Client prediction: calculate expected positions locally, interpolate against official position, this smooths the client experience giving the impression of an immediate response, the better the prediction and lower the latency, the less jumping, snapping, and rubberbanding the player will experience.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Mar 2017 09:19
Quote: "just 2 players, should be done with time based movement."

But this isn't consistent between devices. When frame rates slow, the distance an object will move per frame will increase due to rounding and other factors, causing the OPs issue.

TBM is a good predictor for player locations, but the ONLY way to ensure that multiple players move the same across multiple networked devices is to have the server calculate all player locations. (Like any commercial game does)
Signature removed by mod because it's larger than 600x120... please resize and try again.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 16th Mar 2017 09:34
You can use tween commands to interpolate between current position and new position (sent by the server). Tweening is like automatic TBM and will move the player at the same speed regardless of framerate.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Mar 2017 09:52
a little bit different but not visible.
i made a example with 60 fps and then 30 fps over 5 seconds each.
AGK (Steam) V2017.02.28 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 16th Mar 2017 19:34 Edited at: 16th Mar 2017 19:43
Quote: "
But this isn't consistent between devices. When frame rates slow, the distance an object will move per frame will increase"


Right and it should, if player B frames take twice as long as player A frames, player B must move twice the distance of Player A each frame to keep up and bring them to the same final position over a given period of time.

Speed = 5 units per second
Player A 60 fps
Player B 30 fps
Elapsed time 2 seconds

Player A (2 * 5) / 60 = 0.066 units per frame = 10 units over 2 seconds

Player B (2 * 5) / 30 = 0.133 units per frame = 10 units over 2 seconds

Given the same start point, both players will reach the same end point over the same period of time even if they move different distances per step.

This can create visual jumping for player B if thier framerate is greatly lower which is unfortunate but is still a much better than the alternative which is to slow down player A to half his normal speed.

The visual jump for player B can be softened by tweening/interpolation putting them closer to where they should be and doing similar with player A predicted position instead of snapping them directly this is good for transitioning over a temporary lag spike, but can create the problem where something happens to a player that they dont feel should have based on where he thinks he is vs where other player /server/host etc thinks he is if it is a more constant low frame rate
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Mar 2017 08:46
Quote: "Player A (2 * 5) / 60 = 0.066 units per frame = 10 units over 2 seconds

Player B (2 * 5) / 30 = 0.133 units per frame = 10 units over 2 seconds"

But due to rounding, this isn't the exactly case. the slower framerate will actually end up moving faster than the higher framerate one and end up out of sync.
This was discussed many times in the old DBPro days. The theory is sound, but in practice it doesn't always end up the same way.
Signature removed by mod because it's larger than 600x120... please resize and try again.
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 17th Mar 2017 11:02

You can do the following :

Create a timer at the top of the graphics code of each client
& Get the timer difference at the end of the code right before sync of each client.

Then both clients compare their timer :


Do

If my_timer_difference < his_timer_difference

wait_penalty = (his_timer_difference - my_timer_difference) + timer ()

If wait_penalty <= timer() gosub frameend

Loop


frameend:

Sync()
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Mar 2017 11:03
Or the server can control all movement.
Signature removed by mod because it's larger than 600x120... please resize and try again.
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 17th Mar 2017 11:11
But before that has happened, his friend will have quit, because he's been coming in second too often.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 17th Mar 2017 13:10
They don't run with different sync rates, I just tried both 30 and 60 on both clients at the same time where sync rate would either be 30 on booth clients or 60 on both clients. I am learning C++ now so that I can move from Tier 1 to Tier 2 and then use some other networking libraries that handles small errors in the connection better and ideally have UDP packets as well. When I am done moving my project to Tier 2, I will implement server control of the movement speed.
13/0
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 17th Mar 2017 13:37 Edited at: 17th Mar 2017 13:39
This reminds me of moving up to higher stakes at poker because one can't beat the "bad" players at the low limits. Don't do it.
Practise the BASIC's until u master them. It takes a lot of effort, but it will be equally rewarding.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 17th Mar 2017 18:49 Edited at: 17th Mar 2017 18:49
Quote: "But due to rounding, this isn't the exactly case. the slower framerate will actually end up moving faster than the higher framerate one and end up out of sync.
This was discussed many times in the old DBPro days. The theory is sound, but in practice it doesn't always end up the same way."


Yes, I've agreed that you need a single authoritative host or server that manages the 'official' position and clients can correct against this, that doesn't change the fact that the player B client has to move things a greater distance each update than the player A client in order to keep them where they are supposed to be.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.

Login to post a reply

Server time is: 2024-11-24 18:47:29
Your offset time is: 2024-11-24 18:47:29