mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Implement a new event to receive notifications when an object world has changed.
This commit is contained in:
parent
0afd4f3c2e
commit
3bbff3f258
@ -255,6 +255,7 @@ protected:
|
|||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
Function mOnShot;
|
Function mOnShot;
|
||||||
Function mOnTouched;
|
Function mOnTouched;
|
||||||
|
Function mOnWorld;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
@ -1006,6 +1007,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world);
|
void EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world);
|
||||||
void EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius);
|
void EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius);
|
||||||
|
void EmitObjectWorld(Int32 object_id, Int32 old_world, Int32 new_world);
|
||||||
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
|
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
|
||||||
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
|
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
|
||||||
void EmitPlayerWeapon(Int32 player_id, Int32 old_weapon, Int32 new_weapon);
|
void EmitPlayerWeapon(Int32 player_id, Int32 old_weapon, Int32 new_weapon);
|
||||||
@ -1150,6 +1152,7 @@ private:
|
|||||||
Function mOnVehicleRespawn;
|
Function mOnVehicleRespawn;
|
||||||
Function mOnObjectShot;
|
Function mOnObjectShot;
|
||||||
Function mOnObjectTouched;
|
Function mOnObjectTouched;
|
||||||
|
Function mOnObjectWorld;
|
||||||
Function mOnPickupClaimed;
|
Function mOnPickupClaimed;
|
||||||
Function mOnPickupCollected;
|
Function mOnPickupCollected;
|
||||||
Function mOnPickupRespawn;
|
Function mOnPickupRespawn;
|
||||||
|
@ -692,6 +692,14 @@ void Core::EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32
|
|||||||
Emit(mOnCheckpointRadius, _checkpoint.mObj, old_radius, new_radius);
|
Emit(mOnCheckpointRadius, _checkpoint.mObj, old_radius, new_radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void Core::EmitObjectWorld(Int32 object_id, Int32 old_world, Int32 new_world)
|
||||||
|
{
|
||||||
|
ObjectInst & _object = m_Objects.at(object_id);
|
||||||
|
Emit(_object.mOnWorld, old_world, new_world);
|
||||||
|
Emit(mOnObjectWorld, _object.mObj, old_world, new_world);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
|
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
|
||||||
{
|
{
|
||||||
|
@ -152,6 +152,7 @@ void Core::ResetFunc(ObjectInst & inst)
|
|||||||
inst.mOnCustom.ReleaseGently();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnShot.ReleaseGently();
|
inst.mOnShot.ReleaseGently();
|
||||||
inst.mOnTouched.ReleaseGently();
|
inst.mOnTouched.ReleaseGently();
|
||||||
|
inst.mOnWorld.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -344,6 +345,7 @@ void Core::ResetFunc()
|
|||||||
Core::Get().mOnVehicleRespawn.ReleaseGently();
|
Core::Get().mOnVehicleRespawn.ReleaseGently();
|
||||||
Core::Get().mOnObjectShot.ReleaseGently();
|
Core::Get().mOnObjectShot.ReleaseGently();
|
||||||
Core::Get().mOnObjectTouched.ReleaseGently();
|
Core::Get().mOnObjectTouched.ReleaseGently();
|
||||||
|
Core::Get().mOnObjectWorld.ReleaseGently();
|
||||||
Core::Get().mOnPickupClaimed.ReleaseGently();
|
Core::Get().mOnPickupClaimed.ReleaseGently();
|
||||||
Core::Get().mOnPickupCollected.ReleaseGently();
|
Core::Get().mOnPickupCollected.ReleaseGently();
|
||||||
Core::Get().mOnPickupRespawn.ReleaseGently();
|
Core::Get().mOnPickupRespawn.ReleaseGently();
|
||||||
@ -468,6 +470,7 @@ Function & Core::GetEvent(Int32 evid)
|
|||||||
case EVT_VEHICLERESPAWN: return mOnVehicleRespawn;
|
case EVT_VEHICLERESPAWN: return mOnVehicleRespawn;
|
||||||
case EVT_OBJECTSHOT: return mOnObjectShot;
|
case EVT_OBJECTSHOT: return mOnObjectShot;
|
||||||
case EVT_OBJECTTOUCHED: return mOnObjectTouched;
|
case EVT_OBJECTTOUCHED: return mOnObjectTouched;
|
||||||
|
case EVT_OBJECTWORLD: return mOnObjectWorld;
|
||||||
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
|
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
|
||||||
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
|
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
|
||||||
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
|
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
|
||||||
@ -570,6 +573,7 @@ Function & Core::GetObjectEvent(Int32 id, Int32 evid)
|
|||||||
case EVT_OBJECTCUSTOM: return inst.mOnCustom;
|
case EVT_OBJECTCUSTOM: return inst.mOnCustom;
|
||||||
case EVT_OBJECTSHOT: return inst.mOnShot;
|
case EVT_OBJECTSHOT: return inst.mOnShot;
|
||||||
case EVT_OBJECTTOUCHED: return inst.mOnTouched;
|
case EVT_OBJECTTOUCHED: return inst.mOnTouched;
|
||||||
|
case EVT_OBJECTWORLD: return inst.mOnWorld;
|
||||||
default: return NullFunction();
|
default: return NullFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ Object & CObject::GetNull()
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
CObject::CObject(Int32 id)
|
CObject::CObject(Int32 id)
|
||||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_OBJECT_POOL))
|
: m_ID(VALID_ENTITYGETEX(id, SQMOD_OBJECT_POOL))
|
||||||
, m_Tag(ToStrF("%d", id)), m_Data()
|
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
|
||||||
, mMoveToDuration(0)
|
, mMoveToDuration(0)
|
||||||
, mMoveByDuration(0)
|
, mMoveByDuration(0)
|
||||||
, mRotateToDuration(0)
|
, mRotateToDuration(0)
|
||||||
@ -184,12 +184,27 @@ Int32 CObject::GetWorld() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void CObject::SetWorld(Int32 world) const
|
void CObject::SetWorld(Int32 world)
|
||||||
{
|
{
|
||||||
// Validate the managed identifier
|
// Validate the managed identifier
|
||||||
Validate();
|
Validate();
|
||||||
// Perform the requested operation
|
// Grab the current value for this property
|
||||||
|
const Int32 current = _Func->GetObjectWorld(m_ID);
|
||||||
|
// Don't even bother if it's the same value
|
||||||
|
if (current == world)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Avoid property unwind from a recursive call
|
||||||
_Func->SetObjectWorld(m_ID, world);
|
_Func->SetObjectWorld(m_ID, world);
|
||||||
|
// Avoid infinite recursive event loops
|
||||||
|
if (!(m_CircularLocks & OBJECTCL_EMIT_OBJECT_WORLD))
|
||||||
|
{
|
||||||
|
// Prevent this event from triggering while executed
|
||||||
|
BitGuardU32 bg(m_CircularLocks, OBJECTCL_EMIT_OBJECT_WORLD);
|
||||||
|
// Now forward the event call
|
||||||
|
Core::Get().EmitObjectWorld(m_ID, current, world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -7,6 +7,14 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* Circular locks employed by the object manager.
|
||||||
|
*/
|
||||||
|
enum ObjectCircularLocks
|
||||||
|
{
|
||||||
|
OBJECTCL_EMIT_OBJECT_WORLD = (1 << 0)
|
||||||
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Manages a single object entity.
|
* Manages a single object entity.
|
||||||
*/
|
*/
|
||||||
@ -36,6 +44,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
Object m_Data;
|
Object m_Data;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Prevent events from triggering themselves.
|
||||||
|
*/
|
||||||
|
Uint32 m_CircularLocks;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Base constructor.
|
* Base constructor.
|
||||||
*/
|
*/
|
||||||
@ -212,7 +225,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Modify the world in which the managed object entity exists.
|
* Modify the world in which the managed object entity exists.
|
||||||
*/
|
*/
|
||||||
void SetWorld(Int32 world) const;
|
void SetWorld(Int32 world);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Retrieve the alpha of the managed object entity.
|
* Retrieve the alpha of the managed object entity.
|
||||||
|
@ -361,6 +361,7 @@ enum EventType
|
|||||||
EVT_VEHICLERESPAWN,
|
EVT_VEHICLERESPAWN,
|
||||||
EVT_OBJECTSHOT,
|
EVT_OBJECTSHOT,
|
||||||
EVT_OBJECTTOUCHED,
|
EVT_OBJECTTOUCHED,
|
||||||
|
EVT_OBJECTWORLD,
|
||||||
EVT_PICKUPCLAIMED,
|
EVT_PICKUPCLAIMED,
|
||||||
EVT_PICKUPCOLLECTED,
|
EVT_PICKUPCOLLECTED,
|
||||||
EVT_PICKUPRESPAWN,
|
EVT_PICKUPRESPAWN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user