SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CEventTimer Class Reference

The event timer. More...

#include <SageEventTimer.h>

Inheritance diagram for Sage::CEventTimer:
Collaboration diagram for Sage::CEventTimer:

Public Member Functions

 CEventTimer (float, bool=false)
 Constructor.
 
 CEventTimer (float, float, bool=false)
 Constructor.
 
bool Triggered ()
 Check if triggered.
 
void SetDelay (const float)
 Set fixed delay between events.
 
void SetDelay (const float, const float)
 Set delay between events.
 
void Start ()
 Start event.
 

Protected Attributes

bool m_bOnce = false
 Whether event happens once only.
 
bool m_bRunning = true
 Whether the event is running.
 
float m_fLastEvent = 0
 Last time event triggered.
 
float m_fCurDelay = 0
 Current delay to next trigger.
 
float m_fFixedDelay = 0
 Fixed component of delay time.
 
float m_fVbleDelay = 0
 Variable component of delay time.
 

Additional Inherited Members

- Static Protected Attributes inherited from Sage::CComponent
static std::unique_ptr< CTimerm_pTimer = std::make_unique<CTimer>()
 Pointer to a timer.
 
static std::unique_ptr< CRandomm_pRandom = std::make_unique<CRandom>()
 Pointer to a PRNG.
 
static std::unique_ptr< CSoundm_pSound = std::make_unique<CSound>()
 Pointer to sound manager.
 
static std::unique_ptr< CKeyboardm_pKeyboard
 Pointer to a keyboard handler.
 
static std::unique_ptr< CMousem_pMouse = std::make_unique<CMouse>()
 Pointer to a mouse handler.
 
static std::unique_ptr< CControllerm_pController
 Pointer to a controller.
 

Detailed Description

The event timer triggers regularly with a random delay time that consists of a fixed component and a variable component. The current delay time, which is computed each time the event is triggered, is computed to be the fixed delay component plus a random fraction of the variable delay component. Function Triggered() must be called at least once per frame to query and update the event.

Constructor & Destructor Documentation

◆ CEventTimer() [1/2]

CEventTimer::CEventTimer ( float fFixed,
bool bOnce = false )

Set the last trigger time to now and compute the current delay time.

Parameters
fFixedThe fixed delay component.
bOnceTrue if event happens once. Defaults to false.

◆ CEventTimer() [2/2]

CEventTimer::CEventTimer ( float fFixed,
float fVariable,
bool bOnce = false )

Set the last trigger time to now and compute the current delay time.

Parameters
fFixedThe fixed delay component.
fVariableThe fixed delay component.
bOnceTrue if event happens once. Defaults to false.

Member Function Documentation

◆ SetDelay() [1/2]

void CEventTimer::SetDelay ( const float ft)

Set the fixed delay and make the variable delay zero, compute the current delay.

Parameters
ftFixed delay time.

◆ SetDelay() [2/2]

void CEventTimer::SetDelay ( const float ft,
const float vt )

Set the fixed and variable delay and compute the current delay.

Parameters
ftFixed delay time.
vtVariable delay time.

◆ Start()

void CEventTimer::Start ( )

Start the event.

◆ Triggered()

bool CEventTimer::Triggered ( )

The event trigger test. If delay time has passed since last time this event was triggered, then trigger it, that is, record the current time, compute a new delay time, and return true. The new delay time equals the fixed delay component plus a random fraction of the variable delay component.

Returns
true if the event is triggered.