6#ifndef MATF_RG_PROJECT_CONTROLLER_HPP
7#define MATF_RG_PROJECT_CONTROLLER_HPP
52 template<
typename TController>
53 static TController *
get(std::source_location location = std::source_location::current()) {
54 static_assert(std::is_base_of_v<Controller, TController>);
57 "Trying to get an unregistered controller in: {}:{}.\nPlease call register_controller<> first during App::app_setup.",
58 location.file_name(), location.line());
66 virtual std::string_view
name()
const {
67 return typeid(*this).name();
78 this->
m_next.push_back(next);
94 const std::vector<Controller *> &
next()
const {
178 template<
typename TController>
180 static_assert(std::is_base_of_v<Controller, TController>);
181 static std::unique_ptr<TController>
controller = std::make_unique<TController>();
219 std::string_view
name()
const override {
220 return "EngineControllersBegin";
240 std::string_view
name()
const override {
241 return "EngineControllersEnd";
Defines Error, UserError, and EngineError classes, along with macros for error handling.
#define RG_GUARANTEE(expr, msg,...)
Guarantees that an expression is true. If it is not, an engine::util::EngineError is thrown.
Definition Errors.hpp:164
Defines the base App class that serves as the application core structure and the entry point.
Definition App.hpp:45
Controllers are a hook into the App main loop execution. By overriding virtual functions of this clas...
Definition Controller.hpp:42
virtual void initialize()
Initializes the controller. Executes in the core::App::initialize.
Definition Controller.hpp:129
virtual void begin_draw()
Perform preparation for drawing. Executes in the core::App::draw, before Controller::draw.
Definition Controller.hpp:155
const std::vector< Controller * > & next() const
Definition Controller.hpp:94
void before(Controller *next)
Definition Controller.hpp:77
std::vector< Controller * > m_next
List of controllers that are dependent on this controller. If controller A is in the m_next,...
Definition Controller.hpp:190
void set_enable(bool value)
Enables or disables the controller based on value. The ControllerManager executes only the enabled co...
Definition Controller.hpp:113
void mark_as_registered()
Definition Controller.hpp:118
static TController * get(std::source_location location=std::source_location::current())
Serves as a single access point for all the Controller types throughout the code base....
Definition Controller.hpp:53
bool m_enabled
Internal field used to control weather the ControllerManager executes the controller.
Definition Controller.hpp:200
virtual std::string_view name() const
Definition Controller.hpp:66
virtual ~Controller()=default
virtual void draw()
Draw the world state. Executes in the core::App::draw.
Definition Controller.hpp:161
virtual bool loop()
Checks whether the main loop should continue. Executes in the core::App::loop.
Definition Controller.hpp:136
bool m_registered
Internal Controller field used to ensure that the controller isn't registered twice.
Definition Controller.hpp:195
virtual void poll_events()
Process internal and external events. Executes in the core::App::poll_events.
Definition Controller.hpp:143
static TController * create_if_absent()
Definition Controller.hpp:179
void after(Controller *prev)
Definition Controller.hpp:86
bool is_enabled() const
Controller will execute as long this function returns true.
Definition Controller.hpp:103
virtual void update()
Update the controller state and prepare for drawing. Executes in the core::App::update.
Definition Controller.hpp:149
virtual void end_draw()
Finalize drawing. Executes in the core::App::draw, after Controller::draw.
Definition Controller.hpp:167
bool is_registered() const
Definition Controller.hpp:122
virtual void terminate()
Terminate the controller. Executes in the core::App::terminate.
Definition Controller.hpp:175
This controller does nothing and together with EngineControllersEnd it servers as a sentinel controll...
Definition Controller.hpp:217
std::string_view name() const override
Definition Controller.hpp:219
This controller does nothing and together with EngineControllersEnd it servers as a sentinel controll...
Definition Controller.hpp:238
std::string_view name() const override
Definition Controller.hpp:240