8
8
#include " DifferentialEq.hpp"
9
9
#include " VectorMaths.hpp"
10
10
11
- constexpr int WIDTH = 8 ; // metres
12
- constexpr int HEIGHT = 6 ; // metres
11
+ constexpr int WIDTH = 9 ; // metres
12
+ constexpr int HEIGHT = 9 ; // metres
13
13
constexpr int SCALE = 100 ;
14
- constexpr int DELAY = 5000 ;
14
+ constexpr int DELAY = 0 ;
15
15
16
16
using vecType = std::array<float , 2 >;
17
17
@@ -20,20 +20,45 @@ void init(SDL_Window* &win, SDL_Renderer* &render, std::vector<Actor> &actors) {
20
20
win = SDL_CreateWindow (" SYCL Crowd Simulation" , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE, HEIGHT * SCALE, SDL_WINDOW_SHOWN);
21
21
render = SDL_CreateRenderer (win, -1 , SDL_RENDERER_ACCELERATED);
22
22
23
- actors.push_back (Actor{{4 , 2 },
24
- {0.01 , 0.01 },
25
- {0.02 , 0.02 },
26
- {8 , 2 },
27
- 50 , 0.05 });
28
- actors.push_back (Actor{{4.5 , 2 },
29
- {-0.02 , -0.02 },
30
- {-0.03 , -0.03 },
31
- {1 , 2 },
32
- 60 , 0.08 });
33
-
34
- // Make actor move towards destination
35
- // actors[0].setVelocity(velToPoint(0.01, actors[0].getPos(), actors[0].getDestination()));
36
- // actors[1].setVelocity(velToPoint(0.008, actors[1].getPos(), actors[1].getDestination()));
23
+ for (int i = 0 ; i < 5 ; i++) {
24
+ for (int j = 0 ; j < 5 ; j++) {
25
+ actors.push_back (Actor{{float (0.5 + (i * 0.5 )), float (0.5 + (j * 0.5 ))},
26
+ {0.01 , 0.01 },
27
+ {0.02 , 0.02 },
28
+ {float (6.5 + (i * 0.5 )), float (6.5 + (j * 0.5 ))},
29
+ 50 , 0.05 , false , {255 , 0 , 0 }});
30
+ }
31
+ }
32
+
33
+ for (int i = 0 ; i < 5 ; i++) {
34
+ for (int j = 0 ; j < 5 ; j++) {
35
+ actors.push_back (Actor{{float (6.5 + (i * 0.5 )), float (0.5 + (j * 0.5 ))},
36
+ {0.01 , 0.01 },
37
+ {0.02 , 0.02 },
38
+ {float (0.5 + (i * 0.5 )), float (6.5 + (j * 0.5 ))},
39
+ 50 , 0.05 , false , {0 , 255 , 0 }});
40
+ }
41
+ }
42
+
43
+ for (int i = 0 ; i < 5 ; i++) {
44
+ for (int j = 0 ; j < 5 ; j++) {
45
+ actors.push_back (Actor{{float (6.5 + (i * 0.5 )), float (6.5 + (j * 0.5 ))},
46
+ {0.01 , 0.01 },
47
+ {0.02 , 0.02 },
48
+ {float (0.5 + (i * 0.5 )), float (0.5 + (j * 0.5 ))},
49
+ 50 , 0.05 , false , {0 , 0 , 255 }});
50
+ }
51
+ }
52
+
53
+ for (int i = 0 ; i < 5 ; i++) {
54
+ for (int j = 0 ; j < 5 ; j++) {
55
+ actors.push_back (Actor{{float (0.5 + (i * 0.5 )), float (6.5 + (j * 0.5 ))},
56
+ {0.01 , 0.01 },
57
+ {0.02 , 0.02 },
58
+ {float (6.5 + (i * 0.5 )), float (0.5 + (j * 0.5 ))},
59
+ 50 , 0.05 , false , {150 , 150 , 150 }});
60
+ }
61
+ }
37
62
}
38
63
39
64
void drawCircle (SDL_Renderer* &render, SDL_Point center, int radius, SDL_Color color) {
@@ -63,28 +88,21 @@ void update(sycl::queue myQueue, std::vector<Actor> &actors, Room room) {
63
88
auto out = sycl::stream{1024 , 768 , cgh};
64
89
65
90
cgh.parallel_for (sycl::range<1 >{actors.size ()}, [=](sycl::id<1 > index) {
66
- differentialEq (index, actorAcc, wallsAcc, out);
91
+ if (!actorAcc[index].getAtDestination ()) {
92
+ differentialEq (index, actorAcc, wallsAcc, out);
93
+ }
67
94
});
68
95
}).wait ();
69
-
70
- // myQueue.submit([&](sycl::handler& cgh) {
71
- // auto actorAcc = actorBuf.get_access<sycl::access::mode::read_write>(cgh);
72
-
73
- // cgh.parallel_for(sycl::range<1>{actors.size()}, [=](sycl::id<1> index) {
74
- // Actor current = actorAcc[index];
75
- // actorAcc[index].setPos(current.getPos() + current.getVelocity());
76
- // });
77
- // }).wait();
78
96
}
79
97
80
98
void draw (SDL_Renderer* &render, std::vector<Actor> actors, Room room) {
81
99
SDL_SetRenderDrawColor (render, 255 , 255 , 255 , 255 );
82
100
SDL_RenderClear (render);
83
101
84
- SDL_Color red = {255 , 0 , 0 , 255 };
85
102
for (Actor actor : actors) {
86
103
SDL_Point pos = {int (actor.getPos ()[0 ] * SCALE), int (actor.getPos ()[1 ] * SCALE)};
87
- drawCircle (render, pos, actor.getRadius () * SCALE, red);
104
+ SDL_Color actorColor = {Uint8 (actor.getColor ()[0 ]), Uint8 (actor.getColor ()[1 ]), Uint8 (actor.getColor ()[2 ]), 255 };
105
+ drawCircle (render, pos, actor.getRadius () * SCALE, actorColor);
88
106
}
89
107
90
108
SDL_SetRenderDrawColor (render, 0 , 0 , 0 , 255 );
@@ -95,9 +113,7 @@ void draw(SDL_Renderer* &render, std::vector<Actor> actors, Room room) {
95
113
96
114
SDL_SetRenderDrawColor (render, 0 , 255 , 0 , 255 );
97
115
SDL_Rect r;
98
- r.x = 690 ; r.y = 190 ; r.w = 20 ; r.h = 20 ;
99
- SDL_RenderDrawRect (render, &r);
100
- r.x = 90 ; r.y = 190 ; r.w = 20 ; r.h = 20 ;
116
+ r.x = 35 ; r.y = 195 ; r.w = 10 ; r.h = 10 ;
101
117
SDL_RenderDrawRect (render, &r);
102
118
103
119
SDL_RenderPresent (render);
@@ -114,12 +130,25 @@ int main() {
114
130
SDL_Renderer* render = NULL ;
115
131
116
132
std::vector<Actor> actors;
117
- Room room = Room ({{vecType{0.5 , 0.5 }, vecType{0.5 , 1.5 }},
118
- {vecType{0.5 , 2.5 }, vecType{0.5 , 5.5 }},
119
- {vecType{0.5 , 5.5 }, vecType{7.5 , 5.5 }},
120
- {vecType{7.5 , 5.5 }, vecType{7.5 , 0.5 }},
121
- {vecType{7.5 , 0.5 }, vecType{0.5 , 0.5 }}
133
+ Room room = Room ({{vecType{3 , 3 }, vecType{4.25 , 3 }},
134
+ {vecType{4.25 , 3 }, vecType{4.25 , 4.25 }},
135
+ {vecType{4.25 , 4.25 }, vecType{3 , 4.25 }},
136
+ {vecType{3 , 4.25 }, vecType{3 , 3 }},
137
+ {vecType{4.75 , 3 }, vecType{6 , 3 }},
138
+ {vecType{6 , 3 }, vecType{6 , 4.25 }},
139
+ {vecType{6 , 4.25 }, vecType{4.75 , 4.25 }},
140
+ {vecType{4.75 , 4.25 }, vecType{4.75 , 3 }},
141
+ {vecType{3 , 4.75 }, vecType{4.25 , 4.75 }},
142
+ {vecType{4.25 , 4.75 }, vecType{4.25 , 6 }},
143
+ {vecType{4.25 , 6 }, vecType{3 , 6 }},
144
+ {vecType{3 , 6 }, vecType{3 , 4.75 }},
145
+ {vecType{4.75 , 4.75 }, vecType{6 , 4.75 }},
146
+ {vecType{6 , 4.75 }, vecType{6 , 6 }},
147
+ {vecType{6 , 6 }, vecType{4.75 , 6 }},
148
+ {vecType{4.75 , 6 }, vecType{4.75 , 4.75 }},
122
149
});
150
+ // Room room = Room({{vecType{2, 3.5}, vecType{6, 3.5}}});
151
+ // Room room = Room({{vecType{3.5, 0.5}, vecType{4.5, 5.5}}});
123
152
124
153
sycl::queue myQueue{sycl::gpu_selector ()};
125
154
@@ -131,13 +160,6 @@ int main() {
131
160
bool isQuit = false ;
132
161
SDL_Event event;
133
162
134
- // std::cout << distanceToWall(GeometricVector({-3, 1}), {GeometricVector({1, 2}), GeometricVector({4, 0})});
135
-
136
- vecType s = {0.01 , 5.2 };
137
- vecType r = {8.7 , 9.9 };
138
- vecType opp = s / 0.5 ;
139
- std::cout << opp[0 ] << " , " << opp[1 ] << std::endl << std::endl;
140
-
141
163
while (!isQuit) {
142
164
if (SDL_PollEvent (&event)) {
143
165
if (event.type == SDL_QUIT) {
0 commit comments