From 9cf7439b78a7f064cb79962784e3ca746ff4cfba Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Wed, 7 Jan 2026 14:10:07 -0600 Subject: [PATCH] Some interpolation fixes --- src/engine/graph_node.h | 1 + src/engine/math_util.c | 2 +- src/game/camera.c | 4 +++- src/game/rendering_graph_node.c | 4 ++-- src/port/game/GeoLayoutParser.cpp | 7 +++++++ src/port/interpolation/FrameInterpolation.cpp | 9 ++++++++- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index 65694b33..8dd7b10f 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -92,6 +92,7 @@ struct GraphNodeRoot { /*0x1C*/ s16 height; // half height /*0x1E*/ s16 numViews; // number of entries in mystery array /*0x20*/ struct GraphNode **views; + u64 nodeId; }; /** A node that sets up an orthographic projection based on the global diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 799bb1e6..86782b7e 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -185,7 +185,7 @@ void mtxf_identity(Mat4 mtx) { */ void mtxf_translate(Mat4 dest, Vec3f b) { // TODO: FrameInterpolation is broken, fix it - // FrameInterpolation_RecordMatrixTranslate(dest, b); + FrameInterpolation_RecordMatrixTranslate(dest, b); mtxf_identity(dest); dest[3][0] = b[0]; dest[3][1] = b[1]; diff --git a/src/game/camera.c b/src/game/camera.c index 76e785c3..ed67d0b7 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -28,6 +28,7 @@ #include "paintings.h" #include "engine/graph_node.h" #include "level_table.h" +#include "port/interpolation/FrameInterpolation.h" #define CBUTTON_MASK (U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS) @@ -3510,11 +3511,12 @@ void create_camera(struct GraphNodeCamera *gc, struct AllocOnlyPool *pool) { void update_graph_node_camera(struct GraphNodeCamera *gc) { UNUSED u8 filler[8]; UNUSED struct Camera *c = gc->config.camera; - + FrameInterpolation_ShouldInterpolateFrame(sFramesPaused == 0); gc->rollScreen = gLakituState.roll; vec3f_copy(gc->pos, gLakituState.pos); vec3f_copy(gc->focus, gLakituState.focus); zoom_out_if_paused_and_outside(gc); + FrameInterpolation_ShouldInterpolateFrame(true); } Gfx *geo_camera_main(s32 callContext, struct GraphNode *g, void *context) { diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 32429b5a..08e9bcf9 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -364,7 +364,7 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation Mat4 mtxf; Vec3f translation; Mtx *mtx = alloc_display_list(sizeof(*mtx)); - FrameInterpolation_RecordOpenChild("geo_process_translation_rotation", (uintptr_t)node); + FrameInterpolation_RecordOpenChild("geo_process_translation_rotation", TAG_OBJECT(node)); vec3s_to_vec3f(translation, node->translation); mtxf_rotate_zxy_and_translate(mtxf, translation, node->rotation); @@ -1102,7 +1102,7 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) UNUSED s32 unused; if (node->node.flags & GRAPH_RENDER_ACTIVE) { - FrameInterpolation_RecordOpenChild("geo_process_root", (uintptr_t)node); + FrameInterpolation_RecordOpenChild("geo_process_root", (uintptr_t)node->nodeId); Mtx *initialMatrix; Vp *viewport = alloc_display_list(sizeof(*viewport)); diff --git a/src/port/game/GeoLayoutParser.cpp b/src/port/game/GeoLayoutParser.cpp index a3c10c6e..bd602e62 100644 --- a/src/port/game/GeoLayoutParser.cpp +++ b/src/port/game/GeoLayoutParser.cpp @@ -288,6 +288,12 @@ void process_cmd_update_node_flags() { } } +uint64_t generate_uuid64() { + uint64_t high = rand(); + uint64_t low = rand(); + return (high << 32) | low; +} + void process_cmd_node_root() { gGeoNumViews = GeoLayoutParser::mReader->ReadInt16() + 2; const auto x = GeoLayoutParser::mReader->ReadInt16(); @@ -299,6 +305,7 @@ void process_cmd_node_root() { gGeoViews = static_cast(alloc_only_pool_alloc(gGraphNodePool, gGeoNumViews * sizeof(GraphNode *))); + graphNode->nodeId = generate_uuid64(); graphNode->views = gGeoViews; graphNode->numViews = gGeoNumViews; diff --git a/src/port/interpolation/FrameInterpolation.cpp b/src/port/interpolation/FrameInterpolation.cpp index beb61d27..9e15fad5 100644 --- a/src/port/interpolation/FrameInterpolation.cpp +++ b/src/port/interpolation/FrameInterpolation.cpp @@ -297,6 +297,13 @@ struct InterpolateCtx { } } + void translate_mtxf(Mat4 dest, Vec3f b) { + mtxf_identity(dest); + dest[3][0] = b[0]; + dest[3][1] = b[1]; + dest[3][2] = b[2]; + } + float lerp(f32 o, f32 n) { return w * o + step * n; } @@ -436,7 +443,7 @@ struct InterpolateCtx { temp[1] = lerp(old_op.matrix_translate.b.y, new_op.matrix_translate.b.y); temp[2] = lerp(old_op.matrix_translate.b.z, new_op.matrix_translate.b.z); - mtxf_translate(*gInterpolationMatrix, temp); + translate_mtxf(*gInterpolationMatrix, temp); break; case Op::MatrixPosRotXYZ: { Vec3f tempF;