summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-11-22 23:55:05 -0300
committerGitHub <noreply@github.com>2023-11-23 13:55:05 +1100
commit506e2155474b1914fe93f070c55debdeaf6df0a6 (patch)
tree5ffab32ee39bb1cafc8803caafd1030ff72f93ef /src/code
parent5ef277df2db5dd54c02c098ec88777f63680f6c3 (diff)
Yet another header cleanup (#1508)
* lights.c * z64skin_matrix.h * Move out some stuff from macros.h * gamealloc.h * move most transition functions to z64transition.h * z64lib.h * `include` cleanup on transition files * z_overlay cleanup * z64malloc.h * format * forgot to remove those * forgot this * fix borken includes
Diffstat (limited to 'src/code')
-rw-r--r--src/code/gamealloc.c6
-rw-r--r--src/code/speed_meter.c13
-rw-r--r--src/code/z_actor.c2
-rw-r--r--src/code/z_camera.c1
-rw-r--r--src/code/z_collision_check.c4
-rw-r--r--src/code/z_effect_soft_sprite.c1
-rw-r--r--src/code/z_fbdemo.c3
-rw-r--r--src/code/z_fbdemo_circle.c24
-rw-r--r--src/code/z_fbdemo_dlftbls.c5
-rw-r--r--src/code/z_fbdemo_fade.c12
-rw-r--r--src/code/z_fcurve_data_skelanime.c10
-rw-r--r--src/code/z_lib.c12
-rw-r--r--src/code/z_lights.c28
-rw-r--r--src/code/z_malloc.c3
-rw-r--r--src/code/z_overlay.c60
-rw-r--r--src/code/z_parameter.c2
-rw-r--r--src/code/z_play.c1
-rw-r--r--src/code/z_play_hireso.c2
-rw-r--r--src/code/z_skelanime.c1
-rw-r--r--src/code/z_skin_awb.c4
-rw-r--r--src/code/z_skin_matrix.c6
21 files changed, 137 insertions, 63 deletions
diff --git a/src/code/gamealloc.c b/src/code/gamealloc.c
index 6067ad91c..a0d6f741f 100644
--- a/src/code/gamealloc.c
+++ b/src/code/gamealloc.c
@@ -1,10 +1,10 @@
-#include "global.h"
+#include "gamealloc.h"
+
#include "system_malloc.h"
void GameAlloc_Log(GameAlloc* this) {
- GameAllocEntry* iter;
+ GameAllocEntry* iter = this->base.next;
- iter = this->base.next;
while (iter != &this->base) {
iter = iter->next;
}
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 0835cbd1b..894127f2c 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -1,8 +1,15 @@
-#include "global.h"
-#include "sys_cfb.h"
+#include "prevent_bss_reordering.h"
#include "z64speed_meter.h"
-#include "z64view.h"
+
+#include "gfx.h"
+#include "regs.h"
+#include "sys_cfb.h"
#include "system_malloc.h"
+#include "z64game.h"
+#include "z64malloc.h"
+#include "z64view.h"
+
+#include "variables.h"
/**
* How much time the RSP ran audio tasks for over the course of `gGraphUpdatePeriod`.
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 7d2df00da..0a5d51e22 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -4,11 +4,13 @@
*/
#include "z64actor.h"
+
#include "prevent_bss_reordering.h"
#include "fault.h"
#include "sys_cfb.h"
#include "loadfragment.h"
#include "z64horse.h"
+#include "z64malloc.h"
#include "z64quake.h"
#include "z64rumble.h"
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 00d2978dd..b9123a718 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -45,6 +45,7 @@
#include "global.h"
#include "libc/string.h"
+#include "z64malloc.h"
#include "z64quake.h"
#include "z64shrink_window.h"
#include "z64view.h"
diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c
index af1f4ad6c..e190084af 100644
--- a/src/code/z_collision_check.c
+++ b/src/code/z_collision_check.c
@@ -1,7 +1,9 @@
#include "prevent_bss_reordering.h"
-#include "global.h"
#include "z64collision_check.h"
+#include "global.h"
+#include "z64malloc.h"
+
typedef s32 (*ColChkResetFunc)(struct PlayState*, Collider*);
typedef void (*ColChkBloodFunc)(struct PlayState*, Collider*, Vec3f*);
typedef void (*ColChkApplyFunc)(struct PlayState*, CollisionCheckContext*, Collider*);
diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c
index 08aa845ab..4b47f2b34 100644
--- a/src/code/z_effect_soft_sprite.c
+++ b/src/code/z_effect_soft_sprite.c
@@ -1,5 +1,6 @@
#include "global.h"
#include "loadfragment.h"
+#include "z64malloc.h"
EffectSsInfo sEffectSsInfo = { NULL, 0, 0 };
diff --git a/src/code/z_fbdemo.c b/src/code/z_fbdemo.c
index 441af901e..6ad5f7a6c 100644
--- a/src/code/z_fbdemo.c
+++ b/src/code/z_fbdemo.c
@@ -9,6 +9,9 @@
* @note The only coded effect has a visual effect to blend the tiles to a single point, which looks like the screen
* gets sucked into.
*/
+
+#include "z64transition.h"
+
#include "global.h"
#include "system_malloc.h"
diff --git a/src/code/z_fbdemo_circle.c b/src/code/z_fbdemo_circle.c
index efd492d5c..81322284f 100644
--- a/src/code/z_fbdemo_circle.c
+++ b/src/code/z_fbdemo_circle.c
@@ -1,7 +1,10 @@
-#include "global.h"
+#include "z64transition.h"
+
#include "sys_cfb.h"
+#include "z64math.h"
+#include "variables.h"
-typedef enum {
+typedef enum TransitionCircleDirection {
/* 0 */ TRANS_CIRCLE_DIR_IN,
/* 1 */ TRANS_CIRCLE_DIR_OUT
} TransitionCircleDirection;
@@ -18,10 +21,18 @@ Gfx sTransCircleSetupDL[] = {
gsSPEndDisplayList(),
};
-//! @bug: TransitionCircle_Update should take an additional argument `s32 updateRate`
+void TransitionCircle_Start(void* thisx);
+void* TransitionCircle_Init(void* thisx);
+void TransitionCircle_Destroy(void* thisx);
+void TransitionCircle_Update(void* thisx, s32 updateRate);
+void TransitionCircle_SetColor(void* thisx, u32 color);
+void TransitionCircle_SetType(void* thisx, s32 type);
+void TransitionCircle_Draw(void* thisx, Gfx** gfxp);
+s32 TransitionCircle_IsDone(void* thisx);
+
TransitionInit TransitionCircle_InitVars = {
- TransitionCircle_Init, TransitionCircle_Destroy, (void*)TransitionCircle_Update, TransitionCircle_Draw,
- TransitionCircle_Start, TransitionCircle_SetType, TransitionCircle_SetColor, NULL,
+ TransitionCircle_Init, TransitionCircle_Destroy, TransitionCircle_Update, TransitionCircle_Draw,
+ TransitionCircle_Start, TransitionCircle_SetType, TransitionCircle_SetColor, NULL,
TransitionCircle_IsDone,
};
@@ -56,8 +67,9 @@ void* TransitionCircle_Init(void* thisx) {
void TransitionCircle_Destroy(void* thisx) {
}
-void TransitionCircle_Update(void* thisx) {
+void TransitionCircle_Update(void* thisx, s32 updateRate) {
TransitionCircle* this = (TransitionCircle*)thisx;
+ s32 unused = updateRate ? 0 : 0;
this->isDone = Math_StepToF(&this->referenceRadius, this->targetRadius, this->stepValue);
}
diff --git a/src/code/z_fbdemo_dlftbls.c b/src/code/z_fbdemo_dlftbls.c
index 48d424813..df73ed1b3 100644
--- a/src/code/z_fbdemo_dlftbls.c
+++ b/src/code/z_fbdemo_dlftbls.c
@@ -1,4 +1,7 @@
-#include "global.h"
+#include "z64transition.h"
+
+#include "segment_symbols.h"
+#include "z64lib.h"
// InitVars and Linker symbol declarations (used in the table below)
#define DEFINE_TRANSITION(_enumValue, structName, _instanceName, name) \
diff --git a/src/code/z_fbdemo_fade.c b/src/code/z_fbdemo_fade.c
index a9ab37d48..f1e535594 100644
--- a/src/code/z_fbdemo_fade.c
+++ b/src/code/z_fbdemo_fade.c
@@ -1,13 +1,19 @@
-#include "global.h"
+#include "z64transition.h"
+
+#include "libc/stdbool.h"
+#include "gfx.h"
+#include "regs.h"
+#include "z64math.h"
+#include "z64save.h"
#define THIS ((TransitionFade*)thisx)
-typedef enum {
+typedef enum TransitionFadeDirection {
/* 0 */ TRANS_FADE_DIR_IN,
/* 1 */ TRANS_FADE_DIR_OUT
} TransitionFadeDirection;
-typedef enum {
+typedef enum TransitionFadeType {
/* 0 */ TRANS_FADE_TYPE_NONE,
/* 1 */ TRANS_FADE_TYPE_ONE_WAY,
/* 2 */ TRANS_FADE_TYPE_FLASH
diff --git a/src/code/z_fcurve_data_skelanime.c b/src/code/z_fcurve_data_skelanime.c
index 669e01348..6569d95d7 100644
--- a/src/code/z_fcurve_data_skelanime.c
+++ b/src/code/z_fcurve_data_skelanime.c
@@ -25,9 +25,15 @@
* - higher detail draws both.
*/
-#include "global.h"
#include "z64curve.h"
+#include "libc/stdbool.h"
+#include "z64actor.h"
+#include "z64animation.h"
+#include "z64curve.h"
+#include "z64malloc.h"
+#include "z64.h"
+
void SkelCurve_Clear(SkelCurve* skelCurve) {
skelCurve->limbCount = 0;
skelCurve->skeleton = NULL;
@@ -76,7 +82,7 @@ void SkelCurve_SetAnim(SkelCurve* skelCurve, CurveAnimationHeader* animation, f3
skelCurve->animation = animation;
}
-typedef enum {
+typedef enum SkelCurveVecType {
/* 0 */ SKELCURVE_VEC_TYPE_SCALE,
/* 1 */ SKELCURVE_VEC_TYPE_ROTATION,
/* 2 */ SKELCURVE_VEC_TYPE_POSIITON,
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index afbcba0ed..12bf959fc 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -1,4 +1,12 @@
-#include "global.h"
+#include "z64lib.h"
+
+#include "main.h"
+#include "ichain.h"
+#include "sfx.h"
+#include "z64actor.h"
+#include "z64game.h"
+#include "functions.h"
+#include "macros.h"
void* Lib_MemCpy(void* dest, void* src, size_t size) {
bcopy(src, dest, size);
@@ -11,7 +19,7 @@ void* Lib_MemSet(void* buffer, s32 value, size_t size) {
s32 i;
if (value == 0) {
- bzero(buffer, (u32)size);
+ bzero(buffer, size);
return buffer;
}
diff --git a/src/code/z_lights.c b/src/code/z_lights.c
index e5b34f387..e15043b9e 100644
--- a/src/code/z_lights.c
+++ b/src/code/z_lights.c
@@ -1,10 +1,15 @@
-#include "global.h"
+#include "z64light.h"
+
#include "sys_cfb.h"
+#include "z64skin_matrix.h"
+#include "z64.h"
+#include "functions.h"
+
#include "objects/gameplay_keep/gameplay_keep.h"
LightsBuffer sLightsBuffer;
-void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, s32 type) {
+void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, LightType type) {
info->type = type;
info->params.point.x = x;
info->params.point.y = y;
@@ -79,7 +84,7 @@ void Lights_Draw(Lights* lights, GraphicsContext* gfxCtx) {
}
Light* Lights_FindSlot(Lights* lights) {
- if (lights->numLights >= 7) {
+ if (lights->numLights >= ARRAY_COUNT(lights->l.l)) {
return NULL;
}
return &lights->l.l[lights->numLights++];
@@ -182,6 +187,9 @@ void Lights_BindDirectional(Lights* lights, LightParams* params, void* unused) {
}
}
+typedef void (*LightsBindFunc)(Lights* lights, LightParams* params, Vec3f* vec);
+typedef void (*LightsPosBindFunc)(Lights* lights, LightParams* params, struct PlayState* play);
+
/**
* For every light in a provided list, try to find a free slot in the provided Lights group and bind
* a light to it. Then apply color and positional/directional info for each light
@@ -240,13 +248,15 @@ LightNode* Lights_FindBufSlot(void) {
}
void Lights_FreeNode(LightNode* light) {
- if (light != NULL) {
- sLightsBuffer.numOccupied--;
- light->info = NULL;
- sLightsBuffer.searchIndex =
- (light - sLightsBuffer.lights) /
- (s32)sizeof(LightNode); //! @bug Due to pointer arithmetic, the division is unnecessary
+ if (light == NULL) {
+ return;
}
+
+ sLightsBuffer.numOccupied--;
+ light->info = NULL;
+
+ //! @bug Due to pointer arithmetic, the division is unnecessary
+ sLightsBuffer.searchIndex = (light - sLightsBuffer.lights) / (s32)sizeof(LightNode);
}
void LightContext_Init(PlayState* play, LightContext* lightCtx) {
diff --git a/src/code/z_malloc.c b/src/code/z_malloc.c
index c23da3927..80d7fc7af 100644
--- a/src/code/z_malloc.c
+++ b/src/code/z_malloc.c
@@ -1,4 +1,5 @@
-#include "global.h"
+#include "z64malloc.h"
+
#include "os_malloc.h"
Arena sZeldaArena;
diff --git a/src/code/z_overlay.c b/src/code/z_overlay.c
index fe0857820..c994ba9ec 100644
--- a/src/code/z_overlay.c
+++ b/src/code/z_overlay.c
@@ -2,18 +2,13 @@
* @file z_overlay.c
*
* Functions for handling transition overlays in memory
- *
- * Status codes returned from TransitionOverlay_Load and TransitionOverlay_Free:
- *
- * -1 : failed allocation or null reference
- * 0 : successfully loaded/freed overlay
- * 1 : successfully added/removed instance
- * 2 : overlay is loaded but has no instances (?) TODO: Figure out why this exists
- * 3 : internal overlay, so always loaded
*/
-#include "global.h"
+#include "z64transition.h"
+
#include "loadfragment.h"
+#include "z64lib.h"
+#include "z64malloc.h"
void* TransitionOverlay_VramToRam(TransitionOverlay* overlayEntry, void* vramAddr) {
void* loadedRamAddr = Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr);
@@ -32,46 +27,51 @@ void TransitionOverlay_VramToRamArray(TransitionOverlay* overlayEntry, void** vr
}
}
-s32 TransitionOverlay_Load(TransitionOverlay* overlayEntry) {
+TransitionOverlayStatus TransitionOverlay_Load(TransitionOverlay* overlayEntry) {
s32 count;
void* loadedRamAddr;
if (overlayEntry->vromStart == 0) {
- return 3;
+ return TRANSITION_OVERLAY_STATUS_INTERNAL;
}
+
if (Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr) == NULL) {
loadedRamAddr = ZeldaArena_Malloc((uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart);
if (loadedRamAddr == NULL) {
- return -1;
+ return TRANSITION_OVERLAY_STATUS_FAILED;
}
+
Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd,
loadedRamAddr);
overlayEntry->loadInfo.addr = Lib_VirtualToPhysical(loadedRamAddr);
overlayEntry->loadInfo.count = 1;
- return 0;
- } else {
- count = overlayEntry->loadInfo.count;
- if (count != 0) {
- count++;
- overlayEntry->loadInfo.count = count;
- if (count == 0) {
- return 2;
- } else {
- return 1;
- }
+ return TRANSITION_OVERLAY_STATUS_LOAD_FREE;
+ }
+
+ count = overlayEntry->loadInfo.count;
+ if (count != 0) {
+ count++;
+ overlayEntry->loadInfo.count = count;
+
+ if (count == 0) {
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
+ } else {
+ return TRANSITION_OVERLAY_STATUS_ADD_REMOVAL;
}
- return 2;
}
+
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
}
-s32 TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
+TransitionOverlayStatus TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
s32 count;
void* loadedRamAddr;
if (overlayEntry->vromStart == 0) {
- return 3;
+ return TRANSITION_OVERLAY_STATUS_INTERNAL;
}
+
loadedRamAddr = Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr);
if (loadedRamAddr != NULL) {
count = overlayEntry->loadInfo.count;
@@ -81,13 +81,13 @@ s32 TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
if (count == 0) {
ZeldaArena_Free(loadedRamAddr);
overlayEntry->loadInfo.addr = Lib_VirtualToPhysical(NULL);
- return 0;
+ return TRANSITION_OVERLAY_STATUS_LOAD_FREE;
}
- return 1;
+ return TRANSITION_OVERLAY_STATUS_ADD_REMOVAL;
}
- return 2;
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
}
- return -1;
+ return TRANSITION_OVERLAY_STATUS_FAILED;
}
void TransitionOverlay_ClearLoadInfo(TransitionOverlay* overlayEntry) {
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index f3077da95..db101efb5 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -1,9 +1,11 @@
#include "global.h"
#include "PR/gs2dex.h"
#include "sys_cfb.h"
+#include "z64malloc.h"
#include "z64snap.h"
#include "z64view.h"
#include "z64voice.h"
+
#include "archives/icon_item_static/icon_item_static_yar.h"
#include "interface/parameter_static/parameter_static.h"
#include "interface/do_action_static/do_action_static.h"
diff --git a/src/code/z_play.c b/src/code/z_play.c
index ee519270a..226980b4d 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -2,6 +2,7 @@
#include "z64.h"
#include "regs.h"
#include "functions.h"
+#include "z64malloc.h"
#include "z64vismono.h"
#include "z64visfbuf.h"
diff --git a/src/code/z_play_hireso.c b/src/code/z_play_hireso.c
index 1b2572ea8..e9610039f 100644
--- a/src/code/z_play_hireso.c
+++ b/src/code/z_play_hireso.c
@@ -1,6 +1,8 @@
#include "global.h"
#include "sys_cfb.h"
#include "z64bombers_notebook.h"
+#include "z64malloc.h"
+
#include "interface/schedule_static/schedule_static.h"
#include "archives/schedule_dma_static/schedule_dma_static_yar.h"
diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c
index 7b33d9cf5..58542b786 100644
--- a/src/code/z_skelanime.c
+++ b/src/code/z_skelanime.c
@@ -1,4 +1,5 @@
#include "global.h"
+#include "z64malloc.h"
#define ANIM_INTERP 1
diff --git a/src/code/z_skin_awb.c b/src/code/z_skin_awb.c
index edbcef05f..8425d961a 100644
--- a/src/code/z_skin_awb.c
+++ b/src/code/z_skin_awb.c
@@ -1,6 +1,8 @@
-#include "global.h"
#include "z64skin.h"
+#include "global.h"
+#include "z64malloc.h"
+
void Skin_Setup(Skin* skin) {
skin->skeletonHeader = NULL;
skin->limbCount = 0;
diff --git a/src/code/z_skin_matrix.c b/src/code/z_skin_matrix.c
index 9b30a3c0b..8f9635508 100644
--- a/src/code/z_skin_matrix.c
+++ b/src/code/z_skin_matrix.c
@@ -1,4 +1,8 @@
-#include "global.h"
+#include "z64skin_matrix.h"
+
+#include "gfx.h"
+#include "macros.h"
+#include "z64math.h"
MtxF sMtxFClear = { {
{ 1.0f, 0.0f, 0.0f, 0.0f },