Wraith  0.1.5
Basic 3D game engine in C++

Each GameObject has up to 3 alarms to used. NOTE: GameObject Entity must be registered in order to process GameObject::alarm0, GameObject::alarm1, and GameObject::alarm2 callbacks. More...

Collaboration diagram for Alarms:

Enumerations

enum class  AlarmID { ALARM_0 , ALARM_1 , ALARM_2 }
 Values that represent alarm Identifiers. More...
 

Functions

void Alarmable::submitAlarmRegistration (float timeDelay, AlarmID alarmID)
 Submit alarm registration to the current scene. More...
 
void Alarmable::submitAlarmDeregistration (AlarmID alarmID)
 Submit alarm deregistration to the current scene. More...
 
bool Alarmable::isRegisteredForAlarm (AlarmID alarmID) const
 Query if 'alarmID' is registered. More...
 
float Alarmable::getTimeLeftForAlarm (AlarmID alarmID) const
 Gets time left for a given alarm. More...
 
virtual void Alarmable::alarm0 ()
 Alarm 0. More...
 
virtual void Alarmable::alarm1 ()
 Alarm 1. More...
 
virtual void Alarmable::alarm2 ()
 Alarm 2. More...
 

Detailed Description

Each GameObject has up to 3 alarms to used. NOTE: GameObject Entity must be registered in order to process GameObject::alarm0, GameObject::alarm1, and GameObject::alarm2 callbacks.

Alarms are simple countdown mechanism to help control time-based events. Uses AlarmID for setting a specific alarm. Below is a simple example of a self-resetting alarm to make the Tank shoot at a constant rate

Tank::Tank( )
{
_fireBulletDelay = 2.0f;
GameObject::submitAlarmRegistration(_fireBulletDelay, AlarmID::ALARM_0); // sets Alarm 0 to go off in 2 secs
_moveTimeDelay = 5.5f;
GameObject::submitAlarmRegistration(_moveTimeDelay, AlarmabaleManager::AlarmID::ALARM_1); // set Alarm 1 to go off in 5 secs
_terminationTimeDelay = 60.0f;
GameObject::submitAlarmRegistration(_terminationTimeDelay, AlarmabaleManager::AlarmID::ALARM_2); // set Alarm 2 to go off in 60 secs
}
void Tank::alarm0() // This is the Alarm0 callback
{
this->fireBullet();
GameObject::submitAlarmRegistration(_fireBulletDelay, AlarmID::ALARM_0); // sets Alarm 0 to go off in 2 secs
}
void Tank::alarm1() // This is the Alarm1 callback
{
Vect randomLocation = generateRandomPosition();
this->moveHere(randomLocation);
GameObject::submitAlarmRegistration(_timeDelay, AlarmID::ALARM_1); // resets Alarm 1 to go off in 5 secs
}
void Tank::alarm3() // This is the Alarm2 callback
{
this->terminate();
}
void Tank::terminate()
{
// deregistrating any possible active alarms
// checking first it is registered before deregistrating
if(GameObject::isRegisteredForAlarm (AlarmID::ALARM_0))
{
}
if(GameObject::isRegisteredForAlarm (AlarmID::ALARM_1))
{
}
}
void submitAlarmRegistration(float timeDelay, AlarmID alarmID)
Submit alarm registration to the current scene.
Definition: Alarmable.cpp:52
void submitAlarmDeregistration(AlarmID alarmID)
Submit alarm deregistration to the current scene.
Definition: Alarmable.cpp:72
bool isRegisteredForAlarm(AlarmID alarmID) const
Query if 'alarmID' is registered.
Definition: Alarmable.cpp:90

Enumeration Type Documentation

◆ AlarmID

enum AlarmID
strong

Values that represent alarm Identifiers.

To be used in GameObject::submitAlarmRegistration() and GameObject::submitAlarmDeregistration()

Function Documentation

◆ alarm0()

void Alarmable::alarm0 ( )
privatevirtual

Alarm 0.

To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable).

◆ alarm1()

void Alarmable::alarm1 ( )
privatevirtual

Alarm 1.

To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable)

◆ alarm2()

void Alarmable::alarm2 ( )
privatevirtual

Alarm 2.

To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable)

◆ getTimeLeftForAlarm()

float Alarmable::getTimeLeftForAlarm ( AlarmID  alarmID) const
protected

Gets time left for a given alarm.

Used only if alarm is registered. Check using GameObject::isRegisteredForAlarm() before calling this function

Parameters
alarmIDIdentifier for the alarm.
Returns
The time left for a given alarm.

◆ isRegisteredForAlarm()

bool Alarmable::isRegisteredForAlarm ( AlarmID  alarmID) const
protected

Query if 'alarmID' is registered.

Parameters
alarmIDIdentifier for the alarm.
Returns
True if registered for alarm, false if not.

◆ submitAlarmDeregistration()

void Alarmable::submitAlarmDeregistration ( AlarmID  alarmID)
protected

Submit alarm deregistration to the current scene.

Parameters
alarmIDIdentifier for the alarm.

◆ submitAlarmRegistration()

void Alarmable::submitAlarmRegistration ( float  timeDelay,
AlarmID  alarmID 
)
protected

Submit alarm registration to the current scene.

Parameters
timeDelayThe time delay.
alarmIDIdentifier for the alarm.