Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
WorldRunnable.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
9
10
#include "
BattlegroundMgr.h
"
11
#include "
Common.h
"
12
#include "
Database/DatabaseEnv.h
"
13
#include "
Errors.h
"
14
#include "
MapManager.h
"
15
#include "
ObjectAccessor.h
"
16
#include "
OutdoorPvPMgr.h
"
17
#include "
Platform/TimeUtils.h
"
18
#include "
ScriptMgr.h
"
19
#include "
Timer.h
"
20
#include "
World.h
"
21
#include "
WorldRunnable.h
"
22
#include "
WorldShutdownLifecycle.h
"
23
#include "
WorldSocketMgr.h
"
24
25
#define WORLD_SLEEP_CONST 50
26
27
#ifdef _WIN32
28
#include "
ServiceWin32.h
"
29
extern
int
m_ServiceStatus;
30
#endif
31
32
namespace
33
{
34
void
AdvanceShutdownStep(
Skyfire::WorldShutdown::WorldShutdownStep
& current,
35
Skyfire::WorldShutdown::WorldShutdownStep
next)
36
{
37
ASSERT
(
Skyfire::WorldShutdown::IsExpectedShutdownTransition
(current, next));
38
current = next;
39
}
40
}
41
43
void
WorldRunnable::Run
()
44
{
45
uint32
realCurrTime = 0;
46
uint32
realPrevTime =
getMSTime
();
47
48
uint32
prevSleepTime = 0;
// used for balanced full tick time length near WORLD_SLEEP_CONST
49
50
sScriptMgr
->OnStartup();
51
53
while
(!
World::IsStopped
())
54
{
55
++
World::m_worldLoopCounter
;
56
realCurrTime =
getMSTime
();
57
58
uint32
diff =
getMSTimeDiff
(realPrevTime, realCurrTime);
59
60
sWorld
->Update(diff);
61
realPrevTime = realCurrTime;
62
63
// diff (D0) include time of previous sleep (d0) + tick time (t0)
64
// we want that next d1 + t1 == WORLD_SLEEP_CONST
65
// we can't know next t1 and then can use (t0 + d1) == WORLD_SLEEP_CONST requirement
66
// d1 = WORLD_SLEEP_CONST - t0 = WORLD_SLEEP_CONST - (D0 - d0) = WORLD_SLEEP_CONST + d0 - D0
67
if
(diff <=
WORLD_SLEEP_CONST
+ prevSleepTime)
68
{
69
prevSleepTime =
WORLD_SLEEP_CONST
+ prevSleepTime - diff;
70
Skyfire::SleepForMilliseconds
(prevSleepTime);
71
}
72
else
73
prevSleepTime = 0;
74
75
#ifdef _WIN32
76
if
(m_ServiceStatus == 0)
77
World::StopNow
(
SHUTDOWN_EXIT_CODE
);
78
79
while
(m_ServiceStatus == 2)
80
Skyfire::SleepForMilliseconds
(1000);
81
#endif
82
}
83
84
Skyfire::WorldShutdown::WorldShutdownStep
shutdownStep =
Skyfire::WorldShutdown::WORLD_SHUTDOWN_START
;
85
86
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_SCRIPT_SHUTDOWN
);
87
sScriptMgr
->OnShutdown();
88
89
// Players must be kicked and sessions updated before maps can be unloaded.
90
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_KICK_PLAYERS
);
91
sWorld
->KickAll();
// save and kick all players
92
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UPDATE_SESSIONS
);
93
sWorld
->UpdateSessions(1);
// real players unload required UpdateSessions call
94
95
// Battleground and network teardown must finish before map/object storage is destroyed.
96
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_DELETE_BATTLEGROUNDS
);
97
sBattlegroundMgr
->DeleteAllBattlegrounds();
98
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_STOP_NETWORK
);
99
sWorldSocketMgr
->StopNetwork();
100
101
// Maps own live world objects; ObjectAccessor corpse storage is unloaded after maps.
102
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_MAPS
);
103
sMapMgr
->UnloadAll();
// unload all grids (including locked in memory)
104
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_OBJECT_ACCESSOR
);
105
sObjectAccessor
->UnloadAll();
// unload 'i_player2corpse' storage and remove from world
106
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_SCRIPTS
);
107
sScriptMgr
->Unload();
108
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_OUTDOOR_PVP_DIE
);
109
sOutdoorPvPMgr
->Die();
110
AdvanceShutdownStep(shutdownStep,
Skyfire::WorldShutdown::WORLD_SHUTDOWN_COMPLETE
);
111
}
BattlegroundMgr.h
sBattlegroundMgr
#define sBattlegroundMgr
Definition
BattlegroundMgr.h:157
Common.h
DatabaseEnv.h
uint32
std::uint32_t uint32
Definition
Define.h:77
Errors.h
ASSERT
#define ASSERT
Definition
Errors.h:29
MapManager.h
sMapMgr
#define sMapMgr
Definition
MapManager.h:145
ObjectAccessor.h
sObjectAccessor
#define sObjectAccessor
Definition
ObjectAccessor.h:195
OutdoorPvPMgr.h
sOutdoorPvPMgr
#define sOutdoorPvPMgr
Definition
OutdoorPvPMgr.h:92
ScriptMgr.h
sScriptMgr
#define sScriptMgr
Definition
ScriptMgr.h:764
ServiceWin32.h
TimeUtils.h
Timer.h
getMSTime
uint32 getMSTime()
Definition
Timer.h:12
getMSTimeDiff
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition
Timer.h:17
World.h
WORLD_SLEEP_CONST
#define WORLD_SLEEP_CONST
Definition
WorldRunnable.cpp:25
WorldRunnable.h
WorldShutdownLifecycle.h
WorldSocketMgr.h
World::StopNow
static void StopNow(uint8 exitcode)
Definition
World.h:674
World::IsStopped
static bool IsStopped()
Definition
World.h:675
World::m_worldLoopCounter
static std::atomic< uint32 > m_worldLoopCounter
Definition
World.h:559
WorldRunnable::Run
void Run()
Heartbeat for the World.
Definition
WorldRunnable.cpp:43
sWorldSocketMgr
#define sWorldSocketMgr
Definition
WorldSocketMgr.h:60
sWorld
#define sWorld
Definition
World.h:910
SHUTDOWN_EXIT_CODE
@ SHUTDOWN_EXIT_CODE
Definition
World.h:64
Skyfire::WorldShutdown::IsExpectedShutdownTransition
bool IsExpectedShutdownTransition(WorldShutdownStep current, WorldShutdownStep next)
Definition
WorldShutdownLifecycle.cpp:77
Skyfire::WorldShutdown::WorldShutdownStep
WorldShutdownStep
Definition
WorldShutdownLifecycle.h:14
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_SCRIPTS
@ WORLD_SHUTDOWN_UNLOAD_SCRIPTS
Definition
WorldShutdownLifecycle.h:23
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_MAPS
@ WORLD_SHUTDOWN_UNLOAD_MAPS
Definition
WorldShutdownLifecycle.h:21
Skyfire::WorldShutdown::WORLD_SHUTDOWN_SCRIPT_SHUTDOWN
@ WORLD_SHUTDOWN_SCRIPT_SHUTDOWN
Definition
WorldShutdownLifecycle.h:16
Skyfire::WorldShutdown::WORLD_SHUTDOWN_COMPLETE
@ WORLD_SHUTDOWN_COMPLETE
Definition
WorldShutdownLifecycle.h:25
Skyfire::WorldShutdown::WORLD_SHUTDOWN_STOP_NETWORK
@ WORLD_SHUTDOWN_STOP_NETWORK
Definition
WorldShutdownLifecycle.h:20
Skyfire::WorldShutdown::WORLD_SHUTDOWN_DELETE_BATTLEGROUNDS
@ WORLD_SHUTDOWN_DELETE_BATTLEGROUNDS
Definition
WorldShutdownLifecycle.h:19
Skyfire::WorldShutdown::WORLD_SHUTDOWN_START
@ WORLD_SHUTDOWN_START
Definition
WorldShutdownLifecycle.h:15
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UNLOAD_OBJECT_ACCESSOR
@ WORLD_SHUTDOWN_UNLOAD_OBJECT_ACCESSOR
Definition
WorldShutdownLifecycle.h:22
Skyfire::WorldShutdown::WORLD_SHUTDOWN_KICK_PLAYERS
@ WORLD_SHUTDOWN_KICK_PLAYERS
Definition
WorldShutdownLifecycle.h:17
Skyfire::WorldShutdown::WORLD_SHUTDOWN_UPDATE_SESSIONS
@ WORLD_SHUTDOWN_UPDATE_SESSIONS
Definition
WorldShutdownLifecycle.h:18
Skyfire::WorldShutdown::WORLD_SHUTDOWN_OUTDOOR_PVP_DIE
@ WORLD_SHUTDOWN_OUTDOOR_PVP_DIE
Definition
WorldShutdownLifecycle.h:24
Skyfire::SleepForMilliseconds
void SleepForMilliseconds(uint32 milliseconds)
Definition
TimeUtils.h:42
src
server
worldserver
WorldThread
WorldRunnable.cpp
Generated on
for Project SkyFire Core by
1.17.0