diff --git a/server/lockstep/lockstep.go b/server/lockstep/lockstep.go index 4215c91..d455498 100644 --- a/server/lockstep/lockstep.go +++ b/server/lockstep/lockstep.go @@ -107,6 +107,7 @@ func (slf *Lockstep[ClientID, Command]) StartBroadcast() { } slf.running = true slf.runningLock.RUnlock() + slf.currentFrame = slf.initFrame slf.ticker.Loop("lockstep", timer.Instantly, time.Second/time.Duration(slf.frameRate), timer.Forever, func() { @@ -132,6 +133,9 @@ func (slf *Lockstep[ClientID, Command]) StartBroadcast() { for clientId, client := range slf.clients { var i = slf.clientFrame[clientId] + if i < slf.initFrame { + i = slf.initFrame + } for ; i < currentFrame; i++ { cache, exist := slf.frameCache[i] if !exist { diff --git a/server/lockstep/lockstep_test.go b/server/lockstep/lockstep_test.go index 4899e30..21b03af 100644 --- a/server/lockstep/lockstep_test.go +++ b/server/lockstep/lockstep_test.go @@ -22,7 +22,9 @@ func (slf *Cli) Write(packet []byte, callback ...func(err error)) { } func TestNewLockstep(t *testing.T) { - ls := lockstep.NewLockstep[string, int]() + ls := lockstep.NewLockstep[string, int]( + lockstep.WithInitFrame[string, int](1), + ) ls.JoinClient(&Cli{id: "player_1"}) ls.JoinClient(&Cli{id: "player_2"}) count := 0