2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-05-01 22:06:35 +00:00
|
|
|
/**
|
|
|
|
* memset: sets `len` bytes to `val` starting at address `dest`.
|
|
|
|
*
|
|
|
|
* Unlike normal memset,
|
|
|
|
* - `dest` is a `u8*` already,
|
|
|
|
* - does not return `dest`,
|
|
|
|
* - the arguments are in a different order,
|
|
|
|
* - `val` is a `u8` instead of the standard `s32`.
|
|
|
|
*
|
|
|
|
* @see There are two other memsets in this codebase, __osMemset(), MemSet()
|
|
|
|
*
|
|
|
|
* @param dest address to start at
|
|
|
|
* @param len number of bytes to write
|
|
|
|
* @param val value to write
|
|
|
|
*/
|
|
|
|
void Lib_MemSet(u8* dest, size_t len, u8 val) {
|
|
|
|
size_t i;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-01 02:00:39 +00:00
|
|
|
// clang-format off
|
2022-05-01 22:06:35 +00:00
|
|
|
for (i = 0; i < len; i++) { *dest++ = val; }
|
2020-05-01 02:00:39 +00:00
|
|
|
// clang-format on
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_CosS(s16 angle) {
|
|
|
|
return coss(angle) * SHT_MINV;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_SinS(s16 angle) {
|
|
|
|
return sins(angle) * SHT_MINV;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step (scaled by the update rate) towards target, setting it equal when the target is reached.
|
|
|
|
* Returns true when target is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step) {
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step != 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 updateScale = R_UPDATE_RATE * 0.5f;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
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;
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target, setting it equal when the target is reached.
|
|
|
|
* Returns true when target is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepToS(s16* pValue, s16 target, s16 step) {
|
2020-03-22 21:19:43 +00:00
|
|
|
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;
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target, setting it equal when the target is reached.
|
|
|
|
* Returns true when target is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepToF(f32* pValue, f32 target, f32 step) {
|
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;
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step. If pvalue reaches limit angle or its opposite, sets it equal to limit angle.
|
|
|
|
* Returns true when limit angle or its opposite is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepUntilAngleS(s16* pValue, s16 limit, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (((s16)(*pValue - limit) * (s16)(orig - limit)) <= 0) {
|
|
|
|
*pValue = limit;
|
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step. If pvalue reaches limit, sets it equal to limit.
|
|
|
|
* Returns true when limit is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepUntilS(s16* pValue, s16 limit, s16 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s16 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (((*pValue - limit) * (orig - limit)) <= 0) {
|
|
|
|
*pValue = limit;
|
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target angle, setting it equal when the target is reached.
|
|
|
|
* Returns true when target is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step) {
|
|
|
|
s32 diff = target - *pValue;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (diff < 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-12-26 10:44:53 +00:00
|
|
|
if (diff >= 0x8000) {
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
2020-12-26 10:44:53 +00:00
|
|
|
diff = -0xFFFF - -diff;
|
|
|
|
} else if (diff <= -0x8000) {
|
|
|
|
diff += 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
step = -step;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (step != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += step;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if ((diff * step) <= 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue = target;
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (target == *pValue) {
|
2020-12-26 10:44:53 +00:00
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step. If pvalue reaches limit, sets it equal to limit.
|
|
|
|
* Returns true when limit is reached, false otherwise.
|
|
|
|
*/
|
|
|
|
s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 orig = *pValue;
|
|
|
|
|
|
|
|
*pValue += step;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (((*pValue - limit) * (orig - limit)) <= 0) {
|
|
|
|
*pValue = limit;
|
|
|
|
return true;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return false;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue toward target by incrStep if pValue is smaller and by decrStep if it is greater, setting it equal when
|
|
|
|
* target is reached. Returns true when target is reached, false otherwise.
|
|
|
|
*/
|
2020-12-27 16:13:38 +00:00
|
|
|
s32 Math_AsymStepToF(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-09-19 01:45:39 +00:00
|
|
|
void func_80077D10(f32* arg0, s16* arg1, Input* input) {
|
2020-10-03 15:22:44 +00:00
|
|
|
f32 relX = input->rel.stick_x;
|
|
|
|
f32 relY = input->rel.stick_y;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-09-19 01:45:39 +00:00
|
|
|
*arg0 = sqrtf(SQ(relX) + SQ(relY));
|
2020-03-17 04:31:30 +00:00
|
|
|
*arg0 = (60.0f < *arg0) ? 60.0f : *arg0;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*arg1 = Math_Atan2S(relY, -relX);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
s16 Rand_S16Offset(s16 base, s16 range) {
|
|
|
|
return (s16)(Rand_ZeroOne() * range) + base;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
s16 Rand_S16OffsetStride(s16 base, s16 stride, s16 range) {
|
|
|
|
return (s16)(Rand_ZeroOne() * range) * stride + base;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return Math_Atan2S(dz, dx);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b) {
|
2020-12-26 10:44:53 +00:00
|
|
|
return Math_Atan2S(Math_Vec3f_DistXZ(a, b), a->y - b->y);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2021-02-14 00:49:40 +00:00
|
|
|
Vec3f* vec = (Vec3f*)(ptr + ichain->offset);
|
|
|
|
f32 val = ichain->value;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
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) {
|
2021-02-14 00:49:40 +00:00
|
|
|
Vec3f* vec = (Vec3f*)(ptr + ichain->offset);
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 val;
|
|
|
|
|
2020-10-13 16:32:19 +00:00
|
|
|
osSyncPrintf("pp=%x data=%f\n", vec, ichain->value / 1000.0f);
|
2020-03-17 04:31:30 +00:00
|
|
|
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) {
|
2021-02-14 00:49:40 +00:00
|
|
|
Vec3s* vec = (Vec3s*)(ptr + ichain->offset);
|
|
|
|
s16 val = ichain->value;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
vec->z = val;
|
|
|
|
vec->y = val;
|
|
|
|
vec->x = val;
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target. If this step is more than fraction of the remaining distance, step by that
|
|
|
|
* instead, with a minimum step of minStep. Returns remaining distance to target.
|
|
|
|
*/
|
|
|
|
f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep) {
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 stepSize = (target - *pValue) * fraction;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if ((stepSize >= minStep) || (stepSize <= -minStep)) {
|
|
|
|
if (stepSize > step) {
|
|
|
|
stepSize = step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize < -step) {
|
|
|
|
stepSize = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue += stepSize;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize < minStep) {
|
2020-03-17 04:31:30 +00:00
|
|
|
*pValue += minStep;
|
2020-12-26 10:44:53 +00:00
|
|
|
stepSize = minStep;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
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-12-26 10:44:53 +00:00
|
|
|
if (stepSize > -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-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target. If step is more than fraction of the remaining distance, step by that instead.
|
|
|
|
*/
|
|
|
|
void Math_ApproachF(f32* pValue, f32 target, f32 fraction, f32 step) {
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 stepSize = (target - *pValue) * fraction;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize > step) {
|
|
|
|
stepSize = step;
|
|
|
|
} else if (stepSize < -step) {
|
|
|
|
stepSize = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue += stepSize;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards zero. If step is more than fraction of the remaining distance, step by that instead.
|
|
|
|
*/
|
|
|
|
void Math_ApproachZeroF(f32* pValue, f32 fraction, f32 step) {
|
|
|
|
f32 stepSize = *pValue * fraction;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize > step) {
|
|
|
|
stepSize = step;
|
|
|
|
} else if (stepSize < -step) {
|
|
|
|
stepSize = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue -= stepSize;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target angle in degrees. If this step is more than fraction of the remaining distance,
|
|
|
|
* step by that instead, with a minimum step of minStep. Returns the value of the step taken.
|
|
|
|
*/
|
|
|
|
f32 Math_SmoothStepToDegF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep) {
|
|
|
|
f32 stepSize = 0.0f;
|
|
|
|
f32 diff = target - *pValue;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-12-26 10:44:53 +00:00
|
|
|
if (diff > 180.0f) {
|
|
|
|
diff = -(360.0f - diff);
|
|
|
|
} else if (diff < -180.0f) {
|
|
|
|
diff = 360.0f + diff;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
stepSize = diff * fraction;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if ((stepSize >= minStep) || (stepSize <= -minStep)) {
|
|
|
|
if (stepSize > step) {
|
|
|
|
stepSize = step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize < -step) {
|
|
|
|
stepSize = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue += stepSize;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize < minStep) {
|
|
|
|
stepSize = minStep;
|
|
|
|
*pValue += stepSize;
|
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-12-26 10:44:53 +00:00
|
|
|
if (stepSize > -minStep) {
|
|
|
|
stepSize = -minStep;
|
|
|
|
*pValue += stepSize;
|
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
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
return stepSize;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target. If this step is more than 1/scale of the remaining distance, step by that
|
|
|
|
* instead, with a minimum step of minStep. Returns remaining distance to target.
|
|
|
|
*/
|
|
|
|
s16 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep) {
|
|
|
|
s16 stepSize = 0;
|
|
|
|
s16 diff = target - *pValue;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (*pValue != target) {
|
2020-12-26 10:44:53 +00:00
|
|
|
stepSize = diff / scale;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if ((stepSize > minStep) || (stepSize < -minStep)) {
|
|
|
|
if (stepSize > step) {
|
|
|
|
stepSize = step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
if (stepSize < -step) {
|
|
|
|
stepSize = -step;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue += stepSize;
|
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-12-26 10:44:53 +00:00
|
|
|
/**
|
|
|
|
* Changes pValue by step towards target. If step is more than 1/scale of the remaining distance, step by that instead.
|
|
|
|
*/
|
2022-02-20 13:22:29 +00:00
|
|
|
void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 step) {
|
2020-12-26 10:44:53 +00:00
|
|
|
s16 diff = target - *pValue;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
diff /= scale;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-02-20 13:22:29 +00:00
|
|
|
if (diff > step) {
|
|
|
|
*pValue += step;
|
|
|
|
} else if (diff < -step) {
|
|
|
|
*pValue -= step;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-12-26 10:44:53 +00:00
|
|
|
*pValue += diff;
|
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) {
|
2022-07-30 13:05:27 +00:00
|
|
|
Audio_PlaySfxGeneral(sfxId, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
|
|
|
|
&gSfxDefaultReverb);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800788CC(u16 sfxId) {
|
2022-07-30 13:05:27 +00:00
|
|
|
Audio_PlaySfxGeneral(sfxId, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
|
|
|
|
&gSfxDefaultReverb);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_80078914(Vec3f* arg0, u16 sfxId) {
|
2022-07-30 13:05:27 +00:00
|
|
|
Audio_PlaySfxGeneral(sfxId, arg0, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|