From 2f573d17f900fc15b0e93e8039c4bae85cd5e30b Mon Sep 17 00:00:00 2001 From: djoslin0 Date: Sun, 15 Jun 2025 03:15:23 -0700 Subject: [PATCH] Change get_game_tick_counter() to use gGlobalTimer (#853) The old version was incrementing at the start of the code iteration, but it makes more sense to increment after the frame is built. That way every event within one visible game tick will get the same tick identifier Co-authored-by: MysterD --- autogen/lua_definitions/functions.lua | 2 +- docs/lua/functions-6.md | 2 +- src/game/game_init.c | 3 --- src/game/game_init.h | 1 - src/pc/lua/utils/smlua_misc_utils.c | 2 +- src/pc/lua/utils/smlua_misc_utils.h | 2 +- 6 files changed, 4 insertions(+), 8 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 062072618..21898980a 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -11105,7 +11105,7 @@ function texture_to_lua_table(tex) end --- @return integer ---- Gets the total number of game ticks since the game was launched. Wraps around at U64_MAX. +--- Gets the total number of game ticks since the game was launched. Wraps around at U32_MAX. function get_game_tick_counter() -- ... end diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md index 6e6331fc1..0b1e93180 100644 --- a/docs/lua/functions-6.md +++ b/docs/lua/functions-6.md @@ -5131,7 +5131,7 @@ Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, re ## [get_game_tick_counter](#get_game_tick_counter) ### Description -Gets the total number of game ticks since the game was launched. Wraps around at U64_MAX. +Gets the total number of game ticks since the game was launched. Wraps around at U32_MAX. ### Lua Example `local integerValue = get_game_tick_counter()` diff --git a/src/game/game_init.c b/src/game/game_init.c index 63ea79102..2e13c7e57 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -63,7 +63,6 @@ struct Controller *gPlayer3Controller = &gControllers[2]; struct DemoInput *gCurrDemoInput = NULL; // demo input sequence u16 gDemoInputListID = 0; struct DemoInput gRecordedDemoInput = { 0 }; // possibly removed in EU. TODO: Check -u64 gGameTickCounter = 0; /** * Initializes the Reality Display Processor (RDP). @@ -603,8 +602,6 @@ void thread5_game_loop(UNUSED void *arg) { void game_loop_one_iteration(void) { profiler_log_thread5_time(THREAD5_START); - gGameTickCounter++; - // if any controllers are plugged in, start read the data for when // read_controller_inputs is called later. if (gControllerBits) { diff --git a/src/game/game_init.h b/src/game/game_init.h index ee6edd254..86710b1e0 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -58,7 +58,6 @@ extern u8 gDemoInputs[]; extern u16 frameBufferIndex; extern u32 gGlobalTimer; -extern u64 gGameTickCounter; void setup_game_memory(void); void thread5_game_loop(UNUSED void *arg); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index d567335ea..6ce1989c2 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -627,5 +627,5 @@ void texture_to_lua_table(const u8 *tex) { } u64 get_game_tick_counter(void) { - return gGameTickCounter; + return gGlobalTimer; } diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index 8d2bc1b18..af346b3f0 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -234,7 +234,7 @@ struct GraphNodeHeldObject* geo_get_current_held_object(void); /* |description|Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a table as a pure memory buffer. Supports rgba16 and rgba32 textures.|descriptionEnd|*/ void texture_to_lua_table(const u8 *tex); -/* |description|Gets the total number of game ticks since the game was launched. Wraps around at U64_MAX.|descriptionEnd|*/ +/* |description|Gets the total number of game ticks since the game was launched. Wraps around at U32_MAX.|descriptionEnd|*/ u64 get_game_tick_counter(void); #endif