文档介绍:Unity3D 中帧同步的实现(一):帧同步长度固定间隔下的实现
在帧同步模型中,每个客户端都会对整个游戏世界进行模拟。这种方法的好
处在于减少了需要发送的信息。帧同步只需要发送用户的输入信息,而对于反过
来的中心once per unity frame
void Update() {
7. //Basically same logic as FixedUpdate, but we can scale it by adjusting
FrameLength
8. AccumilatedTime = AccumilatedTime + ;
9.
10. //in case the FPS is too slow, we may need to update the game multiple
times a frame
11. while(AccumilatedTime > FrameLength) {
12. GameFrameTurn ();
13. AccumilatedTime = AccumilatedTime - FrameLength;
14. }
15. }
我们跟踪当前帧同步回合中游戏帧的数量。每当我们在帧同步回合中达到我
们想要的游戏回合次数,我们就会更新帧同步回合到下一轮。如果帧同步还不能
到下一轮,我们就不能增加游戏帧,而且我们会在下一次同样执行帧同步检查。
void GameFrameTurn() {
2. //first frame is used to process actions
3. if(GameFrame == 0) {
4. if(LockStepTurn()) {5. GameFrame++;
6. }
7. } else {
8. //update game
9.
10. //...
11.
12. GameFrame++;
13. if(GameFrame == GameFramesPerLocksetpTurn) {
14. GameFrame = 0;