Api

Engine API

Public engine lifecycle, global services, scene loading, runtime helpers, and gameplay-facing helpers.

Include

#include <EngineExports.hpp>

Public::Engine is a singleton facade over the internal engine. Game code should use this public class instead of including internals/Engine.hpp.

auto& engine = Public::Engine::getInstance();

Lifecycle

APIPurpose
static Engine& getInstance()Access the singleton facade.
Initialize(bool skipResizeCallback = false)Initialize engine systems, then process pending custom component registrations.
Loop(bool renderManagerAuthority = true, bool renderScene = true)Run one frame of update/render work.
Shutdown()Shut down engine systems.
IsActive()Return whether the app should keep looping.

Typical game loop:

auto& engine = Public::Engine::getInstance();
engine.Initialize();

while (engine.IsActive()) {
  engine.Loop();
}

engine.Shutdown();

NVEditor uses the optional Loop flags because the editor owns some rendering and ImGui flow. Normal games can use defaults.

Runtime Timing and Window

APIPurpose
HasWindow() constCheck whether the main window object exists.
GetDeltaTime() constFrame delta used by gameplay updates.
GetPotentialDeltaTime() constRaw/uncapped candidate delta used internally by timing code.
GetWindowWidth() constCurrent OS window width.
GetWindowHeight() constCurrent OS window height.
GetRenderWidth() constActive render target width.
GetRenderHeight() constActive render target height.
SetWindowTitle(const std::string& title)Update window title.
SetWindowSize(int width, int height)Resize window; returns false for non-positive sizes.
SetWindowPosition(int x, int y)Move window position.
SetFullscreen(bool fullscreen)Switch fullscreen mode.
SetCursorVisibility(bool visible)Hide or show the cursor.
SetMouseCapture(bool capture)Enable or disable mouse capture.
SetClearColor(float r, float g, float b, float a)Set active render clear color.
IsWindowFocused() constQuery whether the game window has focus.
IsCursorLocked() constQuery cursor lock state.

Global Services

APIReturns
GetCoordinator()Public::ECS::Coordinator& for entities, components, and systems.
GetInputManager()Public::Input::InputManager&.
GetFlagManager()Public::Input::FlagManager&.
GetPhysicsSystem()Public::ECS::Systems::Builtin::PhysicsSystem*, or nullptr if unavailable.

Example:

auto& coord = engine.GetCoordinator();
auto& input = engine.GetInputManager();

if (auto* physics = engine.GetPhysicsSystem()) {
  physics->SetSimulationEnabled(true);
}

Command-Line Flags

Pass argc/argv into the flag manager before checking flags:

engine.GetFlagManager().passFlags(argc, argv);

if (ISFLAG("--hotReload")) {
    LOG_INFO("Hot reload enabled");
}

auto maybeValue = FLAGVALUE("--useProject");
if (maybeValue) {
    LOG_INFO("Project path: " + *maybeValue);
}

The macros are convenience wrappers over GetFlagManager():

ISFLAG("--flag")
FLAGVALUE("--flag")

Resource Loading, IDs, and Counts

These APIs allow runtime-only tooling and gameplay systems to ensure assets are loaded before use.

APIReturnsPurpose
LoadMesh(const std::string&)boolLoad a mesh by path/ID.
LoadMaterial(const std::string&)std::stringLoad and return a material ID; returns empty on failure.
LoadTexture(const std::string&, const std::string& textureType = "diffuse")boolLoad a texture by path and slot role.
LoadShader(const std::string&)boolLoad and compile/register a shader.
HasMesh(const std::string&)boolCheck mesh registry state.
HasMaterial(const std::string&)boolCheck material registry state.
HasTexture(const std::string&)boolCheck texture registry state.
HasShader(const std::string&)boolCheck shader registry state.
GetMeshCount() constsize_tTotal loaded meshes.
GetMaterialCount() constsize_tTotal loaded materials.
GetTextureCount() constsize_tTotal loaded textures.
GetShaderCount() constsize_tTotal loaded shaders.
GetSceneCount() constsize_tTotal loaded scenes tracked by resource manager.
GetMeshIDs() conststd::vector<std::string>Sorted mesh IDs.
GetMaterialIDs() conststd::vector<std::string>Material IDs.
GetTextureIDs() conststd::vector<std::string>Texture IDs.
GetShaderIDs() conststd::vector<std::string>Shader IDs.
RemoveMeshResource(const std::string&)boolRemove mesh from resource cache.
RemoveMaterialResource(const std::string&)boolRemove material from resource cache.
RemoveTextureResource(const std::string&)boolRemove texture from resource cache.
RemoveShaderResource(const std::string&)boolRemove shader from resource cache.
engine.LoadMesh("assets/objects/crate.glb");
engine.LoadMaterial("basic");
engine.LoadShader("basic");
engine.LoadTexture("textures/asphalt/Road012B_4K-PNG_NormalDX.png", "normal");

auto meshes = engine.GetMeshIDs();

Scene Loading

engine.LoadScene("outside");

Scene loading searches for:

  1. outside.json
  2. levels/outside.json
  3. scenes/outside.json

Scene JSON must include version and ent. See Scene JSON.

To reload a scene from a gameplay hotkey, clear current entities first:

if (input.GetKeyDown(Public::Input::Key::Code::R)) {
    coord.clearAllEntities();
    engine.LoadScene("test_place");
}

Entity, Transform, and Hierarchy Helpers

APIReturnsPurpose
CreateEntity()EntityIDCreate a new entity.
DestroyEntity(EntityID)voidDestroy the entity and attached components.
GetTransform(EntityID, Transform&) constboolRead full transform by copy.
SetTransform(EntityID, const Transform&)boolOverwrite full transform values.
GetTransformPosition(EntityID, float[3]) constboolRead position.
SetTransformPosition(EntityID, float x, float y, float z)boolCreate transform if missing and set position.
GetTransformRotation(EntityID, float[4]) constboolRead quaternion rotation.
SetTransformRotation(EntityID, float x, float y, float z, float w)boolCreate transform if missing and set rotation.
GetTransformScale(EntityID, float[3]) constboolRead scale.
SetTransformScale(EntityID, float x, float y, float z)boolCreate transform if missing and set scale.
GetParent(EntityID) constEntityIDImmediate parent or INVALID_ENTITY.
GetChildren(EntityID) conststd::vector<EntityID>Immediate child snapshot.
GetChildCount(EntityID) constsize_tImmediate child count.
GetChild(EntityID, size_t index) constEntityIDChild by index or INVALID_ENTITY if out of range.
IsDescendantOf(EntityID entity, EntityID ancestor) constboolTrue when ancestor appears in parent chain.
SetParent(EntityID, EntityID parent, bool keepExistingChildren = false)boolRe-parent while updating both parent and child lists. keepExistingChildren is currently accepted for compatibility and not used yet.

Component Search Helpers

These convenience templates are available on Public::Engine:

APIReturnsPurpose
GetComponent<T>(EntityID) constT*Runtime lookup of a single component pointer.
GetComponentInChildren<T>(EntityID, bool includeSelf = true) constT*First matching component found by depth-first traversal.
GetEntitiesWithComponentInChildren<T>(EntityID, bool includeSelf = true) conststd::vector<EntityID>All matching entity IDs in the transform subtree.

Physics Convenience API

Public::Engine also mirrors many common PhysicsSystem body operations for gameplay convenience.

APIReturnsPurpose
HasPhysicsBody(EntityID) constboolCheck whether a body is created for this entity.
SetPhysicsSimulationEnabled(bool)boolEnable/disable global physics stepping.
IsPhysicsSimulationEnabled() constboolQuery simulation state.
SetPhysicsGravity(const float[3])boolSet world gravity.
GetPhysicsGravity(float[3]) constboolRead world gravity.
SetBodyLinearVelocity(EntityID, const float[3])boolSet body linear velocity.
GetBodyLinearVelocity(EntityID, float[3]) constboolRead body linear velocity.
AddBodyForce(EntityID, const float[3])boolAdd force each step.
AddBodyImpulse(EntityID, const float[3])boolAdd one-frame impulse.
SetBodyEnabled(EntityID, bool)boolEnable/disable a single body.
TryGetBodyEnabled(EntityID, bool&)boolRead body enabled state.
GetBodyTransform(EntityID, float[3], float[4]) constboolRead body pose.
SetBodyTransform(EntityID, const float[3], const float[4])boolWrite body pose.
TeleportRigidBody(EntityID, const float[3], const float[4] = nullptr)boolTeleport body position with optional rotation.
Raycast(const float[3], const float[3], float, PhysicsRaycastHit&) constboolWorld ray query; check hit.hit on success.

When you need simulation filters, body handles, or stepping control, use GetPhysicsSystem() directly.

Procedural Runtime Generation

auto pickup = engine.SpawnMeshEntity("assets/props/pickup.glb", {});

SpawnMeshEntity creates an entity with:

  • Transform (using provided transform)
  • MeshRenderer (mesh + material list)

If materialNames is empty or all names fail, fallback material is basic. Returned entity id is INVALID_ENTITY if load or component creation fails.

Public::ECS::Components::Transform spawnPoint{};
spawnPoint.position = {1.2f, 0.0f, -4.0f};
spawnPoint.scale = {0.5f, 0.5f, 0.5f};
auto enemy = engine.SpawnMeshEntity("assets/characters/enemy.glb",
                                   {"basic"},
                                   spawnPoint);

Custom Component Registration

For a scene JSON component type that is not built into the engine, register a creator before Initialize():

using json = nlohmann::json;

struct Spin {
    float speed = 1.0f;
};

inline void CreateSpinComponent(Public::ECS::EntityID entity, const json& data) {
    Spin spin{};
    spin.speed = data.value("speed", 1.0f);
    Public::Engine::getInstance().GetCoordinator().addComponent(entity, spin);
}

int main(int argc, char* argv[]) {
    auto& engine = Public::Engine::getInstance();
    engine.RegisterComponent("Spin", CreateSpinComponent);
    engine.Initialize();

    auto& coord = engine.GetCoordinator();
    coord.registerComponent<Spin>();
}

RegisterComponent stores pending registrations and forwards them to scene loading during Initialize(). The type name must match the scene component "type" string.

int main(int argc, char* argv[]) {
    Public::Debug::DebugManager::getInstance().Initialize("game.log");

    auto& engine = Public::Engine::getInstance();
    engine.GetFlagManager().passFlags(argc, argv);

    engine.RegisterComponent("Freecam", CreateFreecamComponent);
    engine.RegisterComponent("MonkeyRot", CreateMonkeyRotComponent);
    engine.Initialize();

    auto& coord = engine.GetCoordinator();
    coord.registerComponent<Freecam>();
    coord.registerComponent<MonkeyRot>();

    auto freecamSystem = coord.registerSystem<FreecamSystem>();
    auto monkeySystem = coord.registerSystem<MonkeyRotSystem>();

    engine.LoadScene("nevo_image1");

    while (engine.IsActive()) {
        engine.Loop();
    }

    engine.Shutdown();
}

Register scene creators before Initialize; register ECS storage/systems after Initialize.