1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Implement a new event to receive notifications when an pickup auto timer has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-19 18:26:52 +03:00
parent a47f7541d0
commit e179452a61
6 changed files with 36 additions and 4 deletions

View File

@ -306,6 +306,7 @@ protected:
Function mOnWorld;
Function mOnAlpha;
Function mOnAutomatic;
Function mOnAutoTimer;
};
/* --------------------------------------------------------------------------------------------
@ -1017,6 +1018,7 @@ public:
void EmitPickupWorld(Int32 pickup_id, Int32 old_world, Int32 new_world);
void EmitPickupAlpha(Int32 pickup_id, Int32 old_alpha, Int32 new_alpha);
void EmitPickupAutomatic(Int32 pickup_id, bool old_status, bool new_status);
void EmitPickupAutoTimer(Int32 pickup_id, Int32 old_timer, Int32 new_timer);
void EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched);
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
@ -1171,6 +1173,7 @@ private:
Function mOnPickupWorld;
Function mOnPickupAlpha;
Function mOnPickupAutomatic;
Function mOnPickupAutoTimer;
Function mOnCheckpointEntered;
Function mOnCheckpointExited;
Function mOnCheckpointWorld;

View File

@ -732,6 +732,14 @@ void Core::EmitPickupAutomatic(Int32 pickup_id, bool old_status, bool new_status
Emit(mOnPickupAutomatic, _pickup.mObj, old_status, new_status);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitPickupAutoTimer(Int32 pickup_id, Int32 old_timer, Int32 new_timer)
{
PickupInst & _pickup = m_Pickups.at(pickup_id);
Emit(_pickup.mOnAutoTimer, old_timer, new_timer);
Emit(mOnPickupAutoTimer, _pickup.mObj, old_timer, new_timer);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched)
{

View File

@ -168,6 +168,7 @@ void Core::ResetFunc(PickupInst & inst)
inst.mOnWorld.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
inst.mOnAutomatic.ReleaseGently();
inst.mOnAutoTimer.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -359,6 +360,7 @@ void Core::ResetFunc()
Core::Get().mOnPickupWorld.ReleaseGently();
Core::Get().mOnPickupAlpha.ReleaseGently();
Core::Get().mOnPickupAutomatic.ReleaseGently();
Core::Get().mOnPickupAutoTimer.ReleaseGently();
Core::Get().mOnCheckpointEntered.ReleaseGently();
Core::Get().mOnCheckpointExited.ReleaseGently();
Core::Get().mOnCheckpointWorld.ReleaseGently();
@ -489,6 +491,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_PICKUPWORLD: return mOnPickupWorld;
case EVT_PICKUPALPHA: return mOnPickupAlpha;
case EVT_PICKUPAUTOMATIC: return mOnPickupAutomatic;
case EVT_PICKUPAUTOTIMER: return mOnPickupAutoTimer;
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
case EVT_CHECKPOINTWORLD: return mOnCheckpointWorld;
@ -610,6 +613,7 @@ Function & Core::GetPickupEvent(Int32 id, Int32 evid)
case EVT_PICKUPWORLD: return inst.mOnWorld;
case EVT_PICKUPALPHA: return inst.mOnAlpha;
case EVT_PICKUPAUTOMATIC: return inst.mOnAutomatic;
case EVT_PICKUPAUTOTIMER: return inst.mOnAutoTimer;
default: return NullFunction();
}
}

View File

@ -266,12 +266,27 @@ Int32 CPickup::GetAutoTimer() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutoTimer(Int32 timer) const
void CPickup::SetAutoTimer(Int32 timer)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetPickupAutoTimer(m_ID);
// Don't even bother if it's the same value
if (current == timer)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetPickupAutoTimer(m_ID, timer);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PICKUPCL_EMIT_PICKUP_AUTOTIMER))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PICKUPCL_EMIT_PICKUP_AUTOTIMER);
// Now forward the event call
Core::Get().EmitPickupAutoTimer(m_ID, current, timer);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -14,7 +14,8 @@ enum PickupCircularLocks
{
PICKUPCL_EMIT_PICKUP_WORLD = (1 << 0),
PICKUPCL_EMIT_PICKUP_ALPHA = (2 << 0),
PICKUPCL_EMIT_PICKUP_AUTOMATIC = (3 << 0)
PICKUPCL_EMIT_PICKUP_AUTOMATIC = (3 << 0),
PICKUPCL_EMIT_PICKUP_AUTOTIMER = (4 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -233,7 +234,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Mpdify the automatic timer of the managed pickup entity.
*/
void SetAutoTimer(Int32 timer) const;
void SetAutoTimer(Int32 timer);
/* --------------------------------------------------------------------------------------------
* Refresh the managed pickup entity.

View File

@ -370,6 +370,7 @@ enum EventType
EVT_PICKUPWORLD,
EVT_PICKUPALPHA,
EVT_PICKUPAUTOMATIC,
EVT_PICKUPAUTOTIMER,
EVT_CHECKPOINTENTERED,
EVT_CHECKPOINTEXITED,
EVT_CHECKPOINTWORLD,