From b5a12ec1c094a2757834f40db4799acc384e1efd Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 2 Jul 2024 00:59:26 +0200 Subject: [PATCH 1/8] Refactor client CLuaBlipDefs --- .../deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 409 +++++------------- .../deathmatch/logic/luadefs/CLuaBlipDefs.h | 31 +- 2 files changed, 120 insertions(+), 320 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index 7abffd1df0..6ced73115e 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -10,23 +10,25 @@ *****************************************************************************/ #include "StdInc.h" +#include "lua/CLuaFunctionParser.h" void CLuaBlipDefs::LoadFunctions() { constexpr static const std::pair functions[]{ - {"createBlip", CreateBlip}, - {"createBlipAttachedTo", CreateBlipAttachedTo}, - {"getBlipIcon", GetBlipIcon}, - {"getBlipSize", GetBlipSize}, - {"getBlipColor", GetBlipColor}, - {"getBlipOrdering", GetBlipOrdering}, - {"getBlipVisibleDistance", GetBlipVisibleDistance}, - - {"setBlipIcon", SetBlipIcon}, - {"setBlipSize", SetBlipSize}, - {"setBlipColor", SetBlipColor}, - {"setBlipOrdering", SetBlipOrdering}, - {"setBlipVisibleDistance", SetBlipVisibleDistance}, + {"createBlip", ArgumentParserWarn}, + {"createBlipAttachedTo", ArgumentParserWarn}, + + {"getBlipIcon", ArgumentParserWarn}, + {"getBlipSize", ArgumentParserWarn}, + {"getBlipColor", ArgumentParserWarn}, + {"getBlipOrdering", ArgumentParserWarn}, + {"getBlipVisibleDistance", ArgumentParserWarn}, + + {"setBlipIcon", ArgumentParserWarn}, + {"setBlipSize", ArgumentParserWarn}, + {"setBlipColor", ArgumentParserWarn}, + {"setBlipOrdering", ArgumentParserWarn}, + {"setBlipVisibleDistance", ArgumentParserWarn}, }; // Add functions @@ -57,358 +59,151 @@ void CLuaBlipDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "size", "setBlipSize", "getBlipSize"); lua_classvariable(luaVM, "ordering", "setBlipOrdering", "getBlipOrdering"); lua_classvariable(luaVM, "visibleDistance", "setBlipVisibleDistance", "getBlipVisibleDistance"); - // lua_classvariable ( luaVM, "color", "setBlipColor", "getBlipColor" ); + //lua_classvariable ( luaVM, "color", "setBlipColor", "getBlipColor" ); lua_registerclass(luaVM, "Blip", "Element"); } -int CLuaBlipDefs::CreateBlip(lua_State* luaVM) +std::variant CLuaBlipDefs::CreateBlip(lua_State* luaVM, CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) { - CVector vecPosition; - unsigned char ucIcon = 0; - int iSize = 2; - SColorRGBA color(255, 0, 0, 255); - int iOrdering = 0; - int iVisibleDistance = 16383; - CScriptArgReader argStream(luaVM); - argStream.ReadVector3D(vecPosition); - argStream.ReadNumber(ucIcon, 0); - argStream.ReadNumber(iSize, 2); - argStream.ReadNumber(color.R, 255); - argStream.ReadNumber(color.G, 0); - argStream.ReadNumber(color.B, 0); - argStream.ReadNumber(color.A, 255); - argStream.ReadNumber(iOrdering, 0); - argStream.ReadNumber(iVisibleDistance, 16383); - - if (!CClientRadarMarkerManager::IsValidIcon(ucIcon)) + if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) + throw std::invalid_argument("Invalid icon"); + + if (size.has_value() && (size.value() < 0 || size.value() > 25)) { - argStream.SetCustomError("Invalid icon"); + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); + size = Clamp(0ui8, size.value(), 25ui8); } - if (iSize < 0 || iSize > 25) - argStream.SetCustomWarning(SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", iSize)); + if (ordering.has_value()) + ordering = Clamp(0i32, ordering.value(), (std::int32_t)UINT16_MAX); + + if (visibleDistance.has_value()) + visibleDistance = Clamp(0ui32, visibleDistance.value(), (std::uint32_t)UINT16_MAX); - if (!argStream.HasErrors()) + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) { - CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (pLuaMain) - { - CResource* pResource = pLuaMain->GetResource(); - if (pResource) - { - unsigned char ucSize = Clamp(0, iSize, 25); - short sOrdering = Clamp(-32768, iOrdering, 32767); - unsigned short usVisibleDistance = Clamp(0, iVisibleDistance, 65535); - - // Create the blip - CClientRadarMarker* pMarker = - CStaticFunctionDefinitions::CreateBlip(*pResource, vecPosition, ucIcon, ucSize, color, sOrdering, usVisibleDistance); - if (pMarker) - { - CElementGroup* pGroup = pResource->GetElementGroup(); - if (pGroup) - { - pGroup->Add(pMarker); - } - - lua_pushelement(luaVM, pMarker); - return 1; - } - } - } + m_pScriptDebugging->LogError(luaVM, "Couldn't find the virtual machine"); + return false; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; -} -int CLuaBlipDefs::CreateBlipAttachedTo(lua_State* luaVM) -{ - CClientEntity* pEntity = NULL; - // Default colors and size - unsigned char ucIcon = 0; - int iSize = 2; - SColorRGBA color(255, 0, 0, 255); - int iOrdering = 0; - int iVisibleDistance = 16383; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(ucIcon, 0); - argStream.ReadNumber(iSize, 2); - argStream.ReadNumber(color.R, 255); - argStream.ReadNumber(color.G, 0); - argStream.ReadNumber(color.B, 0); - argStream.ReadNumber(color.A, 255); - argStream.ReadNumber(iOrdering, 0); - argStream.ReadNumber(iVisibleDistance, 16383); - - if (!CClientRadarMarkerManager::IsValidIcon(ucIcon)) + CResource* resource = luaMain->GetResource(); + if (!resource) { - argStream.SetCustomError("Invalid icon"); + m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); + return false; } - if (iSize < 0 || iSize > 25) - argStream.SetCustomWarning(SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", iSize)); + CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlip(*resource, vecPosition, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); + if (!radarMarker) + return false; - if (!argStream.HasErrors()) - { - CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (pLuaMain) - { - CResource* pResource = pLuaMain->GetResource(); - if (pResource) - { - unsigned char ucSize = Clamp(0, iSize, 25); - short sOrdering = Clamp(-32768, iOrdering, 32767); - unsigned short usVisibleDistance = Clamp(0, iVisibleDistance, 65535); - - // Create the blip - CClientRadarMarker* pMarker = - CStaticFunctionDefinitions::CreateBlipAttachedTo(*pResource, *pEntity, ucIcon, ucSize, color, sOrdering, usVisibleDistance); - if (pMarker) - { - CElementGroup* pGroup = pResource->GetElementGroup(); - if (pGroup) - { - pGroup->Add(pMarker); - } - lua_pushelement(luaVM, pMarker); - return 1; - } - } - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CElementGroup* elementGroup = resource->GetElementGroup(); + if (elementGroup) + elementGroup->Add(radarMarker); - lua_pushboolean(luaVM, false); - return 1; + return radarMarker; } -int CLuaBlipDefs::GetBlipIcon(lua_State* luaVM) +std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) { - CClientRadarMarker* pMarker = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pMarker); + if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) + throw std::invalid_argument("Invalid icon"); - if (!argStream.HasErrors()) + if (size.has_value() && (size.value() < 0 || size.value() > 25)) { - unsigned char ucIcon = static_cast(pMarker->GetSprite()); - lua_pushnumber(luaVM, ucIcon); - return 1; + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); + size = Clamp(0ui8, size.value(), 25ui8); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; -} + if (ordering.has_value()) + ordering = Clamp(0i32, ordering.value(), (std::int32_t)UINT16_MAX); -int CLuaBlipDefs::GetBlipSize(lua_State* luaVM) -{ - CClientRadarMarker* pMarker = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pMarker); + if (visibleDistance.has_value()) + visibleDistance = Clamp(0ui32, visibleDistance.value(), (std::uint32_t)UINT16_MAX); - if (!argStream.HasErrors()) + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) { - unsigned char ucSize = static_cast(pMarker->GetScale()); - lua_pushnumber(luaVM, ucSize); - return 1; + m_pScriptDebugging->LogError(luaVM, "Couldn't find the virtual machine"); + return false; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; -} - -int CLuaBlipDefs::GetBlipColor(lua_State* luaVM) -{ - CClientRadarMarker* pMarker = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pMarker); - - if (!argStream.HasErrors()) + CResource* resource = luaMain->GetResource(); + if (!resource) { - SColor color = pMarker->GetColor(); - lua_pushnumber(luaVM, color.R); - lua_pushnumber(luaVM, color.G); - lua_pushnumber(luaVM, color.B); - lua_pushnumber(luaVM, color.A); - return 4; + m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); + return false; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; -} -int CLuaBlipDefs::GetBlipOrdering(lua_State* luaVM) -{ - CClientRadarMarker* pMarker = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pMarker); + CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlipAttachedTo(*resource, *entity, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); + if (!radarMarker) + return false; - if (!argStream.HasErrors()) - { - short sOrdering = pMarker->GetOrdering(); - lua_pushnumber(luaVM, sOrdering); - return 1; - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CElementGroup* elementGroup = resource->GetElementGroup(); + if (elementGroup) + elementGroup->Add(radarMarker); - lua_pushboolean(luaVM, false); - return 1; + return radarMarker; } -int CLuaBlipDefs::GetBlipVisibleDistance(lua_State* luaVM) +std::uint8_t CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* radarMarker) noexcept { - CClientRadarMarker* pMarker = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pMarker); - - if (!argStream.HasErrors()) - { - unsigned short usVisibleDistance = pMarker->GetVisibleDistance(); - lua_pushnumber(luaVM, usVisibleDistance); - return 1; - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return std::uint8_t(radarMarker->GetSprite()); } -int CLuaBlipDefs::SetBlipIcon(lua_State* luaVM) +std::uint8_t CLuaBlipDefs::GetBlipSize(CClientRadarMarker* radarMarker) noexcept { - CClientEntity* pEntity = NULL; - unsigned char ucIcon = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(ucIcon); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetBlipIcon(*pEntity, ucIcon)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return radarMarker->GetScale(); } -int CLuaBlipDefs::SetBlipSize(lua_State* luaVM) +CLuaMultiReturn CLuaBlipDefs::GetBlipColor(CClientRadarMarker* radarMarker) noexcept { - CClientEntity* pEntity = NULL; - int iSize = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(iSize); - - if (iSize < 0 || iSize > 25) - argStream.SetCustomWarning(SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", iSize)); - - if (!argStream.HasErrors()) - { - unsigned char ucSize = Clamp(0, iSize, 25); + SColor color = radarMarker->GetColor(); + return {color.R, color.G, color.B, color.A}; +} - if (CStaticFunctionDefinitions::SetBlipSize(*pEntity, ucSize)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); +std::int16_t CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept +{ + return radarMarker->GetOrdering(); +} - lua_pushboolean(luaVM, false); - return 1; +std::uint16_t CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept +{ + return radarMarker->GetVisibleDistance(); } -int CLuaBlipDefs::SetBlipColor(lua_State* luaVM) +bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon) { - CClientEntity* pEntity = NULL; - SColor color; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(color.R); - argStream.ReadNumber(color.G); - argStream.ReadNumber(color.B); - argStream.ReadNumber(color.A); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetBlipColor(*pEntity, color)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (!CClientRadarMarkerManager::IsValidIcon(icon)) + throw std::invalid_argument("Invalid icon"); - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetBlipIcon(*radarMarker, icon); } -int CLuaBlipDefs::SetBlipOrdering(lua_State* luaVM) +bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept { - CClientEntity* pEntity = NULL; - int iOrdering; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(iOrdering); - - if (!argStream.HasErrors()) + if (size < 0 || size > 25) { - short sOrdering = Clamp(-32768, iOrdering, 32767); - - if (CStaticFunctionDefinitions::SetBlipOrdering(*pEntity, sOrdering)) - { - lua_pushboolean(luaVM, true); - return 1; - } + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size)); + size = Clamp(0ui8, size, 25ui8); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetBlipSize(*radarMarker, size); } -int CLuaBlipDefs::SetBlipVisibleDistance(lua_State* luaVM) +bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept { - CClientEntity* pEntity = NULL; - int iVisibleDistance; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(iVisibleDistance); - - if (!argStream.HasErrors()) - { - unsigned short usVisibleDistance = Clamp(0, iVisibleDistance, 65535); + return CStaticFunctionDefinitions::SetBlipColor(*radarMarker, SColorRGBA(r, g, b, a)); +} - if (CStaticFunctionDefinitions::SetBlipVisibleDistance(*pEntity, usVisibleDistance)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); +bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept +{ + return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(0i32, ordering, (std::int32_t)UINT16_MAX)); +} - lua_pushboolean(luaVM, false); - return 1; +bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept +{ + return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(0ui32, visibleDistance, (std::uint32_t)UINT16_MAX)); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h index 45c62397bb..ef64180e7c 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h @@ -11,6 +11,7 @@ #pragma once #include "CLuaDefs.h" +#include class CLuaBlipDefs : public CLuaDefs { @@ -18,17 +19,21 @@ class CLuaBlipDefs : public CLuaDefs static void LoadFunctions(); static void AddClass(lua_State* luaVM); - LUA_DECLARE(CreateBlip); - LUA_DECLARE(CreateBlipAttachedTo); - LUA_DECLARE(GetBlipIcon); - LUA_DECLARE(GetBlipSize); - LUA_DECLARE(GetBlipColor); - LUA_DECLARE(GetBlipOrdering); - LUA_DECLARE(GetBlipVisibleDistance); + // Create functions + static std::variant CreateBlip(lua_State* luaVM, CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); + static std::variant CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); - LUA_DECLARE(SetBlipIcon); - LUA_DECLARE(SetBlipSize); - LUA_DECLARE(SetBlipColor); - LUA_DECLARE(SetBlipOrdering); - LUA_DECLARE(SetBlipVisibleDistance); -}; \ No newline at end of file + // Get functions + static std::uint8_t GetBlipIcon(CClientRadarMarker* radarMarker) noexcept; + static std::uint8_t GetBlipSize(CClientRadarMarker* radarMarker) noexcept; + static CLuaMultiReturn GetBlipColor(CClientRadarMarker* radarMarker) noexcept; + static std::int16_t GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept; + static std::uint16_t GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept; + + // Set functions + static bool SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon); + static bool SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept; + static bool SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept; + static bool SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept; + static bool SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept; +}; From 4694e2cbb48a047ad76b9642051e59f6640432c0 Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 2 Jul 2024 01:32:16 +0200 Subject: [PATCH 2/8] Comments --- Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index 6ced73115e..ef0dde1eb1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -15,15 +15,18 @@ void CLuaBlipDefs::LoadFunctions() { constexpr static const std::pair functions[]{ + // Create functions {"createBlip", ArgumentParserWarn}, {"createBlipAttachedTo", ArgumentParserWarn}, + // Get functions {"getBlipIcon", ArgumentParserWarn}, {"getBlipSize", ArgumentParserWarn}, {"getBlipColor", ArgumentParserWarn}, {"getBlipOrdering", ArgumentParserWarn}, {"getBlipVisibleDistance", ArgumentParserWarn}, + // Set functions {"setBlipIcon", ArgumentParserWarn}, {"setBlipSize", ArgumentParserWarn}, {"setBlipColor", ArgumentParserWarn}, @@ -59,7 +62,7 @@ void CLuaBlipDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "size", "setBlipSize", "getBlipSize"); lua_classvariable(luaVM, "ordering", "setBlipOrdering", "getBlipOrdering"); lua_classvariable(luaVM, "visibleDistance", "setBlipVisibleDistance", "getBlipVisibleDistance"); - //lua_classvariable ( luaVM, "color", "setBlipColor", "getBlipColor" ); + // lua_classvariable ( luaVM, "color", "setBlipColor", "getBlipColor" ); lua_registerclass(luaVM, "Blip", "Element"); } From 47d105738966accf0ba195c856fb2c399bbe99b4 Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 2 Jul 2024 16:39:30 +0200 Subject: [PATCH 3/8] std::numeric_limits --- .../mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index ef0dde1eb1..1c954ccbd3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -79,10 +79,10 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* luaV } if (ordering.has_value()) - ordering = Clamp(0i32, ordering.value(), (std::int32_t)UINT16_MAX); + ordering = Clamp(std::numeric_limits().min(), (std::int16_t)ordering.value(), std::numeric_limits().max()); if (visibleDistance.has_value()) - visibleDistance = Clamp(0ui32, visibleDistance.value(), (std::uint32_t)UINT16_MAX); + visibleDistance = Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance.value(), std::numeric_limits().max()); CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) @@ -121,10 +121,10 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S } if (ordering.has_value()) - ordering = Clamp(0i32, ordering.value(), (std::int32_t)UINT16_MAX); + ordering = Clamp(std::numeric_limits().min(), (std::int16_t)ordering.value(), std::numeric_limits().max()); if (visibleDistance.has_value()) - visibleDistance = Clamp(0ui32, visibleDistance.value(), (std::uint32_t)UINT16_MAX); + visibleDistance = Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance.value(), std::numeric_limits().max()); CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) @@ -203,10 +203,10 @@ bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept { - return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(0i32, ordering, (std::int32_t)UINT16_MAX)); + return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(std::numeric_limits().min(), (std::int16_t)ordering, std::numeric_limits().max())); } bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept { - return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(0ui32, visibleDistance, (std::uint32_t)UINT16_MAX)); + return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance, std::numeric_limits().max())); } From ef97e9ba93d0dfd4efdb605efa2b449cdb9813b2 Mon Sep 17 00:00:00 2001 From: FileEX Date: Thu, 15 Aug 2024 15:29:23 +0200 Subject: [PATCH 4/8] Changes --- .../deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index 1c954ccbd3..8ec0c930ba 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -75,14 +75,14 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* luaV if (size.has_value() && (size.value() < 0 || size.value() > 25)) { m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); - size = Clamp(0ui8, size.value(), 25ui8); + size = Clamp(0, size.value(), 25); } if (ordering.has_value()) - ordering = Clamp(std::numeric_limits().min(), (std::int16_t)ordering.value(), std::numeric_limits().max()); + ordering = Clamp(std::numeric_limits().min(), ordering.value(), std::numeric_limits().max()); if (visibleDistance.has_value()) - visibleDistance = Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance.value(), std::numeric_limits().max()); + visibleDistance = Clamp(std::numeric_limits().min(), visibleDistance.value(), std::numeric_limits().max()); CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) @@ -117,14 +117,14 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S if (size.has_value() && (size.value() < 0 || size.value() > 25)) { m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); - size = Clamp(0ui8, size.value(), 25ui8); + size = Clamp(0, size.value(), 25); } if (ordering.has_value()) - ordering = Clamp(std::numeric_limits().min(), (std::int16_t)ordering.value(), std::numeric_limits().max()); + ordering = Clamp(std::numeric_limits().min(), ordering.value(), std::numeric_limits().max()); if (visibleDistance.has_value()) - visibleDistance = Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance.value(), std::numeric_limits().max()); + visibleDistance = Clamp(std::numeric_limits().min(), visibleDistance.value(), std::numeric_limits().max()); CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) @@ -153,12 +153,12 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S std::uint8_t CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* radarMarker) noexcept { - return std::uint8_t(radarMarker->GetSprite()); + return static_cast(radarMarker->GetSprite()); } std::uint8_t CLuaBlipDefs::GetBlipSize(CClientRadarMarker* radarMarker) noexcept { - return radarMarker->GetScale(); + return static_cast(radarMarker->GetScale()); } CLuaMultiReturn CLuaBlipDefs::GetBlipColor(CClientRadarMarker* radarMarker) noexcept @@ -169,12 +169,12 @@ CLuaMultiReturn CLuaBlip std::int16_t CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept { - return radarMarker->GetOrdering(); + return static_cast(radarMarker->GetOrdering()); } std::uint16_t CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept { - return radarMarker->GetVisibleDistance(); + return static_cast(radarMarker->GetVisibleDistance()); } bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon) @@ -190,7 +190,7 @@ bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker if (size < 0 || size > 25) { m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size)); - size = Clamp(0ui8, size, 25ui8); + size = Clamp(0, size, 25); } return CStaticFunctionDefinitions::SetBlipSize(*radarMarker, size); @@ -203,10 +203,10 @@ bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept { - return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(std::numeric_limits().min(), (std::int16_t)ordering, std::numeric_limits().max())); + return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(std::numeric_limits().min(), ordering, std::numeric_limits().max())); } bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept { - return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(std::numeric_limits().min(), (std::uint16_t)visibleDistance, std::numeric_limits().max())); + return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(std::numeric_limits().min(), visibleDistance, std::numeric_limits().max())); } From d6787f1c1eb416a5ad1beab3a82421c8e3342503 Mon Sep 17 00:00:00 2001 From: FileEX Date: Thu, 15 Aug 2024 16:59:47 +0200 Subject: [PATCH 5/8] Update --- .../deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 78 +++++++------------ .../deathmatch/logic/luadefs/CLuaBlipDefs.h | 24 +++--- 2 files changed, 39 insertions(+), 63 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index 8ec0c930ba..039037a057 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -12,6 +12,8 @@ #include "StdInc.h" #include "lua/CLuaFunctionParser.h" +constexpr std::uint8_t MAX_BLIP_SIZE = 25; + void CLuaBlipDefs::LoadFunctions() { constexpr static const std::pair functions[]{ @@ -67,31 +69,18 @@ void CLuaBlipDefs::AddClass(lua_State* luaVM) lua_registerclass(luaVM, "Blip", "Element"); } -std::variant CLuaBlipDefs::CreateBlip(lua_State* luaVM, CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) +std::variant CLuaBlipDefs::CreateBlip(lua_State* const luaVM, const CVector vecPosition, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance) { if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) throw std::invalid_argument("Invalid icon"); - if (size.has_value() && (size.value() < 0 || size.value() > 25)) + if (size.has_value() && size.value() > MAX_BLIP_SIZE) { - m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); - size = Clamp(0, size.value(), 25); - } - - if (ordering.has_value()) - ordering = Clamp(std::numeric_limits().min(), ordering.value(), std::numeric_limits().max()); - - if (visibleDistance.has_value()) - visibleDistance = Clamp(std::numeric_limits().min(), visibleDistance.value(), std::numeric_limits().max()); - - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (!luaMain) - { - m_pScriptDebugging->LogError(luaVM, "Couldn't find the virtual machine"); - return false; + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond %i is no longer supported (got %i). It will be clamped between 0 and %i.", MAX_BLIP_SIZE, size.value(), MAX_BLIP_SIZE)); + size = MAX_BLIP_SIZE; } - CResource* resource = luaMain->GetResource(); + CResource* resource = &lua_getownerresource(luaVM); if (!resource) { m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); @@ -109,31 +98,18 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* luaV return radarMarker; } -std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) +std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_State* const luaVM, CClientEntity* const entity, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance) { if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) throw std::invalid_argument("Invalid icon"); - if (size.has_value() && (size.value() < 0 || size.value() > 25)) + if (size.has_value() && size.value() > MAX_BLIP_SIZE) { - m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size.value())); - size = Clamp(0, size.value(), 25); - } - - if (ordering.has_value()) - ordering = Clamp(std::numeric_limits().min(), ordering.value(), std::numeric_limits().max()); - - if (visibleDistance.has_value()) - visibleDistance = Clamp(std::numeric_limits().min(), visibleDistance.value(), std::numeric_limits().max()); - - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (!luaMain) - { - m_pScriptDebugging->LogError(luaVM, "Couldn't find the virtual machine"); - return false; + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond %i is no longer supported (got %i). It will be clamped between 0 and %i.", MAX_BLIP_SIZE, size.value(), MAX_BLIP_SIZE)); + size = MAX_BLIP_SIZE; } - CResource* resource = luaMain->GetResource(); + CResource* resource = &lua_getownerresource(luaVM); if (!resource) { m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); @@ -151,33 +127,33 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S return radarMarker; } -std::uint8_t CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* radarMarker) noexcept +std::uint8_t CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* const radarMarker) noexcept { return static_cast(radarMarker->GetSprite()); } -std::uint8_t CLuaBlipDefs::GetBlipSize(CClientRadarMarker* radarMarker) noexcept +std::uint8_t CLuaBlipDefs::GetBlipSize(CClientRadarMarker* const radarMarker) noexcept { return static_cast(radarMarker->GetScale()); } -CLuaMultiReturn CLuaBlipDefs::GetBlipColor(CClientRadarMarker* radarMarker) noexcept +CLuaMultiReturn CLuaBlipDefs::GetBlipColor(CClientRadarMarker* const radarMarker) noexcept { SColor color = radarMarker->GetColor(); return {color.R, color.G, color.B, color.A}; } -std::int16_t CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept +std::int16_t CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* const radarMarker) noexcept { return static_cast(radarMarker->GetOrdering()); } -std::uint16_t CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept +std::uint16_t CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* const radarMarker) noexcept { return static_cast(radarMarker->GetVisibleDistance()); } -bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon) +bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* const radarMarker, const std::uint8_t icon) { if (!CClientRadarMarkerManager::IsValidIcon(icon)) throw std::invalid_argument("Invalid icon"); @@ -185,28 +161,28 @@ bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t ico return CStaticFunctionDefinitions::SetBlipIcon(*radarMarker, icon); } -bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept +bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* const radarMarker, std::uint8_t size) noexcept { - if (size < 0 || size > 25) + if (size > MAX_BLIP_SIZE) { - m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond 25 is no longer supported (got %i). It will be clamped between 0 and 25.", size)); - size = Clamp(0, size, 25); + m_pScriptDebugging->LogWarning(luaVM, SString("Blip size beyond %i is no longer supported (got %i). It will be clamped between 0 and %i.", MAX_BLIP_SIZE, size, MAX_BLIP_SIZE)); + size = MAX_BLIP_SIZE; } return CStaticFunctionDefinitions::SetBlipSize(*radarMarker, size); } -bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept +bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* const radarMarker, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a) noexcept { return CStaticFunctionDefinitions::SetBlipColor(*radarMarker, SColorRGBA(r, g, b, a)); } -bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept +bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* const radarMarker, const std::int16_t ordering) noexcept { - return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, Clamp(std::numeric_limits().min(), ordering, std::numeric_limits().max())); + return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, ordering); } -bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept +bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* const radarMarker, const std::uint16_t visibleDistance) noexcept { - return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, Clamp(std::numeric_limits().min(), visibleDistance, std::numeric_limits().max())); + return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, visibleDistance); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h index ef64180e7c..f4914983fe 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h @@ -20,20 +20,20 @@ class CLuaBlipDefs : public CLuaDefs static void AddClass(lua_State* luaVM); // Create functions - static std::variant CreateBlip(lua_State* luaVM, CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); - static std::variant CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); + static std::variant CreateBlip(lua_State* const luaVM, const CVector vecPosition, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance); + static std::variant CreateBlipAttachedTo(lua_State* const luaVM, CClientEntity* const entity, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance); // Get functions - static std::uint8_t GetBlipIcon(CClientRadarMarker* radarMarker) noexcept; - static std::uint8_t GetBlipSize(CClientRadarMarker* radarMarker) noexcept; - static CLuaMultiReturn GetBlipColor(CClientRadarMarker* radarMarker) noexcept; - static std::int16_t GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept; - static std::uint16_t GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept; + static std::uint8_t GetBlipIcon(CClientRadarMarker* const radarMarker) noexcept; + static std::uint8_t GetBlipSize(CClientRadarMarker* const radarMarker) noexcept; + static CLuaMultiReturn GetBlipColor(CClientRadarMarker* const radarMarker) noexcept; + static std::int16_t GetBlipOrdering(CClientRadarMarker* const radarMarker) noexcept; + static std::uint16_t GetBlipVisibleDistance(CClientRadarMarker* const radarMarker) noexcept; // Set functions - static bool SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon); - static bool SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept; - static bool SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept; - static bool SetBlipOrdering(CClientRadarMarker* radarMarker, std::int32_t ordering) noexcept; - static bool SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint32_t visibleDistance) noexcept; + static bool SetBlipIcon(CClientRadarMarker* const radarMarker, const std::uint8_t icon); + static bool SetBlipSize(lua_State* const luaVM, CClientRadarMarker* const radarMarker, std::uint8_t size) noexcept; + static bool SetBlipColor(CClientRadarMarker* const radarMarker, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a) noexcept; + static bool SetBlipOrdering(CClientRadarMarker* const radarMarker, const std::int16_t ordering) noexcept; + static bool SetBlipVisibleDistance(CClientRadarMarker* const radarMarker, const std::uint16_t visibleDistance) noexcept; }; From 0f508e1f45c33af34c87b1effb88f1180fc3c7e3 Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 13 Sep 2024 13:23:37 +0200 Subject: [PATCH 6/8] Clean up --- .../deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 155 +++++++++--------- .../deathmatch/logic/luadefs/CLuaBlipDefs.h | 26 +-- 2 files changed, 88 insertions(+), 93 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index 039037a057..e228e52b6c 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -12,64 +12,9 @@ #include "StdInc.h" #include "lua/CLuaFunctionParser.h" -constexpr std::uint8_t MAX_BLIP_SIZE = 25; +static constexpr std::uint8_t MAX_BLIP_SIZE = 25; -void CLuaBlipDefs::LoadFunctions() -{ - constexpr static const std::pair functions[]{ - // Create functions - {"createBlip", ArgumentParserWarn}, - {"createBlipAttachedTo", ArgumentParserWarn}, - - // Get functions - {"getBlipIcon", ArgumentParserWarn}, - {"getBlipSize", ArgumentParserWarn}, - {"getBlipColor", ArgumentParserWarn}, - {"getBlipOrdering", ArgumentParserWarn}, - {"getBlipVisibleDistance", ArgumentParserWarn}, - - // Set functions - {"setBlipIcon", ArgumentParserWarn}, - {"setBlipSize", ArgumentParserWarn}, - {"setBlipColor", ArgumentParserWarn}, - {"setBlipOrdering", ArgumentParserWarn}, - {"setBlipVisibleDistance", ArgumentParserWarn}, - }; - - // Add functions - for (const auto& [name, func] : functions) - CLuaCFunctions::AddFunction(name, func); -} - -void CLuaBlipDefs::AddClass(lua_State* luaVM) -{ - lua_newclass(luaVM); - - lua_classfunction(luaVM, "create", "createBlip"); - lua_classfunction(luaVM, "createAttachedTo", "createBlipAttachedTo"); - - lua_classfunction(luaVM, "getColor", "getBlipColor"); - lua_classfunction(luaVM, "getVisibleDistance", "getBlipVisibleDistance"); - lua_classfunction(luaVM, "getOrdering", "getBlipOrdering"); - lua_classfunction(luaVM, "getSize", "getBlipSize"); - lua_classfunction(luaVM, "getIcon", "getBlipIcon"); - - lua_classfunction(luaVM, "setColor", "setBlipColor"); - lua_classfunction(luaVM, "setVisibleDistance", "setBlipVisibleDistance"); - lua_classfunction(luaVM, "setOrdering", "setBlipOrdering"); - lua_classfunction(luaVM, "setSize", "setBlipSize"); - lua_classfunction(luaVM, "setIcon", "setBlipIcon"); - - lua_classvariable(luaVM, "icon", "setBlipIcon", "getBlipIcon"); - lua_classvariable(luaVM, "size", "setBlipSize", "getBlipSize"); - lua_classvariable(luaVM, "ordering", "setBlipOrdering", "getBlipOrdering"); - lua_classvariable(luaVM, "visibleDistance", "setBlipVisibleDistance", "getBlipVisibleDistance"); - // lua_classvariable ( luaVM, "color", "setBlipColor", "getBlipColor" ); - - lua_registerclass(luaVM, "Blip", "Element"); -} - -std::variant CLuaBlipDefs::CreateBlip(lua_State* const luaVM, const CVector vecPosition, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance) +std::variant CLuaBlipDefs::CreateBlip(lua_State* luaVM, const CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) { if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) throw std::invalid_argument("Invalid icon"); @@ -82,10 +27,7 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* cons CResource* resource = &lua_getownerresource(luaVM); if (!resource) - { - m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); - return false; - } + throw LuaFunctionError("Couldn't find the resource element. Please restart the resource and try again", false); CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlip(*resource, vecPosition, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); if (!radarMarker) @@ -98,7 +40,7 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* cons return radarMarker; } -std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_State* const luaVM, CClientEntity* const entity, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance) +std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance) { if (icon.has_value() && !CClientRadarMarkerManager::IsValidIcon(icon.value())) throw std::invalid_argument("Invalid icon"); @@ -111,10 +53,7 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S CResource* resource = &lua_getownerresource(luaVM); if (!resource) - { - m_pScriptDebugging->LogError(luaVM, "Couldn't find the resource element"); - return false; - } + throw LuaFunctionError("Couldn't find the resource element. Please restart the resource and try again", false); CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlipAttachedTo(*resource, *entity, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); if (!radarMarker) @@ -127,33 +66,33 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S return radarMarker; } -std::uint8_t CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* const radarMarker) noexcept +auto CLuaBlipDefs::GetBlipIcon(CClientRadarMarker* const radarMarker) noexcept { return static_cast(radarMarker->GetSprite()); } -std::uint8_t CLuaBlipDefs::GetBlipSize(CClientRadarMarker* const radarMarker) noexcept +auto CLuaBlipDefs::GetBlipSize(CClientRadarMarker* const radarMarker) noexcept { - return static_cast(radarMarker->GetScale()); + return radarMarker->GetScale(); } -CLuaMultiReturn CLuaBlipDefs::GetBlipColor(CClientRadarMarker* const radarMarker) noexcept +auto CLuaBlipDefs::GetBlipColor(CClientRadarMarker* radarMarker) noexcept { SColor color = radarMarker->GetColor(); - return {color.R, color.G, color.B, color.A}; + return std::make_tuple(color.R, color.G, color.B, color.A); } -std::int16_t CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* const radarMarker) noexcept +auto CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept { - return static_cast(radarMarker->GetOrdering()); + return radarMarker->GetOrdering(); } -std::uint16_t CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* const radarMarker) noexcept +auto CLuaBlipDefs::GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept { - return static_cast(radarMarker->GetVisibleDistance()); + return radarMarker->GetVisibleDistance(); } -bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* const radarMarker, const std::uint8_t icon) +bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon) { if (!CClientRadarMarkerManager::IsValidIcon(icon)) throw std::invalid_argument("Invalid icon"); @@ -161,7 +100,7 @@ bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* const radarMarker, const std: return CStaticFunctionDefinitions::SetBlipIcon(*radarMarker, icon); } -bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* const radarMarker, std::uint8_t size) noexcept +bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept { if (size > MAX_BLIP_SIZE) { @@ -172,17 +111,73 @@ bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* const radar return CStaticFunctionDefinitions::SetBlipSize(*radarMarker, size); } -bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* const radarMarker, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a) noexcept +bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept { return CStaticFunctionDefinitions::SetBlipColor(*radarMarker, SColorRGBA(r, g, b, a)); } -bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* const radarMarker, const std::int16_t ordering) noexcept +bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering) noexcept { return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, ordering); } -bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* const radarMarker, const std::uint16_t visibleDistance) noexcept +bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance) noexcept { return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, visibleDistance); } + + +void CLuaBlipDefs::LoadFunctions() +{ + constexpr static const std::pair functions[]{ + // Create functions + {"createBlip", ArgumentParserWarn}, + {"createBlipAttachedTo", ArgumentParserWarn}, + + // Get functions + {"getBlipIcon", ArgumentParserWarn}, + {"getBlipSize", ArgumentParserWarn}, + {"getBlipColor", ArgumentParserWarn}, + {"getBlipOrdering", ArgumentParserWarn}, + {"getBlipVisibleDistance", ArgumentParserWarn}, + + // Set functions + {"setBlipIcon", ArgumentParserWarn}, + {"setBlipSize", ArgumentParserWarn}, + {"setBlipColor", ArgumentParserWarn}, + {"setBlipOrdering", ArgumentParserWarn}, + {"setBlipVisibleDistance", ArgumentParserWarn}, + }; + + // Add functions + for (const auto& [name, func] : functions) + CLuaCFunctions::AddFunction(name, func); +} + +void CLuaBlipDefs::AddClass(lua_State* luaVM) +{ + lua_newclass(luaVM); + + lua_classfunction(luaVM, "create", "createBlip"); + lua_classfunction(luaVM, "createAttachedTo", "createBlipAttachedTo"); + + lua_classfunction(luaVM, "getColor", "getBlipColor"); + lua_classfunction(luaVM, "getVisibleDistance", "getBlipVisibleDistance"); + lua_classfunction(luaVM, "getOrdering", "getBlipOrdering"); + lua_classfunction(luaVM, "getSize", "getBlipSize"); + lua_classfunction(luaVM, "getIcon", "getBlipIcon"); + + lua_classfunction(luaVM, "setColor", "setBlipColor"); + lua_classfunction(luaVM, "setVisibleDistance", "setBlipVisibleDistance"); + lua_classfunction(luaVM, "setOrdering", "setBlipOrdering"); + lua_classfunction(luaVM, "setSize", "setBlipSize"); + lua_classfunction(luaVM, "setIcon", "setBlipIcon"); + + lua_classvariable(luaVM, "icon", "setBlipIcon", "getBlipIcon"); + lua_classvariable(luaVM, "size", "setBlipSize", "getBlipSize"); + lua_classvariable(luaVM, "ordering", "setBlipOrdering", "getBlipOrdering"); + lua_classvariable(luaVM, "visibleDistance", "setBlipVisibleDistance", "getBlipVisibleDistance"); + // TODO add oop color variable + + lua_registerclass(luaVM, "Blip", "Element"); +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h index f4914983fe..d1680b7634 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h @@ -11,7 +11,6 @@ #pragma once #include "CLuaDefs.h" -#include class CLuaBlipDefs : public CLuaDefs { @@ -19,21 +18,22 @@ class CLuaBlipDefs : public CLuaDefs static void LoadFunctions(); static void AddClass(lua_State* luaVM); +private: // Create functions - static std::variant CreateBlip(lua_State* const luaVM, const CVector vecPosition, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance); - static std::variant CreateBlipAttachedTo(lua_State* const luaVM, CClientEntity* const entity, const std::optional icon, std::optional size, const std::optional r, const std::optional g, const std::optional b, const std::optional a, const std::optional ordering, const std::optional visibleDistance); + static std::variant CreateBlip(lua_State* luaVM, const CVector vecPosition, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); + static std::variant CreateBlipAttachedTo(lua_State* luaVM, CClientEntity* entity, std::optional icon, std::optional size, std::optional r, std::optional g, std::optional b, std::optional a, std::optional ordering, std::optional visibleDistance); // Get functions - static std::uint8_t GetBlipIcon(CClientRadarMarker* const radarMarker) noexcept; - static std::uint8_t GetBlipSize(CClientRadarMarker* const radarMarker) noexcept; - static CLuaMultiReturn GetBlipColor(CClientRadarMarker* const radarMarker) noexcept; - static std::int16_t GetBlipOrdering(CClientRadarMarker* const radarMarker) noexcept; - static std::uint16_t GetBlipVisibleDistance(CClientRadarMarker* const radarMarker) noexcept; + static auto GetBlipIcon(CClientRadarMarker* radarMarker) noexcept; + static auto GetBlipSize(CClientRadarMarker* radarMarker) noexcept; + static auto GetBlipColor(CClientRadarMarker* radarMarker) noexcept; + static auto GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept; + static auto GetBlipVisibleDistance(CClientRadarMarker* radarMarker) noexcept; // Set functions - static bool SetBlipIcon(CClientRadarMarker* const radarMarker, const std::uint8_t icon); - static bool SetBlipSize(lua_State* const luaVM, CClientRadarMarker* const radarMarker, std::uint8_t size) noexcept; - static bool SetBlipColor(CClientRadarMarker* const radarMarker, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a) noexcept; - static bool SetBlipOrdering(CClientRadarMarker* const radarMarker, const std::int16_t ordering) noexcept; - static bool SetBlipVisibleDistance(CClientRadarMarker* const radarMarker, const std::uint16_t visibleDistance) noexcept; + static bool SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon); + static bool SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept; + static bool SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept; + static bool SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering) noexcept; + static bool SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance) noexcept; }; From 7d4475ff449417853cdfbb920283e4810674e97b Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 10 Jan 2025 18:36:37 +0100 Subject: [PATCH 7/8] Review --- .../deathmatch/logic/CClientRadarMarker.h | 10 ++++---- .../logic/CClientRadarMarkerManager.h | 2 +- .../deathmatch/logic/luadefs/CLuaBlipDefs.cpp | 23 ++++++++----------- .../deathmatch/logic/luadefs/CLuaBlipDefs.h | 8 +++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientRadarMarker.h b/Client/mods/deathmatch/logic/CClientRadarMarker.h index 0963d229db..b687622321 100644 --- a/Client/mods/deathmatch/logic/CClientRadarMarker.h +++ b/Client/mods/deathmatch/logic/CClientRadarMarker.h @@ -39,13 +39,13 @@ class CClientRadarMarker final : public CClientEntity void SetPosition(const CVector& vecPosition); void GetPosition(CVector& vecPosition) const; - unsigned short GetScale() { return m_usScale; }; + unsigned short GetScale() const noexcept { return m_usScale; }; void SetScale(unsigned short usScale); - SColor GetColor() const { return m_Color; } + SColor GetColor() const noexcept { return m_Color; } void SetColor(const SColor color); - unsigned long GetSprite() const { return m_ulSprite; }; + unsigned long GetSprite() const noexcept { return m_ulSprite; }; void SetSprite(unsigned long ulSprite); bool IsVisible() const { return m_bIsVisible; }; @@ -54,10 +54,10 @@ class CClientRadarMarker final : public CClientEntity void SetDimension(unsigned short usDimension) override; void RelateDimension(unsigned short usDimension); - short GetOrdering() { return m_sOrdering; } + short GetOrdering() const noexcept { return m_sOrdering; } void SetOrdering(short sOrdering); - unsigned short GetVisibleDistance() { return m_usVisibleDistance; } + unsigned short GetVisibleDistance() const noexcept { return m_usVisibleDistance; } void SetVisibleDistance(unsigned short usVisibleDistance) { m_usVisibleDistance = usVisibleDistance; } bool IsInVisibleDistance(); diff --git a/Client/mods/deathmatch/logic/CClientRadarMarkerManager.h b/Client/mods/deathmatch/logic/CClientRadarMarkerManager.h index 0fa2a303da..8fd0450ca2 100644 --- a/Client/mods/deathmatch/logic/CClientRadarMarkerManager.h +++ b/Client/mods/deathmatch/logic/CClientRadarMarkerManager.h @@ -36,7 +36,7 @@ class CClientRadarMarkerManager std::list::const_iterator IterEnd() { return m_Markers.end(); }; bool Exists(CClientRadarMarker* pMarker); - static bool IsValidIcon(unsigned long ulIcon) { return ulIcon <= RADAR_MARKER_LIMIT; } + static bool IsValidIcon(unsigned long ulIcon) noexcept { return ulIcon <= RADAR_MARKER_LIMIT; } private: void AddToList(CClientRadarMarker* pMarker) { m_Markers.push_back(pMarker); }; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp index e228e52b6c..5eaaadca23 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.cpp @@ -27,14 +27,13 @@ std::variant CLuaBlipDefs::CreateBlip(lua_State* luaV CResource* resource = &lua_getownerresource(luaVM); if (!resource) - throw LuaFunctionError("Couldn't find the resource element. Please restart the resource and try again", false); + return false; CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlip(*resource, vecPosition, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); if (!radarMarker) return false; - CElementGroup* elementGroup = resource->GetElementGroup(); - if (elementGroup) + if (CElementGroup* elementGroup = resource->GetElementGroup()) elementGroup->Add(radarMarker); return radarMarker; @@ -53,14 +52,13 @@ std::variant CLuaBlipDefs::CreateBlipAttachedTo(lua_S CResource* resource = &lua_getownerresource(luaVM); if (!resource) - throw LuaFunctionError("Couldn't find the resource element. Please restart the resource and try again", false); + return false; CClientRadarMarker* radarMarker = CStaticFunctionDefinitions::CreateBlipAttachedTo(*resource, *entity, icon.value_or(0), size.value_or(2), SColorRGBA(r.value_or(255), g.value_or(0), b.value_or(0), a.value_or(255)), ordering.value_or(0), visibleDistance.value_or(16383)); if (!radarMarker) return false; - - CElementGroup* elementGroup = resource->GetElementGroup(); - if (elementGroup) + + if (CElementGroup* elementGroup = resource->GetElementGroup()) elementGroup->Add(radarMarker); return radarMarker; @@ -79,7 +77,7 @@ auto CLuaBlipDefs::GetBlipSize(CClientRadarMarker* const radarMarker) noexcept auto CLuaBlipDefs::GetBlipColor(CClientRadarMarker* radarMarker) noexcept { SColor color = radarMarker->GetColor(); - return std::make_tuple(color.R, color.G, color.B, color.A); + return CLuaMultiReturn{color.R, color.G, color.B, color.A}; } auto CLuaBlipDefs::GetBlipOrdering(CClientRadarMarker* radarMarker) noexcept @@ -100,7 +98,7 @@ bool CLuaBlipDefs::SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t ico return CStaticFunctionDefinitions::SetBlipIcon(*radarMarker, icon); } -bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept +bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) { if (size > MAX_BLIP_SIZE) { @@ -111,22 +109,21 @@ bool CLuaBlipDefs::SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker return CStaticFunctionDefinitions::SetBlipSize(*radarMarker, size); } -bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept +bool CLuaBlipDefs::SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) { return CStaticFunctionDefinitions::SetBlipColor(*radarMarker, SColorRGBA(r, g, b, a)); } -bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering) noexcept +bool CLuaBlipDefs::SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering) { return CStaticFunctionDefinitions::SetBlipOrdering(*radarMarker, ordering); } -bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance) noexcept +bool CLuaBlipDefs::SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance) { return CStaticFunctionDefinitions::SetBlipVisibleDistance(*radarMarker, visibleDistance); } - void CLuaBlipDefs::LoadFunctions() { constexpr static const std::pair functions[]{ diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h index d1680b7634..a82a218c9b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBlipDefs.h @@ -32,8 +32,8 @@ class CLuaBlipDefs : public CLuaDefs // Set functions static bool SetBlipIcon(CClientRadarMarker* radarMarker, std::uint8_t icon); - static bool SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size) noexcept; - static bool SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept; - static bool SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering) noexcept; - static bool SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance) noexcept; + static bool SetBlipSize(lua_State* luaVM, CClientRadarMarker* radarMarker, std::uint8_t size); + static bool SetBlipColor(CClientRadarMarker* radarMarker, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a); + static bool SetBlipOrdering(CClientRadarMarker* radarMarker, std::int16_t ordering); + static bool SetBlipVisibleDistance(CClientRadarMarker* radarMarker, std::uint16_t visibleDistance); }; From c2e177454354d14883c33e6850336f75f470c590 Mon Sep 17 00:00:00 2001 From: Marek Kulik Date: Fri, 10 Jan 2025 21:33:19 +0100 Subject: [PATCH 8/8] Apply suggestions from code review --- Client/mods/deathmatch/logic/CClientRadarMarker.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientRadarMarker.h b/Client/mods/deathmatch/logic/CClientRadarMarker.h index b687622321..c2709e00ee 100644 --- a/Client/mods/deathmatch/logic/CClientRadarMarker.h +++ b/Client/mods/deathmatch/logic/CClientRadarMarker.h @@ -39,13 +39,13 @@ class CClientRadarMarker final : public CClientEntity void SetPosition(const CVector& vecPosition); void GetPosition(CVector& vecPosition) const; - unsigned short GetScale() const noexcept { return m_usScale; }; + unsigned short GetScale() const noexcept { return m_usScale; } void SetScale(unsigned short usScale); SColor GetColor() const noexcept { return m_Color; } void SetColor(const SColor color); - unsigned long GetSprite() const noexcept { return m_ulSprite; }; + unsigned long GetSprite() const noexcept { return m_ulSprite; } void SetSprite(unsigned long ulSprite); bool IsVisible() const { return m_bIsVisible; };