* Added new World::OnStartup/OnShutdown hooks.

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2010-08-07 14:30:10 +02:00
parent 360e028331
commit f1c571a79e
3 changed files with 28 additions and 3 deletions
+10
View File
@@ -1012,6 +1012,16 @@ void ScriptMgr::OnRelocate(Transport* transport, uint32 mapId, float x, float y,
tmpscript->OnRelocate(transport, mapId, x, y, z);
}
void ScriptMgr::OnStartup()
{
FOREACH_SCRIPT(WorldScript)->OnStartup();
}
void ScriptMgr::OnShutdown()
{
FOREACH_SCRIPT(WorldScript)->OnShutdown();
}
void SpellHandlerScript::RegisterSelf()
{
ScriptMgr::ScriptRegistry<SpellHandlerScript>::AddScript(this);
+8
View File
@@ -292,6 +292,12 @@ class WorldScript : public ScriptObject, public UpdatableScript<void>
// Called on every world tick (don't execute too heavy code here).
virtual void OnUpdate(void* null, uint32 diff) { }
// Called when the world is started.
virtual void OnStartup() { }
// Called when the world is actually shut down.
virtual void OnShutdown() { }
};
class FormulaScript : public ScriptObject
@@ -787,6 +793,8 @@ class ScriptMgr
void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask);
void OnShutdownCancel();
void OnWorldUpdate(uint32 diff);
void OnStartup();
void OnShutdown();
public: /* FormulaScript */
@@ -27,7 +27,7 @@
#include "World.h"
#include "WorldSocketMgr.h"
#include "Database/DatabaseEnv.h"
#include "ScriptMgr.h"
#include "BattleGroundMgr.h"
#include "MapManager.h"
#include "Timer.h"
@@ -53,6 +53,8 @@ void WorldRunnable::run()
uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST
sScriptMgr.OnStartup();
///- While we have not World::m_stopEvent, update the world
while (!World::IsStopped())
{
@@ -77,11 +79,16 @@ void WorldRunnable::run()
prevSleepTime = 0;
#ifdef _WIN32
if (m_ServiceStatus == 0) World::StopNow(SHUTDOWN_EXIT_CODE);
while (m_ServiceStatus == 2) Sleep(1000);
if (m_ServiceStatus == 0)
World::StopNow(SHUTDOWN_EXIT_CODE);
while (m_ServiceStatus == 2)
Sleep(1000);
#endif
}
sScriptMgr.OnShutdown();
sWorld.KickAll(); // save and kick all players
sWorld.UpdateSessions( 1 ); // real players unload required UpdateSessions call