mirror of
https://github.com/zeldaret/tp
synced 2026-06-29 19:42:18 -04:00
JSUList.h templates and JKRHeap matches (#13)
* JSULink, JSUList, JSUTree and more matching in JKRHeap * Added JSUListIterator and decompiled JKRHeap::dispose_subroutine * more templates and JKRHeap functions * JKRDisposer! * only 4 functions not OK in JKRHeap * fixed: *this->getObject() Co-authored-by: Pheenoh <pheenoh@gmail.com>
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
#include "global.h"
|
||||
|
||||
// #include "JSupport/asm/func_802DBDFC.s"
|
||||
JSUPtrLink::JSUPtrLink(void* owner) {
|
||||
this->list = NULL;
|
||||
this->owner = owner;
|
||||
this->prev = NULL;
|
||||
this->next = NULL;
|
||||
JSUPtrLink::JSUPtrLink(void* object) {
|
||||
this->mList = NULL;
|
||||
this->mObject = object;
|
||||
this->mPrev = NULL;
|
||||
this->mNext = NULL;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBE14.s"
|
||||
JSUPtrLink::~JSUPtrLink() {
|
||||
if (this->list != NULL) {
|
||||
this->list->remove(this);
|
||||
if (this->mList != NULL) {
|
||||
this->mList->remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,59 +21,59 @@ JSUPtrLink::~JSUPtrLink() {
|
||||
//
|
||||
|
||||
// #include "JSupport/asm/func_802DBE74.s"
|
||||
JSUPtrList::JSUPtrList(bool should_initiate) {
|
||||
if (should_initiate != false) {
|
||||
JSUPtrList::JSUPtrList(bool init) {
|
||||
if (init) {
|
||||
this->initiate();
|
||||
}
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBEAC.s"
|
||||
JSUPtrList::~JSUPtrList() {
|
||||
JSUPtrLink* node = this->head;
|
||||
JSUPtrLink* node = this->mHead;
|
||||
s32 removed = 0;
|
||||
while (this->length > removed) {
|
||||
node->list = NULL;
|
||||
node = node->next;
|
||||
while (this->mLength > removed) {
|
||||
node->mList = NULL;
|
||||
node = node->getNext();
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF14.s"
|
||||
void JSUPtrList::initiate() {
|
||||
this->head = NULL;
|
||||
this->tail = NULL;
|
||||
this->length = 0;
|
||||
this->mHead = NULL;
|
||||
this->mTail = NULL;
|
||||
this->mLength = 0;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF28.s"
|
||||
void JSUPtrList::setFirst(JSUPtrLink* first) {
|
||||
first->list = this;
|
||||
first->prev = NULL;
|
||||
first->next = NULL;
|
||||
this->tail = first;
|
||||
this->head = first;
|
||||
this->length = 1;
|
||||
first->mList = this;
|
||||
first->mPrev = NULL;
|
||||
first->mNext = NULL;
|
||||
this->mTail = first;
|
||||
this->mHead = first;
|
||||
this->mLength = 1;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF4C.s"
|
||||
bool JSUPtrList::append(JSUPtrLink* ptr) {
|
||||
JSUPtrList* list = ptr->list;
|
||||
bool result = (NULL == list);
|
||||
JSUPtrList* list = ptr->mList;
|
||||
bool result = (NULL == list);
|
||||
if (!result) {
|
||||
result = list->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (this->length == 0) {
|
||||
if (result) {
|
||||
if (this->mLength == 0) {
|
||||
this->setFirst(ptr);
|
||||
} else {
|
||||
ptr->list = this;
|
||||
ptr->prev = this->tail;
|
||||
ptr->next = NULL;
|
||||
this->tail->next = ptr;
|
||||
this->tail = ptr;
|
||||
this->length++;
|
||||
}
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = this->mTail;
|
||||
ptr->mNext = NULL;
|
||||
this->mTail->mNext = ptr;
|
||||
this->mTail = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -81,23 +81,23 @@ bool JSUPtrList::append(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DBFF0.s"
|
||||
bool JSUPtrList::prepend(JSUPtrLink* ptr) {
|
||||
JSUPtrList* list = ptr->list;
|
||||
bool result = (NULL == list);
|
||||
JSUPtrList* list = ptr->mList;
|
||||
bool result = (NULL == list);
|
||||
if (!result) {
|
||||
result = list->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (this->length == 0) {
|
||||
if (result) {
|
||||
if (this->mLength == 0) {
|
||||
this->setFirst(ptr);
|
||||
} else {
|
||||
ptr->list = this;
|
||||
ptr->prev = (JSUPtrLink*)NULL;
|
||||
ptr->next = this->head;
|
||||
this->head->prev = ptr;
|
||||
this->head = ptr;
|
||||
this->length++;
|
||||
}
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = NULL;
|
||||
ptr->mNext = this->mHead;
|
||||
this->mHead->mPrev = ptr;
|
||||
this->mHead = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -105,29 +105,29 @@ bool JSUPtrList::prepend(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC094.s"
|
||||
bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
|
||||
if (before == this->head) {
|
||||
return this->prepend(ptr);
|
||||
if (before == this->mHead) {
|
||||
return this->prepend(ptr);
|
||||
} else if (before == NULL) {
|
||||
return this->append(ptr);
|
||||
}
|
||||
|
||||
if (before->list != this) {
|
||||
|
||||
if (before->mList != this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = (NULL == ptr->list);
|
||||
|
||||
bool result = (NULL == ptr->mList);
|
||||
if (!result) {
|
||||
result = ptr->list->remove(ptr);
|
||||
result = ptr->mList->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
JSUPtrLink* prev = before->prev;
|
||||
ptr->list = this;
|
||||
ptr->prev = prev;
|
||||
ptr->next = before;
|
||||
prev->next = ptr;
|
||||
before->prev = ptr;
|
||||
this->length++;
|
||||
JSUPtrLink* prev = before->mPrev;
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = prev;
|
||||
ptr->mNext = before;
|
||||
prev->mNext = ptr;
|
||||
before->mPrev = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -135,24 +135,24 @@ bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC15C.s"
|
||||
bool JSUPtrList::remove(JSUPtrLink* ptr) {
|
||||
bool is_parent = (ptr->list == this);
|
||||
bool is_parent = (ptr->mList == this);
|
||||
if (is_parent) {
|
||||
if (this->length == 1) {
|
||||
this->head = NULL;
|
||||
this->tail = NULL;
|
||||
} else if (ptr == this->head) {
|
||||
ptr->next->prev = NULL;
|
||||
this->head = ptr->next;
|
||||
} else if (ptr == this->tail) {
|
||||
ptr->prev->next = NULL;
|
||||
this->tail = ptr->prev;
|
||||
if (this->mLength == 1) {
|
||||
this->mHead = NULL;
|
||||
this->mTail = NULL;
|
||||
} else if (ptr == this->mHead) {
|
||||
ptr->mNext->mPrev = NULL;
|
||||
this->mHead = ptr->mNext;
|
||||
} else if (ptr == this->mTail) {
|
||||
ptr->mPrev->mNext = NULL;
|
||||
this->mTail = ptr->mPrev;
|
||||
} else {
|
||||
ptr->prev->next = ptr->next;
|
||||
ptr->next->prev = ptr->prev;
|
||||
ptr->mPrev->mNext = ptr->mNext;
|
||||
ptr->mNext->mPrev = ptr->mPrev;
|
||||
}
|
||||
|
||||
ptr->list = NULL;
|
||||
this->length--;
|
||||
ptr->mList = NULL;
|
||||
this->mLength--;
|
||||
}
|
||||
|
||||
return is_parent;
|
||||
@@ -160,15 +160,14 @@ bool JSUPtrList::remove(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC20C.s"
|
||||
JSUPtrLink* JSUPtrList::getNthLink(u32 index) const {
|
||||
if (index >= this->length) {
|
||||
if (index >= this->mLength) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSUPtrLink* node = this->head;
|
||||
for(u32 i = 0; i < index; i++) {
|
||||
node = node->next;
|
||||
JSUPtrLink* node = this->mHead;
|
||||
for (u32 i = 0; i < index; i++) {
|
||||
node = node->getNext();
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user