add list types and fix code that uses them

This commit is contained in:
dark-samus 2020-10-21 20:07:00 -04:00
parent 66bc833880
commit 49c7ba0239
5 changed files with 55 additions and 34 deletions

View File

@ -115,6 +115,8 @@ typedef struct Npc {
/* 0x0AB */ char unk_AB[661]; /* 0x0AB */ char unk_AB[661];
} Npc; // size = 0x340 } Npc; // size = 0x340
typedef Npc* NpcList[MAX_NPCS];
typedef struct PlayerData { typedef struct PlayerData {
/* 0x000 */ s8 bootsLevel; /* 0x000 */ s8 bootsLevel;
/* 0x001 */ s8 hammerLevel; /* 0x001 */ s8 hammerLevel;
@ -204,6 +206,8 @@ typedef struct Trigger {
/* 0x34 */ ScriptID runningScriptID; /* 0x34 */ ScriptID runningScriptID;
} Trigger; // size = 0x38 } Trigger; // size = 0x38
typedef Trigger* TriggerList[MAX_TRIGGERS];
typedef struct ScriptInstance { typedef struct ScriptInstance {
/* 0x000 */ u8 state; /* 0x000 */ u8 state;
/* 0x001 */ u8 currentArgc; /* 0x001 */ u8 currentArgc;
@ -271,6 +275,10 @@ typedef struct Entity {
/* 0xB1 */ char unk_B1[71]; /* 0xB1 */ char unk_B1[71];
} Entity; // size = 0xF8 } Entity; // size = 0xF8
typedef Entity* EntityList[MAX_ENTITIES];
typedef UNK_TYPE* DynamicEntityList[MAX_DYNAMIC_ENTITIES];
typedef struct StaticEntityData { typedef struct StaticEntityData {
/* 0x00 */ s16 flags; /* 0x00 */ s16 flags;
/* 0x02 */ s16 argSize; /* 0x02 */ s16 argSize;
@ -364,6 +372,7 @@ typedef struct UiStatus {
/* 0x68 */ s32 iconIndex13; /* 0x68 */ s32 iconIndex13;
/* 0x6C */ s8 unk_6C[4]; /* 0x6C */ s8 unk_6C[4];
} UiStatus; // size = 0x70 } UiStatus; // size = 0x70
typedef struct Collider { typedef struct Collider {
/* 0x00 */ s32 flags; /* 0x00 */ s32 flags;
/* 0x04 */ s16 nextSibling; /* 0x04 */ s16 nextSibling;
@ -672,6 +681,8 @@ typedef struct Model {
/* 0xAA */ char unk_AA[6]; /* 0xAA */ char unk_AA[6];
} Model; // size = 0xB0 } Model; // size = 0xB0
typedef Model* ModelList[MAX_MODELS];
typedef struct AnimatedMesh { typedef struct AnimatedMesh {
/* 0x000 */ s32 flags; /* 0x000 */ s32 flags;
/* 0x004 */ u8 renderMode; /* 0x004 */ u8 renderMode;
@ -921,6 +932,8 @@ typedef struct Shadow {
/* 0x28 */ char unk_28[80]; /* 0x28 */ char unk_28[80];
} Shadow; // size = 0x78 } Shadow; // size = 0x78
typedef Shadow* ShadowList[MAX_SHADOWS];
typedef struct PushBlockGrid { typedef struct PushBlockGrid {
/* 0x00 */ s8* cells; /* 0x00 */ s8* cells;
/* 0x04 */ u8 numCellsX; /* 0x04 */ u8 numCellsX;

View File

@ -23,7 +23,13 @@
#define MAX_MAPVARS 16 #define MAX_MAPVARS 16
#define MAX_MAPFLAGS 3 #define MAX_MAPFLAGS 3
#define MAX_MODELS 256
#define MAX_SCRIPTS 128 #define MAX_SCRIPTS 128
#define MAX_NPCS 64
#define MAX_TRIGGERS 64
#define MAX_SHADOWS 60
#define MAX_ENTITIES 30
#define MAX_DYNAMIC_ENTITIES 16
//NOTE: SCRIPT_ALLOC is probably not quite correct, but this is the closest thing to matching for the functions its used in. Needs more work. //NOTE: SCRIPT_ALLOC is probably not quite correct, but this is the closest thing to matching for the functions its used in. Needs more work.
#define SCRIPT_ALLOC(new, index) \ #define SCRIPT_ALLOC(new, index) \

View File

@ -38,30 +38,31 @@ extern s32 gScriptIndexList[MAX_SCRIPTS];
extern s32 gMoveScriptTable[][4]; extern s32 gMoveScriptTable[][4];
extern Model* gWorldModelList[256]; extern ModelList gWorldModelList;
extern Model* gBattleModelList[256]; extern ModelList gBattleModelList;
extern Model** gCurrentModelListPtr[256]; extern ModelList* gCurrentModelListPtr;
// TODO: potentially a display list, figure this out
extern u32* gWorldModelSpecialDls[32]; extern u32* gWorldModelSpecialDls[32];
extern u32* gBattleModelSpecialDls[32]; extern u32* gBattleModelSpecialDls[32];
extern u32** gCurrentModelSpecialDlsPtr[32]; extern u32** gCurrentModelSpecialDlsPtr[32];
extern Entity* gWorldEntityList[30]; extern EntityList gWorldEntityList;
extern Entity* gBattleEntityList[30]; extern EntityList gBattleEntityList;
extern Entity** gCurrentEntityListPtr[30]; extern EntityList* gCurrentEntityListPtr;
extern s32 gLastCreatedEntityIndex; extern s32 gLastCreatedEntityIndex;
extern UNK_TYPE* gWorldDynamicEntityList[16]; extern DynamicEntityList gWorldDynamicEntityList;
extern UNK_TYPE* gBattleDynamicEntityList[16]; extern DynamicEntityList gBattleDynamicEntityList;
extern UNK_TYPE*** gCurrentDynamicEntityListPtr; extern DynamicEntityList* gCurrentDynamicEntityListPtr;
extern Npc* gWorldNpcList[64]; extern NpcList gWorldNpcList;
extern Npc* gBattleNpcList[64]; extern NpcList gBattleNpcList;
extern Npc** gCurrentNpcListPtr[64]; extern NpcList* gCurrentNpcListPtr;
extern Shadow* gWorldShadowList[60]; extern ShadowList gWorldShadowList;
extern Shadow* gBattleShadowList[60]; extern ShadowList gBattleShadowList;
extern Shadow** gCurrentShadowListPtr[60]; extern ShadowList* gCurrentShadowListPtr;
extern Camera gCameras[4]; extern Camera gCameras[4];
extern s32 gCurrentCameraID; extern s32 gCurrentCameraID;
@ -89,9 +90,9 @@ extern PrintContext* D_802DB268;
// Triggers // Triggers
extern s16 gTriggerCount; extern s16 gTriggerCount;
extern Trigger* gTriggerList1[64]; extern TriggerList gTriggerList1;
extern Trigger* gTriggerList2[64]; extern TriggerList gTriggerList2;
extern Trigger** gCurrentTriggerListPtr[64]; extern TriggerList* gCurrentTriggerListPtr;
// Map transition data. Should probably be a struct // Map transition data. Should probably be a struct
extern u16 gMapTransitionAlpha; extern u16 gMapTransitionAlpha;

View File

@ -34,24 +34,24 @@ Shadow* get_shadow_by_index(s32 index) {
return (*gCurrentShadowListPtr)[index & 0xFFF]; return (*gCurrentShadowListPtr)[index & 0xFFF];
} }
Entity** get_entity_list(void) { EntityList* get_entity_list(void) {
Entity** ret; EntityList* ret;
if (!GAME_STATUS->isBattle) { if (!GAME_STATUS->isBattle) {
ret = gWorldEntityList; ret = &gWorldEntityList;
} else { } else {
ret = gBattleEntityList; ret = &gBattleEntityList;
} }
return ret; return ret;
} }
Shadow** get_shadow_list(void) { ShadowList* get_shadow_list(void) {
Shadow** ret; ShadowList* ret;
if (!GAME_STATUS->isBattle) { if (!GAME_STATUS->isBattle) {
ret = gWorldShadowList; ret = &gWorldShadowList;
} else { } else {
ret = gBattleShadowList; ret = &gBattleShadowList;
} }
return ret; return ret;
} }

View File

@ -8,9 +8,9 @@ INCLUDE_ASM(s32, "code_dbd70_len_700", clear_trigger_data);
void init_trigger_list(void) { void init_trigger_list(void) {
if (!GAME_STATUS->isBattle) { if (!GAME_STATUS->isBattle) {
*gCurrentTriggerListPtr = gTriggerList1; gCurrentTriggerListPtr = &gTriggerList1;
} else { } else {
*gCurrentTriggerListPtr = gTriggerList2; gCurrentTriggerListPtr = &gTriggerList2;
} }
gTriggerCount = 0; gTriggerCount = 0;
@ -22,16 +22,17 @@ INCLUDE_ASM(s32, "code_dbd70_len_700", update_triggers);
void delete_trigger(Trigger* toDelete) { void delete_trigger(Trigger* toDelete) {
s32 i; s32 i;
TriggerList** currentTriggerListPtr = &gCurrentTriggerListPtr;
for (i = 0; i < ARRAY_COUNT(gCurrentTriggerListPtr); i++) { for (i = 0; i < MAX_TRIGGERS; i++) {
if ((*gCurrentTriggerListPtr)[i] == toDelete) { if ((**currentTriggerListPtr)[i] == toDelete) {
break; break;
} }
} }
if (i < ARRAY_COUNT(gCurrentTriggerListPtr)) { if (i < MAX_TRIGGERS) {
heap_free((*gCurrentTriggerListPtr)[i]); heap_free((**currentTriggerListPtr)[i]);
(*gCurrentTriggerListPtr)[i] = NULL; (**currentTriggerListPtr)[i] = NULL;
} }
} }
@ -48,7 +49,7 @@ s32 func_80145CE8(s32 arg0) {
return 0; return 0;
} }
for (i = 0; i < ARRAY_COUNT(gCurrentTriggerListPtr); i++) { for (i = 0; i < MAX_TRIGGERS; i++) {
Trigger* trigger = (*gCurrentTriggerListPtr)[i]; Trigger* trigger = (*gCurrentTriggerListPtr)[i];
if ((trigger != NULL) && if ((trigger != NULL) &&