vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::ReflectedBehavior< Derived > Class Template Reference

CRTP base that derives typeName(), visitFields() and clone() from the reflect block. More...

#include <reflected_behavior.h>

Inheritance diagram for Vkm::Engine::ReflectedBehavior< Derived >:
Vkm::Engine::Behavior

Public Member Functions

const char * typeName () const override
 Stable type name, identical to this type's BehaviorRegistry key; serialization uses it.
void visitFields (BehaviorFieldVisitor &visitor) override
 Visit the behavior's reflected authoring fields; ReflectedBehavior generates it.
std::unique_ptr< Behavior > clone () const override
 Deep copy for entity duplication; authored fields only, the context is rebound.
Public Member Functions inherited from Vkm::Engine::Behavior
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).
EntityId entity () const
 The entity this behavior is attached to.

Additional Inherited Members

Protected Member Functions inherited from Vkm::Engine::Behavior
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 * findInScene ()
 The scene's behavior of type T, as findBehavior(Scene&) finds it.
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.
const RenderSettings & projectRender () const
 The project's render settings, which render() started from.
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.
ScreenView screen () const
 The 3D view through the scene's active camera: the pointer's ray into the world, a point of the world on a canvas.
const OceanData * ocean () const
 The scene's sea at this moment: the tick's in onFixedUpdate, the frame's in onUpdate (OceanSystem).
std::optional< Math::Ray > pointerRay () const
 The ray from the camera through the cursor.
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.
void restartScene ()
 Start the scene being played over: the file loadScene last loaded, else the scene the host began play with - its entry scene, or under the editor the scene as Play found it, unsaved edits and all.
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 inherited from Vkm::Engine::Behavior
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.

Detailed Description

template<typename Derived>
class Vkm::Engine::ReflectedBehavior< Derived >

CRTP base that derives typeName(), visitFields() and clone() from the reflect block.

The block (VKM_REFLECT_BEGIN(::Game::Derived) / VKM_F / VKM_REFLECT_END) is required, even if empty. The name is the unqualified class name, which scenes store, so renaming the class renames the behavior.

Member Function Documentation

◆ typeName()

template<typename Derived>
const char * Vkm::Engine::ReflectedBehavior< Derived >::typeName ( ) const
inlineoverridevirtual

Stable type name, identical to this type's BehaviorRegistry key; serialization uses it.

Returns
The type's registered name.

Implements Vkm::Engine::Behavior.

◆ visitFields()

template<typename Derived>
void Vkm::Engine::ReflectedBehavior< Derived >::visitFields ( BehaviorFieldVisitor & visitor)
inlineoverridevirtual

Visit the behavior's reflected authoring fields; ReflectedBehavior generates it.

Parameters
visitorVisited once per reflected field, in markup order.

Reimplemented from Vkm::Engine::Behavior.

◆ clone()

template<typename Derived>
std::unique_ptr< Behavior > Vkm::Engine::ReflectedBehavior< Derived >::clone ( ) const
inlineoverridevirtual

Deep copy for entity duplication; authored fields only, the context is rebound.

Returns
A new instance of the same type carrying the authored fields.

Implements Vkm::Engine::Behavior.


The documentation for this class was generated from the following file: