Some Cleanups
This commit is contained in:
+26
-28
@@ -43,35 +43,33 @@ namespace Game.Maps
|
||||
if (!File.Exists(filename))
|
||||
return LoadResult.FileNotFound;
|
||||
|
||||
using (BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
||||
using BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read));
|
||||
MapFileHeader header = reader.Read<MapFileHeader>();
|
||||
if (header.mapMagic != MapConst.MapMagic || (header.versionMagic != MapConst.MapVersionMagic && header.versionMagic != MapConst.MapVersionMagic2)) // Hack for some different extractors using v2.0 header
|
||||
{
|
||||
MapFileHeader header = reader.Read<MapFileHeader>();
|
||||
if (header.mapMagic != MapConst.MapMagic || (header.versionMagic != MapConst.MapVersionMagic && header.versionMagic != MapConst.MapVersionMagic2)) // Hack for some different extractors using v2.0 header
|
||||
{
|
||||
Log.outError(LogFilter.Maps, $"Map file '{filename}' is from an incompatible map version. Please recreate using the mapextractor.");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.areaMapOffset != 0 && !LoadAreaData(reader, header.areaMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map area data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.heightMapOffset != 0 && !LoadHeightData(reader, header.heightMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map height data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.liquidMapOffset != 0 && !LoadLiquidData(reader, header.liquidMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map liquids data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
return LoadResult.Success;
|
||||
Log.outError(LogFilter.Maps, $"Map file '{filename}' is from an incompatible map version. Please recreate using the mapextractor.");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.areaMapOffset != 0 && !LoadAreaData(reader, header.areaMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map area data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.heightMapOffset != 0 && !LoadHeightData(reader, header.heightMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map height data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
if (header.liquidMapOffset != 0 && !LoadLiquidData(reader, header.liquidMapOffset))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Error loading map liquids data");
|
||||
return LoadResult.ReadFromFileFailed;
|
||||
}
|
||||
|
||||
return LoadResult.Success;
|
||||
}
|
||||
|
||||
public void UnloadData()
|
||||
@@ -450,7 +448,7 @@ namespace Game.Maps
|
||||
float gx = x - ((int)gridCoord.X_coord - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;
|
||||
float gy = y - ((int)gridCoord.Y_coord - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;
|
||||
|
||||
uint quarterIndex = 0;
|
||||
uint quarterIndex;
|
||||
if (Convert.ToBoolean(doubleGridY & 1))
|
||||
{
|
||||
if (Convert.ToBoolean(doubleGridX & 1))
|
||||
|
||||
@@ -2156,7 +2156,7 @@ namespace Game.Maps
|
||||
{
|
||||
me = creature;
|
||||
m_range = (dist == 0 ? 9999 : dist);
|
||||
m_force = (dist == 0 ? false : true);
|
||||
m_force = (dist != 0);
|
||||
}
|
||||
|
||||
public bool Invoke(Unit u)
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace Game.Maps
|
||||
if (GetId() != mapId || player == null)
|
||||
return null;
|
||||
|
||||
Map map = null;
|
||||
uint newInstanceId = 0; // instanceId of the resulting map
|
||||
Map map;
|
||||
uint newInstanceId; // instanceId of the resulting map
|
||||
|
||||
if (IsBattlegroundOrArena())
|
||||
{
|
||||
@@ -124,7 +124,7 @@ namespace Game.Maps
|
||||
return (map && map.GetId() == GetId()) ? map : null; // is this check necessary? or does MapInstanced only find instances of itself?
|
||||
}
|
||||
|
||||
InstanceBind groupBind = null;
|
||||
InstanceBind groupBind;
|
||||
Group group = player.GetGroup();
|
||||
// use the player's difficulty setting (it may not be the same as the group's)
|
||||
if (group)
|
||||
|
||||
@@ -57,31 +57,29 @@ namespace Game
|
||||
return false;
|
||||
}
|
||||
|
||||
using (BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read), Encoding.UTF8))
|
||||
using BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read), Encoding.UTF8);
|
||||
Detour.dtNavMeshParams Params = new();
|
||||
Params.orig[0] = reader.ReadSingle();
|
||||
Params.orig[1] = reader.ReadSingle();
|
||||
Params.orig[2] = reader.ReadSingle();
|
||||
|
||||
Params.tileWidth = reader.ReadSingle();
|
||||
Params.tileHeight = reader.ReadSingle();
|
||||
Params.maxTiles = reader.ReadInt32();
|
||||
Params.maxPolys = reader.ReadInt32();
|
||||
|
||||
Detour.dtNavMesh mesh = new();
|
||||
if (Detour.dtStatusFailed(mesh.init(Params)))
|
||||
{
|
||||
Detour.dtNavMeshParams Params = new();
|
||||
Params.orig[0] = reader.ReadSingle();
|
||||
Params.orig[1] = reader.ReadSingle();
|
||||
Params.orig[2] = reader.ReadSingle();
|
||||
|
||||
Params.tileWidth = reader.ReadSingle();
|
||||
Params.tileHeight = reader.ReadSingle();
|
||||
Params.maxTiles = reader.ReadInt32();
|
||||
Params.maxPolys = reader.ReadInt32();
|
||||
|
||||
Detour.dtNavMesh mesh = new();
|
||||
if (Detour.dtStatusFailed(mesh.init(Params)))
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {0:D4} from file {1}", mapId, filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.outInfo(LogFilter.Maps, "MMAP:loadMapData: Loaded {0:D4}.mmap", mapId);
|
||||
|
||||
// store inside our map list
|
||||
loadedMMaps[mapId] = new MMapData(mesh);
|
||||
return true;
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {0:D4} from file {1}", mapId, filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.outInfo(LogFilter.Maps, "MMAP:loadMapData: Loaded {0:D4}.mmap", mapId);
|
||||
|
||||
// store inside our map list
|
||||
loadedMMaps[mapId] = new MMapData(mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint PackTileID(uint x, uint y)
|
||||
@@ -133,38 +131,36 @@ namespace Game
|
||||
return false;
|
||||
}
|
||||
|
||||
using (BinaryReader reader = new(new FileStream(fileName, FileMode.Open, FileAccess.Read)))
|
||||
using BinaryReader reader = new(new FileStream(fileName, FileMode.Open, FileAccess.Read));
|
||||
MmapTileHeader fileHeader = reader.Read<MmapTileHeader>();
|
||||
if (fileHeader.mmapMagic != MapConst.mmapMagic)
|
||||
{
|
||||
MmapTileHeader fileHeader = reader.Read<MmapTileHeader>();
|
||||
if (fileHeader.mmapMagic != MapConst.mmapMagic)
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: Bad header in mmap {0:D4}{1:D2}{2:D2}.mmtile", mapId, x, y);
|
||||
return false;
|
||||
}
|
||||
if (fileHeader.mmapVersion != MapConst.mmapVersion)
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: {0:D4}{1:D2}{2:D2}.mmtile was built with generator v{3}, expected v{4}",
|
||||
mapId, x, y, fileHeader.mmapVersion, MapConst.mmapVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
var bytes = reader.ReadBytes((int)fileHeader.size);
|
||||
Detour.dtRawTileData data = new();
|
||||
data.FromBytes(bytes, 0);
|
||||
|
||||
ulong tileRef = 0;
|
||||
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
|
||||
if (Detour.dtStatusSucceed(mmap.navMesh.addTile(data, 1, 0, ref tileRef)))
|
||||
{
|
||||
mmap.loadedTileRefs.Add(packedGridPos, tileRef);
|
||||
++loadedTiles;
|
||||
Log.outInfo(LogFilter.Maps, "MMAP:loadMap: Loaded mmtile {0:D4}[{1:D2}, {2:D2}]", mapId, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: Could not load {0:D4}{1:D2}{2:D2}.mmtile into navmesh", mapId, x, y);
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: Bad header in mmap {0:D4}{1:D2}{2:D2}.mmtile", mapId, x, y);
|
||||
return false;
|
||||
}
|
||||
if (fileHeader.mmapVersion != MapConst.mmapVersion)
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: {0:D4}{1:D2}{2:D2}.mmtile was built with generator v{3}, expected v{4}",
|
||||
mapId, x, y, fileHeader.mmapVersion, MapConst.mmapVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
var bytes = reader.ReadBytes((int)fileHeader.size);
|
||||
Detour.dtRawTileData data = new();
|
||||
data.FromBytes(bytes, 0);
|
||||
|
||||
ulong tileRef = 0;
|
||||
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
|
||||
if (Detour.dtStatusSucceed(mmap.navMesh.addTile(data, 1, 0, ref tileRef)))
|
||||
{
|
||||
mmap.loadedTileRefs.Add(packedGridPos, tileRef);
|
||||
++loadedTiles;
|
||||
Log.outInfo(LogFilter.Maps, "MMAP:loadMap: Loaded mmtile {0:D4}[{1:D2}, {2:D2}]", mapId, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.outError(LogFilter.Maps, "MMAP:loadMap: Could not load {0:D4}{1:D2}{2:D2}.mmtile into navmesh", mapId, x, y);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LoadMapInstance(string basePath, uint mapId, uint instanceId)
|
||||
@@ -235,8 +231,7 @@ namespace Game
|
||||
ulong tileRef = mmap.loadedTileRefs[packedGridPos];
|
||||
|
||||
// unload, and mark as non loaded
|
||||
Detour.dtRawTileData data;
|
||||
if (Detour.dtStatusFailed(mmap.navMesh.removeTile(tileRef, out data)))
|
||||
if (Detour.dtStatusFailed(mmap.navMesh.removeTile(tileRef, out _)))
|
||||
{
|
||||
// this is technically a memory leak
|
||||
// if the grid is later reloaded, dtNavMesh.addTile will return error but no extra memory is used
|
||||
@@ -270,8 +265,7 @@ namespace Game
|
||||
{
|
||||
uint x = (i.Key >> 16);
|
||||
uint y = (i.Key & 0x0000FFFF);
|
||||
Detour.dtRawTileData data;
|
||||
if (Detour.dtStatusFailed(mmap.navMesh.removeTile(i.Value, out data)))
|
||||
if (Detour.dtStatusFailed(mmap.navMesh.removeTile(i.Value, out _)))
|
||||
Log.outError(LogFilter.Maps, "MMAP:unloadMap: Could not unload {0:D4}{1:D2}{2:D2}.mmtile from navmesh", mapId, x, y);
|
||||
else
|
||||
{
|
||||
|
||||
+18
-23
@@ -119,20 +119,18 @@ namespace Game.Maps
|
||||
// tile list is optional
|
||||
if (File.Exists(tileListName))
|
||||
{
|
||||
using (var reader = new BinaryReader(new FileStream(tileListName, FileMode.Open, FileAccess.Read)))
|
||||
using var reader = new BinaryReader(new FileStream(tileListName, FileMode.Open, FileAccess.Read));
|
||||
var mapMagic = reader.ReadUInt32();
|
||||
var versionMagic = reader.ReadUInt32();
|
||||
if (mapMagic == MapConst.MapMagic && versionMagic == MapConst.MapVersionMagic)
|
||||
{
|
||||
var mapMagic = reader.ReadUInt32();
|
||||
var versionMagic = reader.ReadUInt32();
|
||||
if (mapMagic == MapConst.MapMagic && versionMagic == MapConst.MapVersionMagic)
|
||||
{
|
||||
var build = reader.ReadUInt32();
|
||||
byte[] tilesData = reader.ReadArray<byte>(MapConst.MaxGrids * MapConst.MaxGrids);
|
||||
for (uint gx = 0; gx < MapConst.MaxGrids; ++gx)
|
||||
for (uint gy = 0; gy < MapConst.MaxGrids; ++gy)
|
||||
i_gridFileExists[(int)(gx * MapConst.MaxGrids + gy)] = tilesData[(int)(gx * MapConst.MaxGrids + gy)] == 49; // char of 1
|
||||
var build = reader.ReadUInt32();
|
||||
byte[] tilesData = reader.ReadArray<byte>(MapConst.MaxGrids * MapConst.MaxGrids);
|
||||
for (uint gx = 0; gx < MapConst.MaxGrids; ++gx)
|
||||
for (uint gy = 0; gy < MapConst.MaxGrids; ++gy)
|
||||
i_gridFileExists[(int)(gx * MapConst.MaxGrids + gy)] = tilesData[(int)(gx * MapConst.MaxGrids + gy)] == 49; // char of 1
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,17 +157,15 @@ namespace Game.Maps
|
||||
return false;
|
||||
}
|
||||
|
||||
using (var reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read)))
|
||||
using var reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
|
||||
var header = reader.Read<MapFileHeader>();
|
||||
if (header.mapMagic != MapConst.MapMagic || (header.versionMagic != MapConst.MapVersionMagic && header.versionMagic != MapConst.MapVersionMagic2)) // Hack for some different extractors using v2.0 header
|
||||
{
|
||||
var header = reader.Read<MapFileHeader>();
|
||||
if (header.mapMagic != MapConst.MapMagic || (header.versionMagic != MapConst.MapVersionMagic && header.versionMagic != MapConst.MapVersionMagic2)) // Hack for some different extractors using v2.0 header
|
||||
{
|
||||
Log.outError(LogFilter.Maps, "Map file '{0}' is from an incompatible map version ({1}), {2} is expected. Please recreate using the mapextractor.",
|
||||
fileName, header.versionMagic, MapConst.MapVersionMagic);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
Log.outError(LogFilter.Maps, "Map file '{0}' is from an incompatible map version ({1}), {2} is expected. Please recreate using the mapextractor.",
|
||||
fileName, header.versionMagic, MapConst.MapVersionMagic);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExistVMap(uint mapid, uint gx, uint gy)
|
||||
@@ -1004,7 +1000,7 @@ namespace Game.Maps
|
||||
bool CheckGridIntegrity<T>(T obj, bool moved) where T : WorldObject
|
||||
{
|
||||
Cell cur_cell = obj.GetCurrentCell();
|
||||
Cell xy_cell = new Cell(obj.GetPositionX(), obj.GetPositionY());
|
||||
Cell xy_cell = new(obj.GetPositionX(), obj.GetPositionY());
|
||||
if (xy_cell != cur_cell)
|
||||
{
|
||||
//$"grid[{GetGridX()}, {GetGridY()}]cell[{GetCellX()}, {GetCellY()}]";
|
||||
@@ -4966,7 +4962,6 @@ namespace Game.Maps
|
||||
public Dictionary<ulong, CreatureGroup> CreatureGroupHolder = new();
|
||||
internal uint i_InstanceId;
|
||||
long i_gridExpiry;
|
||||
List<WorldObject> i_objects = new();
|
||||
bool i_scriptLock;
|
||||
|
||||
public int m_VisibilityNotifyPeriod;
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace Game.Entities
|
||||
MapRecord mEntry = CliDB.MapStorage.LookupByKey(mapid);
|
||||
|
||||
if (startUp)
|
||||
return mEntry != null ? true : false;
|
||||
return mEntry != null;
|
||||
else
|
||||
return mEntry != null && (!mEntry.IsDungeon() || Global.ObjectMgr.GetInstanceTemplate(mapid) != null);
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ namespace Game.Maps
|
||||
|
||||
// Add extra points to allow derivative calculations for all path nodes
|
||||
allPoints.Insert(0, allPoints.First().lerp(allPoints[1], -0.2f));
|
||||
allPoints.Add(allPoints.Last().lerp(allPoints[allPoints.Count - 2], -0.2f));
|
||||
allPoints.Add(allPoints.Last().lerp(allPoints[allPoints.Count - 2], -1.0f));
|
||||
allPoints.Add(allPoints.Last().lerp(allPoints[^2], -0.2f));
|
||||
allPoints.Add(allPoints.Last().lerp(allPoints[^2], -1.0f));
|
||||
|
||||
SplineRawInitializer initer = new(allPoints);
|
||||
Spline orientationSpline = new();
|
||||
@@ -204,7 +204,7 @@ namespace Game.Maps
|
||||
int extra = !keyFrames[i - 1].Teleport ? 1 : 0;
|
||||
Spline spline = new();
|
||||
Span<Vector3> span = splinePath.ToArray();
|
||||
spline.InitSpline(span.Slice(start), i - start + extra, Spline.EvaluationMode.Catmullrom);
|
||||
spline.InitSpline(span[start..], i - start + extra, Spline.EvaluationMode.Catmullrom);
|
||||
spline.InitLengths();
|
||||
for (int j = start; j < i + extra; ++j)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user