fix: 修复 lockstep.WithInitFrame 不生效的问题

This commit is contained in:
kercylan98 2023-10-21 11:22:12 +08:00
parent 20f62fee87
commit 859e0a1ac1
2 changed files with 7 additions and 1 deletions

View File

@ -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 {

View File

@ -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