Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreliable inputs with redundancy #221

Merged

Conversation

albertok
Copy link
Contributor

@albertok albertok commented Apr 29, 2024

Switches input rpcs to be unreliable but with redundancy.

The idea is we don't want a single lost or out of order packet to jam up the flow of our game. Something that becomes increasingly likely the more players you have or the faster you dial up the tick rate.

This simple change dramatically improved response times in my test games and stopped states of 'rollback choking' as Enet tries to recover from a packet discrepancy.

The other benefit is now UDP packets race to provide the next tick info at the cost of slightly more data.

Tested with upto 20% packet loss and game remained stable. At higher packet loss rates Enet kills the connection.

Relevant discussion: #194

How Enet works when set to reliable

Happy to change this to a switch if prefered. Let me know what you think :)

@elementbound
Copy link
Contributor

Thanks @albertok, both for looking into it and providing this PR! This looks promising, I'll do some testing on my end too.

Copy link
Contributor

@elementbound elementbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some initial thoughts.

I'd classify this PR on the same level as a new feature ( which it kind of is, even though the API doesn't change much ), could you please bump the addon version to 1.6.0? You can run sh/version.sh bump minor, depending on your platform.

addons/netfox/rollback/network-rollback.gd Outdated Show resolved Hide resolved
addons/netfox/rollback/network-rollback.gd Outdated Show resolved Hide resolved
docs/netfox/guides/network-rollback.md Outdated Show resolved Hide resolved
@elementbound
Copy link
Contributor

Tested locally as well - although it didn't disconnect ( somehow ) at 20% packet loss. The improvement is massive! It went from barely playable to playable with some slight jitters! Which is pretty good at a 200ms roundtrip with 20% packet loss.

This is the command I've used:

sudo tc qdisc change dev lo root netem delay 100ms loss random 20

addons/netfox/rollback/rollback-synchronizer.gd Outdated Show resolved Hide resolved
the current tick. We send data unreliably over UDP for speed. In the event a packet is
lost or arrives out of order we add some redundancy. You can calculate your target
reliability % packet success chance by using the formula
`1 - (1 - packet_success_rate) ^ input_redundancy`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch with the formula!

@albertok
Copy link
Contributor Author

albertok commented May 7, 2024

Good catch on the unnecessary resimulations!

Tested locally as well - although it didn't disconnect ( somehow ) at 20% packet loss. The improvement is massive! It went from barely playable to playable with some slight jitters! Which is pretty good at a 200ms roundtrip with 20% packet loss.

This is the command I've used:

sudo tc qdisc change dev lo root netem delay 100ms loss random 20

I had been using

sudo tc qdisc add dev lo root netem loss 20%

which is a static 20% loss, random 20 I believe does 'random loss upto 20%'

var old_input = _inputs.get(t, {}).get(property)
var new_input = sanitized[property][i]

if old_input == null:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a tiny window for cheating if we allow re-writing of what's previously been received with

if old_input != new_input:

so changed it to only allow backfilling missing inputs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@albertok albertok requested a review from elementbound May 9, 2024 00:07
Copy link
Contributor

@elementbound elementbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks a lot @albertok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants