Name some utils functions

This commit is contained in:
Ryan Dwyer 2025-02-14 22:53:23 +10:00
parent 6a0bff99f4
commit 86f61e88ec
7 changed files with 106 additions and 102 deletions

View File

@ -1093,13 +1093,13 @@ bool light_tick_broken(s32 roomnum, s32 lightnum)
sp80.y = -sp8c.y;
sp80.z = -sp8c.z;
func0f177164(&sp98, &spa4, VERSION >= VERSION_NTSC_1_0 ? 1546 : 1570, "dlights.c");
vec3f_normalise(&sp98, &spa4, VERSION >= VERSION_NTSC_1_0 ? 1546 : 1570, "dlights.c");
spa4.x += sp80.x;
spa4.y += sp80.y;
spa4.z += sp80.z;
func0f177164(&spa4, &spa4, VERSION >= VERSION_NTSC_1_0 ? 1548 : 1572, "dlights.c");
vec3f_normalise(&spa4, &spa4, VERSION >= VERSION_NTSC_1_0 ? 1548 : 1572, "dlights.c");
room = (void *) (roomnum * sizeof(struct bgroom));
@ -2070,7 +2070,7 @@ void lights_find_distance_through_rooms(s32 roomnum1, struct coord *pos1, s32 ro
*result = 32767;
if (roomnum1 == roomnum2) {
*result = coords_get_distance(pos1, pos2);
*result = vec3f_get_distance(pos1, pos2);
} else {
for (i = 0; i < g_Rooms[roomnum1].numportals; i++) {
portalnum1 = g_RoomPortals[g_Rooms[roomnum1].roomportallistoffset + i];

View File

@ -742,7 +742,7 @@ void explosion_inflict_damage(struct prop *expprop)
sp158.f[1] = damageradius;
sp158.f[2] = damageradius;
if (func0f1773c8(&sp14c, &sp158)) {
if (vec3f_is_pos_within_radius(&sp14c, &sp158)) {
room_set_light_broken(roomnum, j);
}
}

View File

@ -100,7 +100,7 @@ void splat_tick_chr(struct prop *prop)
u32 value = chr->bulletstaken * chr->tickssincesplat;
if (value > TICKS(240)) {
f32 dist = coords_get_distance(&chr->lastdroppos, &prop->pos);
f32 dist = vec3f_get_distance(&chr->lastdroppos, &prop->pos);
s32 addmore = false;
if (dist > 40) {
@ -166,7 +166,7 @@ s32 splats_create(s32 qty, f32 scale, struct prop *prop, struct shotdata *shotda
s32 j;
if (splattype == 0) {
dist = coords_get_distance(&shotdata->gunpos3d, arg5);
dist = vec3f_get_distance(&shotdata->gunpos3d, arg5);
for (i = 0; i < 3; i++) {
spfc.f[i] = shotdata->gundir3d.f[i];
@ -212,11 +212,11 @@ s32 splats_create(s32 qty, f32 scale, struct prop *prop, struct shotdata *shotda
mtx4_rotate_vec(&spa4, &spf0, &shotdata->gundir2d);
#if VERSION >= VERSION_NTSC_1_0
func0f177164(&shotdata->gundir3d, &shotdata->gundir3d, 403, "splat.c");
func0f177164(&shotdata->gundir2d, &shotdata->gundir2d, 404, "splat.c");
vec3f_normalise(&shotdata->gundir3d, &shotdata->gundir3d, 403, "splat.c");
vec3f_normalise(&shotdata->gundir2d, &shotdata->gundir2d, 404, "splat.c");
#else
func0f177164(&shotdata->gundir3d, &shotdata->gundir3d, 405, "splat.c");
func0f177164(&shotdata->gundir2d, &shotdata->gundir2d, 406, "splat.c");
vec3f_normalise(&shotdata->gundir3d, &shotdata->gundir3d, 405, "splat.c");
vec3f_normalise(&shotdata->gundir2d, &shotdata->gundir2d, 406, "splat.c");
#endif
if (splat_create_one(scale, prop, shotdata, /*reused var*/ dist, isskedar, splattype, timermax, chr, timerspeed)) {
@ -301,7 +301,7 @@ bool splat_create_one(f32 scale, struct prop *chrprop, struct shotdata *shotdata
}
if (hasresult) {
spraydistance = coords_get_distance(&stackshotdata.gunpos3d, &besthitthing.pos);
spraydistance = vec3f_get_distance(&stackshotdata.gunpos3d, &besthitthing.pos);
if (spraydistance < g_SplatMaxDistance) {
sp50c = &hitthing.pos;
@ -463,7 +463,7 @@ void splat_create_wallhit(struct splatdata *splat)
break;
}
distance = coords_get_distance(&splat->gunpos, &splat->unk0c);
distance = vec3f_get_distance(&splat->gunpos, &splat->unk0c);
diameter = g_SplatDistanceScale * distance * scale;
if (diameter > g_SplatMaxDiameter) {

View File

@ -6,14 +6,6 @@
#include "data.h"
#include "types.h"
const char var7f1b7cb0[] = "UM_Make : In\n";
const char var7f1b7cc0[] = "UM_Make : Out\n";
const char var7f1b7cd0[] = "Utils -> ERROR at Line %d of %s\n";
const char var7f1b7cf4[] = "Utils -> UM_fVec3_NormaliseTo - Vec = %s%s (%f,%f,%f)\n";
const char var7f1b7d2c[] = "";
const char var7f1b7d30[] = "";
const char var7f1b7d34[] = "Utils -> Attempt to normalise zeo length vector\n";
void *var800ac0d0;
u32 var800ac0d4;
u32 var800ac0d8;
@ -23,9 +15,9 @@ u32 var800ac0e4;
u8 *var800ac0e8[4];
u32 var800ac0f8[4];
f32 var800845d0 = 999999;
f32 var800845d4 = 0.00001f;
s32 var800845d8 = 1;
f32 g_UtilsMaxSaneFloat = 999999;
f32 g_UtilsMinSaneFloat = 0.00001f;
s32 g_UtilsSavedInt = 1;
struct coord var800845dc = {0, 0, 0};
u32 var800845e8 = 0x00000000;
u32 var800845ec = 0x3f800000;
@ -41,20 +33,20 @@ u8 *var80084618 = NULL;
u32 var8008461c = 0x00000004;
u32 var80084620 = 0x00000000;
void func0f176d70(s32 arg0)
void utils_set_int(s32 value)
{
var800845d8 = arg0;
g_UtilsSavedInt = value;
}
s32 func0f176d7c(void)
s32 utils_get_int(void)
{
return var800845d8;
return g_UtilsSavedInt;
}
u32 align4(u32 arg0)
{
if (arg0 & 3) {
arg0 = (arg0 & 0xfffffffc) + 4;
arg0 = (arg0 & ~3) + 4;
}
return arg0;
@ -63,7 +55,7 @@ u32 align4(u32 arg0)
u32 align16(u32 arg0)
{
if (arg0 & 0xf) {
arg0 = (arg0 & 0xfffffff0) + 0x10;
arg0 = (arg0 & ~15) + 16;
}
return arg0;
@ -72,7 +64,7 @@ u32 align16(u32 arg0)
u32 align32(u32 arg0)
{
if (arg0 & 0x1f) {
arg0 = (arg0 & 0xffffffe0) + 0x20;
arg0 = (arg0 & ~31) + 32;
}
return arg0;
@ -85,6 +77,8 @@ void utils_init(void)
u32 slotssize = 0x1900;
u32 allocsize;
osSyncPrintf("UM_Make : In\n");
var800ac0d0 = memp_alloc(10000, MEMPOOL_8);
allocsize = align16(0x3900);
@ -103,53 +97,57 @@ void utils_init(void)
var80084610 = var800ac0e8[0] + slotssize;
var80084618 = var800ac0e8[0] + allocsize - 1;
var80084614 = var80084610;
osSyncPrintf("UM_Make : Out\n");
}
s32 func0f176eb0(s32 arg0, s32 arg1)
const char var7f1b7cd0[] = "Utils -> ERROR at Line %d of %s\n";
s32 utils_get_ceiled_quotient(s32 dividend, s32 divisor)
{
if (arg0 % arg1 == 0) {
return arg0;
if (dividend % divisor == 0) {
return dividend;
}
return (arg0 / arg1 + 1) * arg1;
return (dividend / divisor + 1) * divisor;
}
void func0f176f34(struct coord *a, struct coord *b, struct coord *out)
void vec3f_sum2(struct coord *a, struct coord *b, struct coord *dst)
{
out->x = a->x + b->x;
out->y = a->y + b->y;
out->z = a->z + b->z;
dst->x = a->x + b->x;
dst->y = a->y + b->y;
dst->z = a->z + b->z;
}
void func0f176f68(struct coord *a, struct coord *b, struct coord *c, struct coord *out)
void vec3f_sum3(struct coord *a, struct coord *b, struct coord *c, struct coord *dst)
{
out->x = a->x + b->x + c->x;
out->y = a->y + b->y + c->y;
out->z = a->z + b->z + c->z;
dst->x = a->x + b->x + c->x;
dst->y = a->y + b->y + c->y;
dst->z = a->z + b->z + c->z;
}
void func0f176fb4(struct coord *a, struct coord *b, struct coord *c, struct coord *d, struct coord *out)
void vec3f_sum4(struct coord *a, struct coord *b, struct coord *c, struct coord *d, struct coord *dst)
{
out->x = a->x + b->x + c->x + d->x;
out->y = a->y + b->y + c->y + d->y;
out->z = a->z + b->z + c->z + d->z;
dst->x = a->x + b->x + c->x + d->x;
dst->y = a->y + b->y + c->y + d->y;
dst->z = a->z + b->z + c->z + d->z;
}
void func0f17701c(struct coord *a, struct coord *b, struct coord *out)
void vec3f_subtract(struct coord *a, struct coord *b, struct coord *dst)
{
out->x = b->x - a->x;
out->y = b->y - a->y;
out->z = b->z - a->z;
dst->x = b->x - a->x;
dst->y = b->y - a->y;
dst->z = b->z - a->z;
}
void func0f177050(struct coord *a, f32 mult, struct coord *out)
void vec3f_multiply_scalar(struct coord *a, f32 mult, struct coord *dst)
{
out->x = a->x * mult;
out->y = a->y * mult;
out->z = a->z * mult;
dst->x = a->x * mult;
dst->y = a->y * mult;
dst->z = a->z * mult;
}
f32 func0f17707c(struct coord *a, struct coord *b)
f32 vec3f_sqdist(struct coord *a, struct coord *b)
{
return a->x * b->x + a->y * b->y + a->z * b->z;
}
@ -161,38 +159,44 @@ void func0f1770ac(struct coord *a, struct coord *b, struct coord *out)
out->z = a->x * b->y - a->y * b->x;
}
void func0f177120(struct coord *in, struct coord *out)
void vec3f_copy(struct coord *src, struct coord *dst)
{
out->x = in->x;
out->y = in->y;
out->z = in->z;
dst->x = src->x;
dst->y = src->y;
dst->z = src->z;
}
void func0f17713c(struct coord *in, struct coord *out)
void vec3f_invert(struct coord *src, struct coord *dst)
{
out->x = -in->x;
out->y = -in->y;
out->z = -in->z;
dst->x = -src->x;
dst->y = -src->y;
dst->z = -src->z;
}
bool func0f177164(struct coord *arg0, struct coord *arg1, u32 line, char *file)
bool vec3f_normalise(struct coord *src, struct coord *dst, u32 line, char *file)
{
f32 hypotenuse = arg0->x * arg0->x + arg0->y * arg0->y + arg0->z * arg0->z;
f32 hypotenuse;
f32 mult;
if (hypotenuse < var800845d4) {
arg0->x = var800845f4.x;
arg0->y = var800845f4.y;
arg0->z = var800845f4.z;
osSyncPrintf("Utils -> UM_fVec3_NormaliseTo - Vec = %s%s (%f,%f,%f)\n", "", "", src->x, src->y, src->z);
hypotenuse = src->x * src->x + src->y * src->y + src->z * src->z;
if (hypotenuse < g_UtilsMinSaneFloat) {
osSyncPrintf("Utils -> Attempt to normalise zeo length vector\n");
src->x = var800845f4.x;
src->y = var800845f4.y;
src->z = var800845f4.z;
return false;
}
mult = 1.0f / sqrtf(hypotenuse);
arg1->x = arg0->x * mult;
arg1->y = arg0->y * mult;
arg1->z = arg0->z * mult;
dst->x = src->x * mult;
dst->y = src->y * mult;
dst->z = src->z * mult;
return true;
}
@ -217,17 +221,17 @@ bool func0f177298(struct coord *a, struct coord *b, struct coord *c)
return diff.x * c->x + diff.y * c->y + diff.z * c->z < 0;
}
bool func0f177300(struct coord *a, struct coord *b)
bool vec3f_is_practically_equal(struct coord *a, struct coord *b)
{
f32 diff = a->x - b->x;
if (ABS(diff) < var800845d4) {
if (ABS(diff) < g_UtilsMinSaneFloat) {
diff = a->y - b->y;
if (ABS(diff) < var800845d4) {
if (ABS(diff) < g_UtilsMinSaneFloat) {
diff = a->z - b->z;
if (ABS(diff) < var800845d4) {
if (ABS(diff) < g_UtilsMinSaneFloat) {
return true;
}
}
@ -236,18 +240,18 @@ bool func0f177300(struct coord *a, struct coord *b)
return false;
}
bool func0f1773c8(struct coord *a, struct coord *b)
bool vec3f_is_pos_within_radius(struct coord *pos, struct coord *radius)
{
if (a->x < b->x && -b->x < a->x
&& a->y < b->y && -b->y < a->y
&& a->z < b->z && -b->z < a->z) {
if (pos->x < radius->x && pos->x > -radius->x
&& pos->y < radius->y && pos->y > -radius->y
&& pos->z < radius->z && pos->z > -radius->z) {
return true;
}
return false;
}
f32 coords_get_distance(struct coord *a, struct coord *b)
f32 vec3f_get_distance(struct coord *a, struct coord *b)
{
f32 xdiff = b->x - a->x;
f32 ydiff = b->y - a->y;
@ -256,19 +260,19 @@ f32 coords_get_distance(struct coord *a, struct coord *b)
return sqrtf(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
}
bool func0f1774b4(struct coord *arg0, struct coord *arg1, struct coord *out)
bool vec3f_make_normal_to(struct coord *arg0, struct coord *arg1, struct coord *out)
{
struct coord a;
struct coord b;
struct coord c;
f32 mult;
if (!func0f177164(arg1, &a, 702, "utils.c")) {
if (!vec3f_normalise(arg1, &a, 702, "utils.c")) {
osSyncPrintf("UTILS -> DEBUG ERROR - UM_fVec3_MakeNormalTo - Cant normalise\n");
return false;
}
if (!func0f177164(arg0, &b, 710, "utils.c")) {
if (!vec3f_normalise(arg0, &b, 710, "utils.c")) {
osSyncPrintf("UTILS -> DEBUG ERROR - UM_fVec3_MakeNormalTo - Cant normalise\n");
return false;
}
@ -308,7 +312,7 @@ void func0f177624(struct coord *arg0, struct coord *arg1, struct coord *arg2, st
f32 tmpx;
f32 tmpz;
func0f177164(arg0, arg1, 771, "utils.c");
vec3f_normalise(arg0, arg1, 771, "utils.c");
dist = sqrtf(arg1->x * arg1->x + arg1->z * arg1->z);
@ -334,8 +338,8 @@ f32 func0f1776cc(struct coord *a, struct coord *b, struct coord *c)
f32 sqdist = xdiff * b->x + ydiff * b->y + zdiff * b->z;
if (sqdist < var800845d4 && sqdist > -var800845d4) {
return var800845d0;
if (sqdist < g_UtilsMinSaneFloat && sqdist > -g_UtilsMinSaneFloat) {
return g_UtilsMaxSaneFloat;
}
return (xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) / sqdist;
@ -395,14 +399,14 @@ bool func0f17781c(struct coord *arg0, s32 arg1)
func0f1770ac(&sp78, &sp6c, &sp60);
func0f177164(&sp60, &sp60, 1101, "utils.c");
vec3f_normalise(&sp60, &sp60, 1101, "utils.c");
for (i = 3; i < arg1; i++) {
sp50.x = arg0[i].x - arg0[0].x;
sp50.y = arg0[i].y - arg0[0].y;
sp50.z = arg0[i].z - arg0[0].z;
func0f177164(&sp50, &sp50, 1109, "utils.c");
vec3f_normalise(&sp50, &sp50, 1109, "utils.c");
f0 = sp50.x * sp60.x + sp50.y * sp60.y + sp50.z * sp60.z;

View File

@ -689,9 +689,9 @@ void wallhit_create_with_20_args(struct coord *relpos, struct coord *arg1, struc
sp1b8.z = arg1->z;
#if VERSION >= VERSION_NTSC_1_0
func0f177164(&sp1b8, &sp1b8, 956, "wallhit.c");
vec3f_normalise(&sp1b8, &sp1b8, 956, "wallhit.c");
#else
func0f177164(&sp1b8, &sp1b8, 955, "wallhit.c");
vec3f_normalise(&sp1b8, &sp1b8, 955, "wallhit.c");
#endif
#if VERSION >= VERSION_NTSC_1_0
@ -829,9 +829,9 @@ void wallhit_create_with_20_args(struct coord *relpos, struct coord *arg1, struc
sp1ac.f[1] = relpos->y;
sp1ac.f[2] = relpos->z;
xiszero = ABS(arg1->x) < var800845d4 ? true : false;
yiszero = ABS(arg1->y) < var800845d4 ? true : false;
ziszero = ABS(arg1->z) < var800845d4 ? true : false;
xiszero = ABS(arg1->x) < g_UtilsMinSaneFloat ? true : false;
yiszero = ABS(arg1->y) < g_UtilsMinSaneFloat ? true : false;
ziszero = ABS(arg1->z) < g_UtilsMinSaneFloat ? true : false;
if (xiszero && ziszero) {
sp1f4.x = -1.0f;
@ -867,11 +867,11 @@ void wallhit_create_with_20_args(struct coord *relpos, struct coord *arg1, struc
sp130.z = arg4[2];
#if VERSION >= VERSION_NTSC_1_0
func0f177164(&sp13c, &sp13c, 1151, "wallhit.c");
func0f177164(&sp130, &sp130, 1152, "wallhit.c");
vec3f_normalise(&sp13c, &sp13c, 1151, "wallhit.c");
vec3f_normalise(&sp130, &sp130, 1152, "wallhit.c");
#else
func0f177164(&sp13c, &sp13c, 1142, "wallhit.c");
func0f177164(&sp130, &sp130, 1143, "wallhit.c");
vec3f_normalise(&sp13c, &sp13c, 1142, "wallhit.c");
vec3f_normalise(&sp130, &sp130, 1143, "wallhit.c");
#endif
f0 = (sp13c.x * sp130.x + sp13c.y * sp130.y + sp13c.z * sp130.z) * -1.0f;

View File

@ -448,7 +448,7 @@ extern s32 g_LanguageId;
#endif
extern struct surfacetype *g_SurfaceTypes[15];
extern u16 *g_ZbufPtr1;
extern f32 var800845d4;
extern f32 g_UtilsMinSaneFloat;
extern struct coord var800845dc;
extern struct menudialogdef g_2PMissionInventoryHMenuDialog;
extern struct menudialogdef g_2PMissionInventoryVMenuDialog;

View File

@ -9,9 +9,9 @@ u32 align16(u32 arg0);
u32 align32(u32 arg0);
void utils_init(void);
void func0f1770ac(struct coord *a, struct coord *b, struct coord *out);
bool func0f177164(struct coord *arg0, struct coord *arg1, u32 line, char *file);
bool func0f1773c8(struct coord *a, struct coord *b);
f32 coords_get_distance(struct coord *a, struct coord *b);
bool vec3f_normalise(struct coord *arg0, struct coord *arg1, u32 line, char *file);
bool vec3f_is_pos_within_radius(struct coord *a, struct coord *b);
f32 vec3f_get_distance(struct coord *a, struct coord *b);
void utils_reset(void);
s32 func0f177a54(u8 *arg0, s32 arg1, u8 *arg2, s32 arg3);
s32 func0f177c8c(u8 *arg0, s32 *arg1, s32 *roomnum);