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 world has changed.
This commit is contained in:
parent
fee9b66750
commit
f38aa16b5f
@ -159,6 +159,7 @@ protected:
|
||||
// ----------------------------------------------------------------------------------------
|
||||
Function mOnEntered;
|
||||
Function mOnExited;
|
||||
Function mOnWorld;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1002,6 +1003,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Miscellaneous events.
|
||||
*/
|
||||
void EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world);
|
||||
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);
|
||||
@ -1151,6 +1153,7 @@ private:
|
||||
Function mOnPickupRespawn;
|
||||
Function mOnCheckpointEntered;
|
||||
Function mOnCheckpointExited;
|
||||
Function mOnCheckpointWorld;
|
||||
Function mOnEntityPool;
|
||||
Function mOnClientScriptData;
|
||||
Function mOnPlayerUpdate;
|
||||
|
@ -676,6 +676,14 @@ void Core::EmitCheckpointExited(Int32 checkpoint_id, Int32 player_id)
|
||||
Emit(mOnCheckpointExited, _player.mObj, _checkpoint.mObj);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world)
|
||||
{
|
||||
CheckpointInst & _checkpoint = m_Checkpoints.at(checkpoint_id);
|
||||
Emit(_checkpoint.mOnWorld, old_world, new_world);
|
||||
Emit(mOnCheckpointWorld, _checkpoint.mObj, old_world, new_world);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
|
||||
{
|
||||
|
@ -132,6 +132,7 @@ void Core::ResetFunc(CheckpointInst & inst)
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnEntered.ReleaseGently();
|
||||
inst.mOnExited.ReleaseGently();
|
||||
inst.mOnWorld.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -347,6 +348,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPickupRespawn.ReleaseGently();
|
||||
Core::Get().mOnCheckpointEntered.ReleaseGently();
|
||||
Core::Get().mOnCheckpointExited.ReleaseGently();
|
||||
Core::Get().mOnCheckpointWorld.ReleaseGently();
|
||||
Core::Get().mOnEntityPool.ReleaseGently();
|
||||
Core::Get().mOnClientScriptData.ReleaseGently();
|
||||
Core::Get().mOnPlayerUpdate.ReleaseGently();
|
||||
@ -469,6 +471,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
|
||||
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
|
||||
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
|
||||
case EVT_CHECKPOINTWORLD: return mOnCheckpointWorld;
|
||||
case EVT_ENTITYPOOL: return mOnEntityPool;
|
||||
case EVT_CLIENTSCRIPTDATA: return mOnClientScriptData;
|
||||
case EVT_PLAYERUPDATE: return mOnPlayerUpdate;
|
||||
@ -531,6 +534,7 @@ Function & Core::GetCheckpointEvent(Int32 id, Int32 evid)
|
||||
case EVT_CHECKPOINTCUSTOM: return inst.mOnCustom;
|
||||
case EVT_CHECKPOINTENTERED: return inst.mOnEntered;
|
||||
case EVT_CHECKPOINTEXITED: return inst.mOnExited;
|
||||
case EVT_CHECKPOINTWORLD: return inst.mOnWorld;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ Object & CCheckpoint::GetNull()
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCheckpoint::CCheckpoint(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_CHECKPOINT_POOL))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -184,12 +184,27 @@ Int32 CCheckpoint::GetWorld() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetWorld(Int32 world) const
|
||||
void CCheckpoint::SetWorld(Int32 world)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetCheckPointWorld(m_ID);
|
||||
// Don't even bother if it's the same value
|
||||
if (current == world)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetCheckPointWorld(m_ID, world);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & CHECKPOINTCL_EMIT_CHECKPOINT_WORLD))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, CHECKPOINTCL_EMIT_CHECKPOINT_WORLD);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitCheckpointWorld(m_ID, current, world);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -7,6 +7,14 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Circular locks employed by the checkpoint manager.
|
||||
*/
|
||||
enum CheckpointCircularLocks
|
||||
{
|
||||
CHECKPOINTCL_EMIT_CHECKPOINT_WORLD = (1 << 0)
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single checkpoint entity.
|
||||
*/
|
||||
@ -39,6 +47,11 @@ private:
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Prevent events from triggering themselves.
|
||||
*/
|
||||
Uint32 m_CircularLocks;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
@ -197,7 +210,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the world in which the managed checkpoint entity exists.
|
||||
*/
|
||||
void SetWorld(Int32 world) const;
|
||||
void SetWorld(Int32 world);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the color of the managed checkpoint entity.
|
||||
|
@ -366,6 +366,7 @@ enum EventType
|
||||
EVT_PICKUPRESPAWN,
|
||||
EVT_CHECKPOINTENTERED,
|
||||
EVT_CHECKPOINTEXITED,
|
||||
EVT_CHECKPOINTWORLD,
|
||||
EVT_ENTITYPOOL,
|
||||
EVT_CLIENTSCRIPTDATA,
|
||||
EVT_PLAYERUPDATE,
|
||||
|
Loading…
Reference in New Issue
Block a user