From a9272305920091a1fc6270fabf0a3e0fcf8429dd Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 8 Oct 2024 16:06:28 +0200 Subject: [PATCH 1/2] Fix bug --- .../deathmatch/logic/luadefs/CLuaBuildingDefs.cpp | 11 +++++------ .../mods/deathmatch/logic/luadefs/CLuaBuildingDefs.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp index bcb765e712..db9b5b62dc 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp @@ -33,7 +33,7 @@ void CLuaBuildingDefs::AddClass(lua_State* luaVM) lua_registerclass(luaVM, "Building", "Element"); } -CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, std::uint16_t modelId, CVector pos, std::optional rot, std::optional interior) +CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, std::uint16_t modelId, CVector pos, std::optional rotX, std::optional rotY, std::optional rotZ, std::optional interior) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); @@ -48,14 +48,13 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, std::u if (!CClientBuildingManager::IsValidPosition(pos)) throw std::invalid_argument("Position is outside of game world"); - if (rot.has_value()) - ConvertDegreesToRadians(rot.value()); - else - rot.emplace(CVector(0, 0, 0)); + CVector rot{rotX.value_or(0), rotY.value_or(0), rotZ.value_or(0)}; + if (rot.fX != 0 || rot.fY != 0 || rot.fZ != 0) + ConvertDegreesToRadians(rot); m_pBuildingManager->ResizePoolIfNeeds(); - CClientBuilding* pBuilding = new CClientBuilding(m_pManager, INVALID_ELEMENT_ID, modelId, pos, rot.value() , interior.value_or(0)); + CClientBuilding* pBuilding = new CClientBuilding(m_pManager, INVALID_ELEMENT_ID, modelId, pos, rot, interior.value_or(0)); CClientEntity* pRoot = pResource->GetResourceDynamicEntity(); pBuilding->SetParent(pRoot); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.h index a244c74bbb..0299ca5c2c 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.h @@ -19,7 +19,7 @@ class CLuaBuildingDefs : public CLuaDefs static void AddClass(lua_State* luaVM); // Buiding create funcs - static CClientBuilding* CreateBuilding(lua_State* const luaVM, std::uint16_t modelId, CVector pos, std::optional rot, std::optional interior); + static CClientBuilding* CreateBuilding(lua_State* const luaVM, std::uint16_t modelId, CVector pos, std::optional rotX, std::optional rotY, std::optional rotZ, std::optional interior); static void RemoveAllGameBuildings(); static void RestoreGameBuildings(); }; From ca0a451b1b893a7382618ebf551f9a77e2ad15b2 Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 8 Oct 2024 18:40:22 +0200 Subject: [PATCH 2/2] Review --- Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp index db9b5b62dc..74757a28bc 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp @@ -49,7 +49,8 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, std::u throw std::invalid_argument("Position is outside of game world"); CVector rot{rotX.value_or(0), rotY.value_or(0), rotZ.value_or(0)}; - if (rot.fX != 0 || rot.fY != 0 || rot.fZ != 0) + float epsilon = std::numeric_limits::epsilon(); + if (std::abs(rot.fX) < epsilon || std::abs(rot.fY) < epsilon || std::abs(rot.fZ) < epsilon) ConvertDegreesToRadians(rot); m_pBuildingManager->ResizePoolIfNeeds();