Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Oct 15, 2023
1 parent a18eae0 commit c587ffe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ public interface IManagedObject
/// Destroys the native object associated with this managed object.
/// </summary>
public void Destroy();

/// <summary>
/// Determines whether the specified managed object is equal to the current managed object.
/// </summary>
public bool Equals(IManagedObject other)
{
if (other == null) return false;
else return NativeObject == other.NativeObject;
}
}
}
13 changes: 7 additions & 6 deletions Assets/Scripts/Engine/Navigation/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Engine.Navigation
{
using System.Collections.Generic;
using Pal3.Core.Contract.Enums;

using Vector3 = UnityEngine.Vector3;
Expand All @@ -24,7 +25,7 @@ public sealed class Path

public bool IgnoreObstacle { get; private set; }

private Vector3[] _wayPoints = {};
private readonly List<Vector3> _wayPoints = new ();

private int _currentWayPointIndex;

Expand All @@ -35,7 +36,7 @@ public sealed class Path
{
Clear();

_wayPoints = wayPoints;
_wayPoints.AddRange(wayPoints);
_currentWayPointIndex = 0;

MovementMode = movementMode;
Expand All @@ -47,23 +48,23 @@ public void Clear()
{
MovementMode = 0;
EndOfPathAction = EndOfPathActionType.Idle;
_wayPoints = new Vector3[] {};
_wayPoints.Clear();
_currentWayPointIndex = 0;
}

public bool MoveToNextWayPoint()
{
return ++_currentWayPointIndex < _wayPoints.Length;
return ++_currentWayPointIndex < _wayPoints.Count;
}

public bool IsEndOfPath()
{
return !(_wayPoints.Length > 0 && _currentWayPointIndex < _wayPoints.Length);
return !(_wayPoints.Count > 0 && _currentWayPointIndex < _wayPoints.Count);
}

public Vector3[] GetAllWayPoints()
{
return _wayPoints;
return _wayPoints.ToArray();
}

public Vector3 GetCurrentWayPoint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ protected override void OnCollisionEnterGameEntity(IGameEntity otherGameEntity)

protected override void OnCollisionExitGameEntity(IGameEntity otherGameEntity)
{
// We have to compare the native object pointer instead of the game entity
// to make sure we are removing the correct collider.
_activeColliders.RemoveWhere(_ => _.ColliderGameEntity.NativeObject == otherGameEntity.NativeObject);
_activeColliders.RemoveWhere(_ => _.ColliderGameEntity.Equals(otherGameEntity));

if (_actionController.GetRigidBody() is { isKinematic: false } actorRigidbody)
{
Expand Down

0 comments on commit c587ffe

Please sign in to comment.