shithub: zelda3

Download patch

ref: 97f28c534d3e54af2d1ff106fb10a03b7178482f
parent: 3ef8be9e8ddc7b5acefbf98e5264a8547f7ef090
author: Snesrev <[email protected]>
date: Mon Oct 17 19:40:56 EDT 2022

Avoid calling ApplyLinksMovementToCamera twice per frame (#126)

Bug report:
If you bounce between two bouncers for about 30 seconds,
then change rooms, the camera coordinates desync until you
leave the dungeon or use the mirror.

--- a/player.c
+++ b/player.c
@@ -13,6 +13,8 @@
 #include "player_oam.h"
 #include "sprite_main.h"
 
+static bool g_ApplyLinksMovementToCamera_called;
+
 static const uint8 kSpinAttackDelays[] = { 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 3, 3, 3, 3, 4, 4, 1, 5 };
 static const uint8 kFireBeamSounds[] = { 1, 2, 3, 4, 0, 9, 18, 27 };
 static const int8 kTagalongArr1[] = { -1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -231,6 +233,8 @@
 }
 
 void PlayerHandler_00_Ground_3() {  // 8781a0
+  g_ApplyLinksMovementToCamera_called = false;
+
   link_z_coord = 0xffff;
   link_actual_vel_z = 0xff;
   link_recoilmode_timer = 0;
@@ -322,6 +326,13 @@
 
 getout_dostuff:
   fallhole_var1 = 0;
+
+  // HandleIndoorCameraAndDoors must not be called twice in the same frame,
+  // this might mess up camera positioning. For example when using spin attack
+  // in between bumpers.
+  if (g_ApplyLinksMovementToCamera_called && (enhanced_features0 & kFeatures0_MiscBugFixes))
+    return;
+
   HandleIndoorCameraAndDoors();
 }
 
@@ -6125,6 +6136,10 @@
 }
 
 void ApplyLinksMovementToCamera() {  // 87e9d3
+  // Sometimes, when using spin attack, this routine will end up getting
+  // called twice in the same frame, which messes up things.
+  g_ApplyLinksMovementToCamera_called = true;
+
   link_y_page_movement_delta = (link_y_coord >> 8) - link_y_coord_safe_return_hi;
   link_x_page_movement_delta = (link_x_coord >> 8) - link_x_coord_safe_return_hi;