1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

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

This commit is contained in:
Sandu Liviu Catalin
2016-08-18 16:37:55 +03:00
parent 0afd4f3c2e
commit 3bbff3f258
6 changed files with 48 additions and 4 deletions

View File

@ -39,7 +39,7 @@ Object & CObject::GetNull()
// ------------------------------------------------------------------------------------------------
CObject::CObject(Int32 id)
: 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)
, mMoveByDuration(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();
// 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);
// 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);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -7,6 +7,14 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Circular locks employed by the object manager.
*/
enum ObjectCircularLocks
{
OBJECTCL_EMIT_OBJECT_WORLD = (1 << 0)
};
/* ------------------------------------------------------------------------------------------------
* Manages a single object entity.
*/
@ -36,6 +44,11 @@ private:
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
@ -212,7 +225,7 @@ public:
/* --------------------------------------------------------------------------------------------
* 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.