Module ark_api::behavior_controller
source ¡ [−]Expand description
đ¤ Behavior Controller API
This API provides functionality to indirectly communicate with external behavior modules.
Through this API, a user can retrieve reflection info of all loaded behavior modules, create new behavior instances of a particular type, and send messages to behavior instances.
Message passing
Messages are the protocols through which behaviors communicate. At the lowest level they are serializable Rust structures.
The entire message passing flow between this API and behavior modules goes as follows:
- A user creates
IncomingMessage
s and batch sends them to Ark throughBehaviorController::instances_handle_messages
- Ark owns the actual behavior modules and will, in order, send the
IncomingMessage
s to the correct behavior instances inside external behavior modules - A behavior instance will then process the just received message
- During the processing of a message, a behavior instance can create new
OutgoingMessage
s that will be returned to the user, which then decides what to do with it
Aspects
Aspects are used to associate data with actors, and share it between behaviors. Aspects are just data and
donât implement any logic. Through BehaviorController::aspect_upsert
, users can sync their aspect data with Ark.
Internally, Ark stores aspects in so called âaspect storesâ, keyed by aspect guid first to be able to iterate on
all actors that have a given aspect blazingly fast.
Why aspects?
As each behavior module is a separate Wasm module, behavior instances from separate behavior modules canât access each others memory, meaning there is no direct sharing of state. While state could be asynchronously queried via message passing, aspects allow for a more optimal route for sharing state.
Structs
An aspectâs address, comprising of an aspect guid and an actor id
A command used for BehaviorController::aspect_upsert
to issue an aspect insertion/update
that needs to be synced with the host
The BehaviorController
API provides functionality for interacting with external behavior modules
Weak reference to a behavior instance that lives somewhere in an external behavior module.
Identifier for a specific version of a module.
Contains all registration info for an external behavior module
Describes a behavior in an external behavior module
Represents a unique behavior type in an external behavior module
Represents a message to be sent to a specific behavior instance for processing
An outgoing message generated by a behavior instance during message processing
Collection of outgoing messages returned from BehaviorController::instances_handle_messages
Iterator for OutgoingMessage
stored in OutgoingMessages
Enums
A response message received from a behavior module.