Add ability to disable aspect ratio adjustment

This commit is contained in:
Agent X 2024-02-21 19:26:30 -05:00
parent b6a396b0cd
commit 18a3b333e8
9 changed files with 106 additions and 1 deletions

View file

@ -8828,6 +8828,17 @@ function get_vertex_color(index)
-- ...
end
--- @param enable boolean
--- @return nil
function gfx_enable_adjust_for_aspect_ratio(enable)
-- ...
end
--- @return boolean
function gfx_get_adjust_for_aspect_ratio()
-- ...
end
--- @param type HudDisplayValue
--- @return integer
function hud_get_value(type)

View file

@ -1192,6 +1192,44 @@
<br />
## [gfx_enable_adjust_for_aspect_ratio](#gfx_enable_adjust_for_aspect_ratio)
### Lua Example
`gfx_enable_adjust_for_aspect_ratio(enable)`
### Parameters
| Field | Type |
| ----- | ---- |
| enable | `boolean` |
### Returns
- None
### C Prototype
`void gfx_enable_adjust_for_aspect_ratio(bool enable);`
[:arrow_up_small:](#)
<br />
## [gfx_get_adjust_for_aspect_ratio](#gfx_get_adjust_for_aspect_ratio)
### Lua Example
`local booleanValue = gfx_get_adjust_for_aspect_ratio()`
### Parameters
- None
### Returns
- `boolean`
### C Prototype
`bool gfx_get_adjust_for_aspect_ratio(void);`
[:arrow_up_small:](#)
<br />
## [hud_get_value](#hud_get_value)
### Lua Example

View file

@ -1657,6 +1657,8 @@
- [get_time](functions-5.md#get_time)
- [get_ttc_speed_setting](functions-5.md#get_ttc_speed_setting)
- [get_vertex_color](functions-5.md#get_vertex_color)
- [gfx_enable_adjust_for_aspect_ratio](functions-5.md#gfx_enable_adjust_for_aspect_ratio)
- [gfx_get_adjust_for_aspect_ratio](functions-5.md#gfx_get_adjust_for_aspect_ratio)
- [hud_get_value](functions-5.md#hud_get_value)
- [hud_hide](functions-5.md#hud_hide)
- [hud_is_hidden](functions-5.md#hud_is_hidden)

View file

@ -189,6 +189,8 @@ Color gVertexColor = { 255, 255, 255 };
Color gFogColor = { 255, 255, 255 };
f32 gFogIntensity = 1;
bool gAdjustForAspectRatio = true;
// 4x4 pink-black checkerboard texture to indicate missing textures
#define MISSING_W 4
#define MISSING_H 4
@ -751,6 +753,8 @@ static void gfx_sp_pop_matrix(uint32_t count) {
}
static float gfx_adjust_x_for_aspect_ratio(float x) {
if (!gAdjustForAspectRatio) return x * (4.0 / 3.0f) / (4.0f / 3.0f);
return x * (4.0f / 3.0f) / ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height);
}
@ -1816,7 +1820,7 @@ void gfx_start_frame(void) {
// Avoid division by zero
gfx_current_dimensions.height = 1;
}
gfx_current_dimensions.aspect_ratio = (float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height;
gfx_current_dimensions.aspect_ratio = gAdjustForAspectRatio ? ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height) : (4.0f / 3.0f);
}
void gfx_run(Gfx *commands) {

View file

@ -19,6 +19,8 @@ extern Color gVertexColor;
extern Color gFogColor;
extern f32 gFogIntensity;
extern bool gAdjustForAspectRatio;
#ifdef __cplusplus
extern "C" {
#endif

View file

@ -29133,6 +29133,38 @@ int smlua_func_get_vertex_color(lua_State* L) {
return 1;
}
int smlua_func_gfx_enable_adjust_for_aspect_ratio(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_enable_adjust_for_aspect_ratio", 1, top);
return 0;
}
bool enable = smlua_to_boolean(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "gfx_enable_adjust_for_aspect_ratio"); return 0; }
gfx_enable_adjust_for_aspect_ratio(enable);
return 1;
}
int smlua_func_gfx_get_adjust_for_aspect_ratio(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 0) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "gfx_get_adjust_for_aspect_ratio", 0, top);
return 0;
}
lua_pushboolean(L, gfx_get_adjust_for_aspect_ratio());
return 1;
}
int smlua_func_hud_get_value(lua_State* L) {
if (L == NULL) { return 0; }
@ -32894,6 +32926,8 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "get_time", smlua_func_get_time);
smlua_bind_function(L, "get_ttc_speed_setting", smlua_func_get_ttc_speed_setting);
smlua_bind_function(L, "get_vertex_color", smlua_func_get_vertex_color);
smlua_bind_function(L, "gfx_enable_adjust_for_aspect_ratio", smlua_func_gfx_enable_adjust_for_aspect_ratio);
smlua_bind_function(L, "gfx_get_adjust_for_aspect_ratio", smlua_func_gfx_get_adjust_for_aspect_ratio);
smlua_bind_function(L, "hud_get_value", smlua_func_hud_get_value);
smlua_bind_function(L, "hud_hide", smlua_func_hud_hide);
smlua_bind_function(L, "hud_is_hidden", smlua_func_hud_is_hidden);

View file

@ -628,6 +628,16 @@ bool get_coop_compatibility_enabled(void) {
///
bool gfx_get_adjust_for_aspect_ratio(void) {
return gAdjustForAspectRatio;
}
void gfx_enable_adjust_for_aspect_ratio(bool enable) {
gAdjustForAspectRatio = enable;
}
///
const char* get_os_name(void) {
#if defined(_WIN32) || defined(_WIN64)
return "Windows";

View file

@ -155,6 +155,9 @@ void set_override_envfx(s32 envfx);
bool get_coop_compatibility_enabled(void);
bool gfx_get_adjust_for_aspect_ratio(void);
void gfx_enable_adjust_for_aspect_ratio(bool enable);
const char* get_os_name(void);
#endif

View file

@ -672,6 +672,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gFogIntensity = 1;
gOverrideBackground = -1;
gOverrideEnvFx = -1;
gAdjustForAspectRatio = true;
gRomhackCameraAllowCentering = TRUE;
gOverrideAllowToxicGasCamera = FALSE;
gRomhackCameraAllowDpad = FALSE;