1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 09:57:14 +01:00

Updated the local event type and it's filters to used the new debugging system.

This commit is contained in:
Sandu Liviu Catalin 2015-11-11 12:51:32 +02:00
parent 7762359068
commit 9493f110c6
2 changed files with 78 additions and 69 deletions

View File

@ -57,7 +57,7 @@ LocalEvent::LocalEvent(SQInt32 type, bool suspended)
LocalEvent::~LocalEvent() LocalEvent::~LocalEvent()
{ {
// Detach from all attached signals // Detach from all attached signals
Detach(); Detach("LocalEvent", "destructor");
// Stop receiving notification when the VM is about to be closed // Stop receiving notification when the VM is about to be closed
_Core->VMClose.Disconnect< LocalEvent, &LocalEvent::VMClose >(this); _Core->VMClose.Disconnect< LocalEvent, &LocalEvent::VMClose >(this);
/* The entity filters should to unhook themselves from the destroy signal! */ /* The entity filters should to unhook themselves from the destroy signal! */
@ -169,18 +169,19 @@ void LocalEvent::SetType(SQInt32 type)
// Make sure the newly specified event is compatible // Make sure the newly specified event is compatible
if (!Compatible(type)) if (!Compatible(type))
{ {
LogErr("Cannot change the event to an incompatible type: %s", GetEventName(type)); DbgErr("LocalEvent", "@type", "Cannot change the event to an incompatible type: %s",
GetEventName(type));
} }
else else
{ {
// Clear anything that cannot adapt to the new event type // Clear anything that cannot adapt to the new event type
Adaptable(type, m_Inversed); Adaptable(type, m_Inversed);
// Detach from the current event type // Detach from the current event type
Detach(); Detach("LocalEvent", "@type");
// Set the new event type // Set the new event type
m_Type = type; m_Type = type;
// Attach to the new event type // Attach to the new event type
Attach(); Attach("LocalEvent", "@type");
} }
} }
@ -271,7 +272,7 @@ void LocalEvent::SetInversed(bool toggle)
// Toggle the inversed option // Toggle the inversed option
m_Inversed = toggle; m_Inversed = toggle;
// Attach back to the new event type // Attach back to the new event type
Attach(); Attach("LocalEvent", "@inversed");
} }
// Just set the option to what was requested // Just set the option to what was requested
else else
@ -1363,14 +1364,14 @@ bool LocalEvent::Trigger()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Attach() void LocalEvent::Attach(const char * type, const char * func)
{ {
// Filters take care of both attaching and hooking for local filters // Filters take care of both attaching and hooking for local filters
Hook(); Hook(type, func);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Attach(SQInt32 id) void LocalEvent::Attach(const char * type, const char * func, SQInt32 id)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -1718,19 +1719,20 @@ void LocalEvent::Attach(SQInt32 id)
} }
break; break;
default: default:
LogErr("Attempting to <attach> to an unknown event type: %d", _SCI32(m_Type)); DbgErr(type, func, "Attempting to <attach event> to an unknown type: %d",
_SCI32(m_Type));
} }
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Detach() void LocalEvent::Detach(const char * type, const char * func)
{ {
// Filters take care of both detaching and unhooking for local filters // Filters take care of both detaching and unhooking for local filters
Unhook(); Unhook(type, func);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Detach(SQInt32 id) void LocalEvent::Detach(const char * type, const char * func, SQInt32 id)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -2078,115 +2080,116 @@ void LocalEvent::Detach(SQInt32 id)
} }
break; break;
default: default:
LogErr("Attempting to <detach> from an unknown event type: %d", _SCI32(m_Type)); DbgErr(type, func, "Attempting to <dettach event> from an unknown type: %d",
_SCI32(m_Type));
} }
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Hook() void LocalEvent::Hook(const char * type, const char * func)
{ {
if (Ent< CBlip >::InEvent(m_Type, m_Inversed)) if (Ent< CBlip >::InEvent(m_Type, m_Inversed))
{ {
m_Blips.Hook(); m_Blips.Hook(type, func);
} }
if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed)) if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed))
{ {
m_Checkpoints.Hook(); m_Checkpoints.Hook(type, func);
} }
if (Ent< CKeybind >::InEvent(m_Type, m_Inversed)) if (Ent< CKeybind >::InEvent(m_Type, m_Inversed))
{ {
m_Keybinds.Hook(); m_Keybinds.Hook(type, func);
} }
if (Ent< CObject >::InEvent(m_Type, m_Inversed)) if (Ent< CObject >::InEvent(m_Type, m_Inversed))
{ {
m_Objects.Hook(); m_Objects.Hook(type, func);
} }
if (Ent< CPickup >::InEvent(m_Type, m_Inversed)) if (Ent< CPickup >::InEvent(m_Type, m_Inversed))
{ {
m_Pickups.Hook(); m_Pickups.Hook(type, func);
} }
if (Ent< CPlayer >::InEvent(m_Type, m_Inversed)) if (Ent< CPlayer >::InEvent(m_Type, m_Inversed))
{ {
m_Players.Hook(); m_Players.Hook(type, func);
} }
if (Ent< CSphere >::InEvent(m_Type, m_Inversed)) if (Ent< CSphere >::InEvent(m_Type, m_Inversed))
{ {
m_Spheres.Hook(); m_Spheres.Hook(type, func);
} }
if (Ent< CSprite >::InEvent(m_Type, m_Inversed)) if (Ent< CSprite >::InEvent(m_Type, m_Inversed))
{ {
m_Sprites.Hook(); m_Sprites.Hook(type, func);
} }
if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed)) if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed))
{ {
m_Textdraws.Hook(); m_Textdraws.Hook(type, func);
} }
if (Ent< CVehicle >::InEvent(m_Type, m_Inversed)) if (Ent< CVehicle >::InEvent(m_Type, m_Inversed))
{ {
m_Vehicles.Hook(); m_Vehicles.Hook(type, func);
} }
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void LocalEvent::Unhook() void LocalEvent::Unhook(const char * type, const char * func)
{ {
if (Ent< CBlip >::InEvent(m_Type, m_Inversed)) if (Ent< CBlip >::InEvent(m_Type, m_Inversed))
{ {
m_Blips.Unhook(); m_Blips.Unhook(type, func);
} }
if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed)) if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed))
{ {
m_Checkpoints.Unhook(); m_Checkpoints.Unhook(type, func);
} }
if (Ent< CKeybind >::InEvent(m_Type, m_Inversed)) if (Ent< CKeybind >::InEvent(m_Type, m_Inversed))
{ {
m_Keybinds.Unhook(); m_Keybinds.Unhook(type, func);
} }
if (Ent< CObject >::InEvent(m_Type, m_Inversed)) if (Ent< CObject >::InEvent(m_Type, m_Inversed))
{ {
m_Objects.Unhook(); m_Objects.Unhook(type, func);
} }
if (Ent< CPickup >::InEvent(m_Type, m_Inversed)) if (Ent< CPickup >::InEvent(m_Type, m_Inversed))
{ {
m_Pickups.Unhook(); m_Pickups.Unhook(type, func);
} }
if (Ent< CPlayer >::InEvent(m_Type, m_Inversed)) if (Ent< CPlayer >::InEvent(m_Type, m_Inversed))
{ {
m_Players.Unhook(); m_Players.Unhook(type, func);
} }
if (Ent< CSphere >::InEvent(m_Type, m_Inversed)) if (Ent< CSphere >::InEvent(m_Type, m_Inversed))
{ {
m_Spheres.Unhook(); m_Spheres.Unhook(type, func);
} }
if (Ent< CSprite >::InEvent(m_Type, m_Inversed)) if (Ent< CSprite >::InEvent(m_Type, m_Inversed))
{ {
m_Sprites.Unhook(); m_Sprites.Unhook(type, func);
} }
if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed)) if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed))
{ {
m_Textdraws.Unhook(); m_Textdraws.Unhook(type, func);
} }
if (Ent< CVehicle >::InEvent(m_Type, m_Inversed)) if (Ent< CVehicle >::InEvent(m_Type, m_Inversed))
{ {
m_Vehicles.Unhook(); m_Vehicles.Unhook(type, func);
} }
} }

View File

@ -74,7 +74,8 @@ public:
*/ */
~LocalFilter() ~LocalFilter()
{ {
Unhook(); /* No need to listen listen to events from the specified entities anymore! */ /* No need to listen listen to events from the specified entities anymore! */
Unhook(ToStrF("%sLocalFilter", EntType::Name), "destructor");
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
@ -161,8 +162,9 @@ public:
} }
else else
{ {
LogWrn("Cannot test whether a <%s> entity is filtered or not using an invalid instance: %d", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "enabled",
EntType::Name, _SCI32(ent)); "Attempting to <see whether entity is filtered> using an invalid reference: %d", \
_SCI32(ent));
} }
return false; return false;
@ -228,12 +230,12 @@ protected:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Hook to the entity destroy signal that the parent didn't. * Hook to the entity destroy signal that the parent didn't.
*/ */
void Hook(); void Hook(const char * type, const char * func);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Unhook from the entity destroy signal that the parent didn't. * Unhook from the entity destroy signal that the parent didn't.
*/ */
void Unhook(); void Unhook(const char * type, const char * func);
private: private:
@ -1045,32 +1047,32 @@ protected:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Attach(); void Attach(const char * type, const char * func);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Attach(SQInt32 id); void Attach(const char * type, const char * func, SQInt32 id);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Detach(); void Detach(const char * type, const char * func);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Detach(SQInt32 id); void Detach(const char * type, const char * func, SQInt32 id);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Hook(); void Hook(const char * type, const char * func);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void Unhook(); void Unhook(const char * type, const char * func);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
@ -1128,11 +1130,11 @@ template < class T > LocalFilter< T > & LocalFilter< T >::operator = (const Loca
if (this != &o && EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed)) if (this != &o && EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{ {
// Unhook from the currently filtered entities // Unhook from the currently filtered entities
Unhook(); Unhook(ToStrF("%sLocalFilter", EntType::Name), "copy");
// Copy the internal filter from the other instance // Copy the internal filter from the other instance
m_Filter = o.m_Filter; m_Filter = o.m_Filter;
// Hook back to the newly filtered entities // Hook back to the newly filtered entities
Hook(); Hook(ToStrF("%sLocalFilter", EntType::Name), "copy");
/* Parent is ignored intentionally as filters should not change parents! */ /* Parent is ignored intentionally as filters should not change parents! */
} }
@ -1145,14 +1147,15 @@ template < class T > bool LocalFilter< T >::Include(const RefType & ent, SQInt32
// Make sure the entity is valid before we proceed // Make sure the entity is valid before we proceed
if (!ent) if (!ent)
{ {
LogErr("Attempting to <filter %s events> using an invalid entity instance: %d", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "include",
EntType::Name, _SCI32(ent)); "Attempting to <filter events> using an invalid reference: %d", _SCI32(ent));
} }
// Make sure the entity type is allowed for this event type // Make sure the entity type is allowed for this event type
else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed)) else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{ {
LogErr("Attempting to <filter %s events> using an incompatible event type: %s", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "include",
EntType::Name, GetEventName(m_Event->m_Type)); "Attempting to <filter events> for an incompatible event type: %s",
GetEventName(m_Event->m_Type));
} }
// Make sure the entity is not already included in the filter // Make sure the entity is not already included in the filter
else if (!m_Filter[_SCU32(ent)]) else if (!m_Filter[_SCU32(ent)])
@ -1176,7 +1179,7 @@ template < class T > bool LocalFilter< T >::Include(const RefType & ent, SQInt32
RefType::Get(_SCI32(ent)).Destroyed().template Connect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this); RefType::Get(_SCI32(ent)).Destroyed().template Connect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this);
} }
// Just attach to the specified entity as normally // Just attach to the specified entity as normally
m_Event->Attach(_SCI32(ent)); m_Event->Attach(ToStrF("%sLocalFilter", EntType::Name), "include", _SCI32(ent));
// Enable the specified entity instance in our filter // Enable the specified entity instance in our filter
m_Filter.set(_SCU32(ent), true); m_Filter.set(_SCU32(ent), true);
} }
@ -1193,14 +1196,15 @@ template < class T > bool LocalFilter< T >::Exclude(const RefType & ent, SQInt32
// Make sure the entity is valid before we proceed // Make sure the entity is valid before we proceed
if (!ent) if (!ent)
{ {
LogErr("Attempting to <unfilter %s events> using an invalid entity instance: %d", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "exclude",
EntType::Name, _SCI32(ent)); "Attempting to <unfilter events> using an invalid reference: %d", _SCI32(ent));
} }
// Make sure the entity type is allowed for this event type // Make sure the entity type is allowed for this event type
else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed)) else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{ {
LogErr("Attempting to <unfilter %s events> using an incompatible event type: %s", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "exclude",
EntType::Name, GetEventName(m_Event->m_Type)); "Attempting to <unfilter events> for an incompatible event type: %s",
GetEventName(m_Event->m_Type));
} }
// Make sure the entity is not already excluded fom the filter // Make sure the entity is not already excluded fom the filter
else if (m_Filter[_SCU32(ent)]) else if (m_Filter[_SCU32(ent)])
@ -1224,7 +1228,7 @@ template < class T > bool LocalFilter< T >::Exclude(const RefType & ent, SQInt32
RefType::Get(_SCI32(ent)).Destroyed().template Disconnect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this); RefType::Get(_SCI32(ent)).Destroyed().template Disconnect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this);
} }
// Just detach from the specified entity as normally // Just detach from the specified entity as normally
m_Event->Detach(_SCI32(ent)); m_Event->Detach(ToStrF("%sLocalFilter", EntType::Name), "exclude", _SCI32(ent));
// Disable the specified entity instance in our filter // Disable the specified entity instance in our filter
m_Filter.set(_SCU32(ent), false); m_Filter.set(_SCU32(ent), false);
} }
@ -1241,8 +1245,9 @@ template < class T > void LocalFilter< T >::Clear(SQInt32 header)
// Make sure the filter is compatible with the specified event type // Make sure the filter is compatible with the specified event type
if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed)) if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{ {
LogWrn("Attempting to <clear %s filter> using an incompatible event type: %s", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "clear",
EntType::Name, GetEventName(m_Event->m_Type)); "Attempting to <clear filter> for an incompatible event type: %s",
GetEventName(m_Event->m_Type));
} }
// Don't even attempt to clear if there's nothing to be cleared // Don't even attempt to clear if there's nothing to be cleared
else if (m_Filter.any()) else if (m_Filter.any())
@ -1253,7 +1258,7 @@ template < class T > void LocalFilter< T >::Clear(SQInt32 header)
m_Event->m_OnCleared.Execute< SQInt32 >(header); m_Event->m_OnCleared.Execute< SQInt32 >(header);
} }
// Unhook from the currently filtered entities // Unhook from the currently filtered entities
Unhook(); Unhook(ToStrF("%sLocalFilter", EntType::Name), "clear");
// Now it's safe to reset the filter // Now it's safe to reset the filter
m_Filter.reset(); m_Filter.reset();
} }
@ -1266,18 +1271,19 @@ template < class T > void LocalFilter< T >::Flip(SQInt32 header)
// Make sure the filter is compatible with the parent event type // Make sure the filter is compatible with the parent event type
if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed)) if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{ {
LogWrn("Attempting to <flip %s filter> using an incompatible event type: %s", \ DbgErr(ToStrF("%sLocalFilter", EntType::Name), "flip",
EntType::Name, GetEventName(m_Event->m_Type)); "Attempting to <flip filter> for an incompatible event type: %s",
GetEventName(m_Event->m_Type));
} }
// Now it's safe to proceed with reversing the filters // Now it's safe to proceed with reversing the filters
else else
{ {
// Unhook from the currently filtered entities // Unhook from the currently filtered entities
Unhook(); Unhook(ToStrF("%sLocalFilter", EntType::Name), "flip");
// Reverse the values in the internal filter // Reverse the values in the internal filter
m_Filter.flip(); m_Filter.flip();
// Hook from the newly filtered entities // Hook from the newly filtered entities
Hook(); Hook(ToStrF("%sLocalFilter", EntType::Name), "flip");
} }
SQMOD_UNUSED_VAR(header); SQMOD_UNUSED_VAR(header);
} }
@ -1295,7 +1301,7 @@ template < class T > void LocalFilter< T >::Release(SQInt32 id)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template < class T > void LocalFilter< T >::Hook() template < class T > void LocalFilter< T >::Hook(const char * type, const char * func)
{ {
// No iterators here because we're dealing with a bitset! // No iterators here because we're dealing with a bitset!
unsigned i = 0; unsigned i = 0;
@ -1311,7 +1317,7 @@ template < class T > void LocalFilter< T >::Hook()
RefType::Get(i).Destroyed().template Connect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this); RefType::Get(i).Destroyed().template Connect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this);
} }
// Just attach to the specified entity as normally // Just attach to the specified entity as normally
m_Event->Attach(i); m_Event->Attach(type, func, i);
} }
// If this entity is not active then disable it from the filter as well // If this entity is not active then disable it from the filter as well
else if (!enabled) else if (!enabled)
@ -1322,7 +1328,7 @@ template < class T > void LocalFilter< T >::Hook()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template < class T > void LocalFilter< T >::Unhook() template < class T > void LocalFilter< T >::Unhook(const char * type, const char * func)
{ {
// No iterators here because we're dealing with a bitset! // No iterators here because we're dealing with a bitset!
unsigned i = 0; unsigned i = 0;
@ -1338,7 +1344,7 @@ template < class T > void LocalFilter< T >::Unhook()
RefType::Get(i).Destroyed().template Disconnect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this); RefType::Get(i).Destroyed().template Disconnect< LocalFilter< T >, &LocalFilter< T >::Destroyed >(this);
} }
// Just detach from the specified entity as normally // Just detach from the specified entity as normally
m_Event->Detach(i); m_Event->Detach(type, func, i);
} }
// If this entity is not active then disable it from the filter as well // If this entity is not active then disable it from the filter as well
else if (!enabled) else if (!enabled)