Skip to content

Getting Started with Application

This guide demonstrates how to create and run an Astra application.

Basic Application

Every Astra application follows three steps: initialize, start, then run.

cpp
#include "application.hpp"

using namespace astralix;

int main() {
    Application* app = Application::init();
    app->start();
    app->run(); // blocks until window closes, then cleans up
    return 0;
}

What init() Sets Up

Application::init() creates the singleton instance and initializes all core subsystems in order:

  1. EventDispatcher
  2. EventScheduler
  3. Time
  4. ProjectManager
  5. Engine
  6. SystemManager
  7. WindowManager

What start() Does

start() activates the three runtime subsystems:

  • WindowManager - opens the window and prepares the rendering context
  • Engine - starts the ECS engine
  • SystemManager - starts all registered systems

The Run Loop

run() executes the main loop until the window is closed, then deletes the application instance:

while window is open:
    time->update()
    wm->update()
    scheduler POST_FRAME events
    system->fixed_update(1/60)
    system->update(deltaTime)
    scheduler IMMEDIATE events
    wm->swap()

// on exit: ~Application() ends Engine, Time, WindowManager

The destructor handles cleanup automatically - no explicit shutdown call is needed.

Accessing From Anywhere

Use the static accessor to retrieve the singleton from any context:

cpp
Application* app = Application::get();

Explicit Teardown

If you need to destroy the application before run() exits (e.g. in a headless context), call:

cpp
Application::end();

This deletes the instance and triggers the same destructor cleanup as the normal run loop exit.

Next Steps

  • Learn about the Engine module for ECS architecture
  • Explore Window for input and rendering context
  • Review Project for configuration management