Documentation ¶
Index ¶
- Constants
- Variables
- func CrcItem(o object7.SnapObject) int
- func GetItemPayload(o object7.SnapObject) []int
- func ItemKey(o object7.SnapObject) int
- func UndiffItemSlow(oldItem object7.SnapObject, diffItem object7.SnapObject) object7.SnapObject
- type Snapshot
- type Storage
- func (s *Storage) Add(tick int, snapshot *Snapshot) error
- func (s *Storage) AddIncomingData(part int, numParts int, data []byte) error
- func (s *Storage) AltSnap() (*Snapshot, error)
- func (s *Storage) FindAltSnapItem(typeId, itemId int) (obj object7.SnapObject, found bool, err error)
- func (s *Storage) First() (snap *Snapshot, found bool)
- func (s *Storage) Get(tick int) (snap *Snapshot, found bool)
- func (s *Storage) IncomingData() []byte
- func (s *Storage) Last() (snap *Snapshot, found bool)
- func (s *Storage) NewestTick() int
- func (s *Storage) NextTick(tick int) int
- func (s *Storage) OldestTick() int
- func (s *Storage) PreviousTick(tick int) int
- func (s *Storage) PurgeUntil(tick int)
- func (s *Storage) SetAltSnap(tick int, snap *Snapshot)
- func (s *Storage) Size(tick int) int
- func (s *Storage) TicksSorted() []int
Constants ¶
const ( MaxType = 0x7fff MaxId = 0xffff MaxParts = 64 MaxSize = MaxParts * 1024 MaxPackSize = 900 )
const ( // passed to methods EmptySnapTick = -1 // returned by methods UninitializedTick = -1 )
Variables ¶
var (
ErrNoAltSnapInSnapStorage = errors.New("there is no alt snap in the storage")
)
Functions ¶
func CrcItem ¶
func CrcItem(o object7.SnapObject) int
TODO: this is wasting clock cycles for no reason
the crc is all snap item payload integers summed together it does not have to be perfectly optimized but repacking every item to get its payload summed is horrible i also had another approach with reflect where every snap object would implement Crc() on them selfs but reflect is messy and especially the enum types got annoying to sum because they require specific casting
func ItemKey ¶
func ItemKey(o object7.SnapObject) int
func UndiffItemSlow ¶
func UndiffItemSlow(oldItem object7.SnapObject, diffItem object7.SnapObject) object7.SnapObject
TODO: don't undiff items the slowest possible way
there should be way to do it like the C++ implementation which does no unpacking or repacking before applying the diff
Types ¶
type Snapshot ¶
type Snapshot struct { NumRemovedItems int NumItemDeltas int Crc int Items []object7.SnapObject }
func UnpackDelta ¶
from has to be the old snapshot we delta against and the unpacker has to point to the payload of the new delta snapshot the payload starts with NumRemovedItems
it returns the new full snapshot with the delta applied to the from
See also (Snapshot *)Unpack()
func (*Snapshot) GetItemAtKey ¶
func (snap *Snapshot) GetItemAtKey(key int) (obj *object7.SnapObject, found bool)
the key is one integer holding both type and id
func (*Snapshot) GetItemIndex ¶
the key is one integer holding both type and id
func (*Snapshot) Unpack ¶
unpacks the snapshot as is the unpacker has to point to the payload of the new delta snapshot the payload starts with NumRemovedItems
it does not unpack any delta just a raw snapshot parser useful for inspecting network traffic not useful for gameplay relevant things because snap items will be missing since it is not merged into the old delta
See also snapshot7.UnpackDelta()
type Storage ¶
type Storage struct { // the tick we are currently collecting parts for CurrentRecvTick int // received parts for the current tick // as a bit field // to check if we received all previous parts // when we get the last part number SnapshotParts int // contains filtered or unexported fields }
TODO: do we need this at all?
in teeworlds this makes sense because its a custom data structure but in golang users could just define their own map
TODO: make this an interface with a default implementation which the user can change and just replace with their own implementation if they want
func NewStorage ¶
func NewStorage() *Storage
func (*Storage) AddIncomingData ¶
func (*Storage) FindAltSnapItem ¶
func (*Storage) IncomingData ¶
func (*Storage) NewestTick ¶
func (*Storage) OldestTick ¶
func (*Storage) PreviousTick ¶
you probably never have to use this method
func (*Storage) PurgeUntil ¶
func (*Storage) SetAltSnap ¶
func (*Storage) TicksSorted ¶
you probably never have to use this method