The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
Public Member Functions | Protected Attributes | List of all members
LEventTimer Class Reference

The event timer. More...

#include <EventTimer.h>

Inheritance diagram for LEventTimer:
LComponent

Public Member Functions

 LEventTimer (const float, const float=0.0f)
 Constructor. More...
 
bool Triggered ()
 Check if triggered. More...
 
void SetDelay (const float)
 Set fixed delay between events. More...
 
void SetDelay (const float, const float)
 Set delay between events. More...
 

Protected Attributes

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 LComponent
static LTimerm_pTimer = &cTimer
 Pointer to a timer. More...
 
static LRandomm_pRandom = &cRandom
 Pointer to a PRNG. More...
 
static LKeyboardm_pKeyboard = &cKeyboard
 Pointer to a keyboard handler. More...
 
static LXBoxControllerm_pController = &cController
 Pointer to a XBox controller. More...
 
static LSoundm_pAudio = &cAudio
 Pointer to an audio player. More...
 

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

◆ LEventTimer()

LEventTimer::LEventTimer ( const float  fFixed,
const float  fVariable = 0.0f 
)

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

Parameters
fFixedThe fixed delay component.
fVariableThe fixed delay component, defaults to 0.

Member Function Documentation

◆ SetDelay() [1/2]

void LEventTimer::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 LEventTimer::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.

◆ Triggered()

bool LEventTimer::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. This function must be called at least once per frame to query and update this event.

Returns
true if the event is triggered.