summaryrefslogtreecommitdiff
path: root/src/code/z_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/code/z_lib.c')
-rw-r--r--src/code/z_lib.c590
1 files changed, 342 insertions, 248 deletions
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 {