stmm-games-doc  0.32.0
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
stmg::Event Class Referenceabstract

The level event class. More...

Inheritance diagram for stmg::Event:
Inheritance graph
[legend]

Classes

struct  Init
 

Public Types

enum  MSG_FILTER_VALUE_OP {
  MSG_FILTER_VALUE_OP_FIRST = 0, MSG_FILTER_VALUE_OP_UNCHANGED = 0, MSG_FILTER_VALUE_OP_SET = 1, MSG_FILTER_VALUE_OP_MULT_ADD = 2,
  MSG_FILTER_VALUE_OP_DIV_ADD = 3, MSG_FILTER_VALUE_OP_PERCENT_ADD = 4, MSG_FILTER_VALUE_OP_PERMILL_ADD = 5, MSG_FILTER_VALUE_OP_MOD_ADD = 6,
  MSG_FILTER_VALUE_OP_MIN_ADD = 7, MSG_FILTER_VALUE_OP_MAX_ADD = 8, MSG_FILTER_VALUE_OP_LAST = 8
}
 Value filter. More...
 
enum  { LISTENER_GROUP_FINISHED = 0 }
 

Public Member Functions

virtual ~Event () noexcept=default
 
virtual void addMsgFilter (int32_t nInFromMsg, int32_t nInToMsg, int32_t nInFromValue, int32_t nInToValue, bool bOutMsgDefined, int32_t nOutMsg, MSG_FILTER_VALUE_OP eOutValueOperator, int32_t nOutValueOperand, int32_t nOutValueAdd) noexcept
 Add a message filter. More...
 
virtual void addListener (int32_t nGroupId, Event *p0ListenerEvent, int32_t nMsg) noexcept
 Adds a listener to the event. More...
 
bool isActive () const noexcept
 Tells whether the event is active. More...
 
int32_t getTriggerTime () const noexcept
 The triggering time. More...
 
int32_t getPriority () const noexcept
 The priority. More...
 
int32_t getDebugTag () const noexcept
 The debug tag. More...
 

Protected Member Functions

 Event (Init &&oInit) noexcept
 Constructor. More...
 
void reInit (Init &&oInit) noexcept
 Reinitialization. More...
 
virtual void informListeners (int32_t nGroupId, int32_t nValue) noexcept
 Calls the trigger function of a group of listeners. More...
 
virtual void trigger (int32_t nMsg, int32_t nValue, Event *p0TriggeringEvent) noexcept=0
 The trigger function. More...
 
const Levellevel () const noexcept
 The level this event belongs to. More...
 
Levellevel () noexcept
 The level this event belongs to. More...
 

Detailed Description

The level event class.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
LISTENER_GROUP_FINISHED 

Reserved group that is triggered when an event has "expired".

◆ MSG_FILTER_VALUE_OP

Value filter.

See also
Event::addMsgFilter().
Enumerator
MSG_FILTER_VALUE_OP_FIRST 
MSG_FILTER_VALUE_OP_UNCHANGED 

The value is not changed.

MSG_FILTER_VALUE_OP_SET 

The value is set.

MSG_FILTER_VALUE_OP_MULT_ADD 

The value is multiplied.

MSG_FILTER_VALUE_OP_DIV_ADD 

The value is divided.

MSG_FILTER_VALUE_OP_PERCENT_ADD 

The value is "percentaged".

MSG_FILTER_VALUE_OP_PERMILL_ADD 

The value is "permilled".

MSG_FILTER_VALUE_OP_MOD_ADD 

The value is "moduloed".

MSG_FILTER_VALUE_OP_MIN_ADD 

The value is minimized.

MSG_FILTER_VALUE_OP_MAX_ADD 

The value is maximized.

MSG_FILTER_VALUE_OP_LAST 

Constructor & Destructor Documentation

◆ Event()

stmg::Event::Event ( Init &&  oInit)
explicitprotectednoexcept

Constructor.

The event can only be added to the level passed as parameter to this function. The level passed as oInit.m_p0Level must also be valid (already be constructed or reinitialized).

Parameters
oInitThe initialization data.

◆ ~Event()

virtual stmg::Event::~Event ( )
virtualdefaultnoexcept

Member Function Documentation

◆ addListener()

virtual void stmg::Event::addListener ( int32_t  nGroupId,
Event p0ListenerEvent,
int32_t  nMsg 
)
virtualnoexcept

Adds a listener to the event.

Parameters
nGroupIdThe listening group it is added to. If negative the listener is added to all groups.
p0ListenerEventThe listener. Cannot be null.
nMsgThe message to send to the listener when triggered. If negative the group as passed to informListeners() is used.

◆ addMsgFilter()

virtual void stmg::Event::addMsgFilter ( int32_t  nInFromMsg,
int32_t  nInToMsg,
int32_t  nInFromValue,
int32_t  nInToValue,
bool  bOutMsgDefined,
int32_t  nOutMsg,
MSG_FILTER_VALUE_OP  eOutValueOperator,
int32_t  nOutValueOperand,
int32_t  nOutValueAdd 
)
virtualnoexcept

Add a message filter.

All messages should be numbers >= -1.

The new value set by the filter is the result of the expression nValue "MSG_FILTER_VALUE_OP" nOutValueOperand [+ nOutValueAdd]

Example: if eOutValueOperator is MSG_FILTER_VALUE_OP_MULT_ADD the new value is nValue * nOutValueOperand + nOutValueAdd.

Parameters
nInFromMsgThe filter is applied when the incoming message is >= this nInFromMsg.
nInToMsgThe filter is applied when the incoming message is <= this nInToMsg.
nInFromValueThe filter is applied when the incoming value is >= this nInFromValue.
nInToValueThe filter is applied when the incoming value is <= this nInToValue.
bOutMsgDefinedWhether the message is overwritten.
nOutMsgThe new message.
eOutValueOperatorThe operator applied to the old value and nOutValueOperand.
nOutValueOperandThe operand of eOutValueOperator.
nOutValueAddThe value added to the new value expression.

◆ getDebugTag()

int32_t stmg::Event::getDebugTag ( ) const
inlinenoexcept

The debug tag.

Returns
The tag.

◆ getPriority()

int32_t stmg::Event::getPriority ( ) const
inlinenoexcept

The priority.

Returns
The priority.

◆ getTriggerTime()

int32_t stmg::Event::getTriggerTime ( ) const
inlinenoexcept

The triggering time.

The event must be active to be triggered by the timer.

The returned value might not be -1 even if the event is not active. See Level::triggerEvent().

Returns
The time in game ticks the event should be triggered or -1.

◆ informListeners()

virtual void stmg::Event::informListeners ( int32_t  nGroupId,
int32_t  nValue 
)
protectedvirtualnoexcept

Calls the trigger function of a group of listeners.

Before the trigger function of the listeners is called the listener's filters are applied.

Parameters
nGroupIdThe group. Must be >= 0.
nValueThe value to send.

◆ isActive()

bool stmg::Event::isActive ( ) const
inlinenoexcept

Tells whether the event is active.

To activate an event call Level::activateEvent(p0Event, nTriggerTime). To deactivate an event call Level::deactivateEvent(p0Event). The event is also deactivate by the Level::triggerEvent() function.

Returns
whether the event is active.

◆ level() [1/2]

const Level& stmg::Event::level ( ) const
inlineprotectednoexcept

The level this event belongs to.

Returns
The level.

◆ level() [2/2]

Level& stmg::Event::level ( )
inlineprotectednoexcept

The level this event belongs to.

Returns
The level.

◆ reInit()

void stmg::Event::reInit ( Init &&  oInit)
protectednoexcept

Reinitialization.

The event can only be added to the level passed as parameter to this function. The level passed as oInit.m_p0Level must also be valid (already be constructed or reinitialized).

Parameters
oInitThe initialization data.

◆ trigger()

virtual void stmg::Event::trigger ( int32_t  nMsg,
int32_t  nValue,
Event p0TriggeringEvent 
)
protectedpure virtualnoexcept

The trigger function.

This function provides the functionality of the event and can be called in two ways.

It can be called by an event through informListeners() this event was listening to. Note: events can listen to themselves.

It can also be called by the timer if the event was active.

When this function is called the event has already been deactivated by the level (if it was active in the first place).

When this function is called the filters of this event have already been applied.

Parameters
nMsgThe message received.
nValueThe value received.
p0TriggeringEventThe triggering event or null if triggered by timer.

Implemented in stmg::ScrollerEvent, stmg::ShowTextEvent, stmg::AlarmsEvent, stmg::TileAnimatorEvent, stmg::RandomEvent, stmg::FillerEvent, stmg::MockEvent, stmg::BackgroundEvent, stmg::SoundEvent, stmg::ArrayEvent, stmg::SquarsorEvent, stmg::DumbBlockEvent, stmg::PositionerEvent, stmg::SpeedEvent, stmg::SysEvent, stmg::DelayedQueueEvent, stmg::OthersSenderEvent, stmg::VariableEvent, stmg::CumulCmpEvent, stmg::LogEvent, stmg::StaticGridEvent, stmg::SelectEvent, and stmg::OthersReceiverEvent.