diff --git a/enhancements/60fps_alpha.patch b/enhancements/60fps_alpha.patch index ab96e42a..578ce1c0 100644 --- a/enhancements/60fps_alpha.patch +++ b/enhancements/60fps_alpha.patch @@ -1,21 +1,15 @@ diff --git a/include/types.h b/include/types.h -index b3dc27e..c46bdf0 100644 +index b3dc27e2..c46bdf01 100644 --- a/include/types.h +++ b/include/types.h -@@ -118,6 +118,10 @@ struct GraphNodeObject_sub - /*0x0A 0x42*/ u16 animTimer; - /*0x0C 0x44*/ s32 animFrameAccelAssist; +@@ -120,2 +120,6 @@ struct GraphNodeObject_sub /*0x10 0x48*/ s32 animAccel; + s16 prevAnimFrame; + s16 prevAnimID; + u32 prevAnimFrameTimestamp; + struct Animation *prevAnimPtr; }; - - struct GraphNodeObject -@@ -128,11 +132,22 @@ struct GraphNodeObject - /*0x19*/ s8 unk19; - /*0x1A*/ Vec3s angle; +@@ -130,3 +134,10 @@ struct GraphNodeObject /*0x20*/ Vec3f pos; + Vec3s prevAngle; + Vec3f prevPos; @@ -25,8 +19,8 @@ index b3dc27e..c46bdf0 100644 /*0x2C*/ Vec3f scale; + Vec3f prevScale; + u32 prevScaleTimestamp; - /*0x38*/ struct GraphNodeObject_sub unk38; - /*0x4C*/ struct SpawnInfo *unk4C; + /*0x38*/ struct GraphNodeObject_sub curAnim; +@@ -134,3 +145,7 @@ struct GraphNodeObject /*0x50*/ Mat4 *throwMatrix; // matrix ptr + Mat4 prevThrowMatrix; + u32 prevThrowMatrixTimestamp; @@ -34,45 +28,29 @@ index b3dc27e..c46bdf0 100644 /*0x54*/ Vec3f cameraToObject; + u32 skipInterpolationTimestamp; }; - - struct ObjectNode -@@ -243,6 +258,10 @@ struct Surface - } normal; - /*0x28*/ f32 originOffset; +@@ -245,2 +260,6 @@ struct Surface /*0x2C*/ struct Object *object; + Vec3s prevVertex1; + Vec3s prevVertex2; + Vec3s prevVertex3; + u32 modifiedTimestamp; }; - - struct MarioBodyState diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h -index 802d97a..1b0d677 100644 +index 802d97a8..1b0d6772 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h -@@ -110,6 +110,8 @@ struct GraphNodePerspective - /*0x1C*/ f32 fov; // horizontal field of view in degrees - /*0x20*/ s16 near; // near clipping plane +@@ -112,2 +112,4 @@ struct GraphNodePerspective /*0x22*/ s16 far; // far clipping plane + f32 prevFov; + f32 prevTimestamp; }; - - /** An entry in the master list. It is a linked list of display lists -@@ -118,7 +120,9 @@ struct GraphNodePerspective - struct DisplayListNode - { +@@ -120,3 +122,5 @@ struct DisplayListNode Mtx *transform; + void *transformInterpolated; void *displayList; + void *displayListInterpolated; struct DisplayListNode *next; - }; - -@@ -185,7 +189,11 @@ struct GraphNodeCamera - } config; - /*0x1C*/ Vec3f pos; +@@ -187,3 +191,7 @@ struct GraphNodeCamera /*0x28*/ Vec3f focus; + Vec3f prevPos; + Vec3f prevFocus; @@ -80,77 +58,50 @@ index 802d97a..1b0d677 100644 /*0x34*/ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4 + Mat4 *matrixPtrInterpolated; /*0x38*/ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen. - /*0x3A*/ s16 rollScreen; // rolls screen while keeping the light direction consistent - }; -@@ -226,7 +234,8 @@ struct GraphNodeRotation - /*0x00*/ struct GraphNode node; - /*0x14*/ void *displayList; +@@ -228,3 +236,4 @@ struct GraphNodeRotation /*0x18*/ Vec3s rotation; - u8 pad1E[2]; + Vec3s prevRotation; + u32 prevTimestamp; }; - - /** GraphNode part that transforms itself and its children based on animation -@@ -323,6 +332,9 @@ struct GraphNodeBackground - /*0x00*/ struct FnGraphNode fnNode; - /*0x18*/ s32 unused; +@@ -325,2 +334,5 @@ struct GraphNodeBackground /*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null + Vec3f prevCameraPos; + Vec3f prevCameraFocus; + u32 prevCameraTimestamp; }; - - /** Renders the object that Mario is holding. -@@ -333,6 +345,8 @@ struct GraphNodeHeldObject - /*0x18*/ s32 playerIndex; - /*0x1C*/ struct Object *objNode; +@@ -335,2 +347,4 @@ struct GraphNodeHeldObject /*0x20*/ Vec3s translation; + Vec3f prevShadowPos; + u32 prevShadowPosTimestamp; }; - - /** A node that allows an object to specify a different culling radius than the diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c -index 5b6775f..2c11e25 100644 +index 5b6775fe..2c11e254 100644 --- a/src/engine/surface_collision.c +++ b/src/engine/surface_collision.c -@@ -8,6 +8,7 @@ - #include "surface_collision.h" - #include "surface_load.h" +@@ -10,2 +10,3 @@ #include "math_util.h" +#include "game/game_init.h" - /************************************************** - * WALLS * -@@ -394,26 +395,44 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometr - return floorHeight; - } +@@ -396,2 +397,4 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometr +u8 gInterpolatingSurfaces; + /** - * Iterate through the list of floors and find the first floor under a given point. - */ - static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) { +@@ -401,3 +404,3 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 register struct Surface *surf; - register s32 x1, z1, x2, z2, x3, z3; + register f32 x1, z1, x2, z2, x3, z3; f32 nx, ny, nz; - f32 oo; - f32 height; +@@ -406,2 +409,3 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 struct Surface *floor = NULL; + s32 interpolate; - // Iterate through the list of floors until there are no more floors. - while (surfaceNode != NULL) { - surf = surfaceNode->surface; +@@ -411,2 +415,3 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 surfaceNode = surfaceNode->next; + interpolate = gInterpolatingSurfaces && surf->modifiedTimestamp == gGlobalTimer; - x1 = surf->vertex1[0]; - z1 = surf->vertex1[2]; - x2 = surf->vertex2[0]; +@@ -416,2 +421,16 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 z2 = surf->vertex2[2]; + if (interpolate) { + f32 diff = (surf->prevVertex1[0] - x1) * (surf->prevVertex1[0] - x1); @@ -167,22 +118,14 @@ index 5b6775f..2c11e25 100644 + } + } - // Check that the point is within the triangle bounds. - if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) { -@@ -423,6 +442,10 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 - // To slightly save on computation time, set this later. - x3 = surf->vertex3[0]; +@@ -425,2 +444,6 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 z3 = surf->vertex3[2]; + if (interpolate) { + x3 = (surf->prevVertex3[0] + x3) / 2; + z3 = (surf->prevVertex3[2] + z3) / 2; + } - if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) { - continue; -@@ -442,10 +465,30 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 - continue; - } +@@ -444,6 +467,26 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 - nx = surf->normal.x; - ny = surf->normal.y; @@ -213,11 +156,7 @@ index 5b6775f..2c11e25 100644 + oo = surf->originOffset; + } - // If a wall, ignore it. Likely a remnant, should never occur. - if (ny == 0.0f) { -@@ -460,6 +503,15 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 - } - +@@ -462,2 +505,11 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 *pheight = height; + if (interpolate) { + static struct Surface s; @@ -229,23 +168,15 @@ index 5b6775f..2c11e25 100644 + return &s; + } floor = surf; - break; - } diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c -index ac2ee50..323b7d0 100644 +index ac2ee50c..323b7d05 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c -@@ -14,6 +14,7 @@ - #include "game/mario.h" - #include "game/object_list_processor.h" +@@ -16,2 +16,3 @@ #include "surface_load.h" +#include "game/game_init.h" - s32 unused8038BE90; - -@@ -359,6 +360,11 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) { - - surface = alloc_surface(); +@@ -361,2 +362,7 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) { + vec3s_copy(surface->prevVertex1, surface->vertex1); + vec3s_copy(surface->prevVertex2, surface->vertex2); @@ -253,147 +184,75 @@ index ac2ee50..323b7d0 100644 + surface->modifiedTimestamp = gGlobalTimer; + surface->vertex1[0] = x1; - surface->vertex2[0] = x2; - surface->vertex3[0] = x3; diff --git a/src/game/camera.c b/src/game/camera.c -index bde0662..9351dea 100644 +index bde06626..aa65c00b 100644 --- a/src/game/camera.c +++ b/src/game/camera.c -@@ -484,6 +484,10 @@ CameraTransition sModeTransitions[] = { - extern u8 sDanceCutsceneIndexTable[][4]; - extern u8 sZoomOutAreaMasks[]; +@@ -486,2 +486,6 @@ extern u8 sZoomOutAreaMasks[]; +static void skip_camera_interpolation(void) { + gLakituState.skipCameraInterpolationTimestamp = gGlobalTimer; +} + /** - * Starts a camera shake triggered by an interaction - */ -@@ -5552,6 +5556,7 @@ s32 set_camera_mode_fixed(struct Camera *c, s16 x, s16 y, s16 z) { - c->mode = CAMERA_MODE_FIXED; - vec3f_set(c->pos, sFixedModeBasePosition[0], sMarioCamState->pos[1], +@@ -5554,2 +5558,3 @@ s32 set_camera_mode_fixed(struct Camera *c, s16 x, s16 y, s16 z) { sFixedModeBasePosition[2]); + skip_camera_interpolation(); } - return basePosSet; - } -@@ -5714,6 +5719,7 @@ BAD_RETURN(s32) cam_rr_enter_building_side(struct Camera *c) { - if (c->mode != CAMERA_MODE_FIXED) { - sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT; +@@ -5716,2 +5721,3 @@ BAD_RETURN(s32) cam_rr_enter_building_side(struct Camera *c) { c->mode = CAMERA_MODE_FIXED; + skip_camera_interpolation(); } - } - -@@ -5909,6 +5915,7 @@ BAD_RETURN(s32) cam_castle_enter_lobby(struct Camera *c) { - sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT; - set_fixed_cam_axis_sa_lobby(c->mode); +@@ -5911,2 +5917,3 @@ BAD_RETURN(s32) cam_castle_enter_lobby(struct Camera *c) { c->mode = CAMERA_MODE_FIXED; + skip_camera_interpolation(); } - } - -@@ -7279,6 +7286,7 @@ BAD_RETURN(s32) cutscene_unused_loop(UNUSED struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_mario_fall_start(struct Camera *c) { - vec3f_set(c->focus, -26.f, 0.f, -137.f); +@@ -7281,2 +7288,3 @@ BAD_RETURN(s32) cutscene_ending_mario_fall_start(struct Camera *c) { vec3f_set(c->pos, 165.f, 4725.f, 324.f); + skip_camera_interpolation(); } - - /** -@@ -7311,6 +7319,7 @@ BAD_RETURN(s32) cutscene_ending_mario_fall(struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) { - vec3f_set(c->focus, 85.f, 826.f, 250.f); +@@ -7313,2 +7321,3 @@ BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) { vec3f_set(c->pos, -51.f, 988.f, -202.f); + skip_camera_interpolation(); player2_rotate_cam(c, -0x2000, 0x2000, -0x2000, 0x2000); - } - -@@ -7320,6 +7329,7 @@ BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_reset_spline(UNUSED struct Camera *c) { - sCutsceneVars[9].point[0] = 0.f; +@@ -7322,2 +7331,3 @@ BAD_RETURN(s32) cutscene_ending_reset_spline(UNUSED struct Camera *c) { cutscene_reset_spline(); + skip_camera_interpolation(); } - - /** -@@ -7355,6 +7365,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appear_closeup(struct Camera *c) { - vec3f_set(c->pos, 179.f, 2463.f, -1216.f); - c->pos[1] = gCutsceneFocus->oPosY + 35.f; +@@ -7357,2 +7367,3 @@ BAD_RETURN(s32) cutscene_ending_peach_appear_closeup(struct Camera *c) { vec3f_set(c->focus, gCutsceneFocus->oPosX, gCutsceneFocus->oPosY + 125.f, gCutsceneFocus->oPosZ); + skip_camera_interpolation(); } - - /** -@@ -7373,6 +7384,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appears(struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_peach_descends_start(UNUSED struct Camera *c) { - cutscene_reset_spline(); +@@ -7375,2 +7386,3 @@ BAD_RETURN(s32) cutscene_ending_peach_descends_start(UNUSED struct Camera *c) { sCutsceneVars[2].point[1] = 150.f; + skip_camera_interpolation(); } - - /** -@@ -7459,6 +7471,7 @@ BAD_RETURN(s32) cutscene_ending_peach_wakeup(struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_dialog(struct Camera *c) { - vec3f_set(c->focus, 11.f, 983.f, -1273.f); +@@ -7461,2 +7473,3 @@ BAD_RETURN(s32) cutscene_ending_dialog(struct Camera *c) { vec3f_set(c->pos, -473.f, 970.f, -1152.f); + skip_camera_interpolation(); player2_rotate_cam(c, -0x800, 0x2000, -0x2000, 0x2000); - } - -@@ -7469,6 +7482,7 @@ BAD_RETURN(s32) cutscene_ending_kiss_closeup(struct Camera *c) { - set_fov_function(CAM_FOV_SET_29); - vec3f_set(c->focus, 350.f, 1034.f, -1216.f); +@@ -7471,2 +7484,3 @@ BAD_RETURN(s32) cutscene_ending_kiss_closeup(struct Camera *c) { vec3f_set(c->pos, -149.f, 1021.f, -1216.f); + skip_camera_interpolation(); } - - /** -@@ -7504,6 +7518,7 @@ BAD_RETURN(s32) cutscene_ending_kiss(struct Camera *c) { - BAD_RETURN(s32) cutscene_ending_look_at_sky(struct Camera *c) { - move_point_along_spline(c->focus, sEndingLookAtSkyFocus, &sCutsceneSplineSegment, &sCutsceneSplineSegmentProgress); - vec3f_set(c->pos, 699.f, 1680.f, -703.f); -+ skip_camera_interpolation(); - } - - /** -@@ -10340,6 +10355,7 @@ BAD_RETURN(s32) cutscene_door_start(struct Camera *c) { - BAD_RETURN(s32) cutscene_door_fix_cam(struct Camera *c) { - vec3f_copy(c->pos, sCutsceneVars[0].point); - vec3f_copy(c->focus, sCutsceneVars[1].point); -+ skip_camera_interpolation(); - } - - /** -@@ -10373,6 +10389,7 @@ BAD_RETURN(s32) cutscene_door_move_behind_mario(struct Camera *c) { - } - +@@ -10375,2 +10389,3 @@ BAD_RETURN(s32) cutscene_door_move_behind_mario(struct Camera *c) { offset_rotated(c->pos, sMarioCamState->pos, camOffset, sCutsceneVars[0].angle); + skip_camera_interpolation(); } - - /** diff --git a/src/game/camera.h b/src/game/camera.h -index 173ab8a..b1abdc4 100644 +index 173ab8a7..b1abdc4f 100644 --- a/src/game/camera.h +++ b/src/game/camera.h -@@ -657,6 +657,8 @@ struct LakituState - /// Mario's action from the previous frame. Only used to determine if Mario just finished a dive. - /*0xB8*/ u32 lastFrameAction; +@@ -659,2 +659,4 @@ struct LakituState /*0xBC*/ s16 unused; + + u32 skipCameraInterpolationTimestamp; }; - - // bss order hack to not affect BSS order. if possible, remove me, but it will be hard to match otherwise diff --git a/src/game/envfx_bubbles.c b/src/game/envfx_bubbles.c -index 16a9272..ee1b029 100644 +index 16a92720..ee1b029d 100644 --- a/src/game/envfx_bubbles.c +++ b/src/game/envfx_bubbles.c -@@ -35,6 +35,20 @@ Vtx_t gBubbleTempVtx[3] = { - { { 0, 0, 0 }, 0, { -498, 964 }, { 0xFF, 0xFF, 0xFF, 0xFF } }, - }; +@@ -37,2 +37,16 @@ Vtx_t gBubbleTempVtx[3] = { +static Gfx sGfxSaved[60 / 5]; +static Gfx *sBubbleInterpolatedDisplayListPos[60 / 5]; @@ -410,27 +269,15 @@ index 16a9272..ee1b029 100644 +} + /** - * Check whether the particle with the given index is - * laterally within distance of point (x, z). Used to -@@ -241,6 +255,7 @@ void envfx_update_whirlpool(void) { - (gEnvFxBuffer + i)->yPos = (i + gEnvFxBuffer)->bubbleY; - (gEnvFxBuffer + i)->unusedBubbleVar = 0; +@@ -243,2 +257,3 @@ void envfx_update_whirlpool(void) { (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer; - envfx_rotate_around_whirlpool(&(gEnvFxBuffer + i)->xPos, &(gEnvFxBuffer + i)->yPos, - &(gEnvFxBuffer + i)->zPos); -@@ -299,6 +314,7 @@ void envfx_update_jetstream(void) { - + coss((gEnvFxBuffer + i)->angleAndDist[0]) * (gEnvFxBuffer + i)->angleAndDist[1]; - (gEnvFxBuffer + i)->yPos = +@@ -301,2 +316,3 @@ void envfx_update_jetstream(void) { gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] + (random_float() * 400.0f - 200.0f); + (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer; } else { - (gEnvFxBuffer + i)->angleAndDist[1] += 10; - (gEnvFxBuffer + i)->xPos += sins((gEnvFxBuffer + i)->angleAndDist[0]) * 10.0f; -@@ -506,6 +522,12 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro - Vec3s vertex1; - Vec3s vertex2; +@@ -508,2 +524,8 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro Vec3s vertex3; + Vec3s interpolatedVertices[3]; + @@ -439,11 +286,7 @@ index 16a9272..ee1b029 100644 + static Vec3s prevVertex3; + static u32 prevTimestamp; - Gfx *gfxStart; - -@@ -521,18 +543,52 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro - envfx_bubbles_update_switch(mode, camTo, vertex1, vertex2, vertex3); - rotate_triangle_vertices(vertex1, vertex2, vertex3, pitch, yaw); +@@ -523,2 +545,12 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro + if (gGlobalTimer == prevTimestamp + 1) { + interpolate_vectors_s16(interpolatedVertices[0], prevVertex1, vertex1); @@ -456,7 +299,7 @@ index 16a9272..ee1b029 100644 + prevTimestamp = gGlobalTimer; + gSPDisplayList(sGfxCursor++, &tiny_bubble_dl_0B006D38); - +@@ -526,5 +558,24 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro for (i = 0; i < sBubbleParticleMaxCount; i += 5) { + Vtx *interpolatedVertBuf = alloc_display_list(15 * sizeof(Vtx)); + s32 j, k; @@ -482,10 +325,7 @@ index 16a9272..ee1b029 100644 + gSPVertex(sGfxCursor++, VIRTUAL_TO_PHYSICAL(interpolatedVertBuf), 15, 0); + append_bubble_vertex_buffer(&sGfxSaved[i / 5], i, vertex1, vertex2, vertex3, (Vtx *) gBubbleTempVtx); gSP1Triangle(sGfxCursor++, 0, 1, 2, 0); - gSP1Triangle(sGfxCursor++, 3, 4, 5, 0); - gSP1Triangle(sGfxCursor++, 6, 7, 8, 0); - gSP1Triangle(sGfxCursor++, 9, 10, 11, 0); - gSP1Triangle(sGfxCursor++, 12, 13, 14, 0); +@@ -535,2 +586,7 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro } + for (i = 0; i < sBubbleParticleMaxCount; i++) { + sPrevBubblePositions[i][0] = gEnvFxBuffer[i].xPos; @@ -493,15 +333,11 @@ index 16a9272..ee1b029 100644 + sPrevBubblePositions[i][2] = gEnvFxBuffer[i].zPos; + } - gSPDisplayList(sGfxCursor++, &tiny_bubble_dl_0B006AB0); - gSPEndDisplayList(sGfxCursor++); diff --git a/src/game/envfx_snow.c b/src/game/envfx_snow.c -index c3c14a5..d2212ef 100644 +index c3c14a5c..d2212ef6 100644 --- a/src/game/envfx_snow.c +++ b/src/game/envfx_snow.c -@@ -54,6 +54,26 @@ extern void *tiny_bubble_dl_0B006AB0; - extern void *tiny_bubble_dl_0B006A50; - extern void *tiny_bubble_dl_0B006CD8; +@@ -56,2 +56,22 @@ extern void *tiny_bubble_dl_0B006CD8; +static struct { + Gfx *pos; @@ -524,44 +360,24 @@ index c3c14a5..d2212ef 100644 +} + /** - * Initialize snow particles by allocating a buffer for storing their state - * and setting a start amount. -@@ -217,6 +237,7 @@ void envfx_update_snow_normal(s32 snowCylinderX, s32 snowCylinderY, s32 snowCyli - 400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2); - (gEnvFxBuffer + i)->yPos = 200.0f * random_float() + snowCylinderY; +@@ -219,2 +239,3 @@ void envfx_update_snow_normal(s32 snowCylinderX, s32 snowCylinderY, s32 snowCyli (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer; } else { - (gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2); - (gEnvFxBuffer + i)->yPos -= 2 -(s16)(deltaY * 0.8); -@@ -251,6 +272,7 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy - 400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2); - (gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY; +@@ -253,2 +274,3 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer; } else { - (gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2) + 20.0f; - (gEnvFxBuffer + i)->yPos -= 5 -(s16)(deltaY * 0.8); -@@ -294,6 +316,7 @@ void envfx_update_snow_water(s32 snowCylinderX, s32 snowCylinderY, s32 snowCylin - (gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ; - (gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY; +@@ -296,2 +318,3 @@ void envfx_update_snow_water(s32 snowCylinderX, s32 snowCylinderY, s32 snowCylin (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer; } - } - } -@@ -346,6 +369,8 @@ void rotate_triangle_vertices(Vec3s vertex1, Vec3s vertex2, Vec3s vertex3, s16 p - void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s vertex2, Vec3s vertex3) { - s32 i = 0; +@@ -348,2 +371,4 @@ void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s ve Vtx *vertBuf = (Vtx *) alloc_display_list(15 * sizeof(Vtx)); + Vtx *vertBufInterpolated = (Vtx *) alloc_display_list(15 * sizeof(Vtx)); + Vtx *v; #ifdef VERSION_EU - Vtx *p; - #endif -@@ -395,7 +420,23 @@ void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s ve - #endif - } +@@ -397,3 +422,19 @@ void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s ve - gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBuf), 15, 0); + for (i = 0; i < 15; i++) { @@ -582,38 +398,26 @@ index c3c14a5..d2212ef 100644 + sPrevSnowVertices[index / 5].pos = gfx; + gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBufInterpolated), 15, 0); } - - /** -@@ -479,6 +520,8 @@ Gfx *envfx_update_snow(s32 snowMode, Vec3s marioPos, Vec3s camFrom, Vec3s camTo) - gSP1Triangle(gfx++, 9, 10, 11, 0); - gSP1Triangle(gfx++, 12, 13, 14, 0); +@@ -481,2 +522,4 @@ Gfx *envfx_update_snow(s32 snowMode, Vec3s marioPos, Vec3s camFrom, Vec3s camTo) } + sPrevSnowParticleCount = gSnowParticleCount; + sPrevSnowTimestamp = gGlobalTimer; - gSPDisplayList(gfx++, &tiny_bubble_dl_0B006AB0) gSPEndDisplayList(gfx++); - diff --git a/src/game/envfx_snow.h b/src/game/envfx_snow.h -index 7a83b53..f4acc2d 100644 +index 7a83b536..f4acc2de 100644 --- a/src/game/envfx_snow.h +++ b/src/game/envfx_snow.h -@@ -25,7 +25,8 @@ struct EnvFxParticle { - s32 angleAndDist[2]; // for whirpools, [0] = angle from center, [1] = distance from center - s32 unusedBubbleVar; // set to zero for bubbles when respawning, never used elsewhere +@@ -27,3 +27,4 @@ struct EnvFxParticle { s32 bubbleY; // for Bubbles, yPos is always set to this - s8 filler20[56 - 0x20]; + //s8 filler20[56 - 0x20]; + u32 spawnTimestamp; }; - - extern s8 gEnvFxMode; diff --git a/src/game/hud.c b/src/game/hud.c -index 1540b67..0de6e0b 100644 +index 1540b675..0de6e0bb 100644 --- a/src/game/hud.c +++ b/src/game/hud.c -@@ -59,6 +59,20 @@ static struct UnusedHUDStruct sUnusedHUDValues = { 0x00, 0x0A, 0x00 }; - - static struct CameraHUD sCameraHUD = { CAM_STATUS_NONE }; +@@ -61,2 +61,16 @@ static struct CameraHUD sCameraHUD = { CAM_STATUS_NONE }; +static u32 sPowerMeterLastRenderTimestamp; +static s16 sPowerMeterLastY; @@ -630,19 +434,11 @@ index 1540b67..0de6e0b 100644 +} + /** - * Renders a rgba16 16x16 glyph texture from a table list. - */ -@@ -111,6 +125,7 @@ void render_power_meter_health_segment(s16 numHealthWedges) { - */ - void render_dl_power_meter(s16 numHealthWedges) { +@@ -113,2 +127,3 @@ void render_dl_power_meter(s16 numHealthWedges) { Mtx *mtx; + f32 interpolatedY; - mtx = alloc_display_list(sizeof(Mtx)); - -@@ -118,7 +133,15 @@ void render_dl_power_meter(s16 numHealthWedges) { - return; - } +@@ -120,3 +135,11 @@ void render_dl_power_meter(s16 numHealthWedges) { - guTranslate(mtx, (f32) sPowerMeterHUD.x, (f32) sPowerMeterHUD.y, 0); + if (gGlobalTimer == sPowerMeterLastRenderTimestamp + 1) { @@ -655,16 +451,12 @@ index 1540b67..0de6e0b 100644 + sPowerMeterLastRenderTimestamp = gGlobalTimer; + sPowerMeterDisplayListPos = gDisplayListHead; - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx++), - G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH); diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c -index 7ae9f1e..1c23c96 100644 +index 3f02281a..d7d0aced 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c -@@ -130,6 +130,42 @@ s32 gDialogResponse = 0; - static struct CachedChar { u8 used; u8 data[CHCACHE_BUFLEN]; } charCache[256]; - #endif // VERSION - +@@ -118,2 +118,43 @@ u8 gMenuHoldKeyTimer = 0; + s32 gDialogResponse = 0; +static Gfx *sInterpolatedDialogOffsetPos; +static f32 sInterpolatedDialogOffset; +static Gfx *sInterpolatedDialogRotationPos; @@ -678,35 +470,36 @@ index 7ae9f1e..1c23c96 100644 + if (sInterpolatedDialogOffsetPos != NULL) { + matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); + guTranslate(matrix, 0, sInterpolatedDialogOffset, 0); -+ gSPMatrix(sInterpolatedDialogOffsetPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); ++ gSPMatrix(sInterpolatedDialogOffsetPos, VIRTUAL_TO_PHYSICAL(matrix), ++ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + sInterpolatedDialogOffsetPos = NULL; + } + if (sInterpolatedDialogRotationPos != NULL) { + matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); + guScale(matrix, 1.0 / sInterpolatedDialogScale, 1.0 / sInterpolatedDialogScale, 1.0f); -+ gSPMatrix(sInterpolatedDialogRotationPos++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); ++ gSPMatrix(sInterpolatedDialogRotationPos++, VIRTUAL_TO_PHYSICAL(matrix), ++ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); + guRotate(matrix, sInterpolatedDialogRotation * 4.0f, 0, 0, 1.0f); -+ gSPMatrix(sInterpolatedDialogRotationPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); ++ gSPMatrix(sInterpolatedDialogRotationPos, VIRTUAL_TO_PHYSICAL(matrix), ++ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + sInterpolatedDialogRotationPos = NULL; + } + if (sInterpolatedDialogZoomPos != NULL) { + matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); -+ guTranslate(matrix, 65.0 - (65.0 / sInterpolatedDialogScale), (40.0 / sInterpolatedDialogScale) - 40, 0); -+ gSPMatrix(sInterpolatedDialogZoomPos++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); ++ guTranslate(matrix, 65.0 - (65.0 / sInterpolatedDialogScale), ++ (40.0 / sInterpolatedDialogScale) - 40, 0); ++ gSPMatrix(sInterpolatedDialogZoomPos++, VIRTUAL_TO_PHYSICAL(matrix), ++ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); + guScale(matrix, 1.0 / sInterpolatedDialogScale, 1.0 / sInterpolatedDialogScale, 1.0f); -+ gSPMatrix(sInterpolatedDialogZoomPos, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); ++ gSPMatrix(sInterpolatedDialogZoomPos, VIRTUAL_TO_PHYSICAL(matrix), ++ G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + sInterpolatedDialogZoomPos = NULL; + } +} -+ - void create_dl_identity_matrix(void) { - Mtx *matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); -@@ -969,6 +1005,14 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) { - switch (gDialogBoxType) { - case DIALOG_TYPE_ROTATE: // Renders a dialog black box with zoom and rotation +@@ -940,2 +981,10 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) { if (gDialogBoxState == DIALOG_STATE_OPENING || gDialogBoxState == DIALOG_STATE_CLOSING) { + sInterpolatedDialogRotationPos = gDisplayListHead; + if (gDialogBoxState == DIALOG_STATE_OPENING) { @@ -717,11 +510,7 @@ index 7ae9f1e..1c23c96 100644 + sInterpolatedDialogRotation = gDialogBoxOpenTimer + 7.5f / 2; + } create_dl_scale_matrix(MENU_MTX_NOPUSH, 1.0 / gDialogBoxScale, 1.0 / gDialogBoxScale, 1.0f); - // convert the speed into angle - create_dl_rotation_matrix(MENU_MTX_NOPUSH, gDialogBoxOpenTimer * 4.0f, 0, 0, 1.0f); -@@ -977,6 +1021,12 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) { - break; - case DIALOG_TYPE_ZOOM: // Renders a dialog white box with zoom +@@ -948,2 +997,8 @@ void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) { if (gDialogBoxState == DIALOG_STATE_OPENING || gDialogBoxState == DIALOG_STATE_CLOSING) { + sInterpolatedDialogZoomPos = gDisplayListHead; + if (gDialogBoxState == DIALOG_STATE_OPENING) { @@ -730,57 +519,38 @@ index 7ae9f1e..1c23c96 100644 + sInterpolatedDialogScale = gDialogBoxScale + 2 / 2; + } create_dl_translation_matrix(MENU_MTX_NOPUSH, 65.0 - (65.0 / gDialogBoxScale), - (40.0 / gDialogBoxScale) - 40, 0); - create_dl_scale_matrix(MENU_MTX_NOPUSH, 1.0 / gDialogBoxScale, 1.0 / gDialogBoxScale, 1.0f); -@@ -1259,6 +1309,8 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l - #ifdef VERSION_EU - gDialogY -= gDialogScrollOffsetY; +@@ -1230,2 +1285,4 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l #else + sInterpolatedDialogOffset = gDialogScrollOffsetY + dialog->linesPerBox; + sInterpolatedDialogOffsetPos = gDisplayListHead; create_dl_translation_matrix(MENU_MTX_NOPUSH, 0, (f32) gDialogScrollOffsetY, 0); - #endif - } diff --git a/src/game/level_geo.c b/src/game/level_geo.c -index 4c98e70..abc5121 100644 +index 4c98e705..abc51213 100644 --- a/src/game/level_geo.c +++ b/src/game/level_geo.c -@@ -34,12 +34,16 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) { - vec3f_to_vec3s(marioPos, gPlayerCameraState->pos); - particleList = envfx_update_particles(snowMode, marioPos, camTo, camFrom); +@@ -36,2 +36,3 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) { if (particleList != NULL) { +#if 0 Mtx *mtx = alloc_display_list(sizeof(*mtx)); - - gfx = alloc_display_list(2 * sizeof(*gfx)); - mtxf_to_mtx(mtx, mtxf); - gSPMatrix(&gfx[0], VIRTUAL_TO_PHYSICAL(mtx), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); +@@ -42,2 +43,5 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) { gSPBranchList(&gfx[1], VIRTUAL_TO_PHYSICAL(particleList)); +#else + gfx = particleList; +#endif execNode->fnNode.node.flags = (execNode->fnNode.node.flags & 0xFF) | 0x400; - } - SET_HIGH_U16_OF_32(*params, gAreaUpdateCounter); diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c -index 22b45b3..109d7f7 100644 +index 22b45b32..109d7f74 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c -@@ -1554,6 +1554,7 @@ void cur_obj_set_pos_to_home(void) { - o->oPosX = o->oHomeX; - o->oPosY = o->oHomeY; +@@ -1556,2 +1556,3 @@ void cur_obj_set_pos_to_home(void) { o->oPosZ = o->oHomeZ; + o->header.gfx.skipInterpolationTimestamp = gGlobalTimer; } - - void cur_obj_set_pos_to_home_and_stop(void) { diff --git a/src/game/paintings.c b/src/game/paintings.c -index 6cae19c..a304d4a 100644 +index 6cae19c0..a304d4ae 100644 --- a/src/game/paintings.c +++ b/src/game/paintings.c -@@ -189,6 +189,32 @@ struct Painting **sPaintingGroups[] = { - s16 gPaintingUpdateCounter = 1; - s16 gLastPaintingUpdateCounter = 0; +@@ -191,2 +191,28 @@ s16 gLastPaintingUpdateCounter = 0; +static Vtx sLastVertices[2 * 264 * 3]; +static u32 sLastVerticesTimestamp; @@ -809,11 +579,7 @@ index 6cae19c..a304d4a 100644 +} + /** - * Stop paintings in paintingGroup from rippling if their id is different from *idptr. - */ -@@ -890,6 +916,23 @@ Gfx *render_painting(u8 *img, s16 tWidth, s16 tHeight, s16 *textureMap, s16 mapV - gSP1Triangle(gfx++, group * 3, group * 3 + 1, group * 3 + 2, 0); - } +@@ -892,2 +918,19 @@ Gfx *render_painting(u8 *img, s16 tWidth, s16 tHeight, s16 *textureMap, s16 mapV + if (sVerticesCount >= numVtx * 2) { + sVerticesCount = 0; @@ -833,56 +599,32 @@ index 6cae19c..a304d4a 100644 + sVerticesCount += numVtx; + gSPEndDisplayList(gfx); - return dlist; - } -@@ -954,6 +997,7 @@ Gfx *painting_ripple_image(struct Painting *painting) { - meshTris = textureMap[meshVerts * 3 + 1]; - gSPDisplayList(gfx++, render_painting(textures[i], tWidth, tHeight, textureMap, meshVerts, meshTris, painting->alpha)); +@@ -956,2 +999,3 @@ Gfx *painting_ripple_image(struct Painting *painting) { } + sLastVerticesTimestamp = gGlobalTimer; - // Update the ripple, may automatically reset the painting's state. - painting_update_ripple_state(painting); -@@ -991,6 +1035,7 @@ Gfx *painting_ripple_env_mapped(struct Painting *painting) { - meshVerts = textureMap[0]; - meshTris = textureMap[meshVerts * 3 + 1]; +@@ -993,2 +1037,3 @@ Gfx *painting_ripple_env_mapped(struct Painting *painting) { gSPDisplayList(gfx++, render_painting(tArray[0], tWidth, tHeight, textureMap, meshVerts, meshTris, painting->alpha)); + sLastVerticesTimestamp = gGlobalTimer; - // Update the ripple, may automatically reset the painting's state. - painting_update_ripple_state(painting); diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c -index d5bf577..71656b4 100644 +index d5bf5778..71656b49 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c -@@ -39,6 +39,8 @@ - s16 gMatStackIndex; - Mat4 gMatStack[32]; +@@ -41,2 +41,4 @@ Mat4 gMatStack[32]; Mtx *gMatStackFixed[32]; +Mat4 gMatStackInterpolated[32]; +Mtx *gMatStackInterpolatedFixed[32]; - /** - * Animation nodes have state in global variables, so this struct captures -@@ -52,6 +54,7 @@ struct GeoAnimState { - /*0x04*/ f32 translationMultiplier; - /*0x08*/ u16 *attribute; +@@ -54,2 +56,3 @@ struct GeoAnimState { /*0x0C*/ s16 *data; + s16 prevFrame; }; - - // For some reason, this is a GeoAnimState struct, but the current state consists -@@ -61,6 +64,7 @@ struct GeoAnimState gGeoTempState; - u8 gCurAnimType; - u8 gCurAnimEnabled; +@@ -63,2 +66,3 @@ u8 gCurAnimEnabled; s16 gCurrAnimFrame; +s16 gPrevAnimFrame; f32 gCurAnimTranslationMultiplier; - u16 *gCurrAnimAttribute; - s16 *gCurAnimData; -@@ -129,6 +133,46 @@ u16 gAreaUpdateCounter = 0; - LookAt lookAt; - #endif +@@ -131,2 +135,42 @@ LookAt lookAt; +static Gfx *sPerspectivePos; +static Mtx *sPerspectiveMtx; @@ -925,11 +667,7 @@ index d5bf577..71656b4 100644 +} + /** - * Process a master list node. - */ -@@ -156,9 +200,14 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) { - if ((currList = node->listHeads[i]) != NULL) { - gDPSetRenderMode(gDisplayListHead++, modeList->modes[i], mode2List->modes[i]); +@@ -158,5 +202,10 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) { while (currList != NULL) { - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(currList->transform), + if ((u32) gMtxTblSize < sizeof(gMtxTbl) / sizeof(gMtxTbl[0])) { @@ -942,51 +680,31 @@ index d5bf577..71656b4 100644 - gSPDisplayList(gDisplayListHead++, currList->displayList); + gSPDisplayList(gDisplayListHead++, currList->displayListInterpolated); currList = currList->next; - } - } -@@ -174,7 +223,7 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) { - * parameter. Look at the RenderModeContainer struct to see the corresponding - * render modes of layers. +@@ -176,3 +225,3 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) { */ -static void geo_append_display_list(void *displayList, s16 layer) { +static void geo_append_display_list2(void *displayList, void *displayListInterpolated, s16 layer) { - #ifdef F3DEX_GBI_2 - gSPLookAt(gDisplayListHead++, &lookAt); -@@ -184,7 +233,9 @@ static void geo_append_display_list(void *displayList, s16 layer) { - alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode)); - +@@ -186,3 +235,5 @@ static void geo_append_display_list(void *displayList, s16 layer) { listNode->transform = gMatStackFixed[gMatStackIndex]; + listNode->transformInterpolated = gMatStackInterpolatedFixed[gMatStackIndex]; listNode->displayList = displayList; + listNode->displayListInterpolated = displayListInterpolated; listNode->next = 0; - if (gCurGraphNodeMasterList->listHeads[layer] == 0) { - gCurGraphNodeMasterList->listHeads[layer] = listNode; -@@ -195,6 +246,10 @@ static void geo_append_display_list(void *displayList, s16 layer) { - } - } +@@ -197,2 +248,6 @@ static void geo_append_display_list(void *displayList, s16 layer) { +static void geo_append_display_list(void *displayList, s16 layer) { + geo_append_display_list2(displayList, displayList, layer); +} + /** - * Process the master list node. - */ -@@ -241,7 +296,9 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { - } - if (node->fnNode.node.children != NULL) { +@@ -243,3 +298,5 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { u16 perspNorm; + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); Mtx *mtx = alloc_display_list(sizeof(*mtx)); + f32 fovInterpolated; - #ifdef VERSION_EU - f32 aspect = ((f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height) * 1.1f; -@@ -250,9 +307,23 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { - #endif - +@@ -252,5 +309,19 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { guPerspective(mtx, &perspNorm, node->fov, aspect, node->near, node->far, 1.0f); - gSPPerspNormalize(gDisplayListHead++, perspNorm); @@ -1008,11 +726,7 @@ index d5bf577..71656b4 100644 + node->prevFov = node->fov; + node->prevTimestamp = gGlobalTimer; - gCurGraphNodeCamFrustum = node; - geo_process_node_and_siblings(node->fnNode.node.children); -@@ -297,6 +368,39 @@ static void geo_process_switch(struct GraphNodeSwitchCase *node) { - } - } +@@ -299,2 +370,35 @@ static void geo_process_switch(struct GraphNodeSwitchCase *node) { +void interpolate_vectors(Vec3f res, Vec3f a, Vec3f b) { + res[0] = (a[0] + b[0]) / 2.0f; @@ -1048,21 +762,13 @@ index d5bf577..71656b4 100644 +} + /** - * Process a camera node. - */ -@@ -304,6 +408,9 @@ static void geo_process_camera(struct GraphNodeCamera *node) { - Mat4 cameraTransform; - Mtx *rollMtx = alloc_display_list(sizeof(*rollMtx)); +@@ -306,2 +410,5 @@ static void geo_process_camera(struct GraphNodeCamera *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); + Vec3f posInterpolated; + Vec3f focusInterpolated; - if (node->fnNode.func != NULL) { - node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]); -@@ -314,12 +421,40 @@ static void geo_process_camera(struct GraphNodeCamera *node) { - - mtxf_lookat(cameraTransform, node->pos, node->focus, node->roll); +@@ -316,2 +423,27 @@ static void geo_process_camera(struct GraphNodeCamera *node) { mtxf_mul(gMatStack[gMatStackIndex + 1], cameraTransform, gMatStack[gMatStackIndex]); + + if (gGlobalTimer == node->prevTimestamp + 1 && gGlobalTimer != gLakituState.skipCameraInterpolationTimestamp) { @@ -1090,61 +796,47 @@ index d5bf577..71656b4 100644 + mtxf_mul(gMatStackInterpolated[gMatStackIndex + 1], cameraTransform, gMatStackInterpolated[gMatStackIndex]); + gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -319,2 +451,4 @@ static void geo_process_camera(struct GraphNodeCamera *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->fnNode.node.children != 0) { - gCurGraphNodeCamera = node; +@@ -322,2 +456,3 @@ static void geo_process_camera(struct GraphNodeCamera *node) { node->matrixPtr = &gMatStack[gMatStackIndex]; + node->matrixPtrInterpolated = &gMatStackInterpolated[gMatStackIndex]; geo_process_node_and_siblings(node->fnNode.node.children); - gCurGraphNodeCamera = NULL; - } -@@ -336,13 +471,17 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation - Mat4 mtxf; - Vec3f translation; +@@ -338,2 +473,3 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); - vec3s_to_vec3f(translation, node->translation); - mtxf_rotate_zxy_and_translate(mtxf, translation, node->rotation); +@@ -342,2 +478,3 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation mtxf_mul(gMatStack[gMatStackIndex + 1], mtxf, gMatStack[gMatStackIndex]); + mtxf_mul(gMatStackInterpolated[gMatStackIndex + 1], mtxf, gMatStackInterpolated[gMatStackIndex]); gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -345,2 +482,4 @@ static void geo_process_translation_rotation(struct GraphNodeTranslationRotation gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -361,13 +500,17 @@ static void geo_process_translation(struct GraphNodeTranslation *node) { - Mat4 mtxf; - Vec3f translation; +@@ -363,2 +502,3 @@ static void geo_process_translation(struct GraphNodeTranslation *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); - vec3s_to_vec3f(translation, node->translation); - mtxf_rotate_zxy_and_translate(mtxf, translation, gVec3sZero); +@@ -367,2 +507,3 @@ static void geo_process_translation(struct GraphNodeTranslation *node) { mtxf_mul(gMatStack[gMatStackIndex + 1], mtxf, gMatStack[gMatStackIndex]); + mtxf_mul(gMatStackInterpolated[gMatStackIndex + 1], mtxf, gMatStackInterpolated[gMatStackIndex]); gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -370,2 +511,4 @@ static void geo_process_translation(struct GraphNodeTranslation *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -385,12 +528,23 @@ static void geo_process_translation(struct GraphNodeTranslation *node) { - static void geo_process_rotation(struct GraphNodeRotation *node) { - Mat4 mtxf; +@@ -387,2 +530,4 @@ static void geo_process_rotation(struct GraphNodeRotation *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); + Vec3s rotationInterpolated; - mtxf_rotate_zxy_and_translate(mtxf, gVec3fZero, node->rotation); +@@ -390,2 +535,9 @@ static void geo_process_rotation(struct GraphNodeRotation *node) { mtxf_mul(gMatStack[gMatStackIndex + 1], mtxf, gMatStack[gMatStackIndex]); + if (gGlobalTimer == node->prevTimestamp + 1) { + interpolate_angles(rotationInterpolated, node->prevRotation, node->rotation); @@ -1154,64 +846,49 @@ index d5bf577..71656b4 100644 + node->prevTimestamp = gGlobalTimer; + mtxf_mul(gMatStackInterpolated[gMatStackIndex + 1], mtxf, gMatStackInterpolated[gMatStackIndex]); gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -393,2 +545,4 @@ static void geo_process_rotation(struct GraphNodeRotation *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -409,12 +563,16 @@ static void geo_process_scale(struct GraphNodeScale *node) { - UNUSED Mat4 transform; - Vec3f scaleVec; +@@ -411,2 +565,3 @@ static void geo_process_scale(struct GraphNodeScale *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); - vec3f_set(scaleVec, node->scale, node->scale, node->scale); +@@ -414,2 +569,3 @@ static void geo_process_scale(struct GraphNodeScale *node) { mtxf_scale_vec3f(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex], scaleVec); + mtxf_scale_vec3f(gMatStackInterpolated[gMatStackIndex + 1], gMatStackInterpolated[gMatStackIndex], scaleVec); gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -417,2 +573,4 @@ static void geo_process_scale(struct GraphNodeScale *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -433,21 +591,30 @@ static void geo_process_scale(struct GraphNodeScale *node) { - static void geo_process_billboard(struct GraphNodeBillboard *node) { - Vec3f translation; +@@ -435,2 +593,3 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); - gMatStackIndex++; - vec3s_to_vec3f(translation, node->translation); - mtxf_billboard(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex - 1], translation, +@@ -440,2 +599,4 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) { gCurGraphNodeCamera->roll); + mtxf_billboard(gMatStackInterpolated[gMatStackIndex], gMatStackInterpolated[gMatStackIndex - 1], translation, + gCurGraphNodeCamera->roll); if (gCurGraphNodeHeldObject != NULL) { - mtxf_scale_vec3f(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex], +@@ -443,2 +604,4 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) { gCurGraphNodeHeldObject->objNode->header.gfx.scale); + mtxf_scale_vec3f(gMatStackInterpolated[gMatStackIndex], gMatStackInterpolated[gMatStackIndex], + gCurGraphNodeHeldObject->objNode->header.gfx.scale); } else if (gCurGraphNodeObject != NULL) { - mtxf_scale_vec3f(gMatStack[gMatStackIndex], gMatStack[gMatStackIndex], +@@ -446,2 +609,4 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) { gCurGraphNodeObject->scale); + mtxf_scale_vec3f(gMatStackInterpolated[gMatStackIndex], gMatStackInterpolated[gMatStackIndex], + gCurGraphNodeObject->scale); } - - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -450,2 +615,4 @@ static void geo_process_billboard(struct GraphNodeBillboard *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -496,13 +663,39 @@ static void geo_process_generated_list(struct GraphNodeGenerated *node) { - */ - static void geo_process_background(struct GraphNodeBackground *node) { +@@ -498,9 +665,35 @@ static void geo_process_background(struct GraphNodeBackground *node) { Gfx *list = NULL; + Gfx *listInterpolated = NULL; @@ -1248,11 +925,7 @@ index d5bf577..71656b4 100644 + geo_append_display_list2((void *) VIRTUAL_TO_PHYSICAL(list), + (void *) VIRTUAL_TO_PHYSICAL(listInterpolated), node->fnNode.node.flags >> 8); } else if (gCurGraphNodeMasterList != NULL) { - #ifndef F3DEX_GBI_2E - Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 7); -@@ -527,61 +720,81 @@ static void geo_process_background(struct GraphNodeBackground *node) { - } - } +@@ -529,43 +722,32 @@ static void geo_process_background(struct GraphNodeBackground *node) { -/** - * Render an animated part. The current animation state is not part of the node @@ -1315,8 +988,7 @@ index d5bf577..71656b4 100644 + *animAttribute += 6; + *animType = ANIM_TYPE_ROTATION; } - } - } +@@ -574,9 +756,38 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) { - if (gCurAnimType == ANIM_TYPE_ROTATION) { - rotation[0] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; @@ -1359,16 +1031,12 @@ index d5bf577..71656b4 100644 + mtxf_rotate_xyz_and_translate(matrix, translationInterpolated, rotationInterpolated); + mtxf_mul(gMatStackInterpolated[gMatStackIndex + 1], matrix, gMatStackInterpolated[gMatStackIndex]); gMatStackIndex++; - mtxf_to_mtx(matrixPtr, gMatStack[gMatStackIndex]); +@@ -584,2 +795,4 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) { gMatStackFixed[gMatStackIndex] = matrixPtr; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->displayList != NULL) { - geo_append_display_list(node->displayList, node->node.flags >> 8); - } -@@ -613,6 +826,17 @@ void geo_set_animation_globals(struct GraphNodeObject_sub *node, s32 hasAnimatio - } - +@@ -615,2 +828,13 @@ void geo_set_animation_globals(struct GraphNodeObject_sub *node, s32 hasAnimatio gCurrAnimFrame = node->animFrame; + if (node->prevAnimPtr == anim && node->prevAnimID == node->animID && + gGlobalTimer == node->prevAnimFrameTimestamp + 1) { @@ -1382,30 +1050,18 @@ index d5bf577..71656b4 100644 + node->prevAnimFrameTimestamp = gGlobalTimer; + gCurAnimEnabled = (anim->flags & ANIM_FLAG_5) == 0; - gCurrAnimAttribute = segmented_to_virtual((void *) anim->index); - gCurAnimData = segmented_to_virtual((void *) anim->values); -@@ -631,8 +855,10 @@ void geo_set_animation_globals(struct GraphNodeObject_sub *node, s32 hasAnimatio - */ - static void geo_process_shadow(struct GraphNodeShadow *node) { +@@ -633,4 +857,6 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { Gfx *shadowList; + Gfx *shadowListInterpolated; Mat4 mtxf; Vec3f shadowPos; + Vec3f shadowPosInterpolated; Vec3f animOffset; - f32 objScale; - f32 shadowScale; -@@ -640,6 +866,7 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { - f32 cosAng; - struct GraphNode *geo; +@@ -642,2 +868,3 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { Mtx *mtx; + Mtx *mtxInterpolated; - if (gCurGraphNodeCamera != NULL && gCurGraphNodeObject != NULL) { - if (gCurGraphNodeHeldObject != NULL) { -@@ -678,21 +905,57 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { - } - } +@@ -680,7 +907,34 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { + if (gCurGraphNodeHeldObject != NULL) { + if (gGlobalTimer == gCurGraphNodeHeldObject->prevShadowPosTimestamp + 1) { @@ -1441,8 +1097,7 @@ index d5bf577..71656b4 100644 gMatStackIndex++; + mtxf_translate(mtxf, shadowPos); - mtxf_mul(gMatStack[gMatStackIndex], mtxf, *gCurGraphNodeCamera->matrixPtr); - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -689,8 +943,17 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { gMatStackFixed[gMatStackIndex] = mtx; + + mtxf_translate(mtxf, shadowPosInterpolated); @@ -1463,11 +1118,7 @@ index d5bf577..71656b4 100644 + geo_append_display_list2((void *) VIRTUAL_TO_PHYSICAL(shadowList), + (void *) VIRTUAL_TO_PHYSICAL(shadowListInterpolated), 6); } - gMatStackIndex--; - } -@@ -789,31 +1052,101 @@ static int obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { - return TRUE; - } +@@ -791,2 +1054,11 @@ static int obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { +static void interpolate_matrix(Mat4 result, Mat4 a, Mat4 b) { + s32 i, j; @@ -1479,16 +1130,11 @@ index d5bf577..71656b4 100644 +} + /** - * Process an object node. - */ - static void geo_process_object(struct Object *node) { - Mat4 mtxf; +@@ -797,2 +1069,3 @@ static void geo_process_object(struct Object *node) { s32 hasAnimation = (node->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0; + Vec3f scaleInterpolated; - if (node->header.gfx.unk18 == gCurGraphNodeRoot->areaIndex) { - if (node->header.gfx.throwMatrix != NULL) { - mtxf_mul(gMatStack[gMatStackIndex + 1], *node->header.gfx.throwMatrix, +@@ -802,12 +1075,69 @@ static void geo_process_object(struct Object *node) { gMatStack[gMatStackIndex]); + if (gGlobalTimer == node->header.gfx.prevThrowMatrixTimestamp + 1 && + gGlobalTimer != node->header.gfx.skipInterpolationTimestamp) { @@ -1558,57 +1204,39 @@ index d5bf577..71656b4 100644 + vec3f_copy(node->header.gfx.prevScale, node->header.gfx.scale); + node->header.gfx.prevScaleTimestamp = gGlobalTimer; - mtxf_scale_vec3f(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex + 1], +@@ -815,3 +1145,6 @@ static void geo_process_object(struct Object *node) { node->header.gfx.scale); + mtxf_scale_vec3f(gMatStackInterpolated[gMatStackIndex + 1], gMatStackInterpolated[gMatStackIndex + 1], + scaleInterpolated); node->header.gfx.throwMatrix = &gMatStack[++gMatStackIndex]; + node->header.gfx.throwMatrixInterpolated = &gMatStackInterpolated[gMatStackIndex]; node->header.gfx.cameraToObject[0] = gMatStack[gMatStackIndex][3][0]; - node->header.gfx.cameraToObject[1] = gMatStack[gMatStackIndex][3][1]; - node->header.gfx.cameraToObject[2] = gMatStack[gMatStackIndex][3][2]; -@@ -824,9 +1157,12 @@ static void geo_process_object(struct Object *node) { - } - if (obj_is_in_view(&node->header.gfx, gMatStack[gMatStackIndex])) { +@@ -826,2 +1159,3 @@ static void geo_process_object(struct Object *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -829,2 +1163,4 @@ static void geo_process_object(struct Object *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; if (node->header.gfx.sharedChild != NULL) { - gCurGraphNodeObject = (struct GraphNodeObject *) node; - node->header.gfx.sharedChild->parent = &node->header.gfx.node; -@@ -837,11 +1173,16 @@ static void geo_process_object(struct Object *node) { - if (node->header.gfx.node.children != NULL) { - geo_process_node_and_siblings(node->header.gfx.node.children); +@@ -839,2 +1175,6 @@ static void geo_process_object(struct Object *node) { } + } else { + node->header.gfx.prevThrowMatrixTimestamp = 0; + node->header.gfx.prevTimestamp = 0; + node->header.gfx.prevScaleTimestamp = 0; } - - gMatStackIndex--; - gCurAnimType = ANIM_TYPE_NONE; +@@ -844,2 +1184,3 @@ static void geo_process_object(struct Object *node) { node->header.gfx.throwMatrix = NULL; + node->header.gfx.throwMatrixInterpolated = NULL; } - } - -@@ -868,6 +1209,8 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { - Mat4 mat; - Vec3f translation; +@@ -870,2 +1211,4 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); + Mtx *mtxInterpolated = alloc_display_list(sizeof(*mtxInterpolated)); + Vec3f scaleInterpolated; - #ifdef F3DEX_GBI_2 - gSPLookAt(gDisplayListHead++, &lookAt); -@@ -883,6 +1226,14 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { - translation[1] = node->translation[1] / 4.0f; - translation[2] = node->translation[2] / 4.0f; +@@ -885,2 +1228,10 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { + if (gGlobalTimer == node->objNode->header.gfx.prevScaleTimestamp + 1) { + interpolate_vectors(scaleInterpolated, node->objNode->header.gfx.prevScale, node->objNode->header.gfx.scale); @@ -1619,11 +1247,7 @@ index d5bf577..71656b4 100644 + node->objNode->header.gfx.prevScaleTimestamp = gGlobalTimer; + mtxf_translate(mat, translation); - mtxf_copy(gMatStack[gMatStackIndex + 1], *gCurGraphNodeObject->throwMatrix); - gMatStack[gMatStackIndex + 1][3][0] = gMatStack[gMatStackIndex][3][0]; -@@ -891,6 +1242,13 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { - mtxf_mul(gMatStack[gMatStackIndex + 1], mat, gMatStack[gMatStackIndex + 1]); - mtxf_scale_vec3f(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex + 1], +@@ -893,2 +1244,9 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { node->objNode->header.gfx.scale); + mtxf_copy(gMatStackInterpolated[gMatStackIndex + 1], (void *) gCurGraphNodeObject->throwMatrixInterpolated); + gMatStackInterpolated[gMatStackIndex + 1][3][0] = gMatStackInterpolated[gMatStackIndex][3][0]; @@ -1633,43 +1257,24 @@ index d5bf577..71656b4 100644 + mtxf_scale_vec3f(gMatStackInterpolated[gMatStackIndex + 1], gMatStackInterpolated[gMatStackIndex + 1], + scaleInterpolated); if (node->fnNode.func != NULL) { - node->fnNode.func(GEO_CONTEXT_HELD_OBJ, &node->fnNode.node, - (struct AllocOnlyPool *) gMatStack[gMatStackIndex + 1]); -@@ -898,12 +1256,15 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { - gMatStackIndex++; - mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); +@@ -900,2 +1258,4 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { gMatStackFixed[gMatStackIndex] = mtx; + mtxf_to_mtx(mtxInterpolated, gMatStackInterpolated[gMatStackIndex]); + gMatStackInterpolatedFixed[gMatStackIndex] = mtxInterpolated; gGeoTempState.type = gCurAnimType; - gGeoTempState.enabled = gCurAnimEnabled; - gGeoTempState.frame = gCurrAnimFrame; - gGeoTempState.translationMultiplier = gCurAnimTranslationMultiplier; - gGeoTempState.attribute = gCurrAnimAttribute; +@@ -906,2 +1266,3 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { gGeoTempState.data = gCurAnimData; + gGeoTempState.prevFrame = gPrevAnimFrame; gCurAnimType = 0; - gCurGraphNodeHeldObject = (void *) node; - if (node->objNode->header.gfx.unk38.curAnim != NULL) { -@@ -918,6 +1279,7 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { - gCurAnimTranslationMultiplier = gGeoTempState.translationMultiplier; - gCurrAnimAttribute = gGeoTempState.attribute; +@@ -920,2 +1281,3 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { gCurAnimData = gGeoTempState.data; + gPrevAnimFrame = gGeoTempState.prevFrame; gMatStackIndex--; - } - -@@ -1039,6 +1401,7 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) - if (node->node.flags & GRAPH_RENDER_ACTIVE) { - Mtx *initialMatrix; +@@ -1041,2 +1403,3 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) Vp *viewport = alloc_display_list(sizeof(*viewport)); + Vp *viewportInterpolated = viewport; - gDisplayListHeap = alloc_only_pool_init(main_pool_available() - sizeof(struct AllocOnlyPool), - MEMORY_POOL_LEFT); -@@ -1049,7 +1412,12 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) - vec3s_set(viewport->vp.vscale, node->width * 4, node->height * 4, 511); - if (b != NULL) { +@@ -1051,3 +1414,8 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) clear_frame_buffer(clearColor); - make_viewport_clip_rect(b); + viewportInterpolated = alloc_display_list(sizeof(*viewportInterpolated)); @@ -1679,16 +1284,11 @@ index d5bf577..71656b4 100644 + sViewportPos = gDisplayListHead; + make_viewport_clip_rect(viewportInterpolated); *viewport = *b; - } - -@@ -1057,11 +1425,16 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) - clear_frame_buffer(clearColor); - make_viewport_clip_rect(c); +@@ -1059,2 +1427,3 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) } + sPrevViewport = *viewport; - mtxf_identity(gMatStack[gMatStackIndex]); - mtxf_to_mtx(initialMatrix, gMatStack[gMatStackIndex]); +@@ -1063,3 +1432,7 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) gMatStackFixed[gMatStackIndex] = initialMatrix; - gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(viewport)); + @@ -1697,15 +1297,11 @@ index d5bf577..71656b4 100644 + + gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(viewportInterpolated)); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(gMatStackFixed[gMatStackIndex]), - G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); - gCurGraphNodeRoot = node; diff --git a/src/game/screen_transition.c b/src/game/screen_transition.c -index b49ddaf..d6656af 100644 +index b49ddaf5..d6656af2 100644 --- a/src/game/screen_transition.c +++ b/src/game/screen_transition.c -@@ -16,6 +16,19 @@ - u8 sTransitionColorFadeCount[4] = { 0 }; - u16 sTransitionTextureFadeCount[2] = { 0 }; +@@ -18,2 +18,15 @@ u16 sTransitionTextureFadeCount[2] = { 0 }; +static Gfx *sScreenTransitionVerticesPos[2]; +static Vtx *sScreenTransitionVertices; @@ -1721,18 +1317,12 @@ index b49ddaf..d6656af 100644 +} + s32 set_and_reset_transition_fade_timer(s8 fadeTimer, u8 transTime) { - s32 reset = FALSE; - -@@ -85,14 +98,29 @@ s32 render_fade_transition_into_color(s8 fadeTimer, u8 transTime, struct WarpTra - return dl_transition_color(fadeTimer, transTime, transData, alpha); - } +@@ -87,2 +100,4 @@ s32 render_fade_transition_into_color(s8 fadeTimer, u8 transTime, struct WarpTra +#if 0 + s16 calc_tex_transition_radius(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData) { - f32 texRadius = transData->endTexRadius - transData->startTexRadius; - f32 radiusTime = sTransitionColorFadeCount[fadeTimer] * texRadius / (f32)(transTime - 1); - f32 result = transData->startTexRadius + radiusTime; +@@ -92,5 +107,18 @@ s16 calc_tex_transition_radius(s8 fadeTimer, s8 transTime, struct WarpTransition - return (s16)(result + 0.5);; + return (s16)(result + 0.5); @@ -1752,20 +1342,12 @@ index b49ddaf..d6656af 100644 +#endif + f32 calc_tex_transition_time(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData) { - f32 startX = transData->startTexX; - f32 startY = transData->startTexY; -@@ -166,6 +194,8 @@ void *sTextureTransitionID[] = { - texture_transition_bowser_half, - }; +@@ -168,2 +196,4 @@ void *sTextureTransitionID[] = { +#if 0 + s32 render_textured_transition(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData, s8 texID, s8 transTexType) { - f32 texTransTime = calc_tex_transition_time(fadeTimer, transTime, transData); - u16 texTransPos = convert_tex_transition_angle_to_pos(transData); -@@ -206,6 +236,56 @@ s32 render_textured_transition(s8 fadeTimer, s8 transTime, struct WarpTransition - return set_and_reset_transition_fade_timer(fadeTimer, transTime); - } +@@ -208,2 +238,52 @@ s32 render_textured_transition(s8 fadeTimer, s8 transTime, struct WarpTransition +#else + @@ -1818,22 +1400,24 @@ index b49ddaf..d6656af 100644 +#endif + int render_screen_transition(s8 fadeTimer, s8 transType, u8 transTime, struct WarpTransitionData *transData) { - switch (transType) { - case WARP_TRANSITION_FADE_FROM_COLOR: +diff --git a/src/game/skybox.c b/src/game/skybox.c +index 258ef0a3..bf92d0d5 100644 +--- a/src/game/skybox.c ++++ b/src/game/skybox.c +@@ -253,3 +253,3 @@ void *create_skybox_ortho_matrix(s8 player) { + Gfx *init_skybox_display_list(s8 player, s8 background, s8 colorIndex) { +- s32 dlCommandCount = 7 + (3 * 3) * 7; // 5 for the start and end, plus 9 skybox tiles ++ s32 dlCommandCount = 124; // 5 for the start and end, plus 9 skybox tiles + void *skybox = alloc_display_list(dlCommandCount * sizeof(Gfx)); diff --git a/src/menu/intro_geo.c b/src/menu/intro_geo.c -index 37c6752..d823d40 100644 +index 1d3be071..01c5ad61 100644 --- a/src/menu/intro_geo.c +++ b/src/menu/intro_geo.c -@@ -1,5 +1,6 @@ - #include +@@ -2,2 +2,3 @@ +#include "engine/math_util.h" #include "game/memory.h" - #include "game/segment2.h" - #include "game/segment7.h" -@@ -70,6 +71,18 @@ s8 gameOverBackgroundTable[] = { - s8 gameOverBackgroundFlipOrder[] = { 0x00, 0x01, 0x02, 0x03, 0x07, 0x0B, - 0x0a, 0x09, 0x08, 0x04, 0x05, 0x06 }; +@@ -72,2 +73,14 @@ s8 gameOverBackgroundFlipOrder[] = { 0x00, 0x01, 0x02, 0x03, 0x07, 0x0B, +static Gfx *sIntroScalePos; +static Vec3f sIntroScale; @@ -1848,37 +1432,24 @@ index 37c6752..d823d40 100644 +} + Gfx *geo_title_screen(s32 sp50, struct GraphNode *sp54, UNUSED void *context) { - struct GraphNode *graphNode; // sp4c - Gfx *displayList; // sp48 -@@ -80,6 +93,8 @@ Gfx *geo_title_screen(s32 sp50, struct GraphNode *sp54, UNUSED void *context) { - f32 scaleX; // sp34 - f32 scaleY; // sp30 +@@ -82,2 +95,4 @@ Gfx *geo_title_screen(s32 sp50, struct GraphNode *sp54, UNUSED void *context) { f32 scaleZ; // sp2c + Vec3f scale; + Vec3f scaleInterpolated; graphNode = sp54; - displayList = NULL; - displayListIter = NULL; -@@ -110,7 +125,11 @@ Gfx *geo_title_screen(s32 sp50, struct GraphNode *sp54, UNUSED void *context) { - scaleY = 0.0f; - scaleZ = 0.0f; - } -- guScale(scaleMat, scaleX, scaleY, scaleZ); +@@ -113,2 +128,7 @@ Gfx *geo_title_screen(s32 sp50, struct GraphNode *sp54, UNUSED void *context) { + guScale(scaleMat, scaleX, scaleY, scaleZ); + vec3f_set(scale, scaleX, scaleY, scaleZ); + interpolate_vectors(scaleInterpolated, sIntroScale, scale); + vec3f_set(sIntroScale, scaleX, scaleY, scaleZ); + guScale(scaleMat, scaleInterpolated[0], scaleInterpolated[1], scaleInterpolated[2]); + sIntroScalePos = displayListIter; gSPMatrix(displayListIter++, scaleMat, G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH); - gSPDisplayList(displayListIter++, &intro_seg7_dl_0700B3A0); - gSPPopMatrix(displayListIter++, G_MTX_MODELVIEW); diff --git a/src/pc/gfx/gfx_dxgi.cpp b/src/pc/gfx/gfx_dxgi.cpp -index 0467495..fa4eb33 100644 +index 04674952..fa4eb33c 100644 --- a/src/pc/gfx/gfx_dxgi.cpp +++ b/src/pc/gfx/gfx_dxgi.cpp -@@ -36,10 +36,10 @@ - - #ifdef VERSION_EU +@@ -38,6 +38,6 @@ #define FRAME_INTERVAL_US_NUMERATOR 40000 -#define FRAME_INTERVAL_US_DENOMINATOR 1 +#define FRAME_INTERVAL_US_DENOMINATOR 2 @@ -1887,31 +1458,16 @@ index 0467495..fa4eb33 100644 -#define FRAME_INTERVAL_US_DENOMINATOR 3 +#define FRAME_INTERVAL_US_DENOMINATOR 6 #endif - - using namespace Microsoft::WRL; // For ComPtr diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c -index 242d6e8..08e5cac 100644 +index 4d907893..0b21e230 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c -@@ -59,7 +59,7 @@ static void (*kb_all_keys_up)(void) = NULL; - // whether to use timer for frame control - static bool use_timer = true; +@@ -55,3 +55,3 @@ static bool use_timer = true; // time between consequtive game frames -static const int frame_time = 1000 / FRAMERATE; +static const int frame_time = 1000 / (2 * FRAMERATE); - const SDL_Scancode windows_scancode_table[] = { - /* 0 1 2 3 4 5 6 7 */ -@@ -146,13 +146,17 @@ int test_vsync(void) { - - static inline void gfx_sdl_set_vsync(const bool enabled) { - #ifdef TARGET_SWITCH -- SDL_GL_SetSwapInterval(2); -+ SDL_GL_SetSwapInterval(1); - use_timer = false; - #else - if (enabled) { - // try to detect refresh rate +@@ -144,3 +144,7 @@ static inline void gfx_sdl_set_vsync(const bool enabled) { SDL_GL_SetSwapInterval(1); - const int vblanks = test_vsync(); + int vblanks = test_vsync(); @@ -1920,15 +1476,11 @@ index 242d6e8..08e5cac 100644 + else + vblanks /= 2; if (vblanks) { - printf("determined swap interval: %d\n", vblanks); - SDL_GL_SetSwapInterval(vblanks); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c -index 923e7ea..4fe6161 100644 +index 3a725c03..7bff83d5 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c -@@ -83,6 +83,25 @@ void send_display_list(struct SPTask *spTask) { - #define SAMPLES_LOW 528 - #endif +@@ -87,2 +87,21 @@ void send_display_list(struct SPTask *spTask) { +static inline void patch_interpolations(void) { + extern void mtx_patch_interpolated(void); @@ -1950,17 +1502,11 @@ index 923e7ea..4fe6161 100644 +} + void produce_one_frame(void) { - gfx_start_frame(); - -@@ -110,6 +129,11 @@ void produce_one_frame(void) { - audio_api->play((u8 *)audio_buffer, 2 * num_audio_samples * 4); - +@@ -114,2 +133,7 @@ void produce_one_frame(void) { gfx_end_frame(); + + gfx_start_frame(); + patch_interpolations(); + send_display_list(gGfxSPTask); + gfx_end_frame(); - } - - void audio_shutdown(void) { \ No newline at end of file + } \ No newline at end of file