diff --git a/src/Core/Worlds/World.cs b/src/Core/Worlds/World.cs index bbcc5b8..a1b293c 100644 --- a/src/Core/Worlds/World.cs +++ b/src/Core/Worlds/World.cs @@ -28,7 +28,17 @@ public abstract class World : ISerializable /// /// An actor has been killed. /// - public event NotifyDeath? ActorKilled; + public event NotifyActorEvent? ActorKilled; + + /// + /// An actor has been added. + /// + public event NotifyActorEvent? ActorAdded; + + /// + /// An actor has been moved. + /// + public event NotifyActorMoved? ActorMoved; /// /// Get the current step. @@ -161,7 +171,7 @@ protected void Step() { _actors.Remove(a); positions.Remove(a); - ActorKilled?.Invoke(a); + ActorKilled?.Invoke(a, GetPosition(a)); } _actorsToBeRemoved.Clear(); } @@ -184,6 +194,8 @@ public void Add(Actor a, Vector3 v) { positions.Add(a, v); } + + ActorAdded?.Invoke(a, v); } /// @@ -235,6 +247,8 @@ public Vector3 GetPosition(Actor a) /// The location the actor will be moved to public void MoveTo(Actor a, Vector3 v) { + Vector3 oldPosition = GetPosition(a); + lock (_positionsLock) { if (positions.ContainsKey(a)) @@ -242,6 +256,8 @@ public void MoveTo(Actor a, Vector3 v) positions[a] = v; } } + + ActorMoved?.Invoke(a, oldPosition, v); } /// @@ -251,13 +267,9 @@ public void MoveTo(Actor a, Vector3 v) /// Direction and distance the actor will be moved public void Move(Actor a, Vector3 v) { - lock (_positionsLock) - { - if (positions.ContainsKey(a)) - { - positions[a] += v; - } - } + Vector3 oldPosition = GetPosition(a); + + MoveTo(a, oldPosition + v); } public abstract void Start(); @@ -265,5 +277,6 @@ public void Move(Actor a, Vector3 v) } public delegate void Notify(); - public delegate void NotifyDeath(Actor actor); + public delegate void NotifyActorEvent(Actor actor, Vector3 vector); + public delegate void NotifyActorMoved(Actor actor, Vector3 oldPosition, Vector3 newPosition); }