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~
Rollback Netcode?
Moderator: ickputzdirwech
-
- Burner Inserter
- Posts: 16
- Joined: Thu Jan 11, 2024 4:38 am
- Contact:
Re: Rollback Netcode?
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
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
Re: Rollback Netcode?
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.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.
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.
Re: Rollback Netcode?
Factorio does use something like this; they call it latency hiding.
-
- Filter Inserter
- Posts: 521
- Joined: Mon Feb 05, 2018 10:01 am
- Contact:
Re: Rollback Netcode?
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.
-
- Fast Inserter
- Posts: 211
- Joined: Sat Oct 07, 2023 6:44 am
- Contact:
Re: Rollback Netcode?
You can actually notice that jerk on foot when you start trying to fight bitersIlliander42 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.
Re: 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)
-
- Filter Inserter
- Posts: 521
- Joined: Mon Feb 05, 2018 10:01 am
- Contact: