Documentation
¶
Index ¶
- Constants
- type Command
- type ID
- type Manager
- func (m *Manager) Clear()
- func (m *Manager) Drain() []Command
- func (m *Manager) Enqueue(ctx context.Context, command *iscv1.Command) error
- func (m *Manager) Get(id ID) ([]Command, error)
- func (m *Manager) Lookup(name string) (ID, bool)
- 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 ¶
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
Span trace.SpanContext // Span that enqueued the command; invalid when the caller was untraced
}
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: World.Commands resolves a name to an ID once and indexes the read-only buffer directly.
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.