Rollback Netcode?

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
Jaskills
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Sep 11, 2016 4:59 am
Contact:

Rollback Netcode?

Post by Jaskills »

I was playing with my EU friends being in NA West Coast and I noticed that driving/doing anything has a considerable amount of latency between me actually doing the action and getting a response. It's understandable that this exists, but I do also play fighting games and know that they implement a technology called rollback netcode.

Rollback Netcode is this neat little thing where your game feels responsive even if the ping is high, because the game processes your inputs clientside and responds without needing to wait for your peer's responses. If something your peer has done invalidates what you did, then the gamestate is rolled back and resimulated to reflect the new, correct gamestate.

I did a cursory search of "rollback netcode" in the forums and am mildly surprised to see nothing at all about it. It seems quite usable in Factorio even, given that the game is completely deterministic and player inputs generally aren't as complex or frequent as fighting games. I'd love to see it and be able to play cross-continent with my friends~

camela_camera
Burner Inserter
Burner Inserter
Posts: 16
Joined: Thu Jan 11, 2024 4:38 am
Contact:

Re: Rollback Netcode?

Post by camela_camera »

i've got a feeling that the devs aren't up for combining this plane of computation with their existing work

like, factorio is real limited by UPS

many things that are processed every tick, could be abstracted such that they don't need to be observed every tick and can be computed all at once based on how many ticks have passed. i believe factorio does this in specific cases in many ways, such as with belts [1].

it's possible to extend this generally to almost everything in this game, improving UPS in extreme non-linear fashion. it's been a while since i did maths, but i think they call the basic idea "finding a closed formula for a recurrence relation" sometimes. this technique is heavily used in game of life engines. i believe a similar thing applied in factorio would improve UPS by 10x to 10000x, particularly in megabases.

maybe i don't know what i'm talking about, but i think it's easy for fighter games to do rollback because they aren't UPS limited, and factorio would need to do at least some element of the approach i describe to for this to be effective. my hunch is that going all the way with this approach would be easier than trying to extend the existing piecemeal aspects of this approach to enough elements to make rollback effective.

[1] maybe they just batch item offsets so that they update an offset each tick for each section of belting, rather than each item. i am not knowing

Tertius
Filter Inserter
Filter Inserter
Posts: 677
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Rollback Netcode?

Post by Tertius »

Jaskills wrote:
Sat Feb 10, 2024 9:00 am
I did a cursory search of "rollback netcode" in the forums and am mildly surprised to see nothing at all about it. It seems quite usable in Factorio even, given that the game is completely deterministic and player inputs generally aren't as complex or frequent as fighting games.
The game concept you mention is used for games with a true client/server architecture. In such games, one server is computing the whole game state and broadcasting every action that has some visibility or interaction for players to the clients. The game client is just a display system for what the server sends it. Something like a browser. To enhance user experience, the game client has a tiny part of the game engine included, and this tiny part is computing what the reaction to some input would probably result visually, so it is able to display input reactions before the server is able to broadcast it.

However, Factorio isn't built like that. It's not a true client/server architecture. Instead, every client is running the full game engine and computing the full game state. The server is only the one machine that is authoritative for the game state, and from time to time every machine is computing a checksum across the game state and comparing that with the game state checksum of the server, so they know they are still in sync. If for some client the game state doesn't match, that client is known to be desynced and as result disconnected, because it isn't computing the same game state any more as everyone else.

To change this design to something else, for example to that client/server architecture I discussed before, is a completely different design and like rewriting half of the game code. This life roll back of the game state is simply not possible, because the game state changes as a whole, so you have to simply load a previous save to roll back. And that would be a very often used function. if you have 4 players, you will roll back the game state of 3 game clients on every client interaction, because the one client with some user interaction computes the next tick with the interaction, and the 3 other clients will compute it without the interaction, because they don't know of it yet. A few ticks later, they are notified of the interaction by the other player and need to roll back their game state to what it was perhaps 3 ticks before, then quickly recompute that 3 ticks with the interaction, and ... well, you see, this would simply be not feasible. Would create huge lags on every interaction.

This is feasible where the client only computes tiny parts of the game state to only simulate the user interaction. But not where every client computes the whole game state. Developers choose such a model at design time of the game engine. That was even before the first early access for Factorio. You cannot change that afterwards without complete redesign and complete rewrite.

pleegwat
Filter Inserter
Filter Inserter
Posts: 260
Joined: Fri May 19, 2017 7:31 pm
Contact:

Re: Rollback Netcode?

Post by pleegwat »

Factorio does use something like this; they call it latency hiding.

Illiander42
Filter Inserter
Filter Inserter
Posts: 414
Joined: Mon Feb 05, 2018 10:01 am
Contact:

Re: Rollback Netcode?

Post by Illiander42 »

pleegwat wrote:
Sat Feb 10, 2024 2:28 pm
Factorio does use something like this; they call it latency hiding.
And due to the way the engine works, you can't avoid lag when using it with anything that interacts with an inserter. It's really clean with the engineer unless you're F-ing a belt or swiping machines.

But vehicles interact with inserters, so they have issues using it.

I'm not sure if it would be better to apply it to vehicles when they're more than a few chunks from inserters, because the jerk when you enter non-hiding range would be pretty severe.

computeraddict
Fast Inserter
Fast Inserter
Posts: 111
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Rollback Netcode?

Post by computeraddict »

Illiander42 wrote:
Sat Feb 10, 2024 8:36 pm
But vehicles interact with inserters, so they have issues using it.

I'm not sure if it would be better to apply it to vehicles when they're more than a few chunks from inserters, because the jerk when you enter non-hiding range would be pretty severe.
You can actually notice that jerk on foot when you start trying to fight biters

EustaceCS
Inserter
Inserter
Posts: 42
Joined: Tue Dec 15, 2020 5:41 am
Contact:

Re: Rollback Netcode?

Post by EustaceCS »

Jaskills wrote:
Sat Feb 10, 2024 9:00 am
It's understandable that this exists, but I do also play fighting games and know that they implement a technology called rollback netcode.
Well, and Decentraland and some other building games implemented blockchain. But it doesn't mean that everything needs blockchain.

In fighting games, you care about very few things.
LIke player position, player's current animation, player's current input queue. All that - for each player.
Everything else can either be cheesed on round load or deduced from already available data. Simply because players don't interact with anything but each other.
"Rollback Netcode" doesn't do any significant voodoo - it just passes batches of that data regardless of it is needed and does client-side rollbacks to most appropriate state as necessary using that data surplus.
Also, as all involved players should receive all available information, we don't need to conceal anything...

About how many entities, entity states and input queues we care during multiplayer in Factorio? And about how many player states and interactions?
Not mentioning that one failed rollback - and the whole game becomes desynced...
(and teamed modes are a colossal problem)

Illiander42
Filter Inserter
Filter Inserter
Posts: 414
Joined: Mon Feb 05, 2018 10:01 am
Contact:

Re: Rollback Netcode?

Post by Illiander42 »

EustaceCS wrote:
Tue Feb 20, 2024 8:35 pm
But it doesn't mean that everything needs blockchain.
Anything that says is needs blockchain is a scam.

Post Reply

Return to “Ideas and Suggestions”