mirror of
https://github.com/zeldaret/ss
synced 2026-08-01 08:17:21 -04:00
Merge branch 'main' into flag-mgr-experimenting
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#include <c/c_list.h>
|
||||
|
||||
|
||||
bool cListMg_c::insertAfter(cListNd_c *node, cListNd_c *prevNode) {
|
||||
if (prevNode == nullptr) {
|
||||
return this->prepend(node);
|
||||
}
|
||||
if (node == nullptr) {
|
||||
return;
|
||||
}
|
||||
node->mpNext = prevNode->mpNext;
|
||||
node->mpPrev = prevNode;
|
||||
prevNode->mpNext = node;
|
||||
if (node->mpNext != nullptr) {
|
||||
node->mpNext->mpPrev = node;
|
||||
} else {
|
||||
this->mpLast = node;
|
||||
}
|
||||
}
|
||||
|
||||
bool cListMg_c::remove(cListNd_c *node) {
|
||||
if (node == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->mpPrev == nullptr && node->mpNext == nullptr) {
|
||||
if (this->mpFirst == node && this->mpLast == node) {
|
||||
this->mpFirst = nullptr;
|
||||
this->mpLast = nullptr;
|
||||
}
|
||||
} else {
|
||||
if (node->mpPrev != nullptr) {
|
||||
node->mpPrev->mpNext = node->mpNext;
|
||||
} else if (node == this->mpFirst) {
|
||||
this->mpFirst = node->mpNext;
|
||||
}
|
||||
|
||||
if (node->mpNext != nullptr) {
|
||||
node->mpNext->mpPrev = node->mpPrev;
|
||||
} else if (node == this->mpLast) {
|
||||
this->mpLast = node->mpPrev;
|
||||
}
|
||||
|
||||
node->mpPrev = nullptr;
|
||||
node->mpNext = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool cListMg_c::append(cListNd_c *node) {
|
||||
if (node == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (this->mpLast != nullptr) {
|
||||
this->mpLast->mpNext = node;
|
||||
node->mpPrev = this->mpLast;
|
||||
} else {
|
||||
this->mpFirst = node;
|
||||
}
|
||||
this->mpLast = node;
|
||||
}
|
||||
|
||||
bool cListMg_c::prepend(cListNd_c *node) {
|
||||
if (node == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (this->mpFirst != nullptr) {
|
||||
this->mpFirst->mpPrev = node;
|
||||
node->mpNext = this->mpFirst;
|
||||
} else {
|
||||
this->mpLast = node;
|
||||
}
|
||||
this->mpFirst = node;
|
||||
}
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
NOTE: This file does not match fully yet, Inlining + function ordering needs to still be addressed
|
||||
|
||||
Nonmatching functions:
|
||||
DrawStringLineToXfb_ https://decomp.me/scratch/uqeZ6
|
||||
|
||||
This worked for SS: as seen in egg stuff ive worked on, not sure if it works for others ¯\_(ツ)_/¯
|
||||
- Especially with inlines. DWARF provides info of local vars and maps provide calls to functions,
|
||||
but outside of that I made some guesses.
|
||||
@@ -256,9 +253,7 @@ const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width)
|
||||
char c;
|
||||
int code, cnt, tab_size;
|
||||
|
||||
cnt = 0;
|
||||
while (*str != '\0') {
|
||||
c = *str;
|
||||
for (cnt = 0; (c = *str) != '\0'; str++) {
|
||||
if (c == '\n' || c == '\0') {
|
||||
return str;
|
||||
}
|
||||
@@ -274,11 +269,12 @@ const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width)
|
||||
posh += 6;
|
||||
cnt++;
|
||||
}
|
||||
if (cnt >= width && str[1] == '\n') {
|
||||
str++;
|
||||
if (cnt >= width) {
|
||||
if (str[1] == '\n') {
|
||||
str++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#include <nw4r/ut/ut_list.h>
|
||||
|
||||
namespace nw4r {
|
||||
namespace ut {
|
||||
|
||||
#define NODE_PTR(list, object) ((Node*)(((char*)object) + list->offset))
|
||||
|
||||
void* List_GetNth(const List* list, u16 n) {
|
||||
void *object;
|
||||
int c;
|
||||
|
||||
for (c = 0, object = nullptr; object = List_GetNext(list, object); c++) {
|
||||
if (n == c) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* List_GetPrev(const List* list, const void* object) {
|
||||
if (object == nullptr) {
|
||||
return list->last;
|
||||
} else {
|
||||
return NODE_PTR(list, object)->prev;
|
||||
}
|
||||
}
|
||||
|
||||
void* List_GetNext(const List* list, const void* object) {
|
||||
if (object == nullptr) {
|
||||
return list->first;
|
||||
} else {
|
||||
return NODE_PTR(list, object)->next;
|
||||
}
|
||||
}
|
||||
|
||||
void List_Remove(List* list, void* object) {
|
||||
Node *node = NODE_PTR(list, object);
|
||||
if (node->prev == nullptr) {
|
||||
list->first = node->next;
|
||||
} else {
|
||||
NODE_PTR(list, node->prev)->next = node->next;
|
||||
}
|
||||
|
||||
if (node->next == nullptr) {
|
||||
list->last = node->prev;
|
||||
} else {
|
||||
NODE_PTR(list, node->next)->prev = node->prev;
|
||||
}
|
||||
|
||||
node->prev = nullptr;
|
||||
node->next = nullptr;
|
||||
list->size--;
|
||||
}
|
||||
|
||||
void List_Insert(List* list, void* next, void* object) {
|
||||
if (next == nullptr) {
|
||||
List_Append(list, object);
|
||||
} else if (next == list->first) {
|
||||
List_Prepend(list, object);
|
||||
} else {
|
||||
Node *newNode = NODE_PTR(list, object);
|
||||
void *prevObj = NODE_PTR(list, next)->prev;
|
||||
Node *prevNode = NODE_PTR(list, prevObj);
|
||||
newNode->prev = prevObj;
|
||||
newNode->next = next;
|
||||
prevNode->next = object;
|
||||
NODE_PTR(list, next)->prev = object;
|
||||
list->size++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void List_Prepend(List* list, void* object) {
|
||||
if (list->first == nullptr) {
|
||||
Node *node = NODE_PTR(list, object);
|
||||
node->next = nullptr;
|
||||
node->prev = nullptr;
|
||||
list->first = object;
|
||||
list->last = object;
|
||||
list->size++;
|
||||
} else {
|
||||
Node *node = NODE_PTR(list, object);
|
||||
node->prev = nullptr;
|
||||
node->next = list->first;
|
||||
NODE_PTR(list, list->first)->prev = object;
|
||||
list->first = object;
|
||||
list->size++;
|
||||
}
|
||||
}
|
||||
|
||||
void List_Append(List* list, void* object) {
|
||||
if (list->first == nullptr) {
|
||||
Node *node = NODE_PTR(list, object);
|
||||
node->next = nullptr;
|
||||
node->prev = nullptr;
|
||||
list->first = object;
|
||||
list->last = object;
|
||||
list->size++;
|
||||
} else {
|
||||
Node *node = NODE_PTR(list, object);
|
||||
node->prev = list->last;
|
||||
node->next = nullptr;
|
||||
NODE_PTR(list, list->last)->next = object;
|
||||
list->last = object;
|
||||
list->size++;
|
||||
}
|
||||
}
|
||||
|
||||
void List_Init(List* list, u16 offset) {
|
||||
list->first = nullptr;
|
||||
list->last = nullptr;
|
||||
list->size = 0;
|
||||
list->offset = offset;
|
||||
}
|
||||
|
||||
} // namespace ut
|
||||
} // namespace nw4r
|
||||
Reference in New Issue
Block a user