Skip to content

Commit

Permalink
Update CMangos implementation to match Mangos (#4)
Browse files Browse the repository at this point in the history
* Check that elunaEvents exists before updating timed events
* Change Eluna init code to be the same as on Mangos
* Update map hooks to reflect Mangos implementation
* Make sure Eluna exists before calling hooks
  • Loading branch information
Foereaper authored and Niam5 committed May 27, 2024
1 parent eb18405 commit 8e64864
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,8 @@ void WorldObject::CleanupsBeforeDelete()
void WorldObject::Update(const uint32 diff)
{
#ifdef BUILD_ELUNA
elunaEvents->Update(diff);
if (elunaEvents) // can be null on maps without eluna
elunaEvents->Update(diff);
#endif
m_heartBeatTimer.Update(diff);
while (m_heartBeatTimer.Passed())
Expand Down Expand Up @@ -2064,8 +2065,11 @@ void WorldObject::SetMap(Map* map)
// in single state, the timed events should move across maps
if (!sElunaConfig->IsElunaCompatibilityMode())
{
delete elunaEvents;
elunaEvents = nullptr; // set to null in case map doesn't use eluna
if (elunaEvents)
{
delete elunaEvents;
elunaEvents = nullptr; // set to null in case map doesn't use eluna
}
}

if (Eluna* e = map->GetEluna())
Expand Down Expand Up @@ -3313,4 +3317,4 @@ Eluna* WorldObject::GetEluna() const

return nullptr;
}
#endif
#endif
6 changes: 3 additions & 3 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ bool Map::Add(Player* player)
UpdateObjectVisibility(player, cell, p);

#ifdef BUILD_ELUNA
if(Eluna* e = player->GetEluna())
if (Eluna* e = GetEluna())
{
e->OnMapChanged(player);

if(Eluna* e = GetEluna())
e->OnPlayerEnter(this, player);
}
#endif

#ifdef BUILD_SOLOCRAFT
Expand Down
10 changes: 5 additions & 5 deletions src/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@ void World::SetInitialWorldSettings()
sLog.outString();

#ifdef BUILD_ELUNA
// lua state begins uninitialized
eluna = nullptr;

sLog.outString("Loading Eluna config...");
sElunaConfig->Initialize();

Expand Down Expand Up @@ -1504,9 +1507,6 @@ void World::SetInitialWorldSettings()
sTicketMgr.LoadGMTickets();

#ifdef BUILD_ELUNA
// lua state begins uninitialized
eluna = nullptr;

if (sElunaConfig->IsElunaEnabled())
{
///- Run eluna scripts.
Expand Down Expand Up @@ -1651,8 +1651,8 @@ void World::SetInitialWorldSettings()
#endif

#ifdef BUILD_ELUNA
if (GetEluna())
GetEluna()->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run
if (Eluna* e = GetEluna())
e->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run
sLog.outString();
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/mangosd/WorldRunnable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ extern int m_ServiceStatus;
void WorldRunnable::run()
{
#ifdef BUILD_ELUNA
sWorld.GetEluna()->OnStartup();
if(Eluna* e = sWorld.GetEluna())
e->OnStartup();
#endif

///- Init new SQL thread for the world database
Expand Down Expand Up @@ -85,7 +86,8 @@ void WorldRunnable::run()
#endif
}
#ifdef BUILD_ELUNA
sWorld.GetEluna()->OnShutdown();
if(Eluna* e = sWorld.GetEluna())
e->OnShutdown();
#endif

sWorld.CleanupsBeforeStop();
Expand Down

0 comments on commit 8e64864

Please sign in to comment.