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

#include <EngineDeterministicComponent.h>

Inheritance diagram for EngineDeterministicComponent:
ProxyPlatform ProxyOpenGLContext PlatformApplicationAware

Public Member Functions

 EngineDeterministicComponent ()
 
virtual ~EngineDeterministicComponent ()
 
void restart (int frameTimeMs, RandomEngineType rngType)
 
void finish ()
 
bool isActive () const
 

Private Member Functions

virtual int64_t tickCount () const override
 
virtual void swapBuffers () override
 
virtual void removeNotify () override
 
- Private Member Functions inherited from ProxyPlatform
 ProxyPlatform (Platform *base=nullptr)
 
virtual ~ProxyPlatform ()=default
 
virtual std::unique_ptr< PlatformWindowcreateWindow () override
 
virtual std::unique_ptr< PlatformEventLoopcreateEventLoop () override
 
virtual std::vector< PlatformGamepad * > gamepads () override
 
virtual void setCursorShown (bool cursorShown) override
 
virtual bool isCursorShown () const override
 
virtual std::vector< RectidisplayGeometries () const override
 
virtual void showMessageBox (const std::string &title, const std::string &message) const override
 
virtual int64_t tickCount () const override
 
- Private Member Functions inherited from ProxyBase< Platform >
 ProxyBase (Platform *base)
 
Platformbase () const
 
void setBase (Platform *base)
 
PlatformnonNullBase () const
 
- Private Member Functions inherited from Platform
virtual ~Platform ()=default
 
virtual std::unique_ptr< PlatformWindowcreateWindow ()=0
 
virtual std::unique_ptr< PlatformEventLoopcreateEventLoop ()=0
 
virtual std::vector< PlatformGamepad * > gamepads ()=0
 
virtual void setCursorShown (bool cursorShown)=0
 
virtual bool isCursorShown () const =0
 
virtual std::vector< RectidisplayGeometries () const =0
 
virtual void showMessageBox (const std::string &title, const std::string &message) const =0
 
virtual int64_t tickCount () const =0
 
- 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 PlatformApplicationAware
 ~PlatformApplicationAware ()=default
 
PlatformApplicationapplication () const
 
template<class T >
T * component () const
 
virtual void installNotify ()
 
virtual void removeNotify ()
 

Private Attributes

bool _active = false
 
int64_t _tickCount = 0
 
int _frameTimeMs = 0
 
RandomEngineType _oldRandomEngineType = RANDOM_ENGINE_MERSENNE_TWISTER
 

Friends

class PlatformIntrospection
 

Additional Inherited Members

- Static Private Member Functions inherited from Platform
static std::unique_ptr< PlatformcreateStandardPlatform ()
 

Detailed Description

This component can be used to make the engine more deterministic. It replaces the system timer with a fake one that advances by a fixed number of milliseconds each frame, and also resets the global random number generator.

Note that this component is intentionally very dumb. All the methods just do exactly what you would expect right away, so where you're calling them from becomes very important. E.g. calling restart from an event handler would probably make little sense.

Constructor & Destructor Documentation

◆ EngineDeterministicComponent()

EngineDeterministicComponent::EngineDeterministicComponent ( )
default

◆ ~EngineDeterministicComponent()

EngineDeterministicComponent::~EngineDeterministicComponent ( )
virtualdefault

Member Function Documentation

◆ finish()

void EngineDeterministicComponent::finish ( )

Leaves deterministic mode if currently is in it, does nothing otherwise.

◆ isActive()

bool EngineDeterministicComponent::isActive ( ) const
inline

◆ removeNotify()

void EngineDeterministicComponent::removeNotify ( )
overrideprivatevirtual

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

Reimplemented from PlatformApplicationAware.

◆ restart()

void EngineDeterministicComponent::restart ( int  frameTimeMs,
RandomEngineType  rngType 
)

Starts a new deterministic segment, resetting all state - rolls the tick count back to zero, and resets grng.

Why we're passing frame time in milliseconds here and not setting the target fps directly? For example, it is possible to target 60fps, but since the platform API is in milliseconds, this will result in staggered frame times, with every 1st and 2nd frame taking 17ms, and every 3rd one taking 16ms. This might result in some non-determinism down the line. Unlikely to really affect anything, but we'd rather not find out.

Parameters
frameTimeMsFrame time to use inside the segment, in milliseconds.
rngTypeRandom engine type to use inside the segment.

◆ swapBuffers()

void EngineDeterministicComponent::swapBuffers ( )
overrideprivatevirtual

Reimplemented from ProxyOpenGLContext.

◆ tickCount()

int64_t EngineDeterministicComponent::tickCount ( ) const
overrideprivatevirtual
Returns
Current value of a monotonic clock in milliseconds.

Reimplemented from ProxyPlatform.

Friends And Related Function Documentation

◆ PlatformIntrospection

friend class PlatformIntrospection
friend

Member Data Documentation

◆ _active

bool EngineDeterministicComponent::_active = false
private

◆ _frameTimeMs

int EngineDeterministicComponent::_frameTimeMs = 0
private

◆ _oldRandomEngineType

RandomEngineType EngineDeterministicComponent::_oldRandomEngineType = RANDOM_ENGINE_MERSENNE_TWISTER
private

◆ _tickCount

int64_t EngineDeterministicComponent::_tickCount = 0
private

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