Engine

SafiEngine::Engine is the core runtime class. It creates a window, initializes OpenGL 3.3 Core Profile, and runs the ECS-driven game loop.

Header: Core/include/Core/Engine.h

Constructor

Engine(int width, int height, const char *title, const std::string &assetsDir = ".")

Creates a GLFW window with an OpenGL 3.3 Core Profile context and initializes all subsystems.

ParameterTypeDescription
widthintWindow width in pixels
heightintWindow height in pixels
titleconst char*Window title
assetsDirconst std::string&Base directory for engine assets (default ".")

Subsystem Access

These methods are available in any behavior via the engine parameter:

MethodReturnsDescription
GetInput()Input&Keyboard, mouse, action mapping
GetPhysicsWorld()PhysicsWorld&Physics simulation and queries
GetAudioEngine()AudioEngine&Sound playback and 3D audio
GetWorld()flecs::world&ECS world for entity operations
GetEventBus()EventBus&Event publish/subscribe system
GetAssetManager()AssetManager&Asset loading and caching
GetDebugDraw()DebugDraw&Wireframe drawing (lines, boxes, spheres)
GetCameraUtils()CameraUtils&Camera helpers (follow, orbit, shake, zoom, screen/world projection)
GetRenderer()Renderer&View/projection matrices, shaders
GetDefaultShader()Shader&Default rendering shader

Camera

flecs::entity GetMainCamera()

Returns the entity with a Camera component where isMain == true. Returns an invalid entity if no main camera exists.

void SetMainCamera(flecs::entity camera)

Clears isMain on all Camera components, then sets isMain = true on the given entity. Use this to switch between cameras at runtime.

Timing

float GetDeltaTime() const

Returns the time elapsed since the last frame in seconds. Also available as the dt parameter in OnUpdate.

Play Mode

void SetPlaying(bool playing)
bool IsPlaying() const

Controls and queries play mode state. When playing, physics, behaviors, and animations are active. When stopped, only editor systems run.

View / Projection

const glm::mat4 &GetView() const
void SetView(const glm::mat4 &view)
const glm::mat4 &GetProjection() const
void SetProjection(const glm::mat4 &proj)

Get or set the current view and projection matrices. During play mode, these are set automatically by the CameraSystem from the main camera entity. During edit mode, they are set by the editor camera.

Window

GLFWwindow *GetWindow() const
int GetWidth() const
int GetHeight() const
void SetViewportSize(int width, int height)
const std::string &GetAssetsDir() const
bool IsValid() const

Run (Standalone)

void Run()

Starts the standalone game loop (used when running without the editor). Sets play mode to true and runs until the window is closed.