Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Engine Class Reference

#include <engine.hpp>

Public Member Functions

 Engine (std::string _appName="Calamity App")
 
 ~Engine ()
 
int appendWindow (std::shared_ptr< Window > window)
 
void removeWindow (int id)
 
std::shared_ptr< WindowgetWindow (int id)
 
void update ()
 
void render (Graphics &graphics)
 
void initialize ()
 
void exit ()
 
template<class Archive >
void serialize (Archive &ar)
 

Public Attributes

const std::string appName
 
float physicsTimestep = 1.0f / 60.0f
 
float accumulator = 0.0f
 
Uint64 now = SDL_GetPerformanceCounter()
 
Uint64 last = 0
 

Detailed Description

Engine

This class is mostly used to abstract stuff like the root node and obtaining deltaTime. It determines when the lifetime functions of every other node and component is called.

The engine class should be initialized in the main function after nodes are setup and have its update and render functions called in the main loop. In the end, the engine.exit() function should be called. Also, the engines constructor defines the app name which is used when reading/writing to the user folder. All Calamity Engine apps are stored under the Calamity Engine base folder and the app name is used as the organization folder. For more information read this SDL3 wiki page.

You also must append atleast 1 Window to the engine for anything to render to the screen.

Graphics graphics = Graphics();
Engine engine = Engine("Your app name goes here");
auto window = std::make_shared<Window>("my window title", Rect({0, 0}, {480, 272}), RenderLogicalPresentation::LETTERBOX, WindowFlags::RESIZABLE, Color::BLACK);
engine.appendWindow(window);
Services::init(&graphics, &engine, ...); // imagine every other core service in here aswell
// setup nodes, components, etc here
engine->initialize();
while (!input.shouldQuit) {
engine.update();
}
engine.exit();
static const Color BLACK
Definition definitions.hpp:59
Definition engine.hpp:35
int appendWindow(std::shared_ptr< Window > window)
Definition engine.cpp:129
void initialize()
Definition engine.cpp:61
void render(Graphics &graphics)
Definition engine.cpp:118
void update()
Definition engine.cpp:70
void exit()
Definition engine.cpp:102
Definition graphics.hpp:26
static void init(Graphics *graphics, Physics *physics, Engine *engine, Input *input, InputRegistry *inputRegistry, Audio *audio)
Definition services.cpp:13
static Graphics * graphics()
Definition services.cpp:23
Definition definitions.hpp:294

Constructor & Destructor Documentation

◆ Engine()

Engine::Engine ( std::string  _appName = "Calamity App")

◆ ~Engine()

Engine::~Engine ( )

Member Function Documentation

◆ appendWindow()

int Engine::appendWindow ( std::shared_ptr< Window window)

◆ exit()

void Engine::exit ( )

◆ getWindow()

std::shared_ptr< Window > Engine::getWindow ( int  id)

◆ initialize()

void Engine::initialize ( )

◆ removeWindow()

void Engine::removeWindow ( int  id)

◆ render()

void Engine::render ( Graphics graphics)

◆ serialize()

template<class Archive >
void Engine::serialize ( Archive &  ar)
inline

◆ update()

void Engine::update ( )

Member Data Documentation

◆ accumulator

float Engine::accumulator = 0.0f

◆ appName

const std::string Engine::appName

◆ last

Uint64 Engine::last = 0

◆ now

Uint64 Engine::now = SDL_GetPerformanceCounter()

◆ physicsTimestep

float Engine::physicsTimestep = 1.0f / 60.0f

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