From 3b2fa2ddce242f20c3a6553910bbdee235e927f0 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 24 Aug 2014 14:52:38 +0100 Subject: [PATCH] Trying to find cause of subtle bug --- src/map.c | 7 +++---- src/map.h | 12 ++++++------ src/viewport.c | 24 +++++++++++++++++------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/map.c b/src/map.c index d965ed6fab..55ad530943 100644 --- a/src/map.c +++ b/src/map.c @@ -168,7 +168,7 @@ int map_element_height(int x, int y) // Remove the extra height bit slope &= 0xF; - uint8 quad, quad_extra; // which quadrant the element is in? + sint8 quad, quad_extra; // which quadrant the element is in? // quad_extra is for extra height tiles uint8 xl, yl; // coordinates across this tile @@ -198,7 +198,7 @@ int map_element_height(int x, int y) quad = TILE_SIZE - yl - xl; break; case 8: // NW corner up - quad = xl - yl; + quad = yl - xl; break; } // If the element is in the quadrant with the slope, raise its height @@ -241,7 +241,7 @@ int map_element_height(int x, int y) break; case 14: // NE corner down quad_extra = (TILE_SIZE - xl) + (TILE_SIZE - yl); - quad = TILE_SIZE - yl - xl; + quad = TILE_SIZE - yl - xl - 1; break; } @@ -255,7 +255,6 @@ int map_element_height(int x, int y) // so we move *down* the slope if (quad < 0) { height += quad / 2; - height += 0xFF00; } } diff --git a/src/map.h b/src/map.h index cacd717306..8aa4e171fd 100644 --- a/src/map.h +++ b/src/map.h @@ -24,8 +24,8 @@ #include "rct2.h" typedef struct { - uint8 slope; - uint8 terrain; + uint8 slope; //4 + uint8 terrain; //5 uint8 grass_length; uint8 ownership; } rct_map_element_surface_properties; @@ -92,10 +92,10 @@ typedef union { * size: 0x08 */ typedef struct { - uint8 type; - uint8 flags; - uint8 base_height; - uint8 clearance_height; + uint8 type; //0 + uint8 flags; //1 + uint8 base_height; //2 + uint8 clearance_height; //3 rct_map_element_properties properties; } rct_map_element; diff --git a/src/viewport.c b/src/viewport.c index e91bbd7da5..f39df94dfe 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -18,6 +18,7 @@ * along with this program. If not, see . *****************************************************************************/ +#include #include "addresses.h" #include "config.h" #include "gfx.h" @@ -221,25 +222,32 @@ void viewport_update_pointers() } void sub_689174(sint16* x, sint16* y, uint8 curr_rotation){ + //RCT2_CALLFUNC_X(0x00689174, (int*)&x, (int*)&y, &ecx, &curr_rotation, (int*)&window, (int*)&viewport, &ebp); + int start_x = *x; int start_y = *y; - int eax, ebx, ecx = 0; + int eax = start_x, ebx, ecx = 0; switch (curr_rotation){ case 0: for (int i = 0; i < 6; ++i){ int edx = start_x / 2; - eax = -start_x; + eax = -start_x / 2; eax += start_y; ebx = start_y + edx; eax += ecx; ebx += ecx; + + int __eax = eax, __ebx = 0, __ecx = ebx, __edx = 0, __edi= 0, __esi = 0, __ebp = 0; + RCT2_CALLFUNC_X(0x00662783, &__eax, &__ebx, &__ecx, &__edx, &__esi, &__edi, &__ebp); ecx = map_element_height((0xFFFF) & eax, (0xFFFF) & ebx); + ecx = map_element_height((0xFFFF) & eax, (0xFFFF) & ebx); + assert(ecx == __edx); } break; case 1: for (int i = 0; i < 6; ++i){ int edx = start_x / 2; - eax = -start_x; + eax = -start_x / 2; eax -= start_y; ebx = start_y - edx; eax -= ecx; @@ -250,7 +258,7 @@ void sub_689174(sint16* x, sint16* y, uint8 curr_rotation){ case 2: for (int i = 0; i < 6; ++i){ int edx = start_x / 2; - eax -= start_y; + eax = start_x / 2 - start_y; ebx = -start_y; ebx -= edx; eax -= ecx; @@ -261,7 +269,7 @@ void sub_689174(sint16* x, sint16* y, uint8 curr_rotation){ case 3: for (int i = 0; i < 6; ++i){ int edx = start_x / 2; - eax += start_y; + eax = start_x / 2 + start_y; ebx = -start_y; ebx += edx; eax += ecx; @@ -272,6 +280,10 @@ void sub_689174(sint16* x, sint16* y, uint8 curr_rotation){ } *x = eax; *y = ebx; + int _eax = start_x, _ebx = start_y, _ecx, _edx = curr_rotation, _esi, _edi, _ebp; + RCT2_CALLFUNC_X(0x00689174, &_eax, &_ebx, &_ecx, &_edx, &_esi, &_edi, &_ebp); + assert(*x == (sint16)_eax); + assert(*y == (sint16)_ebx); } /** @@ -307,9 +319,7 @@ void viewport_update_position(rct_window *window) sint16 y = viewport->view_height / 2 + window->saved_view_y; int curr_rotation = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32); - int ecx = 0, ebp; sub_689174(&x, &y, curr_rotation); - //RCT2_CALLFUNC_X(0x00689174, (int*)&x, (int*)&y, &ecx, &curr_rotation, (int*)&window, (int*)&viewport, &ebp); RCT2_CALLPROC_X(0x006E7A15, x, y, 0, 0, (int)window, (int)viewport, 0);