Control Modules & Job System

Agent behaviors are no longer hard coded but instead created by equippable control modules
Game Context has a job system which assigns appropriate tasks to drone control modules
This commit is contained in:
hyperion51 2020-05-07 03:53:54 +01:00
commit ab8aa5fb9a
27 changed files with 480 additions and 190 deletions

View file

@ -9,35 +9,28 @@ public class VelocityMatch : AgentBehavior
{
public event Action OnMatch;
public Guid TargetOrbit;
private Guid _entity;
private IAnalogBehavior _thrust;
private IAnalogBehavior _turning;
private const float TurningSensitivity = 1;
private const float ThrustSensitivity = 1;
private Thruster _thrust;
private Turning _turning;
private const float TargetThreshold = .1f;
private GameContext _context;
public VelocityMatch(GameContext context, Guid entity)
public VelocityMatch(GameContext context, Entity entity, ControllerData controllerData) : base(context, entity, controllerData)
{
_context = context;
_entity = entity;
var entityObject = _context.Cache.Get<Entity>(_entity);
_thrust = entityObject.Axes.Keys.FirstOrDefault(x => x is Thruster);
_turning = entityObject.Axes.Keys.FirstOrDefault(x => x is Turning);
_thrust = Entity.Axes.Keys.FirstOrDefault(x => x is Thruster) as Thruster;
_turning = Entity.Axes.Keys.FirstOrDefault(x => x is Turning) as Turning;
}
public override void Update(float delta)
{
var entity = _context.Cache.Get<Entity>(_entity);
if (TargetOrbit != Guid.Empty && _thrust != null && _turning != null)
{
var deltaV = _context.GetOrbitVelocity(TargetOrbit) - entity.Velocity;
var deltaV = _context.GetOrbitVelocity(TargetOrbit) - Entity.Velocity;
if(length(deltaV) < TargetThreshold)
OnMatch?.Invoke();
var angleDiff = entity.Direction.AngleDiff(deltaV);
entity.Axes[_turning] = clamp(-angleDiff * TurningSensitivity, -1, 1);
entity.Axes[_thrust] = saturate(length(pow(saturate(dot(normalize(entity.Direction),normalize(deltaV))), 8)*length(deltaV))*ThrustSensitivity);
Entity.Axes[_turning] = TurningInput(deltaV);
Entity.Axes[_thrust] = ThrustInput(deltaV);
}
}
@ -45,15 +38,14 @@ public class VelocityMatch : AgentBehavior
{
get
{
var entity = _context.Cache.Get<Entity>(_entity);
var velocity = length(entity.Velocity);
var deltaV = _context.GetOrbitVelocity(TargetOrbit) - entity.Velocity;
var velocity = length(Entity.Velocity);
var deltaV = _context.GetOrbitVelocity(TargetOrbit) - Entity.Velocity;
var stoppingTime = length(deltaV) / (_context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, entity) / entity.Mass);
var stoppingTime = length(deltaV) / (_thrust.Thrust / Entity.Mass);
var stoppingDistance = stoppingTime * (velocity / 2);
var angleDiff = entity.Direction.AngleDiff(deltaV);
var turnaroundTime = angleDiff / (_context.Evaluate((_turning.Data as TurningData).Torque, _turning.Item, entity) / entity.Mass);
var angleDiff = Entity.Direction.AngleDiff(deltaV);
var turnaroundTime = angleDiff / (_turning.Torque / Entity.Mass);
var turnaroundDistance = turnaroundTime * velocity;
return float2(stoppingDistance + turnaroundDistance, stoppingTime + turnaroundTime);