sendtables

package
Version: v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 10 Imported by: 11

Documentation

Overview

Package sendtables contains sendtable specific magic and should really be better documented (TODO).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	// contains filtered or unexported fields
}

Entity stores a entity in the game (e.g. players etc.) with its properties.

func (*Entity) ApplyUpdate

func (e *Entity) ApplyUpdate(reader *bit.BitReader)

ApplyUpdate reads an update to an Enitiy's properties and triggers registered PropertyUpdateHandlers if values changed.

Intended for internal use only.

func (*Entity) BindPosition added in v1.0.0

func (e *Entity) BindPosition(pos *r3.Vector)

BindPosition binds the entity's position to a pointer variable. The pointer is updated every time a position-relevant property is updated.

See also OnPositionUpdate()

func (*Entity) BindProperty added in v0.5.4

func (e *Entity) BindProperty(name string, variable interface{}, valueType PropertyValueType)

BindProperty combines FindPropertyI() & Property.Bind() into one. Essentially binds a property's value to a pointer. See the docs of the two individual functions for more info.

func (*Entity) Destroy added in v0.5.4

func (e *Entity) Destroy()

Destroy triggers all via OnDestroy() registered functions.

Intended for internal use only.

func (*Entity) FindProperty

func (e *Entity) FindProperty(name string) (prop *Property)

FindProperty is deprecated, use FindPropertyI() instead which returns an interface.

func (*Entity) FindPropertyI added in v1.2.0

func (e *Entity) FindPropertyI(name string) IProperty

FindPropertyI finds a property on the Entity by name.

Returns nil if the property wasn't found.

Panics if more than one property with the same name was found.

func (*Entity) ID

func (e *Entity) ID() int

ID returns the entity's ID.

func (*Entity) OnCreateFinished added in v0.5.4

func (e *Entity) OnCreateFinished(delegate func())

OnCreateFinished registers a function to be called once the entity is fully created - i.e. once all property updates have been sent out.

func (*Entity) OnDestroy added in v0.5.4

func (e *Entity) OnDestroy(delegate func())

OnDestroy registers a function to be called on the entity's destruction.

func (*Entity) OnPositionUpdate added in v1.0.0

func (e *Entity) OnPositionUpdate(h func(pos r3.Vector))

OnPositionUpdate registers a handler for the entity's position update. The handler is called with the new position every time a position-relevant property is updated.

See also Position()

func (*Entity) Position added in v0.5.4

func (e *Entity) Position() r3.Vector

Position returns the entity's position in world coordinates.

func (*Entity) Properties added in v1.0.0

func (e *Entity) Properties() (out []Property)

Properties is deprecated, use PropertiesI() instead which returns a slice of interfaces.

func (*Entity) PropertiesI added in v1.2.0

func (e *Entity) PropertiesI() (out []IProperty)

PropertiesI returns all properties of the Entity.

func (*Entity) ServerClass

func (e *Entity) ServerClass() *ServerClass

ServerClass returns the entity's server-class.

type EntityCreatedHandler

type EntityCreatedHandler func(*Entity)

EntityCreatedHandler is the interface for handlers that are interested in EntityCreatedEvents.

type IEntity added in v1.1.0

type IEntity interface {
	// ServerClass returns the entity's server-class.
	ServerClass() *ServerClass
	// ID returns the entity's ID.
	ID() int
	// Properties is deprecated, use PropertiesI() instead which returns a slice of interfaces.
	Properties() (out []Property)
	// PropertiesI returns all properties of the Entity.
	PropertiesI() (out []IProperty)
	// FindProperty is deprecated, use FindPropertyI() instead which returns an interface.
	FindProperty(name string) (prop *Property)
	// FindPropertyI finds a property on the Entity by name.
	//
	// Returns nil if the property wasn't found.
	//
	// Panics if more than one property with the same name was found.
	FindPropertyI(name string) IProperty
	// BindProperty combines FindPropertyI() & Property.Bind() into one.
	// Essentially binds a property's value to a pointer.
	// See the docs of the two individual functions for more info.
	BindProperty(name string, variable interface{}, valueType PropertyValueType)
	// ApplyUpdate reads an update to an Enitiy's properties and
	// triggers registered PropertyUpdateHandlers if values changed.
	//
	// Intended for internal use only.
	ApplyUpdate(reader *bit.BitReader)
	// Position returns the entity's position in world coordinates.
	Position() r3.Vector
	// OnPositionUpdate registers a handler for the entity's position update.
	// The handler is called with the new position every time a position-relevant property is updated.
	//
	// See also Position()
	OnPositionUpdate(h func(pos r3.Vector))
	// BindPosition binds the entity's position to a pointer variable.
	// The pointer is updated every time a position-relevant property is updated.
	//
	// See also OnPositionUpdate()
	BindPosition(pos *r3.Vector)
	// OnDestroy registers a function to be called on the entity's destruction.
	OnDestroy(delegate func())
	// Destroy triggers all via OnDestroy() registered functions.
	//
	// Intended for internal use only.
	Destroy()
	// OnCreateFinished registers a function to be called once the entity is fully created -
	// i.e. once all property updates have been sent out.
	OnCreateFinished(delegate func())
}

IEntity is an auto-generated interface for Entity, intended to be used when mockability is needed. Entity stores a entity in the game (e.g. players etc.) with its properties.

type IProperty added in v1.2.0

type IProperty interface {
	// Name returns the property's name.
	Name() string
	// Value returns current value of the property.
	Value() PropertyValue
	// OnUpdate registers a handler for updates of the Property's value.
	//
	// The handler will be called with the current value upon registration.
	OnUpdate(handler PropertyUpdateHandler)
	/*
	   Bind binds a property's value to a pointer.

	   Example:
	   	var i int
	   	Property.Bind(&i, ValTypeInt)

	   This will bind the property's value to i so every time it's updated i is updated as well.

	   The valueType indicates which field of the PropertyValue to use for the binding.
	*/
	Bind(variable interface{}, valueType PropertyValueType)
}

IProperty is an auto-generated interface for Property, intended to be used when mockability is needed. Property wraps a flattenedPropEntry and allows registering handlers that can be triggered on a update of the property.

type Property added in v1.0.0

type Property struct {
	// contains filtered or unexported fields
}

Property wraps a flattenedPropEntry and allows registering handlers that can be triggered on a update of the property.

func (*Property) Bind added in v1.0.0

func (pe *Property) Bind(variable interface{}, valueType PropertyValueType)

Bind binds a property's value to a pointer.

Example:

var i int
Property.Bind(&i, ValTypeInt)

This will bind the property's value to i so every time it's updated i is updated as well.

The valueType indicates which field of the PropertyValue to use for the binding.

func (*Property) Name added in v1.0.0

func (pe *Property) Name() string

Name returns the property's name.

func (*Property) OnUpdate added in v1.0.0

func (pe *Property) OnUpdate(handler PropertyUpdateHandler)

OnUpdate registers a handler for updates of the Property's value.

The handler will be called with the current value upon registration.

func (*Property) Value added in v1.0.0

func (pe *Property) Value() PropertyValue

Value returns current value of the property.

type PropertyUpdateHandler

type PropertyUpdateHandler func(PropertyValue)

PropertyUpdateHandler is the interface for handlers that are interested in Property changes.

type PropertyValue added in v1.0.0

type PropertyValue struct {
	VectorVal r3.Vector
	IntVal    int
	ArrayVal  []PropertyValue
	StringVal string
	FloatVal  float32
}

PropertyValue stores parsed & decoded send-table values. For instance player health, location etc.

type PropertyValueType added in v1.1.0

type PropertyValueType int

PropertyValueType specifies the type of a PropertyValue

const (
	ValTypeInt PropertyValueType = iota
	ValTypeFloat32
	ValTypeFloat64 // Like ValTypeFloat32 but with additional cast to float64
	ValTypeString
	ValTypeVector
	ValTypeArray
	ValTypeBoolInt // Int that is treated as bool (1 -> true, != 1 -> false)
)

Possible types of property values. See Property.Bind()

type SendTableParser added in v0.4.0

type SendTableParser struct {
	// contains filtered or unexported fields
}

SendTableParser provides functions for parsing send-tables.

Intended for internal use only.

func NewSendTableParser added in v1.0.0

func NewSendTableParser() *SendTableParser

NewSendTableParser returns a new SendTableParser.

Intended for internal use only.

func (*SendTableParser) ParsePacket added in v0.4.0

func (p *SendTableParser) ParsePacket(r *bit.BitReader)

ParsePacket parses a send-table packet.

Intended for internal use only.

func (*SendTableParser) ReadEnterPVS added in v1.0.0

func (p *SendTableParser) ReadEnterPVS(r *bit.BitReader, entityID int) *Entity

ReadEnterPVS reads an entity entering the PVS (potentially visible system).

Intended for internal use only.

func (*SendTableParser) ServerClasses added in v0.4.0

func (p *SendTableParser) ServerClasses() ServerClasses

ServerClasses returns the parsed server-classes.

Intended for internal use only.

func (*SendTableParser) SetInstanceBaseline added in v1.0.0

func (p *SendTableParser) SetInstanceBaseline(scID int, data []byte)

SetInstanceBaseline sets the raw instance-baseline data for a serverclass by ID.

Intended for internal use only.

type ServerClass

type ServerClass struct {
	// contains filtered or unexported fields
}

ServerClass stores meta information about Entity types (e.g. palyers, teams etc.).

func (*ServerClass) BaseClasses

func (sc *ServerClass) BaseClasses() []*ServerClass

BaseClasses returns the base-classes of this server-class.

func (*ServerClass) DataTableID

func (sc *ServerClass) DataTableID() int

DataTableID returns the data-table ID.

func (*ServerClass) DataTableName added in v1.0.0

func (sc *ServerClass) DataTableName() string

DataTableName returns the data-table name.

func (*ServerClass) ID added in v1.0.0

func (sc *ServerClass) ID() int

ID returns the server-class's ID.

func (*ServerClass) Name

func (sc *ServerClass) Name() string

Name returns the server-class's name.

func (*ServerClass) OnEntityCreated added in v1.0.0

func (sc *ServerClass) OnEntityCreated(handler EntityCreatedHandler)

OnEntityCreated registers a function to be called when a new entity is created from this ServerClass.

func (*ServerClass) PropertyEntries added in v1.0.0

func (sc *ServerClass) PropertyEntries() []string

PropertyEntries returns the names of all property-entries on this server-class.

func (*ServerClass) String

func (sc *ServerClass) String() string

type ServerClasses added in v1.0.0

type ServerClasses []*ServerClass

ServerClasses is a searchable list of ServerClasses.

func (ServerClasses) FindByName added in v1.0.0

func (sc ServerClasses) FindByName(name string) *ServerClass

FindByName finds and returns a server-class by it's name.

Returns nil if the server-class wasn't found.

Panics if more than one server-class with the same name was found.

Directories

Path Synopsis
Package fake provides basic mocks for IEntity and IProperty.
Package fake provides basic mocks for IEntity and IProperty.

Jump to

Keyboard shortcuts

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