OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
EngineControlComponent Class Reference

#include <EngineControlComponent.h>

Inheritance diagram for EngineControlComponent:
ProxyOpenGLContext ProxyEventLoop PlatformApplicationAware

Public Types

using ControlRoutine = std::function< void(EngineController *)>
 

Public Member Functions

 EngineControlComponent ()
 
virtual ~EngineControlComponent ()
 
void runControlRoutine (ControlRoutine routine)
 
bool hasControlRoutine () const
 

Private Member Functions

void processSyntheticEvents (PlatformEventHandler *eventHandler, int count=-1)
 
virtual void exec (PlatformEventHandler *eventHandler) override
 
virtual void processMessages (PlatformEventHandler *eventHandler, int count) override
 
virtual void waitForMessages () override
 
virtual void swapBuffers () override
 
virtual void removeNotify () override
 
- Private Member Functions inherited from ProxyOpenGLContext
 ProxyOpenGLContext (PlatformOpenGLContext *base=nullptr)
 
virtual ~ProxyOpenGLContext ()=default
 
virtual bool bind () override
 
virtual bool unbind () override
 
virtual void * nativeHandle () override
 
virtual void swapBuffers () override
 
virtual void * getProcAddress (const char *name) override
 
- Private Member Functions inherited from ProxyBase< PlatformOpenGLContext >
 ProxyBase (PlatformOpenGLContext *base)
 
PlatformOpenGLContextbase () const
 
void setBase (PlatformOpenGLContext *base)
 
PlatformOpenGLContextnonNullBase () const
 
- Private Member Functions inherited from PlatformOpenGLContext
virtual ~PlatformOpenGLContext ()=default
 
virtual bool bind ()=0
 
virtual bool unbind ()=0
 
virtual void * nativeHandle ()=0
 
virtual void swapBuffers ()=0
 
virtual void * getProcAddress (const char *name)=0
 
- Private Member Functions inherited from ProxyEventLoop
 ProxyEventLoop (PlatformEventLoop *base=nullptr)
 
virtual ~ProxyEventLoop ()=default
 
virtual void exec (PlatformEventHandler *eventHandler) override
 
virtual void quit () override
 
virtual void processMessages (PlatformEventHandler *eventHandler, int count=-1) override
 
virtual void waitForMessages () override
 
- Private Member Functions inherited from ProxyBase< PlatformEventLoop >
 ProxyBase (PlatformEventLoop *base)
 
PlatformEventLoopbase () const
 
void setBase (PlatformEventLoop *base)
 
PlatformEventLoopnonNullBase () const
 
- Private Member Functions inherited from PlatformEventLoop
virtual ~PlatformEventLoop ()=default
 
virtual void exec (PlatformEventHandler *eventHandler)=0
 
virtual void quit ()=0
 
virtual void processMessages (PlatformEventHandler *eventHandler, int count=-1)=0
 
virtual void waitForMessages ()=0
 
- Private Member Functions inherited from PlatformApplicationAware
 ~PlatformApplicationAware ()=default
 
PlatformApplicationapplication () const
 
template<class T >
T * component () const
 
virtual void installNotify ()
 
virtual void removeNotify ()
 

Private Attributes

std::thread _controlThread
 
std::unique_ptr< EngineControlState_unsafeState
 
EngineControlStateHandle _state
 
std::unique_ptr< PlatformEventHandler_emptyHandler
 

Friends

class PlatformIntrospection
 

Detailed Description

This component exposes a coroutine-like API that makes it possible to control the game by passing in synthetic platform events.

The implementation just uses a separate thread that runs a control routine, and the execution can switch between threads from inside the swapBuffers call. This effectively means that the control routine runs in between game frames.

If the control component is destroyed while the control routine is still running, the control routine will be terminated by throwing an exception from inside EngineController. If you use catch(...) inside the control routine then this won't work (e.g. google test does this).

See also
EngineController

Member Typedef Documentation

◆ ControlRoutine

Constructor & Destructor Documentation

◆ EngineControlComponent()

EngineControlComponent::EngineControlComponent ( )

◆ ~EngineControlComponent()

EngineControlComponent::~EngineControlComponent ( )
virtual

Member Function Documentation

◆ exec()

void EngineControlComponent::exec ( PlatformEventHandler eventHandler)
overrideprivatevirtual

Starts this event loop.

This function blocks until either quit is called from inside the event handler code, or an application is closed by the user (e.g. after the last window is closed, or Command+Q is pressed on Mac).

Parameters
eventHandlerCallback for event processing.

Reimplemented from ProxyEventLoop.

◆ hasControlRoutine()

bool EngineControlComponent::hasControlRoutine ( ) const
Returns
Whether there is a control routine running or queued.

◆ processMessages()

void EngineControlComponent::processMessages ( PlatformEventHandler eventHandler,
int  count 
)
overrideprivatevirtual

Processes the messages that are currently in the message queue, and returns. Returns immediately if there are no messages in the message queue.

Parameters
eventHandlerCallback for event processing.
countMaximum number of messages to process, -1 means unlimited.

Reimplemented from ProxyEventLoop.

◆ processSyntheticEvents()

void EngineControlComponent::processSyntheticEvents ( PlatformEventHandler eventHandler,
int  count = -1 
)
private

◆ removeNotify()

void EngineControlComponent::removeNotify ( )
overrideprivatevirtual

Called before removal from a PlatformApplication. application() will return non-null inside this function.

Reimplemented from PlatformApplicationAware.

◆ runControlRoutine()

void EngineControlComponent::runControlRoutine ( ControlRoutine  routine)

Schedules a control routine for execution. It will be started in a control thread from inside the next swapBuffers call. All spontaneous (OS-generated) events will be blocked while the control routine is running.

If another control routine is already running, passed routine will be added to the queue.

Don't call this function from a control thread, just call the control routine directly.

Note that it's up to the user to set up a notification for when the control routine has finished.

Parameters
routineControl routine to schedule.

◆ swapBuffers()

void EngineControlComponent::swapBuffers ( )
overrideprivatevirtual

Reimplemented from ProxyOpenGLContext.

◆ waitForMessages()

void EngineControlComponent::waitForMessages ( )
overrideprivatevirtual

Blocks until at least one message is delivered to the queue, and returns.

Reimplemented from ProxyEventLoop.

Friends And Related Function Documentation

◆ PlatformIntrospection

friend class PlatformIntrospection
friend

Member Data Documentation

◆ _controlThread

std::thread EngineControlComponent::_controlThread
private

◆ _emptyHandler

std::unique_ptr<PlatformEventHandler> EngineControlComponent::_emptyHandler
private

◆ _state

EngineControlStateHandle EngineControlComponent::_state
private

◆ _unsafeState

std::unique_ptr<EngineControlState> EngineControlComponent::_unsafeState
private

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