I have a tick-based Multiplayer-RTS game: Client sends action to server at Frame n which will be broadcasted to all clients and executed at Frame n+x (x depends on network latency of slowest player)
I'm unsure how to hide this latency in GUI dialogs. E.g. a value that is adjustable with a slider between 0 and 100. The current solution simply fills a "virtual" value with the actual value at game start and always operates on that value. It is highly unlikely that a change command for this does not get executed (TCP, unconditional change execution) but it is possible (packet sent and ignored during pause)
I also wanted to keep that value local to the dialog and not store it somewhere else. Start idea: Get the current value on dialog open and use this while the dialog is open. Problems: Maybe the value was changed before (packet sent, but not executed) in which case the change does not get displayed. An idea I have is storing the last value I got and update the slider if that value has changed. Maybe only when the sliders position itself did not change (by the user). However then after the update it will detect that change and change it again which leads to a change of twice the amount requested. I could also update the "last value" when the packet is sent but that will cause the (time-based) update to change it back till the actual change is made which might even result in a loop of back-and-forth changes. How can I keep the GUI and game in sync but allow visual changes? Seems I'm missing a little piece here...
Another part where this is even worse is with other kinds of dialogs. E.g. an ordering dialog (put some entities in a specific order) or a number input that is used to request producing the specified amount, hence the game may also decrease this, not only the packet. I could not find any guides or solution besides "use inter/extrapolation" which is not applicable here. How do others do this?
Edit: Maybe a little example for the strategy I though off with its flaws:
A) OK
- Value=4
- Open Dialog -> Show Value=4
- User Changes Value to 6 (Slider position change)-> Sent to server
- Server sends "6" -> Slider changes to "6" (no change as it already is)
B) OK
- Same as A) but dialog closed before receiving from server
- Dialog reopened -> Show Value=4
- Server sends "6" -> Slider changes to "6"
C)
- Value=4
- Open Dialog -> Show Value=4
- User Changes Value to 6 (Slider position change)-> Sent to server
- User Changes Value to 7 -> Sent to server
- Server sends "6" -> Slider changes to 6 BAD
- Server sends "7" -> Slider changes to 7 => OK, but strange and may cause feedback loops
D)
- Value=4, change to 6 requested
- Open Dialog -> Show Value=4 (6 was stored in the old dialog)
- User Changes Value to 7 -> Sent to server
- Server sends "6" -> Slider changes to 6 BAD
- Server sends "7" -> Slider changes to 7 => OK, but strange and may cause feedback loops
So on one hand I only want to show visual values (and store them between dialogs) but on the other hand I want to keep them in sync with the actual value. So only solution here seems to be to persistently store the visual value and make sure, each update will eventually be executed. But I'm still clueless what to do with values that can be changed by the came (e.g. production orders that decrease once they are processed)