-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworlds.ads
99 lines (75 loc) · 3.65 KB
/
worlds.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
with Entities; use Entities;
with Vectors2D; use Vectors2D;
with Ada.Containers.Doubly_Linked_Lists;
with Links; use Links;
with Collisions; use Collisions;
package Worlds is
package EntsList is new Ada.Containers.Doubly_Linked_Lists(EntityClassAcc);
type EntsListAcc is access EntsList.List;
package LinksList is new Ada.Containers.Doubly_Linked_Lists(LinkAcc);
type LinksListAcc is access LinksList.List;
type SearchModes is (SM_Entity, SM_Environment, SM_All);
type StepModes is (Step_Normal, Step_LowRAM);
type EntCheckerAcc is access function(E : EntityClassAcc) return Boolean;
type World is tagged record
-- Access to accesses to the entities
Entities : EntsListAcc;
-- Access to accesses to the environments entities
Environments : EntsListAcc;
-- Access to accesses to the links
Links : LinksListAcc;
-- Access to collisions (note this is different from the 3 above)
Cols : ColsListAcc;
-- Entities.len + Environments.len + Links.len < MaxEntities
MaxEntities : Natural;
-- Timestep
dt : Float;
-- Inverse timestep
Invdt : Float;
-- Function called when World checks the validity of its entities
InvalidChecker : EntCheckerAcc;
-- Max speed of entities, 0.0 to disable on an axis
MaxSpeed : Vec2D := (0.0, 0.0);
-- Default static entity, useful for faking collisions
-- Its restitution is LinkTypesFactors(LTRope)
StaticEnt : EntityClassAcc := null;
end record;
pragma Pack (World);
-- init world
procedure Init(This : in out World; dt : in Float; MaxEnts : Natural := 32);
procedure Step(This : in out World; Mode : StepModes := Step_Normal);
-- clear the world (deep free)
procedure Free(This : in out World);
-- Add entity to the world
procedure AddEntity(This : in out World; Ent : not null EntityClassAcc);
-- Add env to the world
procedure AddEnvironment(This : in out World; Ent : not null EntityClassAcc);
-- Add a link between two entities (rope, spring...)
procedure LinkEntities(This : in out World; A, B : EntityClassAcc; LinkType : LinkTypes; Factor : Float := 0.0);
-- Remove all links tied to the passed entity
procedure UnlinkEntity(This : in out World; E : EntityClassAcc);
-- Increases the number of max entities by Count
procedure IncreaseMaxEntities(This : in out World; Count : Positive);
-- Gives the world a function to check if entities are valid or not
procedure SetInvalidChecker(This : in out World; Invalider : EntCheckerAcc);
-- Remove entity from the world
-- Entity is detroyed if Destroy is true
procedure RemoveEntity(This : in out World; Ent : EntityClassAcc; Destroy : Boolean);
-- Remove env from the world
-- Entity is detroyed if Destroy is true
procedure RemoveEnvironment(This : in out World; Ent : not null EntityClassAcc; Destroy : Boolean);
-- Returns the entity in which Pos is
-- If SearchMode = SM_All, searches first entities, then envs (ents are "on top")
function GetClosest(This : in out World; Pos : Vec2D; SearchMode : SearchModes := SM_All) return EntityClassAcc;
-- Get the list of entities
function GetEntities(This : in World) return EntsListAcc;
-- Get the list of envs
function GetEnvironments(This : in World) return EntsListAcc;
-- Get the list of links
function GetLinks(This : in World) return LinksListAcc;
-- Lets you set a maximum speed >= 0
-- If max speed = 0 -> no max speed on that axis
procedure SetMaxSpeed(This : in out World; Speed : Vec2D);
-- Remove invalid entities according to InvalidChecker, if not null
procedure CheckEntities(This : in out World);
end Worlds;