pub trait TnuaAction<B: TnuaBasis>:
'static
+ Send
+ Sync {
type Config: Send + Sync + Clone + Serialize + for<'de> Deserialize<'de>;
type Memory: Send + Sync + Default;
// Required methods
fn initiation_decision(
&self,
config: &Self::Config,
sensors: &B::Sensors<'_>,
ctx: TnuaActionContext<'_, B>,
being_fed_for: &Stopwatch,
) -> TnuaActionInitiationDirective;
fn apply(
&self,
config: &Self::Config,
memory: &mut Self::Memory,
sensors: &B::Sensors<'_>,
ctx: TnuaActionContext<'_, B>,
lifecycle_status: TnuaActionLifecycleStatus,
motor: &mut TnuaMotor,
) -> TnuaActionLifecycleDirective;
// Provided method
fn influence_basis(
&self,
config: &Self::Config,
memory: &Self::Memory,
ctx: TnuaBasisContext<'_>,
basis_input: &B,
basis_config: &B::Config,
basis_memory: &mut B::Memory,
) { ... }
}Expand description
A character movement command for performing special actions.
“Special” does not necessarily mean that special - even
jumping or crouching
are considered TnuaActions. Unlike basis - which is something constant - an action is
usually something more momentarily that has a flow.
The type that implements this trait is called the action input, and is expected to be
overwritten each frame by the controller system of the game code - although unlike basis the
input will probably be the exact same. Configuration is stored in an asset, as part of a struct
implementing TnuaSchemeConfig which holds the configuration for the basis and all the
actions. If the action needs to persist data between frames it must keep it in its
memory.
Required Associated Types§
type Config: Send + Sync + Clone + Serialize + for<'de> Deserialize<'de>
Sourcetype Memory: Send + Sync + Default
type Memory: Send + Sync + Default
Data that the action can persist between frames.
The action will typically update this in its apply. It has three purposes:
-
Store data that cannot be calculated on the spot. For example - the part of the jump the character is currently at.
-
Pass data from the action to Tnua’s internal mechanisms.
-
Inspect the action from game code systems, like an animation controlling system that needs to know which animation to play based on the action’s current state.
Required Methods§
Sourcefn initiation_decision(
&self,
config: &Self::Config,
sensors: &B::Sensors<'_>,
ctx: TnuaActionContext<'_, B>,
being_fed_for: &Stopwatch,
) -> TnuaActionInitiationDirective
fn initiation_decision( &self, config: &Self::Config, sensors: &B::Sensors<'_>, ctx: TnuaActionContext<'_, B>, being_fed_for: &Stopwatch, ) -> TnuaActionInitiationDirective
Decides whether the action can start.
The difference between rejecting the action here with
TnuaActionInitiationDirective::Reject or TnuaActionInitiationDirective::Delay and
approving it with TnuaActionInitiationDirective::Allow only to do nothing in it and
terminate with TnuaActionLifecycleDirective::Finished on the first frame, is that if
some other action is currently running, in the former that action will continue to be
active, while in the latter it’ll be cancelled into this new action - which, having being
immediately finished, will leave the controller with no active action, or with some third
action if there is one.
Sourcefn apply(
&self,
config: &Self::Config,
memory: &mut Self::Memory,
sensors: &B::Sensors<'_>,
ctx: TnuaActionContext<'_, B>,
lifecycle_status: TnuaActionLifecycleStatus,
motor: &mut TnuaMotor,
) -> TnuaActionLifecycleDirective
fn apply( &self, config: &Self::Config, memory: &mut Self::Memory, sensors: &B::Sensors<'_>, ctx: TnuaActionContext<'_, B>, lifecycle_status: TnuaActionLifecycleStatus, motor: &mut TnuaMotor, ) -> TnuaActionLifecycleDirective
This is where the action affects the character’s motion.
This method gets called each frame to let the action control the TnuaMotor that will
later move the character. Note that this happens the motor was set by the basis’
apply. Here the action can modify some aspects of or even completely
overwrite what the basis did.
It can also update the memory.
The returned value of this action determines whether or not the action will continue in the next frame.
Provided Methods§
Sourcefn influence_basis(
&self,
config: &Self::Config,
memory: &Self::Memory,
ctx: TnuaBasisContext<'_>,
basis_input: &B,
basis_config: &B::Config,
basis_memory: &mut B::Memory,
)
fn influence_basis( &self, config: &Self::Config, memory: &Self::Memory, ctx: TnuaBasisContext<'_>, basis_input: &B, basis_config: &B::Config, basis_memory: &mut B::Memory, )
An action can use this method to send information back to the basis’ memory.
For example - a jump action can use that to violate the basis’ coyote time.