Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Tick System

The tick system executes game logic every frame. Classes receive time delta values and can implement update logic, movement, input handling, etc.

Architecture

The engine runs ticks in this order each frame:

  1. GameModule::preTick()
  2. All ITickable::preTick() (entities with Engine::Ecs::Tick component)
  3. GameModule::tick(deltaTime)
  4. All ITickable::tick(deltaTime) (entities with Engine::Ecs::Tick component)
  5. GameModule::postTick()
  6. All ITickable::postTick() (entities with Engine::Ecs::Tick component)

ITickable Interface

Classes that implement the tick interface inherit from Engine::Core::ITickable.

File: Engine/include/Engine/Core/Tick.h

Methods

virtual void preTick();
virtual void tick(double deltaTimeSeconds);
virtual void postTick();

All methods have empty default implementations. Override only what you need.

Example: Actor with Tick

class MyActor : public Engine::Entities::Actor {
public:
void tick(double deltaTime) override {
Actor::tick(deltaTime); // Call parent first
// Your logic here
position += velocity * deltaTime;
}
};
An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform.
Definition Actor.h:65
void tick(double deltaTime) override
Executed every frame.

Entity and Actor already inherit from ITickable. Override tick() directly.

Enabling Tick

Entities don't tick by default. allowTicking_ defaults to false, so set it to true before calling enableTick(true).

Scene Tick

Engine::Entities::Scene inherits from Engine::Core::ITickable, so a scene subclass can override tick(double). The active scene is not registered in the ECS tick view, so overriding Scene::tick() alone does not make it run.

Forward tick from your GameModule if you want the active scene to receive per-frame updates.

Scene Subclass

class MyScene : public Engine::Entities::Scene {
public:
void loadContent() override {
// Spawn actors here.
}
void tick(double deltaTimeSeconds) override {
Scene::tick(deltaTimeSeconds);
// Scene-level update logic here.
}
};
virtual void tick(double deltaTimeSeconds)
Function called each frame when a tick component has been registered with EnTT Ecs::Tick.
Definition Tick.h:46
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:62
virtual void loadContent()

GameModule Forwarding

void MyGame::tick(float deltaTime) {
GameModule::tick(deltaTime);
if (engine == nullptr) {
return;
}
auto* scene = engine->getSceneManager()->getActiveScene();
if (scene != nullptr) {
scene->tick(static_cast<double>(deltaTime));
}
}
const std::unique_ptr< Core::SceneManager > & getSceneManager() const
Definition Engine.h:237
static EngineManager & getInstance()
gets a reference to the engine manager
EngineKern * getEngineModule()
gets the pointer to the engine object

With this wiring, MyGame::tick() calls the active scene before the engine calls tick-enabled entities. Move the scene call inside MyGame::tick() if you need game-level work before or after scene logic.

Do not call enableTick(true) on a scene. Only Entity and Actor expose enableTick() because they own an EnTT entity handle.

If a scene needs preTick() or postTick(), forward those from GameModule::preTick() and GameModule::postTick() the same way.

For Entity/Actor

class MyActor : public Engine::Entities::Actor {
public:
explicit MyActor(const Engine::Entities::SpawnContext& context)
: Actor(context) {
allowTicking_ = true;
enableTick(true);
}
void tick(double deltaTime) override {
Actor::tick(deltaTime);
// Update logic
}
};
void enableTick(bool enable)
Enables or disables ticking for this entity.
Scene ownership data passed to actor and component constructors during spawning.

What enableTick Does

Adds an Engine::Ecs::Tick component to the entity's EnTT registry entry only when canEverTick() returns true:

void Entity::enableTick(bool enable) {
if (enable && canEverTick()) {
registry.emplace_or_replace<Engine::Ecs::Tick>(data_, this, tickPriority_);
} else if (registry.all_of<Engine::Ecs::Tick>(data_)) {
registry.remove<Engine::Ecs::Tick>(data_);
}
}
static entt::registry & get()
Gets the registry for all components.
Tag for everything which wants to receive tick events.
Definition EcsData.h:292

The engine queries all entities with Engine::Ecs::Tick each frame and calls their tick methods.

Logic Component Tick

Engine::Components::Logic doesn't inherit from ITickable but has its own tick system.

Enabling Component Tick

class MyComponent : public Engine::Components::Logic {
public:
explicit MyComponent(Engine::Entities::Scene* scene) : Logic(scene) {
setCanTick(true); // Enable ticking
}
void tick(double deltaTime) override {
// Component logic
}
};
Base class for all logic components that can be attached to an actor. Provides access to the scene,...
void setCanTick(bool enable)
Enables or disables ticking for this component.
virtual void tick(double deltaTime)
Called every frame if ticking is enabled.

How It Works

Actor::tick() iterates through components and calls tick() on those with ticking enabled:

void Actor::tick(double deltaTime) {
Entity::tick(deltaTime);
for (auto& component : components) {
if (component->canTick()) {
component->tick(deltaTime);
}
}
}

Non-ITickable Classes

For classes that don't inherit from ITickable, wrap them or call their update methods manually.

Option 1: Manual Calls in Actor

class ThirdPartySystem {
public:
void update(float dt) { /* ... */ }
};
class MyActor : public Engine::Entities::Actor {
ThirdPartySystem system_;
public:
void tick(double deltaTime) override {
Actor::tick(deltaTime);
system_.update(static_cast<float>(deltaTime));
}
};

Option 2: Wrap in Logic

class ThirdPartySystem {
public:
void update(float dt) { /* ... */ }
};
class ThirdPartySystemComponent : public Engine::Components::Logic {
ThirdPartySystem system_;
public:
explicit ThirdPartySystemComponent(Engine::Entities::Scene* scene) : Logic(scene) {
setCanTick(true);
}
void tick(double deltaTime) override {
system_.update(static_cast<float>(deltaTime));
}
};
// Usage in actor
actor->addComponent<ThirdPartySystemComponent>(scene);

GameModule Tick

Override GameModule methods for global game logic.

File: Engine/include/Engine/Game/GameModule.h

class MyGame : public Engine::GameModule {
public:
void preTick() override {
// Runs before all entities
}
void tick(float deltaTime) override {
// Update global state
gameTime_ += deltaTime;
}
void postTick() override {
// Cleanup after all entities
}
};
virtual void tick(float deltaTime)
virtual void preTick()
virtual void postTick()

Async Tick (Asset Pipelines)

Asset pipelines use tick() for state machine advancement, not frame timing.

Example: Engine::Ecs::ModelAssetPipeline::tick(bool async)

void tick(bool async = true) {
submitLoadModel(async);
processModel(async);
processMaterial(async);
processMeshData(async);
}

These ticks happen each frame but advance background loading tasks. The async parameter controls whether work happens on background threads or the main thread.

Delta Time

Delta time is the seconds elapsed since the last frame.

Get delta time:

double dt = EngineManager::getInstance().getEngineModule()->getDeltaTimeSeconds();

Typical usage:

void tick(double deltaTime) {
// Move 5 units per second
position += direction * 5.0f * static_cast<float>(deltaTime);
// Rotate 90 degrees per second
rotation += 90.0f * static_cast<float>(deltaTime);
}

Checking Tick State

// Entity
if (entity->canTick()) { /* ... */ }
if (entity->canEverTick()) { /* ... */ }
// Logic component
if (component->canTick()) { /* ... */ }

Summary

Class Type Inherits ITickable? How to Enable Tick Method
Entity/Actor Yes enableTick(true) Override tick()
Logic component No setCanTick(true) Override tick()
GameModule No Always ticks Override tick()
Scene Yes Forward active scene tick from GameModule Override tick()
Other classes No Wrap in component or call manually N/A

Default execution order: GameModule → Entities (with Engine::Ecs::Tick) → Components (within their entity)

Scene forwarding order: GameModule → Scene (where you call it) → Entities (with Engine::Ecs::Tick) → Components (within their entity)

Files: