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 a checkpoint radius has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 16:10:18 +03:00
parent f38aa16b5f
commit 5f60d7b90d
6 changed files with 30 additions and 3 deletions

View File

@ -160,6 +160,7 @@ protected:
Function mOnEntered;
Function mOnExited;
Function mOnWorld;
Function mOnRadius;
};
/* --------------------------------------------------------------------------------------------
@ -1004,6 +1005,7 @@ public:
* Miscellaneous events.
*/
void EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world);
void EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius);
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
void EmitPlayerWeapon(Int32 player_id, Int32 old_weapon, Int32 new_weapon);
@ -1154,6 +1156,7 @@ private:
Function mOnCheckpointEntered;
Function mOnCheckpointExited;
Function mOnCheckpointWorld;
Function mOnCheckpointRadius;
Function mOnEntityPool;
Function mOnClientScriptData;
Function mOnPlayerUpdate;

View File

@ -684,6 +684,14 @@ void Core::EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_w
Emit(mOnCheckpointWorld, _checkpoint.mObj, old_world, new_world);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius)
{
CheckpointInst & _checkpoint = m_Checkpoints.at(checkpoint_id);
Emit(_checkpoint.mOnRadius, old_radius, new_radius);
Emit(mOnCheckpointRadius, _checkpoint.mObj, old_radius, new_radius);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
{

View File

@ -133,6 +133,7 @@ void Core::ResetFunc(CheckpointInst & inst)
inst.mOnEntered.ReleaseGently();
inst.mOnExited.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnRadius.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -349,6 +350,7 @@ void Core::ResetFunc()
Core::Get().mOnCheckpointEntered.ReleaseGently();
Core::Get().mOnCheckpointExited.ReleaseGently();
Core::Get().mOnCheckpointWorld.ReleaseGently();
Core::Get().mOnCheckpointRadius.ReleaseGently();
Core::Get().mOnEntityPool.ReleaseGently();
Core::Get().mOnClientScriptData.ReleaseGently();
Core::Get().mOnPlayerUpdate.ReleaseGently();
@ -472,6 +474,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
case EVT_CHECKPOINTWORLD: return mOnCheckpointWorld;
case EVT_CHECKPOINTRADIUS: return mOnCheckpointRadius;
case EVT_ENTITYPOOL: return mOnEntityPool;
case EVT_CLIENTSCRIPTDATA: return mOnClientScriptData;
case EVT_PLAYERUPDATE: return mOnPlayerUpdate;
@ -535,6 +538,7 @@ Function & Core::GetCheckpointEvent(Int32 id, Int32 evid)
case EVT_CHECKPOINTENTERED: return inst.mOnEntered;
case EVT_CHECKPOINTEXITED: return inst.mOnExited;
case EVT_CHECKPOINTWORLD: return inst.mOnWorld;
case EVT_CHECKPOINTRADIUS: return inst.mOnRadius;
default: return NullFunction();
}
}

View File

@ -294,8 +294,18 @@ void CCheckpoint::SetRadius(Float32 radius) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Float32 current = _Func->GetCheckPointRadius(m_ID);
// Avoid property unwind from a recursive call
_Func->SetCheckPointRadius(m_ID, radius);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & CHECKPOINTCL_EMIT_CHECKPOINT_RADIUS))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, CHECKPOINTCL_EMIT_CHECKPOINT_RADIUS);
// Now forward the event call
Core::Get().EmitCheckpointRadius(m_ID, current, radius);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -12,7 +12,8 @@ namespace SqMod {
*/
enum CheckpointCircularLocks
{
CHECKPOINTCL_EMIT_CHECKPOINT_WORLD = (1 << 0)
CHECKPOINTCL_EMIT_CHECKPOINT_WORLD = (1 << 0),
CHECKPOINTCL_EMIT_CHECKPOINT_RADIUS = (2 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -255,7 +256,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the radius of the managed checkpoint entity.
*/
void SetRadius(Float32 radius) const;
void SetRadius(Float32 radius);
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the managed checkpoint entity.

View File

@ -367,6 +367,7 @@ enum EventType
EVT_CHECKPOINTENTERED,
EVT_CHECKPOINTEXITED,
EVT_CHECKPOINTWORLD,
EVT_CHECKPOINTRADIUS,
EVT_ENTITYPOOL,
EVT_CLIENTSCRIPTDATA,
EVT_PLAYERUPDATE,