Beta matching MxVariableTable (#811)

This commit is contained in:
MS 2024-04-17 05:31:48 -04:00 committed by GitHub
parent 2600b1b421
commit 536c4336f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 54 deletions

View file

@ -9,6 +9,7 @@
class MxParam; class MxParam;
// VTABLE: LEGO1 0x100dc0f8 // VTABLE: LEGO1 0x100dc0f8
// VTABLE: BETA10 0x101c1bc8
// SIZE 0x08 // SIZE 0x08
class MxCore { class MxCore {
public: public:
@ -17,9 +18,11 @@ class MxCore {
virtual MxLong Notify(MxParam& p_param); // vtable+04 virtual MxLong Notify(MxParam& p_param); // vtable+04
// FUNCTION: LEGO1 0x10001f70 // FUNCTION: LEGO1 0x10001f70
// FUNCTION: BETA10 0x1000f380
virtual MxResult Tickle() { return SUCCESS; } // vtable+08 virtual MxResult Tickle() { return SUCCESS; } // vtable+08
// FUNCTION: LEGO1 0x100144c0 // FUNCTION: LEGO1 0x100144c0
// FUNCTION: BETA10 0x100126d0
inline virtual const char* ClassName() const // vtable+0c inline virtual const char* ClassName() const // vtable+0c
{ {
// STRING: LEGO1 0x100f007c // STRING: LEGO1 0x100f007c
@ -27,6 +30,7 @@ class MxCore {
} }
// FUNCTION: LEGO1 0x100140d0 // FUNCTION: LEGO1 0x100140d0
// FUNCTION: BETA10 0x10012680
inline virtual MxBool IsA(const char* p_name) const // vtable+10 inline virtual MxBool IsA(const char* p_name) const // vtable+10
{ {
return !strcmp(p_name, MxCore::ClassName()); return !strcmp(p_name, MxCore::ClassName());
@ -35,6 +39,7 @@ class MxCore {
inline MxU32 GetId() { return m_id; } inline MxU32 GetId() { return m_id; }
// SYNTHETIC: LEGO1 0x100ae1c0 // SYNTHETIC: LEGO1 0x100ae1c0
// SYNTHETIC: BETA10 0x1012c0d0
// MxCore::`scalar deleting destructor' // MxCore::`scalar deleting destructor'
private: private:

View file

@ -13,12 +13,12 @@ class MxHashTableCursor;
template <class T> template <class T>
class MxHashTableNode { class MxHashTableNode {
public: public:
MxHashTableNode<T>(T p_obj, MxU32 p_hash) MxHashTableNode<T>(T p_obj, MxU32 p_hash, MxHashTableNode* p_prev, MxHashTableNode* p_next)
{ {
m_obj = p_obj; m_obj = p_obj;
m_hash = p_hash; m_hash = p_hash;
m_prev = NULL; m_prev = p_prev;
m_next = NULL; m_next = p_next;
} }
// DECOMP: Should use getter and setter methods here per the style guide. // DECOMP: Should use getter and setter methods here per the style guide.
@ -41,7 +41,8 @@ class MxHashTable : protected MxCollection<T> {
MxHashTable() MxHashTable()
{ {
m_numSlots = HASH_TABLE_INIT_SIZE; m_numSlots = HASH_TABLE_INIT_SIZE;
m_slots = new MxHashTableNode<T>*[HASH_TABLE_INIT_SIZE]; MxU32 unused = 0;
m_slots = new MxHashTableNode<T>*[m_numSlots];
memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots); memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots);
m_resizeOption = e_noExpand; m_resizeOption = e_noExpand;
} }
@ -94,15 +95,11 @@ template <class T>
MxBool MxHashTableCursor<T>::Find(T p_obj) MxBool MxHashTableCursor<T>::Find(T p_obj)
{ {
MxU32 hash = m_table->Hash(p_obj); MxU32 hash = m_table->Hash(p_obj);
MxS32 bucket = hash % m_table->m_numSlots;
MxHashTableNode<T>* t = m_table->m_slots[bucket]; for (MxHashTableNode<T>* t = m_table->m_slots[hash % m_table->m_numSlots]; t; t = t->m_next) {
while (t) {
if (t->m_hash == hash && !m_table->Compare(t->m_obj, p_obj)) { if (t->m_hash == hash && !m_table->Compare(t->m_obj, p_obj)) {
m_match = t; m_match = t;
} }
t = t->m_next;
} }
return m_match != NULL; return m_match != NULL;
@ -123,17 +120,13 @@ void MxHashTableCursor<T>::DeleteMatch()
{ {
// Cut the matching node out of the linked list // Cut the matching node out of the linked list
// by updating pointer references. // by updating pointer references.
if (m_match == NULL) { if (m_match) {
return;
}
if (m_match->m_prev) { if (m_match->m_prev) {
m_match->m_prev->m_next = m_match->m_next; m_match->m_prev->m_next = m_match->m_next;
} }
else { else {
// No "prev" node, so move "next" to the head of the list. // No "prev" node, so move "next" to the head of the list.
MxS32 bucket = m_match->m_hash % m_table->m_numSlots; m_table->m_slots[m_match->m_hash % m_table->m_numSlots] = m_match->m_next;
m_table->m_slots[bucket] = m_match->m_next;
} }
if (m_match->m_next) { if (m_match->m_next) {
@ -144,31 +137,29 @@ void MxHashTableCursor<T>::DeleteMatch()
delete m_match; delete m_match;
m_table->m_count--; m_table->m_count--;
} }
}
template <class T> template <class T>
MxHashTable<T>::~MxHashTable() MxHashTable<T>::~MxHashTable()
{ {
DeleteAll(); DeleteAll();
delete[] m_slots;
} }
template <class T> template <class T>
void MxHashTable<T>::DeleteAll() void MxHashTable<T>::DeleteAll()
{ {
for (MxS32 i = 0; i < m_numSlots; i++) { for (MxS32 i = 0; i < m_numSlots; i++) {
MxHashTableNode<T>* t = m_slots[i]; MxHashTableNode<T>* next;
for (MxHashTableNode<T>* t = m_slots[i]; t != NULL; t = next) {
while (t) { next = t->m_next;
MxHashTableNode<T>* next = t->m_next;
this->m_customDestructor(t->m_obj); this->m_customDestructor(t->m_obj);
delete t; delete t;
t = next;
} }
} }
this->m_count = 0; this->m_count = 0;
memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots); memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots);
delete[] m_slots;
} }
template <class T> template <class T>
@ -188,18 +179,16 @@ inline void MxHashTable<T>::Resize()
break; break;
} }
MxHashTableNode<T>** newTable = new MxHashTableNode<T>*[m_numSlots]; MxU32 unused = 0;
m_slots = newTable; m_slots = new MxHashTableNode<T>*[m_numSlots];
memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots); memset(m_slots, 0, sizeof(MxHashTableNode<T>*) * m_numSlots);
this->m_count = 0; this->m_count = 0;
for (MxS32 i = 0; i != oldSize; i++) { for (MxS32 i = 0; i < oldSize; i++) {
MxHashTableNode<T>* t = oldTable[i]; MxHashTableNode<T>* next;
for (MxHashTableNode<T>* t = oldTable[i]; t != NULL; t = next) {
while (t) { next = t->m_next;
MxHashTableNode<T>* next = t->m_next;
NodeInsert(t); NodeInsert(t);
t = next;
} }
} }
@ -229,7 +218,9 @@ inline void MxHashTable<T>::Add(T p_newobj)
} }
MxU32 hash = Hash(p_newobj); MxU32 hash = Hash(p_newobj);
MxHashTableNode<T>* node = new MxHashTableNode<T>(p_newobj, hash); MxU32 unused = 0;
MxHashTableNode<T>* node = new MxHashTableNode<T>(p_newobj, hash, NULL, NULL);
MxHashTable<T>::NodeInsert(node); MxHashTable<T>::NodeInsert(node);
} }

View file

@ -5,31 +5,38 @@
#include "mxstring.h" #include "mxstring.h"
// VTABLE: LEGO1 0x100d7498 // VTABLE: LEGO1 0x100d7498
// VTABLE: BETA10 0x101bc038
// SIZE 0x24 // SIZE 0x24
class MxVariable { class MxVariable {
public: public:
MxVariable() {} MxVariable() {}
MxVariable(const char* p_key) // FUNCTION: BETA10 0x1012a840
{
m_key = p_key;
m_key.ToUpperCase();
}
MxVariable(const char* p_key, const char* p_value) MxVariable(const char* p_key, const char* p_value)
{ {
m_key = p_key; m_key = p_key;
m_key.ToUpperCase(); m_key.ToUpperCase();
m_value = p_value; m_value = p_value;
} }
// FUNCTION: BETA10 0x1012aa30
MxVariable(const char* p_key)
{
m_key = p_key;
m_key.ToUpperCase();
}
// FUNCTION: LEGO1 0x1003bea0 // FUNCTION: LEGO1 0x1003bea0
// FUNCTION: BETA10 0x1007b810
virtual MxString* GetValue() { return &m_value; } // vtable+0x00 virtual MxString* GetValue() { return &m_value; } // vtable+0x00
// FUNCTION: LEGO1 0x1003beb0 // FUNCTION: LEGO1 0x1003beb0
// FUNCTION: BETA10 0x1007b840
virtual void SetValue(const char* p_value) { m_value = p_value; } // vtable+0x04 virtual void SetValue(const char* p_value) { m_value = p_value; } // vtable+0x04
// FUNCTION: LEGO1 0x1003bec0 // FUNCTION: LEGO1 0x1003bec0
// FUNCTION: BETA10 0x1007b870
virtual void Destroy() { delete this; } // vtable+0x08 virtual void Destroy() { delete this; } // vtable+0x08
// FUNCTION: BETA10 0x1012a7f0
inline const MxString* GetKey() const { return &m_key; } inline const MxString* GetKey() const { return &m_key; }
protected: protected:

View file

@ -6,66 +6,115 @@
#include "mxvariable.h" #include "mxvariable.h"
// VTABLE: LEGO1 0x100dc1c8 // VTABLE: LEGO1 0x100dc1c8
// VTABLE: BETA10 0x101c1c78
// SIZE 0x28 // SIZE 0x28
class MxVariableTable : public MxHashTable<MxVariable*> { class MxVariableTable : public MxHashTable<MxVariable*> {
public: public:
MxVariableTable() { m_customDestructor = Destroy; } // FUNCTION: BETA10 0x10130e50
MxVariableTable() { SetDestroy(Destroy); }
void SetVariable(const char* p_key, const char* p_value); void SetVariable(const char* p_key, const char* p_value);
void SetVariable(MxVariable* p_var); void SetVariable(MxVariable* p_var);
const char* GetVariable(const char* p_key); const char* GetVariable(const char* p_key);
// FUNCTION: LEGO1 0x100afdb0
// FUNCTION: BETA10 0x10130f00
static void Destroy(MxVariable* p_obj) { p_obj->Destroy(); } static void Destroy(MxVariable* p_obj) { p_obj->Destroy(); }
MxS8 Compare(MxVariable*, MxVariable*) override; // vtable+0x14 MxS8 Compare(MxVariable*, MxVariable*) override; // vtable+0x14
MxU32 Hash(MxVariable*) override; // vtable+0x18 MxU32 Hash(MxVariable*) override; // vtable+0x18
// SYNTHETIC: LEGO1 0x100afdd0 // SYNTHETIC: LEGO1 0x100afdd0
// SYNTHETIC: BETA10 0x10130f20
// MxVariableTable::`scalar deleting destructor' // MxVariableTable::`scalar deleting destructor'
}; };
// VTABLE: LEGO1 0x100dc1b0 // VTABLE: LEGO1 0x100dc1b0
// VTABLE: BETA10 0x101c1cd0
// class MxCollection<MxVariable *> // class MxCollection<MxVariable *>
// VTABLE: LEGO1 0x100dc1e8 // VTABLE: LEGO1 0x100dc1e8
// VTABLE: BETA10 0x101c1cb0
// class MxHashTable<MxVariable *> // class MxHashTable<MxVariable *>
// VTABLE: LEGO1 0x100dc680 // VTABLE: LEGO1 0x100dc680
// VTABLE: BETA10 0x101c1b48
// class MxHashTableCursor<MxVariable *> // class MxHashTableCursor<MxVariable *>
// TEMPLATE: LEGO1 0x100afcd0 // TEMPLATE: LEGO1 0x100afcd0
// TEMPLATE: BETA10 0x10132950
// MxCollection<MxVariable *>::Compare // MxCollection<MxVariable *>::Compare
// TEMPLATE: LEGO1 0x100afce0 // TEMPLATE: LEGO1 0x100afce0
// TEMPLATE: BETA10 0x10132a00
// MxCollection<MxVariable *>::~MxCollection<MxVariable *> // MxCollection<MxVariable *>::~MxCollection<MxVariable *>
// TEMPLATE: LEGO1 0x100afd30 // TEMPLATE: LEGO1 0x100afd30
// TEMPLATE: BETA10 0x10132a70
// MxCollection<MxVariable *>::Destroy // MxCollection<MxVariable *>::Destroy
// SYNTHETIC: LEGO1 0x100afd40 // SYNTHETIC: LEGO1 0x100afd40
// SYNTHETIC: BETA10 0x10132a80
// MxCollection<MxVariable *>::`scalar deleting destructor' // MxCollection<MxVariable *>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x100afdb0
// MxVariableTable::Destroy
// TEMPLATE: LEGO1 0x100afdc0 // TEMPLATE: LEGO1 0x100afdc0
// TEMPLATE: BETA10 0x10132ac0
// MxHashTable<MxVariable *>::Hash // MxHashTable<MxVariable *>::Hash
// TEMPLATE: LEGO1 0x100b0bd0 // TEMPLATE: LEGO1 0x100b0bd0
// TEMPLATE: BETA10 0x10132ae0
// MxHashTable<MxVariable *>::~MxHashTable<MxVariable *> // MxHashTable<MxVariable *>::~MxHashTable<MxVariable *>
// SYNTHETIC: LEGO1 0x100b0ca0 // SYNTHETIC: LEGO1 0x100b0ca0
// SYNTHETIC: BETA10 0x10132b70
// MxHashTable<MxVariable *>::`scalar deleting destructor' // MxHashTable<MxVariable *>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x100b7680 // TEMPLATE: LEGO1 0x100b7680
// TEMPLATE: BETA10 0x1012a990
// MxHashTableCursor<MxVariable *>::~MxHashTableCursor<MxVariable *> // MxHashTableCursor<MxVariable *>::~MxHashTableCursor<MxVariable *>
// SYNTHETIC: LEGO1 0x100b76d0 // SYNTHETIC: LEGO1 0x100b76d0
// SYNTHETIC: BETA10 0x1012a9f0
// MxHashTableCursor<MxVariable *>::`scalar deleting destructor' // MxHashTableCursor<MxVariable *>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x100b7ab0 // TEMPLATE: LEGO1 0x100b7ab0
// TEMPLATE: BETA10 0x1012adc0
// MxHashTable<MxVariable *>::Resize // MxHashTable<MxVariable *>::Resize
// TEMPLATE: LEGO1 0x100b7b80 // TEMPLATE: LEGO1 0x100b7b80
// TEMPLATE: BETA10 0x1012af10
// MxHashTable<MxVariable *>::NodeInsert // MxHashTable<MxVariable *>::NodeInsert
// TEMPLATE: BETA10 0x1012a900
// MxHashTableCursor<MxVariable *>::MxHashTableCursor<MxVariable *>
// TEMPLATE: BETA10 0x1012aae0
// MxHashTable<MxVariable *>::Add
// TEMPLATE: BETA10 0x1012abd0
// MxHashTableCursor<MxVariable *>::Current
// TEMPLATE: BETA10 0x1012ac20
// MxHashTableCursor<MxVariable *>::DeleteMatch
// TEMPLATE: BETA10 0x1012ad00
// MxHashTableCursor<MxVariable *>::Find
// TEMPLATE: BETA10 0x1012af90
// MxHashTableNode<MxVariable *>::MxHashTableNode<MxVariable *>
// TEMPLATE: BETA10 0x10132890
// MxHashTable<MxVariable *>::MxHashTable<MxVariable *>
// TEMPLATE: BETA10 0x10130ed0
// MxCollection<MxVariable *>::SetDestroy
// SYNTHETIC: BETA10 0x10130f60
// MxVariableTable::~MxVariableTable
// SYNTHETIC: BETA10 0x10132970
// MxCollection<MxVariable *>::MxCollection<MxVariable *>
// TEMPLATE: BETA10 0x10132bb0
// MxHashTable<MxVariable *>::DeleteAll
#endif // MXVARIABLETABLE_H #endif // MXVARIABLETABLE_H

View file

@ -3,9 +3,11 @@
#include <assert.h> #include <assert.h>
// GLOBAL: LEGO1 0x1010141c // GLOBAL: LEGO1 0x1010141c
// GLOBAL: BETA10 0x10201f88
MxU32 MxCore::g_nextCoreId = 0; MxU32 MxCore::g_nextCoreId = 0;
// FUNCTION: LEGO1 0x100ae1a0 // FUNCTION: LEGO1 0x100ae1a0
// FUNCTION: BETA10 0x1012c020
MxCore::MxCore() MxCore::MxCore()
{ {
m_id = g_nextCoreId++; m_id = g_nextCoreId++;
@ -13,11 +15,13 @@ MxCore::MxCore()
} }
// FUNCTION: LEGO1 0x100ae1e0 // FUNCTION: LEGO1 0x100ae1e0
// FUNCTION: BETA10 0x1012c077
MxCore::~MxCore() MxCore::~MxCore()
{ {
} }
// FUNCTION: LEGO1 0x100ae1f0 // FUNCTION: LEGO1 0x100ae1f0
// FUNCTION: BETA10 0x1012c096
MxLong MxCore::Notify(MxParam& p_param) MxLong MxCore::Notify(MxParam& p_param)
{ {
assert(0); assert(0);

View file

@ -1,18 +1,20 @@
#include "mxvariabletable.h" #include "mxvariabletable.h"
// FUNCTION: LEGO1 0x100b7330 // FUNCTION: LEGO1 0x100b7330
// FUNCTION: BETA10 0x1012a470
MxS8 MxVariableTable::Compare(MxVariable* p_var0, MxVariable* p_var1) MxS8 MxVariableTable::Compare(MxVariable* p_var0, MxVariable* p_var1)
{ {
return p_var0->GetKey()->Compare(*p_var1->GetKey()); return p_var0->GetKey()->Compare(*p_var1->GetKey());
} }
// FUNCTION: LEGO1 0x100b7370 // FUNCTION: LEGO1 0x100b7370
// FUNCTION: BETA10 0x1012a4a0
MxU32 MxVariableTable::Hash(MxVariable* p_var) MxU32 MxVariableTable::Hash(MxVariable* p_var)
{ {
const char* str = p_var->GetKey()->GetData(); const char* str = p_var->GetKey()->GetData();
MxU32 value = 0; MxU32 value = 0;
for (int i = 0; str[i]; i++) { for (MxS32 i = 0; str[i]; i++) {
value += str[i]; value += str[i];
} }
@ -20,6 +22,7 @@ MxU32 MxVariableTable::Hash(MxVariable* p_var)
} }
// FUNCTION: LEGO1 0x100b73a0 // FUNCTION: LEGO1 0x100b73a0
// FUNCTION: BETA10 0x1012a507
void MxVariableTable::SetVariable(const char* p_key, const char* p_value) void MxVariableTable::SetVariable(const char* p_key, const char* p_value)
{ {
MxHashTableCursor<MxVariable*> cursor(this); MxHashTableCursor<MxVariable*> cursor(this);
@ -36,12 +39,12 @@ void MxVariableTable::SetVariable(const char* p_key, const char* p_value)
} }
// FUNCTION: LEGO1 0x100b7740 // FUNCTION: LEGO1 0x100b7740
// FUNCTION: BETA10 0x1012a629
void MxVariableTable::SetVariable(MxVariable* p_var) void MxVariableTable::SetVariable(MxVariable* p_var)
{ {
MxHashTableCursor<MxVariable*> cursor(this); MxHashTableCursor<MxVariable*> cursor(this);
MxBool found = cursor.Find(p_var);
if (found) { if (cursor.Find(p_var)) {
cursor.DeleteMatch(); cursor.DeleteMatch();
} }
@ -49,6 +52,7 @@ void MxVariableTable::SetVariable(MxVariable* p_var)
} }
// FUNCTION: LEGO1 0x100b78f0 // FUNCTION: LEGO1 0x100b78f0
// FUNCTION: BETA10 0x1012a6bd
const char* MxVariableTable::GetVariable(const char* p_key) const char* MxVariableTable::GetVariable(const char* p_key)
{ {
// STRING: ISLE 0x41008c // STRING: ISLE 0x41008c

View file

@ -77,6 +77,7 @@ void MxOmni::SetInstance(MxOmni* p_instance)
} }
// FUNCTION: LEGO1 0x100af0c0 // FUNCTION: LEGO1 0x100af0c0
// FUNCTION: BETA10 0x1012f3ff
MxResult MxOmni::Create(MxOmniCreateParam& p_param) MxResult MxOmni::Create(MxOmniCreateParam& p_param)
{ {
MxResult result = FAILURE; MxResult result = FAILURE;