From 73db1b034589bb19b275517564ee2bf12d150e63 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Fri, 6 Jun 2025 07:29:24 +1000 Subject: [PATCH] fix autogen texinfo get --- autogen/convert_functions.py | 8 +--- docs/lua/functions-3.md | 8 ++-- src/pc/djui/djui_hud_utils.c | 8 ++-- src/pc/djui/djui_hud_utils.h | 10 ++-- src/pc/lua/smlua_functions.c | 2 +- src/pc/lua/smlua_functions_autogen.c | 8 ++-- src/pc/lua/smlua_utils.c | 68 ++++++++++++++-------------- src/pc/lua/smlua_utils.h | 3 +- 8 files changed, 53 insertions(+), 62 deletions(-) diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 3a7cc9159..04c1cd120 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -776,8 +776,8 @@ def build_param(fid, param, i): ptype = alter_type(param['type']) pid = param['identifier'] - if param.get('texinfo', False): - return ' struct TextureInfo *texInfo = get_texture_info_from_lua(L);\n' + if "struct TextureInfo" in ptype and "*" in ptype: + return ' struct TextureInfo *texInfo = smlua_to_texture_info(L, %d);\n' % (i) if ptype in VEC_TYPES: if ptype == "Vec3f" and fid in SOUND_FUNCTIONS: @@ -1017,10 +1017,6 @@ def process_function(fname, line, description): param['out'] = True param_str = param_str[len('OUT'):].strip() - if param_str.startswith('TEXINFO '): - param['texinfo'] = True - param_str = param_str[len('TEXINFO'):].strip() - if param_str.endswith('*') or ' ' not in param_str: param['type'] = normalize_type(param_str) param['identifier'] = 'arg%d' % param_index diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 1ea37753b..b65f95308 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -3367,7 +3367,7 @@ Renders a DJUI HUD texture onto the screen - None ### C Prototype -`void djui_hud_render_texture(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH);` +`void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH);` [:arrow_up_small:](#) @@ -3398,7 +3398,7 @@ Renders a DJUI HUD texture tile onto the screen - None ### C Prototype -`void djui_hud_render_texture_tile(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);` +`void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);` [:arrow_up_small:](#) @@ -3429,7 +3429,7 @@ Renders an interpolated DJUI HUD texture onto the screen - None ### C Prototype -`void djui_hud_render_texture_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH);` +`void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH);` [:arrow_up_small:](#) @@ -3464,7 +3464,7 @@ Renders an interpolated DJUI HUD texture tile onto the screen - None ### C Prototype -`void djui_hud_render_texture_tile_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);` +`void djui_hud_render_texture_tile_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);` [:arrow_up_small:](#) diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index ae9b8d15f..6500fa269 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -512,15 +512,15 @@ void djui_hud_render_texture_tile_raw(const u8* texture, u32 bitSize, u32 width, gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); } -void djui_hud_render_texture(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH) { +void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH) { djui_hud_render_texture_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, x, y, scaleW, scaleH); } -void djui_hud_render_texture_tile(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) { +void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) { djui_hud_render_texture_tile_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, x, y, scaleW, scaleH, tileX, tileY, tileW, tileH); } -void djui_hud_render_texture_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH) { +void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH) { Gfx* savedHeadPos = gDisplayListHead; f32 savedZ = gDjuiHudUtilsZ; @@ -544,7 +544,7 @@ void djui_hud_render_texture_interpolated(TEXINFO struct TextureInfo* texInfo, f interp->rotation = sRotation; } -void djui_hud_render_texture_tile_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) { +void djui_hud_render_texture_tile_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) { Gfx* savedHeadPos = gDisplayListHead; f32 savedZ = gDjuiHudUtilsZ; diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index 7b36d21b8..47bd8ff69 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -1,8 +1,6 @@ #ifndef DJUI_HUD_UTILS_H #define DJUI_HUD_UTILS_H -#define TEXINFO - enum HudUtilsResolution { RESOLUTION_DJUI, RESOLUTION_N64, @@ -114,15 +112,15 @@ void djui_hud_print_text(const char* message, f32 x, f32 y, f32 scale); /* |description|Prints interpolated DJUI HUD text onto the screen|descriptionEnd| */ void djui_hud_print_text_interpolated(const char* message, f32 prevX, f32 prevY, f32 prevScale, f32 x, f32 y, f32 scale); /* |description|Renders a DJUI HUD texture onto the screen|descriptionEnd| */ -void djui_hud_render_texture(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH); +void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH); void djui_hud_render_texture_raw(const u8* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH); /* |description|Renders a DJUI HUD texture tile onto the screen|descriptionEnd| */ -void djui_hud_render_texture_tile(TEXINFO struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH); +void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH); void djui_hud_render_texture_tile_raw(const u8* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH); /* |description|Renders an interpolated DJUI HUD texture onto the screen|descriptionEnd| */ -void djui_hud_render_texture_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH); +void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH); /* |description|Renders an interpolated DJUI HUD texture tile onto the screen|descriptionEnd| */ -void djui_hud_render_texture_tile_interpolated(TEXINFO struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH); +void djui_hud_render_texture_tile_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH); /* |description|Renders a DJUI HUD rect onto the screen|descriptionEnd| */ void djui_hud_render_rect(f32 x, f32 y, f32 width, f32 height); /* |description|Renders an interpolated DJUI HUD rect onto the screen|descriptionEnd| */ diff --git a/src/pc/lua/smlua_functions.c b/src/pc/lua/smlua_functions.c index e153c58e5..5a42e8ae9 100644 --- a/src/pc/lua/smlua_functions.c +++ b/src/pc/lua/smlua_functions.c @@ -450,7 +450,7 @@ int smlua_func_texture_override_set(lua_State* L) { const char* textureName = smlua_to_string(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("texture_override_set: Failed to convert parameter 1"); return 0; } - struct TextureInfo *overrideTexInfo = get_texture_info_from_lua(L); + struct TextureInfo *overrideTexInfo = smlua_to_texture_info(L, 2); if (!overrideTexInfo || !gSmLuaConvertSuccess) { LOG_LUA("texture_override_set: Failed to convert parameter 2"); return 0; } dynos_texture_override_set(textureName, overrideTexInfo); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5a248bf3c..5b9edfe53 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -12719,7 +12719,7 @@ int smlua_func_djui_hud_render_texture(lua_State* L) { return 0; } - struct TextureInfo *texInfo = get_texture_info_from_lua(L); + struct TextureInfo *texInfo = smlua_to_texture_info(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_render_texture"); return 0; } f32 x = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "djui_hud_render_texture"); return 0; } @@ -12744,7 +12744,7 @@ int smlua_func_djui_hud_render_texture_tile(lua_State* L) { return 0; } - struct TextureInfo *texInfo = get_texture_info_from_lua(L); + struct TextureInfo *texInfo = smlua_to_texture_info(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_render_texture_tile"); return 0; } f32 x = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "djui_hud_render_texture_tile"); return 0; } @@ -12777,7 +12777,7 @@ int smlua_func_djui_hud_render_texture_interpolated(lua_State* L) { return 0; } - struct TextureInfo *texInfo = get_texture_info_from_lua(L); + struct TextureInfo *texInfo = smlua_to_texture_info(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_render_texture_interpolated"); return 0; } f32 prevX = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "djui_hud_render_texture_interpolated"); return 0; } @@ -12810,7 +12810,7 @@ int smlua_func_djui_hud_render_texture_tile_interpolated(lua_State* L) { return 0; } - struct TextureInfo *texInfo = get_texture_info_from_lua(L); + struct TextureInfo *texInfo = smlua_to_texture_info(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_render_texture_tile_interpolated"); return 0; } f32 prevX = smlua_to_number(L, 2); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "djui_hud_render_texture_tile_interpolated"); return 0; } diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index c69503af9..51169721b 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -258,6 +258,39 @@ struct LSTNetworkType smlua_to_lnt(lua_State* L, int index) { return lnt; } +struct TextureInfo *smlua_to_texture_info(lua_State *L, int index) { + static struct TextureInfo tmpTexInfo = { 0 }; // Static should be okay + struct TextureInfo *texInfo = &tmpTexInfo; + + if (smlua_is_cobject(L, index, LOT_TEXTUREINFO)) { + return smlua_to_cobject(L, index, LOT_TEXTUREINFO); + } else { + int top = lua_gettop(L); + lua_pushvalue(L, index); + + lua_pushstring(L, "texture"); + lua_gettable(L, top + 1); + tmpTexInfo.texture = smlua_to_cpointer(L, lua_gettop(L), LVT_U8_P); + lua_pop(L, 1); + if (!gSmLuaConvertSuccess) { return NULL; } + + tmpTexInfo.bitSize = smlua_get_integer_field(top + 1, "bitSize"); + if (!gSmLuaConvertSuccess) { return NULL; } + + tmpTexInfo.width = smlua_get_integer_field(top + 1, "width"); + if (!gSmLuaConvertSuccess) { return NULL; } + + tmpTexInfo.height = smlua_get_integer_field(top + 1, "height"); + if (!gSmLuaConvertSuccess) { return NULL; } + + tmpTexInfo.name = smlua_get_string_field(top + 1, "name"); + if (!gSmLuaConvertSuccess) { return NULL; } + + lua_settop(L, top); + } + return texInfo; +} + /////////////////////////////////////////////////////////////////////////////////////////// bool packet_write_lnt(struct Packet* p, struct LSTNetworkType* lnt) { @@ -641,41 +674,6 @@ LuaFunction smlua_get_any_function_mod_variable(const char *variable) { /////////////////////////////////////////////////////////////////////////////////////////// -struct TextureInfo *get_texture_info_from_lua(lua_State *L) { - static struct TextureInfo tmpTexInfo = { 0 }; // Static should be okay - struct TextureInfo *texInfo = &tmpTexInfo; - - if (smlua_is_cobject(L, 1, LOT_TEXTUREINFO)) { - return smlua_to_cobject(L, 1, LOT_TEXTUREINFO); - } else { - int top = lua_gettop(L); - lua_pushvalue(L, 1); - - lua_pushstring(L, "texture"); - lua_gettable(L, top + 1); - tmpTexInfo.texture = smlua_to_cpointer(L, lua_gettop(L), LVT_U8_P); - lua_pop(L, 1); - if (!gSmLuaConvertSuccess) { return NULL; } - - tmpTexInfo.bitSize = smlua_get_integer_field(top + 1, "bitSize"); - if (!gSmLuaConvertSuccess) { return NULL; } - - tmpTexInfo.width = smlua_get_integer_field(top + 1, "width"); - if (!gSmLuaConvertSuccess) { return NULL; } - - tmpTexInfo.height = smlua_get_integer_field(top + 1, "height"); - if (!gSmLuaConvertSuccess) { return NULL; } - - tmpTexInfo.name = smlua_get_string_field(top + 1, "name"); - if (!gSmLuaConvertSuccess) { return NULL; } - - lua_settop(L, top); - } - return texInfo; -} - -/////////////////////////////////////////////////////////////////////////////////////////// - const char* smlua_lnt_to_str(struct LSTNetworkType* lnt) { static char sLntStr[32] = ""; switch (lnt->type) { diff --git a/src/pc/lua/smlua_utils.h b/src/pc/lua/smlua_utils.h index e0cb2c56c..26e2882a5 100644 --- a/src/pc/lua/smlua_utils.h +++ b/src/pc/lua/smlua_utils.h @@ -24,6 +24,7 @@ bool smlua_is_cobject(lua_State* L, int index, u16 lot); void* smlua_to_cobject(lua_State* L, int index, u16 lot); void* smlua_to_cpointer(lua_State* L, int index, u16 lvt); struct LSTNetworkType smlua_to_lnt(lua_State* L, int index); +struct TextureInfo *smlua_to_texture_info(lua_State *L, int index); bool packet_write_lnt(struct Packet* p, struct LSTNetworkType* lnt); bool packet_read_lnt(struct Packet* p, struct LSTNetworkType* lnt); @@ -50,8 +51,6 @@ s64 smlua_get_any_integer_mod_variable(const char* variable); LuaFunction smlua_get_function_mod_variable(u16 modIndex, const char *variable); LuaFunction smlua_get_any_function_mod_variable(const char *variable); -struct TextureInfo *get_texture_info_from_lua(lua_State *L); - void smlua_logline(void); void smlua_dump_stack(void); void smlua_dump_globals(void);