Core/Maps: Implement optional pre-loading of maps.

This commit is contained in:
Aokromes
2016-05-16 22:24:58 +02:00
parent 73389d44c4
commit 95018939a8
7 changed files with 61 additions and 6 deletions

View File

@@ -125,9 +125,9 @@ void Map::LoadMMap(int gx, int gy)
bool mmapLoadResult = MMAP::MMapFactory::createOrGetMMapManager()->loadMap((sWorld->GetDataPath() + "mmaps").c_str(), GetId(), gx, gy);
if (mmapLoadResult)
TC_LOG_DEBUG("maps", "MMAP loaded name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
TC_LOG_DEBUG("mmaps", "MMAP loaded name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
else
TC_LOG_ERROR("maps", "Could not load MMAP name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
TC_LOG_ERROR("mmaps", "Could not load MMAP name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
}
void Map::LoadVMap(int gx, int gy)
@@ -201,6 +201,13 @@ void Map::LoadMapAndVMap(int gx, int gy)
}
}
void Map::LoadAllCells()
{
for (uint32 cellX = 0; cellX < TOTAL_NUMBER_OF_CELLS_PER_MAP; cellX++)
for (uint32 cellY = 0; cellY < TOTAL_NUMBER_OF_CELLS_PER_MAP; cellY++)
LoadGrid((cellX + 0.5f - CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL, (cellY + 0.5f - CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL);
}
void Map::InitStateMachine()
{
si_GridStates[GRID_STATE_INVALID] = new InvalidState;

View File

@@ -304,6 +304,7 @@ class Map : public GridRefManager<NGridType>
bool GetUnloadLock(const GridCoord &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
void SetUnloadLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
void LoadGrid(float x, float y);
void LoadAllCells();
bool UnloadGrid(NGridType& ngrid, bool pForce);
virtual void UnloadAll();

View File

@@ -230,6 +230,9 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
bool load_data = save != NULL;
map->CreateInstanceData(load_data);
if (sWorld->getBoolConfig(CONFIG_INSTANCEMAP_LOAD_GRIDS))
map->LoadAllCells();
m_InstancedMaps[InstanceId] = map;
return map;
}

View File

@@ -610,6 +610,18 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_PRESERVE_CUSTOM_CHANNELS] = sConfigMgr->GetBoolDefault("PreserveCustomChannels", false);
m_int_configs[CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION] = sConfigMgr->GetIntDefault("PreserveCustomChannelDuration", 14);
m_bool_configs[CONFIG_GRID_UNLOAD] = sConfigMgr->GetBoolDefault("GridUnload", true);
m_bool_configs[CONFIG_BASEMAP_LOAD_GRIDS] = sConfigMgr->GetBoolDefault("BaseMapLoadAllGrids", false);
if (m_bool_configs[CONFIG_BASEMAP_LOAD_GRIDS] && m_bool_configs[CONFIG_GRID_UNLOAD])
{
TC_LOG_ERROR("server.loading", "BaseMapLoadAllGrids enabled, but GridUnload also enabled. GridUnload must be disabled to enable base map pre-loading. Base map pre-loading disabled");
m_bool_configs[CONFIG_BASEMAP_LOAD_GRIDS] = false;
}
m_bool_configs[CONFIG_INSTANCEMAP_LOAD_GRIDS] = sConfigMgr->GetBoolDefault("InstanceMapLoadAllGrids", false);
if (m_bool_configs[CONFIG_INSTANCEMAP_LOAD_GRIDS] && m_bool_configs[CONFIG_GRID_UNLOAD])
{
TC_LOG_ERROR("server.loading", "InstanceMapLoadAllGrids enabled, but GridUnload also enabled. GridUnload must be disabled to enable instance map pre-loading. Instance map pre-loading disabled");
m_bool_configs[CONFIG_INSTANCEMAP_LOAD_GRIDS] = false;
}
m_int_configs[CONFIG_INTERVAL_SAVE] = sConfigMgr->GetIntDefault("PlayerSaveInterval", 15 * MINUTE * IN_MILLISECONDS);
m_int_configs[CONFIG_INTERVAL_DISCONNECT_TOLERANCE] = sConfigMgr->GetIntDefault("DisconnectToleranceInterval", 0);
m_bool_configs[CONFIG_STATS_SAVE_ONLY_ON_LOGOUT] = sConfigMgr->GetBoolDefault("PlayerSave.Stats.SaveOnlyOnLogout", true);
@@ -1967,6 +1979,19 @@ void World::SetInitialWorldSettings()
LoadCharacterInfoStore();
// Preload all cells, if required for the base maps
if (sWorld->getBoolConfig(CONFIG_BASEMAP_LOAD_GRIDS))
{
sMapMgr->DoForAllMaps([](Map* map)
{
if (!map->Instanceable())
{
TC_LOG_INFO("server.loading", "Pre-loading base map data for map %u", map->GetId());
map->LoadAllCells();
}
});
}
TC_LOG_INFO("misc", "Initializing Opcodes...");
opcodeTable.Initialize();

View File

@@ -175,6 +175,8 @@ enum WorldBoolConfigs
CONFIG_CALCULATE_GAMEOBJECT_ZONE_AREA_DATA,
CONFIG_RESET_DUEL_COOLDOWNS,
CONFIG_RESET_DUEL_HEALTH_MANA,
CONFIG_BASEMAP_LOAD_GRIDS,
CONFIG_INSTANCEMAP_LOAD_GRIDS,
BOOL_CONFIG_VALUE_COUNT
};

View File

@@ -1438,10 +1438,7 @@ public:
map = player->GetMap();
handler->PSendSysMessage("Loading all cells (mapId: %u). Current next GameObject %u, Creature %u", map->GetId(), map->GetMaxLowGuid<HighGuid::GameObject>(), map->GetMaxLowGuid<HighGuid::Unit>());
for (uint32 cellX = 0; cellX < TOTAL_NUMBER_OF_CELLS_PER_MAP; cellX++)
for (uint32 cellY = 0; cellY < TOTAL_NUMBER_OF_CELLS_PER_MAP; cellY++)
map->LoadGrid((cellX + 0.5f - CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL, (cellY + 0.5f - CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL);
map->LoadAllCells();
handler->PSendSysMessage("Cells loaded (mapId: %u) After load - Next GameObject %u, Creature %u", map->GetId(), map->GetMaxLowGuid<HighGuid::GameObject>(), map->GetMaxLowGuid<HighGuid::Unit>());
return true;
}

View File

@@ -270,6 +270,25 @@ MaxOverspeedPings = 2
GridUnload = 1
#
# BaseMapLoadAllGrids
# Description: Load all grids for base maps upon load. Requires GridUnload to be 0.
# This will take around 5GB of ram upon server load, and will take some time
# to initially load the server.
# Default: 0 - (Don't pre-load all base maps, dynamically load as used)
# 1 - (Preload all grids in all base maps upon load)
BaseMapLoadAllGrids = 0
#
# InstanceMapLoadAllGrids
# Description: Load all grids for instance maps upon load. Requires GridUnload to be 0.
# Upon loading an instance map, all creatures/objects in the map will be pre-loaded
# Default: 0 - (Don't pre-load all base maps, dynamically load as used)
# 1 - (Preload all grids in the instance upon load)
InstanceMapLoadAllGrids = 0
#
# SocketTimeOutTime
# Description: Time (in milliseconds) after which a connection being idle on the character
@@ -3476,6 +3495,7 @@ Logger.server=3,Console Server
Logger.commands.gm=3,Console GM
Logger.sql.sql=5,Console DBErrors
Logger.sql.updates=3,Console Server
#Logger.mmaps=3,Server
#Logger.achievement=3,Console Server
#Logger.addon=3,Console Server