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

Implement a new event to receive notifications when an object shot or touched report status has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 17:12:00 +03:00
parent 9ce8a8a4f8
commit ed5f1a86de
6 changed files with 54 additions and 7 deletions

View File

@ -257,6 +257,7 @@ protected:
Function mOnTouched;
Function mOnWorld;
Function mOnAlpha;
Function mOnReport;
};
/* --------------------------------------------------------------------------------------------
@ -1010,6 +1011,7 @@ public:
void EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius);
void EmitObjectWorld(Int32 object_id, Int32 old_world, Int32 new_world);
void EmitObjectAlpha(Int32 object_id, Int32 old_alpha, Int32 new_alpha, Int32 time);
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);
void EmitPlayerWeapon(Int32 player_id, Int32 old_weapon, Int32 new_weapon);
@ -1156,6 +1158,7 @@ private:
Function mOnObjectTouched;
Function mOnObjectWorld;
Function mOnObjectAlpha;
Function mOnObjectReport;
Function mOnPickupClaimed;
Function mOnPickupCollected;
Function mOnPickupRespawn;

View File

@ -708,6 +708,14 @@ void Core::EmitObjectAlpha(Int32 object_id, Int32 old_alpha, Int32 new_alpha, In
Emit(mOnObjectAlpha, _object.mObj, old_alpha, new_alpha, time);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched)
{
ObjectInst & _object = m_Objects.at(object_id);
Emit(_object.mOnReport, old_status, new_status, touched);
Emit(mOnObjectReport, _object.mObj, old_status, new_status, touched);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
{

View File

@ -154,6 +154,7 @@ void Core::ResetFunc(ObjectInst & inst)
inst.mOnTouched.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
inst.mOnReport.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -348,6 +349,7 @@ void Core::ResetFunc()
Core::Get().mOnObjectTouched.ReleaseGently();
Core::Get().mOnObjectWorld.ReleaseGently();
Core::Get().mOnObjectAlpha.ReleaseGently();
Core::Get().mOnObjectReport.ReleaseGently();
Core::Get().mOnPickupClaimed.ReleaseGently();
Core::Get().mOnPickupCollected.ReleaseGently();
Core::Get().mOnPickupRespawn.ReleaseGently();
@ -474,6 +476,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_OBJECTTOUCHED: return mOnObjectTouched;
case EVT_OBJECTWORLD: return mOnObjectWorld;
case EVT_OBJECTALPHA: return mOnObjectAlpha;
case EVT_OBJECTREPORT: return mOnObjectReport;
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
@ -578,6 +581,7 @@ Function & Core::GetObjectEvent(Int32 id, Int32 evid)
case EVT_OBJECTTOUCHED: return inst.mOnTouched;
case EVT_OBJECTWORLD: return inst.mOnWorld;
case EVT_OBJECTALPHA: return inst.mOnAlpha;
case EVT_OBJECTREPORT: return inst.mOnReport;
default: return NullFunction();
}
}

View File

@ -421,12 +421,27 @@ bool CObject::GetShotReport() const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetShotReport(bool toggle) const
void CObject::SetShotReport(bool toggle)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const bool current = _Func->IsObjectShotReportEnabled(m_ID);
// Don't even bother if it's the same value
if (current == toggle)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetObjectShotReportEnabled(m_ID, toggle);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & OBJECTCL_EMIT_OBJECT_REPORT))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, OBJECTCL_EMIT_OBJECT_REPORT);
// Now forward the event call
Core::Get().EmitObjectReport(m_ID, current, toggle, false);
}
}
// ------------------------------------------------------------------------------------------------
@ -439,12 +454,27 @@ bool CObject::GetTouchedReport() const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetTouchedReport(bool toggle) const
void CObject::SetTouchedReport(bool toggle)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const bool current = _Func->IsObjectTouchedReportEnabled(m_ID);
// Don't even bother if it's the same value
if (current == toggle)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetObjectTouchedReportEnabled(m_ID, toggle);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & OBJECTCL_EMIT_OBJECT_REPORT))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, OBJECTCL_EMIT_OBJECT_REPORT);
// Now forward the event call
Core::Get().EmitObjectReport(m_ID, current, toggle, true);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -13,7 +13,8 @@ namespace SqMod {
enum ObjectCircularLocks
{
OBJECTCL_EMIT_OBJECT_WORLD = (1 << 0),
OBJECTCL_EMIT_OBJECT_ALPHA = (2 << 0)
OBJECTCL_EMIT_OBJECT_ALPHA = (2 << 0),
OBJECTCL_EMIT_OBJECT_REPORT = (3 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -336,7 +337,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports gunshots.
*/
void SetShotReport(bool toggle) const;
void SetShotReport(bool toggle);
/* --------------------------------------------------------------------------------------------
* See whether the managed object entity reports player bumps.
@ -346,7 +347,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports player bumps.
*/
void SetTouchedReport(bool toggle) const;
void SetTouchedReport(bool toggle);
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed object entity.

View File

@ -363,6 +363,7 @@ enum EventType
EVT_OBJECTTOUCHED,
EVT_OBJECTWORLD,
EVT_OBJECTALPHA,
EVT_OBJECTREPORT,
EVT_PICKUPCLAIMED,
EVT_PICKUPCOLLECTED,
EVT_PICKUPRESPAWN,