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
App.hpp
Go to the documentation of this file.
1
6#ifndef APP_H
7#define APP_H
8
9namespace engine::util {
10 class Error;
11}
12
13#include <vector>
14
15namespace engine::core {
16 class Controller;
45 class App {
46 public:
69 int run(int argc, char **argv);
70
71 private:
79 void engine_setup(int argc, char **argv);
80
84 virtual void app_setup();
85
92 void initialize();
93
100 void poll_events();
101
110 bool loop();
111
118 void update();
119
126 void draw();
127
133 void terminate();
134
144 virtual int on_exit() {
145 return 0;
146 }
147
148 virtual void handle_error(const util::Error &);
149
150 protected:
159 template<typename TController>
160 TController *register_controller() {
161 TController *controller = TController::template create_if_absent<TController>();
162 if (!controller->is_registered()) {
163 m_controllers.push_back(controller);
164 controller->mark_as_registered();
165 }
166 return controller;
167 }
168
169 public:
170 virtual ~App() = default;
171
172 private:
173 std::vector<Controller *> m_controllers;
174 };
175} // namespace engine
176
177#endif//APP_H
178
Defines the base App class that serves as the application core structure and the entry point.
Definition App.hpp:45
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
TController * register_controller()
Registers the controller for execution. The Controller instance that the register_controller returns ...
Definition App.hpp:160
std::vector< Controller * > m_controllers
Definition App.hpp:173
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
virtual ~App()=default
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
Controllers are a hook into the App main loop execution. By overriding virtual functions of this clas...
Definition Controller.hpp:42
Base class for all errors.
Definition Errors.hpp:22
Definition App.hpp:15
Definition App.hpp:9