chore(style): clean up line endings in event

This commit is contained in:
fallenoak 2025-11-20 21:36:18 -06:00
parent 4c8fc4e7a9
commit be1ab67257
2 changed files with 445 additions and 450 deletions

View file

@ -1,422 +1,420 @@
#include "Event.hpp" #include "Event.hpp"
#include <cstdint> #include <cstdint>
#include "list/TSList.hpp" #include "list/TSList.hpp"
#include "thread/CCritSect.hpp" #include "thread/CCritSect.hpp"
#include "Atomic.hpp" #include "Atomic.hpp"
#include "Error.hpp" #include "Error.hpp"
#include "Memory.hpp" #include "Memory.hpp"
struct BREAKCMD : public TSLinkedNode<BREAKCMD> {
struct BREAKCMD : public TSLinkedNode<BREAKCMD> { void* data;
void* data; };
};
static CCritSect s_critsect;
static CCritSect s_critsect; static TSList<BREAKCMD, TSGetLink<BREAKCMD>> s_breakcmdlist;
static TSList<BREAKCMD, TSGetLink<BREAKCMD>> s_breakcmdlist; static int32_t s_modified;
static int32_t s_modified; static ATOMIC32 s_dispatchesinprogress;
static ATOMIC32 s_dispatchesinprogress;
struct _IDHASHENTRY {
uint32_t id;
struct _IDHASHENTRY { uint32_t sequence;
uint32_t id; SEVTHANDLER handler;
uint32_t sequence; _IDHASHENTRY* next;
SEVTHANDLER handler; };
_IDHASHENTRY* next;
}; struct _IDHASHTABLE {
_IDHASHENTRY** data;
struct _IDHASHTABLE { uint32_t size;
_IDHASHENTRY** data; uint32_t used;
uint32_t size; _IDHASHTABLE* next;
uint32_t used; };
_IDHASHTABLE* next;
}; struct _TYPEHASHENTRY {
uint32_t type;
struct _TYPEHASHENTRY { uint32_t subtype;
uint32_t type; uint32_t sequence;
uint32_t subtype; _IDHASHTABLE* idhashtable;
uint32_t sequence; _TYPEHASHENTRY* next;
_IDHASHTABLE* idhashtable; };
_TYPEHASHENTRY* next;
}; static _TYPEHASHENTRY **s_typehashtable;
static uint32_t s_typehashtablesize;
static _TYPEHASHENTRY **s_typehashtable; static uint32_t s_typehashtableused;
static uint32_t s_typehashtablesize;
static uint32_t s_typehashtableused; // Fake function to make tests not bleed into each other
void SEvtCleanExtraDataForTests() {
// Fake function to make tests not bleed into each other s_breakcmdlist.Clear();
void SEvtCleanExtraDataForTests() { }
s_breakcmdlist.Clear();
} void DeleteIdHashTable(_IDHASHTABLE* pTable) {
for (uint32_t i = 0; i < pTable->size; i++) {
void DeleteIdHashTable(_IDHASHTABLE* pTable) { for (_IDHASHENTRY* pEntry = pTable->data[i]; pEntry; pEntry = pTable->data[i]) {
for (uint32_t i = 0; i < pTable->size; i++) { pTable->data[i] = pEntry->next;
for (_IDHASHENTRY* pEntry = pTable->data[i]; pEntry; pEntry = pTable->data[i]) { delete pEntry;
pTable->data[i] = pEntry->next; }
delete pEntry; }
} STORM_FREE(pTable->data);
} delete pTable;
STORM_FREE(pTable->data); }
delete pTable;
} _TYPEHASHENTRY* FindTypeHashEntry(uint32_t type, uint32_t subtype) {
if (!s_typehashtable || s_typehashtablesize == 0) {
_TYPEHASHENTRY* FindTypeHashEntry(uint32_t type, uint32_t subtype) { return nullptr;
if (!s_typehashtable || s_typehashtablesize == 0) { }
return nullptr;
} for (_TYPEHASHENTRY* pEntry = s_typehashtable[(s_typehashtablesize - 1) & (subtype ^ type)]; pEntry; pEntry = pEntry->next) {
if (pEntry->type == type && pEntry->subtype == subtype) {
for (_TYPEHASHENTRY* pEntry = s_typehashtable[(s_typehashtablesize - 1) & (subtype ^ type)]; pEntry; pEntry = pEntry->next) { return pEntry;
if (pEntry->type == type && pEntry->subtype == subtype) { }
return pEntry; }
} return nullptr;
} }
return nullptr;
} uint32_t ComputeNewTableSize(uint32_t size) {
uint32_t result = 1;
uint32_t ComputeNewTableSize(uint32_t size) { while (result <= size * 2 + 2) {
uint32_t result = 1; result *= 2;
while (result <= size * 2 + 2) { }
result *= 2; return result;
} }
return result;
} void CopyIdHashTable(_IDHASHTABLE *dest, _IDHASHTABLE *source) {
dest->size = source->size;
void CopyIdHashTable(_IDHASHTABLE *dest, _IDHASHTABLE *source) { dest->used = source->used;
dest->size = source->size; dest->data = (_IDHASHENTRY**)STORM_ALLOC(sizeof(_IDHASHENTRY*) * dest->size);
dest->used = source->used;
dest->data = (_IDHASHENTRY**)STORM_ALLOC(sizeof(_IDHASHENTRY*) * dest->size); for (uint32_t i = 0; i < source->size; i++) {
_IDHASHENTRY* pSourceData = source->data[i];
for (uint32_t i = 0; i < source->size; i++) { _IDHASHENTRY** ppDestData = &dest->data[i];
_IDHASHENTRY* pSourceData = source->data[i]; for (; pSourceData; pSourceData = pSourceData->next) {
_IDHASHENTRY** ppDestData = &dest->data[i]; _IDHASHENTRY* pNewEntry = STORM_NEW(_IDHASHENTRY);
for (; pSourceData; pSourceData = pSourceData->next) {
_IDHASHENTRY* pNewEntry = STORM_NEW(_IDHASHENTRY); *ppDestData = pNewEntry;
*pNewEntry = *pSourceData;
*ppDestData = pNewEntry; ppDestData = &(*ppDestData)->next;
*pNewEntry = *pSourceData; }
ppDestData = &(*ppDestData)->next; *ppDestData = nullptr;
} }
*ppDestData = nullptr; }
}
} int32_t STORMAPI SEvtBreakHandlerChain(void* data) {
s_critsect.Enter();
int32_t STORMAPI SEvtBreakHandlerChain(void* data) { s_breakcmdlist.NewNode(2, 0, 0)->data = data;
s_critsect.Enter(); s_critsect.Leave();
s_breakcmdlist.NewNode(2, 0, 0)->data = data; return 1;
s_critsect.Leave(); }
return 1;
} int32_t STORMAPI SEvtDestroy() {
s_critsect.Enter();
int32_t STORMAPI SEvtDestroy() {
s_critsect.Enter(); for (uint32_t i = 0; i < s_typehashtablesize; i++) {
for (_TYPEHASHENTRY* pTypeEntry = s_typehashtable[i]; pTypeEntry; pTypeEntry = s_typehashtable[i]) {
for (uint32_t i = 0; i < s_typehashtablesize; i++) { for (_IDHASHTABLE* pTable = pTypeEntry->idhashtable; pTable; pTable = pTypeEntry->idhashtable) {
for (_TYPEHASHENTRY* pTypeEntry = s_typehashtable[i]; pTypeEntry; pTypeEntry = s_typehashtable[i]) { pTypeEntry->idhashtable = pTable->next;
for (_IDHASHTABLE* pTable = pTypeEntry->idhashtable; pTable; pTable = pTypeEntry->idhashtable) { DeleteIdHashTable(pTable);
pTypeEntry->idhashtable = pTable->next; }
DeleteIdHashTable(pTable); s_typehashtable[i] = pTypeEntry->next;
} delete pTypeEntry;
s_typehashtable[i] = pTypeEntry->next; }
delete pTypeEntry; }
}
} if (s_typehashtable) {
delete s_typehashtable;
if (s_typehashtable) { }
delete s_typehashtable; s_typehashtable = nullptr;
} s_typehashtablesize = 0;
s_typehashtable = nullptr; s_typehashtableused = 0;
s_typehashtablesize = 0;
s_typehashtableused = 0; s_modified = 1;
s_modified = 1; s_critsect.Leave();
return 1;
s_critsect.Leave(); }
return 1;
} int32_t STORMAPI SEvtDispatch(uint32_t type, uint32_t subtype, uint32_t id, void* data) {
SInterlockedIncrement(&s_dispatchesinprogress);
int32_t STORMAPI SEvtDispatch(uint32_t type, uint32_t subtype, uint32_t id, void* data) {
SInterlockedIncrement(&s_dispatchesinprogress); int32_t success = 0;
uint32_t currsequence = -1;
int32_t success = 0; _IDHASHENTRY *currptr = nullptr;
uint32_t currsequence = -1;
_IDHASHENTRY *currptr = nullptr; do {
s_critsect.Enter();
do {
s_critsect.Enter(); bool breakcmd = false;
for (BREAKCMD* curr = s_breakcmdlist.Head(); reinterpret_cast<intptr_t>(curr) > 0; curr = s_breakcmdlist.RawNext(curr)) {
bool breakcmd = false; if (curr->data == data) {
for (BREAKCMD* curr = s_breakcmdlist.Head(); reinterpret_cast<intptr_t>(curr) > 0; curr = s_breakcmdlist.RawNext(curr)) { breakcmd = true;
if (curr->data == data) { s_breakcmdlist.DeleteNode(curr);
breakcmd = true; break;
s_breakcmdlist.DeleteNode(curr); }
break; }
} if (breakcmd) {
} s_critsect.Leave();
if (breakcmd) { break;
s_critsect.Leave(); }
break;
} if (!currptr || s_modified) {
currptr = nullptr;
if (!currptr || s_modified) { auto typeentry = FindTypeHashEntry(type, subtype);
currptr = nullptr; if (typeentry) {
auto typeentry = FindTypeHashEntry(type, subtype); _IDHASHTABLE* idhash = typeentry->idhashtable;
if (typeentry) { if (idhash->data && idhash->size != 0) {
_IDHASHTABLE* idhash = typeentry->idhashtable; for (currptr = idhash->data[id & (idhash->size - 1)]; currptr; currptr = currptr->next) {
if (idhash->data && idhash->size != 0) { if (currptr->id == id && currptr->sequence < currsequence) {
for (currptr = idhash->data[id & (idhash->size - 1)]; currptr; currptr = currptr->next) { break;
if (currptr->id == id && currptr->sequence < currsequence) { }
break; }
}
} if (s_dispatchesinprogress == 1) {
s_modified = 0;
if (s_dispatchesinprogress == 1) { }
s_modified = 0; }
} }
} }
}
} SEVTHANDLER handler = nullptr;
SEVTHANDLER handler = nullptr; if (currptr) {
handler = currptr->handler;
if (currptr) { currsequence = currptr->sequence;
handler = currptr->handler; do {
currsequence = currptr->sequence; currptr = currptr->next;
do { } while (currptr && currptr->id != id);
currptr = currptr->next; }
} while (currptr && currptr->id != id);
} s_critsect.Leave();
s_critsect.Leave(); if (handler) {
success = 1;
if (handler) { handler(data);
success = 1; }
handler(data); } while(currptr);
}
} while(currptr); SInterlockedDecrement(&s_dispatchesinprogress);
SInterlockedDecrement(&s_dispatchesinprogress); if (s_breakcmdlist.Head()) {
s_critsect.Enter();
if (s_breakcmdlist.Head()) {
s_critsect.Enter(); for (BREAKCMD* curr = s_breakcmdlist.Head(); reinterpret_cast<intptr_t>(curr) > 0;) {
if (curr->data == data) {
for (BREAKCMD* curr = s_breakcmdlist.Head(); reinterpret_cast<intptr_t>(curr) > 0;) { curr = s_breakcmdlist.DeleteNode(curr);
if (curr->data == data) { }
curr = s_breakcmdlist.DeleteNode(curr); else {
} curr = s_breakcmdlist.RawNext(curr);
else { }
curr = s_breakcmdlist.RawNext(curr); }
}
} s_critsect.Leave();
}
s_critsect.Leave(); return success;
} }
return success;
} int32_t STORMAPI SEvtPopState(uint32_t type, uint32_t subtype) {
int32_t success = 0;
int32_t STORMAPI SEvtPopState(uint32_t type, uint32_t subtype) { s_critsect.Enter();
int32_t success = 0;
s_critsect.Enter(); _TYPEHASHENTRY* typeentry = FindTypeHashEntry(type, subtype);
if (typeentry) {
_TYPEHASHENTRY* typeentry = FindTypeHashEntry(type, subtype); _IDHASHTABLE *next = typeentry->idhashtable->next;
if (typeentry) { if (next) {
_IDHASHTABLE *next = typeentry->idhashtable->next; DeleteIdHashTable(typeentry->idhashtable);
if (next) { typeentry->idhashtable = next;
DeleteIdHashTable(typeentry->idhashtable); }
typeentry->idhashtable = next; else {
} // This WILL hang if called without recursive CCritSect.
else { // Provide a hack since it never gets called in WoW anyway.
// This WILL hang if called without recursive CCritSect. // It also doesn't get called by SC for that matter. Nothing calls it. Classic.
// Provide a hack since it never gets called in WoW anyway. #if !defined(WHOA_STORM_C_CRIT_SECT_RECURSIVE)
// It also doesn't get called by SC for that matter. Nothing calls it. Classic. s_critsect.Leave();
#if !defined(WHOA_STORM_C_CRIT_SECT_RECURSIVE) success = SEvtUnregisterType(type, subtype);
s_critsect.Leave(); s_critsect.Enter();
success = SEvtUnregisterType(type, subtype); #else
s_critsect.Enter(); success = SEvtUnregisterType(type, subtype);
#else #endif
success = SEvtUnregisterType(type, subtype); }
#endif }
}
} s_modified = 1;
s_critsect.Leave();
s_modified = 1; return success;
s_critsect.Leave(); }
return success;
} int32_t STORMAPI SEvtPushState(uint32_t type, uint32_t subtype) {
int32_t success = 0;
int32_t STORMAPI SEvtPushState(uint32_t type, uint32_t subtype) { s_critsect.Enter();
int32_t success = 0;
s_critsect.Enter(); _TYPEHASHENTRY* pTypeHash = FindTypeHashEntry(type, subtype);
if (pTypeHash) {
_TYPEHASHENTRY* pTypeHash = FindTypeHashEntry(type, subtype); _IDHASHTABLE* pNewTable = STORM_NEW(_IDHASHTABLE);
if (pTypeHash) {
_IDHASHTABLE* pNewTable = STORM_NEW(_IDHASHTABLE); CopyIdHashTable(pNewTable, pTypeHash->idhashtable);
pNewTable->next = pTypeHash->idhashtable;
CopyIdHashTable(pNewTable, pTypeHash->idhashtable); pTypeHash->idhashtable = pNewTable;
pNewTable->next = pTypeHash->idhashtable;
pTypeHash->idhashtable = pNewTable; success = 1;
s_modified = 1;
success = 1; }
s_modified = 1;
} s_critsect.Leave();
return success;
s_critsect.Leave(); }
return success;
} int32_t STORMAPI SEvtRegisterHandler(uint32_t type, uint32_t subtype, uint32_t id, uint32_t flags, SEVTHANDLER handler) {
STORM_VALIDATE_BEGIN;
int32_t STORMAPI SEvtRegisterHandler(uint32_t type, uint32_t subtype, uint32_t id, uint32_t flags, SEVTHANDLER handler) { STORM_VALIDATE(handler);
STORM_VALIDATE_BEGIN; STORM_VALIDATE(!flags);
STORM_VALIDATE(handler); STORM_VALIDATE_END;
STORM_VALIDATE(!flags);
STORM_VALIDATE_END; s_critsect.Enter();
s_critsect.Enter(); _TYPEHASHENTRY* pTypeHash = FindTypeHashEntry(type, subtype);
if (!pTypeHash) {
_TYPEHASHENTRY* pTypeHash = FindTypeHashEntry(type, subtype); if (s_typehashtableused >= s_typehashtablesize / 2) {
if (!pTypeHash) { uint32_t newsize = ComputeNewTableSize(s_typehashtableused);
if (s_typehashtableused >= s_typehashtablesize / 2) { _TYPEHASHENTRY** pNewTable = static_cast<_TYPEHASHENTRY**>(STORM_ALLOC_ZERO(sizeof(_TYPEHASHENTRY*) * newsize));
uint32_t newsize = ComputeNewTableSize(s_typehashtableused);
_TYPEHASHENTRY** pNewTable = static_cast<_TYPEHASHENTRY**>(STORM_ALLOC_ZERO(sizeof(_TYPEHASHENTRY*) * newsize)); if (s_typehashtable) {
for (uint32_t i = 0; i < s_typehashtablesize; i++) {
if (s_typehashtable) { _TYPEHASHENTRY* pNext;
for (uint32_t i = 0; i < s_typehashtablesize; i++) { for (_TYPEHASHENTRY* pTable = s_typehashtable[i]; pTable; pTable = pNext) {
_TYPEHASHENTRY* pNext; pNext = pTable->next;
for (_TYPEHASHENTRY* pTable = s_typehashtable[i]; pTable; pTable = pNext) {
pNext = pTable->next; uint32_t idx = (newsize - 1) & (pTable->type ^ pTable->subtype);
pTable->next = pNewTable[idx];
uint32_t idx = (newsize - 1) & (pTable->type ^ pTable->subtype); pNewTable[idx] = pTable;
pTable->next = pNewTable[idx]; }
pNewTable[idx] = pTable; }
} if (s_typehashtable) {
} STORM_FREE(s_typehashtable);
if (s_typehashtable) { }
STORM_FREE(s_typehashtable); }
} s_typehashtable = pNewTable;
} s_typehashtablesize = newsize;
s_typehashtable = pNewTable; }
s_typehashtablesize = newsize;
} uint32_t idx = (s_typehashtablesize - 1) & (type ^ subtype);
uint32_t idx = (s_typehashtablesize - 1) & (type ^ subtype); _TYPEHASHENTRY* pNewTypeHash = STORM_NEW_ZERO(_TYPEHASHENTRY);
_TYPEHASHENTRY* pNewTypeHash = STORM_NEW_ZERO(_TYPEHASHENTRY); pNewTypeHash->type = type;
pNewTypeHash->subtype = subtype;
pNewTypeHash->type = type; pNewTypeHash->idhashtable = STORM_NEW_ZERO(_IDHASHTABLE);
pNewTypeHash->subtype = subtype; pNewTypeHash->next = s_typehashtable[idx];
pNewTypeHash->idhashtable = STORM_NEW_ZERO(_IDHASHTABLE);
pNewTypeHash->next = s_typehashtable[idx]; s_typehashtable[idx] = pNewTypeHash;
s_typehashtableused++;
s_typehashtable[idx] = pNewTypeHash;
s_typehashtableused++; pTypeHash = pNewTypeHash;
}
pTypeHash = pNewTypeHash;
} if (pTypeHash->idhashtable->used >= pTypeHash->idhashtable->size / 2) {
uint32_t newsize = ComputeNewTableSize(pTypeHash->idhashtable->size);
if (pTypeHash->idhashtable->used >= pTypeHash->idhashtable->size / 2) { _IDHASHENTRY** pNewTable = static_cast<_IDHASHENTRY**>(STORM_ALLOC_ZERO(sizeof(_IDHASHENTRY*) * newsize));
uint32_t newsize = ComputeNewTableSize(pTypeHash->idhashtable->size); _IDHASHENTRY*** pTempTable = static_cast<_IDHASHENTRY***>(STORM_ALLOC_ZERO(sizeof(_IDHASHENTRY*) * newsize));
_IDHASHENTRY** pNewTable = static_cast<_IDHASHENTRY**>(STORM_ALLOC_ZERO(sizeof(_IDHASHENTRY*) * newsize));
_IDHASHENTRY*** pTempTable = static_cast<_IDHASHENTRY***>(STORM_ALLOC_ZERO(sizeof(_IDHASHENTRY*) * newsize)); for (uint32_t i = 0; i < newsize; i++) {
pTempTable[i] = &pNewTable[i];
for (uint32_t i = 0; i < newsize; i++) { }
pTempTable[i] = &pNewTable[i];
} if (pTypeHash->idhashtable->data && pTypeHash->idhashtable->size != 0) {
for (uint32_t i = 0; i < pTypeHash->idhashtable->size; i++) {
if (pTypeHash->idhashtable->data && pTypeHash->idhashtable->size != 0) { _IDHASHENTRY* pNext;
for (uint32_t i = 0; i < pTypeHash->idhashtable->size; i++) { for (_IDHASHENTRY* pEntry = pTypeHash->idhashtable->data[i]; pEntry; pEntry = pNext) {
_IDHASHENTRY* pNext; uint32_t idx = (newsize - 1) & pEntry->id;
for (_IDHASHENTRY* pEntry = pTypeHash->idhashtable->data[i]; pEntry; pEntry = pNext) { pNext = pEntry->next;
uint32_t idx = (newsize - 1) & pEntry->id; pEntry->next = nullptr;
pNext = pEntry->next;
pEntry->next = nullptr; *pTempTable[idx] = pEntry;
pTempTable[idx] = &pEntry->next;
*pTempTable[idx] = pEntry; }
pTempTable[idx] = &pEntry->next; }
} }
}
} STORM_FREE(pTempTable);
if (pTypeHash->idhashtable->data) {
STORM_FREE(pTempTable); STORM_FREE(pTypeHash->idhashtable->data);
if (pTypeHash->idhashtable->data) { }
STORM_FREE(pTypeHash->idhashtable->data); pTypeHash->idhashtable->data = pNewTable;
} pTypeHash->idhashtable->size = newsize;
pTypeHash->idhashtable->data = pNewTable; }
pTypeHash->idhashtable->size = newsize;
} uint32_t idx = (pTypeHash->idhashtable->size - 1) & id;
_IDHASHENTRY* pNewIdHash = STORM_NEW_ZERO(_IDHASHENTRY);
uint32_t idx = (pTypeHash->idhashtable->size - 1) & id;
_IDHASHENTRY* pNewIdHash = STORM_NEW_ZERO(_IDHASHENTRY); pNewIdHash->id = id;
pNewIdHash->sequence = ++pTypeHash->sequence;
pNewIdHash->id = id; pNewIdHash->handler = handler;
pNewIdHash->sequence = ++pTypeHash->sequence;
pNewIdHash->handler = handler; pNewIdHash->next = pTypeHash->idhashtable->data[idx];
pTypeHash->idhashtable->data[idx] = pNewIdHash;
pNewIdHash->next = pTypeHash->idhashtable->data[idx];
pTypeHash->idhashtable->data[idx] = pNewIdHash; pTypeHash->idhashtable->used++;
pTypeHash->idhashtable->used++; s_modified = 1;
s_critsect.Leave();
s_modified = 1; return 1;
s_critsect.Leave(); }
return 1;
} int32_t STORMAPI SEvtUnregisterHandler(uint32_t type, uint32_t subtype, uint32_t id, SEVTHANDLER handler) {
int32_t success = 0;
int32_t STORMAPI SEvtUnregisterHandler(uint32_t type, uint32_t subtype, uint32_t id, SEVTHANDLER handler) { s_critsect.Enter();
int32_t success = 0;
s_critsect.Enter(); _TYPEHASHENTRY* pTypeEntry = FindTypeHashEntry(type, subtype);
if (pTypeEntry) {
_TYPEHASHENTRY* pTypeEntry = FindTypeHashEntry(type, subtype); _IDHASHTABLE* pTable = pTypeEntry->idhashtable;
if (pTypeEntry) { if (pTable->data && pTable->size != 0) {
_IDHASHTABLE* pTable = pTypeEntry->idhashtable; _IDHASHENTRY** ppNextEntry = &pTable->data[id & (pTable->size - 1)];
if (pTable->data && pTable->size != 0) { for (_IDHASHENTRY* pEntry = *ppNextEntry; pEntry; pEntry = *ppNextEntry) {
_IDHASHENTRY** ppNextEntry = &pTable->data[id & (pTable->size - 1)]; if (pEntry->id == id && (!handler || pEntry->handler == handler)) {
for (_IDHASHENTRY* pEntry = *ppNextEntry; pEntry; pEntry = *ppNextEntry) { *ppNextEntry = pEntry->next;
if (pEntry->id == id && (!handler || pEntry->handler == handler)) { delete pEntry;
*ppNextEntry = pEntry->next;
delete pEntry; success = 1;
s_modified = 1;
success = 1; pTable->used--;
s_modified = 1; }
pTable->used--; else {
} ppNextEntry = &pEntry->next;
else { }
ppNextEntry = &pEntry->next; }
} }
} }
}
} s_critsect.Leave();
return success;
s_critsect.Leave(); }
return success;
} int32_t STORMAPI SEvtUnregisterType(uint32_t type, uint32_t subtype) {
int32_t success = 0;
int32_t STORMAPI SEvtUnregisterType(uint32_t type, uint32_t subtype) { s_critsect.Enter();
int32_t success = 0;
s_critsect.Enter(); _TYPEHASHENTRY *pTypeEntry = FindTypeHashEntry(type, subtype);
if (pTypeEntry) {
_TYPEHASHENTRY *pTypeEntry = FindTypeHashEntry(type, subtype); for (auto pTable = pTypeEntry->idhashtable; pTable; pTable = pTypeEntry->idhashtable) {
if (pTypeEntry) { pTypeEntry->idhashtable = pTable->next;
for (auto pTable = pTypeEntry->idhashtable; pTable; pTable = pTypeEntry->idhashtable) { DeleteIdHashTable(pTable);
pTypeEntry->idhashtable = pTable->next; }
DeleteIdHashTable(pTable);
} uint32_t idx = (s_typehashtablesize - 1) & (subtype ^ type);
_TYPEHASHENTRY** ppNextEntry = &s_typehashtable[idx];
uint32_t idx = (s_typehashtablesize - 1) & (subtype ^ type); for (_TYPEHASHENTRY* pEntry = *ppNextEntry; pEntry; pEntry = *ppNextEntry) {
_TYPEHASHENTRY** ppNextEntry = &s_typehashtable[idx]; if (pEntry == pTypeEntry) {
for (_TYPEHASHENTRY* pEntry = *ppNextEntry; pEntry; pEntry = *ppNextEntry) { *ppNextEntry = pEntry->next;
if (pEntry == pTypeEntry) { delete pEntry;
*ppNextEntry = pEntry->next; s_typehashtableused--;
delete pEntry; }
s_typehashtableused--; else {
} ppNextEntry = &pEntry->next;
else { }
ppNextEntry = &pEntry->next; }
}
} success = 1;
s_modified = 1;
success = 1; }
s_modified = 1;
} s_critsect.Leave();
return success;
s_critsect.Leave(); }
return success;
}

View file

@ -1,28 +1,25 @@
#ifndef STORM_EVENT_HPP #ifndef STORM_EVENT_HPP
#define STORM_EVENT_HPP #define STORM_EVENT_HPP
#include <cstdint> #include <cstdint>
#include "Core.hpp" #include "Core.hpp"
typedef void (STORMAPI* SEVTHANDLER)(void*);
typedef void (STORMAPI* SEVTHANDLER)(void*);
int32_t STORMAPI SEvtBreakHandlerChain(void* data);
int32_t STORMAPI SEvtBreakHandlerChain(void* data); int32_t STORMAPI SEvtDestroy();
int32_t STORMAPI SEvtDestroy(); int32_t STORMAPI SEvtDispatch(uint32_t type, uint32_t subtype, uint32_t id, void* data);
int32_t STORMAPI SEvtDispatch(uint32_t type, uint32_t subtype, uint32_t id, void* data); int32_t STORMAPI SEvtPopState(uint32_t type, uint32_t subtype);
int32_t STORMAPI SEvtPopState(uint32_t type, uint32_t subtype); int32_t STORMAPI SEvtPushState(uint32_t type, uint32_t subtype);
int32_t STORMAPI SEvtPushState(uint32_t type, uint32_t subtype); int32_t STORMAPI SEvtRegisterHandler(uint32_t type, uint32_t subtype, uint32_t id, uint32_t flags, SEVTHANDLER handler);
int32_t STORMAPI SEvtRegisterHandler(uint32_t type, uint32_t subtype, uint32_t id, uint32_t flags, SEVTHANDLER handler); int32_t STORMAPI SEvtUnregisterHandler(uint32_t type, uint32_t subtype, uint32_t id, SEVTHANDLER handler);
int32_t STORMAPI SEvtUnregisterHandler(uint32_t type, uint32_t subtype, uint32_t id, SEVTHANDLER handler); int32_t STORMAPI SEvtUnregisterType(uint32_t type, uint32_t subtype);
int32_t STORMAPI SEvtUnregisterType(uint32_t type, uint32_t subtype); #endif
#endif