From fff0c838664751348ee18aa3c99d1edfa78a842e Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:21:06 -0500 Subject: [PATCH] Add option to disable first person centering with L --- autogen/lua_definitions/structs.lua | 1 + docs/lua/structs.md | 1 + src/game/first_person_cam.c | 4 +++- src/game/first_person_cam.h | 1 + src/pc/lua/smlua_cobject_autogen.c | 3 ++- 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 750208668..90036142f 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -591,6 +591,7 @@ --- @field public r integer --- @class FirstPersonCamera +--- @field public centerL boolean --- @field public crouch number --- @field public enabled boolean --- @field public forceRoll boolean diff --git a/docs/lua/structs.md b/docs/lua/structs.md index ab5907ba5..d1c30080e 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -846,6 +846,7 @@ | Field | Type | Access | | ----- | ---- | ------ | +| centerL | `boolean` | | | crouch | `number` | | | enabled | `boolean` | read-only | | forceRoll | `boolean` | | diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c index dd9b3e9e5..1dcff1eb2 100644 --- a/src/game/first_person_cam.c +++ b/src/game/first_person_cam.c @@ -23,6 +23,7 @@ struct FirstPersonCamera gFirstPersonCamera = { .enabled = false, .forceRoll = true, + .centerL = true, .pitch = 0, .yaw = 0, .crouch = 0, @@ -71,7 +72,7 @@ void first_person_camera_update(void) { gFirstPersonCamera.pitch = CLAMP(gFirstPersonCamera.pitch, -0x3F00, 0x3F00); // update yaw - if (m->controller->buttonPressed & L_TRIG) { + if (m->controller->buttonPressed & L_TRIG && gFirstPersonCamera.centerL) { gFirstPersonCamera.yaw = m->faceAngle[1] + 0x8000; } else { gFirstPersonCamera.yaw += sensX * (invX * m->controller->extStickX - 1.5f * mouse_x); @@ -187,6 +188,7 @@ void first_person_update(void) { void first_person_reset(void) { gFirstPersonCamera.forceRoll = false; + gFirstPersonCamera.centerL = true; gFirstPersonCamera.pitch = 0; gFirstPersonCamera.yaw = 0; gFirstPersonCamera.crouch = 0; diff --git a/src/game/first_person_cam.h b/src/game/first_person_cam.h index c8429ec14..64a858d71 100644 --- a/src/game/first_person_cam.h +++ b/src/game/first_person_cam.h @@ -11,6 +11,7 @@ struct FirstPersonCamera { bool enabled; bool forceRoll; + bool centerL; s16 pitch; s16 yaw; f32 crouch; diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index af7a23e70..8d4caffad 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -674,8 +674,9 @@ 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 7 +#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 8 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 }, { "forceRoll", LVT_BOOL, offsetof(struct FirstPersonCamera, forceRoll), false, LOT_NONE },