@@ -31,7 +31,7 @@ void ElunaMgr::Create(Map* map, ElunaInfo const& info)
3131 _elunaMap.emplace (info.key , std::make_unique<Eluna>(map));
3232}
3333
34- Eluna* ElunaMgr::Get (uint64 key) const
34+ Eluna* ElunaMgr::Get (ElunaInfoKey key) const
3535{
3636 auto it = _elunaMap.find (key);
3737 if (it != _elunaMap.end ())
@@ -45,7 +45,7 @@ Eluna* ElunaMgr::Get(ElunaInfo const& info) const
4545 return Get (info.key );
4646}
4747
48- void ElunaMgr::Destroy (uint64 key)
48+ void ElunaMgr::Destroy (ElunaInfoKey key)
4949{
5050 _elunaMap.erase (key);
5151}
@@ -55,45 +55,75 @@ void ElunaMgr::Destroy(ElunaInfo const& info)
5555 Destroy (info.key );
5656}
5757
58- ElunaInfo::ElunaInfo (uint32 mapId, uint32 instanceId)
58+ ElunaInfoKey::ElunaInfoKey (uint32 mapId, uint32 instanceId)
5959{
60- key = MakeKey (mapId, instanceId);
60+ value = MakeKey (mapId, instanceId);
6161}
6262
63- ElunaInfo::~ElunaInfo ()
63+ bool ElunaInfoKey:: operator ==( const ElunaInfoKey& other) const
6464{
65- if (IsValid () && sElunaMgr )
66- sElunaMgr ->Destroy (key);
65+ return value == other.value ;
6766}
6867
69- constexpr uint64 ElunaInfo ::MakeKey (uint32 mapId, uint32 instanceId)
68+ constexpr ElunaInfoKey ElunaInfoKey ::MakeKey (uint32 mapId, uint32 instanceId)
7069{
71- return instanceId | (static_cast <uint64>(mapId) << 32 );
70+ return ElunaInfoKey ( instanceId | (static_cast <uint64>(mapId) << 32 ) );
7271}
7372
74- constexpr uint64 ElunaInfo ::MakeGlobalKey (uint32 instanceId)
73+ constexpr ElunaInfoKey ElunaInfoKey ::MakeGlobalKey (uint32 instanceId)
7574{
7675 return MakeKey (GLOBAL_MAP_ID, instanceId);
7776}
7877
78+ bool ElunaInfoKey::IsValid () const
79+ {
80+ return value != INVALID_KEY_VALUE;
81+ }
82+
83+ bool ElunaInfoKey::IsGlobal () const
84+ {
85+ return IsValid () && GetMapId () == GLOBAL_MAP_ID;
86+ }
87+
88+ uint32 ElunaInfoKey::GetMapId () const
89+ {
90+ return value >> 32 ;
91+ }
92+
93+ uint32 ElunaInfoKey::GetInstanceId () const
94+ {
95+ return value & 0xFFFFFFFF ;
96+ }
97+
98+ ElunaInfo::ElunaInfo (uint32 mapId, uint32 instanceId)
99+ {
100+ key = ElunaInfoKey::MakeKey (mapId, instanceId);
101+ }
102+
103+ ElunaInfo::~ElunaInfo ()
104+ {
105+ if (IsValid () && sElunaMgr )
106+ sElunaMgr ->Destroy (key);
107+ }
108+
79109bool ElunaInfo::IsValid () const
80110{
81- return key != INVALID_KEY_ID ;
111+ return key. IsValid () ;
82112}
83113
84114bool ElunaInfo::IsGlobal () const
85115{
86- return IsValid () && GetMapId () == GLOBAL_MAP_ID ;
116+ return key. IsGlobal () ;
87117}
88118
89119uint32 ElunaInfo::GetMapId () const
90120{
91- return key >> 32 ;
121+ return key. GetMapId () ;
92122}
93123
94124uint32 ElunaInfo::GetInstanceId () const
95125{
96- return key & 0xFFFFFFFF ;
126+ return key. GetInstanceId () ;
97127}
98128
99129Eluna* ElunaInfo::GetEluna () const
0 commit comments