matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
|
Controllers are a hook into the App main loop
execution. By overriding virtual functions of this class the user can execute custom code during each of the main loop
phases.
More...
#include <Controller.hpp>
Public Member Functions | |
virtual std::string_view | name () const |
virtual | ~Controller ()=default |
void | before (Controller *next) |
void | after (Controller *prev) |
const std::vector< Controller * > & | next () const |
bool | is_enabled () const |
Controller will execute as long this function returns true. | |
void | set_enable (bool value) |
Enables or disables the controller based on value. The ControllerManager executes only the enabled controllers, except for the Controller::poll_events function, that's executed always. By default, controllers are enabled when registered. | |
Static Public Member Functions | |
template<typename TController > | |
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. Make sure to register the controller via App::register_controller before calling this function. | |
Private Member Functions | |
void | mark_as_registered () |
bool | is_registered () const |
virtual void | initialize () |
Initializes the controller. Executes in the core::App::initialize. | |
virtual bool | loop () |
Checks whether the main loop should continue. Executes in the core::App::loop. | |
virtual void | poll_events () |
Process internal and external events. Executes in the core::App::poll_events. | |
virtual void | update () |
Update the controller state and prepare for drawing. Executes in the core::App::update. | |
virtual void | begin_draw () |
Perform preparation for drawing. Executes in the core::App::draw, before Controller::draw. | |
virtual void | draw () |
Draw the world state. Executes in the core::App::draw. | |
virtual void | end_draw () |
Finalize drawing. Executes in the core::App::draw, after Controller::draw. | |
virtual void | terminate () |
Terminate the controller. Executes in the core::App::terminate. | |
Static Private Member Functions | |
template<typename TController > | |
static TController * | create_if_absent () |
Private Attributes | |
std::vector< Controller * > | m_next {} |
List of controllers that are dependent on this controller. If controller A is in the m_next , that means that this Controller will execute before the controller A . | |
bool | m_registered {false} |
Internal Controller field used to ensure that the controller isn't registered twice. | |
bool | m_enabled {true} |
Internal field used to control weather the ControllerManager executes the controller. | |
Friends | |
class | App |
Controllers are a hook into the App main loop
execution. By overriding virtual functions of this class the user can execute custom code during each of the main loop
phases.
Register controller with App::register_controller during the App::app_setup function.
Every controller instance is a singleton instance that is managed by the App. There can be no two instances of the same controller.
@usage
To have the engine execute the code from the LoggingController
we must first register it:
|
virtualdefault |
|
inlinestatic |
Serves as a single access point for all the Controller types throughout the code base. Make sure to register the controller via App::register_controller before calling this function.
|
inlinevirtual |
Returns the controller class name; used for logging.
Reimplemented in engine::core::EngineControllersBegin, engine::core::EngineControllersEnd, engine::graphics::GraphicsController, engine::platform::PlatformController, and engine::resources::ResourcesController.
|
inline |
Orders the controller next
to be after this
controller. All the virtual member methods of the controller this
will always execute before the member functions of the controller next
.
|
inline |
Orders the controller this
to be after prev
controller. All the virtual member methods of the controller prev
will always execute before the member functions of the controller this
.
|
inline |
Returns the controllers that have a direct dependency to this
controller.
this
|
inline |
Controller will execute as long this function returns true.
You can turn the controller on/off by calling Controller::enable Controller::disable
Enables or disables the controller based on value. The ControllerManager executes only the enabled controllers, except for the Controller::poll_events function, that's executed always. By default, controllers are enabled when registered.
|
inlineprivate |
|
inlineprivate |
Initializes the controller. Executes in the core::App::initialize.
Reimplemented in engine::graphics::GraphicsController, engine::platform::PlatformController, engine::resources::ResourcesController, engine::test::app::GUIController, and engine::test::app::MainController.
Checks whether the main loop should continue. Executes in the core::App::loop.
Reimplemented in engine::platform::PlatformController, and engine::test::app::MainController.
Process internal and external events. Executes in the core::App::poll_events.
Reimplemented in engine::platform::PlatformController, engine::test::app::GUIController, and engine::test::app::MainController.
Update the controller state and prepare for drawing. Executes in the core::App::update.
Reimplemented in engine::test::app::MainController.
Perform preparation for drawing. Executes in the core::App::draw, before Controller::draw.
Reimplemented in engine::test::app::MainController.
Draw the world state. Executes in the core::App::draw.
Reimplemented in engine::test::app::GUIController, and engine::test::app::MainController.
Finalize drawing. Executes in the core::App::draw, after Controller::draw.
Reimplemented in engine::test::app::MainController.
Terminate the controller. Executes in the core::App::terminate.
Note that the terminate
executes in the reverse order from initialize.
Reimplemented in engine::graphics::GraphicsController, and engine::platform::PlatformController.
|
inlinestaticprivate |
|
private |
List of controllers that are dependent on this controller. If controller A
is in the m_next
, that means that this
Controller will execute before the controller A
.
Internal Controller field used to ensure that the controller isn't registered twice.
Internal field used to control weather the ControllerManager executes the controller.