From 781c422c76b8511cdfb3913847a6da3ed1001b9e Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 20 May 2016 22:56:45 +0100 Subject: [PATCH] integrate tick variables --- src/addresses.h | 9 +++------ src/game.c | 4 +++- src/game.h | 4 +++- src/input.c | 8 ++++---- src/interface/window.c | 2 +- src/platform/windows.c | 1 - src/rct2.c | 14 ++++---------- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index a423340620..59f01c39cf 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -145,10 +145,6 @@ // Of type viewport interaction #define RCT2_ADDRESS_PAINT_SETUP_CURRENT_TYPE 0x009DE570 -#define RCT2_ADDRESS_LAST_TICK_COUNT 0x009DE580 - -#define RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE 0x009DE588 - #define RCT2_ADDRESS_PAINT_BOUNDBOX_OFFSET_X 0x009DEA52 #define RCT2_ADDRESS_PAINT_BOUNDBOX_OFFSET_Y 0x009DEA54 #define RCT2_ADDRESS_PAINT_BOUNDBOX_OFFSET_Z 0x009DEA56 @@ -163,8 +159,6 @@ #define RCT2_ADDRESS_TEXTINPUT_WINDOWNUMBER 0x009DEB8A #define RCT2_ADDRESS_TEXTINPUT_WINDOWCLASS 0x009DEB8C -#define RCT2_ADDRESS_CMDLINE 0x009E2D98 - #define RCT2_ADDRESS_MOUSE_WRITE_INDEX 0x009E2DE4 #define RCT2_ADDRESS_MOUSE_READ_INDEX 0x009E2DE8 #define RCT2_ADDRESS_HFONT 0x009E2DEC @@ -496,7 +490,9 @@ #define RCT2_ADDRESS_PICKEDUP_PEEP_X 0x009DE554 #define RCT2_ADDRESS_PICKEDUP_PEEP_Y 0x009DE556 +#define RCT2_ADDRESS_LAST_TICK_COUNT 0x009DE580 #define RCT2_ADDRESS_PALETTE_EFFECT_FRAME_NO 0x009DE584 +#define RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE 0x009DE588 // Flags: // 0x1 Enable selection @@ -530,6 +526,7 @@ #define RCT2_ADDRESS_GAME_PAUSED 0x009DEA6E #define RCT2_ADDRESS_WINDOW_DPI 0x009DEA74 +#define RCT2_ADDRESS_CMDLINE 0x009E2D98 #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C #define RCT2_ADDRESS_LAND_LOWER_COST 0x009E2E20 #define RCT2_ADDRESS_SELECTED_TERRAIN_EDGE 0x009E2E24 diff --git a/src/game.c b/src/game.c index 83d8735137..8cf4f4b356 100644 --- a/src/game.c +++ b/src/game.c @@ -59,6 +59,8 @@ #define NUMBER_OF_AUTOSAVES_TO_KEEP 9 +uint16 gTicksSinceLastUpdate; +uint32 gLastTickCount; uint8 gGamePaused = 0; int gGameSpeed = 1; float gDayNightCycle = 0; @@ -261,7 +263,7 @@ void game_update() if (gGameSpeed > 1) { numUpdates = 1 << (gGameSpeed - 1); } else { - numUpdates = RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, uint16) / 31; + numUpdates = gTicksSinceLastUpdate / 31; numUpdates = clamp(1, numUpdates, 4); } diff --git a/src/game.h b/src/game.h index dd0276acb1..87c361482b 100644 --- a/src/game.h +++ b/src/game.h @@ -130,8 +130,10 @@ extern uint16 gErrorStringId; extern GAME_COMMAND_POINTER* new_game_command_table[67]; -#define gCurrentTicks RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) +#define gCurrentTicks RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) +extern uint16 gTicksSinceLastUpdate; +extern uint32 gLastTickCount; extern uint8 gGamePaused; extern int gGameSpeed; extern float gDayNightCycle; diff --git a/src/input.c b/src/input.c index e22d7f6110..a1416759c3 100644 --- a/src/input.c +++ b/src/input.c @@ -271,7 +271,7 @@ static void input_scroll_right(int x, int y, int state) switch (state) { case MOUSE_STATE_RELEASED: - _ticksSinceDragStart += RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, sint16); + _ticksSinceDragStart += gTicksSinceLastUpdate; if (x != 0 || y != 0) { _ticksSinceDragStart = 1000; input_scroll_drag_continue(x, y, w); @@ -541,7 +541,7 @@ static void input_viewport_drag_continue() } viewport = w->viewport; - _ticksSinceDragStart += RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, sint16); + _ticksSinceDragStart += gTicksSinceLastUpdate; if (viewport == NULL) { platform_show_cursor(); gInputState = INPUT_STATE_RESET; @@ -1346,7 +1346,7 @@ static void input_update_tooltip(rct_window *w, int widgetIndex, int x, int y) { if (gTooltipWidget.window_classification == 255) { if (gTooltipNotShownTicks < 500 || (gTooltipCursorX == x && gTooltipCursorY == y)) { - gTooltipTimeout = RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, uint16); + gTooltipTimeout = gTicksSinceLastUpdate; int time = 2000; if (gTooltipNotShownTicks >= 1) { @@ -1368,7 +1368,7 @@ static void input_update_tooltip(rct_window *w, int widgetIndex, int x, int y) ) { window_tooltip_close(); } - gTooltipTimeout += RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, uint16); + gTooltipTimeout += gTicksSinceLastUpdate; if (gTooltipTimeout >= 8000) { window_close_by_class(WC_TOOLTIP); } diff --git a/src/interface/window.c b/src/interface/window.c index e9d9f5b5f9..0859c421f4 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -161,7 +161,7 @@ void window_update_all() gfx_draw_all_dirty_blocks(); // 1000 tick update - RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, sint16) += RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, sint16); + RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, sint16) += gTicksSinceLastUpdate; if (RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, sint16) >= 1000) { RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, sint16) = 0; for (rct_window* w = RCT2_LAST_WINDOW; w >= g_window_list; w--) diff --git a/src/platform/windows.c b/src/platform/windows.c index 0a0cb58e42..8f8fd650a9 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -91,7 +91,6 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta } RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE) = hInstance; - RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine; // argv = CommandLineToArgvA(lpCmdLine, &argc); argv = (char**)windows_get_command_line_args(&argc); diff --git a/src/rct2.c b/src/rct2.c index 24023d734c..52f7456f08 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -141,7 +141,6 @@ int rct2_init() log_verbose("initialising game"); gScenarioTicks = 0; - RCT2_GLOBAL(0x009AC310, char*) = RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, char*); util_srand((unsigned int)time(0)); if (!rct2_init_directories()) return 0; @@ -436,16 +435,11 @@ int check_file_path(int pathId) void rct2_update() { - int tick, tick2; - - tick = SDL_GetTicks(); - - tick2 = tick - RCT2_GLOBAL(RCT2_ADDRESS_LAST_TICK_COUNT, sint32); - RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, sint16) = tick2 = min(tick2, 500); - - RCT2_GLOBAL(RCT2_ADDRESS_LAST_TICK_COUNT, sint32) = tick; + int tickCount = SDL_GetTicks(); + gTicksSinceLastUpdate = min(tickCount - gLastTickCount, 500); + gLastTickCount = tickCount; if (game_is_not_paused()) { - gPaletteEffectFrame += tick2; + gPaletteEffectFrame += gTicksSinceLastUpdate; } date_update_real_time_of_day();