ZDoom / gzdoom

GZDoom is a feature centric port for all Doom engine games, based on ZDoom, adding an OpenGL renderer and powerful scripting capabilities
http://zdoom.org
GNU General Public License v3.0
2.33k stars 528 forks source link

Reworked client network state handling #2542

Closed Boondorl closed 1 week ago

Boondorl commented 2 months ago

Currently working with client-side prediction is a bit too limiting due to the nature of only having the info that the client is predicting and nothing else. Not only this, but handling the prediction state via cheats is volatile as it allows players to unset it (likely unintentionally) while predicting which will break the game state immediately.

Prediction is now locked behind ClientState which is readonly. This will be used for getting a client's network status (both the consoleplayer and others) and currently supports CS_PREDICTING, CS_LATEST_TICK, and CS_RUBBERBANDING. CS_LATEST_TICK is of particular interest because it can allow effects and sounds to be executed on the player's last "real" tick rather than constantly being repredicted. This allows for things like sounds on landing to be played at the last predicted tick without rapid firing when being played back.

ClientTic has also been added which can be compared against gametic to see how far ahead the player is currently predicting on a given tick. Note that gametic becomes one tick ahead when predicting since its value is incremented after all game logic but before prediction starts.

These fields should mainly be used for client-side prediction as they won't give the same values across clients (similar to consoleplayer), but things like CS_LATEST_TICK and ClientTic are still set for all clients so logic can execute correctly on their end. For instance, a non-consoleplayer client will only update on a real tick, but their flag will always be set to CS_LATEST_TICK so a landing sound would still play at the correct time if checking against it.

inkoalawetrust commented 1 month ago

So CF_PREDICTING is just a total dud now? Isn't that bad for compatibility with mods that might rely on the old client prediction handling, like mods that are no longer in development to be changed to use IsPredicting() instead? Might be a good idea to have CF_PREDICTING still be set and unset somewhere for backwards compatibility.

Boondorl commented 1 month ago

It does still get set. As someone who's written a lot of client-side safe code, I'm fully aware it can't be tossed.

inkoalawetrust commented 1 month ago

Oh my bad, I didn't see the line where it still gets switched on and off.

Boondorl commented 1 week ago

With 4.13 looming, gonna close this for now since it'll need to be re-structured anyway for the prediction overhaul