1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-10-15 07:27:19 +02:00

Implement a new event to receive notifications when an pickup world has changed.

This commit is contained in:
Sandu Liviu Catalin
2016-08-19 17:58:08 +03:00
parent d08e57f69a
commit 102c77aa77
5 changed files with 48 additions and 4 deletions

View File

@@ -37,7 +37,7 @@ Object & CPickup::GetNull()
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
, m_Tag(ToStrF("%d", id))
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
{
/* ... */
}
@@ -167,12 +167,27 @@ Int32 CPickup::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetWorld(Int32 world) const
void CPickup::SetWorld(Int32 world)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetPickupWorld(m_ID);
// Don't even bother if it's the same value
if (current == world)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetPickupWorld(m_ID, world);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PICKUPCL_EMIT_PICKUP_WORLD))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PICKUPCL_EMIT_PICKUP_WORLD);
// Now forward the event call
Core::Get().EmitPickupWorld(m_ID, current, world);
}
}
// ------------------------------------------------------------------------------------------------

View File

@@ -7,6 +7,14 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Circular locks employed by the pickup manager.
*/
enum PickupCircularLocks
{
PICKUPCL_EMIT_PICKUP_WORLD = (1 << 0)
};
/* ------------------------------------------------------------------------------------------------
* Manages a single pickup entity.
*/
@@ -35,6 +43,11 @@ private:
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
@@ -188,7 +201,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Mpdify the world in which the managed pickup entity exists.
*/
void SetWorld(Int32 world) const;
void SetWorld(Int32 world);
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed pickup entity.