Core/Maps: Move terrain data handling out of Map class
Port From (https://github.com/TrinityCore/TrinityCore/commit/16a06346aea16ffd6ee84081cedfdb0c75ac0b38)
This commit is contained in:
@@ -35,7 +35,8 @@ namespace Game.Collision
|
||||
Success,
|
||||
FileNotFound,
|
||||
VersionMismatch,
|
||||
ReadFromFileFailed
|
||||
ReadFromFileFailed,
|
||||
DisabledInConfig
|
||||
}
|
||||
|
||||
public class VMapManager : Singleton<VMapManager>
|
||||
@@ -46,40 +47,15 @@ namespace Game.Collision
|
||||
|
||||
public void Initialize(MultiMap<uint, uint> mapData)
|
||||
{
|
||||
iChildMapData = mapData;
|
||||
foreach (var pair in mapData)
|
||||
iParentMapData[pair.Value] = pair.Key;
|
||||
}
|
||||
|
||||
public VMAPLoadResult LoadMap(uint mapId, uint x, uint y)
|
||||
public LoadResult LoadMap(uint mapId, int x, int y)
|
||||
{
|
||||
var result = VMAPLoadResult.Ignored;
|
||||
if (IsMapLoadingEnabled())
|
||||
{
|
||||
LoadResult parentLoadResult = LoadSingleMap(mapId, x, y);
|
||||
if (parentLoadResult == LoadResult.Success || parentLoadResult == LoadResult.FileNotFound)
|
||||
{
|
||||
if (parentLoadResult == LoadResult.Success)
|
||||
result = VMAPLoadResult.OK;
|
||||
// else VMAP_LOAD_RESULT_IGNORED
|
||||
if (!IsMapLoadingEnabled())
|
||||
return LoadResult.DisabledInConfig;
|
||||
|
||||
var childMaps = iChildMapData.LookupByKey(mapId);
|
||||
foreach (uint childMapId in childMaps)
|
||||
{
|
||||
LoadResult childLoadResult = LoadSingleMap(childMapId, x, y);
|
||||
if (childLoadResult != LoadResult.Success && childLoadResult != LoadResult.FileNotFound)
|
||||
result = VMAPLoadResult.Error;
|
||||
}
|
||||
}
|
||||
else
|
||||
result = VMAPLoadResult.Error;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LoadResult LoadSingleMap(uint mapId, uint tileX, uint tileY)
|
||||
{
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree == null)
|
||||
{
|
||||
@@ -94,19 +70,10 @@ namespace Game.Collision
|
||||
instanceTree = newTree;
|
||||
}
|
||||
|
||||
return instanceTree.LoadMapTile(tileX, tileY, this);
|
||||
return instanceTree.LoadMapTile(x, y, this);
|
||||
}
|
||||
|
||||
public void UnloadMap(uint mapId, uint x, uint y)
|
||||
{
|
||||
var childMaps = iChildMapData.LookupByKey(mapId);
|
||||
foreach (uint childMapId in childMaps)
|
||||
UnloadSingleMap(childMapId, x, y);
|
||||
|
||||
UnloadSingleMap(mapId, x, y);
|
||||
}
|
||||
|
||||
void UnloadSingleMap(uint mapId, uint x, uint y)
|
||||
public void UnloadMap(uint mapId, int x, int y)
|
||||
{
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree != null)
|
||||
@@ -120,15 +87,6 @@ namespace Game.Collision
|
||||
}
|
||||
|
||||
public void UnloadMap(uint mapId)
|
||||
{
|
||||
var childMaps = iChildMapData.LookupByKey(mapId);
|
||||
foreach (uint childMapId in childMaps)
|
||||
UnloadSingleMap(childMapId);
|
||||
|
||||
UnloadSingleMap(mapId);
|
||||
}
|
||||
|
||||
void UnloadSingleMap(uint mapId)
|
||||
{
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree != null)
|
||||
@@ -329,7 +287,7 @@ namespace Game.Collision
|
||||
}
|
||||
}
|
||||
|
||||
public LoadResult ExistsMap(uint mapId, uint x, uint y)
|
||||
public LoadResult ExistsMap(uint mapId, int x, int y)
|
||||
{
|
||||
return StaticMapTree.CanLoadMap(VMapPath, mapId, x, y, this);
|
||||
}
|
||||
@@ -367,7 +325,6 @@ namespace Game.Collision
|
||||
|
||||
Dictionary<string, ManagedModel> iLoadedModelFiles = new();
|
||||
Dictionary<uint, StaticMapTree> iInstanceMapTrees = new();
|
||||
MultiMap<uint, uint> iChildMapData = new();
|
||||
Dictionary<uint, uint> iParentMapData = new();
|
||||
bool _enableLineOfSightCalc;
|
||||
bool _enableHeightCalc;
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Game.Collision
|
||||
iLoadedTiles.Clear();
|
||||
}
|
||||
|
||||
public LoadResult LoadMapTile(uint tileX, uint tileY, VMapManager vm)
|
||||
public LoadResult LoadMapTile(int tileX, int tileY, VMapManager vm)
|
||||
{
|
||||
if (iTreeValues == null)
|
||||
{
|
||||
@@ -183,7 +183,7 @@ namespace Game.Collision
|
||||
return result;
|
||||
}
|
||||
|
||||
public void UnloadMapTile(uint tileX, uint tileY, VMapManager vm)
|
||||
public void UnloadMapTile(int tileX, int tileY, VMapManager vm)
|
||||
{
|
||||
uint tileID = PackTileID(tileX, tileY);
|
||||
if (!iLoadedTiles.ContainsKey(tileID))
|
||||
@@ -233,10 +233,10 @@ namespace Game.Collision
|
||||
iLoadedTiles.Remove(tileID);
|
||||
}
|
||||
|
||||
static uint PackTileID(uint tileX, uint tileY) { return tileX << 16 | tileY; }
|
||||
static void UnpackTileID(uint ID, ref uint tileX, ref uint tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
|
||||
static uint PackTileID(int tileX, int tileY) { return (uint)(tileX << 16 | tileY); }
|
||||
static void UnpackTileID(int ID, ref int tileX, ref int tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
|
||||
|
||||
static TileFileOpenResult OpenMapTileFile(string vmapPath, uint mapID, uint tileX, uint tileY, VMapManager vm)
|
||||
static TileFileOpenResult OpenMapTileFile(string vmapPath, uint mapID, int tileX, int tileY, VMapManager vm)
|
||||
{
|
||||
TileFileOpenResult result = new();
|
||||
result.Name = vmapPath + GetTileFileName(mapID, tileX, tileY);
|
||||
@@ -265,7 +265,7 @@ namespace Game.Collision
|
||||
return result;
|
||||
}
|
||||
|
||||
public static LoadResult CanLoadMap(string vmapPath, uint mapID, uint tileX, uint tileY, VMapManager vm)
|
||||
public static LoadResult CanLoadMap(string vmapPath, uint mapID, int tileX, int tileY, VMapManager vm)
|
||||
{
|
||||
string fullname = vmapPath + VMapManager.GetMapFileName(mapID);
|
||||
if (!File.Exists(fullname))
|
||||
@@ -290,7 +290,7 @@ namespace Game.Collision
|
||||
return LoadResult.Success;
|
||||
}
|
||||
|
||||
public static string GetTileFileName(uint mapID, uint tileX, uint tileY)
|
||||
public static string GetTileFileName(uint mapID, int tileX, int tileY)
|
||||
{
|
||||
return $"{mapID:D4}_{tileY:D2}_{tileX:D2}.vmtile";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user