Documentation
¶
Index ¶
- Constants
- func HasCodec(name string) bool
- func Marshal(p Payload) ([]byte, error)
- func RegisterCodec(name string, c Codec)
- func Seal()
- type Codec
- type Command
- type ID
- type Manager
- func (m *Manager) Clear()
- func (m *Manager) Drain() []Command
- func (m *Manager) Enqueue(command *iscv1.Command) error
- func (m *Manager) Get(id ID) ([]Command, error)
- func (m *Manager) Names() []string
- func (m *Manager) Register(name string, queue Queue) (ID, error)
- func (m *Manager) Zero(name string) Payload
- type Payload
- type Queue
Constants ¶
const InvalidID = MaxID + 1
InvalidID is a sentinel id for errors or when we have exceeded the maximum command count.
const MaxID = math.MaxUint32 - 1
MaxID is the maximum number of command types that can be registered.
Variables ¶
This section is empty.
Functions ¶
func HasCodec ¶ added in v0.14.0
HasCodec reports whether a codec is registered for the command name.
func RegisterCodec ¶ added in v0.14.0
RegisterCodec registers the wire codec for a command name. Generated code calls this from init(). A name may be registered only once: a duplicate means two generated files claim the same wire name (e.g. a stale commands_wire.gen.go left behind after a command moved packages), so we fail loudly at startup rather than let a last-wins map write silently shadow the correct codec. Registration must happen before the world starts (Seal); a later call panics rather than racing the hot-path reads.
func Seal ¶ added in v0.14.0
func Seal()
Seal freezes the codec registry. cardinal calls it when a world starts. Codecs must be registered from generated init() (which runs before any StartGame); registering afterwards would be an unrecoverable concurrent-map write against the command hot path, so a post-seal register panics deterministically instead of racing.
Types ¶
type Codec ¶ added in v0.14.0
Codec encodes and decodes a command payload to and from its wire bytes. Each command type has its own codec (generated from its schema); the engine does not know a command's shape, so it looks the codec up by command name. Unmarshal returns a fresh payload rather than mutating a receiver, so a codec implementation needs no pointer receivers.
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 (*Manager) Clear ¶
func (m *Manager) Clear()
Clear discards all pending commands from both queues and buffers.
func (*Manager) Drain ¶
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 ¶
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 ¶
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.
type Payload ¶
type Payload interface {
schema.Serializable
}
Payload is the interface all command payloads must implement.