1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +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()
{
// Detach from all attached signals
Detach();
Detach("LocalEvent", "destructor");
// Stop receiving notification when the VM is about to be closed
_Core->VMClose.Disconnect< LocalEvent, &LocalEvent::VMClose >(this);
/* 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
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
{
// Clear anything that cannot adapt to the new event type
Adaptable(type, m_Inversed);
// Detach from the current event type
Detach();
Detach("LocalEvent", "@type");
// Set the new event type
m_Type = type;
// Attach to the new event type
Attach();
Attach("LocalEvent", "@type");
}
}
@ -271,7 +272,7 @@ void LocalEvent::SetInversed(bool toggle)
// Toggle the inversed option
m_Inversed = toggle;
// Attach back to the new event type
Attach();
Attach("LocalEvent", "@inversed");
}
// Just set the option to what was requested
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
Hook();
Hook(type, func);
}
// ------------------------------------------------------------------------------------------------
void LocalEvent::Attach(SQInt32 id)
void LocalEvent::Attach(const char * type, const char * func, SQInt32 id)
{
switch (m_Type)
{
@ -1718,19 +1719,20 @@ void LocalEvent::Attach(SQInt32 id)
}
break;
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
Unhook();
Unhook(type, func);
}
// ------------------------------------------------------------------------------------------------
void LocalEvent::Detach(SQInt32 id)
void LocalEvent::Detach(const char * type, const char * func, SQInt32 id)
{
switch (m_Type)
{
@ -2078,115 +2080,116 @@ void LocalEvent::Detach(SQInt32 id)
}
break;
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))
{
m_Blips.Hook();
m_Blips.Hook(type, func);
}
if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed))
{
m_Checkpoints.Hook();
m_Checkpoints.Hook(type, func);
}
if (Ent< CKeybind >::InEvent(m_Type, m_Inversed))
{
m_Keybinds.Hook();
m_Keybinds.Hook(type, func);
}
if (Ent< CObject >::InEvent(m_Type, m_Inversed))
{
m_Objects.Hook();
m_Objects.Hook(type, func);
}
if (Ent< CPickup >::InEvent(m_Type, m_Inversed))
{
m_Pickups.Hook();
m_Pickups.Hook(type, func);
}
if (Ent< CPlayer >::InEvent(m_Type, m_Inversed))
{
m_Players.Hook();
m_Players.Hook(type, func);
}
if (Ent< CSphere >::InEvent(m_Type, m_Inversed))
{
m_Spheres.Hook();
m_Spheres.Hook(type, func);
}
if (Ent< CSprite >::InEvent(m_Type, m_Inversed))
{
m_Sprites.Hook();
m_Sprites.Hook(type, func);
}
if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed))
{
m_Textdraws.Hook();
m_Textdraws.Hook(type, func);
}
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))
{
m_Blips.Unhook();
m_Blips.Unhook(type, func);
}
if (Ent< CCheckpoint >::InEvent(m_Type, m_Inversed))
{
m_Checkpoints.Unhook();
m_Checkpoints.Unhook(type, func);
}
if (Ent< CKeybind >::InEvent(m_Type, m_Inversed))
{
m_Keybinds.Unhook();
m_Keybinds.Unhook(type, func);
}
if (Ent< CObject >::InEvent(m_Type, m_Inversed))
{
m_Objects.Unhook();
m_Objects.Unhook(type, func);
}
if (Ent< CPickup >::InEvent(m_Type, m_Inversed))
{
m_Pickups.Unhook();
m_Pickups.Unhook(type, func);
}
if (Ent< CPlayer >::InEvent(m_Type, m_Inversed))
{
m_Players.Unhook();
m_Players.Unhook(type, func);
}
if (Ent< CSphere >::InEvent(m_Type, m_Inversed))
{
m_Spheres.Unhook();
m_Spheres.Unhook(type, func);
}
if (Ent< CSprite >::InEvent(m_Type, m_Inversed))
{
m_Sprites.Unhook();
m_Sprites.Unhook(type, func);
}
if (Ent< CTextdraw >::InEvent(m_Type, m_Inversed))
{
m_Textdraws.Unhook();
m_Textdraws.Unhook(type, func);
}
if (Ent< CVehicle >::InEvent(m_Type, m_Inversed))
{
m_Vehicles.Unhook();
m_Vehicles.Unhook(type, func);
}
}

View File

@ -74,7 +74,8 @@ public:
*/
~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
{
LogWrn("Cannot test whether a <%s> entity is filtered or not using an invalid instance: %d", \
EntType::Name, _SCI32(ent));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "enabled",
"Attempting to <see whether entity is filtered> using an invalid reference: %d", \
_SCI32(ent));
}
return false;
@ -228,12 +230,12 @@ protected:
/* --------------------------------------------------------------------------------------------
* 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.
*/
void Unhook();
void Unhook(const char * type, const char * func);
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))
{
// Unhook from the currently filtered entities
Unhook();
Unhook(ToStrF("%sLocalFilter", EntType::Name), "copy");
// Copy the internal filter from the other instance
m_Filter = o.m_Filter;
// Hook back to the newly filtered entities
Hook();
Hook(ToStrF("%sLocalFilter", EntType::Name), "copy");
/* 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
if (!ent)
{
LogErr("Attempting to <filter %s events> using an invalid entity instance: %d", \
EntType::Name, _SCI32(ent));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "include",
"Attempting to <filter events> using an invalid reference: %d", _SCI32(ent));
}
// Make sure the entity type is allowed for this event type
else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{
LogErr("Attempting to <filter %s events> using an incompatible event type: %s", \
EntType::Name, GetEventName(m_Event->m_Type));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "include",
"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
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);
}
// 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
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
if (!ent)
{
LogErr("Attempting to <unfilter %s events> using an invalid entity instance: %d", \
EntType::Name, _SCI32(ent));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "exclude",
"Attempting to <unfilter events> using an invalid reference: %d", _SCI32(ent));
}
// Make sure the entity type is allowed for this event type
else if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{
LogErr("Attempting to <unfilter %s events> using an incompatible event type: %s", \
EntType::Name, GetEventName(m_Event->m_Type));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "exclude",
"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
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);
}
// 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
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
if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{
LogWrn("Attempting to <clear %s filter> using an incompatible event type: %s", \
EntType::Name, GetEventName(m_Event->m_Type));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "clear",
"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
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);
}
// Unhook from the currently filtered entities
Unhook();
Unhook(ToStrF("%sLocalFilter", EntType::Name), "clear");
// Now it's safe to reset the filter
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
if (!EntType::InEvent(m_Event->m_Type, m_Event->m_Inversed))
{
LogWrn("Attempting to <flip %s filter> using an incompatible event type: %s", \
EntType::Name, GetEventName(m_Event->m_Type));
DbgErr(ToStrF("%sLocalFilter", EntType::Name), "flip",
"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
else
{
// Unhook from the currently filtered entities
Unhook();
Unhook(ToStrF("%sLocalFilter", EntType::Name), "flip");
// Reverse the values in the internal filter
m_Filter.flip();
// Hook from the newly filtered entities
Hook();
Hook(ToStrF("%sLocalFilter", EntType::Name), "flip");
}
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!
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);
}
// 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
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!
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);
}
// 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
else if (!enabled)