From 803dd4f2eb192e268a0fa486f1b83ed269c7e86a Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Sat, 21 Oct 2023 18:19:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20lockstep=20=E6=94=AF=E6=8C=81=E4=B8=A2?= =?UTF-8?q?=E5=BC=83=E5=B8=A7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/lockstep/lockstep.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/lockstep/lockstep.go b/server/lockstep/lockstep.go index d455498..c9b3d55 100644 --- a/server/lockstep/lockstep.go +++ b/server/lockstep/lockstep.go @@ -88,6 +88,17 @@ func (slf *Lockstep[ClientID, Command]) JoinClientWithFrame(client Client[Client } +// DropCache 丢弃特定帧的缓存,当 handler 返回 true 时将丢弃缓存 +func (slf *Lockstep[ClientID, Command]) DropCache(handler func(frame int64) bool) { + slf.frameCacheLock.Lock() + defer slf.frameCacheLock.Unlock() + for frame, _ := range slf.frameCache { + if handler(frame) { + delete(slf.frameCache, frame) + } + } +} + // LeaveClient 将客户端从广播队列中移除 func (slf *Lockstep[ClientID, Command]) LeaveClient(clientId ClientID) { slf.clientLock.Lock()