From d9f5869fcd69f94c497386791be8ac7b70b10f20 Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:59:26 +0200 Subject: [PATCH] Fix Texture type; add various get_name functions (#945) --- autogen/common.py | 2 +- autogen/lua_definitions/functions.lua | 28 ++++- autogen/lua_definitions/structs.lua | 3 +- data/dynos.c.h | 2 + data/dynos.cpp.h | 2 + data/dynos_bin_gfx.cpp | 2 +- data/dynos_c.cpp | 8 ++ data/dynos_mgr_gfx.cpp | 111 +++++++++++++++---- data/dynos_mgr_moddata.hpp | 12 +- data/dynos_mgr_tex.cpp | 4 +- docs/lua/functions-6.md | 153 +++++++++++++------------- docs/lua/functions-7.md | 74 +++++++++++++ docs/lua/functions.md | 9 +- docs/lua/structs.md | 2 +- include/types.h | 2 +- src/game/characters.c | 10 +- src/game/hud.c | 2 +- src/game/hud.h | 2 +- src/pc/djui/djui_gfx.c | 4 +- src/pc/djui/djui_gfx.h | 4 +- src/pc/djui/djui_hud_utils.c | 32 +++--- src/pc/djui/djui_hud_utils.h | 4 +- src/pc/djui/djui_image.c | 4 +- src/pc/djui/djui_image.h | 6 +- src/pc/lua/smlua_cobject.c | 42 +++---- src/pc/lua/smlua_cobject.h | 6 +- src/pc/lua/smlua_cobject_autogen.c | 10 +- src/pc/lua/smlua_functions.c | 2 +- src/pc/lua/smlua_functions_autogen.c | 58 +++++++++- src/pc/lua/smlua_utils.c | 2 +- src/pc/lua/utils/smlua_gfx_utils.c | 16 ++- src/pc/lua/utils/smlua_gfx_utils.h | 6 +- src/pc/lua/utils/smlua_misc_utils.c | 32 ++++-- src/pc/lua/utils/smlua_misc_utils.h | 7 +- 34 files changed, 457 insertions(+), 206 deletions(-) diff --git a/autogen/common.py b/autogen/common.py index 2a76f2dd2..cea0d42f1 100644 --- a/autogen/common.py +++ b/autogen/common.py @@ -4,7 +4,7 @@ from vec_types import * usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32', 'f64'] vec_types = list(VEC_TYPES.keys()) -typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory'] +typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory', 'Texture'] type_mappings = { 'char': 's8', diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index bc9bbc883..673c1a31f 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -10776,12 +10776,19 @@ function gfx_get_vertex_count(cmd) end --- @param cmd Pointer_Gfx ---- @return Pointer_integer +--- @return Pointer_Texture --- Gets the texture from a display list command if it has an image related op function gfx_get_texture(cmd) -- ... end +--- @param gfx Pointer_Gfx +--- @return string +--- Gets the name of a display list +function gfx_get_name(gfx) + -- ... +end + --- @param gfx Pointer_Gfx --- @return integer --- Gets the max length of a display list @@ -10838,6 +10845,13 @@ function gfx_delete_all() -- ... end +--- @param vtx Pointer_Vtx +--- @return string +--- Gets the name of a vertex buffer +function vtx_get_name(vtx) + -- ... +end + --- @param vtx Pointer_Vtx --- @return integer --- Gets the max count of vertices of a vertex buffer @@ -11514,12 +11528,19 @@ function geo_get_current_held_object() -- ... end ---- @param tex Pointer_integer ---- 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. +--- @param tex Pointer_Texture +--- 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 function texture_to_lua_table(tex) -- ... end +--- @param tex Pointer_Texture +--- @return string +--- Gets the name of the provided texture pointer `tex` +function get_texture_name(tex) + -- ... +end + --- @param name string --- @return ModelExtendedId --- Gets the extended model ID for the `name` of a `GeoLayout` @@ -12318,6 +12339,7 @@ end --- @alias Pointer_Collision Collision --- @alias Pointer_Gfx Gfx --- @alias Pointer_Vtx Vtx +--- @alias Pointer_Texture Texture --- @alias Vec2fp Vec2f --- @alias Vec3fp Vec3f --- @alias Vec4fp Vec4f diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index eb545250c..8dfc585dc 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -2357,7 +2357,7 @@ --- @field public object Object --- @class TextureInfo ---- @field public texture Pointer_integer +--- @field public texture Pointer_Texture --- @field public name string --- @field public width integer --- @field public height integer @@ -2528,3 +2528,4 @@ --- @alias Pointer_Mat4 Mat4 --- @alias Pointer_Vec4s Vec4s --- @alias Pointer_BehaviorScript BehaviorScript +--- @alias Pointer_Texture Texture diff --git a/data/dynos.c.h b/data/dynos.c.h index 9fd738463..c5171f31e 100644 --- a/data/dynos.c.h +++ b/data/dynos.c.h @@ -90,11 +90,13 @@ void dynos_model_clear_pool(enum ModelPool aModelPool); // -- gfx -- // Gfx *dynos_gfx_get_writable_display_list(Gfx* gfx); Gfx *dynos_gfx_get(const char *name, u32 *outLength); +const char *dynos_gfx_get_name(Gfx *gfx); Gfx *dynos_gfx_create(const char *name, u32 length); bool dynos_gfx_resize(Gfx *gfx, u32 newLength); bool dynos_gfx_delete(Gfx *gfx); void dynos_gfx_delete_all(); Vtx *dynos_vtx_get(const char *name, u32 *outCount); +const char *dynos_vtx_get_name(Vtx *vtx); Vtx *dynos_vtx_create(const char *name, u32 count); bool dynos_vtx_resize(Vtx *vtx, u32 newCount); bool dynos_vtx_delete(Vtx *vtx); diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 763cec64b..d45985daf 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -996,11 +996,13 @@ void DynOS_Model_ClearPool(enum ModelPool aModelPool); Gfx *DynOS_Gfx_GetWritableDisplayList(Gfx *aGfx); Gfx *DynOS_Gfx_Get(const char *aName, u32 *outLength); +const char *DynOS_Gfx_GetName(Gfx *aGfx); Gfx *DynOS_Gfx_Create(const char *aName, u32 aLength); bool DynOS_Gfx_Resize(Gfx *aGfx, u32 aNewLength); bool DynOS_Gfx_Delete(Gfx *aGfx); void DynOS_Gfx_DeleteAll(); Vtx *DynOS_Vtx_Get(const char *aName, u32 *outCount); +const char *DynOS_Vtx_GetName(Vtx *aVtx); Vtx *DynOS_Vtx_Create(const char *aName, u32 aCount); bool DynOS_Vtx_Resize(Vtx *aVtx, u32 aNewCount); bool DynOS_Vtx_Delete(Vtx *aVtx); diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index a5d97daba..1c686cb50 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -1213,7 +1213,7 @@ static String ResolveParam(lua_State *L, GfxData *aGfxData, u32 paramIndex, char case GFX_PARAM_TYPE_TEX: return ConvertParam( L, aGfxData, paramIndex, "Texture pointer", - [] (lua_State *L, u32 paramIndex) { return (Texture *) smlua_to_cpointer(L, paramIndex, LVT_U8_P); }, + [] (lua_State *L, u32 paramIndex) { return (Texture *) smlua_to_cpointer(L, paramIndex, LVT_TEXTURE_P); }, [&aGfxData] (Texture *texture) { return CreateRawPointerDataNode(aGfxData, texture); } ); diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp index 850f4006d..f3f501249 100644 --- a/data/dynos_c.cpp +++ b/data/dynos_c.cpp @@ -292,6 +292,10 @@ Gfx *dynos_gfx_get(const char *name, u32 *outLength) { return DynOS_Gfx_Get(name, outLength); } +const char *dynos_gfx_get_name(Gfx *gfx) { + return DynOS_Gfx_GetName(gfx); +} + Gfx *dynos_gfx_create(const char *name, u32 length) { return DynOS_Gfx_Create(name, length); } @@ -312,6 +316,10 @@ Vtx *dynos_vtx_get(const char *name, u32 *outCount) { return DynOS_Vtx_Get(name, outCount); } +const char *dynos_vtx_get_name(Vtx *vtx) { + return DynOS_Vtx_GetName(vtx); +} + Vtx *dynos_vtx_create(const char *name, u32 count) { return DynOS_Vtx_Create(name, count); } diff --git a/data/dynos_mgr_gfx.cpp b/data/dynos_mgr_gfx.cpp index 068cba698..99228d0d6 100644 --- a/data/dynos_mgr_gfx.cpp +++ b/data/dynos_mgr_gfx.cpp @@ -3,6 +3,7 @@ extern "C" { #include "pc/lua/smlua.h" #include "pc/lua/utils/smlua_gfx_utils.h" +#include "pc/mods/mods.h" } struct MapNode { @@ -13,6 +14,7 @@ struct MapNode { // Maps read-only Gfx and Vtx buffers to their writable duplicates static std::map sRomToRamGfxVtxMap; +static std::map sRamToRomGfxVtxMap; // Reverse map for duplicate to vanilla lookup static Vtx *DynOS_Vtx_Duplicate(Vtx *aVtx, u32 vtxCount, bool shouldDuplicate) { if (!aVtx) { return NULL; } @@ -29,6 +31,7 @@ static Vtx *DynOS_Vtx_Duplicate(Vtx *aVtx, u32 vtxCount, bool shouldDuplicate) { Vtx *vtxDuplicate = vtx_allocate_internal(NULL, vtxCount); memcpy(vtxDuplicate, aVtx, vtxSize); sRomToRamGfxVtxMap[aVtx] = { (void *) vtxDuplicate, vtxSize, NULL }; + sRamToRomGfxVtxMap[vtxDuplicate] = aVtx; return vtxDuplicate; } @@ -81,6 +84,7 @@ static Gfx *DynOS_Gfx_Duplicate(Gfx *aGfx, bool shouldDuplicate) { Gfx *gfxCopy = (Gfx *) malloc(gfxSize); memcpy(gfxCopy, gfxDuplicate, gfxSize); sRomToRamGfxVtxMap[aGfx] = { (void *) gfxDuplicate, gfxSize, gfxCopy }; + sRamToRomGfxVtxMap[gfxDuplicate] = aGfx; } return gfxDuplicate; @@ -136,24 +140,20 @@ Gfx *DynOS_Gfx_Get(const char *aName, u32 *outLength) { // Check levels for (auto &lvl : DynOS_Lvl_GetArray()) { - if (modIndex == -1 || lvl.second->mModIndex == modIndex) { - for (auto &gfx : lvl.second->mDisplayLists) { - if (gfx->mName == aName) { - *outLength = gfx->mSize; - return gfx->mData; - } + for (auto &gfx : lvl.second->mDisplayLists) { + if (gfx->mName == aName) { + *outLength = gfx->mSize; + return gfx->mData; } } } // Check loaded actors for (auto &actor : DynOS_Actor_GetValidActors()) { - if (modIndex == -1 || actor.second.mGfxData->mModIndex == modIndex) { - for (auto &gfx : actor.second.mGfxData->mDisplayLists) { - if (gfx->mName == aName) { - *outLength = gfx->mSize; - return gfx->mData; - } + for (auto &gfx : actor.second.mGfxData->mDisplayLists) { + if (gfx->mName == aName) { + *outLength = gfx->mSize; + return gfx->mData; } } } @@ -176,6 +176,42 @@ Gfx *DynOS_Gfx_Get(const char *aName, u32 *outLength) { return NULL; } +const char *DynOS_Gfx_GetName(Gfx *aGfx) { + if (!aGfx) { return NULL; } + s32 modIndex = (gLuaActiveMod ? gLuaActiveMod->index : -1); + + // Check mod data + static std::string outName; + if (sModsDisplayLists.GetName(modIndex, aGfx, outName)) { + return outName.c_str(); + } + + // Check levels + for (auto &lvl : DynOS_Lvl_GetArray()) { + for (auto &gfx : lvl.second->mDisplayLists) { + if (gfx->mData == aGfx) { + return gfx->mName.begin(); + } + } + } + + // Check loaded actors + for (auto &actor : DynOS_Actor_GetValidActors()) { + for (auto &gfx : actor.second.mGfxData->mDisplayLists) { + if (gfx->mData == aGfx) { + return gfx->mName.begin(); + } + } + } + + // Check vanilla display lists + auto it = sRamToRomGfxVtxMap.find(aGfx); + if (it != sRamToRomGfxVtxMap.end()) { + return DynOS_Builtin_Gfx_GetFromData((const Gfx *) it->second); + } + return DynOS_Builtin_Gfx_GetFromData(aGfx); +} + Gfx *DynOS_Gfx_Create(const char *aName, u32 aLength) { s32 modIndex = (gLuaActiveMod ? gLuaActiveMod->index : -1); return sModsDisplayLists.Create(modIndex, aName, aLength); @@ -240,24 +276,51 @@ Vtx *DynOS_Vtx_Get(const char *aName, u32 *outCount) { // Check levels for (auto &lvl : DynOS_Lvl_GetArray()) { - if (modIndex == -1 || lvl.second->mModIndex == modIndex) { - for (auto &vtx : lvl.second->mVertices) { - if (vtx->mName == aName) { - *outCount = vtx->mSize; - return vtx->mData; - } + for (auto &vtx : lvl.second->mVertices) { + if (vtx->mName == aName) { + *outCount = vtx->mSize; + return vtx->mData; } } } // Check loaded actors for (auto &actor : DynOS_Actor_GetValidActors()) { - if (modIndex == -1 || actor.second.mGfxData->mModIndex == modIndex) { - for (auto &vtx : actor.second.mGfxData->mVertices) { - if (vtx->mName == aName) { - *outCount = vtx->mSize; - return vtx->mData; - } + for (auto &vtx : actor.second.mGfxData->mVertices) { + if (vtx->mName == aName) { + *outCount = vtx->mSize; + return vtx->mData; + } + } + } + + return NULL; +} + +const char *DynOS_Vtx_GetName(Vtx *aVtx) { + if (!aVtx) { return NULL; } + s32 modIndex = (gLuaActiveMod ? gLuaActiveMod->index : -1); + + // Check mod data + static std::string outName; + if (sModsVertexBuffers.GetName(modIndex, aVtx, outName)) { + return outName.c_str(); + } + + // Check levels + for (auto &lvl : DynOS_Lvl_GetArray()) { + for (auto &vtx : lvl.second->mVertices) { + if (vtx->mData == aVtx) { + return vtx->mName.begin(); + } + } + } + + // Check loaded actors + for (auto &actor : DynOS_Actor_GetValidActors()) { + for (auto &vtx : actor.second.mGfxData->mVertices) { + if (vtx->mData == aVtx) { + return vtx->mName.begin(); } } } diff --git a/data/dynos_mgr_moddata.hpp b/data/dynos_mgr_moddata.hpp index 56db167a5..c4d3721cf 100644 --- a/data/dynos_mgr_moddata.hpp +++ b/data/dynos_mgr_moddata.hpp @@ -135,7 +135,6 @@ public: mMapNameToItem.clear(); } -private: ModDataResult *> Find(T *aPointer, std::string &outName) { if (!aPointer) { return { NULL, DYNOS_MOD_DATA_ERROR_POINTER_IS_NULL }; @@ -151,6 +150,7 @@ private: return { NULL, 0 }; } +private: ModDataResult *> FindAvailableItem() { // Create pool if it doesn't exist yet @@ -212,6 +212,16 @@ public: return getResult.first->mBuffer; } + bool GetName(s32 aModIndex, T *aPointer, std::string &outName) { + ModDataT *modData = GetModData(aModIndex); + auto findResult = modData->Find(aPointer, outName); + if (!findResult.first) { + gDynosModDataLastError = findResult.second; + return false; + } + return true; + } + T *Create(s32 aModIndex, const char *aName, u32 aSize) { ModDataT *modData = GetModData(aModIndex); auto createResult = modData->Create(aName, aSize); diff --git a/data/dynos_mgr_tex.cpp b/data/dynos_mgr_tex.cpp index 5531c0710..799af9ac9 100644 --- a/data/dynos_mgr_tex.cpp +++ b/data/dynos_mgr_tex.cpp @@ -503,7 +503,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { aOutTexInfo->bitSize = info->bitSize; aOutTexInfo->width = info->width; aOutTexInfo->height = info->height; - aOutTexInfo->texture = (u8*)info->pointer; + aOutTexInfo->texture = (Texture*)info->pointer; aOutTexInfo->name = aTexName; return true; } @@ -522,7 +522,7 @@ bool DynOS_Tex_GetFromData(const Texture *aTex, struct TextureInfo* aOutTexInfo) aOutTexInfo->bitSize = info->bitSize; aOutTexInfo->width = info->width; aOutTexInfo->height = info->height; - aOutTexInfo->texture = (u8*)info->pointer; + aOutTexInfo->texture = (Texture*)info->pointer; aOutTexInfo->name = info->identifier; return true; } diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md index a9fd4062c..713f1d2eb 100644 --- a/docs/lua/functions-6.md +++ b/docs/lua/functions-6.md @@ -3446,10 +3446,33 @@ Gets the texture from a display list command if it has an image related op | cmd | `Pointer` <`Gfx`> | ### Returns -- `Pointer` <`integer`> +- `Pointer` <`Texture`> ### C Prototype -`u8 *gfx_get_texture(Gfx *cmd);` +`Texture *gfx_get_texture(Gfx *cmd);` + +[:arrow_up_small:](#) + +
+ +## [gfx_get_name](#gfx_get_name) + +### Description +Gets the name of a display list + +### Lua Example +`local stringValue = gfx_get_name(gfx)` + +### Parameters +| Field | Type | +| ----- | ---- | +| gfx | `Pointer` <`Gfx`> | + +### Returns +- `string` + +### C Prototype +`const char *gfx_get_name(Gfx *gfx);` [:arrow_up_small:](#) @@ -3642,6 +3665,29 @@ Deletes all display lists created by `gfx_create`
+## [vtx_get_name](#vtx_get_name) + +### Description +Gets the name of a vertex buffer + +### Lua Example +`local stringValue = vtx_get_name(vtx)` + +### Parameters +| Field | Type | +| ----- | ---- | +| vtx | `Pointer` <`Vtx`> | + +### Returns +- `string` + +### C Prototype +`const char *vtx_get_name(Vtx *vtx);` + +[:arrow_up_small:](#) + +
+ ## [vtx_get_count](#vtx_get_count) ### Description @@ -5951,7 +5997,7 @@ Gets the current GraphNodeHeldObject ## [texture_to_lua_table](#texture_to_lua_table) ### 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. +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 ### Lua Example `texture_to_lua_table(tex)` @@ -5959,13 +6005,36 @@ Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, re ### Parameters | Field | Type | | ----- | ---- | -| tex | `Pointer` <`integer`> | +| tex | `Pointer` <`Texture`> | ### Returns - None ### C Prototype -`void texture_to_lua_table(const u8 *tex);` +`void texture_to_lua_table(const Texture *tex);` + +[:arrow_up_small:](#) + +
+ +## [get_texture_name](#get_texture_name) + +### Description +Gets the name of the provided texture pointer `tex` + +### Lua Example +`local stringValue = get_texture_name(tex)` + +### Parameters +| Field | Type | +| ----- | ---- | +| tex | `Pointer` <`Texture`> | + +### Returns +- `string` + +### C Prototype +`const char *get_texture_name(const Texture *tex);` [:arrow_up_small:](#) @@ -8442,80 +8511,6 @@ Gets the closest point of the triangle to `src` and returns it in `out`. [:arrow_up_small:](#) -
- ---- -# functions from surface_load.h - -
- - -## [load_object_collision_model](#load_object_collision_model) - -### Description -Loads the object's collision data into dynamic collision. You must run this every frame in your object's behavior loop for it to have collision - -### Lua Example -`load_object_collision_model()` - -### Parameters -- None - -### Returns -- None - -### C Prototype -`void load_object_collision_model(void);` - -[:arrow_up_small:](#) - -
- -## [obj_get_surface_from_index](#obj_get_surface_from_index) - -### Description -Gets a surface corresponding to `index` from the surface pool buffer - -### Lua Example -`local SurfaceValue = obj_get_surface_from_index(o, index)` - -### Parameters -| Field | Type | -| ----- | ---- | -| o | [Object](structs.md#Object) | -| index | `integer` | - -### Returns -[Surface](structs.md#Surface) - -### C Prototype -`struct Surface *obj_get_surface_from_index(struct Object *o, u32 index);` - -[:arrow_up_small:](#) - -
- -## [surface_has_force](#surface_has_force) - -### Description -Checks if a surface has force - -### Lua Example -`local booleanValue = surface_has_force(surfaceType)` - -### Parameters -| Field | Type | -| ----- | ---- | -| surfaceType | `integer` | - -### Returns -- `boolean` - -### C Prototype -`bool surface_has_force(s16 surfaceType);` - -[:arrow_up_small:](#) -
--- diff --git a/docs/lua/functions-7.md b/docs/lua/functions-7.md index bc3786df4..c1c05249a 100644 --- a/docs/lua/functions-7.md +++ b/docs/lua/functions-7.md @@ -5,6 +5,80 @@ [< prev](functions-6.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [6](functions-6.md) | 7] +--- +# functions from surface_load.h + +
+ + +## [load_object_collision_model](#load_object_collision_model) + +### Description +Loads the object's collision data into dynamic collision. You must run this every frame in your object's behavior loop for it to have collision + +### Lua Example +`load_object_collision_model()` + +### Parameters +- None + +### Returns +- None + +### C Prototype +`void load_object_collision_model(void);` + +[:arrow_up_small:](#) + +
+ +## [obj_get_surface_from_index](#obj_get_surface_from_index) + +### Description +Gets a surface corresponding to `index` from the surface pool buffer + +### Lua Example +`local SurfaceValue = obj_get_surface_from_index(o, index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| o | [Object](structs.md#Object) | +| index | `integer` | + +### Returns +[Surface](structs.md#Surface) + +### C Prototype +`struct Surface *obj_get_surface_from_index(struct Object *o, u32 index);` + +[:arrow_up_small:](#) + +
+ +## [surface_has_force](#surface_has_force) + +### Description +Checks if a surface has force + +### Lua Example +`local booleanValue = surface_has_force(surfaceType)` + +### Parameters +| Field | Type | +| ----- | ---- | +| surfaceType | `integer` | + +### Returns +- `boolean` + +### C Prototype +`bool surface_has_force(s16 surfaceType);` + +[:arrow_up_small:](#) + +
+ --- # functions from sync_object.h diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 5683b3946..4ec201ce2 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1934,6 +1934,7 @@ - [gfx_get_vertex_buffer](functions-6.md#gfx_get_vertex_buffer) - [gfx_get_vertex_count](functions-6.md#gfx_get_vertex_count) - [gfx_get_texture](functions-6.md#gfx_get_texture) + - [gfx_get_name](functions-6.md#gfx_get_name) - [gfx_get_length](functions-6.md#gfx_get_length) - [gfx_get_command](functions-6.md#gfx_get_command) - [gfx_get_next_command](functions-6.md#gfx_get_next_command) @@ -1942,6 +1943,7 @@ - [gfx_resize](functions-6.md#gfx_resize) - [gfx_delete](functions-6.md#gfx_delete) - [gfx_delete_all](functions-6.md#gfx_delete_all) + - [vtx_get_name](functions-6.md#vtx_get_name) - [vtx_get_count](functions-6.md#vtx_get_count) - [vtx_get_vertex](functions-6.md#vtx_get_vertex) - [vtx_get_next_vertex](functions-6.md#vtx_get_next_vertex) @@ -2053,6 +2055,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_texture_name](functions-6.md#get_texture_name)
@@ -2185,9 +2188,9 @@
- surface_load.h - - [load_object_collision_model](functions-6.md#load_object_collision_model) - - [obj_get_surface_from_index](functions-6.md#obj_get_surface_from_index) - - [surface_has_force](functions-6.md#surface_has_force) + - [load_object_collision_model](functions-7.md#load_object_collision_model) + - [obj_get_surface_from_index](functions-7.md#obj_get_surface_from_index) + - [surface_has_force](functions-7.md#surface_has_force)
diff --git a/docs/lua/structs.md b/docs/lua/structs.md index e603068cb..4050f958e 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -3240,7 +3240,7 @@ | Field | Type | Access | | ----- | ---- | ------ | -| texture | `Pointer` <`integer`> | read-only | +| texture | `Pointer` <`Texture`> | read-only | | name | `string` | read-only | | width | `integer` | read-only | | height | `integer` | read-only | diff --git a/include/types.h b/include/types.h index 70c697636..53f07d508 100644 --- a/include/types.h +++ b/include/types.h @@ -577,7 +577,7 @@ struct MarioState struct TextureInfo { - u8 *texture; + Texture *texture; const char *name; u32 width; u32 height; diff --git a/src/game/characters.c b/src/game/characters.c index 4c0fce483..d751fba7d 100644 --- a/src/game/characters.c +++ b/src/game/characters.c @@ -35,7 +35,7 @@ struct Character gCharacters[CT_MAX] = { .type = CT_MARIO, .name = "Mario", .hudHead = '(', - .hudHeadTexture = { .texture = (u8*)texture_hud_char_mario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_mario_head" }, + .hudHeadTexture = { .texture = (Texture*)texture_hud_char_mario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_mario_head" }, .cameraHudHead = GLYPH_CAM_MARIO_HEAD, .modelId = MODEL_MARIO, .capModelId = MODEL_MARIOS_CAP, @@ -101,7 +101,7 @@ struct Character gCharacters[CT_MAX] = { .type = CT_LUIGI, .name = "Luigi", .hudHead = ')', - .hudHeadTexture = { .texture = (u8*)texture_hud_char_luigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_luigi_head" }, + .hudHeadTexture = { .texture = (Texture*)texture_hud_char_luigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_luigi_head" }, .cameraHudHead = GLYPH_CAM_LUIGI_HEAD, .modelId = MODEL_LUIGI, .capModelId = MODEL_LUIGIS_CAP, @@ -167,7 +167,7 @@ struct Character gCharacters[CT_MAX] = { .type = CT_TOAD, .name = "Toad", .hudHead = '|', - .hudHeadTexture = { .texture = (u8*)texture_hud_char_toad_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_toad_head" }, + .hudHeadTexture = { .texture = (Texture*)texture_hud_char_toad_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_toad_head" }, .cameraHudHead = GLYPH_CAM_TOAD_HEAD, .modelId = MODEL_TOAD_PLAYER, .capModelId = MODEL_TOADS_CAP, @@ -233,7 +233,7 @@ struct Character gCharacters[CT_MAX] = { .type = CT_WALUIGI, .name = "Waluigi", .hudHead = ']', - .hudHeadTexture = { .texture = (u8*)texture_hud_char_waluigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_waluigi_head" }, + .hudHeadTexture = { .texture = (Texture*)texture_hud_char_waluigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_waluigi_head" }, .cameraHudHead = GLYPH_CAM_WALUIGI_HEAD, .modelId = MODEL_WALUIGI, .capModelId = MODEL_WALUIGIS_CAP, @@ -299,7 +299,7 @@ struct Character gCharacters[CT_MAX] = { .type = CT_WARIO, .name = "Wario", .hudHead = '[', - .hudHeadTexture = { .texture = (u8*)texture_hud_char_wario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_wario_head" }, + .hudHeadTexture = { .texture = (Texture*)texture_hud_char_wario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_wario_head" }, .cameraHudHead = GLYPH_CAM_WARIO_HEAD, .modelId = MODEL_WARIO, .capModelId = MODEL_WARIOS_CAP, diff --git a/src/game/hud.c b/src/game/hud.c index 3397dc2bd..245edd56b 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -305,7 +305,7 @@ void render_hud_power_meter(void) { #define HUD_TOP_Y 209 #endif -void render_hud_icon(Vtx *vtx, const u8 *texture, u32 fmt, u32 siz, s32 texW, s32 texH, s32 x, s32 y, s32 w, s32 h, s32 tileX, s32 tileY, s32 tileW, s32 tileH) { +void render_hud_icon(Vtx *vtx, const Texture *texture, u32 fmt, u32 siz, s32 texW, s32 texH, s32 x, s32 y, s32 w, s32 h, s32 tileX, s32 tileY, s32 tileW, s32 tileH) { create_dl_ortho_matrix(); if (!vtx) { vtx = alloc_display_list(sizeof(Vtx) * 4); diff --git a/src/game/hud.h b/src/game/hud.h index 766c81312..e57031349 100644 --- a/src/game/hud.h +++ b/src/game/hud.h @@ -27,7 +27,7 @@ enum CameraHUDLut { extern u8 gOverrideHideHud; -void render_hud_icon(Vtx *vtx, const u8 *texture, u32 fmt, u32 siz, s32 texW, s32 texH, s32 x, s32 y, s32 w, s32 h, s32 tileX, s32 tileY, s32 tileW, s32 tileH); +void render_hud_icon(Vtx *vtx, const Texture *texture, u32 fmt, u32 siz, s32 texW, s32 texH, s32 x, s32 y, s32 w, s32 h, s32 tileX, s32 tileY, s32 tileW, s32 tileH); s16 get_hud_camera_status(void); void set_hud_camera_status(s16 status); diff --git a/src/pc/djui/djui_gfx.c b/src/pc/djui/djui_gfx.c index 5a9d2bbcf..6e347b8e3 100644 --- a/src/pc/djui/djui_gfx.c +++ b/src/pc/djui/djui_gfx.c @@ -123,13 +123,13 @@ static u8 djui_gfx_power_of_two(u32 value) { } } -void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize, bool filter) { +void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u32 bitSize, bool filter) { gDPSetTextureFilter(gDisplayListHead++, filter ? G_TF_BILERP : G_TF_POINT); gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), bitSize); gSPDisplayList(gDisplayListHead++, dl_djui_image); } -void djui_gfx_render_texture_tile(const u8* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font) { +void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font) { if (!gDisplayListHead) { LOG_ERROR("Retrieved a null displaylist head"); return; diff --git a/src/pc/djui/djui_gfx.h b/src/pc/djui/djui_gfx.h index a49227983..93622d0ad 100644 --- a/src/pc/djui/djui_gfx.h +++ b/src/pc/djui/djui_gfx.h @@ -15,8 +15,8 @@ void djui_gfx_displaylist_end(void); f32 djui_gfx_get_scale(void); -void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize, bool filter); -void djui_gfx_render_texture_tile(const u8* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font); +void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u32 bitSize, bool filter); +void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font); void gfx_get_dimensions(u32* width, u32* height); diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index 7fe351d93..ae2485891 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -51,20 +51,20 @@ extern ALIGNED8 const u8 texture_hud_char_apostrophe[]; extern ALIGNED8 const u8 texture_hud_char_double_quote[]; struct GlobalTextures gGlobalTextures = { - .camera = { .texture = (u8*)texture_hud_char_camera, "texture_hud_char_camera", .width = 16, .height = 16, .bitSize = 8 }, - .lakitu = { .texture = (u8*)texture_hud_char_lakitu, "texture_hud_char_lakitu", .width = 16, .height = 16, .bitSize = 8 }, - .no_camera = { .texture = (u8*)texture_hud_char_no_camera, "texture_hud_char_no_camera", .width = 16, .height = 16, .bitSize = 8 }, - .arrow_up = { .texture = (u8*)texture_hud_char_arrow_up, "texture_hud_char_arrow_up", .width = 8, .height = 8, .bitSize = 8 }, - .arrow_down = { .texture = (u8*)texture_hud_char_arrow_down, "texture_hud_char_arrow_down", .width = 8, .height = 8, .bitSize = 8 }, - .coin = { .texture = (u8*)texture_hud_char_coin, "texture_hud_char_coin", .width = 16, .height = 16, .bitSize = 8 }, - .star = { .texture = (u8*)texture_hud_char_star, "texture_hud_char_star", .width = 16, .height = 16, .bitSize = 8 }, - .apostrophe = { .texture = (u8*)texture_hud_char_apostrophe, "texture_hud_char_apostrophe", .width = 16, .height = 16, .bitSize = 8 }, - .double_quote = { .texture = (u8*)texture_hud_char_double_quote, "texture_hud_char_double_quote", .width = 16, .height = 16, .bitSize = 8 }, - .mario_head = { .texture = (u8*)texture_hud_char_mario_head, "texture_hud_char_mario_head", .width = 16, .height = 16, .bitSize = 8 }, - .luigi_head = { .texture = (u8*)texture_hud_char_luigi_head, "texture_hud_char_luigi_head", .width = 16, .height = 16, .bitSize = 8 }, - .toad_head = { .texture = (u8*)texture_hud_char_toad_head, "texture_hud_char_toad_head", .width = 16, .height = 16, .bitSize = 8 }, - .waluigi_head = { .texture = (u8*)texture_hud_char_waluigi_head, "texture_hud_char_waluigi_head", .width = 16, .height = 16, .bitSize = 8 }, - .wario_head = { .texture = (u8*)texture_hud_char_wario_head, "texture_hud_char_wario_head", .width = 16, .height = 16, .bitSize = 8 } + .camera = { .texture = (Texture*)texture_hud_char_camera, "texture_hud_char_camera", .width = 16, .height = 16, .bitSize = 8 }, + .lakitu = { .texture = (Texture*)texture_hud_char_lakitu, "texture_hud_char_lakitu", .width = 16, .height = 16, .bitSize = 8 }, + .no_camera = { .texture = (Texture*)texture_hud_char_no_camera, "texture_hud_char_no_camera", .width = 16, .height = 16, .bitSize = 8 }, + .arrow_up = { .texture = (Texture*)texture_hud_char_arrow_up, "texture_hud_char_arrow_up", .width = 8, .height = 8, .bitSize = 8 }, + .arrow_down = { .texture = (Texture*)texture_hud_char_arrow_down, "texture_hud_char_arrow_down", .width = 8, .height = 8, .bitSize = 8 }, + .coin = { .texture = (Texture*)texture_hud_char_coin, "texture_hud_char_coin", .width = 16, .height = 16, .bitSize = 8 }, + .star = { .texture = (Texture*)texture_hud_char_star, "texture_hud_char_star", .width = 16, .height = 16, .bitSize = 8 }, + .apostrophe = { .texture = (Texture*)texture_hud_char_apostrophe, "texture_hud_char_apostrophe", .width = 16, .height = 16, .bitSize = 8 }, + .double_quote = { .texture = (Texture*)texture_hud_char_double_quote, "texture_hud_char_double_quote", .width = 16, .height = 16, .bitSize = 8 }, + .mario_head = { .texture = (Texture*)texture_hud_char_mario_head, "texture_hud_char_mario_head", .width = 16, .height = 16, .bitSize = 8 }, + .luigi_head = { .texture = (Texture*)texture_hud_char_luigi_head, "texture_hud_char_luigi_head", .width = 16, .height = 16, .bitSize = 8 }, + .toad_head = { .texture = (Texture*)texture_hud_char_toad_head, "texture_hud_char_toad_head", .width = 16, .height = 16, .bitSize = 8 }, + .waluigi_head = { .texture = (Texture*)texture_hud_char_waluigi_head, "texture_hud_char_waluigi_head", .width = 16, .height = 16, .bitSize = 8 }, + .wario_head = { .texture = (Texture*)texture_hud_char_wario_head, "texture_hud_char_wario_head", .width = 16, .height = 16, .bitSize = 8 } }; static void djui_hud_position_translate(f32* x, f32* y) { @@ -495,7 +495,7 @@ static inline bool is_power_of_two(u32 n) { return (n > 0) && ((n & (n - 1)) == 0); } -void djui_hud_render_texture_raw(const u8* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH) { +void djui_hud_render_texture_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH) { if (!is_power_of_two(width) || !is_power_of_two(height)) { LOG_LUA_LINE("Tried to render DJUI HUD texture with NPOT width or height"); return; @@ -534,7 +534,7 @@ void djui_hud_render_texture_raw(const u8* texture, u32 bitSize, u32 width, u32 gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); } -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) { +void djui_hud_render_texture_tile_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) { if (!texture) { return; } gDjuiHudUtilsZ += 0.01f; diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index 2e2748be4..13efed6c8 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -121,10 +121,10 @@ void djui_hud_print_text(const char* message, f32 x, f32 y, f32 scale); 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(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); +void djui_hud_render_texture_raw(const Texture* 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(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); +void djui_hud_render_texture_tile_raw(const Texture* 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(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| */ diff --git a/src/pc/djui/djui_image.c b/src/pc/djui/djui_image.c index f227421c7..fa1101bc7 100644 --- a/src/pc/djui/djui_image.c +++ b/src/pc/djui/djui_image.c @@ -6,7 +6,7 @@ // properties // //////////////// -void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) { +void djui_image_set_image(struct DjuiImage* image, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) { image->texture = texture; image->textureWidth = textureWidth; image->textureHeight = textureHeight; @@ -48,7 +48,7 @@ static void djui_image_destroy(struct DjuiBase* base) { free(image); } -struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) { +struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) { struct DjuiImage* image = calloc(1, sizeof(struct DjuiImage)); struct DjuiBase* base = &image->base; diff --git a/src/pc/djui/djui_image.h b/src/pc/djui/djui_image.h index 84ffb35da..88b2d0b7d 100644 --- a/src/pc/djui/djui_image.h +++ b/src/pc/djui/djui_image.h @@ -3,12 +3,12 @@ struct DjuiImage { struct DjuiBase base; - const u8* texture; + const Texture* texture; u16 textureWidth; u16 textureHeight; u16 textureBitSize; }; -void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize); +void djui_image_set_image(struct DjuiImage* image, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize); -struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize); +struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize); diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index 67b47ecf4..9b8d0b401 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -68,7 +68,7 @@ bool smlua_valid_lvt(u16 lvt) { return (lvt < LVT_MAX); } -const char *sLuaLvtNames[] = { +static const char *sLuaLvtNames[] = { [LVT_BOOL] = "bool", [LVT_BOOL_P] = "bool Pointer", [LVT_U8] = "u8", @@ -91,16 +91,12 @@ const char *sLuaLvtNames[] = { [LVT_COBJECT_P] = "CObject Pointer", [LVT_STRING] = "string", [LVT_STRING_P] = "string Pointer", - [LVT_BEHAVIORSCRIPT] = "BehaviorScript", [LVT_BEHAVIORSCRIPT_P] = "BehaviorScript Pointer", - [LVT_OBJECTANIMPOINTER] = "ObjectAnimPointer", [LVT_OBJECTANIMPOINTER_P] = "ObjectAnimPointer Pointer", - [LVT_COLLISION] = "Collision", [LVT_COLLISION_P] = "Collision Pointer", - [LVT_LEVELSCRIPT] = "LevelScript", [LVT_LEVELSCRIPT_P] = "LevelScript Pointer", - [LVT_TRAJECTORY] = "Trajectory", [LVT_TRAJECTORY_P] = "Trajectory Pointer", + [LVT_TEXTURE_P] = "Texture Pointer", [LVT_LUAFUNCTION] = "LuaFunction", [LVT_POINTER] = "Pointer", [LVT_MAX] = "Max", @@ -373,24 +369,19 @@ struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyInde static bool smlua_push_field(lua_State* L, u8* p, struct LuaObjectField *data) { switch (data->valueType) { - case LVT_BOOL: lua_pushboolean(L, *(u8* )p); break; - case LVT_U8: lua_pushinteger(L, *(u8* )p); break; - case LVT_U16: lua_pushinteger(L, *(u16*)p); break; - case LVT_U32: lua_pushinteger(L, *(u32*)p); break; - case LVT_S8: lua_pushinteger(L, *(s8* )p); break; - case LVT_S16: lua_pushinteger(L, *(s16*)p); break; - case LVT_S32: lua_pushinteger(L, *(s32*)p); break; - case LVT_F32: lua_pushnumber( L, *(f32*)p); break; - case LVT_U64: lua_pushinteger(L, *(u64*)p); break; - case LVT_COBJECT: smlua_push_object(L, data->lot, p, NULL); break; - case LVT_COBJECT_P: smlua_push_object(L, data->lot, *(u8**)p, NULL); break; - case LVT_STRING: lua_pushstring(L, (char*)p); break; - case LVT_STRING_P: lua_pushstring(L, *(char**)p); break; - case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break; - case LVT_OBJECTANIMPOINTER: lua_pushinteger(L, *(s32*)p); break; - case LVT_COLLISION: lua_pushinteger(L, *(s32*)p); break; - case LVT_LEVELSCRIPT: lua_pushinteger(L, *(s32*)p); break; - case LVT_TRAJECTORY: lua_pushinteger(L, *(s16*)p); break; + case LVT_BOOL: lua_pushboolean(L, *(u8* )p); break; + case LVT_U8: lua_pushinteger(L, *(u8* )p); break; + case LVT_U16: lua_pushinteger(L, *(u16*)p); break; + case LVT_U32: lua_pushinteger(L, *(u32*)p); break; + case LVT_S8: lua_pushinteger(L, *(s8* )p); break; + case LVT_S16: lua_pushinteger(L, *(s16*)p); break; + case LVT_S32: lua_pushinteger(L, *(s32*)p); break; + case LVT_F32: lua_pushnumber( L, *(f32*)p); break; + case LVT_U64: lua_pushinteger(L, *(u64*)p); break; + case LVT_COBJECT: smlua_push_object(L, data->lot, p, NULL); break; + case LVT_COBJECT_P: smlua_push_object(L, data->lot, *(u8**)p, NULL); break; + case LVT_STRING: lua_pushstring(L, (char*)p); break; + case LVT_STRING_P: lua_pushstring(L, *(char**)p); break; // pointers case LVT_BOOL_P: @@ -407,6 +398,7 @@ static bool smlua_push_field(lua_State* L, u8* p, struct LuaObjectField *data) { case LVT_COLLISION_P: case LVT_LEVELSCRIPT_P: case LVT_TRAJECTORY_P: + case LVT_TEXTURE_P: smlua_push_pointer(L, data->valueType, *(u8**)p, NULL); break; @@ -453,7 +445,9 @@ static bool smlua_set_field(lua_State* L, u8* p, struct LuaObjectField *data) { case LVT_BEHAVIORSCRIPT_P: case LVT_OBJECTANIMPOINTER_P: case LVT_COLLISION_P: + case LVT_LEVELSCRIPT_P: case LVT_TRAJECTORY_P: + case LVT_TEXTURE_P: if (lua_isnil(L, 3)) { *(u8**)p = NULL; break; diff --git a/src/pc/lua/smlua_cobject.h b/src/pc/lua/smlua_cobject.h index 403f4e828..8976d3670 100644 --- a/src/pc/lua/smlua_cobject.h +++ b/src/pc/lua/smlua_cobject.h @@ -24,16 +24,12 @@ enum LuaValueType { LVT_COBJECT_P, LVT_STRING, LVT_STRING_P, - LVT_BEHAVIORSCRIPT, LVT_BEHAVIORSCRIPT_P, - LVT_OBJECTANIMPOINTER, LVT_OBJECTANIMPOINTER_P, - LVT_COLLISION, LVT_COLLISION_P, - LVT_LEVELSCRIPT, LVT_LEVELSCRIPT_P, - LVT_TRAJECTORY, LVT_TRAJECTORY_P, + LVT_TEXTURE_P, LVT_LUAFUNCTION, LVT_POINTER, LVT_MAX, diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 85db4d3a9..aced624c1 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -2768,11 +2768,11 @@ static struct LuaObjectField sSurfaceFields[LUA_SURFACE_FIELD_COUNT] = { #define LUA_TEXTURE_INFO_FIELD_COUNT 5 static struct LuaObjectField sTextureInfoFields[LUA_TEXTURE_INFO_FIELD_COUNT] = { - { "bitSize", LVT_U8, offsetof(struct TextureInfo, bitSize), true, LOT_NONE, 1, sizeof(u8) }, - { "height", LVT_U32, offsetof(struct TextureInfo, height), true, LOT_NONE, 1, sizeof(u32) }, - { "name", LVT_STRING_P, offsetof(struct TextureInfo, name), true, LOT_NONE, 1, sizeof(const char*) }, - { "texture", LVT_U8_P, offsetof(struct TextureInfo, texture), true, LOT_POINTER, 1, sizeof(u8*) }, - { "width", LVT_U32, offsetof(struct TextureInfo, width), true, LOT_NONE, 1, sizeof(u32) }, + { "bitSize", LVT_U8, offsetof(struct TextureInfo, bitSize), true, LOT_NONE, 1, sizeof(u8) }, + { "height", LVT_U32, offsetof(struct TextureInfo, height), true, LOT_NONE, 1, sizeof(u32) }, + { "name", LVT_STRING_P, offsetof(struct TextureInfo, name), true, LOT_NONE, 1, sizeof(const char*) }, + { "texture", LVT_TEXTURE_P, offsetof(struct TextureInfo, texture), true, LOT_POINTER, 1, sizeof(Texture*) }, + { "width", LVT_U32, offsetof(struct TextureInfo, width), true, LOT_NONE, 1, sizeof(u32) }, }; #define LUA_TRANSITION_INFO_FIELD_COUNT 9 diff --git a/src/pc/lua/smlua_functions.c b/src/pc/lua/smlua_functions.c index 9e931fba5..aae860717 100644 --- a/src/pc/lua/smlua_functions.c +++ b/src/pc/lua/smlua_functions.c @@ -434,7 +434,7 @@ int smlua_func_get_texture_info(lua_State* L) { lua_newtable(L); lua_pushstring(L, "texture"); - smlua_push_pointer(L, LVT_U8_P, texInfo.texture, NULL); + smlua_push_pointer(L, LVT_TEXTURE_P, texInfo.texture, NULL); lua_settable(L, -3); lua_pushstring(L, "bitSize"); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 521a08a18..c28245176 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -32473,7 +32473,24 @@ int smlua_func_gfx_get_texture(lua_State* L) { Gfx * cmd = (Gfx *)smlua_to_cobject(L, 1, LOT_GFX); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "gfx_get_texture"); return 0; } - smlua_push_pointer(L, LVT_U8_P, (void*)gfx_get_texture(cmd), NULL); + smlua_push_pointer(L, LVT_TEXTURE_P, (void*)gfx_get_texture(cmd), NULL); + + return 1; +} + +int smlua_func_gfx_get_name(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "gfx_get_name", 1, top); + return 0; + } + + Gfx * gfx = (Gfx *)smlua_to_cobject(L, 1, LOT_GFX); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "gfx_get_name"); return 0; } + + lua_pushstring(L, gfx_get_name(gfx)); return 1; } @@ -32622,6 +32639,23 @@ int smlua_func_gfx_delete_all(UNUSED lua_State* L) { return 1; } +int smlua_func_vtx_get_name(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "vtx_get_name", 1, top); + return 0; + } + + Vtx * vtx = (Vtx *)smlua_to_cobject(L, 1, LOT_VTX); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "vtx_get_name"); return 0; } + + lua_pushstring(L, vtx_get_name(vtx)); + + return 1; +} + int smlua_func_vtx_get_count(lua_State* L) { if (L == NULL) { return 0; } @@ -34367,7 +34401,7 @@ int smlua_func_texture_to_lua_table(lua_State* L) { return 0; } - u8 * tex = (u8 *)smlua_to_cpointer(L, 1, LVT_U8_P); + Texture * tex = (Texture *)smlua_to_cpointer(L, 1, LVT_TEXTURE_P); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "texture_to_lua_table"); return 0; } texture_to_lua_table(tex); @@ -34375,6 +34409,23 @@ int smlua_func_texture_to_lua_table(lua_State* L) { return 1; } +int smlua_func_get_texture_name(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_texture_name", 1, top); + return 0; + } + + Texture * tex = (Texture *)smlua_to_cpointer(L, 1, LVT_TEXTURE_P); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_texture_name"); return 0; } + + lua_pushstring(L, get_texture_name(tex)); + + return 1; +} + ///////////////////////// // smlua_model_utils.h // ///////////////////////// @@ -38365,6 +38416,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "gfx_get_vertex_buffer", smlua_func_gfx_get_vertex_buffer); smlua_bind_function(L, "gfx_get_vertex_count", smlua_func_gfx_get_vertex_count); smlua_bind_function(L, "gfx_get_texture", smlua_func_gfx_get_texture); + smlua_bind_function(L, "gfx_get_name", smlua_func_gfx_get_name); smlua_bind_function(L, "gfx_get_length", smlua_func_gfx_get_length); smlua_bind_function(L, "gfx_get_command", smlua_func_gfx_get_command); smlua_bind_function(L, "gfx_get_next_command", smlua_func_gfx_get_next_command); @@ -38373,6 +38425,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "gfx_resize", smlua_func_gfx_resize); smlua_bind_function(L, "gfx_delete", smlua_func_gfx_delete); smlua_bind_function(L, "gfx_delete_all", smlua_func_gfx_delete_all); + smlua_bind_function(L, "vtx_get_name", smlua_func_vtx_get_name); smlua_bind_function(L, "vtx_get_count", smlua_func_vtx_get_count); smlua_bind_function(L, "vtx_get_vertex", smlua_func_vtx_get_vertex); smlua_bind_function(L, "vtx_get_next_vertex", smlua_func_vtx_get_next_vertex); @@ -38480,6 +38533,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_texture_name", smlua_func_get_texture_name); // smlua_model_utils.h smlua_bind_function(L, "smlua_model_util_get_id", smlua_func_smlua_model_util_get_id); diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 4018b6f16..138a88e49 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -288,7 +288,7 @@ struct TextureInfo *smlua_to_texture_info(lua_State *L, int index) { lua_pushstring(L, "texture"); lua_gettable(L, top + 1); - const u8 *texPtr = smlua_to_cpointer(L, lua_gettop(L), LVT_U8_P); + const Texture *texPtr = smlua_to_cpointer(L, lua_gettop(L), LVT_TEXTURE_P); lua_pop(L, 1); if (!gSmLuaConvertSuccess) { return NULL; } diff --git a/src/pc/lua/utils/smlua_gfx_utils.c b/src/pc/lua/utils/smlua_gfx_utils.c index b9d663481..821b42696 100644 --- a/src/pc/lua/utils/smlua_gfx_utils.c +++ b/src/pc/lua/utils/smlua_gfx_utils.c @@ -238,13 +238,19 @@ u16 gfx_get_vertex_count(Gfx *cmd) { return C0(cmd, 12, 8); } -u8 *gfx_get_texture(Gfx *cmd) { +Texture *gfx_get_texture(Gfx *cmd) { if (!cmd) { return 0; } u32 op = GFX_OP(cmd); if (op != G_SETCIMG && op != G_SETZIMG && op != G_SETTIMG) { return 0; } if (cmd->words.w1 == 0) { return 0; } - return (u8 *) cmd->words.w1; + return (Texture *) cmd->words.w1; +} + +const char *gfx_get_name(Gfx *gfx) { + if (!gfx) { return NULL; } + + return dynos_gfx_get_name(gfx); } u32 gfx_get_length(Gfx *gfx) { @@ -349,6 +355,12 @@ void gfx_delete_all() { dynos_gfx_delete_all(); } +const char *vtx_get_name(Vtx *vtx) { + if (!vtx) { return NULL; } + + return dynos_vtx_get_name(vtx); +} + u32 vtx_get_count(Vtx *vtx) { if (!vtx) { return 0; } diff --git a/src/pc/lua/utils/smlua_gfx_utils.h b/src/pc/lua/utils/smlua_gfx_utils.h index 331dcc456..4175188b3 100644 --- a/src/pc/lua/utils/smlua_gfx_utils.h +++ b/src/pc/lua/utils/smlua_gfx_utils.h @@ -67,8 +67,10 @@ Vtx *gfx_get_vertex_buffer(Gfx *cmd); /* |description|Gets the number of vertices from a display list command if it has the op `G_VTX`|descriptionEnd| */ u16 gfx_get_vertex_count(Gfx *cmd); /* |description|Gets the texture from a display list command if it has an image related op|descriptionEnd| */ -u8 *gfx_get_texture(Gfx *cmd); +Texture *gfx_get_texture(Gfx *cmd); +/* |description|Gets the name of a display list|descriptionEnd| */ +const char *gfx_get_name(Gfx *gfx); /* |description|Gets the max length of a display list|descriptionEnd| */ u32 gfx_get_length(Gfx *gfx); /* |description|Gets a command of a display list at position `offset`|descriptionEnd| */ @@ -86,6 +88,8 @@ void gfx_delete(Gfx *gfx); /* |description|Deletes all display lists created by `gfx_create`|descriptionEnd| */ void gfx_delete_all(); +/* |description|Gets the name of a vertex buffer|descriptionEnd| */ +const char *vtx_get_name(Vtx *vtx); /* |description|Gets the max count of vertices of a vertex buffer|descriptionEnd| */ u32 vtx_get_count(Vtx *vtx); /* |description|Gets a vertex of a vertex buffer at position `offset`|descriptionEnd| */ diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index c57c06d3f..f953c458a 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -241,16 +241,16 @@ extern const u8 texture_power_meter_two_segments[]; extern const u8 texture_power_meter_one_segments[]; static struct TextureInfo sPowerMeterTexturesInfo[] = { - { (u8*)texture_power_meter_left_side, "texture_power_meter_left_side", 32, 64, 8 }, - { (u8*)texture_power_meter_right_side, "texture_power_meter_right_side", 32, 64, 8 }, - { (u8*)texture_power_meter_one_segments, "texture_power_meter_one_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_two_segments, "texture_power_meter_two_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_three_segments, "texture_power_meter_three_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_four_segments, "texture_power_meter_four_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_five_segments, "texture_power_meter_five_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_six_segments, "texture_power_meter_six_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_seven_segments, "texture_power_meter_seven_segments", 32, 32, 8 }, - { (u8*)texture_power_meter_full, "texture_power_meter_full", 32, 32, 8 }, + { (Texture*)texture_power_meter_left_side, "texture_power_meter_left_side", 32, 64, 8 }, + { (Texture*)texture_power_meter_right_side, "texture_power_meter_right_side", 32, 64, 8 }, + { (Texture*)texture_power_meter_one_segments, "texture_power_meter_one_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_two_segments, "texture_power_meter_two_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_three_segments, "texture_power_meter_three_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_four_segments, "texture_power_meter_four_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_five_segments, "texture_power_meter_five_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_six_segments, "texture_power_meter_six_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_seven_segments, "texture_power_meter_seven_segments", 32, 32, 8 }, + { (Texture*)texture_power_meter_full, "texture_power_meter_full", 32, 32, 8 }, }; void hud_render_power_meter(s32 health, f32 x, f32 y, f32 width, f32 height) { @@ -603,7 +603,7 @@ struct GraphNodeHeldObject* geo_get_current_held_object(void) { return gCurGraphNodeHeldObject; } -void texture_to_lua_table(const u8 *tex) { +void texture_to_lua_table(const Texture *tex) { lua_State *L = gLuaState; if (!L || !tex) { return; } @@ -614,7 +614,7 @@ void texture_to_lua_table(const u8 *tex) { if (bpp != 16 && bpp != 32) { return; } u32 bytesPerPixel = bpp / 8; - const u8 *data = texInfo.texture; + const Texture *data = texInfo.texture; u32 texSize = texInfo.width * texInfo.height * bytesPerPixel; lua_newtable(L); @@ -642,3 +642,11 @@ void texture_to_lua_table(const u8 *tex) { lua_rawseti(L, -2, i / bytesPerPixel + 1); } } + +const char *get_texture_name(const Texture *tex) { + struct TextureInfo texInfo; + if (dynos_texture_get_from_data(tex, &texInfo)) { + return texInfo.name; + } + return NULL; +} diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index b8b5b198b..8332a2d48 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -252,7 +252,10 @@ struct GraphNodeCamera* geo_get_current_camera(void); /* |description|Gets the current GraphNodeHeldObject|descriptionEnd|*/ 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|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 Texture *tex); + +/* |description|Gets the name of the provided texture pointer `tex`|descriptionEnd|*/ +const char *get_texture_name(const Texture *tex); #endif