matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
engine::core::App Class Reference

Defines the base App class that serves as the application core structure and the entry point. More...

#include <App.hpp>

Inheritance diagram for engine::core::App:
Inheritance graph
[legend]

Public Member Functions

int run (int argc, char **argv)
 The main entry point into the App.
 
virtual ~App ()=default
 

Protected Member Functions

template<typename TController >
TController * register_controller ()
 Registers the controller for execution. The Controller instance that the register_controller returns isn't initialized yet. It will be initialized during the App::initialize. If the register_controller is called twice for the same controller, it's registered only once. The other calls just return the pointer to the already registered instance.
 

Private Member Functions

void engine_setup (int argc, char **argv)
 The first function that the engine calls to do its internal Controller classes engine_setup.
 
virtual void app_setup ()
 Override to define your custom app setup that gets called after engine engine_setup.
 
void initialize ()
 Initializes all the controllers registered in App::user_setup. Calls engine::Controller::initialize for registered controllers.
 
void poll_events ()
 Processes all pending events. Calls engine::Controller::poll_events for registered controllers.
 
bool loop ()
 Checks whether the render loop should continue executing. Calls engine::Controller::loop for registered controllers.
 
void update ()
 Updates the app logic state. Calls engine::Controller::update for registered controllers.
 
void draw ()
 Draws the frame. Calls engine::Controller::draw for registered controllers.
 
void terminate ()
 Terminates the app. Calls engine::Controller::terminate for registered controllers in the reverse order.
 
virtual int on_exit ()
 Called right before the App exits.
 
virtual void handle_error (const util::Error &)
 

Private Attributes

std::vector< Controller * > m_controllers
 

Detailed Description

Defines the base App class that serves as the application core structure and the entry point.

The main function calls App::run that defines the core structure of the application. You can hook into the engine execution by overriding the desired methods in your implementations of the engine::Controller class and registering your implementations via App::register_controller.

int App::run(int argc, char **argv) {
try {
engine_setup(argc, argv);
while (loop()) {
update();
draw();
}
} catch (const Error &e) {
}
return on_exit();
}
virtual void app_setup()
Override to define your custom app setup that gets called after engine engine_setup.
Definition App.cpp:115
void draw()
Draws the frame. Calls engine::Controller::draw for registered controllers.
Definition App.cpp:88
void terminate()
Terminates the app. Calls engine::Controller::terminate for registered controllers in the reverse ord...
Definition App.cpp:106
void initialize()
Initializes all the controllers registered in App::user_setup. Calls engine::Controller::initialize f...
Definition App.cpp:47
int run(int argc, char **argv)
The main entry point into the App.
Definition App.cpp:13
virtual void handle_error(const util::Error &)
Definition App.cpp:119
virtual int on_exit()
Called right before the App exits.
Definition App.hpp:144
void update()
Updates the app logic state. Calls engine::Controller::update for registered controllers.
Definition App.cpp:80
void engine_setup(int argc, char **argv)
The first function that the engine calls to do its internal Controller classes engine_setup.
Definition App.cpp:31
bool loop()
Checks whether the render loop should continue executing. Calls engine::Controller::loop for register...
Definition App.cpp:63
void poll_events()
Processes all pending events. Calls engine::Controller::poll_events for registered controllers.
Definition App.cpp:72

Constructor & Destructor Documentation

◆ ~App()

virtual engine::core::App::~App ( )
virtualdefault

Member Function Documentation

◆ run()

int engine::core::App::run ( int  argc,
char **  argv 
)

The main entry point into the App.

int App::run(int argc, char **argv) {
try {
engine_setup(argc, argv);
while (loop()) {
update();
draw();
}
} catch (const Error &e) {
}
return on_exit();
}

◆ engine_setup()

void engine::core::App::engine_setup ( int  argc,
char **  argv 
)
private

The first function that the engine calls to do its internal Controller classes engine_setup.

After the engine engine_setup is finished, engine_setup calls the App::user_setup(int argc, char** argv) that you can override and do your custom setup operations. This is where you should register your own controllers.

◆ app_setup()

void engine::core::App::app_setup ( )
privatevirtual

Override to define your custom app setup that gets called after engine engine_setup.

Reimplemented in engine::test::app::TestApp.

◆ initialize()

void engine::core::App::initialize ( )
private

Initializes all the controllers registered in App::user_setup. Calls engine::Controller::initialize for registered controllers.

After this functions finishes all the controllers have been initialized, and they can be now used by calling engine::core::Controller::get<TController>()

◆ poll_events()

void engine::core::App::poll_events ( )
private

Processes all pending events. Calls engine::Controller::poll_events for registered controllers.

It handles input events, system events, and any other types of events that have been queued. This is where the platform events are processed.

◆ loop()

bool engine::core::App::loop ( )
private

Checks whether the render loop should continue executing. Calls engine::Controller::loop for registered controllers.

This is where you should check if an internal or external event happened that stops the main render loop. For example the user presses ESC.

Returns
true if the main loop should continue, false otherwise.

◆ update()

void engine::core::App::update ( )
private

Updates the app logic state. Calls engine::Controller::update for registered controllers.

This is where all the App state should be updated including handling events registered in App::poll_events, processing physics, world logic etc.

◆ draw()

void engine::core::App::draw ( )
private

Draws the frame. Calls engine::Controller::draw for registered controllers.

This is where all the drawing should happen based on the state that the App::update computed.

◆ terminate()

void engine::core::App::terminate ( )
private

Terminates the app. Calls engine::Controller::terminate for registered controllers in the reverse order.

Terminate is called always, regardless of whether the app closes successfully or an error occurs.

◆ on_exit()

virtual int engine::core::App::on_exit ( )
inlineprivatevirtual

Called right before the App exits.

This where you can do custom operation when all the app state has already been terminated, and all the internal engine systems have been shutdown. This functions gets called just before the return from main.

Returns
The value that should be returned from the int main(...).

◆ handle_error()

void engine::core::App::handle_error ( const util::Error e)
privatevirtual

◆ register_controller()

template<typename TController >
TController * engine::core::App::register_controller ( )
inlineprotected

Registers the controller for execution. The Controller instance that the register_controller returns isn't initialized yet. It will be initialized during the App::initialize. If the register_controller is called twice for the same controller, it's registered only once. The other calls just return the pointer to the already registered instance.

Returns
Pointer to the only instance of the provided Controller class TController.

Member Data Documentation

◆ m_controllers

std::vector<Controller *> engine::core::App::m_controllers
private

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