From a144f44d5edbfd2cb4e2ebaeb20f8611aae31550 Mon Sep 17 00:00:00 2001
From: Sonic Dreamcaster <alejandro.asenjo88@gmail.com>
Date: Sun, 17 Nov 2024 18:03:31 -0300
Subject: [PATCH] improve ground

---
 src/engine/fox_bg.c      | 64 +++++++++++++++++++++++++++-------------
 src/engine/fox_display.c | 25 +++++++---------
 2 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/src/engine/fox_bg.c b/src/engine/fox_bg.c
index 437bba19..44ea8416 100644
--- a/src/engine/fox_bg.c
+++ b/src/engine/fox_bg.c
@@ -501,7 +501,7 @@ void Background_DrawBackdrop(void) {
 
                         if (skipInterpolation) {
                             // @port Skip interpolation
-                            FrameInterpolation_ShouldInterpolateFrame(false);
+                            FrameInterpolation_ShouldInterpolateFrame(true);
                         } else {
                             // @port Pop the transform id.
                             FrameInterpolation_RecordCloseChild();
@@ -557,7 +557,7 @@ void Background_DrawBackdrop(void) {
 
                         if (skipInterpolation) {
                             // @port Skip interpolation
-                            FrameInterpolation_ShouldInterpolateFrame(false);
+                            FrameInterpolation_ShouldInterpolateFrame(true);
                         } else {
                             // @port Pop the transform id.
                             FrameInterpolation_RecordCloseChild();
@@ -658,7 +658,7 @@ void Background_DrawBackdrop(void) {
                         }
                         if (skipInterpolation) {
                             // @port Skip interpolation
-                            FrameInterpolation_ShouldInterpolateFrame(false);
+                            FrameInterpolation_ShouldInterpolateFrame(true);
                         } else {
                             // @port Pop the transform id.
                             FrameInterpolation_RecordCloseChild();
@@ -722,7 +722,6 @@ void Background_DrawBackdrop(void) {
                     sp13C = Math_ModF(sp13C, 7280.0f);
 
                     f32 corneriaCamYawDeg = Math_RadToDeg(gPlayer[0].camYaw);
-
                     if (gLevelMode == LEVELMODE_ON_RAILS) {
                         if (corneriaCamYawDeg < 180.0f) {
                             sp13C = -(7280.0f - sp13C);
@@ -746,7 +745,7 @@ void Background_DrawBackdrop(void) {
 
                     // Render the textures across a wider range to cover the screen
                     for (int i = 0; i < 6; i++) {
-                            if (skipInterpolation) {
+                        if (skipInterpolation) {
                             // @port Skip interpolation
                             FrameInterpolation_ShouldInterpolateFrame(false);
                         } else {
@@ -772,7 +771,7 @@ void Background_DrawBackdrop(void) {
 
                         if (skipInterpolation) {
                             // @port Skip interpolation
-                            FrameInterpolation_ShouldInterpolateFrame(false);
+                            FrameInterpolation_ShouldInterpolateFrame(true);
                         } else {
                             // @port Pop the transform id.
                             FrameInterpolation_RecordCloseChild();
@@ -1127,6 +1126,11 @@ Vtx dynaFloor1Vtx[17 * 17];
 Vtx dynaFloor2Vtx[17 * 17];
 #endif
 
+static u8 skipInterpolationGround = 0;
+static u8 skipInterpolationGround2 = 0;
+static f32 prevPlayerPath = 0.0f;
+static f32 prevPlayerPath2 = 0.0f;
+
 void Background_DrawGround(void) {
     f32 sp1D4;
     s32 i;
@@ -1651,22 +1655,42 @@ void Background_DrawGround(void) {
                 RCP_SetupDL_20(gFogRed, gFogGreen, gFogBlue, gFogAlpha, gFogNear, gFogFar);
             }
 
-            for (i = 0; i < ARRAY_COUNT(sGroundPositions360x_FIX); i++) {
-                Matrix_Push(&gGfxMatrix);
-                Matrix_Translate(gGfxMatrix, sGroundPositions360x_FIX[i], 0.0f, sGroundPositions360z_FIX[i],
-                                 MTXF_APPLY);
-                Matrix_SetGfxMtx(&gMasterDisp);
-                if (gCurrentLevel == LEVEL_FORTUNA) {
-                    gSPDisplayList(gMasterDisp++, D_FO_6001360);
-                } else if (gCurrentLevel == LEVEL_KATINA) {
-                    gSPDisplayList(gMasterDisp++, D_KA_6009250);
-                } else if (gCurrentLevel == LEVEL_BOLSE) {
-                    gSPDisplayList(gMasterDisp++, D_BO_600A810);
-                } else if (gCurrentLevel == LEVEL_VENOM_2) {
-                    gSPDisplayList(gMasterDisp++, D_VE2_6010700);
+            skipInterpolationGround = (fabsf(gPlayer[gPlayerNum].xPath - prevPlayerPath) > 12000.0f / 2.0f);
+            skipInterpolationGround2 = prevPlayerPath2 != sp1D4;
+
+            // if (skipInterpolationGround || skipInterpolationGround2) {
+            //     printf(" Ground interpolation Skipped! \n");
+            // }
+
+            {
+                u32 skipInfo = skipInterpolationGround << 8 | skipInterpolationGround2 << 16;
+
+                printf("skipInfo: %x \n", skipInfo);
+
+                for (i = 0; i < ARRAY_COUNT(sGroundPositions360x_FIX); i++) {
+                    FrameInterpolation_RecordOpenChild("Ground", i | skipInfo);
+                    FrameInterpolation_RecordMarker(__FILE__, __LINE__);
+
+                    Matrix_Push(&gGfxMatrix);
+                    Matrix_Translate(gGfxMatrix, sGroundPositions360x_FIX[i], 0.0f, sGroundPositions360z_FIX[i],
+                                     MTXF_APPLY);
+                    Matrix_SetGfxMtx(&gMasterDisp);
+                    if (gCurrentLevel == LEVEL_FORTUNA) {
+                        gSPDisplayList(gMasterDisp++, D_FO_6001360);
+                    } else if (gCurrentLevel == LEVEL_KATINA) {
+                        gSPDisplayList(gMasterDisp++, D_KA_6009250);
+                    } else if (gCurrentLevel == LEVEL_BOLSE) {
+                        gSPDisplayList(gMasterDisp++, D_BO_600A810);
+                    } else if (gCurrentLevel == LEVEL_VENOM_2) {
+                        gSPDisplayList(gMasterDisp++, D_VE2_6010700);
+                    }
+                    Matrix_Pop(&gGfxMatrix);
+
+                    FrameInterpolation_RecordCloseChild();
                 }
-                Matrix_Pop(&gGfxMatrix);
             }
+            prevPlayerPath = gPlayer[gPlayerNum].xPath;
+            prevPlayerPath2 = sp1D4;
             break;
 
         case LEVEL_VERSUS:
diff --git a/src/engine/fox_display.c b/src/engine/fox_display.c
index b79ba061..bf1053d1 100644
--- a/src/engine/fox_display.c
+++ b/src/engine/fox_display.c
@@ -7,6 +7,9 @@
 #include "assets/ast_sector_z.h"
 #include "port/interpolation/FrameInterpolation.h"
 
+// f32 path1 = 0.0f;
+// f32 path2 = 0.0f;
+
 Vec3f D_display_801613B0[4];
 Vec3f D_display_801613E0[4];
 s16 gReflectY;
@@ -2068,6 +2071,7 @@ void Display_Update(void) {
 
         if (gControllerPress[0].button & L_TRIG) {
             pl->state_1C8 = PLAYERSTATE_1C8_LEVEL_COMPLETE;
+            gMissionStatus = MISSION_ACCOMPLISHED;
         }
     }
 
@@ -2102,22 +2106,15 @@ void Display_Update(void) {
         gLaserStrength[0] = 2;
     }
     Hit64_Main();
-    // background testing
+    // ground testing
 #if 0
     RCP_SetupDL(&gMasterDisp, SETUPDL_83);
     gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
-    if (gTestVarF > 0.0f) {
-        Graphics_DisplaySmallText(10, 220, 1.0f, 1.0f, "TEST:");
-    } else {
-        Graphics_DisplaySmallText(10, 220, 1.0f, 1.0f, "TESTNEG:");
-    }
-    Graphics_DisplaySmallNumber(80, 220, (int) ABS(gTestVarF));
-
-    if (gControllerPress[0].button & Z_TRIG) {
-        gTestVarF -= 10;
-    } else if (gControllerPress[0].button & R_TRIG) {
-        gTestVarF += 10;
-    }
-
+    Graphics_DisplaySmallText(10, 210, 1.0f, 1.0f, "PATH1:");
+    Graphics_DisplaySmallNumber(60, 210, (int) ABS(path1));
+    Graphics_DisplaySmallText(10, 220, 1.0f, 1.0f, "PATH2:");
+    Graphics_DisplaySmallNumber(60, 220, (int) ABS(path2));
+    if (path1 < 0.0f) Graphics_DisplaySmallText(110, 210, 1.0f, 1.0f, "NEG:");
+    if (path2 < 0.0f) Graphics_DisplaySmallText(110, 220, 1.0f, 1.0f, "NEG:");
 #endif
 }