vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::BehaviorSystem Class Reference

Drives the lifecycle of every entity's ScriptComponent behaviors. More...

#include <behavior_system.h>

Inheritance diagram for Vkm::Engine::BehaviorSystem:
Vkm::Engine::System Vkm::Engine::ISceneObserver

Public Member Functions

void init (FrameContext &ctx) override
 Called once after all systems are registered, before the first update.
void update (FrameContext &ctx) override
 Execute this system for the current frame.
void fixedUpdate (FrameContext &ctx) override
 Execute this system at the fixed simulation rate.
bool isReplayed () const override
 Re-run during a replay: it moves the world from state and command, repeatably.
void shutdown () override
 Called once on engine shutdown.
void onEntityDestroyed (EntityId entity) override
 ISceneObserver: fire onDestroy on entity's behaviors before its ScriptComponent goes.
void setPlayedScene (std::string path)
 The file a host began play with, which a restart reloads while no loadScene has replaced it: a runtime's or a server's entry scene.
void setRestartHandler (std::function< void()> restart)
 Hand a restart of the host's own scene to restart, which puts it back itself.
void endSession (Scene &scene)
 End the session: onDestroy on every started behavior, reset, and discard queued requests.

Detailed Description

Drives the lifecycle of every entity's ScriptComponent behaviors.

Runs before PhysicsSystem in Simulation: physics integrates what onFixedUpdate writes the same tick, and what onUpdate writes on the next frame's ticks. Destroy requests drain after each fixed tick and the frame pass; loadScene() after the frame pass only. Contacts are dispatched after onStart and before the destroy drain, so a handler may destroy its own entity. A throwing hook is reported through reportError() and the behavior disabled.

Member Function Documentation

◆ init()

void Vkm::Engine::BehaviorSystem::init ( FrameContext & ctx)
overridevirtual

Called once after all systems are registered, before the first update.

Parameters
ctxThe first frame's context; its products are all null.

Reimplemented from Vkm::Engine::System.

◆ update()

void Vkm::Engine::BehaviorSystem::update ( FrameContext & ctx)
overridevirtual

Execute this system for the current frame.

Parameters
ctxThis frame's services and the products published so far.

Reimplemented from Vkm::Engine::System.

◆ fixedUpdate()

void Vkm::Engine::BehaviorSystem::fixedUpdate ( FrameContext & ctx)
overridevirtual

Execute this system at the fixed simulation rate.

Called 0+ times per frame; the step is ctx.clock.getFixedStep().

Runs before any producer stage, so ctx.visibility and ctx.ui are null here. ctx.poses is set by SkeletalAnimationSystem's own fixedUpdate, so a later Simulation system reads this tick's pose.

Parameters
ctxThis frame's services; see above for which products are set.

Reimplemented from Vkm::Engine::System.

◆ isReplayed()

bool Vkm::Engine::BehaviorSystem::isReplayed ( ) const
inlineoverridevirtual

Re-run during a replay: it moves the world from state and command, repeatably.

Returns
Always true.

Reimplemented from Vkm::Engine::System.

◆ onEntityDestroyed()

void Vkm::Engine::BehaviorSystem::onEntityDestroyed ( EntityId entity)
overridevirtual

ISceneObserver: fire onDestroy on entity's behaviors before its ScriptComponent goes.

Runs inside Scene::destroyEntity, whatever called it.

Parameters
entityThe entity being destroyed.

Implements Vkm::Engine::ISceneObserver.

◆ setPlayedScene()

void Vkm::Engine::BehaviorSystem::setPlayedScene ( std::string path)
inline

The file a host began play with, which a restart reloads while no loadScene has replaced it: a runtime's or a server's entry scene.

Parameters
pathScene file, absolute or relative to the project root.

◆ setRestartHandler()

void Vkm::Engine::BehaviorSystem::setRestartHandler ( std::function< void()> restart)
inline

Hand a restart of the host's own scene to restart, which puts it back itself.

For a host whose scene is held in memory rather than a file: the editor's, the scene as Play found it. Called inside the frame; the host acts where it can replace the world.

Parameters
restartAsked to start play over; null hands restarts back to setPlayedScene.

◆ endSession()

void Vkm::Engine::BehaviorSystem::endSession ( Scene & scene)

End the session: onDestroy on every started behavior, reset, and discard queued requests.

Drops subscriptions and the started/disabled flags. Call while the module is loaded and the EventBus alive. Queued destroy() / loadScene() requests named the world being torn down, so they go too.

Parameters
sceneScene whose session ends.

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