OpenEnroth 73e68f7
|
#include <EngineControlComponent.h>
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) | |
PlatformOpenGLContext * | base () const |
void | setBase (PlatformOpenGLContext *base) |
PlatformOpenGLContext * | nonNullBase () 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) | |
PlatformEventLoop * | base () const |
void | setBase (PlatformEventLoop *base) |
PlatformEventLoop * | nonNullBase () 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 | |
PlatformApplication * | application () 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 |
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).
using EngineControlComponent::ControlRoutine = std::function<void(EngineController *)> |
EngineControlComponent::EngineControlComponent | ( | ) |
|
virtual |
|
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).
eventHandler | Callback for event processing. |
Reimplemented from ProxyEventLoop.
bool EngineControlComponent::hasControlRoutine | ( | ) | const |
|
overrideprivatevirtual |
Processes the messages that are currently in the message queue, and returns. Returns immediately if there are no messages in the message queue.
eventHandler | Callback for event processing. |
count | Maximum number of messages to process, -1 means unlimited. |
Reimplemented from ProxyEventLoop.
|
private |
|
overrideprivatevirtual |
Called before removal from a PlatformApplication
. application()
will return non-null inside this function.
Reimplemented from PlatformApplicationAware.
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.
routine | Control routine to schedule. |
|
overrideprivatevirtual |
Reimplemented from ProxyOpenGLContext.
|
overrideprivatevirtual |
Blocks until at least one message is delivered to the queue, and returns.
Reimplemented from ProxyEventLoop.
|
friend |
|
private |
|
private |
|
private |
|
private |