mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-23 08:24:16 +00:00
Implement/Match LegoTree (#485)
* Implement/Match LegoTree * Fix vtable * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
110
LEGO1/lego/sources/misc/legotree.cpp
Normal file
110
LEGO1/lego/sources/misc/legotree.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "legotree.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "legostorage.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(LegoTreeNodeData, 0x04)
|
||||
DECOMP_SIZE_ASSERT(LegoTreeNode, 0x010)
|
||||
DECOMP_SIZE_ASSERT(LegoTree, 0x08)
|
||||
|
||||
// FUNCTION: LEGO1 0x10099d60
|
||||
LegoTreeNode::LegoTreeNode()
|
||||
{
|
||||
m_data = NULL;
|
||||
m_numChildren = 0;
|
||||
m_children = NULL;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099da0
|
||||
LegoTreeNode::~LegoTreeNode()
|
||||
{
|
||||
if (m_data) {
|
||||
delete m_data;
|
||||
}
|
||||
if (m_children) {
|
||||
delete[] m_children;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099dd0
|
||||
LegoTree::LegoTree()
|
||||
{
|
||||
m_root = NULL;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099e00
|
||||
LegoTree::~LegoTree()
|
||||
{
|
||||
if (m_root) {
|
||||
Delete(m_root);
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099e20
|
||||
LegoResult LegoTree::Read(LegoStorage* p_storage)
|
||||
{
|
||||
return Read(p_storage, m_root);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099e40
|
||||
LegoResult LegoTree::Write(LegoStorage* p_storage)
|
||||
{
|
||||
return Write(p_storage, m_root);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099e60
|
||||
LegoResult LegoTree::Read(LegoStorage* p_storage, LegoTreeNode*& p_node)
|
||||
{
|
||||
LegoResult result;
|
||||
p_node = new LegoTreeNode();
|
||||
p_node->SetData(CreateData());
|
||||
if ((result = p_node->GetData()->Read(p_storage)) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
LegoU32 numChildren;
|
||||
if ((result = p_storage->Read(&numChildren, sizeof(numChildren))) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
if (numChildren) {
|
||||
p_node->SetChildren(new LegoTreeNode*[numChildren]);
|
||||
for (LegoU32 i = 0; i < numChildren; i++) {
|
||||
LegoTreeNode* node;
|
||||
if ((result = Read(p_storage, node)) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
p_node->SetNumChildren(p_node->GetNumChildren() + 1);
|
||||
p_node->SetChild(i, node);
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1009a020
|
||||
LegoResult LegoTree::Write(LegoStorage* p_storage, LegoTreeNode* p_node)
|
||||
{
|
||||
LegoResult result;
|
||||
if (p_node->GetData()) {
|
||||
if ((result = p_node->GetData()->Write(p_storage)) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
LegoU32 numChildren = p_node->GetNumChildren();
|
||||
if ((result = p_storage->Write(&numChildren, sizeof(numChildren))) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
|
||||
if ((result = Write(p_storage, p_node->GetChild(i))) != SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1009a0a0
|
||||
void LegoTree::Delete(LegoTreeNode* p_node)
|
||||
{
|
||||
for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
|
||||
Delete(p_node->GetChild(i));
|
||||
}
|
||||
delete p_node;
|
||||
}
|
77
LEGO1/lego/sources/misc/legotree.h
Normal file
77
LEGO1/lego/sources/misc/legotree.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef __LEGOTREE_H
|
||||
#define __LEGOTREE_H
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "legotypes.h"
|
||||
|
||||
class LegoStorage;
|
||||
|
||||
// VTABLE: LEGO1 0x100db778
|
||||
// SIZE 0x4
|
||||
class LegoTreeNodeData {
|
||||
public:
|
||||
LegoTreeNodeData() {}
|
||||
virtual ~LegoTreeNodeData() {}
|
||||
|
||||
// FUNCTION: LEGO1 0x10099fe0
|
||||
virtual LegoResult Read(LegoStorage* p_storage) { return SUCCESS; } // vtable+0x4
|
||||
|
||||
// FUNCTION: LEGO1 0x10099ff0
|
||||
virtual LegoResult Write(LegoStorage* p_storage) { return SUCCESS; } // vtable+0x8
|
||||
|
||||
// SYNTHETIC: LEGO1 0x1009a000
|
||||
// LegoTreeNodeData::`scalar deleting destructor'
|
||||
};
|
||||
|
||||
// VTABLE: LEGO1 0x100db764
|
||||
// SIZE 0x10
|
||||
class LegoTreeNode {
|
||||
public:
|
||||
LegoTreeNode();
|
||||
virtual ~LegoTreeNode();
|
||||
LegoTreeNodeData* GetData() { return m_data; }
|
||||
void SetData(LegoTreeNodeData* p_data) { m_data = p_data; }
|
||||
LegoU32 GetNumChildren() { return m_numChildren; }
|
||||
void SetNumChildren(LegoU32 p_numChildren) { m_numChildren = p_numChildren; }
|
||||
LegoTreeNode* GetChild(LegoU32 p_i) { return m_children[p_i]; }
|
||||
void SetChild(LegoU32 p_i, LegoTreeNode* p_child) { m_children[p_i] = p_child; }
|
||||
LegoTreeNode** GetChildren() { return m_children; }
|
||||
void SetChildren(LegoTreeNode** p_children) { m_children = p_children; }
|
||||
|
||||
// SYNTHETIC: LEGO1 0x10099d80
|
||||
// LegoTreeNode::`scalar deleting destructor'
|
||||
|
||||
protected:
|
||||
LegoTreeNodeData* m_data; // 0x4
|
||||
LegoU32 m_numChildren; // 0x8
|
||||
LegoTreeNode** m_children; // 0xc
|
||||
};
|
||||
|
||||
// VTABLE: LEGO1 0x100db768
|
||||
// SIZE 0x8
|
||||
class LegoTree {
|
||||
public:
|
||||
LegoTree();
|
||||
virtual ~LegoTree();
|
||||
LegoTreeNode* GetRoot() { return m_root; }
|
||||
void SetRoot(LegoTreeNode* p_root) { m_root = p_root; }
|
||||
virtual LegoResult Read(LegoStorage* p_storage); // vtable+0x4
|
||||
virtual LegoResult Write(LegoStorage* p_storage); // vtable+0x8
|
||||
|
||||
// SYNTHETIC: LEGO1 0x10099de0
|
||||
// LegoTree::`scalar deleting destructor'
|
||||
|
||||
protected:
|
||||
LegoResult Read(LegoStorage* p_storage, LegoTreeNode*& p_node);
|
||||
LegoResult Write(LegoStorage* p_storage, LegoTreeNode* p_node);
|
||||
void Delete(LegoTreeNode* p_node);
|
||||
|
||||
// FUNCTION: LEGO1 0x10099f70
|
||||
virtual LegoTreeNodeData* CreateData() { return new LegoTreeNodeData(); } // vtable+0xc
|
||||
|
||||
LegoTreeNode* m_root; // 0x4
|
||||
};
|
||||
|
||||
#endif // __LEGOTREE_H
|
Reference in New Issue
Block a user