From e179452a61ae87d537398b505b3a7a7cf897a700 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Fri, 19 Aug 2016 18:26:52 +0300 Subject: [PATCH] Implement a new event to receive notifications when an pickup auto timer has changed. --- source/Core.hpp | 3 +++ source/CoreEvents.cpp | 8 ++++++++ source/CoreUtils.cpp | 4 ++++ source/Entity/Pickup.cpp | 19 +++++++++++++++++-- source/Entity/Pickup.hpp | 5 +++-- source/SqBase.hpp | 1 + 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/source/Core.hpp b/source/Core.hpp index e011a8fd..4359c3fa 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -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; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 5dfa32b3..b995222e 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -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) { diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index d07144d3..e2eda911 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -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(); } } diff --git a/source/Entity/Pickup.cpp b/source/Entity/Pickup.cpp index fa26af6b..bb88860c 100644 --- a/source/Entity/Pickup.cpp +++ b/source/Entity/Pickup.cpp @@ -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); + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Entity/Pickup.hpp b/source/Entity/Pickup.hpp index 248400e0..f318bfbd 100644 --- a/source/Entity/Pickup.hpp +++ b/source/Entity/Pickup.hpp @@ -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. diff --git a/source/SqBase.hpp b/source/SqBase.hpp index 5d37053b..51a48b99 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -370,6 +370,7 @@ enum EventType EVT_PICKUPWORLD, EVT_PICKUPALPHA, EVT_PICKUPAUTOMATIC, + EVT_PICKUPAUTOTIMER, EVT_CHECKPOINTENTERED, EVT_CHECKPOINTEXITED, EVT_CHECKPOINTWORLD,