Skip to content

Commit

Permalink
cleaner world death
Browse files Browse the repository at this point in the history
  • Loading branch information
andylippitt committed Mar 12, 2019
1 parent 7633890 commit 3afcdce
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Game.Engine/Core/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ public void Destroy()
Fleet = null;
}

World.Actors.Remove(this);
if (this.Connection != null)
try
{
((IDisposable)this.Connection).Dispose();
} catch (Exception) { }
this.Connection = null;

World.Actors.Remove(this);

var worldPlayers = GetWorldPlayers(World);
worldPlayers.Remove(this);
}
Expand Down
13 changes: 9 additions & 4 deletions Game.Engine/Core/SystemActors/Advertisement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Game.Engine.Core.SystemActors
{
using System;
using System.Linq;

public class Advertisement : SystemActorBase
Expand All @@ -16,11 +15,17 @@ protected override void CycleThink()

if (World.AdvertisedPlayerCount > 0)
EmptySince = World.Time;
}


if (World.Hook.AutoRemoveOnEmptyThreshold > 0 && EmptySince > 0 && (World.Time - EmptySince) > World.Hook.AutoRemoveOnEmptyThreshold)
{
protected override void CycleCreateDestroy()
{
base.CycleCreateDestroy();
if (World.Hook.AutoRemoveOnEmptyThreshold > 0
&& EmptySince > 0
&& (World.Time - EmptySince) > World.Hook.AutoRemoveOnEmptyThreshold
) {
Worlds.Destroy(World.WorldKey);
EmptySince = 0;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions Game.Engine/Core/SystemActors/SystemActorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ public abstract class SystemActorBase : IActor
public World World = null;
protected long SleepUntil = 0;
protected int CycleMS = 1000;
private bool RunningThisStep = false;


public virtual void CreateDestroy()
{
if (RunningThisStep)
CycleCreateDestroy();
}

public virtual void Destroy()
Expand All @@ -30,11 +34,14 @@ public virtual void Think()
{
if (World != null && World.Time > SleepUntil)
{
RunningThisStep = true;
CycleThink();

if (World != null)
SleepUntil = World.Time + CycleMS;
}
else
RunningThisStep = false;
}
}
}
1 change: 1 addition & 0 deletions Game.Engine/Networking/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ private async Task HandleIncomingMessage(NetQuantum quantum)
if (player != null)
{
player.PendingDestruction = true;
player.Connection = null;
}
}
}
Expand Down

0 comments on commit 3afcdce

Please sign in to comment.