首页 > 代码库 > 关于游戏网络延迟的资料
关于游戏网络延迟的资料
client-server
- the server takes snapshots of the current world state at a constant rate and broadcasts these snapshots to the clients.
- server -> snapshot -> client
- server <- userinput <- client
- server runs a physical simulation step, checks the game rules, and updates all object states
- the client has to tell the server its incoming bandwidth capacity
- server doesn‘t send a full world snapshot each time, but rather only changes, Usually full (non-delta) snapshots are only sent when a game starts or a client suffers from heavy packet loss for a couple of seconds
Input prediction
1.local client just predicts the results of its own user commands. 2.if server result != client, Then the client has to correct its own position, since the server has final authority over client-side prediction 3.Prediction is only possible for the local player and entities affected only by him
Lag compensation
1.The lag compensation system keeps a history of all recent player positions for one second. If a user command is executed, the server estimates at what time the command was created as follows:
Command Execution Time = Current Server Time - Packet Latency - Client View Interpolation
Then the server moves all other players - only players - back to where they were at the command execution time. The user command is executed and the hit is detected correctly. After the user command has been processed, the players revert to their original positions.
end
Network latencies and lag compensation can create paradoxes that seem illogical compared to the real world. For example, you can be hit by an attacker you can‘t even see anymore because you already took cover. What happened is that the server moved your player hitboxes back in time, where you were still exposed to your attacker. This inconsistency problem can‘t be solved in general because of the relatively slow packet speeds. In the real world, you don‘t notice this problem because light (the packets) travels so fast and you and everybody around you sees the same world as it is right now.
关于游戏网络延迟的资料