From 669e17bc189f41a41cc906ec6b690b08f7ab4b3c Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 15 Feb 2022 22:14:55 -0800 Subject: [PATCH] Added global textures --- autogen/convert_structs.py | 3 ++- bin/segment2.c | 14 +++++++------- docs/lua/globals.md | 7 +++++++ docs/lua/structs.md | 17 +++++++++++++++++ src/pc/djui/djui_hud_utils.c | 19 +++++++++++++++++++ src/pc/djui/djui_hud_utils.h | 12 ++++++++++++ src/pc/lua/smlua_cobject.c | 6 ++++++ src/pc/lua/smlua_cobject_autogen.c | 13 +++++++++++++ src/pc/lua/smlua_cobject_autogen.h | 1 + 9 files changed, 84 insertions(+), 8 deletions(-) diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index e2ae36c4..8f1fd3c1 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -10,7 +10,8 @@ in_files = [ 'src/game/camera.h', 'src/game/characters.h', 'src/engine/surface_collision.h', - 'src/pc/network/network_player.h' + 'src/pc/network/network_player.h', + 'src/pc/djui/djui_hud_utils.h' ] smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen' diff --git a/bin/segment2.c b/bin/segment2.c index 0bf7bd4d..3877dab4 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -205,7 +205,7 @@ ALIGNED8 static const u8 texture_hud_char_multiply[] = { #include "textures/segment2/segment2.05600.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_coin[] = { +ALIGNED8 const u8 texture_hud_char_coin[] = { #include "textures/segment2/segment2.05800.rgba16.inc.c" }; @@ -229,7 +229,7 @@ ALIGNED8 const u8 texture_hud_char_wario_head[] = { #include "textures/segment2/custom_wario_head.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_star[] = { +ALIGNED8 const u8 texture_hud_char_star[] = { #include "textures/segment2/segment2.05C00.rgba16.inc.c" }; @@ -1801,23 +1801,23 @@ ALIGNED8 static const u8 texture_font_char_us_button_C_right[] = { }; #endif -ALIGNED8 static const u8 texture_hud_char_camera[] = { +ALIGNED8 const u8 texture_hud_char_camera[] = { #include "textures/segment2/segment2.07B50.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_lakitu[] = { +ALIGNED8 const u8 texture_hud_char_lakitu[] = { #include "textures/segment2/segment2.07D50.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_no_camera[] = { +ALIGNED8 const u8 texture_hud_char_no_camera[] = { #include "textures/segment2/segment2.07F50.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_arrow_up[] = { +ALIGNED8 const u8 texture_hud_char_arrow_up[] = { #include "textures/segment2/segment2.08150.rgba16.inc.c" }; -ALIGNED8 static const u8 texture_hud_char_arrow_down[] = { +ALIGNED8 const u8 texture_hud_char_arrow_down[] = { #include "textures/segment2/segment2.081D0.rgba16.inc.c" }; diff --git a/docs/lua/globals.md b/docs/lua/globals.md index 39dff2ae..5d29cc62 100644 --- a/docs/lua/globals.md +++ b/docs/lua/globals.md @@ -30,6 +30,13 @@ The `gCharacter[]` table is an array from `0` to `(CT_MAX - 1)` that contains a
+## [gTextures](#gTextures) +The `gTextures` table contains references to textures. Listed in [GlobalTextures](structs.md#GlobalTextures). + +[:arrow_up_small:](#) + +
+ ## [gGlobalSyncTable](#gGlobalSyncTable) The `gGlobalSyncTable` is a table used for networking. Any field set inside of this table is automatically synchronized with all other clients. Do not use this table for player-specific variables, keep those in [gPlayerSyncTable](#gPlayerSyncTable). Player-specific variable will desynchronize within this table since it doesn't automatically translate `playerIndex`. diff --git a/docs/lua/structs.md b/docs/lua/structs.md index daf5ce1c..004212c4 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -13,6 +13,7 @@ - [CutsceneSplinePoint](#CutsceneSplinePoint) - [CutsceneVariable](#CutsceneVariable) - [FloorGeometry](#FloorGeometry) +- [GlobalTextures](#GlobalTextures) - [GraphNode](#GraphNode) - [GraphNodeObject](#GraphNodeObject) - [GraphNodeObject_sub](#GraphNodeObject_sub) @@ -296,6 +297,22 @@
+## [GlobalTextures](#GlobalTextures) + +| Field | Type | Access | +| ----- | ---- | ------ | +| arrow_down | [TextureInfo](#TextureInfo) | read-only | +| arrow_up | [TextureInfo](#TextureInfo) | read-only | +| camera | [TextureInfo](#TextureInfo) | read-only | +| coin | [TextureInfo](#TextureInfo) | read-only | +| lakitu | [TextureInfo](#TextureInfo) | read-only | +| no_camera | [TextureInfo](#TextureInfo) | read-only | +| star | [TextureInfo](#TextureInfo) | read-only | + +[:arrow_up_small:](#) + +
+ ## [GraphNode](#GraphNode) | Field | Type | Access | diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index 3b1938d3..82127a22 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -15,6 +15,24 @@ static enum HudUtilsResolution sResolution = RESOLUTION_DJUI; static enum DjuiFontType sFont = FONT_NORMAL; +extern ALIGNED8 const u8 texture_hud_char_camera[]; +extern ALIGNED8 const u8 texture_hud_char_lakitu[]; +extern ALIGNED8 const u8 texture_hud_char_no_camera[]; +extern ALIGNED8 const u8 texture_hud_char_arrow_up[]; +extern ALIGNED8 const u8 texture_hud_char_arrow_down[]; +extern ALIGNED8 const u8 texture_hud_char_coin[]; +extern ALIGNED8 const u8 texture_hud_char_star[]; + +struct GlobalTextures gGlobalTextures = { + .camera = { .texture = texture_hud_char_camera, .bitSize = 8, .width = 16, .height = 16 }, + .lakitu = { .texture = texture_hud_char_lakitu, .bitSize = 8, .width = 16, .height = 16 }, + .no_camera = { .texture = texture_hud_char_no_camera, .bitSize = 8, .width = 16, .height = 16 }, + .arrow_up = { .texture = texture_hud_char_arrow_up, .bitSize = 8, .width = 8, .height = 8 }, + .arrow_down = { .texture = texture_hud_char_arrow_down, .bitSize = 8, .width = 8, .height = 8 }, + .coin = { .texture = texture_hud_char_coin, .bitSize = 8, .width = 16, .height = 16 }, + .star = { .texture = texture_hud_char_star, .bitSize = 8, .width = 16, .height = 16 }, +}; + static void djui_hud_position_translate(f32* x, f32* y) { if (sResolution == RESOLUTION_DJUI) { djui_gfx_position_translate(x, y); @@ -141,3 +159,4 @@ static void djui_hud_render_texture_raw(const u8* texture, u32 bitSize, u32 widt 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->width, x, y, scaleW, scaleH); } + diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index ca534865..5a8f3f90 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -14,6 +14,18 @@ enum DjuiFontType { FONT_COUNT, }; +struct GlobalTextures { + struct TextureInfo camera; + struct TextureInfo lakitu; + struct TextureInfo no_camera; + struct TextureInfo arrow_up; + struct TextureInfo arrow_down; + struct TextureInfo coin; + struct TextureInfo star; +}; + +extern struct GlobalTextures gGlobalTextures; + void djui_hud_set_resolution(enum HudUtilsResolution resolutionType); void djui_hud_set_font(enum DjuiFontType fontType); void djui_hud_set_color(u8 r, u8 g, u8 b, u8 a); diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index f9e3198a..bd97f5a4 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -5,6 +5,7 @@ #include "game/mario.h" #include "audio/external.h" #include "object_fields.h" +#include "pc/djui/djui_hud_utils.h" #define LUA_VEC3S_FIELD_COUNT 3 static struct LuaObjectField sVec3sFields[LUA_VEC3S_FIELD_COUNT] = { @@ -222,6 +223,11 @@ void smlua_cobject_init_globals(void) { lua_setglobal(L, "gCharacters"); } + { + smlua_push_object(L, LOT_GLOBALTEXTURES, &gGlobalTextures); + lua_setglobal(L, "gTextures"); + } + } void smlua_bind_cobject(void) { diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index d47e9fec..e6af69eb 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -7,6 +7,7 @@ #include "src/game/characters.h" #include "src/engine/surface_collision.h" #include "src/pc/network/network_player.h" +#include "src/pc/djui/djui_hud_utils.h" #define LUA_ANIMATION_FIELD_COUNT 9 static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = { @@ -207,6 +208,17 @@ static struct LuaObjectField sFloorGeometryFields[LUA_FLOOR_GEOMETRY_FIELD_COUNT // { "unused", LOT_???, offsetof(struct FloorGeometry, unused), false, LOT_??? }, <--- UNIMPLEMENTED }; +#define LUA_GLOBAL_TEXTURES_FIELD_COUNT 7 +static struct LuaObjectField sGlobalTexturesFields[LUA_GLOBAL_TEXTURES_FIELD_COUNT] = { + { "arrow_down", LVT_COBJECT, offsetof(struct GlobalTextures, arrow_down), true, LOT_TEXTUREINFO }, + { "arrow_up", LVT_COBJECT, offsetof(struct GlobalTextures, arrow_up), true, LOT_TEXTUREINFO }, + { "camera", LVT_COBJECT, offsetof(struct GlobalTextures, camera), true, LOT_TEXTUREINFO }, + { "coin", LVT_COBJECT, offsetof(struct GlobalTextures, coin), true, LOT_TEXTUREINFO }, + { "lakitu", LVT_COBJECT, offsetof(struct GlobalTextures, lakitu), true, LOT_TEXTUREINFO }, + { "no_camera", LVT_COBJECT, offsetof(struct GlobalTextures, no_camera), true, LOT_TEXTUREINFO }, + { "star", LVT_COBJECT, offsetof(struct GlobalTextures, star), true, LOT_TEXTUREINFO }, +}; + #define LUA_GRAPH_NODE_FIELD_COUNT 6 static struct LuaObjectField sGraphNodeFields[LUA_GRAPH_NODE_FIELD_COUNT] = { { "children", LVT_COBJECT_P, offsetof(struct GraphNode, children), true, LOT_GRAPHNODE }, @@ -683,6 +695,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN] { LOT_CUTSCENESPLINEPOINT, sCutsceneSplinePointFields, LUA_CUTSCENE_SPLINE_POINT_FIELD_COUNT }, { LOT_CUTSCENEVARIABLE, sCutsceneVariableFields, LUA_CUTSCENE_VARIABLE_FIELD_COUNT }, { LOT_FLOORGEOMETRY, sFloorGeometryFields, LUA_FLOOR_GEOMETRY_FIELD_COUNT }, + { LOT_GLOBALTEXTURES, sGlobalTexturesFields, LUA_GLOBAL_TEXTURES_FIELD_COUNT }, { LOT_GRAPHNODE, sGraphNodeFields, LUA_GRAPH_NODE_FIELD_COUNT }, { LOT_GRAPHNODEOBJECT, sGraphNodeObjectFields, LUA_GRAPH_NODE_OBJECT_FIELD_COUNT }, { LOT_GRAPHNODEOBJECT_SUB, sGraphNodeObject_subFields, LUA_GRAPH_NODE_OBJECT_SUB_FIELD_COUNT }, diff --git a/src/pc/lua/smlua_cobject_autogen.h b/src/pc/lua/smlua_cobject_autogen.h index 19d38f79..d5b1e22e 100644 --- a/src/pc/lua/smlua_cobject_autogen.h +++ b/src/pc/lua/smlua_cobject_autogen.h @@ -17,6 +17,7 @@ enum LuaObjectAutogenType { LOT_CUTSCENESPLINEPOINT, LOT_CUTSCENEVARIABLE, LOT_FLOORGEOMETRY, + LOT_GLOBALTEXTURES, LOT_GRAPHNODE, LOT_GRAPHNODEOBJECT, LOT_GRAPHNODEOBJECT_SUB,