snapshot7

package
v0.0.0-...-bee29bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2024 License: BSD-2-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxType     = 0x7fff
	MaxId       = 0xffff
	MaxParts    = 64
	MaxSize     = MaxParts * 1024
	MaxPackSize = 900
)
View Source
const (
	// passed to methods
	EmptySnapTick = -1

	// returned by methods
	UninitializedTick = -1
)

Variables

View Source
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 GetItemPayload

func GetItemPayload(o object7.SnapObject) []int

TODO: this is horrible

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

func UnpackDelta(from *Snapshot, u *packer.Unpacker) (*Snapshot, error)

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

func (snap *Snapshot) GetItemIndex(key int) (index int, found bool)

the key is one integer holding both type and id

func (*Snapshot) Unpack

func (snap *Snapshot) Unpack(u *packer.Unpacker) error

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) Add

func (s *Storage) Add(tick int, snapshot *Snapshot) error

func (*Storage) AddIncomingData

func (s *Storage) AddIncomingData(part int, numParts int, data []byte) error

func (*Storage) AltSnap

func (s *Storage) AltSnap() (*Snapshot, error)

func (*Storage) FindAltSnapItem

func (s *Storage) FindAltSnapItem(typeId, itemId int) (obj object7.SnapObject, found bool, err error)

func (*Storage) First

func (s *Storage) First() (snap *Snapshot, found bool)

func (*Storage) Get

func (s *Storage) Get(tick int) (snap *Snapshot, found bool)

func (*Storage) IncomingData

func (s *Storage) IncomingData() []byte

func (*Storage) Last

func (s *Storage) Last() (snap *Snapshot, found bool)

func (*Storage) NewestTick

func (s *Storage) NewestTick() int

func (*Storage) NextTick

func (s *Storage) NextTick(tick int) int

func (*Storage) OldestTick

func (s *Storage) OldestTick() int

func (*Storage) PreviousTick

func (s *Storage) PreviousTick(tick int) int

you probably never have to use this method

func (*Storage) PurgeUntil

func (s *Storage) PurgeUntil(tick int)

func (*Storage) SetAltSnap

func (s *Storage) SetAltSnap(tick int, snap *Snapshot)

func (*Storage) Size

func (s *Storage) Size(tick int) int

you probably never have to use this method

func (*Storage) TicksSorted

func (s *Storage) TicksSorted() []int

you probably never have to use this method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL