From 037366538208cbec336fdb893be9d01b821ab429 Mon Sep 17 00:00:00 2001 From: genxium Date: Fri, 2 Dec 2022 10:20:58 +0800 Subject: [PATCH] Minor updates on ringbuffer and formatting. --- battle_srv/models/ringbuf.go | 4 ++-- frontend/assets/scenes/login.fire | 2 +- frontend/assets/scripts/RingBuffer.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/battle_srv/models/ringbuf.go b/battle_srv/models/ringbuf.go index 49a74ab..315de47 100644 --- a/battle_srv/models/ringbuf.go +++ b/battle_srv/models/ringbuf.go @@ -26,7 +26,7 @@ func NewRingBuffer(n int32) *RingBuffer { } func (rb *RingBuffer) Put(pItem interface{}) { - for rb.Cnt >= rb.N-1 { + for 0 < rb.Cnt && rb.Cnt >= rb.N { // Make room for the new element rb.Pop() } @@ -78,7 +78,7 @@ func (rb *RingBuffer) GetByOffset(offsetFromSt int32) interface{} { } func (rb *RingBuffer) GetByFrameId(frameId int32) interface{} { - if frameId >= rb.EdFrameId { + if frameId >= rb.EdFrameId || frameId < rb.StFrameId { return nil } return rb.GetByOffset(frameId - rb.StFrameId) diff --git a/frontend/assets/scenes/login.fire b/frontend/assets/scenes/login.fire index 3861c72..5cbb696 100644 --- a/frontend/assets/scenes/login.fire +++ b/frontend/assets/scenes/login.fire @@ -440,7 +440,7 @@ "array": [ 0, 0, - 210.55745061629165, + 210.4441731196186, 0, 0, 0, diff --git a/frontend/assets/scripts/RingBuffer.js b/frontend/assets/scripts/RingBuffer.js index 5b276d0..e88f605 100644 --- a/frontend/assets/scripts/RingBuffer.js +++ b/frontend/assets/scripts/RingBuffer.js @@ -13,7 +13,7 @@ var RingBuffer = function(capacity) { }; RingBuffer.prototype.put = function(item) { - while (this.cnt >= this.n - 1) { + while (0 < this.cnt && this.cnt >= this.n) { // Make room for the new element this.pop(); } @@ -65,7 +65,7 @@ RingBuffer.prototype.getArrIdxByOffset = function(offsetFromSt) { }; RingBuffer.prototype.getByFrameId = function(frameId) { - if (frameId >= this.edFrameId) return null; + if (frameId >= this.edFrameId || frameId < this.stFrameId) return null; const arrIdx = this.getArrIdxByOffset(frameId - this.stFrameId); return (null == arrIdx ? null : this.eles[arrIdx]); };