Skip to content

Commit

Permalink
fix: 修复 lockstep.WithInitFrame 不生效的问题
Browse files Browse the repository at this point in the history
Rate limit · GitHub

Whoa there!

You have triggered an abuse detection mechanism.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

kercylan98 committed Oct 21, 2023
1 parent 20f62fe commit 859e0a1
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/lockstep/lockstep.go
Original file line number Diff line number Diff line change
@@ -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 {
4 changes: 3 additions & 1 deletion server/lockstep/lockstep_test.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 859e0a1

Please sign in to comment.