summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorRozelette <Rozelette@users.noreply.github.com>2021-04-07 16:16:16 -0500
committerGitHub <noreply@github.com>2021-04-07 17:16:16 -0400
commitd2c181a0a99430cd9893b022bd179cffc11dbbba (patch)
treeceb21e76b835263ac1c8c67835b23c65eb9bcb10 /src/code
parentb22e26dbd84042ffa35d4ee38f44574550d88c82 (diff)
z_lib fully matched (#85)
* z_lib OK * Documentation * Added stdbool and stdint * Fixup for new names * Fixup bad merge * Feedback * Use u/s32 for intptr_t
Diffstat (limited to 'src/code')
-rw-r--r--src/code/code_0x800E8EA0.c14
-rw-r--r--src/code/z_actor.c8
-rw-r--r--src/code/z_effect_soft_sprite_old_init.c2
-rw-r--r--src/code/z_en_item00.c14
-rw-r--r--src/code/z_lib.c590
-rw-r--r--src/code/z_room.c2
-rw-r--r--src/code/z_scene.c46
-rw-r--r--src/code/z_scene_proc.c18
-rw-r--r--src/code/z_skelanime.c62
9 files changed, 425 insertions, 331 deletions
diff --git a/src/code/code_0x800E8EA0.c b/src/code/code_0x800E8EA0.c
index cfb9a5b18..403bdb226 100644
--- a/src/code/code_0x800E8EA0.c
+++ b/src/code/code_0x800E8EA0.c
@@ -19,10 +19,10 @@ s32 nop_800E8EEC(UNK_TYPE4 param_1) {
void nop_800E8EFC(UNK_TYPE4 param_1) {}
s32 func_800E8F08(Vec3s* param_1, Vec3s* param_2) {
- Math_SmoothScaleMaxMinS(&param_1->y, 0, 6, 6200, 100);
- Math_SmoothScaleMaxMinS(&param_1->x, 0, 6, 6200, 100);
- Math_SmoothScaleMaxMinS(&param_2->y, 0, 6, 6200, 100);
- Math_SmoothScaleMaxMinS(&param_2->x, 0, 6, 6200, 100);
+ Math_SmoothStepToS(&param_1->y, 0, 6, 6200, 100);
+ Math_SmoothStepToS(&param_1->x, 0, 6, 6200, 100);
+ Math_SmoothStepToS(&param_2->y, 0, 6, 6200, 100);
+ Math_SmoothStepToS(&param_2->x, 0, 6, 6200, 100);
return 1;
}
@@ -34,10 +34,10 @@ s32 func_800E8FA4(Actor* actor, Vec3f* param_2, Vec3s* param_3, Vec3s* param_4)
targetPitch = Math_Vec3f_Pitch(&actor->focus.pos,param_2);
targetYaw = Math_Vec3f_Yaw(&actor->focus.pos,param_2) - actor->world.rot.y;
- Math_SmoothScaleMaxMinS(&param_3->x, targetPitch, 6, 2000, 1);
+ Math_SmoothStepToS(&param_3->x, targetPitch, 6, 2000, 1);
param_3->x = (param_3->x < -6000)? -6000 : ((6000 < param_3->x)? 6000 : param_3->x);
- yawDiffFromTarget = Math_SmoothScaleMaxMinS(&param_3->y, targetYaw, 6, 2000, 1);
+ yawDiffFromTarget = Math_SmoothStepToS(&param_3->y, targetYaw, 6, 2000, 1);
param_3->y = (param_3->y < -8000)? -8000 : ((8000 < param_3->y)? 8000 : param_3->y);
if (yawDiffFromTarget != 0) {
@@ -46,7 +46,7 @@ s32 func_800E8FA4(Actor* actor, Vec3f* param_2, Vec3s* param_3, Vec3s* param_4)
}
}
- Math_SmoothScaleMaxMinS(&param_4->y, targetYaw - param_3->y, 4, 2000, 1);
+ Math_SmoothStepToS(&param_4->y, targetYaw - param_3->y, 4, 2000, 1);
param_4->y = (param_4->y < -12000)? -12000 : ((12000 < param_4->y)? 12000 : param_4->y);
return 1;
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 2a4699860..e941198f6 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -265,11 +265,11 @@ void Actor_TitleCardCreate(GlobalContext* ctxt, TitleCardContext* titleCtxt, u32
void Actor_TitleCardUpdate(GlobalContext* ctxt, TitleCardContext* titleCtxt) {
if (DECR(titleCtxt->fadeInDelay) == 0) {
if (DECR(titleCtxt->fadeOutDelay) == 0) {
- Lib_StepTowardsCheck_s(&titleCtxt->alpha, 0, 30);
- Lib_StepTowardsCheck_s(&titleCtxt->color, 0, 70);
+ Math_StepToS(&titleCtxt->alpha, 0, 30);
+ Math_StepToS(&titleCtxt->color, 0, 70);
} else {
- Lib_StepTowardsCheck_s(&titleCtxt->alpha, 255, 10);
- Lib_StepTowardsCheck_s(&titleCtxt->color, 255, 20);
+ Math_StepToS(&titleCtxt->alpha, 255, 10);
+ Math_StepToS(&titleCtxt->color, 255, 20);
}
}
}
diff --git a/src/code/z_effect_soft_sprite_old_init.c b/src/code/z_effect_soft_sprite_old_init.c
index bc2ac56c9..b0bbccfab 100644
--- a/src/code/z_effect_soft_sprite_old_init.c
+++ b/src/code/z_effect_soft_sprite_old_init.c
@@ -26,7 +26,7 @@ void EffectSs_DrawGEffect(GlobalContext* globalCtx, EffectSs* this, void* textur
if (mtx != NULL) {
gSPMatrix(POLY_XLU_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
- gSPSegment(POLY_XLU_DISP++, 0x08, Lib_PtrSegToVirt(texture));
+ gSPSegment(POLY_XLU_DISP++, 0x08, Lib_SegmentedToVirtual(texture));
func_8012C9BC(gfxCtx);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, this->rgPrimColorR, this->rgPrimColorG, this->rgPrimColorB,
this->rgPrimColorA);
diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c
index 1bdfc3a39..b4917b637 100644
--- a/src/code/z_en_item00.c
+++ b/src/code/z_en_item00.c
@@ -275,14 +275,14 @@ void func_800A640C(EnItem00* this, GlobalContext* ctxt) {
this->actor.shape.rot.y = this->actor.shape.rot.y + 960;
} else if ((this->actor.params >= ITEM00_SHIELD_HERO) && (this->actor.params != ITEM00_NUTS_10) && (this->actor.params < ITEM00_BOMBS_0)) {
if (this->unk152 == -1) {
- if (!Math_SmoothScaleMaxMinS(&this->actor.shape.rot.x, this->actor.world.rot.x - 0x4000, 2, 3000, 1500)) {
+ if (!Math_SmoothStepToS(&this->actor.shape.rot.x, this->actor.world.rot.x - 0x4000, 2, 3000, 1500)) {
this->unk152 = -2;
}
- } else if (!Math_SmoothScaleMaxMinS(&this->actor.shape.rot.x, -0x4000 - this->actor.world.rot.x, 2, 3000, 1500)) {
+ } else if (!Math_SmoothStepToS(&this->actor.shape.rot.x, -0x4000 - this->actor.world.rot.x, 2, 3000, 1500)) {
this->unk152 = -1;
}
- Math_SmoothScaleMaxMinS(&this->actor.world.rot.x, 0, 2, 2500, 500);
+ Math_SmoothStepToS(&this->actor.world.rot.x, 0, 2, 2500, 500);
} else if ((this->actor.params == ITEM00_MAP) || (this->actor.params == ITEM00_COMPASS)) {
this->unk152 = -1;
this->actor.shape.rot.y = this->actor.shape.rot.y + 960;
@@ -292,7 +292,7 @@ void func_800A640C(EnItem00* this, GlobalContext* ctxt) {
this->actor.shape.yOffset = (Math_SinS(this->actor.shape.rot.y) * 150.0f) + 850.0f;
}
- Math_SmoothScaleMaxMinF(&this->actor.speedXZ, 0.0f, 1.0f, 0.5f, 0.0f);
+ Math_SmoothStepToF(&this->actor.speedXZ, 0.0f, 1.0f, 0.5f, 0.0f);
if (this->unk14C == 0) {
if ((this->actor.params != ITEM00_SMALL_KEY) && (this->actor.params != ITEM00_HEART_PIECE) && (this->actor.params != ITEM00_HEART_CONTAINER)) {
@@ -443,7 +443,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
this->actionFunc(this, globalCtx);
- Math_SmoothScaleMaxMinF(&this->actor.scale.x, this->unk154, 0.1f, this->unk154 * 0.1f, 0.0f);
+ Math_SmoothStepToF(&this->actor.scale.x, this->unk154, 0.1f, this->unk154 * 0.1f, 0.0f);
this->actor.scale.z = this->actor.scale.x;
this->actor.scale.y = this->actor.scale.x;
@@ -709,7 +709,7 @@ void EnItem00_DrawRupee(EnItem00* this, GlobalContext* globalCtx) {
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD);
- gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_801ADF30[iconNb]));
+ gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_801ADF30[iconNb]));
gSPDisplayList(POLY_OPA_DISP++, &D_040622C0); // TODO symbol
@@ -751,7 +751,7 @@ void EnItem00_DrawSprite(EnItem00* this, GlobalContext* globalCtx) {
POLY_OPA_DISP = func_8012C724(POLY_OPA_DISP);
- gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_801ADF44[iconNb]));
+ gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_801ADF44[iconNb]));
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD);
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index de911c257..1d67449e6 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -1,222 +1,268 @@
#include <ultra64.h>
#include <global.h>
-void* Lib_bcopy(void* dest, void* src, size_t n) {
- bcopy(src, dest, n);
+void* Lib_MemCpy(void* dest, void* src, size_t size) {
+ bcopy(src, dest, size);
return dest;
}
-#ifdef NON_MATCHING
-void* Lib_MemSet(u8* a0, u32 a1, u32 a2) {
+void* Lib_MemSet(void* buffer, s32 value, size_t size) {
u8* v0;
+ s32 i;
- // XXX: realloc is messed up
- if (a1 == 0) {
- _blkclr((void*)a0, (u32)a2);
+ if (value == 0) {
+ bzero(buffer, (u32)size);
- return a0;
+ return buffer;
}
- for (v0 = a0; a2 != 0; a2--) {
- *v0++ = a1;
+ for (v0 = (u8*)buffer, i = size; i > 0; i--) {
+ *v0++ = value;
}
- return a0;
+ return buffer;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_MemSet.asm")
-#endif
f32 Math_CosS(s16 angle) {
- return coss(angle) * D_801DDA80;
+ return coss(angle) * SHT_MINV;
}
f32 Math_SinS(s16 angle) {
- return sins(angle) * D_801DDA84;
+ return sins(angle) * SHT_MINV;
}
-s32 Lib_StepTowardsGet_i(s32 start, s32 value, s32 step) {
- s32 v1;
+s32 Math_StepToIImpl(s32 start, s32 target, s32 step) {
+ s32 ret;
- if (value >= start) {
- v1 = start + step;
- if (value >= v1) {
- return v1;
+ if (target >= start) {
+ ret = start + step;
+ if (target >= ret) {
+ return ret;
}
} else {
- v1 = start - step;
- if (v1 >= value) {
- return v1;
+ ret = start - step;
+ if (ret >= target) {
+ return ret;
}
}
- return value;
+ return target;
}
-void Lib_StepTowards_i(s32* start, s32 value, s32 step) {
- *start = Lib_StepTowardsGet_i(*start, value, step);
+void Math_StepToIGet(s32* pValue, s32 target, s32 step) {
+ *pValue = Math_StepToIImpl(*pValue, target, step);
}
-s32 Lib_StepTowardsCheck_i(s32* start, s32 value, s32 step) {
- Lib_StepTowards_i(start, value, step);
+s32 Math_StepToI(s32* pValue, s32 target, s32 step) {
+ Math_StepToIGet(pValue, target, step);
- return value == *start;
+ return target == *pValue;
}
-s32 Lib_StepTowardsCheckFramerateScaled_s(s16* start, s16 target, s16 step) {
+s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step) {
f32 f0;
if (step != 0) {
f0 = gFramerateDivisorHalf;
- if ((s16)(*start - target) > 0) {
+ if ((s16)(*pValue - target) > 0) {
step = -step;
}
- *start += (s16)(step * f0);
+ *pValue += (s16)(step * f0);
- if (((s16)(*start - target) * step) >= 0) {
- *start = target;
+ if (((s16)(*pValue - target) * step) >= 0) {
+ *pValue = target;
- return 1;
+ return true;
}
- } else if (target == *start) {
- return 1;
+ } else if (target == *pValue) {
+ return true;
}
- return 0;
+ return false;
}
-s32 Lib_StepTowardsCheck_s(s16* start, s16 target, s16 step) {
+s32 Math_StepToS(s16* pValue, s16 target, s16 step) {
if (step != 0) {
- if (target < *start) {
+ if (target < *pValue) {
step = -step;
}
- *start += step;
+ *pValue += step;
- if (((*start - target) * step) >= 0) {
- *start = target;
+ if (((*pValue - target) * step) >= 0) {
+ *pValue = target;
- return 1;
+ return true;
}
- } else if (target == *start) {
- return 1;
+ } else if (target == *pValue) {
+ return true;
}
- return 0;
+ return false;
}
-s32 Lib_StepTowardsCheck_c(s8* start, s8 target, s8 step) {
+s32 Math_StepToC(s8* pValue, s8 target, s8 step) {
if (step != 0) {
- if (target < *start) {
+ if (target < *pValue) {
step = -step;
}
- *start += step;
+ *pValue += step;
- if (((*start - target) * step) >= 0) {
- *start = target;
+ if (((*pValue - target) * step) >= 0) {
+ *pValue = target;
- return 1;
+ return true;
}
- } else if (target == *start) {
- return 1;
+ } else if (target == *pValue) {
+ return true;
}
- return 0;
+ return false;
}
-#ifdef NON_MATCHING
-s32 Lib_StepTowardsCheck_f(f32* start, f32 target, f32 step) {
- if (step != 0) {
- // XXX: regalloc is messed up
- if (target < *start) {
+s32 Math_StepToF(f32* pValue, f32 target, f32 step) {
+ if (step != 0.0f) {
+ if (target < *pValue) {
step = -step;
}
- *start += step;
+ *pValue += step;
- if (((*start - target) * step) >= 0) {
- *start = target;
+ if (((*pValue - target) * step) >= 0) {
+ *pValue = target;
- return 1;
+ return true;
}
- } else if (target != *start) {
- return 1;
+ } else if (target == *pValue) {
+ return true;
}
- return 0;
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_StepTowardsCheck_f.asm")
-#endif
-#ifdef NON_MATCHING
-s32 func_800FF0D0(s16* a0, s16 a1, s16 a2) {
- s32 v0 = *a0;
+s32 Math_StepUntilAngleS(s16* pValue, s16 target, s16 step) {
+ s16 orig = *pValue;
- // XXX: regalloc is messed up
- *a0 += a2;
+ *pValue += step;
- if (((*a0 - a1) * (v0 - a1)) <= 0) {
- *a0 = a1;
+ if (((s16)(*pValue - target) * (s16)(orig - target)) <= 0) {
+ *pValue = target;
- return 1;
+ return true;
}
- return 0;
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF0D0.asm")
-#endif
-#ifdef NON_MATCHING
-void func_800FF138() {
+s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step) {
+ s32 diff = target - *pValue;
+
+ if (diff < 0) {
+ step = -step;
+ }
+
+ if (diff > INT16_MAX) {
+ step = -step;
+ diff = -UINT16_MAX - -diff;
+ } else if (diff <= INT16_MIN) {
+ diff += UINT16_MAX;
+ step = -step;
+ }
+
+ if (step != 0) {
+ *pValue += step;
+
+ if ((diff * step) <= 0) {
+ *pValue = target;
+ return true;
+ }
+ } else if (target == *pValue) {
+ return true;
+ }
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF138.asm")
-#endif
-#ifdef NON_MATCHING
-void func_800FF1FC(void) {
+s32 Math_AsymStepToS(s16* pValue, s16 target, s16 incrStep, s16 decrStep) {
+ s16 step = ((target - *pValue) >= 0) ? incrStep : decrStep;
+
+ if (step != 0) {
+ if (target < *pValue) {
+ step = -step;
+ }
+ *pValue += step;
+
+ if (((*pValue - target) * step) >= 0) {
+ *pValue = target;
+ return true;
+ }
+ } else if (target == *pValue) {
+ return true;
+ }
+
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF1FC.asm")
-#endif
-#ifdef NON_MATCHING
-void func_800FF2A8(void) {
+s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step) {
+ f32 orig = *pValue;
+
+ *pValue += step;
+
+ if (((*pValue - limit) * (orig - limit)) <= 0) {
+ *pValue = limit;
+ return true;
+ }
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF2A8.asm")
-#endif
-#ifdef NON_MATCHING
-void func_800FF2F8(void) {
+s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep) {
+ f32 step = (target >= *pValue) ? incrStep : decrStep;
+
+ if (step != 0) {
+ if (target < *pValue) {
+ step = -step;
+ }
+
+ *pValue += step;
+
+ if (((*pValue - target) * step) >= 0) {
+ *pValue = target;
+ return true;
+ }
+ } else if (target == *pValue) {
+ return true;
+ }
+ return false;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF2F8.asm")
-#endif
+void func_800FF3A0(f32* distOut, s16* angleOut, Input* input) {
+ f32 x = input->rel.stick_x;
+ f32 y = input->rel.stick_y;
+ f32 dist;
-#ifdef NON_MATCHING
-void func_800FF3A0(void) {
+ dist = sqrtf(SQ(x) + SQ(y));
+ *distOut = (60.0f < dist) ? 60.0f : dist;
+ if (dist > 0.0f) {
+ x = input->cur.stick_x;
+ y = input->cur.stick_y;
+ *angleOut = Math_FAtan2F(y, -x);
+ } else {
+ *angleOut = 0;
+ }
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF3A0.asm")
-#endif
s16 Rand_S16Offset(s16 base, s16 range) {
return (s16)(Rand_ZeroOne() * range) + base;
}
-s16 Math_Rand_S16OffsetStride(s16 base, s16 stride, s16 range) {
+s16 Rand_S16OffsetStride(s16 base, s16 stride, s16 range) {
return (s16)(Rand_ZeroOne() * range) * stride + base;
}
@@ -302,194 +348,214 @@ void Math_Vec3f_SumScaled(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) {
dest->z = b->z * scale + a->z;
}
-void Math_Vec3f_ModifyRand(Vec3f* orig, f32 scale, Vec3f* dest) {
+void Math_Vec3f_AddRand(Vec3f* orig, f32 scale, Vec3f* dest) {
dest->x = randPlusMinusPoint5Scaled(scale) + orig->x;
dest->y = randPlusMinusPoint5Scaled(scale) + orig->y;
dest->z = randPlusMinusPoint5Scaled(scale) + orig->z;
}
-void Math_Vec3f_DistXYZAndStoreNormalizedDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) {
- f32 f0 = Math_Vec3f_DistXYZAndStoreDiff(a, b, dest);
- f32 f2;
+void Math_Vec3f_DistXYZAndStoreNormDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) {
+ f32 diff = Math_Vec3f_DistXYZAndStoreDiff(a, b, dest);
+ f32 normScale;
- if (f0 == 0) {
+ if (diff == 0) {
return;
}
- f2 = scale / f0;
+ normScale = scale / diff;
- dest->x *= f2;
- dest->y *= f2;
- dest->z *= f2;
+ dest->x *= normScale;
+ dest->y *= normScale;
+ dest->z *= normScale;
}
f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b) {
- Vec3f sp1C;
- Math_Vec3f_Diff(b, a, &sp1C);
- return sqrtf((sp1C.x * sp1C.x) + (sp1C.y * sp1C.y) + (sp1C.z * sp1C.z));
+ Vec3f diff;
+ Math_Vec3f_Diff(b, a, &diff);
+ return sqrtf(SQ(diff.x) + SQ(diff.y) + SQ(diff.z));
}
-f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* difference) {
- Math_Vec3f_Diff(b, a, difference);
- return sqrtf((difference->x * difference->x) + (difference->y * difference->y) + (difference->z * difference->z));
+f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest) {
+ Math_Vec3f_Diff(b, a, dest);
+ return sqrtf(SQ(dest->x) + SQ(dest->y) + SQ(dest->z));
}
f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b) {
f32 dx = b->x - a->x;
f32 dz = b->z - a->z;
- return sqrtf((dx * dx) + (dz * dz));
+ return sqrtf(SQ(dx) + SQ(dz));
}
-f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* xDiff, f32* zDiff) {
- *xDiff = b->x - a->x;
- *zDiff = b->z - a->z;
- return sqrtf((*xDiff * *xDiff) + (*zDiff * *zDiff));
+f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* dx, f32* dz) {
+ *dx = b->x - a->x;
+ *dz = b->z - a->z;
+ return sqrtf(SQ(*dx) + SQ(*dz));
}
-#ifdef NON_MATCHING
-void Math_Vec3f_PushAwayXZ(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) {
+f32 Math_Vec3f_StepToXZ(Vec3f* start, Vec3f* target, f32 speed) {
f32 sp24;
f32 sp20;
- f32 f0 = Math_Vec3f_DistXZAndStore(pusher, start, &sp24, &sp20);
- f32 f2 = f0 - distanceToApproach;
+ f32 f0 = Math_Vec3f_DistXZAndStore(target, start, &sp24, &sp20);
+ f32 f2 = f0 - speed;
+
+ if (speed > f0) {
+ f2 = 0.0f;
+ }
- if ((f0 >= distanceToApproach) && (f2 != 0)) {
- f2 /= f0;
+ if (f2 == 0.0f) {
+ f0 = 0.0f;
} else {
- f2 = 0;
+ f0 = f2 / f0;
}
- start->x = pusher->x + sp24 * f2;
- start->z = pusher->z + sp20 * f2;
+ start->x = target->x + sp24 * f0;
+ start->z = target->z + sp20 * f0;
+
+ return f2;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Math_Vec3f_PushAwayXZ.asm")
-#endif
f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b) {
return b->y - a->y;
}
-s16 Math_Vec3f_Yaw(Vec3f* from, Vec3f* to) {
- f32 f14 = to->x - from->x;
- f32 f12 = to->z - from->z;
+s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b) {
+ f32 f14 = b->x - a->x;
+ f32 f12 = b->z - a->z;
return Math_FAtan2F(f12, f14);
}
-s16 Math_Vec3f_Pitch(Vec3f* from, Vec3f* to) {
- return Math_FAtan2F(Math_Vec3f_DistXZ(from, to), from->y - to->y);
+s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b) {
+ return Math_FAtan2F(Math_Vec3f_DistXZ(a, b), a->y - b->y);
}
-void Actor_ProcessInitChain(Actor* actor, InitChainEntry* init) {
+void IChain_Apply_u8(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_s8(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_u16(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_s16(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_u32(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_s32(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_f32(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain);
+void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain);
+
+void (*sInitChainHandlers[])(u8* ptr, InitChainEntry* ichain) = {
+ IChain_Apply_u8, IChain_Apply_s8, IChain_Apply_u16, IChain_Apply_s16,
+ IChain_Apply_u32, IChain_Apply_s32, IChain_Apply_f32, IChain_Apply_f32div1000,
+ IChain_Apply_Vec3f, IChain_Apply_Vec3fdiv1000, IChain_Apply_Vec3s,
+};
+
+void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain) {
do {
- actorInitVarFuncs[init->type]((u8*)actor, init);
- } while ((init++)->cont);
+ sInitChainHandlers[ichain->type]((u8*)actor, ichain);
+ } while ((ichain++)->cont);
}
-void IChain_Apply_u8(u8* actor, InitChainEntry* init) {
- *(u8*)(actor + init->offset) = (u8)(init->value);
+void IChain_Apply_u8(u8* ptr, InitChainEntry* ichain) {
+ *(u8*)(ptr + ichain->offset) = (u8)(ichain->value);
}
-void IChain_Apply_s8(u8* actor, InitChainEntry* init) {
- *(u8*)(actor + init->offset) = (u8)(init->value);
+void IChain_Apply_s8(u8* ptr, InitChainEntry* ichain) {
+ *(u8*)(ptr + ichain->offset) = (u8)(ichain->value);
}
-void IChain_Apply_u16(u8* actor, InitChainEntry* init) {
- *(u16*)(actor + init->offset) = (u16)(init->value);
+void IChain_Apply_u16(u8* ptr, InitChainEntry* ichain) {
+ *(u16*)(ptr + ichain->offset) = (u16)(ichain->value);
}
-void IChain_Apply_s16(u8* actor, InitChainEntry* init) {
- *(u16*)(actor + init->offset) = (u16)(init->value);
+void IChain_Apply_s16(u8* ptr, InitChainEntry* ichain) {
+ *(u16*)(ptr + ichain->offset) = (u16)(ichain->value);
}
-void IChain_Apply_u32(u8* actor, InitChainEntry* init) {
- *(u32*)(actor + init->offset) = (u32)(init->value);
+void IChain_Apply_u32(u8* ptr, InitChainEntry* ichain) {
+ *(u32*)(ptr + ichain->offset) = (u32)(ichain->value);
}
-void IChain_Apply_s32(u8* actor, InitChainEntry* init) {
- *(u32*)(actor + init->offset) = (u32)(init->value);
+void IChain_Apply_s32(u8* ptr, InitChainEntry* ichain) {
+ *(u32*)(ptr + ichain->offset) = (u32)(ichain->value);
}
-void IChain_Apply_f32(u8* actor, InitChainEntry* init) {
- *(f32*)(actor + init->offset) = (f32)(init->value);
+void IChain_Apply_f32(u8* ptr, InitChainEntry* ichain) {
+ *(f32*)(ptr + ichain->offset) = (f32)(ichain->value);
}
-void IChain_Apply_f32div1000(u8* actor, InitChainEntry* init) {
- *(f32*)(actor + init->offset) = (f32)(init->value) / 1000;
+void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain) {
+ *(f32*)(ptr + ichain->offset) = (f32)(ichain->value) / 1000;
}
-void IChain_Apply_Vec3f(u8* actor, InitChainEntry* init) {
- Vec3f* v0 = (Vec3f*)(actor + init->offset);
- f32 f0 = (f32)(init->value);
+void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain) {
+ Vec3f* v0 = (Vec3f*)(ptr + ichain->offset);
+ f32 f0 = (f32)(ichain->value);
v0->z = f0;
v0->y = f0;
v0->x = f0;
}
-void IChain_Apply_Vec3fdiv1000(u8* actor, InitChainEntry* init) {
- Vec3f* v0 = (Vec3f*)(actor + init->offset);
- f32 f0 = (f32)(init->value) / 1000;
+void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain) {
+ Vec3f* v0 = (Vec3f*)(ptr + ichain->offset);
+ f32 f0 = (f32)(ichain->value) / 1000;
v0->z = f0;
v0->y = f0;
v0->x = f0;
}
-void IChain_Apply_Vec3s(u8* actor, InitChainEntry* init) {
- Vec3s* v0 = (Vec3s*)(actor + init->offset);
- s16 v1 = (s16)(init->value);
+void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain) {
+ Vec3s* v0 = (Vec3s*)(ptr + ichain->offset);
+ s16 v1 = (s16)(ichain->value);
v0->z = v1;
v0->y = v1;
v0->x = v1;
}
-f32 Math_SmoothScaleMaxMinF(f32* a0, f32 a1, f32 a2, f32 a3, f32 a4) {
- f32 f0;
+f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep) {
+ f32 stepSize;
- if (*a0 != a1) {
- f0 = (a1 - *a0) * a2;
+ if (*pValue != target) {
+ stepSize = (target - *pValue) * fraction;
- if ((f0 >= a4) || (f0 <= -a4)) {
- if (f0 > a3) {
- f0 = a3;
+ if ((stepSize >= minStep) || (stepSize <= -minStep)) {
+ if (stepSize > step) {
+ stepSize = step;
}
- if (f0 < -a3) {
- f0 = -a3;
+ if (stepSize < -step) {
+ stepSize = -step;
}
- *a0 += f0;
+ *pValue += stepSize;
} else {
- if (f0 > 0) {
- if (f0 < a4) {
- *a0 += a4;
+ if (stepSize > 0) {
+ if (stepSize < minStep) {
+ *pValue += minStep;
- if (a1 < *a0) {
- *a0 = a1;
+ if (target < *pValue) {
+ *pValue = target;
}
}
} else {
- if (-a4 < f0) {
- *a0 += -a4;
+ if (-minStep < stepSize) {
+ *pValue += -minStep;
- if (*a0 < a1) {
- *a0 = a1;
+ if (*pValue < target) {
+ *pValue = target;
}
}
}
}
}
- return fabsf(a1 - *a0);
+ return fabsf(target - *pValue);
}
-void Math_SmoothScaleMaxF(f32* start, f32 target, f32 scale, f32 maxStep) {
+void Math_ApproachF(f32* pValue, f32 target, f32 scale, f32 maxStep) {
f32 f2;
- if (*start != target) {
- f2 = (target - *start) * scale;
+ if (*pValue != target) {
+ f2 = (target - *pValue) * scale;
if (f2 > maxStep) {
f2 = maxStep;
@@ -497,12 +563,12 @@ void Math_SmoothScaleMaxF(f32* start, f32 target, f32 scale, f32 maxStep) {
f2 = -maxStep;
}
- *start += f2;
+ *pValue += f2;
}
}
-void Math_SmoothDownscaleMaxF(f32* start, f32 scale, f32 maxStep) {
- f32 f0 = *start * scale;
+void Math_ApproachZeroF(f32* pValue, f32 scale, f32 maxStep) {
+ f32 f0 = *pValue * scale;
if (maxStep < f0) {
f0 = maxStep;
@@ -510,32 +576,61 @@ void Math_SmoothDownscaleMaxF(f32* start, f32 scale, f32 maxStep) {
f0 = -maxStep;
}
- *start = *start - f0;
+ *pValue = *pValue - f0;
}
-#ifdef NON_MATCHING
-s32 Math_SmoothScaleMaxMinS(s16* start, s16 target, s16 scale, s16 maxStep, s16 minStep) {
+s32 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep) {
+ s16 stepSize = 0;
+ s16 diff = target - *pValue;
+
+ if (*pValue != target) {
+ stepSize = diff / scale;
+
+ if ((stepSize > minStep) || (stepSize < -minStep)) {
+ if (stepSize > step) {
+ stepSize = step;
+ }
+ if (stepSize < -step) {
+ stepSize = -step;
+ }
+
+ *pValue += stepSize;
+ } else {
+ if (diff >= 0) {
+ *pValue += minStep;
+
+ if ((s16)(target - *pValue) <= 0) {
+ *pValue = target;
+ }
+ } else {
+ *pValue -= minStep;
+
+ if ((s16)(target - *pValue) >= 0) {
+ *pValue = target;
+ }
+ }
+ }
+ }
+
+ return diff;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Math_SmoothScaleMaxMinS.asm")
-#endif
-void Math_SmoothScaleMaxS(s16* start, s16 target, s16 scale, s16 maxStep) {
- s16 v0 = target - *start;
- v0 /= scale;
+void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 maxStep) {
+ s16 diff = target - *pValue;
+ diff /= scale;
- if (v0 > maxStep) {
- *start += maxStep;
+ if (diff > maxStep) {
+ *pValue += maxStep;
return;
}
- if (v0 < -maxStep) {
- *start -= maxStep;
+ if (diff < -maxStep) {
+ *pValue -= maxStep;
return;
}
- *start += v0;
+ *pValue += diff;
}
void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src) {
@@ -545,55 +640,55 @@ void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src) {
dst->a = src->a;
}
-void func_801000A4(u16 a0) {
- play_sound(a0);
+void func_801000A4(u16 sfxId) {
+ play_sound(sfxId);
}
-void func_801000CC(u16 a0) {
- func_8019F128(a0);
+void func_801000CC(u16 sfxId) {
+ func_8019F128(sfxId);
}
void func_801000F4(s32 a0, u16 a1) {
func_8019F1C0(a0, a1);
}
-void Lib_TranslateAndRotateYVec3f(Vec3f* translation, s16 rotation, Vec3f* src, Vec3f* dst) {
+void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 a, Vec3f* src, Vec3f* dst) {
f32 sp1C;
f32 f0;
- sp1C = Math_CosS(rotation);
- f0 = Math_SinS(rotation);
+ sp1C = Math_CosS(a);
+ f0 = Math_SinS(a);
dst->x = translation->x + (src->x * sp1C + src->z * f0);
dst->y = translation->y + src->y;
dst->z = translation->z + (src->z * sp1C - src->x * f0);
}
-#ifdef NON_MATCHING
void Lib_LerpRGB(Color_RGB8* a, Color_RGB8* b, f32 t, Color_RGB8* dst) {
- // XXX regalloc is slightly off
- dst->r = (f32)a->r + ((f32)b->r - (f32)a->r) * t;
- dst->g = (f32)a->g + ((f32)b->g - (f32)a->g) * t;
- dst->b = (f32)a->b + ((f32)b->b - (f32)a->b) * t;
+ f32 aF;
+
+ aF = a->r;
+ dst->r = aF + (b->r - aF) * t;
+ aF = a->g;
+ dst->g = aF + (b->g - aF) * t;
+ aF = a->b;
+ dst->b = aF + (b->b - aF) * t;
}
-#else
-#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_LerpRGB.asm")
-#endif
-f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) {
- Vec3f sp24;
+f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed) {
+ Vec3f diff;
f32 f2;
f32 f0;
- Math_Vec3f_Diff(pusher, start, &sp24);
- f0 = Math3D_Vec3fMagnitude(&sp24);
- if (distanceToApproach < f0) {
- f2 = distanceToApproach / f0;
- f0 = f0 - distanceToApproach;
- start->x = start->x + f2 * sp24.x;
- start->y = start->y + f2 * sp24.y;
- start->z = start->z + f2 * sp24.z;
+ Math_Vec3f_Diff(target, start, &diff);
+ f0 = Math3D_Vec3fMagnitude(&diff);
+ if (speed < f0) {
+ f2 = speed / f0;
+ f0 = f0 - speed;
+ start->x = start->x + f2 * diff.x;
+ start->y = start->y + f2 * diff.y;
+ start->z = start->z + f2 * diff.z;
} else {
- Math_Vec3f_Copy(start, pusher);
+ Math_Vec3f_Copy(start, target);
f0 = 0;
}
@@ -602,20 +697,19 @@ f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) {
void Lib_Nop801004FC(void) {}
-void* Lib_PtrSegToVirt(void* ptr) {
+void* Lib_SegmentedToVirtual(void* ptr) {
return SEGMENTED_TO_VIRTUAL(ptr);
}
-void* Lib_PtrSegToVirtNull(void* ptr) {
- // UB: to cast the pointer to u32 in order to bitshift.
- if (((u32)ptr >> 28) == 0) {
+void* Lib_SegmentedToVirtualNull(void* ptr) {
+ if (((uintptr_t)ptr >> 28) == 0) {
return ptr;
}
return SEGMENTED_TO_VIRTUAL(ptr);
}
-void* Lib_PtrSegToK0(void* ptr) {
+void* Lib_PhysicalToVirtual(void* ptr) {
if (ptr == NULL) {
return NULL;
} else {
@@ -623,7 +717,7 @@ void* Lib_PtrSegToK0(void* ptr) {
}
}
-void* Lib_PtrSegToK0Null(void* ptr) {
+void* Lib_PhysicalToVirtualNull(void* ptr) {
if (ptr == NULL) {
return NULL;
} else {
diff --git a/src/code/z_room.c b/src/code/z_room.c
index 04842eeb6..0e6b1afe3 100644
--- a/src/code/z_room.c
+++ b/src/code/z_room.c
@@ -28,7 +28,7 @@ void Room_DrawType0Mesh(GlobalContext* ctxt, Room* room, u32 flags) {
}
mesh = &room->mesh->type0;
- meshParams = (RoomMeshType0Params*)Lib_PtrSegToVirt(mesh->paramsStart);
+ meshParams = (RoomMeshType0Params*)Lib_SegmentedToVirtual(mesh->paramsStart);
for (i = 0; i < mesh->count; i++) {
if ((flags & 1) && (meshParams->opaqueDl != NULL)) {
gSPDisplayList(gfxCtx->polyOpa.p++, meshParams->opaqueDl);
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index 671f60447..496c8ca7a 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -157,7 +157,7 @@ void Scene_HeaderCommand00(GlobalContext* ctxt, SceneCmd* entry) {
s16 temp16;
u8 unk20;
- ctxt->linkActorEntry = (ActorEntry*)Lib_PtrSegToVirt(entry->spawnList.segment) +
+ ctxt->linkActorEntry = (ActorEntry*)Lib_SegmentedToVirtual(entry->spawnList.segment) +
ctxt->setupEntranceList[ctxt->curSpawn].spawn;
if ( (ctxt->linkActorEntry->params & 0x0F00) >> 8 == 0x0C ||
(gSaveContext.extra.unk10 == 0x02 && gSaveContext.extra.unk42 == 0x0CFF)
@@ -181,13 +181,13 @@ void Scene_HeaderCommand00(GlobalContext* ctxt, SceneCmd* entry) {
// Scene Command 0x01: Actor List
void Scene_HeaderCommand01(GlobalContext* ctxt, SceneCmd* entry) {
ctxt->sceneNumActorsToLoad = (u16)entry->actorList.num;
- ctxt->setupActorList = (ActorEntry*)Lib_PtrSegToVirt(entry->actorList.segment);
+ ctxt->setupActorList = (ActorEntry*)Lib_SegmentedToVirtual(entry->actorList.segment);
ctxt->actorCtx.unkC = (u16)0;
}
// Scene Command 0x02: Cutscene Camera List
void Scene_HeaderCommand02(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->unk18858 = (UNK_PTR)Lib_PtrSegToVirt(entry->csCameraList.segment);
+ ctxt->unk18858 = (UNK_PTR)Lib_SegmentedToVirtual(entry->csCameraList.segment);
}
// Scene Command 0x03: Collision Header
@@ -195,18 +195,18 @@ void Scene_HeaderCommand03(GlobalContext* ctxt, SceneCmd* entry) {
BgMeshHeader* temp_ret;
BgMeshHeader* temp_s0;
- temp_ret = (BgMeshHeader*)Lib_PtrSegToVirt(entry->colHeader.segment);
+ temp_ret = (BgMeshHeader*)Lib_SegmentedToVirtual(entry->colHeader.segment);
temp_s0 = temp_ret;
- temp_s0->vertices = (BgVertex*)Lib_PtrSegToVirt(temp_ret->vertices);
- temp_s0->polygons = (CollisionPoly*)Lib_PtrSegToVirt(temp_s0->polygons);
+ temp_s0->vertices = (BgVertex*)Lib_SegmentedToVirtual(temp_ret->vertices);
+ temp_s0->polygons = (CollisionPoly*)Lib_SegmentedToVirtual(temp_s0->polygons);
if (temp_s0->attributes != 0) {
- temp_s0->attributes = (BgPolygonAttributes*)Lib_PtrSegToVirt(temp_s0->attributes);
+ temp_s0->attributes = (BgPolygonAttributes*)Lib_SegmentedToVirtual(temp_s0->attributes);
}
if (temp_s0->cameraData != 0) {
- temp_s0->cameraData = (void*)Lib_PtrSegToVirt(temp_s0->cameraData);
+ temp_s0->cameraData = (void*)Lib_SegmentedToVirtual(temp_s0->cameraData);
}
if (temp_s0->waterboxes != 0) {
- temp_s0->waterboxes = (BgWaterBox*)Lib_PtrSegToVirt(temp_s0->waterboxes);
+ temp_s0->waterboxes = (BgWaterBox*)Lib_SegmentedToVirtual(temp_s0->waterboxes);
}
BgCheck_Init(&ctxt->colCtx, ctxt, temp_s0);
@@ -215,12 +215,12 @@ void Scene_HeaderCommand03(GlobalContext* ctxt, SceneCmd* entry) {
// Scene Command 0x04: Room List
void Scene_HeaderCommand04(GlobalContext* ctxt, SceneCmd* entry) {
ctxt->numRooms = entry->roomList.num;
- ctxt->roomList = (RoomFileLocation*)Lib_PtrSegToVirt(entry->roomList.segment);
+ ctxt->roomList = (RoomFileLocation*)Lib_SegmentedToVirtual(entry->roomList.segment);
}
// Scene Command 0x06: Entrance List
void Scene_HeaderCommand06(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->setupEntranceList = (EntranceEntry*)Lib_PtrSegToVirt(entry->entranceList.segment);
+ ctxt->setupEntranceList = (EntranceEntry*)Lib_SegmentedToVirtual(entry->entranceList.segment);
}
// Scene Command 0x07: Special Files
@@ -250,7 +250,7 @@ void Scene_HeaderCommand08(GlobalContext* ctxt, SceneCmd* entry) {
// Scene Command 0x0A: Mesh Header
void Scene_HeaderCommand0A(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->roomContext.currRoom.mesh = (RoomMesh*)Lib_PtrSegToVirt(entry->mesh.segment);
+ ctxt->roomContext.currRoom.mesh = (RoomMesh*)Lib_SegmentedToVirtual(entry->mesh.segment);
}
// Scene Command 0x0B: Object List
@@ -262,7 +262,7 @@ void Scene_HeaderCommand0B(GlobalContext *ctxt, SceneCmd *entry) {
s16* objectEntry;
void* nextPtr;
- objectEntry = (s16*)Lib_PtrSegToVirt(entry->objectList.segment);
+ objectEntry = (s16*)Lib_SegmentedToVirtual(entry->objectList.segment);
k = 0;
i = ctxt->sceneContext.spawnedObjectCount;
status = &ctxt->sceneContext.objects[i];
@@ -307,7 +307,7 @@ void Scene_HeaderCommand0C(GlobalContext* ctxt, SceneCmd* entry) {
s32 i;
LightInfo* lightInfo;
- lightInfo = (LightInfo*)Lib_PtrSegToVirt(entry->lightList.segment);
+ lightInfo = (LightInfo*)Lib_SegmentedToVirtual(entry->lightList.segment);
for (i = 0; i < entry->lightList.num; i++)
{
LightContext_InsertLight(ctxt, &ctxt->lightCtx, lightInfo);
@@ -317,13 +317,13 @@ void Scene_HeaderCommand0C(GlobalContext* ctxt, SceneCmd* entry) {
// Scene Command 0x0D: Path List
void Scene_HeaderCommand0D(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->setupPathList = (void*)Lib_PtrSegToVirt(entry->pathList.segment);
+ ctxt->setupPathList = (void*)Lib_SegmentedToVirtual(entry->pathList.segment);
}
// Scene Command 0x0E: Transition Actor List
void Scene_HeaderCommand0E(GlobalContext* ctxt, SceneCmd* entry) {
ctxt->transitionActorCount = entry->transiActorList.num;
- ctxt->transitionActorList = (TransitionActorEntry*)Lib_PtrSegToVirt((void*)entry->transiActorList.segment);
+ ctxt->transitionActorList = (TransitionActorEntry*)Lib_SegmentedToVirtual((void*)entry->transiActorList.segment);
func_80105818(ctxt, ctxt->transitionActorCount, ctxt->transitionActorList);
}
@@ -334,7 +334,7 @@ void func_8012FEBC(GlobalContext* ctxt, u8* nbTransitionActors) {
// Scene Command 0x0F: Light Setting List
void Scene_HeaderCommand0F(GlobalContext* ctxt, SceneCmd* entry) {
ctxt->kankyoContext.environmentSettingsCount = entry->lightSettingList.num;
- ctxt->kankyoContext.environmentSettingsList = (void*)Lib_PtrSegToVirt(entry->lightSettingList.segment);
+ ctxt->kankyoContext.environmentSettingsList = (void*)Lib_SegmentedToVirtual(entry->lightSettingList.segment);
}
s32 func_8012FF10(GlobalContext* ctxt, s32 fileIndex) {
@@ -423,7 +423,7 @@ void Scene_HeaderCommand05(GlobalContext* ctxt, SceneCmd* entry) {
}
void Scene_HeaderCommand13(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->setupExitList = (void*)Lib_PtrSegToVirt(entry->exitList.segment);
+ ctxt->setupExitList = (void*)Lib_SegmentedToVirtual(entry->exitList.segment);
}
// Scene Command 0x09: Undefined
@@ -450,10 +450,10 @@ void Scene_HeaderCommand18(GlobalContext* ctxt, SceneCmd* entry) {
SceneCmd** altHeaderList;
SceneCmd* altHeader;
if (gSaveContext.extra.sceneSetupIndex) {
- altHeaderList = (SceneCmd**)Lib_PtrSegToVirt(entry->altHeaders.segment);
+ altHeaderList = (SceneCmd**)Lib_SegmentedToVirtual(entry->altHeaders.segment);
altHeader = altHeaderList[gSaveContext.extra.sceneSetupIndex - 1];
if (altHeader != NULL) {
- Scene_ProcessHeader(ctxt, (SceneCmd*)Lib_PtrSegToVirt(altHeader));
+ Scene_ProcessHeader(ctxt, (SceneCmd*)Lib_SegmentedToVirtual(altHeader));
(entry + 1)->base.code = 0x14;
}
}
@@ -462,12 +462,12 @@ void Scene_HeaderCommand18(GlobalContext* ctxt, SceneCmd* entry) {
// Scene Command 0x17: Cutscene Data
void Scene_HeaderCommand17(GlobalContext* ctxt, SceneCmd* entry) {
ctxt->csCtx.cutsceneCount = (u8)entry->base.data1;
- ctxt->cutsceneList = (CutsceneEntry*)Lib_PtrSegToVirt((void*)entry->base.data2);
+ ctxt->cutsceneList = (CutsceneEntry*)Lib_SegmentedToVirtual((void*)entry->base.data2);
}
// Scene Command 0x1B: Cutscene Actor List
void Scene_HeaderCommand1B(GlobalContext* ctxt, SceneCmd* entry) {
- ActorCutscene_Init(ctxt, (ActorCutscene*)Lib_PtrSegToVirt(entry->cutsceneActorList.segment),
+ ActorCutscene_Init(ctxt, (ActorCutscene*)Lib_SegmentedToVirtual(entry->cutsceneActorList.segment),
entry->cutsceneActorList.num);
}
@@ -521,7 +521,7 @@ void Scene_HeaderCommand19(GlobalContext *ctxt, SceneCmd *entry) {
// Scene Command 0x1A: Texture Animations
void Scene_HeaderCommand1A(GlobalContext* ctxt, SceneCmd* entry) {
- ctxt->sceneTextureAnimations = (AnimatedTexture*)Lib_PtrSegToVirt(entry->textureAnimations.segment);
+ ctxt->sceneTextureAnimations = (AnimatedTexture*)Lib_SegmentedToVirtual(entry->textureAnimations.segment);
}
void func_801306A4(GlobalContext *ctxt) {
diff --git a/src/code/z_scene_proc.c b/src/code/z_scene_proc.c
index 9dea984ea..6d235616c 100644
--- a/src/code/z_scene_proc.c
+++ b/src/code/z_scene_proc.c
@@ -109,14 +109,14 @@ void SceneProc_DrawFlashingTexture(GlobalContext* ctxt, u32 segment, FlashingTex
void SceneProc_DrawType2Texture(GlobalContext* ctxt, u32 segment, FlashingTextureParams* params) {
Color_RGBA8* envColor;
- FlashingTexturePrimColor* primColor = (FlashingTexturePrimColor *)Lib_PtrSegToVirt(params->primColors);
+ FlashingTexturePrimColor* primColor = (FlashingTexturePrimColor *)Lib_SegmentedToVirtual(params->primColors);
u32 pad;
u32 index = gSceneProcStep % params->cycleLength;
primColor += index;
if (params->envColors) {
- envColor = (Color_RGBA8*)Lib_PtrSegToVirt(params->envColors) + index;
+ envColor = (Color_RGBA8*)Lib_SegmentedToVirtual(params->envColors) + index;
} else {
envColor = NULL;
}
@@ -133,8 +133,8 @@ s32 SceneProc_Lerp(s32 a, s32 b, f32 t) {
void SceneProc_DrawType3Texture(GlobalContext* ctxt, u32 segment, FlashingTextureParams* params) {
FlashingTextureParams* params2 = params;
Color_RGBA8* envColorTo;
- FlashingTexturePrimColor* primColorTo = (FlashingTexturePrimColor *)Lib_PtrSegToVirt(params2->primColors);
- u16* keyFrames = (u16*)Lib_PtrSegToVirt(params2->keyFrames);
+ FlashingTexturePrimColor* primColorTo = (FlashingTexturePrimColor *)Lib_SegmentedToVirtual(params2->primColors);
+ u16* keyFrames = (u16*)Lib_SegmentedToVirtual(params2->keyFrames);
s32 index = gSceneProcStep % params2->cycleLength;
s32 pad1;
s32 keyFrameIndex;
@@ -169,7 +169,7 @@ void SceneProc_DrawType3Texture(GlobalContext* ctxt, u32 segment, FlashingTextur
primColorIn.lodFrac = SceneProc_Lerp(primColorFrom->lodFrac, primColorTo->lodFrac, t);
if (params2->envColors) {
- envColorTo = (Color_RGBA8*)Lib_PtrSegToVirt(params2->envColors) + keyFrameIndex;
+ envColorTo = (Color_RGBA8*)Lib_SegmentedToVirtual(params2->envColors) + keyFrameIndex;
envColorFrom = envColorTo - 1;
envColorIn.red = SceneProc_Lerp(envColorFrom->red, envColorTo->red, t);
envColorIn.green = SceneProc_Lerp(envColorFrom->green, envColorTo->green, t);
@@ -210,10 +210,10 @@ void SceneProc_DrawType5Texture(GlobalContext* ctxt, u32 segment, CyclingTexture
GraphicsContext* gfxCtx;
s32 step;
- dls = (Gfx**)Lib_PtrSegToVirt(params->textureDls);
- offsets = (u8*)Lib_PtrSegToVirt(params->textureDlOffsets);
+ dls = (Gfx**)Lib_SegmentedToVirtual(params->textureDls);
+ offsets = (u8*)Lib_SegmentedToVirtual(params->textureDlOffsets);
step = gSceneProcStep % params->cycleLength;
- dl = (Gfx*)Lib_PtrSegToVirt(dls[offsets[step]]);
+ dl = (Gfx*)Lib_SegmentedToVirtual(dls[offsets[step]]);
gfxCtx = ctxt->state.gfxCtx;
if (gSceneProcFlags & 1) {
@@ -239,7 +239,7 @@ void SceneProc_DrawAnimatedTextures(GlobalContext* ctxt, AnimatedTexture* textur
segment = textures->segment;
segmentAbs = ((segment < 0)? -segment : segment) + 7;
- gSceneProcDrawFuncs[textures->type](ctxt, segmentAbs, (void*)Lib_PtrSegToVirt(textures->params));
+ gSceneProcDrawFuncs[textures->type](ctxt, segmentAbs, (void*)Lib_SegmentedToVirtual(textures->params));
textures++;
} while (segment > -1);
diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c
index 09ac2403c..85e8f3f67 100644
--- a/src/code/z_skelanime.c
+++ b/src/code/z_skelanime.c
@@ -39,7 +39,7 @@ void SkelAnime_LodDrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk
s32 pad;
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -98,7 +98,7 @@ void SkelAnime_LodDraw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
pos.z = limbDrawTable[0].z;
@@ -147,7 +147,7 @@ void SkelAnime_LodDrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton*
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -217,7 +217,7 @@ void SkelAnime_LodDrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* li
gSPSegment(gfxCtx->polyOpa.p++, 0xD, mtx);
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
pos.z = limbDrawTable[0].z;
@@ -268,7 +268,7 @@ void SkelAnime_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skele
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
pos.x = limbEntry->translation.x;
@@ -321,7 +321,7 @@ void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDra
gfxCtx = globalCtx->state.gfxCtx;
Matrix_Push();
- rootLimb = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ rootLimb = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
@@ -365,7 +365,7 @@ void SkelAnime_DrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* ske
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -429,7 +429,7 @@ void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbD
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
@@ -480,7 +480,7 @@ void func_80134148(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton,
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -551,7 +551,7 @@ void func_801343C0(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDraw
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
@@ -598,9 +598,9 @@ void func_801343C0(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDraw
* rotation value list, otherwise it is copied from the initial rotation value list
*/
void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32 limbCount, Vec3s* dst) {
- AnimationHeader* animationHeader = Lib_PtrSegToVirt(animationSeg);
- AnimationRotationIndex* index = Lib_PtrSegToVirt(animationHeader->rotationIndexSeg);
- AnimationRotationValue* rotationValueTable = Lib_PtrSegToVirt(animationHeader->rotationValueSeg);
+ AnimationHeader* animationHeader = Lib_SegmentedToVirtual(animationSeg);
+ AnimationRotationIndex* index = Lib_SegmentedToVirtual(animationHeader->rotationIndexSeg);
+ AnimationRotationValue* rotationValueTable = Lib_SegmentedToVirtual(animationHeader->rotationValueSeg);
AnimationRotationValue* frameRotationValueTable = &rotationValueTable[currentFrame];
s32 i;
u16 limit = animationHeader->limit;
@@ -618,12 +618,12 @@ void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32
}
s16 SkelAnime_GetTotalFrames(GenericAnimationHeader* animationSeg) {
- GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg);
+ GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg);
return animation->frameCount;
}
s16 SkelAnime_GetFrameCount(GenericAnimationHeader* animationSeg) {
- GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg);
+ GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg);
return (u16)animation->frameCount - 1;
}
@@ -641,7 +641,7 @@ Gfx* SkelAnime_Draw2Limb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skel
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -697,7 +697,7 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
@@ -744,7 +744,7 @@ Gfx* SkelAnime_DrawLimbSV2(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]);
limbIndex++;
rot = limbDrawTable[limbIndex];
@@ -808,7 +808,7 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb
Matrix_Push();
- limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]);
+ limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]);
pos.x = limbDrawTable[0].x;
pos.y = limbDrawTable[0].y;
@@ -851,7 +851,7 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_skelanime/func_80134FFC.asm")
s16 func_801353D4(GenericAnimationHeader* animationSeg) {
- GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg);
+ GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg);
return animation->unk02;
}
@@ -861,7 +861,7 @@ s16 func_801353D4(GenericAnimationHeader* animationSeg) {
* SkelAnime_GetTotalFrames
*/
s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) {
- GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg);
+ GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg);
return animation->frameCount;
}
@@ -871,7 +871,7 @@ s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) {
* SkelAnime_GetFrameCount
*/
s16 SkelAnime_GetFrameCount2(GenericAnimationHeader* animationSeg) {
- GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg);
+ GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg);
return animation->frameCount - 1;
}
@@ -941,7 +941,7 @@ void SkelAnime_LoadLinkAnimetion(GlobalContext* globalCtx, LinkAnimetionEntry* l
entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_LINKANIMETION);
if (entry != NULL) {
- linkAnimetionEntry = Lib_PtrSegToVirt(linkAnimetionSeg);
+ linkAnimetionEntry = Lib_SegmentedToVirtual(linkAnimetionSeg);
osCreateMesgQueue(&entry->types.type0.msgQueue, &entry->types.type0.msg, 1);
DmaMgr_SendRequestImpl(
&entry->types.type0.req, ram,
@@ -1096,7 +1096,7 @@ void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime,
s32 limbCount;
u32 allocSize;
- skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg);
+ skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg);
headerCount = skeletonHeader->limbCount;
skelAnime->initFlags = flags;
limbCount = (flags & 2) ? headerCount : 1;
@@ -1111,7 +1111,7 @@ void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime,
skelAnime->limbCount = limbCount;
skelAnime->dListCount = skeletonHeader->dListCount;
- skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg);
+ skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg);
allocSize = sizeof(Vec3s) * limbCount;
if (flags & 8) {
@@ -1363,9 +1363,9 @@ void SkelAnime_Init(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHead
AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) {
SkeletonHeader* skeletonHeader;
- skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg);
+ skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg);
skelAnime->limbCount = skeletonHeader->limbCount + 1;
- skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg);
+ skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg);
if (limbDrawTbl == NULL) {
skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount);
skelAnime->transitionDrawTbl = zelda_malloc(sizeof(*skelAnime->transitionDrawTbl) * skelAnime->limbCount);
@@ -1383,10 +1383,10 @@ void SkelAnime_InitSV(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHe
AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) {
SkeletonHeader* skeletonHeader;
- skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg);
+ skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg);
skelAnime->limbCount = skeletonHeader->limbCount + 1;
skelAnime->dListCount = skeletonHeader->dListCount;
- skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg);
+ skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg);
if (limbDrawTbl == NULL) {
skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount);
@@ -1406,9 +1406,9 @@ void SkelAnime_InitSkin(GlobalContext* globalCtx, SkelAnime* skelAnime, Skeleton
AnimationHeader* animationSeg) {
SkeletonHeader* skeletonHeader;
- skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg);
+ skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg);
skelAnime->limbCount = skeletonHeader->limbCount + 1;
- skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg);
+ skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg);
skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount);
skelAnime->transitionDrawTbl = zelda_malloc(sizeof(*skelAnime->transitionDrawTbl) * skelAnime->limbCount);