Create functionally equivalent C for handwritten func0002f490 and func0002f560

This commit is contained in:
Ryan Dwyer 2022-12-02 20:18:50 +10:00
parent b39c317812
commit c20a31db57
5 changed files with 224 additions and 9 deletions

View File

@ -5322,7 +5322,7 @@ bool bgTestHitOnObj(struct coord *arg0, struct coord *arg1, struct coord *arg2,
if (!(arg0->y < min.y && arg1->y < min.y) && !(arg0->y > max.y && arg1->y > max.y)) {
if (bgTestLineIntersectsBbox(arg0, arg2, &min, &max)
&& func0002f560(point1, point2, point3, 0, arg0, arg1, arg2, &sp8c, &sp80)) {
&& func0002f560(point1, point2, point3, NULL, arg0, arg1, arg2, &sp8c, &sp80)) {
tmp = sp8c.x - arg0->x;
sqdist = tmp * tmp;
@ -5609,7 +5609,7 @@ bool bgTestHitOnChr(struct model *model, struct coord *arg1, struct coord *arg2,
if (!(arg1->y < min.y && arg2->y < min.y) && !(arg1->y > max.y && arg2->y > max.y)) {
if (bgTestLineIntersectsBbox(arg1, arg3, &min, &max)
&& func0002f560(point1, point2, point3, 0, arg1, arg2, arg3, &sp84, &sp78)) {
&& func0002f560(point1, point2, point3, NULL, arg1, arg2, arg3, &sp84, &sp78)) {
tmp = sp84.x - arg1->x;
sqdist = tmp * tmp;
@ -5813,7 +5813,7 @@ bool bgTestHitInVtxBatch(struct coord *arg0, struct coord *arg1, struct coord *a
if (!(arg0->y > max.y && arg1->y > max.y)) {
if (bgTestLineIntersectsBbox(arg0, arg2, &min, &max)
&& func0002f560(point1, point2, point3, 0, arg0, arg1, arg2, &spb0, &spa4)) {
&& func0002f560(point1, point2, point3, NULL, arg0, arg1, arg2, &spb0, &spa4)) {
f32 tmp;
tmp = spb0.x - arg0->x;

View File

@ -499,8 +499,8 @@ bool lightsHandleHit(struct coord *gunpos, struct coord *hitpos, s32 roomnum)
for (i = 0; i < g_Rooms[roomnum].numlights; i++) {
if (light->healthy && light->vulnerable) {
if (func0002f490(&light->bbox[0], &light->bbox[1], &light->bbox[3], 0, &spa4, &sp98, &sp8c, 0, 0)
|| func0002f490(&light->bbox[1], &light->bbox[2], &light->bbox[3], 0, &spa4, &sp98, &sp8c, 0, 0)) {
if (func0002f490(&light->bbox[0], &light->bbox[1], &light->bbox[3], NULL, &spa4, &sp98, &sp8c, 0, 0)
|| func0002f490(&light->bbox[1], &light->bbox[2], &light->bbox[3], NULL, &spa4, &sp98, &sp8c, 0, 0)) {
struct coord soundpos;
soundpos.x = light->bbox[0].x;

View File

@ -4,7 +4,7 @@
#include "data.h"
#include "types.h"
bool func0002f490(struct vec3s16 *arg0, struct vec3s16 *arg1, struct vec3s16 *arg2, s32 arg3, struct coord *arg4, struct coord *arg5, struct coord *arg6, struct coord *arg7, struct coord *arg8);
bool func0002f560(struct coord *arg0, struct coord *arg1, struct coord *arg2, s32 arg3, struct coord *arg4, struct coord *arg5, struct coord *arg6, struct coord *arg7, struct coord *arg8);
bool func0002f490(struct vec3s16 *arg0, struct vec3s16 *arg1, struct vec3s16 *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5, struct coord *arg6, struct coord *arg7, struct coord *arg8);
bool func0002f560(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5, struct coord *arg6, struct coord *arg7, struct coord *arg8);
#endif

View File

@ -2710,7 +2710,7 @@ bool cd0002aac0IntTile(struct coord *arg0, struct coord *arg1, struct coord *arg
if (func0002f490((struct vec3s16 *)&tile->vertices[0][0],
(struct vec3s16 *)&tile->vertices[i - 1][0],
(struct vec3s16 *)&tile->vertices[i][0],
0, arg0, arg1, arg2, arg4, arg5)) {
NULL, arg0, arg1, arg2, arg4, arg5)) {
return true;
}
}
@ -2725,7 +2725,7 @@ bool cd0002ab98FltTile(struct coord *arg0, struct coord *arg1, struct coord *arg
for (i = 2; i < numvertices; i++) {
if (func0002f560(&tile->vertices[0], &tile->vertices[i - 1], &tile->vertices[i],
0, arg0, arg1, arg2, arg4, arg5)) {
NULL, arg0, arg1, arg2, arg4, arg5)) {
return true;
}
}

215
src/lib/lib_2f490_c.c Normal file
View File

@ -0,0 +1,215 @@
#include <ultra64.h>
#include "constants.h"
#include "bss.h"
#include "data.h"
#include "lib/mtx.h"
#include "types.h"
static bool implementation(
f32 f0, f32 f1, f32 f2,
f32 f12, f32 f13, f32 f14,
f32 f15, f32 f16, f32 f17,
struct coord *arg3, struct coord *t0, struct coord *t1,
struct coord *t2, struct coord *t3, struct coord *t4)
{
f32 f3;
f32 f4;
f32 f5;
f32 f6;
f32 f7;
f32 f8;
f32 f9;
f32 f10;
f32 f11;
f32 f18;
f32 f19;
f32 f20;
f32 f21;
f32 f22;
f32 f23;
f32 f24;
f32 f25;
f32 f26;
f32 f27;
f32 f28;
f3 = f12 - f0;
f4 = f13 - f1;
f5 = f14 - f2;
f6 = f15 - f12;
f7 = f16 - f13;
f8 = f17 - f14;
f9 = f15 - f0;
f10 = f16 - f1;
f11 = f17 - f2;
if (arg3 != NULL) {
f0 += arg3->x;
f1 += arg3->y;
f2 += arg3->z;
}
f12 = f4 * f8;
f13 = f7 * f5;
f14 = f5 * f6;
f12 = f12 - f13;
f15 = f8 * f3;
f16 = f3 * f7;
f13 = f14 - f15;
f14 = f6 * f4;
f14 = f16 - f14;
f15 = f12 * f0;
f16 = f13 * f1;
f17 = f14 * f2;
f15 = f15 + f16;
f15 = f15 + f17;
f16 = t2->x;
f17 = t2->y;
f18 = t2->z;
f19 = f12 * f16;
f20 = f13 * f17;
f19 = f19 + f20;
f20 = f14 * f18;
f19 = f19 + f20;
if (f19 == 0.0f) {
return false;
}
f20 = t1->x;
f21 = t1->y;
f22 = t1->z;
f23 = f12 * f20;
f24 = f13 * f21;
f23 = f15 - f23;
f25 = f14 * f22;
f23 = f23 - f24;
f23 = f23 - f25;
f19 = f23 / f19;
f23 = f19 * f16;
f24 = f19 * f17;
f23 = f20 + f23;
f25 = f19 * f18;
f24 = f21 + f24;
f25 = f22 + f25;
f26 = f23 - f20;
f26 = f16 * f26;
f27 = f24 - f21;
f27 = f17 * f27;
f28 = f25 - f22;
f26 = f26 + f27;
f27 = f18 * f28;
f26 = f26 + f27;
if (f26 > 0) {
return false;
}
f20 = t0->x;
f21 = t0->y;
f22 = t0->z;
f26 = f23 - f20;
f26 = f16 * f26;
f27 = f24 - f21;
f27 = f17 * f27;
f28 = f25 - f22;
f26 = f26 + f27;
f27 = f18 * f28;
f26 = f26 + f27;
if (f26 < 0) {
return false;
}
f0 = f23 - f0;
f1 = f24 - f1;
f2 = f25 - f2;
f26 = f6 * f4;
f27 = f3 * f7;
f26 = f26 - f27;
if (f26 != 0.0f) {
f27 = f0 * f4;
f28 = f1 * f3;
} else {
f26 = f7 * f5;
f27 = f4 * f8;
f26 = f26 - f27;
if (f26 != 0.0f) {
f27 = f1 * f5;
f28 = f2 * f4;
} else {
f26 = f8 * f3;
f27 = f5 * f6;
f26 = f26 - f27;
f27 = f2 * f3;
f28 = f0 * f5;
}
}
f27 = f27 - f28;
f27 = f27 / f26;
if (f27 < 0.0f) {
return false;
}
if (f3 != 0.0f) {
f28 = f27 * f9;
f28 = f0 - f28;
f28 = f28 / f3;
} else if (f4 != 0.0f) {
f28 = f27 * f10;
f28 = f1 - f28;
f28 = f28 / f4;
} else {
f28 = f27 * f11;
f28 = f2 - f28;
f28 = f28 / f5;
}
if (f28 >= 0.0f && f28 + f27 <= 1.0f) {
if (t3 != NULL) {
t3->x = f23;
t3->y = f24;
t3->z = f25;
}
if (t4 != NULL) {
t4->x = f12;
t4->y = f13;
t4->z = f14;
}
return true;
}
return false;
}
bool func0002f490(struct vec3s16 *arg0, struct vec3s16 *arg1, struct vec3s16 *arg2,
struct coord *arg3, struct coord *t0, struct coord *t1,
struct coord *t2, struct coord *t3, struct coord *t4)
{
// Casting arg0/arg1/arg2 properties from s16 to float
return implementation(
arg0->x, arg0->y, arg0->z,
arg1->x, arg1->y, arg1->z,
arg2->x, arg2->y, arg2->z,
arg3, t0, t1, t2, t3, t4);
}
bool func0002f560(struct coord *arg0, struct coord *arg1, struct coord *arg2,
struct coord *arg3, struct coord *t0, struct coord *t1,
struct coord *t2, struct coord *t3, struct coord *t4)
{
// No casting (arg0/arg1/arg2 properties are already floats)
return implementation(
arg0->x, arg0->y, arg0->z,
arg1->x, arg1->y, arg1->z,
arg2->x, arg2->y, arg2->z,
arg3, t0, t1, t2, t3, t4);
}