![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Base class for native C++ gameplay behaviors. More...
#include <behavior.h>
Public Member Functions | |
| virtual void | onStart () |
| Called on the first simulation tick this instance runs in play mode. | |
| virtual void | onUpdate (float dt) |
| Called every variable-step frame on which simulation time advanced. | |
| virtual void | onRealtimeUpdate (float dt) |
| Called every frame on real time, paused or not. | |
| virtual void | onFixedUpdate (float dt) |
| Called on each fixed-step tick; fed from simulation time, so pause and time-scale apply. | |
| virtual void | onCollisionEnter (const Collision &hit) |
| Called on the first tick this entity touches another, in a resolved (non-trigger) contact. | |
| virtual void | onCollisionStay (const Collision &hit) |
| Called on each later tick the contact lasts. | |
| virtual void | onCollisionExit (const Collision &hit) |
| Called on the first tick the contact is over. | |
| virtual void | onTriggerEnter (EntityId other) |
Called on the first tick other overlaps this entity's trigger. | |
| virtual void | onTriggerStay (EntityId other) |
Called on each later tick other is still inside, on onCollisionStay's terms. | |
| virtual void | onTriggerExit (EntityId other) |
Called on the first tick other no longer overlaps, on onCollisionExit's terms. | |
| virtual void | onDestroy () |
| Called on entity removal, and when the session ends (see BehaviorSystem::endSession). | |
| virtual const char * | typeName () const =0 |
| Stable type name, identical to this type's BehaviorRegistry key; serialization uses it. | |
| virtual void | visitFields (BehaviorFieldVisitor &visitor) |
| Visit the behavior's reflected authoring fields; ReflectedBehavior generates it. | |
| virtual std::unique_ptr< Behavior > | clone () const =0 |
| Deep copy for entity duplication; authored fields only, the context is rebound. | |
Protected Member Functions | |
| EntityId | entity () const |
| The entity this behavior is attached to. | |
| template<typename T> | |
| T * | tryGet () |
| This entity's T, or null when it has none. | |
| template<typename T> | |
| const T * | tryGet () const |
| This entity's T, or null when it has none. | |
| template<typename T> | |
| T & | get () |
| This entity's T, which it must have. | |
| template<typename T> | |
| const T & | get () const |
| This entity's T, which it must have. | |
| template<typename T> | |
| bool | has () const |
| Whether this entity carries a T. | |
| template<typename T> | |
| auto & | add (T &&component) |
| Give this entity a T. | |
| template<typename T> | |
| T * | findBehavior () |
| This entity's behavior of type T, or null when it has none. | |
| template<typename T> | |
| T * | findBehavior (EntityId other) |
other's behavior of type T, or null when it has none. | |
| Scene & | scene () |
| The scene this behavior's entity lives in. | |
| ResourceManager & | resources () |
| The assets this session holds, to look one up or add one. | |
| EventSender | events () |
| The event bus's sending half, to emit or enqueue on. | |
| RenderSettings & | render () |
| The quality settings the frame is drawn at; a write lands on the next frame. | |
| InputMap & | input () |
| Named input actions, for the frame queries and to define bindings. | |
| NetSession & | net () |
| The wire, or an offline session that answers as though local. | |
| Clock & | clock () |
| Real and simulation time, and the play state behind them. | |
| WindowManager * | window () |
| The window, or null on a host that draws nothing, such as a dedicated server. | |
| bool | isSimulated () const |
| Whether this end decides what happens to this entity. | |
| bool | isMine () const |
| Whether this entity belongs to the player at this end. | |
| bool | isReplaying () const |
| Whether this tick already happened and is being run again. | |
| const InputCommand & | command () const |
| The input driving this entity on the tick now running. | |
| EntityId | spawn () |
| Create a new, empty entity; add components to it through scene(). | |
| EntityId | spawn (const char *name) |
Create an entity carrying name. | |
| EntityId | spawn (const char *name, EntityId parent) |
Create an entity carrying name, parented under parent. | |
| void | destroy (EntityId target) |
Destroy entity and its subtree, firing onDestroy. | |
| void | destroy () |
| Destroy this behavior's own entity and its subtree, deferred likewise. | |
| void | loadScene (const std::string &scenePath) |
Load scenePath, replacing everything currently in the scene. | |
| template<typename EventT = void, typename Fn> | |
| void | subscribe (Fn &&callback) |
| Listen for an event until the behavior is destroyed or the session ends. | |
Static Protected Member Functions | |
| template<typename T> | |
| static T * | findBehavior (Scene &world, EntityId entity) |
| The free findBehavior, which the member overloads would otherwise hide. | |
| template<typename T> | |
| static const T * | findBehavior (const Scene &world, EntityId entity) |
| The free findBehavior, which the member overloads would otherwise hide. | |
Base class for native C++ gameplay behaviors.
Attached through a ScriptComponent. The context is bound before onStart(), so no accessor works in a constructor; being session-stable, they are safe from a subscribe() callback and not worth caching.
|
inlinevirtual |
Called on the first simulation tick this instance runs in play mode.
Never from onRealtimeUpdate, so one spawned while paused waits for time to flow.
|
inlinevirtual |
Called every variable-step frame on which simulation time advanced.
Skipped entirely while paused (and in editor Edit mode), never run with a zero delta; work that must continue goes in onRealtimeUpdate.
| dt | Elapsed simulation time this frame, in seconds; always > 0. |
|
inlinevirtual |
Called every frame on real time, paused or not.
Only for started behaviors, so build a pause menu in onStart and toggle UIElement::visible rather than spawning it on pause.
| dt | Real frame delta in seconds, untouched by setTimeScale(); always > 0. |
|
inlinevirtual |
Called on each fixed-step tick; fed from simulation time, so pause and time-scale apply.
| dt | Fixed timestep (Clock::getFixedStep()), in seconds. |
|
inlinevirtual |
Called on the first tick this entity touches another, in a resolved (non-trigger) contact.
| hit | Who, where, and the normal from them into this entity. |
|
inlinevirtual |
Called on each later tick the contact lasts.
Not while both bodies rest (asleep or static); waking does not enter again.
| hit | The contact this tick. |
|
inlinevirtual |
Called on the first tick the contact is over.
Including when the other was destroyed or disabled, so it may be dead. An entity destroyed while touching hears nothing.
| hit | Who it stopped touching; its point and normal are zero. |
|
inlinevirtual |
Called on the first tick other overlaps this entity's trigger.
| other | The entity that entered. |
|
inlinevirtual |
Called on each later tick other is still inside, on onCollisionStay's terms.
| other | The entity still inside. |
|
inlinevirtual |
Called on the first tick other no longer overlaps, on onCollisionExit's terms.
| other | The entity that left; it may no longer be alive. |
|
pure virtual |
Stable type name, identical to this type's BehaviorRegistry key; serialization uses it.
Implemented in Vkm::Engine::ReflectedBehavior< Derived >.
|
inlinevirtual |
Visit the behavior's reflected authoring fields; ReflectedBehavior generates it.
| visitor | Visited once per reflected field, in markup order. |
Reimplemented in Vkm::Engine::ReflectedBehavior< Derived >.
|
pure virtual |
Deep copy for entity duplication; authored fields only, the context is rebound.
Implemented in Vkm::Engine::ReflectedBehavior< Derived >.
|
inlineprotected |
The entity this behavior is attached to.
|
inlineprotected |
This entity's T, or null when it has none.
| T | Component type. |
|
inlineprotected |
This entity's T, or null when it has none.
| T | Component type. |
|
inlineprotected |
This entity's T, which it must have.
| T | Component type; the entity must carry one. |
|
inlineprotected |
This entity's T, which it must have.
| T | Component type; the entity must carry one. |
|
inlineprotected |
Whether this entity carries a T.
| T | Component type. |
|
inlineprotected |
Give this entity a T.
| T | Component type; the entity must not already have one. |
| component | Component to store. |
|
inlineprotected |
This entity's behavior of type T, or null when it has none.
| T | Behavior subclass with a VKM_REFLECT block. |
|
inlineprotected |
other's behavior of type T, or null when it has none.
Not worth caching: the entity may die and its slot be reused between hooks.
| T | Behavior subclass with a VKM_REFLECT block. |
| other | Entity to look on; a dead one has none. |
other, or nullptr.
|
inlineprotected |
The scene this behavior's entity lives in.
|
inlineprotected |
The assets this session holds, to look one up or add one.
|
inlineprotected |
The event bus's sending half, to emit or enqueue on.
Not the bus: a listener on it would outlive this instance; use subscribe().
|
inlineprotected |
The quality settings the frame is drawn at; a write lands on the next frame.
|
inlineprotected |
|
inlineprotected |
The wire, or an offline session that answers as though local.
|
inlineprotected |
Real and simulation time, and the play state behind them.
A game may pause and resume through this. Never call beginFrame() or consumeFixedStep(): they belong to the main loop.
|
inlineprotected |
The window, or null on a host that draws nothing, such as a dedicated server.
|
inlineprotected |
Whether this end decides what happens to this entity.
True offline and on a server; on a client only for what it owns. Ask before writing a Transform or velocity, never before drawing or playing a sound, or a remote player goes silent and invisible.
|
inlineprotected |
Whether this entity belongs to the player at this end.
Ask before touching the camera, mouse or HUD. Not isSimulated(): a server simulates every player and owns none.
|
inlineprotected |
Whether this tick already happened and is being run again.
A mispredicting client replays ticks. Computation must re-run, but nothing presented (an animation, a sound) may. False offline and on a server.
|
inlineprotected |
The input driving this entity on the tick now running.
Offline, the local player's, whatever the entity; online, its driving player's, or nothing held. Read this, not the device, which misses taps between ticks, repeats presses on slow frames and cannot be replayed.
|
inlineprotected |
Create a new, empty entity; add components to it through scene().
Safe from a hook; a behavior added during a pass starts on the next. Local to this end, so a client warns once; use NetSession::spawn on the server instead.
|
inlineprotected |
Create an entity carrying name.
| name | Human-readable name; truncated into Name's fixed buffer. |
Create an entity carrying name, parented under parent.
Parenting is HierarchyOperations::setParent.
| name | Human-readable name; truncated into Name's fixed buffer. |
| parent | Entity to attach it under; must be alive. |
|
inlineprotected |
Destroy entity and its subtree, firing onDestroy.
Deferred past the hook pass, so destroying your own entity is safe; drained on paused frames too.
| target | Root of the subtree to destroy. |
|
inlineprotected |
Load scenePath, replacing everything currently in the scene.
Deferred to the end of the hook pass, since it destroys the caller; the last request wins. Works while paused, but the new scene starts only once time flows, so a paused caller must resume the clock itself.
| scenePath | Scene file, relative to the project root. |
|
inlineprotected |
Listen for an event until the behavior is destroyed or the session ends.
Name the type (subscribe<UIClickEvent>(...)) only for a generic lambda.
| EventT | Event type to listen for; deduced when left out. |
| Fn | Callable taking const EventT&. |
| callback | Called with each event; a throw is reported but does not disable. |