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, sender Sender) 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
- type Sender
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
Sender Sender // Who sent the command; zero for a command this world sends
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.
func (*Manager) Names ¶ added in v0.10.2
Names returns the names of all registered command types, sorted so a seeded fuzzer that draws from them replays.
type Payload ¶
type Payload interface {
schema.Serializable
}
Payload is the interface all command payloads must implement.
type Queue ¶
type Queue interface {
Enqueue(context.Context, *iscv1.Command, Sender) 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.
type Sender ¶ added in v0.19.0
type Sender struct {
// contains filtered or unexported fields
}
Sender identifies who sent a command: a player or another shard. Only Cardinal builds one, with PlayerSender or ShardSender, so a received command's sender is always one of the two.
func PlayerSender ¶ added in v0.19.0
PlayerSender is the sender of a command a client sent as the authenticated player id.
func ShardSender ¶ added in v0.19.0
func ShardSender(address *micro.ServiceAddress) Sender
ShardSender is the sender of a command the service at address sent.
func (Sender) ID ¶ added in v0.19.0
ID returns the player ID, or the sending shard's address ("region.realm.org.project.shard"). Use it when any sender will do, such as in logs.