with Ada.Containers.Vectors; use Ada.Containers;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Unchecked_Deallocation; use Ada;
with Generic_Realtime_Buffer;
with Vectors_3D; use Vectors_3D;
with Rotations; use Rotations;
with Swarm_Configuration; use Swarm_Configuration;
with Swarm_Structures_Base; use Swarm_Structures_Base;
with Vehicle_Message_Type; use Vehicle_Message_Type;
with Vehicle_Task_Type; use Vehicle_Task_Type;
package Swarm_Structures is
No_Of_Buffered_Incoming_Messages : constant Positive := 10;
No_Of_Buffered_Outgoing_Messages : constant Positive := 2;
type Distance_Entries is
record
Index : Swarm_Element_Index;
Distance : Distances;
Position_Diff : Positions;
Velocity_Diff : Velocities;
end record;
pragma Warnings ("H");
function "<" (L, R : Distance_Entries) return Boolean;
pragma Warnings ("h");
package Distance_Vectors is new Vectors (Swarm_Element_Index, Distance_Entries);
package Sort_Distances is new Distance_Vectors.Generic_Sorting;
type Buffer_Size_Outgoing is mod No_Of_Buffered_Outgoing_Messages;
type Buffer_Size_Incoming is mod No_Of_Buffered_Incoming_Messages;
package Buffers_Outgoing is new Generic_Realtime_Buffer (Inter_Vehicle_Messages, Buffer_Size_Outgoing);
package Buffers_Incoming is new Generic_Realtime_Buffer (Inter_Vehicle_Messages, Buffer_Size_Incoming);
use Buffers_Outgoing;
use Buffers_Incoming;
protected type Vehicle_Comms is
procedure Send (Message : Inter_Vehicle_Messages);
entry Receive (Message : out Inter_Vehicle_Messages);
procedure Push_Message (Message : Inter_Vehicle_Messages);
procedure Fetch_Message (Message : out Inter_Vehicle_Messages);
function Has_Incoming_Messages return Boolean;
function Has_Outgoing_Messages return Boolean;
private
Sent_Messages : Buffers_Outgoing.Realtime_Buffer;
Received_Messages : Buffers_Incoming.Realtime_Buffer;
end Vehicle_Comms;
protected type Vehicle_Controls is
procedure Set_Steering (V : Vector_3D);
procedure Set_Throttle (T : Throttle_T);
function Read_Steering return Vector_3D;
function Read_Throttle return Throttle_T;
private
Steering_Direction : Vector_3D := Zero_Vector_3D;
Throttle : Throttle_T := Idle_Throttle;
end Vehicle_Controls;
type Globes_Touched_A is array (Energy_Globes_Defaults'Range) of Boolean;
No_Globes_Touched : constant Globes_Touched_A := (others => False);
type Charge_Info is record
Level : Vehicle_Charges; pragma Atomic (Level);
Charge_Time : Time; pragma Atomic (Charge_Time);
Charge_No : Natural; pragma Atomic (Charge_No);
Globes_Touched : Globes_Touched_A := No_Globes_Touched;
end record;
type Neighbours_P is access all Distance_Vectors.Vector;
type Vehicle_Comms_P is access all Vehicle_Comms;
type Vehicle_Controls_P is access all Vehicle_Controls;
type Vehicle_Task_P is access all Vehicle_Task;
type Swarm_Element_State is
record
Position : Positions; pragma Atomic (Position);
Rotation : Quaternion_Rotation; pragma Atomic (Rotation);
Velocity : Velocities; pragma Atomic (Velocity);
Acceleration : Accelerations; pragma Atomic (Acceleration);
Charge : Charge_Info;
Neighbours : Neighbours_P;
Controls : Vehicle_Controls_P;
Comms : Vehicle_Comms_P;
Process : Vehicle_Task_P;
Process_Id : Task_Id;
Last_Update : Time;
end record;
package Swarm_Vectors is new Vectors (Swarm_Element_Index, Swarm_Element_State);
procedure Free_Neighbours is new Unchecked_Deallocation (Object => Distance_Vectors.Vector, Name => Neighbours_P);
procedure Free_Controls is new Unchecked_Deallocation (Object => Vehicle_Controls, Name => Vehicle_Controls_P);
procedure Free_Comms is new Unchecked_Deallocation (Object => Vehicle_Comms, Name => Vehicle_Comms_P);
procedure Free_Process is new Unchecked_Deallocation (Object => Vehicle_Task, Name => Vehicle_Task_P);
protected Swarm_Lock is
entry Lock_Write;
entry Lock_Read;
entry Unlock_Write;
entry Unlock_Read;
private
Write_Lock : Boolean := False;
Readers : Natural := 0;
end Swarm_Lock;
protected Simulator_Tick is
entry Wait_For_Next_Tick;
procedure Tick;
private
Trigger : Boolean := False;
end Simulator_Tick;
end Swarm_Structures;