sendtables

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2018 License: MIT Imports: 8 Imported by: 13

Documentation

Overview

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

Index

Constants

View Source
const (
	ValTypeInt propertyValueType = iota
	ValTypeFloat32
	ValTypeFloat64
	ValTypeString
	ValTypeVector
	ValTypeArray
	ValTypeBoolInt // Int that is treated as bool (1 -> true, != 1 -> false)
)

Possible types of property values.

See PropertyEntry.Bind()

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	ID          int
	ServerClass *ServerClass
	// contains filtered or unexported fields
}

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

func NewEntity

func NewEntity(id int, serverClass *ServerClass) *Entity

NewEntity creates a new Entity with a given id and ServerClass and returns it.

func (*Entity) ApplyBaseline added in v0.5.4

func (e *Entity) ApplyBaseline(baseline map[int]PropValue)

ApplyBaseline baseline applies a previously collected baseline.

Intended for internal use only.

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) BindProperty added in v0.5.4

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

BindProperty combines FindProperty() & PropertyEntry.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) *PropertyEntry

FindProperty 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) InitializeBaseline added in v0.5.3

func (e *Entity) InitializeBaseline(r *bit.BitReader) map[int]PropValue

InitializeBaseline applies an update and collects a baseline (default values) from the update.

Intended for internal use only.

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) Position added in v0.5.4

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

Position returns the entity's position in world coordinates.

func (*Entity) Props

func (e *Entity) Props() []PropertyEntry

Props returns all properties (PropertyEntry) for the Entity.

type EntityCreatedEvent

type EntityCreatedEvent struct {
	ServerClass *ServerClass
	Entity      *Entity
}

EntityCreatedEvent contains information about a newly created entity.

type EntityCreatedHandler

type EntityCreatedHandler func(EntityCreatedEvent)

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

type FlattenedPropEntry

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

FlattenedPropEntry stores meta information about a property of an Entity. Might be renamed in a future major release (Deprecated).

func (FlattenedPropEntry) Name

func (fpe FlattenedPropEntry) Name() string

Name returs the name of the prop entry.

type PropValue

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

PropValue stores parsed & decoded send-table values. For instance player health, location etc. Might be renamed in a future major release (Deprecated).

type PropertyEntry

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

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

func (*PropertyEntry) Bind added in v0.5.4

func (pe *PropertyEntry) Bind(variable interface{}, valueType propertyValueType)

Bind binds a property's value to a pointer.

Example:

var i int
PropertyEntry.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 PropValue to use for the binding.

func (*PropertyEntry) Entry

func (pe *PropertyEntry) Entry() *FlattenedPropEntry

Entry returns the underlying FlattenedPropEntry.

func (*PropertyEntry) OnUpdate added in v0.5.4

func (pe *PropertyEntry) OnUpdate(handler PropertyUpdateHandler)

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

func (*PropertyEntry) RegisterPropertyUpdateHandler

func (pe *PropertyEntry) RegisterPropertyUpdateHandler(handler PropertyUpdateHandler)

RegisterPropertyUpdateHandler registers a handler for updates of the PropertyEntry's value. Deprecated: Use OnUpdate instead.

func (*PropertyEntry) Value added in v0.5.3

func (pe *PropertyEntry) Value() PropValue

Value returns current value of the property.

type PropertyUpdateHandler

type PropertyUpdateHandler func(PropValue)

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

type SendTableParser added in v0.4.0

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

SendTableParser provides functions for parsing send-tables.

func (*SendTableParser) ClassBits added in v0.4.0

func (p *SendTableParser) ClassBits() int

ClassBits seems to calculate how many bits must be read for the server-class ID. Not 100% sure how tho tbh.

func (*SendTableParser) FindServerClassByName added in v0.4.0

func (p *SendTableParser) FindServerClassByName(name string) *ServerClass

FindServerClassByName 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.

func (*SendTableParser) ParsePacket added in v0.4.0

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

ParsePacket parses a send-table packet.

func (*SendTableParser) ServerClasses added in v0.4.0

func (p *SendTableParser) ServerClasses() []*ServerClass

ServerClasses returns the parsed server-classes.

type ServerClass

type ServerClass struct {
	ClassID        int
	DataTableID    int
	Name           string
	DTName         string
	FlattenedProps []FlattenedPropEntry
	BaseClasses    []*ServerClass
	// contains filtered or unexported fields
}

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

func (*ServerClass) FireEntityCreatedEvent

func (sc *ServerClass) FireEntityCreatedEvent(entity *Entity)

FireEntityCreatedEvent triggers all registered EntityCreatedHandlers on the ServerClass with a new EntityCreatedEvent.

func (*ServerClass) RegisterEntityCreatedHandler

func (sc *ServerClass) RegisterEntityCreatedHandler(handler EntityCreatedHandler)

RegisterEntityCreatedHandler registers a EntityCreatedHandler on the ServerClass. The handler will be triggered on every FireEntityCreatedEvent call.

Jump to

Keyboard shortcuts

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