From 9f839268e749a27e42ac47c54f34e724a0a7c562 Mon Sep 17 00:00:00 2001 From: Youssef Maged Date: Wed, 9 Sep 2026 04:50:21 +0300 Subject: [PATCH 1/5] Refactor Camera Functions to use new parser --- .../logic/luadefs/CLuaCameraDefs.cpp | 337 +++++------------- .../deathmatch/logic/luadefs/CLuaCameraDefs.h | 24 +- .../logic/luadefs/CLuaCameraDefs.cpp | 227 +++--------- .../deathmatch/logic/luadefs/CLuaCameraDefs.h | 18 +- 4 files changed, 159 insertions(+), 447 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index 8a64fe4f997..2b1cb5c2529 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -28,19 +28,19 @@ void CLuaCameraDefs::LoadFunctions() {"getCameraTarget", ArgumentParserWarn}, {"getCameraInterior", ArgumentParserWarn}, {"getCameraGoggleEffect", ArgumentParserWarn}, - {"getCameraFieldOfView", GetCameraFieldOfView}, + {"getCameraFieldOfView", ArgumentParserWarn}, {"getCameraDrunkLevel", ArgumentParserWarn}, // Cam set funcs - {"setCameraMatrix", SetCameraMatrix}, - {"setCameraFieldOfView", SetCameraFieldOfView}, - {"setCameraTarget", SetCameraTarget}, - {"setCameraInterior", SetCameraInterior}, - {"fadeCamera", FadeCamera}, - {"setCameraClip", SetCameraClip}, - {"getCameraClip", GetCameraClip}, + {"setCameraMatrix", ArgumentParserWarn}, + {"setCameraFieldOfView", ArgumentParserWarn}, + {"setCameraTarget", ArgumentParserWarn}, + {"setCameraInterior", ArgumentParserWarn}, + {"fadeCamera", ArgumentParserWarn}, + {"setCameraClip", ArgumentParserWarn}, + {"getCameraClip", ArgumentParserWarn}, {"setCameraViewMode", ArgumentParserWarn}, - {"setCameraGoggleEffect", SetCameraGoggleEffect}, + {"setCameraGoggleEffect", ArgumentParserWarn}, {"setCameraDrunkLevel", ArgumentParserWarn}, {"shakeCamera", ArgumentParser}, @@ -166,253 +166,106 @@ unsigned char CLuaCameraDefs::GetCameraDrunkLevel() return g_pGame->GetPlayerInfo()->GetCamDrunkLevel(); } -int CLuaCameraDefs::SetCameraMatrix(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraMatrix(std::variant matrixOrPosition, std::optional vecLookAt, std::optional fRoll, + std::optional fFOV) { - CVector vecPosition; - CVector vecLookAt; - float fRoll = 0.0f; - float fFOV = 70.0f; - CScriptArgReader argStream(luaVM); - bool bLookAtValid; + CVector vecPosition; + CVector lookAt; + bool bLookAtValid = false; - if (argStream.NextIsUserDataOfType()) + if (auto* pMatrix = std::get_if(&matrixOrPosition)) { - CLuaMatrix* pMatrix; - argStream.ReadUserData(pMatrix); - - vecPosition = pMatrix->GetPosition(); - vecLookAt = pMatrix->GetRotation(); + vecPosition = (*pMatrix)->GetPosition(); + lookAt = (*pMatrix)->GetRotation(); bLookAtValid = true; } else { - argStream.ReadVector3D(vecPosition); - bLookAtValid = argStream.NextIsVector3D(); - argStream.ReadVector3D(vecLookAt, CVector()); - } - - argStream.ReadNumber(fRoll, 0.0f); - argStream.ReadNumber(fFOV, 70.0f); - if (fFOV <= 0.0f || fFOV >= 180.0f) - fFOV = 70.0f; - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraMatrix(vecPosition, bLookAtValid ? &vecLookAt : nullptr, fRoll, fFOV)) + vecPosition = std::get(matrixOrPosition); + if (vecLookAt.has_value()) { - lua_pushboolean(luaVM, true); - return 1; + lookAt = vecLookAt.value(); + bLookAtValid = true; } } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + float fFOVValue = fFOV.value_or(70.0f); + if (fFOVValue <= 0.0f || fFOVValue >= 180.0f) + fFOVValue = 70.0f; + + return CStaticFunctionDefinitions::SetCameraMatrix(vecPosition, bLookAtValid ? &lookAt : nullptr, fRoll.value_or(0.0f), fFOVValue); } // Only when onfoot/invehicle -int CLuaCameraDefs::SetCameraFieldOfView(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraFieldOfView(eFieldOfViewMode eMode, float fFOV, std::optional instant) { - float fFOV; - eFieldOfViewMode eMode; - bool instant; - CScriptArgReader argStream(luaVM); - argStream.ReadEnumString(eMode); - argStream.ReadNumber(fFOV); - argStream.ReadBool(instant, false); - - if (!argStream.HasErrors()) - { - while (true) - { - if (fFOV < 0 || fFOV > 179) - { - argStream.SetCustomError("Invalid FOV range (0-179)"); - break; - } - - if (eMode == FOV_MODE_PLAYER) - { - g_pGame->GetSettings()->SetFieldOfViewPlayer(fFOV, true, instant); - } - else if (eMode == FOV_MODE_VEHICLE) - { - g_pGame->GetSettings()->SetFieldOfViewVehicle(fFOV, true, instant); - } - else if (eMode == FOV_MODE_VEHICLE_MAX) - { - g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fFOV, true, instant); - } - else - { - argStream.m_iIndex = 1; - argStream.SetCustomError(SString("Enum not yet implemented: " + EnumToString(eMode))); - break; - } - - lua_pushboolean(luaVM, true); - return 1; - } - } + if (fFOV < 0 || fFOV > 179) + throw std::invalid_argument("Invalid FOV range (0-179)"); + + bool bInstant = instant.value_or(false); + if (eMode == FOV_MODE_PLAYER) + g_pGame->GetSettings()->SetFieldOfViewPlayer(fFOV, true, bInstant); + else if (eMode == FOV_MODE_VEHICLE) + g_pGame->GetSettings()->SetFieldOfViewVehicle(fFOV, true, bInstant); + else if (eMode == FOV_MODE_VEHICLE_MAX) + g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fFOV, true, bInstant); + else + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(eMode))); - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return true; } // Only when onfoot/invehicle -int CLuaCameraDefs::GetCameraFieldOfView(lua_State* luaVM) +std::variant CLuaCameraDefs::GetCameraFieldOfView(eFieldOfViewMode eMode) { - eFieldOfViewMode eMode; - CScriptArgReader argStream(luaVM); - - argStream.ReadEnumString(eMode); - - if (!argStream.HasErrors()) - { - float fFOV; - if (eMode == FOV_MODE_PLAYER) - fFOV = g_pGame->GetSettings()->GetFieldOfViewPlayer(); - else if (eMode == FOV_MODE_VEHICLE) - fFOV = g_pGame->GetSettings()->GetFieldOfViewVehicle(); - else if (eMode == FOV_MODE_VEHICLE_MAX) - fFOV = g_pGame->GetSettings()->GetFieldOfViewVehicleMax(); - else - { - argStream.m_iIndex = 1; - m_pScriptDebugging->LogCustom(luaVM, SString("Enum not yet implemented: " + EnumToString(eMode))); - lua_pushboolean(luaVM, false); - return 1; - } - - lua_pushnumber(luaVM, fFOV); - return 1; - } - - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + if (eMode == FOV_MODE_PLAYER) + return g_pGame->GetSettings()->GetFieldOfViewPlayer(); + else if (eMode == FOV_MODE_VEHICLE) + return g_pGame->GetSettings()->GetFieldOfViewVehicle(); + else if (eMode == FOV_MODE_VEHICLE_MAX) + return g_pGame->GetSettings()->GetFieldOfViewVehicleMax(); + + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(eMode))); } -int CLuaCameraDefs::SetCameraTarget(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, std::variant target) { // bool setCameraTarget ( element target = nil ) or setCameraTarget ( float x, float y, float z ) - - CScriptArgReader argStream(luaVM); - if (argStream.NextIsUserDataOfType()) + if (auto* pTarget = std::get_if(&target)) { - CClientEntity* pTarget; - argStream.ReadUserData(pTarget); + if (*pTarget && (*pTarget)->GetType() != CCLIENTPLAYER) + MinClientReqCheck(luaVM, MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); - if (pTarget->GetType() != CCLIENTPLAYER) - MinClientReqCheck(argStream, MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraTarget(pTarget)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } + return CStaticFunctionDefinitions::SetCameraTarget(*pTarget); } - else - { - CVector vecTarget; - argStream.ReadVector3D(vecTarget); - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraTarget(vecTarget)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - } - - if (argStream.HasErrors()) - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetCameraTarget(std::get(target)); } -int CLuaCameraDefs::SetCameraInterior(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraInterior(unsigned char ucInterior) { - unsigned char ucInterior = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadNumber(ucInterior); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraInterior(ucInterior)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetCameraInterior(ucInterior); } -int CLuaCameraDefs::FadeCamera(lua_State* luaVM) +bool CLuaCameraDefs::FadeCamera(bool bFadeIn, std::optional fFadeTime, std::optional ucRed, std::optional ucGreen, + std::optional ucBlue) { - bool bFadeIn = false; - unsigned char ucRed = 0; - unsigned char ucGreen = 0; - unsigned char ucBlue = 0; - float fFadeTime = 1.0f; - - CScriptArgReader argStream(luaVM); - argStream.ReadBool(bFadeIn); - argStream.ReadNumber(fFadeTime, 1.0f); - argStream.ReadNumber(ucRed, 0); - argStream.ReadNumber(ucGreen, 0); - argStream.ReadNumber(ucBlue, 0); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::FadeCamera(bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::FadeCamera(bFadeIn, fFadeTime.value_or(1.0f), ucRed.value_or(0), ucGreen.value_or(0), ucBlue.value_or(0)); } -int CLuaCameraDefs::SetCameraClip(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraClip(std::optional bObjects, std::optional bVehicles) { - bool bObjects = true; - bool bVehicles = true; - - CScriptArgReader argStream(luaVM); - argStream.ReadBool(bObjects, true); - argStream.ReadBool(bVehicles, true); - - m_pManager->GetCamera()->SetCameraClip(bObjects, bVehicles); + m_pManager->GetCamera()->SetCameraClip(bObjects.value_or(true), bVehicles.value_or(true)); - lua_pushboolean(luaVM, true); - return 1; + return true; } -int CLuaCameraDefs::GetCameraClip(lua_State* luaVM) +CLuaMultiReturn CLuaCameraDefs::GetCameraClip() { bool bObjects, bVehicles; m_pManager->GetCamera()->GetCameraClip(bObjects, bVehicles); - lua_pushboolean(luaVM, bObjects); - lua_pushboolean(luaVM, bVehicles); - return 2; + return {bObjects, bVehicles}; } bool CLuaCameraDefs::SetCameraViewMode(std::optional ucVehicleViewMode, std::optional ucPedViewMode) @@ -428,51 +281,29 @@ bool CLuaCameraDefs::SetCameraViewMode(std::optional ucVehicleVie return true; } -int CLuaCameraDefs::SetCameraGoggleEffect(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraGoggleEffect(std::string strMode, std::optional bNoiseEnabled) { - SString strMode; - bool bNoiseEnabled; - CScriptArgReader argStream(luaVM); - argStream.ReadString(strMode); - argStream.ReadBool(bNoiseEnabled, true); - - if (!argStream.HasErrors()) + bool bNoise = bNoiseEnabled.value_or(true); + if (strMode.compare("nightvision") == 0) { - bool bSuccess = false; - - if (strMode.compare("nightvision") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(true, bNoiseEnabled); - g_pMultiplayer->SetThermalVisionEnabled(false, true); - - bSuccess = true; - } - else if (strMode.compare("thermalvision") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(false, true); - g_pMultiplayer->SetThermalVisionEnabled(true, bNoiseEnabled); - - bSuccess = true; - } - else if (strMode.compare("normal") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(false, true); - g_pMultiplayer->SetThermalVisionEnabled(false, true); - - bSuccess = true; - } - - if (bSuccess) - { - lua_pushboolean(luaVM, true); - return 1; - } + g_pMultiplayer->SetNightVisionEnabled(true, bNoise); + g_pMultiplayer->SetThermalVisionEnabled(false, true); + return true; + } + else if (strMode.compare("thermalvision") == 0) + { + g_pMultiplayer->SetNightVisionEnabled(false, true); + g_pMultiplayer->SetThermalVisionEnabled(true, bNoise); + return true; + } + else if (strMode.compare("normal") == 0) + { + g_pMultiplayer->SetNightVisionEnabled(false, true); + g_pMultiplayer->SetThermalVisionEnabled(false, true); + return true; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return false; } bool CLuaCameraDefs::SetCameraDrunkLevel(short drunkLevel) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index b233d4e39c8..67907d1feb6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -29,19 +29,21 @@ class CLuaCameraDefs : public CLuaDefs static std::variant GetCameraTarget(); static unsigned char GetCameraInterior(); static std::string GetCameraGoggleEffect(); - LUA_DECLARE(GetCameraFieldOfView); - static unsigned char GetCameraDrunkLevel(); + static std::variant GetCameraFieldOfView(eFieldOfViewMode eMode); + static unsigned char GetCameraDrunkLevel(); // Cam set funcs - LUA_DECLARE(SetCameraMatrix); - LUA_DECLARE(SetCameraTarget); - LUA_DECLARE(SetCameraInterior); - LUA_DECLARE(SetCameraFieldOfView); - LUA_DECLARE(FadeCamera); - LUA_DECLARE(SetCameraClip); - LUA_DECLARE(GetCameraClip); - LUA_DECLARE(SetCameraGoggleEffect); - static bool SetCameraDrunkLevel(short drunkLevel); + static bool SetCameraMatrix(std::variant matrixOrPosition, std::optional vecLookAt, std::optional fRoll, + std::optional fFOV); + static bool SetCameraTarget(lua_State* luaVM, std::variant target); + static bool SetCameraInterior(unsigned char ucInterior); + static bool SetCameraFieldOfView(eFieldOfViewMode eMode, float fFOV, std::optional instant); + static bool FadeCamera(bool bFadeIn, std::optional fFadeTime, std::optional ucRed, std::optional ucGreen, + std::optional ucBlue); + static bool SetCameraClip(std::optional bObjects, std::optional bVehicles); + static CLuaMultiReturn GetCameraClip(); + static bool SetCameraGoggleEffect(std::string strMode, std::optional bNoiseEnabled); + static bool SetCameraDrunkLevel(short drunkLevel); // Cam do funcs static bool ShakeCamera(float radius, std::optional x, std::optional y, std::optional z) noexcept; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index bbdedd34dba..7e3b782d56e 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -20,15 +20,15 @@ void CLuaCameraDefs::LoadFunctions() { constexpr static const std::pair functions[]{ // Get functions - {"getCameraMatrix", getCameraMatrix}, - {"getCameraTarget", getCameraTarget}, - {"getCameraInterior", getCameraInterior}, + {"getCameraMatrix", ArgumentParserWarn}, + {"getCameraTarget", ArgumentParserWarn}, + {"getCameraInterior", ArgumentParserWarn}, // Set functions - {"setCameraMatrix", setCameraMatrix}, - {"setCameraTarget", setCameraTarget}, - {"setCameraInterior", setCameraInterior}, - {"fadeCamera", fadeCamera}, + {"setCameraMatrix", ArgumentParserWarn}, + {"setCameraTarget", ArgumentParserWarn}, + {"setCameraInterior", ArgumentParserWarn}, + {"fadeCamera", ArgumentParserWarn}, }; // Add functions @@ -36,36 +36,16 @@ void CLuaCameraDefs::LoadFunctions() CLuaCFunctions::AddFunction(name, func); } -int CLuaCameraDefs::getCameraMatrix(lua_State* luaVM) +std::variant, bool> CLuaCameraDefs::GetCameraMatrix(CPlayer* pPlayer) { // float cameraX, float cameraY, float cameraZ, float targetX, float targetY, float targetZ, float roll, float fov getCameraMatrix ( player thePlayer ) - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - - if (!argStream.HasErrors()) - { - CVector vecPosition, vecLookAt; - float fRoll, fFOV; - if (CStaticFunctionDefinitions::GetCameraMatrix(pPlayer, vecPosition, vecLookAt, fRoll, fFOV)) - { - lua_pushnumber(luaVM, vecPosition.fX); - lua_pushnumber(luaVM, vecPosition.fY); - lua_pushnumber(luaVM, vecPosition.fZ); - lua_pushnumber(luaVM, vecLookAt.fX); - lua_pushnumber(luaVM, vecLookAt.fY); - lua_pushnumber(luaVM, vecLookAt.fZ); - lua_pushnumber(luaVM, fRoll); - lua_pushnumber(luaVM, fFOV); - return 8; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CVector vecPosition, vecLookAt; + float fRoll, fFOV; + if (CStaticFunctionDefinitions::GetCameraMatrix(pPlayer, vecPosition, vecLookAt, fRoll, fFOV)) + return CLuaMultiReturn{vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecLookAt.fX, + vecLookAt.fY, vecLookAt.fZ, fRoll, fFOV}; - lua_pushboolean(luaVM, false); - return 1; + return false; } int CLuaCameraDefs::OOP_getCameraMatrix(lua_State* luaVM) @@ -92,184 +72,79 @@ int CLuaCameraDefs::OOP_getCameraMatrix(lua_State* luaVM) return 1; } -int CLuaCameraDefs::getCameraTarget(lua_State* luaVM) +std::variant CLuaCameraDefs::GetCameraTarget(CPlayer* pPlayer) { // element getCameraTarget ( player thePlayer ) - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - - if (!argStream.HasErrors()) - { - CElement* pTarget = CStaticFunctionDefinitions::GetCameraTarget(pPlayer); - if (pTarget) - { - lua_pushelement(luaVM, pTarget); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CElement* pTarget = CStaticFunctionDefinitions::GetCameraTarget(pPlayer); + if (pTarget) + return pTarget; - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaCameraDefs::getCameraInterior(lua_State* luaVM) +std::variant CLuaCameraDefs::GetCameraInterior(CPlayer* pPlayer) { // int getCameraInterior ( player thePlayer ) - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - - if (!argStream.HasErrors()) - { - unsigned char ucInterior; - if (CStaticFunctionDefinitions::GetCameraInterior(pPlayer, ucInterior)) - { - lua_pushnumber(luaVM, ucInterior); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + unsigned char ucInterior; + if (CStaticFunctionDefinitions::GetCameraInterior(pPlayer, ucInterior)) + return ucInterior; - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaCameraDefs::setCameraMatrix(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraMatrix(CElement* pPlayer, std::variant matrixOrPosition, std::optional vecLookAt, + std::optional fRoll, std::optional fFOV) { // bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = // 0, float fov = 70 ] ) - CElement* pPlayer; - CVector vecPosition; - CVector vecLookAt; - float fRoll; - float fFOV; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); + CVector vecPosition; + CVector lookAt; - if (argStream.NextIsUserDataOfType()) + if (auto* pMatrix = std::get_if(&matrixOrPosition)) { - CLuaMatrix* pMatrix; - argStream.ReadUserData(pMatrix); - - vecPosition = pMatrix->GetPosition(); - vecLookAt = pMatrix->GetRotation(); + vecPosition = (*pMatrix)->GetPosition(); + lookAt = (*pMatrix)->GetRotation(); } else { - argStream.ReadVector3D(vecPosition); - argStream.ReadVector3D(vecLookAt, CVector()); + vecPosition = std::get(matrixOrPosition); + lookAt = vecLookAt.value_or(CVector()); } - argStream.ReadNumber(fRoll, 0.0f); - argStream.ReadNumber(fFOV, 70.0f); - - if (!argStream.HasErrors()) - { - if (fFOV <= 0.0f || fFOV >= 180.0f) - fFOV = 70.0f; - - if (CStaticFunctionDefinitions::SetCameraMatrix(pPlayer, vecPosition, &vecLookAt, fRoll, fFOV)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + float fFOVValue = fFOV.value_or(70.0f); + if (fFOVValue <= 0.0f || fFOVValue >= 180.0f) + fFOVValue = 70.0f; - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetCameraMatrix(pPlayer, vecPosition, &lookAt, fRoll.value_or(0.0f), fFOVValue); } -int CLuaCameraDefs::setCameraTarget(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, CElement* pPlayer, std::optional pTarget) { // bool setCameraTarget ( player thePlayer [, element target = nil ] ) - CElement* pPlayer; - CElement* pTarget; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - argStream.ReadUserData(pTarget, NULL); - - if (pTarget && pTarget->GetType() != CElement::PLAYER) - MinServerReqCheck(argStream, MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); - - if (!argStream.HasErrors()) + if (pTarget.has_value() && pTarget.value() && pTarget.value()->GetType() != CElement::PLAYER) { - if (CStaticFunctionDefinitions::SetCameraTarget(pPlayer, pTarget)) + CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM); + if (pLuaMain && pLuaMain->GetResource() && pLuaMain->GetResource()->GetMinServerRequirement() < MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS) { - lua_pushboolean(luaVM, true); - return 1; +#if MTASA_VERSION_TYPE >= VERSION_TYPE_UNTESTED + throw std::invalid_argument(SString(" section in the meta.xml is incorrect or missing (expected at least server %s because %s)", + MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player")); +#endif } } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetCameraTarget(pPlayer, pTarget.value_or(nullptr)); } -int CLuaCameraDefs::setCameraInterior(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraInterior(CElement* pElement, unsigned char ucInterior) { // bool setCameraInterior ( player thePlayer, int interior ) - CElement* pElement; - unsigned char ucInterior; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pElement); - argStream.ReadNumber(ucInterior); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraInterior(pElement, ucInterior)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetCameraInterior(pElement, ucInterior); } -int CLuaCameraDefs::fadeCamera(lua_State* luaVM) +bool CLuaCameraDefs::FadeCamera(CElement* pPlayer, bool bFadeIn, std::optional fFadeTime, std::optional ucRed, + std::optional ucGreen, std::optional ucBlue) { // bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] ) - CElement* pPlayer; - bool bFadeIn; - float fFadeTime; - unsigned char ucRed; - unsigned char ucGreen; - unsigned char ucBlue; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - argStream.ReadBool(bFadeIn); - argStream.ReadNumber(fFadeTime, 1.0f); - argStream.ReadNumber(ucRed, 0); - argStream.ReadNumber(ucGreen, 0); - argStream.ReadNumber(ucBlue, 0); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::FadeCamera(pPlayer, bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::FadeCamera(pPlayer, bFadeIn, fFadeTime.value_or(1.0f), ucRed.value_or(0), ucGreen.value_or(0), ucBlue.value_or(0)); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index e120884d4ed..dd43c7b2f1b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -11,6 +11,7 @@ #pragma once #include "CLuaDefs.h" +#include class CLuaCameraDefs : public CLuaDefs { @@ -18,13 +19,16 @@ class CLuaCameraDefs : public CLuaDefs static void LoadFunctions(); // Get functions - LUA_DECLARE_OOP(getCameraMatrix); - LUA_DECLARE(getCameraTarget); - LUA_DECLARE(getCameraInterior); + static std::variant, bool> GetCameraMatrix(CPlayer* pPlayer); + LUA_DECLARE(OOP_getCameraMatrix); + static std::variant GetCameraTarget(CPlayer* pPlayer); + static std::variant GetCameraInterior(CPlayer* pPlayer); // Set functions - LUA_DECLARE(setCameraMatrix); - LUA_DECLARE(setCameraTarget); - LUA_DECLARE(setCameraInterior); - LUA_DECLARE(fadeCamera); + static bool SetCameraMatrix(CElement* pPlayer, std::variant matrixOrPosition, std::optional vecLookAt, + std::optional fRoll, std::optional fFOV); + static bool SetCameraTarget(lua_State* luaVM, CElement* pPlayer, std::optional pTarget); + static bool SetCameraInterior(CElement* pElement, unsigned char ucInterior); + static bool FadeCamera(CElement* pPlayer, bool bFadeIn, std::optional fFadeTime, std::optional ucRed, + std::optional ucGreen, std::optional ucBlue); }; From dc1df04c638655b0cfefd1ddaa2148e7acf87949 Mon Sep 17 00:00:00 2001 From: Youssef Maged <57957016+iManGaaX@users.noreply.github.com> Date: Thu, 10 Sep 2026 04:17:26 +0300 Subject: [PATCH 2/5] Refactor camera functions to use ArgumentParser --- .../logic/luadefs/CLuaCameraDefs.cpp | 416 ++++++++++++------ 1 file changed, 276 insertions(+), 140 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index 2b1cb5c2529..d13145b528a 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -16,6 +16,10 @@ #include #include +#include +#include +#include + #define MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS "1.5.8-9.20979" void CLuaCameraDefs::LoadFunctions() @@ -60,8 +64,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "resetFarClipDistance", "resetFarClipDistance"); lua_classfunction(luaVM, "resetNearClipDistance", "resetNearClipDistance"); - lua_classfunction(luaVM, "getPosition", OOP_GetCameraPosition); - lua_classfunction(luaVM, "getRotation", OOP_GetCameraRotation); + lua_classfunction(luaVM, "getPosition", ArgumentParserWarn); + lua_classfunction(luaVM, "getRotation", ArgumentParserWarn); lua_classfunction(luaVM, "getTarget", "getCameraTarget"); lua_classfunction(luaVM, "getInterior", "getCameraInterior"); lua_classfunction(luaVM, "getViewMode", "getCameraViewMode"); @@ -73,8 +77,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getNearClipDistance", "getNearClipDistance"); lua_classfunction(luaVM, "getType", ArgumentParser); - lua_classfunction(luaVM, "setPosition", OOP_SetCameraPosition); - lua_classfunction(luaVM, "setRotation", OOP_SetCameraRotation); + lua_classfunction(luaVM, "setPosition", ArgumentParserWarn); + lua_classfunction(luaVM, "setRotation", ArgumentParserWarn); lua_classfunction(luaVM, "setMatrix", "setCameraMatrix"); lua_classfunction(luaVM, "setFieldOfView", "setCameraFieldOfView"); lua_classfunction(luaVM, "setInterior", "setCameraInterior"); @@ -92,8 +96,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "farClipDistance", "setFarClipDistance", "getFarClipDistance"); lua_classvariable(luaVM, "nearClipDistance", "setNearClipDistance", "getNearClipDistance"); - lua_classvariable(luaVM, "position", OOP_SetCameraPosition, OOP_GetCameraPosition); - lua_classvariable(luaVM, "rotation", OOP_SetCameraRotation, OOP_GetCameraRotation); + lua_classvariable(luaVM, "position", ArgumentParserWarn, ArgumentParserWarn); + lua_classvariable(luaVM, "rotation", ArgumentParserWarn, ArgumentParserWarn); lua_classvariable(luaVM, "matrix", NULL, ArgumentParserWarn); lua_classvariable(luaVM, "type", nullptr, ArgumentParser); @@ -102,28 +106,62 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) std::variant CLuaCameraDefs::GetCamera() { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); - if (pCamera) - return pCamera; + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); + + if (camera) + return camera; + return false; } -CLuaMultiReturn CLuaCameraDefs::GetCameraViewMode() +CLuaMultiReturn CLuaCameraDefs::GetCameraViewMode() { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); - unsigned char ucVehicleMode = (unsigned char)pCamera->GetCameraVehicleViewMode(); - unsigned char ucPedMode = (unsigned char)pCamera->GetCameraPedViewMode(); + std::uint8_t vehicleMode = static_cast(camera->GetCameraVehicleViewMode()); + std::uint8_t pedMode = static_cast(camera->GetCameraPedViewMode()); - return {ucVehicleMode, ucPedMode}; + return {vehicleMode, pedMode}; } CLuaMultiReturn CLuaCameraDefs::GetCameraMatrix() { - CVector vecPosition, vecLookAt; - float fRoll, fFOV; - CStaticFunctionDefinitions::GetCameraMatrix(vecPosition, vecLookAt, fRoll, fFOV); - return {vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecLookAt.fX, vecLookAt.fY, vecLookAt.fZ, fRoll, fFOV}; + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + throw std::invalid_argument("Camera not available"); + + CVector position, lookAt; + float roll = 0.0f; + + camera->GetPosition(position); + camera->GetFixedTarget(lookAt, &roll); + + float fov = camera->GetAccurateFOV(); + + if (roll == 0.0f) + { + CMatrix matrix; + camera->GetMatrix(matrix); + + CVector worldUp(0.0f, 0.0f, 1.0f); + CVector cameraUp = matrix.vUp; + CVector cameraRight = matrix.vRight; + + CVector projectedUp = cameraUp - matrix.vFront * cameraUp.DotProduct(&matrix.vFront); + + if (projectedUp.Length() > FLOAT_EPSILON) + { + projectedUp.Normalize(); + + float cosRoll = worldUp.DotProduct(&projectedUp); + float sinRoll = cameraRight.DotProduct(&worldUp); + + roll = std::atan2(sinRoll, cosRoll) * (180.0f / std::numbers::pi_v); + } + } + + return {position.fX, position.fY, position.fZ, lookAt.fX, lookAt.fY, lookAt.fZ, roll, fov}; } CMatrix CLuaCameraDefs::OOP_GetCameraMatrix() @@ -135,97 +173,140 @@ CMatrix CLuaCameraDefs::OOP_GetCameraMatrix() std::variant CLuaCameraDefs::GetCameraTarget() { - CClientEntity* pTarget = CStaticFunctionDefinitions::GetCameraTarget(); - if (pTarget) - return pTarget; + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + return false; + + if (!camera->IsInFixedMode()) + { + if (CClientEntity* target = camera->GetTargetEntity()) + return target; + } + return false; } -unsigned char CLuaCameraDefs::GetCameraInterior() +std::uint8_t CLuaCameraDefs::GetCameraInterior() { - unsigned char ucInterior; - CStaticFunctionDefinitions::GetCameraInterior(ucInterior); - return ucInterior; + auto* world = g_pGame->GetWorld(); + + if (!world) + throw std::invalid_argument("World not available"); + + return static_cast(world->GetCurrentArea()); } std::string CLuaCameraDefs::GetCameraGoggleEffect() { - bool bNightVision = g_pMultiplayer->IsNightVisionEnabled(); - bool bThermalVision = g_pMultiplayer->IsThermalVisionEnabled(); + const bool isNightVision = g_pMultiplayer->IsNightVisionEnabled(); + const bool isThermalVision = g_pMultiplayer->IsThermalVisionEnabled(); - if (bNightVision) + if (isNightVision) return "nightvision"; - else if (bThermalVision) + else if (isThermalVision) return "thermalvision"; else return "normal"; } -unsigned char CLuaCameraDefs::GetCameraDrunkLevel() +std::uint8_t CLuaCameraDefs::GetCameraDrunkLevel() { return g_pGame->GetPlayerInfo()->GetCamDrunkLevel(); } -bool CLuaCameraDefs::SetCameraMatrix(std::variant matrixOrPosition, std::optional vecLookAt, std::optional fRoll, - std::optional fFOV) +bool CLuaCameraDefs::SetCameraMatrix(std::variant matrixOrPosition, std::optional lookAt, std::optional roll, + std::optional fov) { - CVector vecPosition; - CVector lookAt; - bool bLookAtValid = false; + CClientCamera* camera = m_pManager->GetCamera(); - if (auto* pMatrix = std::get_if(&matrixOrPosition)) + if (!camera) + return false; + + CVector position; + CVector lookAtValue; + bool lookAtValid = false; + + if (auto* matrix = std::get_if(&matrixOrPosition)) { - vecPosition = (*pMatrix)->GetPosition(); - lookAt = (*pMatrix)->GetRotation(); - bLookAtValid = true; + position = (*matrix)->GetPosition(); + lookAtValue = (*matrix)->GetRotation(); + lookAtValid = true; } else { - vecPosition = std::get(matrixOrPosition); - if (vecLookAt.has_value()) + position = std::get(matrixOrPosition); + + if (lookAt.has_value()) { - lookAt = vecLookAt.value(); - bLookAtValid = true; + lookAtValue = lookAt.value(); + lookAtValid = true; } } - float fFOVValue = fFOV.value_or(70.0f); - if (fFOVValue <= 0.0f || fFOVValue >= 180.0f) - fFOVValue = 70.0f; + if (!CameraScriptShared::IsFiniteVector(position)) + throw std::invalid_argument("Invalid matrix/position (values out of range)"); + + if (lookAtValid && !CameraScriptShared::IsFiniteVector(lookAtValue)) + throw std::invalid_argument("Invalid lookAt (values out of range)"); + + const float rollValue = CameraScriptShared::NormalizeRoll(roll.value_or(0.0f)); + + float fovValue = fov.value_or(70.0f); + + if (fovValue <= 0.0f || fovValue >= 180.0f) + fovValue = 70.0f; + + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); - return CStaticFunctionDefinitions::SetCameraMatrix(vecPosition, bLookAtValid ? &lookAt : nullptr, fRoll.value_or(0.0f), fFOVValue); + camera->SetPosition(position); + + if (lookAtValid) + camera->SetFixedTarget(lookAtValue, rollValue); + else + { + CVector previousLookAt; + camera->GetFixedTarget(previousLookAt); + camera->SetFixedTarget(previousLookAt, rollValue); + } + + camera->SetFOV(fovValue); + + return true; } // Only when onfoot/invehicle -bool CLuaCameraDefs::SetCameraFieldOfView(eFieldOfViewMode eMode, float fFOV, std::optional instant) +bool CLuaCameraDefs::SetCameraFieldOfView(eFieldOfViewMode mode, float fov, std::optional instant) { - if (fFOV < 0 || fFOV > 179) + if (fov < 0 || fov > 179) throw std::invalid_argument("Invalid FOV range (0-179)"); - bool bInstant = instant.value_or(false); - if (eMode == FOV_MODE_PLAYER) - g_pGame->GetSettings()->SetFieldOfViewPlayer(fFOV, true, bInstant); - else if (eMode == FOV_MODE_VEHICLE) - g_pGame->GetSettings()->SetFieldOfViewVehicle(fFOV, true, bInstant); - else if (eMode == FOV_MODE_VEHICLE_MAX) - g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fFOV, true, bInstant); + const bool isInstant = instant.value_or(false); + + if (mode == FOV_MODE_PLAYER) + g_pGame->GetSettings()->SetFieldOfViewPlayer(fov, true, isInstant); + else if (mode == FOV_MODE_VEHICLE) + g_pGame->GetSettings()->SetFieldOfViewVehicle(fov, true, isInstant); + else if (mode == FOV_MODE_VEHICLE_MAX) + g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fov, true, isInstant); else - throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(eMode))); + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(mode))); return true; } // Only when onfoot/invehicle -std::variant CLuaCameraDefs::GetCameraFieldOfView(eFieldOfViewMode eMode) +std::variant CLuaCameraDefs::GetCameraFieldOfView(eFieldOfViewMode mode) { - if (eMode == FOV_MODE_PLAYER) + if (mode == FOV_MODE_PLAYER) return g_pGame->GetSettings()->GetFieldOfViewPlayer(); - else if (eMode == FOV_MODE_VEHICLE) + else if (mode == FOV_MODE_VEHICLE) return g_pGame->GetSettings()->GetFieldOfViewVehicle(); - else if (eMode == FOV_MODE_VEHICLE_MAX) + else if (mode == FOV_MODE_VEHICLE_MAX) return g_pGame->GetSettings()->GetFieldOfViewVehicleMax(); - throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(eMode))); + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(mode))); } bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, std::variant target) @@ -233,70 +314,146 @@ bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, std::variant(&target)) { - if (*pTarget && (*pTarget)->GetType() != CCLIENTPLAYER) + if (!*pTarget) + return false; + + if ((*pTarget)->IsBeingDeleted()) + return false; + + if ((*pTarget)->GetType() != CCLIENTPLAYER) MinClientReqCheck(luaVM, MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); - return CStaticFunctionDefinitions::SetCameraTarget(*pTarget); + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + return false; + + switch ((*pTarget)->GetType()) + { + case CCLIENTPLAYER: + { + CClientPlayer* player = static_cast(*pTarget); + if (player->IsLocalPlayer()) + { + camera->SetFocusToLocalPlayer(); + } + else + { + // TODO: stream in the player here (needs to be done through the streamer) + + camera->SetFocus(player, MODE_CAM_ON_A_STRING, false); + } + break; + } + case CCLIENTPED: + case CCLIENTVEHICLE: + { + camera->Reset(); + camera->SetFocus(*pTarget, MODE_CAM_ON_A_STRING, false); + break; + } + default: + return false; + } + + return true; } - return CStaticFunctionDefinitions::SetCameraTarget(std::get(target)); + CClientCamera* camera = m_pManager->GetCamera(); + if (!camera) + return false; + + camera->SetOrbitTarget(std::get(target)); + return true; } -bool CLuaCameraDefs::SetCameraInterior(unsigned char ucInterior) +bool CLuaCameraDefs::SetCameraInterior(std::uint8_t interior) { - return CStaticFunctionDefinitions::SetCameraInterior(ucInterior); + auto* world = g_pGame->GetWorld(); + + if (!world) + return false; + + world->SetCurrentArea(interior); + + return true; } -bool CLuaCameraDefs::FadeCamera(bool bFadeIn, std::optional fFadeTime, std::optional ucRed, std::optional ucGreen, - std::optional ucBlue) +bool CLuaCameraDefs::FadeCamera(bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue) { - return CStaticFunctionDefinitions::FadeCamera(bFadeIn, fFadeTime.value_or(1.0f), ucRed.value_or(0), ucGreen.value_or(0), ucBlue.value_or(0)); + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera || !g_pClientGame) + return false; + + g_pClientGame->SetInitiallyFadedOut(false); + + const float fadeTimeValue = fadeTime.value_or(1.0f); + + if (fadeIn) + { + camera->FadeIn(fadeTimeValue); + if (g_pGame && g_pGame->GetHud()) + g_pGame->GetHud()->SetComponentVisible(HUD_AREA_NAME, !g_pClientGame->GetHudAreaNameDisabled()); + } + else + { + camera->FadeOut(fadeTimeValue, red.value_or(0), green.value_or(0), blue.value_or(0)); + if (g_pGame && g_pGame->GetHud()) + g_pGame->GetHud()->SetComponentVisible(HUD_AREA_NAME, false); + } + + return true; } -bool CLuaCameraDefs::SetCameraClip(std::optional bObjects, std::optional bVehicles) +bool CLuaCameraDefs::SetCameraClip(std::optional objects, std::optional vehicles) { - m_pManager->GetCamera()->SetCameraClip(bObjects.value_or(true), bVehicles.value_or(true)); + m_pManager->GetCamera()->SetCameraClip(objects.value_or(true), vehicles.value_or(true)); return true; } CLuaMultiReturn CLuaCameraDefs::GetCameraClip() { - bool bObjects, bVehicles; - m_pManager->GetCamera()->GetCameraClip(bObjects, bVehicles); + bool isObjects = false; + bool isVehicles = false; + + m_pManager->GetCamera()->GetCameraClip(isObjects, isVehicles); - return {bObjects, bVehicles}; + return {isObjects, isVehicles}; } -bool CLuaCameraDefs::SetCameraViewMode(std::optional ucVehicleViewMode, std::optional ucPedViewMode) +bool CLuaCameraDefs::SetCameraViewMode(std::optional vehicleViewMode, std::optional pedViewMode) { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); - if (ucVehicleViewMode) - pCamera->SetCameraVehicleViewMode((eVehicleCamMode)ucVehicleViewMode.value()); + if (vehicleViewMode) + camera->SetCameraVehicleViewMode(static_cast(vehicleViewMode.value())); - if (ucPedViewMode) - pCamera->SetCameraPedViewMode((ePedCamMode)ucPedViewMode.value()); + if (pedViewMode) + camera->SetCameraPedViewMode(static_cast(pedViewMode.value())); return true; } -bool CLuaCameraDefs::SetCameraGoggleEffect(std::string strMode, std::optional bNoiseEnabled) +bool CLuaCameraDefs::SetCameraGoggleEffect(std::string mode, std::optional noiseEnabled) { - bool bNoise = bNoiseEnabled.value_or(true); - if (strMode.compare("nightvision") == 0) + const bool isNoiseEnabled = noiseEnabled.value_or(true); + + if (mode.compare("nightvision") == 0) { - g_pMultiplayer->SetNightVisionEnabled(true, bNoise); + g_pMultiplayer->SetNightVisionEnabled(true, isNoiseEnabled); g_pMultiplayer->SetThermalVisionEnabled(false, true); return true; } - else if (strMode.compare("thermalvision") == 0) + else if (mode.compare("thermalvision") == 0) { g_pMultiplayer->SetNightVisionEnabled(false, true); - g_pMultiplayer->SetThermalVisionEnabled(true, bNoise); + g_pMultiplayer->SetThermalVisionEnabled(true, isNoiseEnabled); return true; } - else if (strMode.compare("normal") == 0) + else if (mode.compare("normal") == 0) { g_pMultiplayer->SetNightVisionEnabled(false, true); g_pMultiplayer->SetThermalVisionEnabled(false, true); @@ -306,79 +463,54 @@ bool CLuaCameraDefs::SetCameraGoggleEffect(std::string strMode, std::optional 255) + if (level < 0 || level > 255) throw std::invalid_argument("Invalid range (0-255)"); - CPlayerInfo* pPlayerInfo = g_pGame->GetPlayerInfo(); - pPlayerInfo->SetCamDrunkLevel(static_cast(drunkLevel)); + CPlayerInfo* playerInfo = g_pGame->GetPlayerInfo(); + + playerInfo->SetCamDrunkLevel(static_cast(level)); return true; } -int CLuaCameraDefs::OOP_GetCameraPosition(lua_State* luaVM) +CVector CLuaCameraDefs::OOP_GetCameraPosition() noexcept { - CVector vecPosition; - m_pManager->GetCamera()->GetPosition(vecPosition); - - lua_pushvector(luaVM, vecPosition); - return 1; + CVector position; + m_pManager->GetCamera()->GetPosition(position); + return position; } -int CLuaCameraDefs::OOP_SetCameraPosition(lua_State* luaVM) +bool CLuaCameraDefs::OOP_SetCameraPosition(CVector position) { - CVector vecPosition; - CScriptArgReader argStream(luaVM); - argStream.ReadVector3D(vecPosition); + CClientCamera* camera = m_pManager->GetCamera(); - if (!argStream.HasErrors()) - { - CClientCamera* pCamera = m_pManager->GetCamera(); - if (!pCamera->IsInFixedMode()) - { - pCamera->ToggleCameraFixedMode(true); - } + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); - pCamera->SetPosition(vecPosition); + camera->SetPosition(position); - lua_pushboolean(luaVM, true); - return 1; - } - lua_pushboolean(luaVM, false); - return 1; + return true; } -int CLuaCameraDefs::OOP_GetCameraRotation(lua_State* luaVM) +CVector CLuaCameraDefs::OOP_GetCameraRotation() noexcept { - CVector vecPosition; - m_pManager->GetCamera()->GetRotationDegrees(vecPosition); - - lua_pushvector(luaVM, vecPosition); - return 1; + CVector rotation; + m_pManager->GetCamera()->GetRotationDegrees(rotation); + return rotation; } -int CLuaCameraDefs::OOP_SetCameraRotation(lua_State* luaVM) +bool CLuaCameraDefs::OOP_SetCameraRotation(CVector rotation) { - CVector vecRotation; - CScriptArgReader argStream(luaVM); - argStream.ReadVector3D(vecRotation); + CClientCamera* camera = m_pManager->GetCamera(); - if (!argStream.HasErrors()) - { - CClientCamera* pCamera = m_pManager->GetCamera(); - if (!pCamera->IsInFixedMode()) - { - pCamera->ToggleCameraFixedMode(true); - } + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); - pCamera->SetRotationDegrees(vecRotation); + camera->SetRotationDegrees(rotation); - lua_pushboolean(luaVM, true); - return 1; - } - lua_pushboolean(luaVM, false); - return 1; + return true; } const SString& CLuaCameraDefs::GetElementType() @@ -390,13 +522,17 @@ bool CLuaCameraDefs::ShakeCamera(float radius, std::optional x, std::opti { if (!x || !y || !z) { - const auto* player = CStaticFunctionDefinitions::GetLocalPlayer(); - CVector out; + const auto* player = m_pPlayerManager->GetLocalPlayer(); + + CVector out; + player->GetPosition(out); + x = out.fX; y = out.fY; z = out.fZ; } + m_pManager->GetCamera()->ShakeCamera(radius, *x, *y, *z); return true; From 519b7da9b4707f5831433b8433061df08203314c Mon Sep 17 00:00:00 2001 From: Youssef Maged <57957016+iManGaaX@users.noreply.github.com> Date: Thu, 10 Sep 2026 04:17:36 +0300 Subject: [PATCH 3/5] Refactor camera function signatures to use std::uint8_t --- .../deathmatch/logic/luadefs/CLuaCameraDefs.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index 67907d1feb6..e45e3132936 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -19,41 +19,41 @@ class CLuaCameraDefs : public CLuaDefs static void LoadFunctions(); static void AddClass(lua_State* luaVM); - static bool SetCameraViewMode(std::optional usVehicleViewMode, std::optional usPedViewMode); - static CLuaMultiReturn GetCameraViewMode(); + static bool SetCameraViewMode(std::optional vehicleViewMode, std::optional pedViewMode); + static CLuaMultiReturn GetCameraViewMode(); // Cam get funcs static std::variant GetCamera(); static CLuaMultiReturn GetCameraMatrix(); static CMatrix OOP_GetCameraMatrix(); static std::variant GetCameraTarget(); - static unsigned char GetCameraInterior(); + static std::uint8_t GetCameraInterior(); static std::string GetCameraGoggleEffect(); - static std::variant GetCameraFieldOfView(eFieldOfViewMode eMode); - static unsigned char GetCameraDrunkLevel(); + static std::variant GetCameraFieldOfView(eFieldOfViewMode mode); + static std::uint8_t GetCameraDrunkLevel(); // Cam set funcs - static bool SetCameraMatrix(std::variant matrixOrPosition, std::optional vecLookAt, std::optional fRoll, - std::optional fFOV); + static bool SetCameraMatrix(std::variant matrixOrPosition, std::optional lookAt, std::optional roll, + std::optional fov); static bool SetCameraTarget(lua_State* luaVM, std::variant target); - static bool SetCameraInterior(unsigned char ucInterior); - static bool SetCameraFieldOfView(eFieldOfViewMode eMode, float fFOV, std::optional instant); - static bool FadeCamera(bool bFadeIn, std::optional fFadeTime, std::optional ucRed, std::optional ucGreen, - std::optional ucBlue); - static bool SetCameraClip(std::optional bObjects, std::optional bVehicles); + static bool SetCameraInterior(std::uint8_t interior); + static bool SetCameraFieldOfView(eFieldOfViewMode mode, float fov, std::optional instant); + static bool FadeCamera(bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue); + static bool SetCameraClip(std::optional objects, std::optional vehicles); static CLuaMultiReturn GetCameraClip(); - static bool SetCameraGoggleEffect(std::string strMode, std::optional bNoiseEnabled); - static bool SetCameraDrunkLevel(short drunkLevel); + static bool SetCameraGoggleEffect(std::string mode, std::optional noiseEnabled); + static bool SetCameraDrunkLevel(std::int16_t level); // Cam do funcs static bool ShakeCamera(float radius, std::optional x, std::optional y, std::optional z) noexcept; static bool ResetShakeCamera() noexcept; // For OOP only - LUA_DECLARE(OOP_GetCameraPosition); - LUA_DECLARE(OOP_SetCameraPosition); - LUA_DECLARE(OOP_GetCameraRotation); - LUA_DECLARE(OOP_SetCameraRotation); + static CVector OOP_GetCameraPosition() noexcept; + static bool OOP_SetCameraPosition(CVector position); + static CVector OOP_GetCameraRotation() noexcept; + static bool OOP_SetCameraRotation(CVector rotation); static const SString& GetElementType(); }; From a95e64140b11d1f0b77a632040bc274773e16e7d Mon Sep 17 00:00:00 2001 From: Youssef Maged <57957016+iManGaaX@users.noreply.github.com> Date: Thu, 10 Sep 2026 04:17:48 +0300 Subject: [PATCH 4/5] Refactor camera functions to use CPlayerCamera Refactor CLuaCameraDefs to use CPlayerCamera methods for camera operations and improve code structure. --- .../logic/luadefs/CLuaCameraDefs.cpp | 293 ++++++++++++++---- 1 file changed, 231 insertions(+), 62 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index 7e3b782d56e..290498a31a9 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -11,8 +11,10 @@ #include "StdInc.h" #include "CLuaCameraDefs.h" -#include "CStaticFunctionDefinitions.h" -#include "CScriptArgReader.h" +#include "CPlayerCamera.h" +#include "CameraScriptShared.h" +#include "packets/CLuaPacket.h" +#include #define MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS "1.5.8-9.20979" @@ -36,95 +38,141 @@ void CLuaCameraDefs::LoadFunctions() CLuaCFunctions::AddFunction(name, func); } -std::variant, bool> CLuaCameraDefs::GetCameraMatrix(CPlayer* pPlayer) +std::variant, bool> CLuaCameraDefs::GetCameraMatrix(CPlayer* player) { // float cameraX, float cameraY, float cameraZ, float targetX, float targetY, float targetZ, float roll, float fov getCameraMatrix ( player thePlayer ) - CVector vecPosition, vecLookAt; - float fRoll, fFOV; - if (CStaticFunctionDefinitions::GetCameraMatrix(pPlayer, vecPosition, vecLookAt, fRoll, fFOV)) - return CLuaMultiReturn{vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecLookAt.fX, - vecLookAt.fY, vecLookAt.fZ, fRoll, fFOV}; + CPlayerCamera* camera = player->GetCamera(); - return false; -} - -int CLuaCameraDefs::OOP_getCameraMatrix(lua_State* luaVM) -{ - // Needs further attention before adding - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); + if (!camera) + return false; - argStream.ReadUserData(pPlayer); + CVector position, lookAt; - if (!argStream.HasErrors()) - { - CMatrix matrix; - // pPlayer->GetCamera ()->GetMatrix ( matrix ); + camera->GetPosition(position); + camera->GetLookAt(lookAt); - lua_pushmatrix(luaVM, matrix); - return 1; - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CLuaMultiReturn{position.fX, position.fY, position.fZ, lookAt.fX, + lookAt.fY, lookAt.fZ, camera->GetRoll(), camera->GetFOV()}; } -std::variant CLuaCameraDefs::GetCameraTarget(CPlayer* pPlayer) +std::variant CLuaCameraDefs::GetCameraTarget(CPlayer* player) { // element getCameraTarget ( player thePlayer ) - CElement* pTarget = CStaticFunctionDefinitions::GetCameraTarget(pPlayer); - if (pTarget) - return pTarget; + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + // Only allow this if we're targeting a player + if (camera->GetMode() == CAMERAMODE_PLAYER) + { + if (CElement* target = camera->GetTarget()) + return target; + } return false; } -std::variant CLuaCameraDefs::GetCameraInterior(CPlayer* pPlayer) +std::variant CLuaCameraDefs::GetCameraInterior(CPlayer* player) { // int getCameraInterior ( player thePlayer ) - unsigned char ucInterior; - if (CStaticFunctionDefinitions::GetCameraInterior(pPlayer, ucInterior)) - return ucInterior; + CPlayerCamera* camera = player->GetCamera(); - return false; + if (!camera) + return false; + + return static_cast(camera->GetInterior()); } -bool CLuaCameraDefs::SetCameraMatrix(CElement* pPlayer, std::variant matrixOrPosition, std::optional vecLookAt, - std::optional fRoll, std::optional fFOV) +bool CLuaCameraDefs::SetCameraMatrix(CElement* element, std::variant matrixOrPosition, std::optional lookAt, + std::optional roll, std::optional fov) { // bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = // 0, float fov = 70 ] ) - CVector vecPosition; - CVector lookAt; + CVector position; + CVector lookAtValue; - if (auto* pMatrix = std::get_if(&matrixOrPosition)) + if (auto* matrix = std::get_if(&matrixOrPosition)) { - vecPosition = (*pMatrix)->GetPosition(); - lookAt = (*pMatrix)->GetRotation(); + position = (*matrix)->GetPosition(); + lookAtValue = (*matrix)->GetRotation(); } else { - vecPosition = std::get(matrixOrPosition); - lookAt = vecLookAt.value_or(CVector()); + position = std::get(matrixOrPosition); + lookAtValue = lookAt.value_or(CVector()); } - float fFOVValue = fFOV.value_or(70.0f); - if (fFOVValue <= 0.0f || fFOVValue >= 180.0f) - fFOVValue = 70.0f; + if (!CameraScriptShared::IsFiniteVector(position)) + throw std::invalid_argument("Invalid matrix/position (values out of range)"); + + if (!CameraScriptShared::IsFiniteVector(lookAtValue)) + throw std::invalid_argument("Invalid lookAt (values out of range)"); + + const float rollValue = CameraScriptShared::NormalizeRoll(roll.value_or(0.0f)); + + float fovValue = fov.value_or(70.0f); + + if (fovValue <= 0.0f || fovValue >= 180.0f) + fovValue = 70.0f; + + auto ApplyToPlayer = [&](CElement* playerElement) + { + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + camera->SetMode(CAMERAMODE_FIXED); + camera->SetMatrix(position, lookAtValue); + camera->SetRoll(rollValue); + camera->SetFOV(fovValue); + + CBitStream BitStream; + + BitStream.pBitStream->Write(camera->GenerateSyncTimeContext()); + + BitStream.pBitStream->Write(position.fX); + BitStream.pBitStream->Write(position.fY); + BitStream.pBitStream->Write(position.fZ); + + BitStream.pBitStream->Write(lookAtValue.fX); + BitStream.pBitStream->Write(lookAtValue.fY); + BitStream.pBitStream->Write(lookAtValue.fZ); + + if (rollValue != 0.0f || fovValue != CameraScriptShared::kDefaultFOV) + { + BitStream.pBitStream->Write(rollValue); + BitStream.pBitStream->Write(fovValue); + } + + player->Send(CLuaPacket(SET_CAMERA_MATRIX, *BitStream.pBitStream)); - return CStaticFunctionDefinitions::SetCameraMatrix(pPlayer, vecPosition, &lookAt, fRoll.value_or(0.0f), fFOVValue); + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraMatrix(*iter, position, lookAtValue, rollValue, fovValue); + } + + return ApplyToPlayer(element); } -bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, CElement* pPlayer, std::optional pTarget) +bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, CElement* element, std::optional target) { // bool setCameraTarget ( player thePlayer [, element target = nil ] ) - if (pTarget.has_value() && pTarget.value() && pTarget.value()->GetType() != CElement::PLAYER) + if (target.has_value() && target.value() && target.value()->GetType() != CElement::PLAYER) { - CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM); - if (pLuaMain && pLuaMain->GetResource() && pLuaMain->GetResource()->GetMinServerRequirement() < MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS) + CLuaMain* luaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM); + if (luaMain && luaMain->GetResource() && luaMain->GetResource()->GetMinServerRequirement() < MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS) { #if MTASA_VERSION_TYPE >= VERSION_TYPE_UNTESTED throw std::invalid_argument(SString(" section in the meta.xml is incorrect or missing (expected at least server %s because %s)", @@ -133,18 +181,139 @@ bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, CElement* pPlayer, std::o } } - return CStaticFunctionDefinitions::SetCameraTarget(pPlayer, pTarget.value_or(nullptr)); + CElement* targetValue = target.value_or(nullptr); + + auto ApplyToPlayer = [&](CElement* playerElement) + { + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + // If we don't have a target, change it to the player + CElement* effectiveTarget = targetValue ? targetValue : player; + + switch (effectiveTarget->GetType()) + { + case CElement::PLAYER: + case CElement::PED: + case CElement::VEHICLE: + { + camera->SetMode(CAMERAMODE_PLAYER); + camera->SetTarget(effectiveTarget); + camera->SetRoll(0.0f); + camera->SetFOV(70.0f); + + CBitStream BitStream; + + BitStream.pBitStream->Write(camera->GenerateSyncTimeContext()); + BitStream.pBitStream->Write(effectiveTarget->GetID()); + + player->Send(CLuaPacket(SET_CAMERA_TARGET, *BitStream.pBitStream)); + + return true; + } + default: + return false; + } + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraTarget(luaVM, *iter, targetValue); + } + + return ApplyToPlayer(element); } -bool CLuaCameraDefs::SetCameraInterior(CElement* pElement, unsigned char ucInterior) +bool CLuaCameraDefs::SetCameraInterior(CElement* element, std::uint8_t interior) { // bool setCameraInterior ( player thePlayer, int interior ) - return CStaticFunctionDefinitions::SetCameraInterior(pElement, ucInterior); + auto ApplyToPlayer = [&](CElement* playerElement) + { + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + if (camera->GetInterior() == interior) + return false; + + camera->SetInterior(interior); + + CBitStream BitStream; + + BitStream.pBitStream->Write(interior); + + player->Send(CLuaPacket(SET_CAMERA_INTERIOR, *BitStream.pBitStream)); + + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraInterior(*iter, interior); + } + + return ApplyToPlayer(element); } -bool CLuaCameraDefs::FadeCamera(CElement* pPlayer, bool bFadeIn, std::optional fFadeTime, std::optional ucRed, - std::optional ucGreen, std::optional ucBlue) +bool CLuaCameraDefs::FadeCamera(CElement* element, bool fadeIn, std::optional fadeTime, std::optional red, + std::optional green, std::optional blue) { // bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] ) - return CStaticFunctionDefinitions::FadeCamera(pPlayer, bFadeIn, fFadeTime.value_or(1.0f), ucRed.value_or(0), ucGreen.value_or(0), ucBlue.value_or(0)); + const float fadeTimeValue = fadeTime.value_or(1.0f); + const std::uint8_t redValue = red.value_or(0); + const std::uint8_t greenValue = green.value_or(0); + const std::uint8_t blueValue = blue.value_or(0); + + auto ApplyToPlayer = [&](CElement* playerElement) + { + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + + const std::uint8_t fadeInValue = fadeIn ? 1 : 0; + + CBitStream BitStream; + + BitStream.pBitStream->Write(fadeInValue); + BitStream.pBitStream->Write(fadeTimeValue); + + if (!fadeIn) + { + BitStream.pBitStream->Write(redValue); + BitStream.pBitStream->Write(greenValue); + BitStream.pBitStream->Write(blueValue); + } + + player->Send(CLuaPacket(FADE_CAMERA, *BitStream.pBitStream)); + + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + FadeCamera(*iter, fadeIn, fadeTimeValue, redValue, greenValue, blueValue); + } + + return ApplyToPlayer(element); } From c8b78d3500cb611ba1fa5d63043069acafac8111 Mon Sep 17 00:00:00 2001 From: Youssef Maged <57957016+iManGaaX@users.noreply.github.com> Date: Thu, 10 Sep 2026 04:17:58 +0300 Subject: [PATCH 5/5] Refactor camera function parameters for consistency --- .../deathmatch/logic/luadefs/CLuaCameraDefs.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index dd43c7b2f1b..48fe79b40b3 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -19,16 +19,15 @@ class CLuaCameraDefs : public CLuaDefs static void LoadFunctions(); // Get functions - static std::variant, bool> GetCameraMatrix(CPlayer* pPlayer); - LUA_DECLARE(OOP_getCameraMatrix); - static std::variant GetCameraTarget(CPlayer* pPlayer); - static std::variant GetCameraInterior(CPlayer* pPlayer); + static std::variant, bool> GetCameraMatrix(CPlayer* player); + static std::variant GetCameraTarget(CPlayer* player); + static std::variant GetCameraInterior(CPlayer* player); // Set functions - static bool SetCameraMatrix(CElement* pPlayer, std::variant matrixOrPosition, std::optional vecLookAt, - std::optional fRoll, std::optional fFOV); - static bool SetCameraTarget(lua_State* luaVM, CElement* pPlayer, std::optional pTarget); - static bool SetCameraInterior(CElement* pElement, unsigned char ucInterior); - static bool FadeCamera(CElement* pPlayer, bool bFadeIn, std::optional fFadeTime, std::optional ucRed, - std::optional ucGreen, std::optional ucBlue); + static bool SetCameraMatrix(CElement* element, std::variant matrixOrPosition, std::optional lookAt, + std::optional roll, std::optional fov); + static bool SetCameraTarget(lua_State* luaVM, CElement* element, std::optional target); + static bool SetCameraInterior(CElement* element, std::uint8_t interior); + static bool FadeCamera(CElement* element, bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue); };