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
This commit is contained in:
Agent X 2023-06-22 14:28:17 -04:00 committed by GitHub
parent c701d26be8
commit 0b43be462f
9 changed files with 130 additions and 6 deletions

View File

@ -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

View File

@ -814,6 +814,26 @@
<br />
## [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:](#)
<br />
## [get_lighting_dir](#get_lighting_dir)
### Lua Example
@ -1331,6 +1351,27 @@
<br />
## [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:](#)
<br />
## [set_lighting_dir](#set_lighting_dir)
### Lua Example

View File

@ -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)

View File

@ -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;

View File

@ -14,6 +14,7 @@ struct GfxDimensions {
extern struct GfxDimensions gfx_current_dimensions;
extern Vec3f gLightingDir;
extern Color gLightingColor;
#ifdef __cplusplus
extern "C" {

View File

@ -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);

View File

@ -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";

View File

@ -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);

View File

@ -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;