matf-rg-engine  1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
App.hpp
Go to the documentation of this file.
1 
6 #ifndef APP_H
7 #define APP_H
8 
9 namespace engine::util {
10  class Error;
11 }
12 
13 #include <vector>
14 
15 namespace engine::core {
16  class Controller;
45  class App {
46  public:
69  int run(int argc, char **argv);
70 
71  private:
75  void engine_setup(int argc, char **argv);
76 
80  virtual void app_setup();
81 
88  void initialize();
89 
96  void poll_events();
97 
106  bool loop();
107 
114  void update();
115 
122  void draw();
123 
129  void terminate();
130 
140  virtual int on_exit() {
141  return 0;
142  }
143 
144  virtual void handle_error(const util::Error &);
145 
146  protected:
155  template<typename TController>
156  TController *register_controller() {
157  TController *controller = TController::template create_if_absent<TController>();
158  if (!controller->is_registered()) {
159  m_controllers.push_back(controller);
160  controller->mark_as_registered();
161  }
162  return controller;
163  }
164 
165  public:
166  virtual ~App() = default;
167 
168  private:
169  std::vector<Controller *> m_controllers;
170  };
171 } // namespace engine
172 
173 #endif//APP_H
174 
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 the engine_setup.
Definition: App.cpp:115
void draw()
Draws the frame. Calls engine::core::Controller::draw for registered controllers.
Definition: App.cpp:88
void terminate()
Terminates the app. Calls engine::core::Controller::terminate for registered controllers in the rever...
Definition: App.cpp:106
void initialize()
Initializes all the controllers registered in App::app_setup. Calls engine::core::Controller::initial...
Definition: App.cpp:47
int run(int argc, char **argv)
The main entry point into the App.
Definition: App.cpp:13
std::vector< Controller * > m_controllers
Definition: App.hpp:169
virtual void handle_error(const util::Error &)
Definition: App.cpp:119
virtual int on_exit()
Called right before the App exits.
Definition: App.hpp:140
void update()
Updates the app logic state. Calls engine::core::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::core::Controller::loop for re...
Definition: App.cpp:63
TController * register_controller()
Registers the controller for execution. The Controller instance that the register_controller returns ...
Definition: App.hpp:156
void poll_events()
Processes all pending events. Calls engine::core::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:41
Base class for all errors.
Definition: Errors.hpp:22
Definition: App.hpp:15
Definition: App.hpp:9