Entity Persistence Refactoring
Entities refactored to enable robust persistence Entities detect stale data references and reload behaviors
This commit is contained in:
parent
87acc75b96
commit
6aeb2ae280
29 changed files with 299 additions and 202 deletions
|
|
@ -7,25 +7,23 @@ using Random = Unity.Mathematics.Random;
|
|||
|
||||
public class AgentController
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public Guid Entity { get; }
|
||||
public EntityAgent EntityAgent { get; }
|
||||
public GameContext Context { get; }
|
||||
public Guid Zone { get; set; }
|
||||
|
||||
public Guid HomeZone;
|
||||
|
||||
private Locomotion _locomotion;
|
||||
private VelocityMatch _velocityMatch;
|
||||
private Random _random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
|
||||
private Guid _targetOrbit;
|
||||
|
||||
public AgentController(GameContext context, Guid zone, Entity entity)
|
||||
public AgentController(GameContext context, Guid zone, Guid entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Zone = zone;
|
||||
Context = context;
|
||||
EntityAgent = new EntityAgent(context, zone, entity);
|
||||
_locomotion = new Locomotion(entity);
|
||||
EntityAgent = new EntityAgent(context, entity, zone, Guid.Empty);
|
||||
_locomotion = new Locomotion(context, entity);
|
||||
_velocityMatch = new VelocityMatch(context, entity);
|
||||
_velocityMatch.OnMatch += () =>
|
||||
{
|
||||
|
|
@ -44,6 +42,7 @@ public class AgentController
|
|||
// $"Agent Distance: {distance} " +
|
||||
// $"Turnaround Distance: {_stoppingDistance + _turnaroundDistance} " +
|
||||
// $"Objective: {_objective.Key.ID.ToString().Substring(0, 8)}");
|
||||
var entity = Context.Cache.Get<Entity>(Entity);
|
||||
|
||||
if (EntityAgent.CurrentBehavior == _locomotion)
|
||||
{
|
||||
|
|
@ -51,7 +50,7 @@ public class AgentController
|
|||
_velocityMatch.TargetOrbit = _targetOrbit;
|
||||
var matchDistanceTime = _velocityMatch.MatchDistanceTime;
|
||||
_locomotion.Objective = Context.GetOrbitPosition(_targetOrbit) + Context.GetOrbitVelocity(_targetOrbit) * matchDistanceTime.y;
|
||||
var distance = length(_locomotion.Objective - Entity.Position);
|
||||
var distance = length(_locomotion.Objective - entity.Position);
|
||||
if (distance < matchDistanceTime.x)
|
||||
EntityAgent.CurrentBehavior = _velocityMatch;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue