command

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const InvalidID = MaxID + 1

InvalidID is a sentinel id for errors or when we have exceeded the maximum command count.

View Source
const MaxID = math.MaxUint32 - 1

MaxID is the maximum number of command types that can be registered.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name    string                // The command name
	Address *micro.ServiceAddress // Service address this command is sent to
	Persona string                // Sender's persona
	Payload Payload               // The command payload itself
}

Command represents a command from a player or external system.

type ID

type ID = uint32

ID is a unique identifier for a command type, used for bookkeeping and performance boosts.

type Manager

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

Manager manages command registration and stores commands received to be passed to the ECS world. Command IDs are mainly used for quick lookup and to check for duplicate WithCommand fields in a system state.

func NewManager

func NewManager() Manager

NewManager creates a new command manager.

func (*Manager) Clear

func (m *Manager) Clear()

Clear discards all pending commands from both queues and buffers.

func (*Manager) Drain

func (m *Manager) Drain() []Command

Drain collects commands from the queues to read-only command buffers. It also returns a list of all commands collected thus far (used by the transaction log). Drain is expected to be called at the start of each tick.

func (*Manager) Enqueue

func (m *Manager) Enqueue(command *iscv1.Command) error

Enqueue stores a command in its corresponding queue. The queues map isn't lock protected, and it is expected that there exists only 1 caller for each command type, therefore each caller reads a different key. This is ok because concurrent reads on Go maps are allowed.

func (*Manager) Get

func (m *Manager) Get(id ID) ([]Command, error)

Get retrieves a slice of commands given the command ID. The ID is returned from Register, and callers are expected to store it for calls to Get. This API is used vs using the command's name as the index as that requires an extra map lookup. We sacrifice extra complexity at the caller to make sure lookups are fast as Get is a hot path as it is called every tick.

func (*Manager) Names added in v0.10.2

func (m *Manager) Names() []string

Names returns the names of all registered command types.

func (*Manager) Register

func (m *Manager) Register(name string, queue Queue) (ID, error)

Register registers the command type with the command manager.

func (*Manager) Zero added in v0.10.2

func (m *Manager) Zero(name string) Payload

ZeroPayload returns a zero-value instance of the named command's payload type.

type Payload

type Payload interface {
	schema.Serializable
}

Payload is the interface all command payloads must implement.

type Queue

type Queue interface {
	Enqueue(*iscv1.Command) error
	Drain(target *[]Command)
	Len() int
	Zero() Payload
}

Queue defines the interface for command queuing operations. It provides methods to enqueue commands and drain all queued commands.

func NewQueue

func NewQueue[T Payload]() Queue

NewQueue creates a new command queue with an initial buffer capacity.

Jump to

Keyboard shortcuts

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