the funny vec3f_copy optimization

This commit is contained in:
Arceveti
2021-09-25 18:33:35 -07:00
parent bf3828b724
commit 3d6725bfa1
5 changed files with 64 additions and 54 deletions

View File

@@ -16,23 +16,23 @@
#include "levels/jrb/header.h"
static const LevelScript script_func_local_1[] = {
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SUNKEN_SHIP, /*pos*/ 2385, 3589, 3727, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SUNKEN_SHIP_BACK, /*pos*/ 2385, 3589, 3727, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SUNKEN_SHIP, /*pos*/ 2385, 3589, 3727, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SUNKEN_SHIP_BACK, /*pos*/ 2385, 3589, 3727, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_LEFT_HALF_PART, /*pos*/ 5385, -5520, 2428, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart2, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_RIGHT_HALF_PART, /*pos*/ 5385, -5520, 2428, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvSunkenShipPart2, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 5385, -5520, 2428, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvInSunkenShip, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 5385, -5520, 2428, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvInSunkenShip, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 5385, -5520, 2428, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvInSunkenShip2, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_LEFT_HALF_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_BACK_LEFT_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_RIGHT_HALF_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_BACK_RIGHT_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_LEFT_HALF_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_BACK_LEFT_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_RIGHT_HALF_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SHIP_BACK_RIGHT_PART, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvShipPart3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 4880, 820, 2375, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvInSunkenShip3, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SLIDING_BOX, /*pos*/ 4668, 1434, 2916, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvJrbSlidingBox, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 6048, -5381, 1154, /*angle*/ 0, 340, 0, /*behParam*/ 0x00000000, /*beh*/ bhvUnagi, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 8270, -3130, 1846, /*angle*/ 0, 285, 0, /*behParam*/ 0x01010000, /*beh*/ bhvUnagi, /*acts*/ ACT_2),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 6048, -5381, 1154, /*angle*/ 0, 340, 0, /*behParam*/ 0x02020000, /*beh*/ bhvUnagi, /*acts*/ ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 4988, -5221, 2473, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvJetStream, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT(/*model*/ MODEL_NONE, /*pos*/ -1800, -2812, -2100, /*angle*/ 0, 0, 0, /*behParam*/ 0x02000000, /*beh*/ bhvTreasureChestsJrb),
OBJECT_WITH_ACTS(/*model*/ MODEL_JRB_SLIDING_BOX, /*pos*/ 4668, 1434, 2916, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvJrbSlidingBox, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 6048, -5381, 1154, /*angle*/ 0, 340, 0, /*behParam*/ 0x00000000, /*beh*/ bhvUnagi, /*acts*/ ACT_1),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 8270, -3130, 1846, /*angle*/ 0, 285, 0, /*behParam*/ 0x01010000, /*beh*/ bhvUnagi, /*acts*/ ACT_2),
OBJECT_WITH_ACTS(/*model*/ MODEL_UNAGI, /*pos*/ 6048, -5381, 1154, /*angle*/ 0, 340, 0, /*behParam*/ 0x02020000, /*beh*/ bhvUnagi, /*acts*/ ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT_WITH_ACTS(/*model*/ MODEL_NONE, /*pos*/ 4988, -5221, 2473, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvJetStream, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
OBJECT( /*model*/ MODEL_NONE, /*pos*/ -1800, -2812, -2100, /*angle*/ 0, 0, 0, /*behParam*/ 0x02000000, /*beh*/ bhvTreasureChestsJrb),
OBJECT_WITH_ACTS(/*model*/ MODEL_BOBOMB_BUDDY, /*pos*/ -1956, 1331, 6500, /*angle*/ 0, 0, 0, /*behParam*/ 0x00000000, /*beh*/ bhvBobombBuddyOpensCannon, /*acts*/ ACT_2 | ACT_3 | ACT_4 | ACT_5 | ACT_6),
RETURN(),
};

View File

@@ -22,7 +22,8 @@ int gSplineState;
/// Copy vector 'src' to 'dest'
void vec3f_copy(Vec3f dest, Vec3f src) {
vec3_copy(dest, src);
((u64 *) dest)[0] = ((u64 *) src)[0];
((u32 *) dest)[2] = ((u32 *) src)[2];
}
/// Set vector 'dest' to (x, y, z)
@@ -32,7 +33,16 @@ void vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) {
/// Add vector 'a' to 'dest'
void vec3f_add(Vec3f dest, Vec3f a) {
vec3_add(dest, a);
register f32 *temp = dest;
register s32 j;
register f32 sum, sum2;
for (j = 0; j < 3; j++) {
sum = *a;
a++;
sum2 = *temp;
temp++;
temp[-1] = (sum + sum2);
}
}
/// Make 'dest' the sum of vectors a and b.
@@ -135,7 +145,7 @@ void mtxf_identity(Mat4 mtx) {
*/
void mtxf_translate(Mat4 dest, Vec3f b) {
mtxf_identity(dest);
vec3_copy(dest[3], b);
vec3f_copy(dest[3], b);
}
/**
@@ -315,10 +325,10 @@ void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s32 yaw) {
vec3_cross(forwardDir, leftDir, upDir);
vec3f_normalize(forwardDir);
vec3_copy(dest[0], leftDir);
vec3_copy(dest[1], upDir);
vec3_copy(dest[2], forwardDir);
vec3_copy(dest[3], pos);
vec3f_copy(dest[0], leftDir);
vec3f_copy(dest[1], upDir);
vec3f_copy(dest[2], forwardDir);
vec3f_copy(dest[3], pos);
dest[0][3] = 0.0f;
dest[1][3] = 0.0f;
@@ -374,9 +384,9 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s32 yaw, f32 radius) {
vec3f_normalize(xColumn);
vec3_cross(zColumn, xColumn, yColumn);
vec3f_normalize(zColumn);
vec3_copy(mtx[0], xColumn);
vec3_copy(mtx[1], yColumn);
vec3_copy(mtx[2], zColumn);
vec3f_copy(mtx[0], xColumn);
vec3f_copy(mtx[1], yColumn);
vec3f_copy(mtx[2], zColumn);
mtx[3][0] = pos[0];
mtx[3][1] = (avgY < pos[1]) ? pos[1] : avgY;
@@ -861,7 +871,7 @@ s32 ray_surface_intersect(Vec3f orig, Vec3f dir, f32 dir_length, struct Surface
return FALSE;
}
// Successful contact
vec3_copy(add_dir, dir);
vec3f_copy(add_dir, dir);
vec3_mul_val(add_dir, *length);
vec3_sum(hit_pos, orig, add_dir);
return TRUE;
@@ -895,7 +905,7 @@ void find_surface_on_ray_list(struct SurfaceNode *list, Vec3f orig, Vec3f dir, f
if ((hit = ray_surface_intersect(orig, dir, dir_length, list->surface, chk_hit_pos, &length)) != 0) {
if (length <= *max_length) {
*hit_surface = list->surface;
vec3_copy(hit_pos, chk_hit_pos);
vec3f_copy(hit_pos, chk_hit_pos);
*max_length = length;
}
}
@@ -944,7 +954,7 @@ void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Ve
// Get normalized direction
dir_length = vec3f_length(dir);
max_length = dir_length;
vec3_copy(normalized_dir, dir);
vec3f_copy(normalized_dir, dir);
vec3f_normalize(normalized_dir);
// Get our cell coordinate

View File

@@ -312,7 +312,7 @@ static struct Surface *read_surface_data(TerrainData *vertexData, TerrainData **
nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
mag = sqrtf(nx * nx + ny * ny + nz * nz);
mag = sqrtf(sqr(nx) + sqr(ny) + sqr(nz));
// Could have used min_3 and max_3 for this...
minY = y1;

View File

@@ -3422,11 +3422,11 @@ Gfx *geo_camera_main(s32 callContext, struct GraphNode *g, void *context) {
}
void object_pos_to_vec3f(Vec3f dst, struct Object *o) {
vec3_copy(dst, &o->oPosVec);
vec3f_copy(dst, &o->oPosVec);
}
void vec3f_to_object_pos(struct Object *o, Vec3f src) {
vec3_copy(&o->oPosVec, src);
vec3f_copy(&o->oPosVec, src);
}
/**

View File

@@ -131,9 +131,9 @@ void func_80181EB0(struct Connection *cxn) {
/* @ 230858 -> 230B70 */
void func_80182088(struct Connection *cxn) {
struct GdVec3f sp4C;
struct GdVec3f vec;
f32 sp24;
f32 sp20;
f32 mag;
struct ObjParticle *sp1C;
struct ObjParticle *sp18;
@@ -143,32 +143,32 @@ void func_80182088(struct Connection *cxn) {
}
sp1C = cxn->node1.ptc;
sp18 = cxn->node2.ptc;
sp4C.x = sp1C->pos.x - sp18->pos.x;
sp4C.y = sp1C->pos.y - sp18->pos.y;
sp4C.z = sp1C->pos.z - sp18->pos.z;
sp20 = gd_vec3f_magnitude(&sp4C);
sp24 = sp20 - cxn->unk24;
sp4C.x /= sp20;
sp4C.y /= sp20;
sp4C.z /= sp20;
sp4C.x *= sp24 * 0.1;
sp4C.y *= sp24 * 0.1;
sp4C.z *= sp24 * 0.1;
sp1C->unk38.x -= sp4C.x;
sp1C->unk38.y -= sp4C.y;
sp1C->unk38.z -= sp4C.z;
sp18->unk38.x += sp4C.x;
sp18->unk38.y += sp4C.y;
sp18->unk38.z += sp4C.z;
vec.x = sp1C->pos.x - sp18->pos.x;
vec.y = sp1C->pos.y - sp18->pos.y;
vec.z = sp1C->pos.z - sp18->pos.z;
mag = gd_vec3f_magnitude(&vec);
sp24 = mag - cxn->unk24;
vec.x /= mag;
vec.y /= mag;
vec.z /= mag;
vec.x *= sp24 * 0.1;
vec.y *= sp24 * 0.1;
vec.z *= sp24 * 0.1;
sp1C->unk38.x -= vec.x;
sp1C->unk38.y -= vec.y;
sp1C->unk38.z -= vec.z;
sp18->unk38.x += vec.x;
sp18->unk38.y += vec.y;
sp18->unk38.z += vec.z;
if (!(sp1C->flags & 2)) {
sp1C->pos.x -= sp4C.x;
sp1C->pos.y -= sp4C.y;
sp1C->pos.z -= sp4C.z;
sp1C->pos.x -= vec.x;
sp1C->pos.y -= vec.y;
sp1C->pos.z -= vec.z;
}
if (!(sp18->flags & 2)) {
sp18->pos.x += sp4C.x;
sp18->pos.y += sp4C.y;
sp18->pos.z += sp4C.z;
sp18->pos.x += vec.x;
sp18->pos.y += vec.y;
sp18->pos.z += vec.z;
}
}