From 518a76a86992696db17fe154c7279c85272512c6 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Thu, 4 Sep 2025 21:12:13 +0200 Subject: [PATCH 01/11] Add ElunaMgr In the future this will be used to decouple Eluna object 1:1 with maps, allowing multiple states per map --- ElunaMgr.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ElunaMgr.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 ElunaMgr.cpp create mode 100644 ElunaMgr.h diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp new file mode 100644 index 0000000000..9d056b1b48 --- /dev/null +++ b/ElunaMgr.cpp @@ -0,0 +1,59 @@ +/* +* Copyright (C) 2010 - 2025 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#include "ElunaMgr.h" + +ElunaMgr::ElunaMgr() +{ +} + +ElunaMgr* ElunaMgr::instance() +{ + static ElunaMgr instance; + return &instance; +} + +ElunaMgr::~ElunaMgr() +{ +} + +void ElunaMgr::Create(Map* map, ElunaInfo const& info) +{ + // If already exists, do nothing + if (_elunaMap.find(info.key) != _elunaMap.end()) + return; + + _elunaMap.emplace(info.key, std::make_unique(map)); +} + +Eluna* ElunaMgr::Get(uint64_t key) const +{ + auto it = _elunaMap.find(key); + if (it != _elunaMap.end()) + return it->second.get(); + + return nullptr; +} + +Eluna* ElunaMgr::Get(ElunaInfo const& info) const +{ + return Get(info.key); +} + +void ElunaMgr::Destroy(uint64_t key) +{ + _elunaMap.erase(key); +} + +void ElunaMgr::Destroy(ElunaInfo const& info) +{ + Destroy(info.key); +} + +Eluna* ElunaInfo::GetEluna() const +{ + return sElunaMgr->Get(key); +} diff --git a/ElunaMgr.h b/ElunaMgr.h new file mode 100644 index 0000000000..3de64a0766 --- /dev/null +++ b/ElunaMgr.h @@ -0,0 +1,56 @@ +/* +* Copyright (C) 2010 - 2025 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef _ELUNAMGR_H +#define _ELUNAMGR_H + +#include "LuaEngine.h" + +#include +#include + +struct ElunaInfo +{ + uint32_t mapId; + uint32_t instanceId; + uint64_t key; + + ElunaInfo(uint32_t map, uint32_t instance) + : mapId(map), instanceId(instance) + { + key = (static_cast(mapId) << 32) | instanceId; + } + + // Getter to fetch Eluna object + Eluna* GetEluna() const; +}; + +class ElunaMgr +{ +private: + ElunaMgr(); + ~ElunaMgr(); + ElunaMgr(ElunaMgr const&) = delete; + ElunaMgr& operator=(ElunaMgr const&) = delete; + +public: + static ElunaMgr* instance(); + + void Create(Map* map, ElunaInfo const& info); + + Eluna* Get(uint64_t key) const; + Eluna* Get(ElunaInfo const& info) const; + + void Destroy(uint64_t key); + void Destroy(ElunaInfo const& info); + +private: + std::unordered_map> _elunaMap; +}; + +#define sElunaMgr ElunaMgr::instance() + +#endif //_ELUNAMGR_H From 1ecf28a66767a6aea06bfd317c52e6129aab5ff2 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Fri, 5 Sep 2025 01:58:06 +0200 Subject: [PATCH 02/11] More EventMgr work --- ElunaMgr.cpp | 16 +++++++++++++--- ElunaMgr.h | 22 ++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index 9d056b1b48..86cc974025 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -5,6 +5,7 @@ */ #include "ElunaMgr.h" +#include "LuaEngine.h" ElunaMgr::ElunaMgr() { @@ -29,7 +30,7 @@ void ElunaMgr::Create(Map* map, ElunaInfo const& info) _elunaMap.emplace(info.key, std::make_unique(map)); } -Eluna* ElunaMgr::Get(uint64_t key) const +Eluna* ElunaMgr::Get(uint64 key) const { auto it = _elunaMap.find(key); if (it != _elunaMap.end()) @@ -43,7 +44,7 @@ Eluna* ElunaMgr::Get(ElunaInfo const& info) const return Get(info.key); } -void ElunaMgr::Destroy(uint64_t key) +void ElunaMgr::Destroy(uint64 key) { _elunaMap.erase(key); } @@ -55,5 +56,14 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Eluna* ElunaInfo::GetEluna() const { - return sElunaMgr->Get(key); + if (sElunaMgr) + return sElunaMgr->Get(key); + + return nullptr; +} + +ElunaInfo::~ElunaInfo() +{ + if (sElunaMgr) + sElunaMgr->Destroy(key); } diff --git a/ElunaMgr.h b/ElunaMgr.h index 3de64a0766..e6c00b91e5 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -7,23 +7,25 @@ #ifndef _ELUNAMGR_H #define _ELUNAMGR_H -#include "LuaEngine.h" - #include #include +class Eluna; + struct ElunaInfo { - uint32_t mapId; - uint32_t instanceId; - uint64_t key; + uint32 mapId; + uint32 instanceId; + uint64 key; - ElunaInfo(uint32_t map, uint32_t instance) + ElunaInfo(uint32 map, uint32 instance) : mapId(map), instanceId(instance) { - key = (static_cast(mapId) << 32) | instanceId; + key = (static_cast(mapId) << 32) | instanceId; } + ~ElunaInfo(); + // Getter to fetch Eluna object Eluna* GetEluna() const; }; @@ -41,14 +43,14 @@ class ElunaMgr void Create(Map* map, ElunaInfo const& info); - Eluna* Get(uint64_t key) const; + Eluna* Get(uint64 key) const; Eluna* Get(ElunaInfo const& info) const; - void Destroy(uint64_t key); + void Destroy(uint64 key); void Destroy(ElunaInfo const& info); private: - std::unordered_map> _elunaMap; + std::unordered_map> _elunaMap; }; #define sElunaMgr ElunaMgr::instance() From 4fd4c7fc313340fbd42c2ea322af8bab0723f297 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 07:51:30 +0200 Subject: [PATCH 03/11] Improvements to ElunaMgr --- ElunaMgr.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++------- ElunaMgr.h | 29 +++++++++++++++++++---------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index 86cc974025..a07ea3db3c 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -24,7 +24,8 @@ ElunaMgr::~ElunaMgr() void ElunaMgr::Create(Map* map, ElunaInfo const& info) { // If already exists, do nothing - if (_elunaMap.find(info.key) != _elunaMap.end()) + bool keyExists = (info.key != ElunaInfo::INVALID_KEY_ID) && (_elunaMap.find(info.key) != _elunaMap.end()); + if (keyExists) return; _elunaMap.emplace(info.key, std::make_unique(map)); @@ -54,16 +55,50 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Destroy(info.key); } -Eluna* ElunaInfo::GetEluna() const +ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) { - if (sElunaMgr) - return sElunaMgr->Get(key); - - return nullptr; + key = MakeKey(mapId, instanceId); } ElunaInfo::~ElunaInfo() { - if (sElunaMgr) + if (IsValid() && sElunaMgr) sElunaMgr->Destroy(key); } + +uint64 ElunaInfo::MakeKey(uint32 mapId, uint32 instanceId) +{ + return instanceId | (static_cast(mapId) << 32); +} + +uint64 ElunaInfo::MakeGlobalKey(uint32 instanceId) +{ + return MakeKey(GLOBAL_MAP_ID, instanceId); +} + +bool ElunaInfo::IsValid() const +{ + return key != INVALID_KEY_ID; +} +bool ElunaInfo::IsGlobal() const +{ + return IsValid() && GetMapId() == GLOBAL_MAP_ID; +} + +uint32 ElunaInfo::GetMapId() const +{ + return key >> 32; +} + +uint32 ElunaInfo::GetInstanceId() const +{ + return key & 0xFFFFFFFF; +} + +Eluna* ElunaInfo::GetEluna() const +{ + if (IsValid() && sElunaMgr) + return sElunaMgr->Get(key); + + return nullptr; +} diff --git a/ElunaMgr.h b/ElunaMgr.h index e6c00b91e5..438229b3ff 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -7,27 +7,36 @@ #ifndef _ELUNAMGR_H #define _ELUNAMGR_H -#include +#include #include +#include class Eluna; struct ElunaInfo { - uint32 mapId; - uint32 instanceId; - uint64 key; +public: + ElunaInfo(uint32 mapId, uint32 instanceId); + ~ElunaInfo(); + +public: + static constexpr uint32 MakeKey(uint32 mapId, uint32 instanceId); + static constexpr uint32 MakeGlobalKey(uint32 instanceId); - ElunaInfo(uint32 map, uint32 instance) - : mapId(map), instanceId(instance) - { - key = (static_cast(mapId) << 32) | instanceId; - } + bool IsValid() const; + bool IsGlobal() const; - ~ElunaInfo(); + uint32 GetMapId() const; + uint32 GetInstanceId() const; // Getter to fetch Eluna object Eluna* GetEluna() const; + +public: + static uint64 const INVALID_KEY_ID = std::numeric_limits().max(); + static uint32 const GLOBAL_MAP_ID = std::numeric_limits().max(); + + uint64 key = INVALID_KEY_ID; }; class ElunaMgr From b7370edbd8fec56f53ffc532c0df634a85721bd3 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 08:15:21 +0200 Subject: [PATCH 04/11] Fixed an issue where MakeKey, MakeGlobalKey failed to compile due to missing keyword specifier constexpr in the cpp file Minor style adjustments --- ElunaMgr.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index a07ea3db3c..d1d1ad8363 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -24,7 +24,7 @@ ElunaMgr::~ElunaMgr() void ElunaMgr::Create(Map* map, ElunaInfo const& info) { // If already exists, do nothing - bool keyExists = (info.key != ElunaInfo::INVALID_KEY_ID) && (_elunaMap.find(info.key) != _elunaMap.end()); + bool keyExists = info.IsValid() && (_elunaMap.find(info.key) != _elunaMap.end()); if (keyExists) return; @@ -66,12 +66,12 @@ ElunaInfo::~ElunaInfo() sElunaMgr->Destroy(key); } -uint64 ElunaInfo::MakeKey(uint32 mapId, uint32 instanceId) +constexpr uint64 ElunaInfo::MakeKey(uint32 mapId, uint32 instanceId) { return instanceId | (static_cast(mapId) << 32); } -uint64 ElunaInfo::MakeGlobalKey(uint32 instanceId) +constexpr uint64 ElunaInfo::MakeGlobalKey(uint32 instanceId) { return MakeKey(GLOBAL_MAP_ID, instanceId); } @@ -80,6 +80,7 @@ bool ElunaInfo::IsValid() const { return key != INVALID_KEY_ID; } + bool ElunaInfo::IsGlobal() const { return IsValid() && GetMapId() == GLOBAL_MAP_ID; From 18f0c16972ba8ac16d8ba75309771f43d7822e12 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 08:17:28 +0200 Subject: [PATCH 05/11] Fixed an issue where MakeKey, MakeGlobalKey failed to compile due to mismatching data types --- ElunaMgr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElunaMgr.h b/ElunaMgr.h index 438229b3ff..b5fef992e6 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -20,8 +20,8 @@ struct ElunaInfo ~ElunaInfo(); public: - static constexpr uint32 MakeKey(uint32 mapId, uint32 instanceId); - static constexpr uint32 MakeGlobalKey(uint32 instanceId); + static constexpr uint64 MakeKey(uint32 mapId, uint32 instanceId); + static constexpr uint64 MakeGlobalKey(uint32 instanceId); bool IsValid() const; bool IsGlobal() const; From 8cc44772c098f32df0b20d2f2d62aad20c4a5a70 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 08:50:15 +0200 Subject: [PATCH 06/11] Added ElunaInfoKey --- ElunaMgr.cpp | 58 +++++++++++++++++++++++++++++++++++++++------------- ElunaMgr.h | 56 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 90 insertions(+), 24 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index d1d1ad8363..b10ccd959e 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -31,7 +31,7 @@ void ElunaMgr::Create(Map* map, ElunaInfo const& info) _elunaMap.emplace(info.key, std::make_unique(map)); } -Eluna* ElunaMgr::Get(uint64 key) const +Eluna* ElunaMgr::Get(ElunaInfoKey key) const { auto it = _elunaMap.find(key); if (it != _elunaMap.end()) @@ -45,7 +45,7 @@ Eluna* ElunaMgr::Get(ElunaInfo const& info) const return Get(info.key); } -void ElunaMgr::Destroy(uint64 key) +void ElunaMgr::Destroy(ElunaInfoKey key) { _elunaMap.erase(key); } @@ -55,45 +55,75 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Destroy(info.key); } -ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) +ElunaInfoKey::ElunaInfoKey(uint32 mapId, uint32 instanceId) { - key = MakeKey(mapId, instanceId); + value = MakeKey(mapId, instanceId); } -ElunaInfo::~ElunaInfo() +bool ElunaInfoKey::operator==(const ElunaInfoKey& other) const { - if (IsValid() && sElunaMgr) - sElunaMgr->Destroy(key); + return value == other.value; } -constexpr uint64 ElunaInfo::MakeKey(uint32 mapId, uint32 instanceId) +constexpr ElunaInfoKey ElunaInfoKey::MakeKey(uint32 mapId, uint32 instanceId) { - return instanceId | (static_cast(mapId) << 32); + return ElunaInfoKey(instanceId | (static_cast(mapId) << 32)); } -constexpr uint64 ElunaInfo::MakeGlobalKey(uint32 instanceId) +constexpr ElunaInfoKey ElunaInfoKey::MakeGlobalKey(uint32 instanceId) { return MakeKey(GLOBAL_MAP_ID, instanceId); } +bool ElunaInfoKey::IsValid() const +{ + return value != INVALID_KEY_VALUE; +} + +bool ElunaInfoKey::IsGlobal() const +{ + return IsValid() && GetMapId() == GLOBAL_MAP_ID; +} + +uint32 ElunaInfoKey::GetMapId() const +{ + return value >> 32; +} + +uint32 ElunaInfoKey::GetInstanceId() const +{ + return value & 0xFFFFFFFF; +} + +ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) +{ + key = ElunaInfoKey::MakeKey(mapId, instanceId); +} + +ElunaInfo::~ElunaInfo() +{ + if (IsValid() && sElunaMgr) + sElunaMgr->Destroy(key); +} + bool ElunaInfo::IsValid() const { - return key != INVALID_KEY_ID; + return key.IsValid(); } bool ElunaInfo::IsGlobal() const { - return IsValid() && GetMapId() == GLOBAL_MAP_ID; + return key.IsGlobal(); } uint32 ElunaInfo::GetMapId() const { - return key >> 32; + return key.GetMapId(); } uint32 ElunaInfo::GetInstanceId() const { - return key & 0xFFFFFFFF; + return key.GetInstanceId(); } Eluna* ElunaInfo::GetEluna() const diff --git a/ElunaMgr.h b/ElunaMgr.h index b5fef992e6..ff3d5b9617 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -13,16 +13,55 @@ class Eluna; +struct ElunaInfoKey +{ +public: + ElunaInfoKey() : value(INVALID_KEY_VALUE) {} + ElunaInfoKey(uint64 key) : value(key) {} + ElunaInfoKey(uint32 mapId, uint32 instanceId); + ~ElunaInfoKey() {} + + bool operator==(const ElunaInfoKey& other) const; + +public: + static constexpr ElunaInfoKey MakeKey(uint32 mapId, uint32 instanceId); + static constexpr ElunaInfoKey MakeGlobalKey(uint32 instanceId); + + bool IsValid() const; + bool IsGlobal() const; + + uint32 GetMapId() const; + uint32 GetInstanceId() const; + +public: + static uint64 const INVALID_KEY_VALUE = std::numeric_limits().max(); + static uint32 const GLOBAL_MAP_ID = std::numeric_limits().max(); + + uint64 value; +}; + +// Specialize ElunaInfoKey for use in unordered_map +namespace std +{ + template <> + struct hash + { + size_t operator()(const ElunaInfoKey& key) const + { + return key.value; + } + }; +} + struct ElunaInfo { public: + ElunaInfo() : key() {} + ElunaInfo(ElunaInfoKey key) : key(key) {} ElunaInfo(uint32 mapId, uint32 instanceId); ~ElunaInfo(); public: - static constexpr uint64 MakeKey(uint32 mapId, uint32 instanceId); - static constexpr uint64 MakeGlobalKey(uint32 instanceId); - bool IsValid() const; bool IsGlobal() const; @@ -33,10 +72,7 @@ struct ElunaInfo Eluna* GetEluna() const; public: - static uint64 const INVALID_KEY_ID = std::numeric_limits().max(); - static uint32 const GLOBAL_MAP_ID = std::numeric_limits().max(); - - uint64 key = INVALID_KEY_ID; + ElunaInfoKey key; }; class ElunaMgr @@ -52,14 +88,14 @@ class ElunaMgr void Create(Map* map, ElunaInfo const& info); - Eluna* Get(uint64 key) const; + Eluna* Get(ElunaInfoKey key) const; Eluna* Get(ElunaInfo const& info) const; - void Destroy(uint64 key); + void Destroy(ElunaInfoKey key); void Destroy(ElunaInfo const& info); private: - std::unordered_map> _elunaMap; + std::unordered_map> _elunaMap; }; #define sElunaMgr ElunaMgr::instance() From 92a786a219ec58ee1029d5130002defe5d216905 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 08:58:48 +0200 Subject: [PATCH 07/11] Fixed an issue where ElunaInfoKey Constructor(uint32 mapId, uint32 instanceId) failed to compile due to incorrect assignment to value --- ElunaMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index b10ccd959e..de45cff669 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -57,7 +57,7 @@ void ElunaMgr::Destroy(ElunaInfo const& info) ElunaInfoKey::ElunaInfoKey(uint32 mapId, uint32 instanceId) { - value = MakeKey(mapId, instanceId); + value = MakeKey(mapId, instanceId).value; } bool ElunaInfoKey::operator==(const ElunaInfoKey& other) const From 87eff33c99376737d9cec016e29eb6cfabb7a595 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 09:13:39 +0200 Subject: [PATCH 08/11] Fix Compilation Issues --- ElunaMgr.cpp | 30 ------------------------------ ElunaMgr.h | 17 ++++++++--------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index de45cff669..6ba033ee62 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -55,16 +55,6 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Destroy(info.key); } -ElunaInfoKey::ElunaInfoKey(uint32 mapId, uint32 instanceId) -{ - value = MakeKey(mapId, instanceId).value; -} - -bool ElunaInfoKey::operator==(const ElunaInfoKey& other) const -{ - return value == other.value; -} - constexpr ElunaInfoKey ElunaInfoKey::MakeKey(uint32 mapId, uint32 instanceId) { return ElunaInfoKey(instanceId | (static_cast(mapId) << 32)); @@ -75,26 +65,6 @@ constexpr ElunaInfoKey ElunaInfoKey::MakeGlobalKey(uint32 instanceId) return MakeKey(GLOBAL_MAP_ID, instanceId); } -bool ElunaInfoKey::IsValid() const -{ - return value != INVALID_KEY_VALUE; -} - -bool ElunaInfoKey::IsGlobal() const -{ - return IsValid() && GetMapId() == GLOBAL_MAP_ID; -} - -uint32 ElunaInfoKey::GetMapId() const -{ - return value >> 32; -} - -uint32 ElunaInfoKey::GetInstanceId() const -{ - return value & 0xFFFFFFFF; -} - ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) { key = ElunaInfoKey::MakeKey(mapId, instanceId); diff --git a/ElunaMgr.h b/ElunaMgr.h index ff3d5b9617..ca88ac4286 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -16,23 +16,22 @@ class Eluna; struct ElunaInfoKey { public: - ElunaInfoKey() : value(INVALID_KEY_VALUE) {} - ElunaInfoKey(uint64 key) : value(key) {} - ElunaInfoKey(uint32 mapId, uint32 instanceId); + constexpr ElunaInfoKey() : value(INVALID_KEY_VALUE) {} + constexpr ElunaInfoKey(uint64 key) : value(key) {} ~ElunaInfoKey() {} - bool operator==(const ElunaInfoKey& other) const; + constexpr bool operator==(const ElunaInfoKey& other) const { return value == other.value; } public: static constexpr ElunaInfoKey MakeKey(uint32 mapId, uint32 instanceId); static constexpr ElunaInfoKey MakeGlobalKey(uint32 instanceId); - bool IsValid() const; - bool IsGlobal() const; + constexpr bool IsValid() const { return value != INVALID_KEY_VALUE; }; + constexpr bool IsGlobal() const { return IsValid() && GetMapId() == GLOBAL_MAP_ID; }; + + constexpr uint32 GetMapId() const { return value >> 32; }; + constexpr uint32 GetInstanceId() const { return value & 0xFFFFFFFF; }; - uint32 GetMapId() const; - uint32 GetInstanceId() const; - public: static uint64 const INVALID_KEY_VALUE = std::numeric_limits().max(); static uint32 const GLOBAL_MAP_ID = std::numeric_limits().max(); From fa1f1dcd61210521cc85ad6315613a1748b376f2 Mon Sep 17 00:00:00 2001 From: NixAJ Date: Fri, 5 Sep 2025 09:25:44 +0200 Subject: [PATCH 09/11] Fix Compilation Issues --- ElunaMgr.cpp | 10 ---------- ElunaMgr.h | 13 ++++++++++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index 6ba033ee62..a8762c4c79 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -55,16 +55,6 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Destroy(info.key); } -constexpr ElunaInfoKey ElunaInfoKey::MakeKey(uint32 mapId, uint32 instanceId) -{ - return ElunaInfoKey(instanceId | (static_cast(mapId) << 32)); -} - -constexpr ElunaInfoKey ElunaInfoKey::MakeGlobalKey(uint32 instanceId) -{ - return MakeKey(GLOBAL_MAP_ID, instanceId); -} - ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) { key = ElunaInfoKey::MakeKey(mapId, instanceId); diff --git a/ElunaMgr.h b/ElunaMgr.h index ca88ac4286..8804bf2c8f 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -18,13 +18,20 @@ struct ElunaInfoKey public: constexpr ElunaInfoKey() : value(INVALID_KEY_VALUE) {} constexpr ElunaInfoKey(uint64 key) : value(key) {} - ~ElunaInfoKey() {} + constexpr ElunaInfoKey(uint32 mapId, uint32 instanceId) : value(instanceId | (static_cast(mapId) << 32)) {} constexpr bool operator==(const ElunaInfoKey& other) const { return value == other.value; } + constexpr bool operator!=(const ElunaInfoKey& other) const { return !(*this == other); } public: - static constexpr ElunaInfoKey MakeKey(uint32 mapId, uint32 instanceId); - static constexpr ElunaInfoKey MakeGlobalKey(uint32 instanceId); + static constexpr ElunaInfoKey MakeKey(uint32 mapId, uint32 instanceId) + { + return ElunaInfoKey(instanceId | (static_cast(mapId) << 32)); + } + static constexpr ElunaInfoKey MakeGlobalKey(uint32 instanceId) + { + return MakeKey(GLOBAL_MAP_ID, instanceId); + } constexpr bool IsValid() const { return value != INVALID_KEY_VALUE; }; constexpr bool IsGlobal() const { return IsValid() && GetMapId() == GLOBAL_MAP_ID; }; From f4dfaac51143a3b344d386315811dbdad5e82224 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Fri, 5 Sep 2025 13:33:02 +0200 Subject: [PATCH 10/11] Forward declare Map Required for global state --- ElunaMgr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ElunaMgr.h b/ElunaMgr.h index 8804bf2c8f..e644676639 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -12,6 +12,7 @@ #include class Eluna; +class Map; struct ElunaInfoKey { From 2b74589376626e28c226121ee47878a66cc5b4e4 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Fri, 5 Sep 2025 14:18:14 +0200 Subject: [PATCH 11/11] Remove ElunaInfo overload for map and instance id Now requires you to use a properly constructed key --- ElunaMgr.cpp | 5 ----- ElunaMgr.h | 1 - 2 files changed, 6 deletions(-) diff --git a/ElunaMgr.cpp b/ElunaMgr.cpp index a8762c4c79..73dab27cfe 100644 --- a/ElunaMgr.cpp +++ b/ElunaMgr.cpp @@ -55,11 +55,6 @@ void ElunaMgr::Destroy(ElunaInfo const& info) Destroy(info.key); } -ElunaInfo::ElunaInfo(uint32 mapId, uint32 instanceId) -{ - key = ElunaInfoKey::MakeKey(mapId, instanceId); -} - ElunaInfo::~ElunaInfo() { if (IsValid() && sElunaMgr) diff --git a/ElunaMgr.h b/ElunaMgr.h index e644676639..a890b9c3b5 100644 --- a/ElunaMgr.h +++ b/ElunaMgr.h @@ -65,7 +65,6 @@ struct ElunaInfo public: ElunaInfo() : key() {} ElunaInfo(ElunaInfoKey key) : key(key) {} - ElunaInfo(uint32 mapId, uint32 instanceId); ~ElunaInfo(); public: