From 0b43be462f454888f7e337a2c6d2f4f7db906ea7 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Thu, 22 Jun 2023 14:28:17 -0400 Subject: [PATCH] Add the ability to change lighting color (#420) * Add the ability to change lighting color Well it's actually multiplying the lighting color and not changing it completely but I think it's better that way. * Consistency --- autogen/lua_definitions/functions.lua | 13 +++++++++ docs/lua/functions-5.md | 41 +++++++++++++++++++++++++++ docs/lua/functions.md | 2 ++ src/pc/gfx/gfx_pc.c | 10 +++++-- src/pc/gfx/gfx_pc.h | 1 + src/pc/lua/smlua_functions_autogen.c | 38 +++++++++++++++++++++++++ src/pc/lua/utils/smlua_misc_utils.c | 25 ++++++++++++++-- src/pc/lua/utils/smlua_misc_utils.h | 3 ++ src/pc/network/network.c | 3 ++ 9 files changed, 130 insertions(+), 6 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 78943667..b0318f03 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -8548,6 +8548,12 @@ function get_last_star_or_key() -- ... end +--- @param index integer +--- @return integer +function get_lighting_color(index) + -- ... +end + --- @param index integer --- @return number function get_lighting_dir(index) @@ -8713,6 +8719,13 @@ function set_last_star_or_key(value) -- ... end +--- @param index integer +--- @param value integer +--- @return nil +function set_lighting_color(index, value) + -- ... +end + --- @param index integer --- @param value number --- @return nil diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index b7646a5b..a692682e 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -814,6 +814,26 @@
+## [get_lighting_color](#get_lighting_color) + +### Lua Example +`local integerValue = get_lighting_color(index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | + +### Returns +- `integer` + +### C Prototype +`u8 get_lighting_color(u8 index);` + +[:arrow_up_small:](#) + +
+ ## [get_lighting_dir](#get_lighting_dir) ### Lua Example @@ -1331,6 +1351,27 @@
+## [set_lighting_color](#set_lighting_color) + +### Lua Example +`set_lighting_color(index, value)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | +| value | `integer` | + +### Returns +- None + +### C Prototype +`void set_lighting_color(u8 index, u8 value);` + +[:arrow_up_small:](#) + +
+ ## [set_lighting_dir](#set_lighting_dir) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index d99d2a2b..e8c5cba8 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1595,6 +1595,7 @@ - [get_last_completed_course_num](functions-5.md#get_last_completed_course_num) - [get_last_completed_star_num](functions-5.md#get_last_completed_star_num) - [get_last_star_or_key](functions-5.md#get_last_star_or_key) + - [get_lighting_color](functions-5.md#get_lighting_color) - [get_lighting_dir](functions-5.md#get_lighting_dir) - [get_network_area_timer](functions-5.md#get_network_area_timer) - [get_os_name](functions-5.md#get_os_name) @@ -1621,6 +1622,7 @@ - [set_last_completed_course_num](functions-5.md#set_last_completed_course_num) - [set_last_completed_star_num](functions-5.md#set_last_completed_star_num) - [set_last_star_or_key](functions-5.md#set_last_star_or_key) + - [set_lighting_color](functions-5.md#set_lighting_color) - [set_lighting_dir](functions-5.md#set_lighting_dir) - [set_override_envfx](functions-5.md#set_override_envfx) - [set_override_far](functions-5.md#set_override_far) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index b9f665e8..8a6869ab 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -179,6 +179,7 @@ static f32 sDepthZMult = 1; static f32 sDepthZSub = 0; Vec3f gLightingDir; +Color gLightingColor = { 255, 255, 255 }; // 4x4 pink-black checkerboard texture to indicate missing textures #define MISSING_W 4 @@ -904,9 +905,12 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons } } - d->color.r = r > 255 ? 255 : r; - d->color.g = g > 255 ? 255 : g; - d->color.b = b > 255 ? 255 : b; + f32 rf = gLightingColor[0] / 255.0f; + f32 gf = gLightingColor[1] / 255.0f; + f32 bf = gLightingColor[2] / 255.0f; + d->color.r = r * rf > 255 ? 255 : r * rf; + d->color.g = g * gf > 255 ? 255 : g * gf; + d->color.b = b * bf > 255 ? 255 : b * bf; if (rsp.geometry_mode & G_TEXTURE_GEN) { float dotx = 0, doty = 0; diff --git a/src/pc/gfx/gfx_pc.h b/src/pc/gfx/gfx_pc.h index b5e7f383..3f7c7835 100644 --- a/src/pc/gfx/gfx_pc.h +++ b/src/pc/gfx/gfx_pc.h @@ -14,6 +14,7 @@ struct GfxDimensions { extern struct GfxDimensions gfx_current_dimensions; extern Vec3f gLightingDir; +extern Color gLightingColor; #ifdef __cplusplus extern "C" { diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index acb4fcf1..72781d08 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -28324,6 +28324,23 @@ int smlua_func_get_last_star_or_key(UNUSED lua_State* L) { return 1; } +int smlua_func_get_lighting_color(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_lighting_color", 1, top); + return 0; + } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_lighting_color"); return 0; } + + lua_pushinteger(L, get_lighting_color(index)); + + return 1; +} + int smlua_func_get_lighting_dir(lua_State* L) { if (L == NULL) { return 0; } @@ -28784,6 +28801,25 @@ int smlua_func_set_last_star_or_key(lua_State* L) { return 1; } +int smlua_func_set_lighting_color(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_lighting_color", 2, top); + return 0; + } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_lighting_color"); return 0; } + u8 value = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "set_lighting_color"); return 0; } + + set_lighting_color(index, value); + + return 1; +} + int smlua_func_set_lighting_dir(lua_State* L) { if (L == NULL) { return 0; } @@ -31950,6 +31986,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_last_completed_course_num", smlua_func_get_last_completed_course_num); smlua_bind_function(L, "get_last_completed_star_num", smlua_func_get_last_completed_star_num); smlua_bind_function(L, "get_last_star_or_key", smlua_func_get_last_star_or_key); + smlua_bind_function(L, "get_lighting_color", smlua_func_get_lighting_color); smlua_bind_function(L, "get_lighting_dir", smlua_func_get_lighting_dir); smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer); smlua_bind_function(L, "get_os_name", smlua_func_get_os_name); @@ -31976,6 +32013,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "set_last_completed_course_num", smlua_func_set_last_completed_course_num); smlua_bind_function(L, "set_last_completed_star_num", smlua_func_set_last_completed_star_num); smlua_bind_function(L, "set_last_star_or_key", smlua_func_set_last_star_or_key); + smlua_bind_function(L, "set_lighting_color", smlua_func_set_lighting_color); smlua_bind_function(L, "set_lighting_dir", smlua_func_set_lighting_dir); smlua_bind_function(L, "set_override_envfx", smlua_func_set_override_envfx); smlua_bind_function(L, "set_override_far", smlua_func_set_override_far); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index 26f7ebfe..72f9888d 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -49,18 +49,22 @@ void djui_popup_create_global(const char* message, int lines) { network_send_global_popup(message, lines); } +/// + void hud_hide(void) { - gOverrideHideHud = 1; + gOverrideHideHud = TRUE; } void hud_show(void) { - gOverrideHideHud = 0; + gOverrideHideHud = FALSE; } bool hud_is_hidden(void) { return gOverrideHideHud; } +/// + extern u8 gLastCollectedStarOrKey; s32 get_last_star_or_key(void) { return gLastCollectedStarOrKey; @@ -106,11 +110,15 @@ void set_save_file_modified(bool value) { gSaveFileModified = value ? TRUE : FALSE; } +/// + extern s8 gDialogBoxState; s8 get_dialog_box_state() { return gDialogBoxState; } +/// + s32 hud_get_value(enum HudDisplayValue type) { switch (type) { case HUD_DISPLAY_LIVES: return gHudDisplay.lives; @@ -525,10 +533,19 @@ f32 get_lighting_dir(u8 index) { void set_lighting_dir(u8 index, f32 value) { if (index > 2) { return; } - gLightingDir[index] = value; } +u8 get_lighting_color(u8 index) { + if (index > 2) { return 0; } + return gLightingColor[index]; +} + +void set_lighting_color(u8 index, u8 value) { + if (index > 2) { return; } + gLightingColor[index] = value; +} + /// s8 get_skybox() { @@ -571,6 +588,8 @@ void set_override_envfx(s32 envfx) { gOverrideEnvFx = envfx; } +/// + char* get_os_name(void) { #if defined(_WIN32) || defined(_WIN64) return "Windows"; diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index 12752771..3c937338 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -109,6 +109,9 @@ void add_scroll_target(u32 index, const char* name, u32 offset, u32 size); f32 get_lighting_dir(u8 index); void set_lighting_dir(u8 index, f32 value); +u8 get_lighting_color(u8 index); +void set_lighting_color(u8 index, u8 value); + s8 get_skybox(); void set_override_skybox(s8 background); diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 387c28d8..f2fc4bdd 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -634,6 +634,9 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gLightingDir[0] = 0; gLightingDir[1] = 0; gLightingDir[2] = 0; + gLightingColor[0] = 255; + gLightingColor[1] = 255; + gLightingColor[2] = 255; gOverrideBackground = -1; gOverrideEnvFx = -1; gDjuiRenderBehindHud = false;