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 | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
engine::core::Controller Class Reference

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>

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

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 TControllerget (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
 

Detailed Description

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

class LoggingController : public engine::Controller {
public:
void initialize() override { spdlog::log("Logging::initialize"); }
void terminate() override { spdlog::log("Logging::terminate"); }
};
virtual void initialize()
Initializes the controller. Executes in the core::App::initialize.
Definition Controller.hpp:129
static TController * create_if_absent()
Definition Controller.hpp:179
virtual void terminate()
Terminate the controller. Executes in the core::App::terminate.
Definition Controller.hpp:175

To have the engine execute the code from the LoggingController we must first register it:

void MyApp::app_setup() {
}

Constructor & Destructor Documentation

◆ ~Controller()

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

Member Function Documentation

◆ get()

template<typename TController >
static TController * engine::core::Controller::get ( std::source_location  location = std::source_location::current())
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.

Returns
The only instance of the TController.

◆ name()

virtual std::string_view engine::core::Controller::name ( ) const
inlinevirtual

◆ before()

void engine::core::Controller::before ( Controller next)
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.

◆ after()

void engine::core::Controller::after ( Controller prev)
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.

◆ next()

const std::vector< Controller * > & engine::core::Controller::next ( ) const
inline

Returns the controllers that have a direct dependency to this controller.

Returns
Controllers executing after this

◆ is_enabled()

bool engine::core::Controller::is_enabled ( ) const
inline

Controller will execute as long this function returns true.

You can turn the controller on/off by calling Controller::enable Controller::disable

◆ set_enable()

void engine::core::Controller::set_enable ( bool  value)
inline

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.

◆ mark_as_registered()

void engine::core::Controller::mark_as_registered ( )
inlineprivate

◆ is_registered()

bool engine::core::Controller::is_registered ( ) const
inlineprivate

◆ initialize()

virtual void engine::core::Controller::initialize ( )
inlineprivatevirtual

◆ loop()

virtual bool engine::core::Controller::loop ( )
inlineprivatevirtual

Checks whether the main loop should continue. Executes in the core::App::loop.

Returns
true if the render loop should continue.

Reimplemented in engine::platform::PlatformController, and engine::test::app::MainController.

◆ poll_events()

virtual void engine::core::Controller::poll_events ( )
inlineprivatevirtual

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()

virtual void engine::core::Controller::update ( )
inlineprivatevirtual

Update the controller state and prepare for drawing. Executes in the core::App::update.

Reimplemented in engine::test::app::MainController.

◆ begin_draw()

virtual void engine::core::Controller::begin_draw ( )
inlineprivatevirtual

Perform preparation for drawing. Executes in the core::App::draw, before Controller::draw.

Reimplemented in engine::test::app::MainController.

◆ draw()

virtual void engine::core::Controller::draw ( )
inlineprivatevirtual

Draw the world state. Executes in the core::App::draw.

Reimplemented in engine::test::app::GUIController, and engine::test::app::MainController.

◆ end_draw()

virtual void engine::core::Controller::end_draw ( )
inlineprivatevirtual

Finalize drawing. Executes in the core::App::draw, after Controller::draw.

Reimplemented in engine::test::app::MainController.

◆ terminate()

virtual void engine::core::Controller::terminate ( )
inlineprivatevirtual

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.

◆ create_if_absent()

template<typename TController >
static TController * engine::core::Controller::create_if_absent ( )
inlinestaticprivate

Friends And Related Symbol Documentation

◆ App

friend class App
friend

Member Data Documentation

◆ m_next

std::vector<Controller *> engine::core::Controller::m_next {}
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.

◆ m_registered

bool engine::core::Controller::m_registered {false}
private

Internal Controller field used to ensure that the controller isn't registered twice.

◆ m_enabled

bool engine::core::Controller::m_enabled {true}
private

Internal field used to control weather the ControllerManager executes the controller.


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