Skip to content

Commit

Permalink
fix: tentatively fix failure to interrupt threads on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Jun 15, 2024
1 parent 4a81eaf commit 5eaf744
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
25 changes: 6 additions & 19 deletions GameServer/Geometry/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,15 @@ public struct Position
public int Y => Coordinate.Y;
public int Z => Coordinate.Z;

private Region m_region = null;

public Region Region
{
get
{
if (m_region?.ID == RegionID)
{
return m_region;
}
m_region = WorldMgr.GetRegion(RegionID);
return m_region;
}
}
public Region Region { get; init; } = null;

public Position() { }

public static Position Create(ushort regionID, int x, int y, int z, ushort heading)
=> new() { RegionID = regionID, Coordinate = Coordinate.Create(x, y, z), Orientation = Angle.Heading(heading) };
=> new() { RegionID = regionID, Coordinate = Coordinate.Create(x, y, z), Orientation = Angle.Heading(heading), Region = WorldMgr.GetRegion(regionID) };

public static Position Create(ushort regionID, int x = 0, int y = 0, int z = 0, Angle? orientation = null)
=> new() { RegionID = regionID, Coordinate = Coordinate.Create(x, y, z), Orientation = orientation ?? Angle.Zero };
=> new() { RegionID = regionID, Coordinate = Coordinate.Create(x, y, z), Orientation = orientation ?? Angle.Zero, Region = WorldMgr.GetRegion(regionID) };

public static Position CreateInZone(ushort zoneID, int x = 0, int y = 0, int z = 0, ushort heading = 0)
{
Expand All @@ -40,10 +27,10 @@ public static Position CreateInZone(ushort zoneID, int x = 0, int y = 0, int z =
}

public static Position Create(ushort regionID, Coordinate coordinate, ushort heading = 0)
=> new() { RegionID = regionID, Coordinate = coordinate, Orientation = Angle.Heading(heading) };
=> new() { RegionID = regionID, Coordinate = coordinate, Orientation = Angle.Heading(heading), Region = WorldMgr.GetRegion(regionID) };

public static Position Create(ushort regionID, Coordinate coordinate, Angle orientation)
=> new() { RegionID = regionID, Coordinate = coordinate, Orientation = orientation };
=> new() { RegionID = regionID, Coordinate = coordinate, Orientation = orientation, Region = WorldMgr.GetRegion(regionID) };

public Position With(ushort? regionID = null, int? x = null, int? y = null, int? z = null, ushort? heading = null)
{
Expand Down Expand Up @@ -92,4 +79,4 @@ public override string ToString()

public readonly static Position Nowhere = Create(regionID: ushort.MaxValue, Coordinate.Nowhere, Angle.Zero);
public readonly static Position Zero = new();
}
}
4 changes: 2 additions & 2 deletions GameServer/gameutils/GameTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ public bool Stop()
{
while (!m_timeThread.Join(2000))
{
log.ErrorFormat("Timer Thread ({0}) can't stop after abort... maybe remaining threads going... trying again !", m_name);

try
{
log.ErrorFormat("Timer Thread ({0}) can't stop after abort... maybe remaining threads going... trying again !", m_name);

m_timeThread.Interrupt();
}
catch
Expand Down
15 changes: 3 additions & 12 deletions GameServer/world/WorldMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -983,11 +983,7 @@ public static void RegisterZone(ZoneData zoneData, ushort zoneID, ushort regionI
/// <returns>true</returns>
public static bool StartRegionMgrs()
{
m_regions.FreezeWhile(dict =>
{
foreach (Region reg in dict.Values)
reg.StartRegionMgr();
});
m_regions.FreezeWhile(dict => dict.Values.ToList()).ForEach(r => r.StartRegionMgr());
return true;
}

Expand All @@ -998,13 +994,8 @@ public static void StopRegionMgrs()
{
if (log.IsDebugEnabled)
log.Debug("Stopping region managers...");

m_regions.FreezeWhile(dict =>
{
foreach (Region reg in dict.Values)
reg.StopRegionMgr();
});

m_regions.FreezeWhile(dict => dict.Values.ToList()).ForEach(r => r.StopRegionMgr());

if (log.IsDebugEnabled)
log.Debug("Region managers stopped.");
Expand Down

0 comments on commit 5eaf744

Please sign in to comment.