From 2a0af8e216f3227d7b77e3a2104ed121213518b8 Mon Sep 17 00:00:00 2001
From: Agent X <44549182+Agent-11@users.noreply.github.com>
Date: Sun, 17 Dec 2023 23:29:31 -0500
Subject: [PATCH] Rework First Person FOV
---
autogen/convert_functions.py | 2 +-
autogen/convert_structs.py | 3 +--
autogen/lua_definitions/functions.lua | 6 ------
autogen/lua_definitions/structs.lua | 1 -
docs/lua/functions-3.md | 20 --------------------
docs/lua/functions.md | 1 -
docs/lua/structs.md | 3 +--
src/game/first_person_cam.c | 14 +++++++-------
src/game/first_person_cam.h | 5 +++--
src/game/rendering_graph_node.c | 6 +++---
src/pc/djui/djui_hud_utils.c | 3 ++-
src/pc/lua/smlua_cobject_autogen.c | 5 ++---
src/pc/lua/smlua_functions_autogen.c | 18 ------------------
src/pc/network/network.c | 1 -
14 files changed, 20 insertions(+), 68 deletions(-)
diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py
index d9ab7a85..b5c504b8 100644
--- a/autogen/convert_functions.py
+++ b/autogen/convert_functions.py
@@ -115,7 +115,7 @@ override_disallowed_functions = {
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_reset_all" ],
"src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ],
"src/pc/network/lag_compensation.h": [ "lag_compensation_clear", "lag_compensation_store" ],
- "src/game/first_person_cam.h": [ "first_person_update" ]
+ "src/game/first_person_cam.h": [ "first_person_update", "get_dest_fov", "get_dest_near" ]
}
override_hide_functions = {
diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py
index 21ff5d18..1f05630c 100644
--- a/autogen/convert_structs.py
+++ b/autogen/convert_structs.py
@@ -113,8 +113,7 @@ override_field_immutable = {
"ObjectWarpNode": [ "next "],
"Animation": [ "length" ],
"AnimationTable": [ "count" ],
- "Controller": [ "controllerData", "statusData" ],
- "FirstPersonCamera": [ "enabled" ],
+ "Controller": [ "controllerData", "statusData" ]
}
override_field_version_excludes = {
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 45e48c1a..1410fe5d 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -4016,12 +4016,6 @@ function get_first_person_enabled()
-- ...
end
---- @param enable boolean
---- @return nil
-function set_first_person_enabled(enable)
- -- ...
-end
-
--- @return nil
function reset_dialog_override_color()
-- ...
diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua
index 90036142..1f661a8d 100644
--- a/autogen/lua_definitions/structs.lua
+++ b/autogen/lua_definitions/structs.lua
@@ -595,7 +595,6 @@
--- @field public crouch number
--- @field public enabled boolean
--- @field public forceRoll boolean
---- @field public fov number
--- @field public offset Vec3f
--- @field public pitch integer
--- @field public yaw integer
diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md
index 7b26dbb5..83be5612 100644
--- a/docs/lua/functions-3.md
+++ b/docs/lua/functions-3.md
@@ -3322,26 +3322,6 @@
-## [set_first_person_enabled](#set_first_person_enabled)
-
-### Lua Example
-`set_first_person_enabled(enable)`
-
-### Parameters
-| Field | Type |
-| ----- | ---- |
-| enable | `boolean` |
-
-### Returns
-- None
-
-### C Prototype
-`void set_first_person_enabled(bool enable);`
-
-[:arrow_up_small:](#)
-
-
-
---
# functions from ingame_menu.h
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index c12f90d7..ba1431e8 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -803,7 +803,6 @@
- [first_person_check_cancels](functions-3.md#first_person_check_cancels)
- [first_person_reset](functions-3.md#first_person_reset)
- [get_first_person_enabled](functions-3.md#get_first_person_enabled)
- - [set_first_person_enabled](functions-3.md#set_first_person_enabled)
diff --git a/docs/lua/structs.md b/docs/lua/structs.md
index d1c30080..b51dfafa 100644
--- a/docs/lua/structs.md
+++ b/docs/lua/structs.md
@@ -848,9 +848,8 @@
| ----- | ---- | ------ |
| centerL | `boolean` | |
| crouch | `number` | |
-| enabled | `boolean` | read-only |
+| enabled | `boolean` | |
| forceRoll | `boolean` | |
-| fov | `number` | |
| offset | [Vec3f](structs.md#Vec3f) | read-only |
| pitch | `integer` | |
| yaw | `integer` | |
diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c
index 1dcff1eb..adcfbe0c 100644
--- a/src/game/first_person_cam.c
+++ b/src/game/first_person_cam.c
@@ -9,6 +9,7 @@
#include "mario.h"
#include "hardcoded.h"
#include "save_file.h"
+#include "rendering_graph_node.h"
#include "engine/math_util.h"
@@ -27,7 +28,6 @@ struct FirstPersonCamera gFirstPersonCamera = {
.pitch = 0,
.yaw = 0,
.crouch = 0,
- .fov = FIRST_PERSON_DEFAULT_FOV,
.offset = { 0, 0, 0 }
};
@@ -54,9 +54,12 @@ bool get_first_person_enabled(void) {
return gFirstPersonCamera.enabled && !first_person_check_cancels(&gMarioStates[0]);
}
-void set_first_person_enabled(bool enable) {
- if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; }
- gFirstPersonCamera.enabled = enable;
+f32 get_dest_fov(f32 fov) {
+ return get_first_person_enabled() ? FIRST_PERSON_DEFAULT_FOV : not_zero(fov, gOverrideFOV);
+}
+
+f32 get_dest_near(f32 near) {
+ return get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear);
}
void first_person_camera_update(void) {
@@ -143,8 +146,6 @@ void first_person_camera_update(void) {
gLakituState.focHSpeed = 0;
gLakituState.focVSpeed = 0;
vec3s_set(gLakituState.shakeMagnitude, 0, 0, 0);
-
- gFOVState.fov = gFirstPersonCamera.fov;
}
void first_person_update(void) {
@@ -192,7 +193,6 @@ void first_person_reset(void) {
gFirstPersonCamera.pitch = 0;
gFirstPersonCamera.yaw = 0;
gFirstPersonCamera.crouch = 0;
- gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV;
gFirstPersonCamera.offset[0] = 0;
gFirstPersonCamera.offset[1] = 0;
gFirstPersonCamera.offset[2] = 0;
diff --git a/src/game/first_person_cam.h b/src/game/first_person_cam.h
index 64a858d7..c5df69b9 100644
--- a/src/game/first_person_cam.h
+++ b/src/game/first_person_cam.h
@@ -15,7 +15,6 @@ struct FirstPersonCamera {
s16 pitch;
s16 yaw;
f32 crouch;
- f32 fov;
Vec3f offset;
};
@@ -24,7 +23,9 @@ extern struct FirstPersonCamera gFirstPersonCamera;
bool first_person_check_cancels(struct MarioState *m);
bool get_first_person_enabled(void);
-void set_first_person_enabled(bool enable);
+
+f32 get_dest_fov(f32 fov);
+f32 get_dest_near(f32 near);
void first_person_update(void);
void first_person_reset(void);
diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c
index b12df4d4..6e529f9b 100644
--- a/src/game/rendering_graph_node.c
+++ b/src/game/rendering_graph_node.c
@@ -237,7 +237,7 @@ void patch_mtx_interpolated(f32 delta) {
u16 perspNorm;
f32 fovInterpolated = delta_interpolate_f32(sPerspectiveNode->prevFov, sPerspectiveNode->fov, delta);
f32 near = MIN(sPerspectiveNode->near, gProjectionMaxNearValue);
- guPerspective(sPerspectiveMtx, &perspNorm, not_zero(fovInterpolated, gOverrideFOV), sPerspectiveAspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f);
+ guPerspective(sPerspectiveMtx, &perspNorm, get_dest_fov(fovInterpolated), sPerspectiveAspect, get_dest_near(near), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f);
gSPMatrix(sPerspectivePos, VIRTUAL_TO_PHYSICAL(sPerspectiveNode), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
}
@@ -488,7 +488,7 @@ static void geo_process_perspective(struct GraphNodePerspective *node) {
gProjectionVanillaNearValue = node->near;
gProjectionVanillaFarValue = node->far;
f32 near = MIN(node->near, gProjectionMaxNearValue);
- guPerspective(mtx, &perspNorm, not_zero(node->prevFov, gOverrideFOV), aspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(node->far, gOverrideFar), 1.0f);
+ guPerspective(mtx, &perspNorm, get_dest_fov(node->prevFov), aspect, get_dest_near(near), not_zero(node->far, gOverrideFar), 1.0f);
sPerspectiveNode = node;
sPerspectiveMtx = mtx;
@@ -1156,7 +1156,7 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
// visibly pop in or out at the edge of the screen.
//
// Half of the fov in in-game angle units instead of degrees.
- s16 halfFov = (not_zero(gCurGraphNodeCamFrustum->fov, gOverrideFOV) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
+ s16 halfFov = (get_dest_fov(gCurGraphNodeCamFrustum->fov) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
f32 divisor = coss(halfFov);
if (divisor == 0) { divisor = 1; }
diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c
index d88e2659..4fa7d553 100644
--- a/src/pc/djui/djui_hud_utils.c
+++ b/src/pc/djui/djui_hud_utils.c
@@ -20,6 +20,7 @@
#include "game/camera.h"
#include "game/hud.h"
#include "game/rendering_graph_node.h"
+#include "game/first_person_cam.h"
#include "engine/math_util.h"
@@ -578,7 +579,7 @@ bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out) {
out[1] *= 256.0f / out[2];
// fov of 45.0 is the default fov
- f32 fovDefault = tanf(not_zero(45.0f, gOverrideFOV) * ((f32)M_PI / 360.0f));
+ f32 fovDefault = tanf(get_dest_fov(45.0f) * ((f32)M_PI / 360.0f));
f32 fovCurrent = tanf((gFOVState.fov + gFOVState.fovOffset) * ((f32)M_PI / 360.0f));
f32 fovDifference = (fovDefault / fovCurrent) * 1.13f;
diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c
index 8d4caffa..3cb29241 100644
--- a/src/pc/lua/smlua_cobject_autogen.c
+++ b/src/pc/lua/smlua_cobject_autogen.c
@@ -674,13 +674,12 @@ static struct LuaObjectField sDjuiColorFields[LUA_DJUI_COLOR_FIELD_COUNT] = {
{ "r", LVT_U8, offsetof(struct DjuiColor, r), false, LOT_NONE },
};
-#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 8
+#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 7
static struct LuaObjectField sFirstPersonCameraFields[LUA_FIRST_PERSON_CAMERA_FIELD_COUNT] = {
{ "centerL", LVT_BOOL, offsetof(struct FirstPersonCamera, centerL), false, LOT_NONE },
{ "crouch", LVT_F32, offsetof(struct FirstPersonCamera, crouch), false, LOT_NONE },
- { "enabled", LVT_BOOL, offsetof(struct FirstPersonCamera, enabled), true, LOT_NONE },
+ { "enabled", LVT_BOOL, offsetof(struct FirstPersonCamera, enabled), false, LOT_NONE },
{ "forceRoll", LVT_BOOL, offsetof(struct FirstPersonCamera, forceRoll), false, LOT_NONE },
- { "fov", LVT_F32, offsetof(struct FirstPersonCamera, fov), false, LOT_NONE },
{ "offset", LVT_COBJECT, offsetof(struct FirstPersonCamera, offset), true, LOT_VEC3F },
{ "pitch", LVT_S16, offsetof(struct FirstPersonCamera, pitch), false, LOT_NONE },
{ "yaw", LVT_S16, offsetof(struct FirstPersonCamera, yaw), false, LOT_NONE },
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 12d1adb0..d6e2db16 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -13231,23 +13231,6 @@ int smlua_func_get_first_person_enabled(UNUSED lua_State* L) {
return 1;
}
-int smlua_func_set_first_person_enabled(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", "set_first_person_enabled", 1, top);
- return 0;
- }
-
- bool enable = smlua_to_boolean(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_first_person_enabled"); return 0; }
-
- set_first_person_enabled(enable);
-
- return 1;
-}
-
///////////////////
// ingame_menu.h //
///////////////////
@@ -32076,7 +32059,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "first_person_check_cancels", smlua_func_first_person_check_cancels);
smlua_bind_function(L, "first_person_reset", smlua_func_first_person_reset);
smlua_bind_function(L, "get_first_person_enabled", smlua_func_get_first_person_enabled);
- smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled);
// ingame_menu.h
smlua_bind_function(L, "reset_dialog_override_color", smlua_func_reset_dialog_override_color);
diff --git a/src/pc/network/network.c b/src/pc/network/network.c
index 586cf8a9..c85c917d 100644
--- a/src/pc/network/network.c
+++ b/src/pc/network/network.c
@@ -708,7 +708,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
cnt->extStickY = 0;
gFirstPersonCamera.enabled = false;
- gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV;
first_person_reset();
extern void save_file_load_all(UNUSED u8 reload);