mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-16 05:30:40 +08:00
4.0初步改造
This commit is contained in:
36
common/ring.go
Normal file
36
common/ring.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/Monibuca/engine/v4/util"
|
||||
)
|
||||
|
||||
type RingBuffer[T any] struct {
|
||||
*util.Ring[T]
|
||||
Size int
|
||||
MoveCount uint32
|
||||
}
|
||||
|
||||
func (rb *RingBuffer[T]) Init(n int) *RingBuffer[T] {
|
||||
if rb == nil {
|
||||
rb = new(RingBuffer[T])
|
||||
}
|
||||
rb.Ring = util.NewRing[T](n)
|
||||
rb.Size = n
|
||||
return rb
|
||||
}
|
||||
|
||||
func (rb RingBuffer[T]) SubRing(rr *util.Ring[T]) *RingBuffer[T] {
|
||||
rb.Ring = rr
|
||||
rb.MoveCount = 0
|
||||
return &rb
|
||||
}
|
||||
|
||||
func (rb *RingBuffer[T]) MoveNext() *T {
|
||||
rb.Ring = rb.Next()
|
||||
rb.MoveCount++
|
||||
return &rb.Value
|
||||
}
|
||||
|
||||
func (rb *RingBuffer[T]) PreValue() *T {
|
||||
return &rb.Prev().Value
|
||||
}
|
Reference in New Issue
Block a user