From c96118bcd8641231f0cb7ccc9fe826aa3c87a75e Mon Sep 17 00:00:00 2001 From: arthurtilly <32559225+arthurtilly@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:03:08 +1300 Subject: [PATCH] Fix objects using throwmatrix having incorrect rotation when paused (#769) * throwmatrix fix * ok fixed it and removed some cringe matching * happy bitch --- src/game/obj_behaviors.c | 28 ++++++++++------------------ src/game/rendering_graph_node.c | 4 +++- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index 0e83b4b3..6fbb7fdd 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -187,8 +187,6 @@ s8 turn_obj_away_from_steep_floor(struct Surface *objFloor, f32 floorY, f32 objV void obj_orient_graph(struct Object *obj, f32 normalX, f32 normalY, f32 normalZ) { Vec3f objVisualPosition, surfaceNormals; - Mat4 *throwMatrix; - // Passes on orienting certain objects that shouldn't be oriented, like boulders. if (!sOrientObjWithFloor) { return; @@ -199,17 +197,11 @@ void obj_orient_graph(struct Object *obj, f32 normalX, f32 normalY, f32 normalZ) return; } - throwMatrix = alloc_display_list(sizeof(*throwMatrix)); - // If out of memory, fail to try orienting the object. - if (throwMatrix == NULL) { - return; - } - vec3f_copy_y_off(objVisualPosition, &obj->oPosVec, obj->oGraphYOffset); vec3f_set(surfaceNormals, normalX, normalY, normalZ); - mtxf_align_terrain_normal(*throwMatrix, surfaceNormals, objVisualPosition, obj->oFaceAngleYaw); - obj->header.gfx.throwMatrix = throwMatrix; + mtxf_align_terrain_normal(obj->transform, surfaceNormals, objVisualPosition, obj->oFaceAngleYaw); + obj->header.gfx.throwMatrix = &obj->transform; } /** @@ -255,10 +247,7 @@ void calc_new_obj_vel_and_pos_y(struct Surface *objFloor, f32 objFloorY, f32 obj } } - //! (Obj Position Crash) If you got an object with height past 2^31, the game would crash. - if ((s32) o->oPosY >= (s32) objFloorY && (s32) o->oPosY < (s32) objFloorY + 37) { - obj_orient_graph(o, floor_nX, floor_nY, floor_nZ); - + if ((o->oPosY >= objFloorY) && (o->oPosY < objFloorY + 37)) { // Adds horizontal component of gravity for horizontal speed. f32 nxz = sqr(floor_nX) + sqr(floor_nZ); f32 vel = ((nxz) / (nxz + sqr(floor_nY))) * o->oGravity * 2; @@ -312,9 +301,7 @@ void calc_new_obj_vel_and_pos_y_underwater(struct Surface *objFloor, f32 floorY, o->oVelY = -o->oVelY; } - if ((s32) o->oPosY >= (s32) floorY && (s32) o->oPosY < (s32) floorY + 37) { - obj_orient_graph(o, floor_nX, floor_nY, floor_nZ); - + if ((o->oPosY >= floorY) && (o->oPosY < floorY + 37)) { // Adds horizontal component of gravity for horizontal speed. f32 nxz = sqr(floor_nX) + sqr(floor_nZ); f32 velm = (nxz / (nxz + sqr(floor_nY))) * netYAccel * 2; @@ -411,6 +398,11 @@ s16 object_step(void) { } obj_update_pos_vel_xz(); + + if (sObjFloor && (o->oPosY >= floorY) && (o->oPosY < floorY + 37)) { + obj_orient_graph(o, sObjFloor->normal.x, sObjFloor->normal.y, sObjFloor->normal.z); + } + if ((s32) o->oPosY == (s32) floorY) { collisionFlags += OBJ_COL_FLAG_GROUNDED; } @@ -420,7 +412,7 @@ s16 object_step(void) { } // Generate a splash if in water. - obj_splash((s32) waterY, (s32) o->oPosY); + obj_splash(waterY, o->oPosY); return collisionFlags; } diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 44a902dd..cb0d62cb 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -1039,6 +1039,8 @@ void geo_process_object(struct Object *node) { if (node->header.gfx.areaIndex == gCurGraphNodeRoot->areaIndex) { s32 isInvisible = (node->header.gfx.node.flags & GRAPH_RENDER_INVISIBLE); s32 noThrowMatrix = (node->header.gfx.throwMatrix == NULL); + // Maintain throw matrix pointer if the game is paused as it won't be updated. + Mat4 *oldThrowMatrix = (sCurrPlayMode == PLAY_MODE_PAUSED) ? node->header.gfx.throwMatrix : NULL; // If the throw matrix is null and the object is invisible, there is no need // to update billboarding, scale, rotation, etc. @@ -1087,7 +1089,7 @@ void geo_process_object(struct Object *node) { gMatStackIndex--; gCurrAnimType = ANIM_TYPE_NONE; - node->header.gfx.throwMatrix = NULL; + node->header.gfx.throwMatrix = oldThrowMatrix; } }