Document SPLList

This commit is contained in:
Fexty12573 2024-07-30 09:23:11 +02:00
parent dbadc443a0
commit ca5e2edced
8 changed files with 124 additions and 125 deletions

View File

@ -3,12 +3,11 @@
#include "nitro/types.h"
#include <nitro/gx/gxcommon.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "struct_defs/struct_020147B8.h"
#include "spl_list.h"
#define GX_RGB_R(RGB) (((RGB) >> GX_RGB_R_SHIFT) & 31)
#define GX_RGB_G(RGB) (((RGB) >> GX_RGB_G_SHIFT) & 31)
#define GX_RGB_B(RGB) (((RGB) >> GX_RGB_B_SHIFT) & 31)
@ -426,17 +425,6 @@ typedef struct SPLConvergence {
u16 reserved0;
} SPLConvergence;
typedef struct SPLNode {
struct SPLNode* p_next;
struct SPLNode* p_prev;
} SPLNode;
typedef struct SPLList {
SPLNode* p_begin;
int node_num;
SPLNode* p_end;
} SPLList;
typedef struct FieldFunc {
void (*func)(SPLParticle *, UnkSPLStruct4 *, int);
BOOL loop;
@ -501,10 +489,6 @@ void sub_0209D998(SPLEmitter *emtr, UnkSPLStruct4 *res, const VecFx32 *param2);
void sub_0209CF00(SPLManager *mgr);
void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr);
SPLNode *sub_020A22B8(SPLList *list);
void sub_020A2304(SPLList *list, SPLNode *node);
SPLNode *sub_020A2238(SPLList *list, SPLNode *node);
u32 sub_0209CE90(u32 param0, BOOL param1);
u32 sub_0209CEC8(u32 param0, BOOL param1);
@ -585,8 +569,4 @@ static inline fx32 rng_next_fx32(u32 shift)
return (fx32)rng_next() >> shift;
}
#ifdef __cplusplus
}
#endif
#endif // POKEPLATINUM_SPL_H

View File

@ -0,0 +1,21 @@
#ifndef SPL_LIST_H
#define SPL_LIST_H
typedef struct SPLNode {
struct SPLNode *next;
struct SPLNode *prev;
} SPLNode;
typedef struct SPLList {
SPLNode *first;
int nodeCount;
SPLNode *last;
} SPLList;
SPLNode *SPLList_PopFront(SPLList *list);
SPLNode *SPLList_PopBack(SPLList *list);
void SPLList_PushFront(SPLList *list, SPLNode *node);
void SPLList_PushBack(SPLList *list, SPLNode *node);
SPLNode *SPLList_Erase(SPLList *list, SPLNode *node);
#endif // SPL_LIST_H

View File

@ -21,7 +21,7 @@ libspl_srcs = files(
'src/unk_020A05BC.c',
'src/unk_020A19F0.c',
'src/unk_020A1E30.c',
'src/unk_020A2238.c',
'src/spl_list.c',
'src/unk_020A2354.c'
)

75
lib/spl/src/spl_list.c Normal file
View File

@ -0,0 +1,75 @@
#include "spl_list.h"
#include <null.h>
void SPLList_PushFront(SPLList *list, SPLNode *node)
{
if (list->first == NULL) { // list is empty
list->first = node;
list->last = node;
node->next = NULL;
node->prev = node->next;
} else {
node->next = list->first;
node->prev = NULL;
list->first->prev = node;
list->first = node;
}
list->nodeCount += 1;
}
void SPLList_PushBack(SPLList *list, SPLNode *node)
{
return;
}
SPLNode *SPLList_PopFront(SPLList *list)
{
SPLNode *node = NULL;
SPLNode *begin = list->first;
if (begin != NULL) { // list is not empty
node = begin;
list->first = begin->next;
if (list->first != NULL) { // list has more than one node
begin->next->prev = NULL;
} else {
list->first = NULL;
list->last = NULL;
}
list->nodeCount -= 1;
}
return node;
}
SPLNode *SPLList_PopBack(SPLList *list)
{
return NULL;
}
SPLNode *SPLList_Erase(SPLList *list, SPLNode *node)
{
SPLNode *next = node->next;
if (next == NULL) { // node is the last node
if (list->first == node) { // node is the only node
list->first = NULL;
list->last = NULL;
} else {
node->prev->next = NULL;
list->last = list->last->prev;
}
} else if (list->first == node) { // node is the first node
list->first = next;
list->first->prev = NULL;
} else { // node is in the middle
next->prev = node->prev;
node->prev->next = node->next;
}
list->nodeCount -= 1;
return node;
}

View File

@ -53,14 +53,14 @@ SPLManager *SPL_0209CD00(void *(*alloc)(u32), u16 max_emtr, u16 max_ptcl, u16 fi
MI_CpuFill8(emtr, 0, max_emtr * sizeof(SPLEmitter));
for (i = 0; i < max_emtr; ++i) {
sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)&emtr[i]);
SPLList_PushFront((SPLList *)&mgr->unk_10, (SPLNode *)&emtr[i]);
}
ptcl = alloc(max_ptcl * sizeof(SPLParticle));
MI_CpuFill8(ptcl, 0, max_ptcl * sizeof(SPLParticle));
for (i = 0; i < max_ptcl; ++i) {
sub_020A2304((SPLList *)&mgr->unk_1C, (SPLNode *)&ptcl[i]);
SPLList_PushFront((SPLList *)&mgr->unk_1C, (SPLNode *)&ptcl[i]);
}
mgr->unk_28 = NULL;
@ -286,8 +286,8 @@ void SPL_0209C6A8(SPLManager *mgr)
if (((base->unk_00.unk_05_6 && base->unk_3C != 0 && emtr->unk_94.started && emtr->unk_BC > base->unk_3C)
|| emtr->unk_94.terminate)
&& emtr->unk_08.unk_04 == 0 && emtr->unk_4C.unk_04 == 0) {
SPLEmitter *e0 = (SPLEmitter *)sub_020A2238((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)e0);
SPLEmitter *e0 = (SPLEmitter *)SPLList_Erase((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
SPLList_PushFront((SPLList *)&mgr->unk_10, (SPLNode *)e0);
}
emtr = next;
@ -335,9 +335,9 @@ SPLEmitter *SPL_0209C56C(SPLManager *mgr, int resno, const VecFx32 *pos)
SPLEmitter *emtr = NULL;
if (mgr->unk_10.unk_00 != NULL) {
emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10);
emtr = (SPLEmitter *)SPLList_PopFront((SPLList *)&mgr->unk_10);
sub_0209D998(emtr, mgr->unk_28 + resno, pos);
sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
SPLList_PushFront((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
if (emtr->p_res->unk_00->unk_00.unk_05_6) {
emtr = NULL;
}
@ -353,12 +353,12 @@ SPLEmitter *SPL_0209C4D8(SPLManager *mgr, int resno, void (*fpcb)(SPLEmitter *))
emtr = NULL;
if (mgr->unk_10.unk_00 != NULL) {
VecFx32 v0 = { 0, 0, 0 };
emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10);
emtr = (SPLEmitter *)SPLList_PopFront((SPLList *)&mgr->unk_10);
sub_0209D998(emtr, mgr->unk_28 + resno, &v0);
if (fpcb != NULL) {
fpcb(emtr);
}
sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
SPLList_PushFront((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
if (emtr->p_res->unk_00->unk_00.unk_05_6) {
emtr = NULL;
}
@ -373,13 +373,13 @@ SPLEmitter *SPL_CreateWithInitializeEx(SPLManager *mgr, int resNo, VecFx32 *pos,
emtr = NULL;
if (mgr->unk_10.unk_00 != NULL) {
emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10);
emtr = (SPLEmitter *)SPLList_PopFront((SPLList *)&mgr->unk_10);
sub_0209D998(emtr, mgr->unk_28 + resNo, pos);
if (cb != NULL) {
cb(emtr, pvoid);
}
sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
SPLList_PushFront((SPLList *)&mgr->unk_04, (SPLNode *)emtr);
if (emtr->p_res->unk_00->unk_00.unk_05_6) {
emtr = NULL;
}
@ -390,22 +390,22 @@ SPLEmitter *SPL_CreateWithInitializeEx(SPLManager *mgr, int resNo, VecFx32 *pos,
void SPL_0209C444(SPLManager *p0, SPLEmitter *p1)
{
SPLEmitter *v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08);
SPLEmitter *v0 = (SPLEmitter *)SPLList_PopFront((SPLList *)&p1->unk_08);
if (v0 != NULL) {
do {
sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0);
v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08);
SPLList_PushFront((SPLList *)&p0->unk_1C, (SPLNode *)v0);
v0 = (SPLEmitter *)SPLList_PopFront((SPLList *)&p1->unk_08);
} while (v0 != NULL);
}
v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C);
v0 = (SPLEmitter *)SPLList_PopFront((SPLList *)&p1->unk_4C);
if (v0 != NULL) {
do {
sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0);
v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C);
SPLList_PushFront((SPLList *)&p0->unk_1C, (SPLNode *)v0);
v0 = (SPLEmitter *)SPLList_PopFront((SPLList *)&p1->unk_4C);
} while (v0 != NULL);
}
sub_020A2238((SPLList *)&p0->unk_04, (SPLNode *)p1);
sub_020A2304((SPLList *)&p0->unk_10, (SPLNode *)p1);
SPLList_Erase((SPLList *)&p0->unk_04, (SPLNode *)p1);
SPLList_PushFront((SPLList *)&p0->unk_10, (SPLNode *)p1);
}
void SPL_0209C400(SPLManager *p0)

View File

@ -210,8 +210,8 @@ void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr)
ptcl->unk_26 += 1;
if (ptcl->unk_26 > ptcl->unk_24) {
SPLNode *node = sub_020A2238((SPLList *)(&emtr->unk_08), (SPLNode *)ptcl);
sub_020A2304((SPLList *)&mgr->unk_1C, node);
SPLNode *node = SPLList_Erase((SPLList *)(&emtr->unk_08), (SPLNode *)ptcl);
SPLList_PushFront((SPLList *)&mgr->unk_1C, node);
}
}
@ -277,7 +277,7 @@ void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr)
ptcl->unk_26 += 1;
if (ptcl->unk_26 > ptcl->unk_24) {
sub_020A2304((SPLList *)&mgr->unk_1C, sub_020A2238((SPLList *)(&emtr->unk_4C), (SPLNode *)ptcl));
SPLList_PushFront((SPLList *)&mgr->unk_1C, SPLList_Erase((SPLList *)(&emtr->unk_4C), (SPLNode *)ptcl));
}
}
}

View File

@ -90,13 +90,13 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list)
if (i < curGenNum) {
fx32 genNum = 0;
do {
ptcl = (SPLParticle *)sub_020A22B8(list);
ptcl = (SPLParticle *)SPLList_PopFront(list);
if (ptcl == NULL) {
return;
}
sub_020A2304((SPLList *)&emtr->unk_08, (SPLNode *)ptcl);
SPLList_PushFront((SPLList *)&emtr->unk_08, (SPLNode *)ptcl);
switch (resBase->unk_00.unk_04_0) {
case 0:
@ -289,11 +289,11 @@ void sub_020A05BC(SPLParticle *ptcl, SPLEmitter *emtr, SPLList *list)
fx32 vel = FX_MUL((fx32)(chldRes->unk_08.unk_00_0 << FX32_SHIFT), FX32_CONST(1 / 256.0f));
for (i = 0; i < chldRes->unk_0C.unk_00_0; i++) {
chld = (SPLParticle *)sub_020A22B8(list);
chld = (SPLParticle *)SPLList_PopFront(list);
if (chld == NULL) {
return;
}
sub_020A2304((SPLList *)&emtr->unk_4C, (SPLNode *)chld);
SPLList_PushFront((SPLList *)&emtr->unk_4C, (SPLNode *)chld);
chld->unk_08 = ptcl->unk_08;

View File

@ -1,77 +0,0 @@
#include "spl.h"
#include <nitro/fx/fx.h>
void sub_020A2304(SPLList *list, SPLNode *node)
{
if (list->p_begin == NULL) {
list->p_begin = node;
list->p_end = node;
node->p_next = NULL;
node->p_prev = node->p_next;
} else {
node->p_next = list->p_begin;
node->p_prev = NULL;
list->p_begin->p_prev = node;
list->p_begin = node;
}
list->node_num += 1;
}
void spl_push_back(SPLList *list, SPLNode *node)
{
return;
}
SPLNode *sub_020A22B8(SPLList *list)
{
SPLNode *begin;
SPLNode *node;
node = NULL;
begin = list->p_begin;
if (begin != NULL) {
node = begin;
list->p_begin = begin->p_next;
if (list->p_begin != NULL) {
begin->p_next->p_prev = NULL;
} else {
list->p_begin = NULL;
list->p_end = NULL;
}
list->node_num -= 1;
}
return node;
}
SPLNode *spl_pop_back(SPLList *list)
{
return NULL;
}
SPLNode *sub_020A2238(SPLList *list, SPLNode *node)
{
SPLNode *next = node->p_next;
if (next == NULL) {
if (list->p_begin == node) {
list->p_begin = NULL;
list->p_end = NULL;
} else {
node->p_prev->p_next = NULL;
list->p_end = list->p_end->p_prev;
}
} else if (list->p_begin == node) {
list->p_begin = next;
list->p_begin->p_prev = NULL;
} else {
next->p_prev = node->p_prev;
node->p_prev->p_next = node->p_next;
}
list->node_num -= 1;
return node;
}