mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-17 21:42:42 +00:00
Add get_game_tick_counter() (#852)
Coop now maintains a counter that increments at the start of each game tick, And another counter that increments at the start of each frame render. This is to be able to identify specific frames regardless of mod load, hook, and execution order. --------- Co-authored-by: MysterD <myster@d>
This commit is contained in:
parent
24b92ecc2a
commit
f42e4ad55b
8 changed files with 55 additions and 0 deletions
|
|
@ -11104,6 +11104,12 @@ 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.
|
||||
function get_game_tick_counter()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param name string
|
||||
--- @return ModelExtendedId
|
||||
--- Gets the extended model ID for the `name` of a `GeoLayout`
|
||||
|
|
|
|||
|
|
@ -5128,6 +5128,27 @@ Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, re
|
|||
|
||||
<br />
|
||||
|
||||
## [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.
|
||||
|
||||
### Lua Example
|
||||
`local integerValue = get_game_tick_counter()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`u64 get_game_tick_counter(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from smlua_model_utils.h
|
||||
|
||||
|
|
|
|||
|
|
@ -1991,6 +1991,7 @@
|
|||
- [geo_get_current_camera](functions-6.md#geo_get_current_camera)
|
||||
- [geo_get_current_held_object](functions-6.md#geo_get_current_held_object)
|
||||
- [texture_to_lua_table](functions-6.md#texture_to_lua_table)
|
||||
- [get_game_tick_counter](functions-6.md#get_game_tick_counter)
|
||||
|
||||
<br />
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ 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).
|
||||
|
|
@ -602,6 +603,8 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ extern u8 gDemoInputs[];
|
|||
|
||||
extern u16 frameBufferIndex;
|
||||
extern u32 gGlobalTimer;
|
||||
extern u64 gGameTickCounter;
|
||||
|
||||
void setup_game_memory(void);
|
||||
void thread5_game_loop(UNUSED void *arg);
|
||||
|
|
|
|||
|
|
@ -33296,6 +33296,21 @@ int smlua_func_texture_to_lua_table(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_get_game_tick_counter(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 0) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_game_tick_counter", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
lua_pushinteger(L, get_game_tick_counter());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// smlua_model_utils.h //
|
||||
/////////////////////////
|
||||
|
|
@ -37179,6 +37194,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "geo_get_current_camera", smlua_func_geo_get_current_camera);
|
||||
smlua_bind_function(L, "geo_get_current_held_object", smlua_func_geo_get_current_held_object);
|
||||
smlua_bind_function(L, "texture_to_lua_table", smlua_func_texture_to_lua_table);
|
||||
smlua_bind_function(L, "get_game_tick_counter", smlua_func_get_game_tick_counter);
|
||||
|
||||
// smlua_model_utils.h
|
||||
smlua_bind_function(L, "smlua_model_util_get_id", smlua_func_smlua_model_util_get_id);
|
||||
|
|
|
|||
|
|
@ -625,3 +625,7 @@ void texture_to_lua_table(const u8 *tex) {
|
|||
lua_rawseti(L, -2, i / bytesPerPixel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
u64 get_game_tick_counter(void) {
|
||||
return gGameTickCounter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,4 +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|*/
|
||||
u64 get_game_tick_counter(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue