2020-03-17 04:31:30 +00:00
|
|
|
#include <ultra64.h>
|
|
|
|
#include <global.h>
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Lib_MemSet(u8* dest, size_t size, u8 val) {
|
2020-03-20 00:25:53 +00:00
|
|
|
u32 i = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-20 00:25:53 +00:00
|
|
|
// TODO: Convert this to while/for if possible
|
2020-03-22 21:19:43 +00:00
|
|
|
if (i == size) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-19 21:48:38 +00:00
|
|
|
do {
|
|
|
|
*dest++ = val;
|
|
|
|
i++;
|
|
|
|
} while (i != size);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Coss(s16 angle) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return coss(angle) * (1.0f / 32767);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Sins(s16 angle) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return sins(angle) * (1.0f / 32767);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 Math_ApproxUpdateScaledS(s16* pValue, s16 target, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 updateScale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
updateScale = R_UPDATE_RATE * 0.5f;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((s16)(*pValue - target) > 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += (s16)(step * updateScale);
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((s16)(*pValue - target) * step) >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 Math_ApproxS(s16* pValue, s16 target, s16 step) {
|
|
|
|
if (step != 0) {
|
|
|
|
if (target < *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((*pValue - target) * step) >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 Math_ApproxF(f32* pValue, f32 target, f32 step) {
|
|
|
|
if (step != 0.0f) {
|
|
|
|
if (target < *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((*pValue - target) * step) >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 func_80077A90(s16* pValue, s16 target, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((s16)(*pValue - target) * (s16)(orig - target)) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 func_80077AF8(s16* pValue, s16 target, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((*pValue - target) * ((s16)orig - target)) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 func_80077B58(s16* pValue, s16 target, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 phi_v0 = target - *pValue;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (phi_v0 < 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (phi_v0 >= 0x8000) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
|
|
|
phi_v0 = 0xFFFF0001 - -phi_v0;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (phi_v0 <= -0x8000) {
|
2020-03-17 04:31:30 +00:00
|
|
|
phi_v0 += 0xFFFF;
|
|
|
|
step = -step;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((phi_v0 * step) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 func_80077C1C(f32* pValue, f32 target, f32 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((*pValue - target) * (orig - target)) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s32 func_80077C6C(f32* pValue, f32 target, f32 incrStep, f32 decrStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 step = (target >= *pValue) ? incrStep : decrStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step != 0.0f) {
|
|
|
|
if (target < *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (((*pValue - target) * step) >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
typedef struct {
|
2020-03-17 04:31:30 +00:00
|
|
|
/* 0x00 */ char unk_00[0x14];
|
2020-03-22 21:19:43 +00:00
|
|
|
/* 0x14 */ s8 unk_14;
|
|
|
|
/* 0x14 */ s8 unk_15;
|
2020-03-17 04:31:30 +00:00
|
|
|
} struct_80077D10;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_80077D10(f32* arg0, s16* arg1, struct_80077D10* arg2) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 var1 = arg2->unk_14;
|
|
|
|
f32 var2 = arg2->unk_15;
|
|
|
|
|
|
|
|
*arg0 = sqrtf(SQ(var1) + SQ(var2));
|
|
|
|
*arg0 = (60.0f < *arg0) ? 60.0f : *arg0;
|
|
|
|
|
|
|
|
*arg1 = atan2s(var2, -var1);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_Rand_S16Offset(s16 base, s16 range) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return (s16)(Math_Rand_ZeroOne() * range) + base;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_Rand_S16OffsetStride(s16 base, s16 stride, s16 range) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return (s16)(Math_Rand_ZeroOne() * range) * stride + base;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3f_Copy(Vec3f* dest, Vec3f* src) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = src->x;
|
|
|
|
dest->y = src->y;
|
|
|
|
dest->z = src->z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3s_ToVec3f(Vec3f* dest, Vec3s* src) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = src->x;
|
|
|
|
dest->y = src->y;
|
|
|
|
dest->z = src->z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3f_Sum(Vec3f* a, Vec3f* b, Vec3f* dest) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = a->x + b->x;
|
|
|
|
dest->y = a->y + b->y;
|
|
|
|
dest->z = a->z + b->z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3f_Diff(Vec3f* a, Vec3f* b, Vec3f* dest) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = a->x - b->x;
|
|
|
|
dest->y = a->y - b->y;
|
|
|
|
dest->z = a->z - b->z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3s_DiffToVec3f(Vec3f* dest, Vec3s* a, Vec3s* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = a->x - b->x;
|
|
|
|
dest->y = a->y - b->y;
|
|
|
|
dest->z = a->z - b->z;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_Vec3f_Scale(Vec3f* vec, f32 scaleF) {
|
2020-03-17 04:31:30 +00:00
|
|
|
vec->x *= scaleF;
|
|
|
|
vec->y *= scaleF;
|
|
|
|
vec->z *= scaleF;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 dx = b->x - a->x;
|
|
|
|
f32 dy = b->y - a->y;
|
|
|
|
f32 dz = b->z - a->z;
|
|
|
|
|
|
|
|
return sqrtf(SQ(dx) + SQ(dy) + SQ(dz));
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->x = b->x - a->x;
|
|
|
|
dest->y = b->y - a->y;
|
|
|
|
dest->z = b->z - a->z;
|
|
|
|
|
|
|
|
return sqrtf(SQ(dest->x) + SQ(dest->y) + SQ(dest->z));
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 dx = b->x - a->x;
|
|
|
|
f32 dz = b->z - a->z;
|
|
|
|
|
|
|
|
return sqrtf(SQ(dx) + SQ(dz));
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return b->y - a->y;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 dx = b->x - a->x;
|
|
|
|
f32 dz = b->z - a->z;
|
|
|
|
|
|
|
|
return atan2s(dz, dx);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return atan2s(Math_Vec3f_DistXZ(a, b), a->y - b->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
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,
|
2020-03-17 04:31:30 +00:00
|
|
|
};
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain) {
|
|
|
|
do {
|
|
|
|
sInitChainHandlers[ichain->type]((u8*)actor, ichain);
|
|
|
|
} while ((ichain++)->cont);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_u8(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(u8*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_s8(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(s8*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_u16(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(u16*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_s16(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(s16*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_u32(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(u32*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_s32(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(s32*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_f32(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(f32*)(ptr + ichain->offset) = ichain->value;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*(f32*)(ptr + ichain->offset) = ichain->value / 1000.0f;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Vec3f* vec;
|
|
|
|
f32 val;
|
|
|
|
|
|
|
|
vec = (Vec3f*)(ptr + ichain->offset);
|
|
|
|
val = ichain->value;
|
|
|
|
|
|
|
|
vec->z = val;
|
|
|
|
vec->y = val;
|
|
|
|
vec->x = val;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Vec3f* vec;
|
|
|
|
f32 val;
|
|
|
|
|
|
|
|
vec = (Vec3f*)(ptr + ichain->offset);
|
|
|
|
osSyncPrintf("pp=%x data=%f\n", vec, (f64)(ichain->value / 1000.0f));
|
|
|
|
val = ichain->value / 1000.0f;
|
|
|
|
|
|
|
|
vec->z = val;
|
|
|
|
vec->y = val;
|
|
|
|
vec->x = val;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Vec3s* vec;
|
|
|
|
s16 val;
|
|
|
|
|
|
|
|
vec = (Vec3s*)(ptr + ichain->offset);
|
|
|
|
val = ichain->value;
|
|
|
|
|
|
|
|
vec->z = val;
|
|
|
|
vec->y = val;
|
|
|
|
vec->x = val;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 Math_SmoothScaleMaxMinF(f32* pValue, f32 target, f32 scale, f32 maxStep, f32 minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 var;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
var = (target - *pValue) * scale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((var >= minStep) || (var <= -minStep)) {
|
|
|
|
if (var > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
var = maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (var < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
var = -maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += var;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
|
|
|
if (var < minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += minStep;
|
|
|
|
var = minStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (target < *pValue) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
if (var > -minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += -minStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue < target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fabsf(target - *pValue);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_SmoothScaleMaxF(f32* pValue, f32 target, f32 scale, f32 maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 step;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = (target - *pValue) * scale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (step < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_SmoothDownscaleMaxF(f32* pValue, f32 scale, f32 maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 step;
|
|
|
|
|
|
|
|
step = *pValue * scale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (step < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue -= step;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
f32 func_800784D8(f32* pValue, f32 target, f32 scale, f32 maxStep, f32 minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 step;
|
|
|
|
f32 baseStep;
|
|
|
|
|
|
|
|
step = 0.0f;
|
|
|
|
baseStep = target - *pValue;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
|
|
|
if (baseStep > 180.0f) {
|
2020-03-17 04:31:30 +00:00
|
|
|
baseStep = -(360.0f - baseStep);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (baseStep < -180.0f) {
|
2020-03-17 04:31:30 +00:00
|
|
|
baseStep = 360.0f + baseStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
step = baseStep * scale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((step >= minStep) || (step <= -minStep)) {
|
|
|
|
if (step > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
|
|
|
if (step < minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = minStep;
|
|
|
|
*pValue += step;
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue > target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step > -minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -minStep;
|
|
|
|
*pValue += step;
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue < target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue >= 360.0f) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue -= 360.0f;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue < 0.0f) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += 360.0f;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_SmoothScaleMaxMinS(s16* pValue, s16 target, s16 invScale, s16 maxStep, s16 minStep) {
|
2020-03-19 21:48:38 +00:00
|
|
|
s16 step = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 diff = (target - *pValue);
|
|
|
|
|
2020-03-19 21:48:38 +00:00
|
|
|
s32 baseStep = diff / invScale;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = baseStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((step > minStep) || (step < -minStep)) {
|
|
|
|
if (step > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
*pValue += step;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
|
|
|
if (diff >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += minStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((s16)(target - *pValue) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue -= minStep;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if ((s16)(target - *pValue) >= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Math_SmoothScaleMaxS(s16* pValue, s16 target, s16 invScale, s16 maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 step = target - *pValue;
|
|
|
|
|
|
|
|
step /= invScale;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step > maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (step < -maxStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue -= maxStep;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src) {
|
2020-03-17 04:31:30 +00:00
|
|
|
dst->r = src->r;
|
|
|
|
dst->g = src->g;
|
|
|
|
dst->b = src->b;
|
|
|
|
dst->a = src->a;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_80078884(u16 sfxId) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Audio_PlaySoundGeneral(sfxId, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800788CC(u16 sfxId) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Audio_PlaySoundGeneral(sfxId, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_80078914(Vec3f* arg0, u16 sfxId) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Audio_PlaySoundGeneral(sfxId, arg0, 4, &D_801333E0, &D_801333E0, &D_801333E8);
|
|
|
|
}
|