fix: 修复 lockstep.WithInitFrame 不生效的问题
This commit is contained in:
parent
20f62fee87
commit
859e0a1ac1
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue