Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/Core/Worlds/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ public abstract class World : ISerializable
/// <summary>
/// An actor has been killed.
/// </summary>
public event NotifyDeath? ActorKilled;
public event NotifyActorEvent? ActorKilled;

/// <summary>
/// An actor has been added.
/// </summary>
public event NotifyActorEvent? ActorAdded;

/// <summary>
/// An actor has been moved.
/// </summary>
public event NotifyActorMoved? ActorMoved;

/// <summary>
/// Get the current step.
Expand Down Expand Up @@ -161,7 +171,7 @@ protected void Step()
{
_actors.Remove(a);
positions.Remove(a);
ActorKilled?.Invoke(a);
ActorKilled?.Invoke(a, GetPosition(a));
}
_actorsToBeRemoved.Clear();
}
Expand All @@ -184,6 +194,8 @@ public void Add(Actor a, Vector3 v)
{
positions.Add(a, v);
}

ActorAdded?.Invoke(a, v);
}

/// <summary>
Expand Down Expand Up @@ -235,13 +247,17 @@ public Vector3 GetPosition(Actor a)
/// <param name="v">The location the actor will be moved to</param>
public void MoveTo(Actor a, Vector3 v)
{
Vector3 oldPosition = GetPosition(a);

lock (_positionsLock)
{
if (positions.ContainsKey(a))
{
positions[a] = v;
}
}

ActorMoved?.Invoke(a, oldPosition, v);
}

/// <summary>
Expand All @@ -251,19 +267,16 @@ public void MoveTo(Actor a, Vector3 v)
/// <param name="v">Direction and distance the actor will be moved</param>
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();
public abstract void Stop();
}

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);
}