18
18
19
19
uint GLOBALSEED;
20
20
21
- void init (int &SCALE, int &DELAY, SDL_Window *&win, SDL_Renderer *&render,
21
+ void init (int &SCALE, int &DELAY,
22
22
std::vector<Actor> &actors, Room &room, std::vector<Path> &paths,
23
23
int argc, char **argv) {
24
24
int WIDTH;
@@ -44,12 +44,6 @@ void init(int &SCALE, int &DELAY, SDL_Window *&win, SDL_Renderer *&render,
44
44
actor.setSeed (GLOBALSEED);
45
45
}
46
46
47
- // Initialise SDL
48
- SDL_Init (SDL_INIT_VIDEO);
49
- win = SDL_CreateWindow (" SYCL Crowd Simulation" , SDL_WINDOWPOS_UNDEFINED,
50
- SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE,
51
- HEIGHT * SCALE, SDL_WINDOW_SHOWN);
52
- render = SDL_CreateRenderer (win, -1 , SDL_RENDERER_ACCELERATED);
53
47
}
54
48
55
49
void drawCircle (SDL_Renderer *&render, SDL_Point center, int radius,
@@ -174,8 +168,8 @@ int main(int argc, char *argv[]) {
174
168
int SCALE;
175
169
int DELAY;
176
170
177
- SDL_Window *win;
178
- SDL_Renderer *render;
171
+ // SDL_Window *win;
172
+ // SDL_Renderer *render;
179
173
180
174
std::vector<Actor> actors;
181
175
Room room = Room ({});
@@ -189,7 +183,7 @@ int main(int argc, char *argv[]) {
189
183
190
184
sycl::queue myQueue{sycl::gpu_selector (), asyncHandler};
191
185
192
- init (SCALE, DELAY, win, render, actors, room, paths, argc, argv);
186
+ init (SCALE, DELAY, actors, room, paths, argc, argv);
193
187
194
188
// Buffer creation
195
189
auto actorBuf = sycl::buffer<Actor>(actors.data (), actors.size ());
@@ -199,76 +193,76 @@ int main(int argc, char *argv[]) {
199
193
auto pathsBuf = sycl::buffer<Path>(paths.data (), paths.size ());
200
194
pathsBuf.set_final_data (nullptr );
201
195
202
- int delayCounter = 0 ;
203
- int updateBBoxCounter = 0 ;
204
- bool isQuit = false ;
205
- bool isPause = false ;
206
- SDL_Event event;
207
-
208
- std::vector<int > executionTimes;
209
-
210
- while (!isQuit) {
211
- if (SDL_PollEvent (&event)) {
212
- if (event.type == SDL_QUIT) {
213
- isQuit = true ;
214
- } else if (event.type == SDL_KEYDOWN &&
215
- event.key .keysym .sym == SDLK_SPACE) {
216
- isPause = !isPause;
217
- }
218
- }
219
-
220
- if (!isPause) {
221
- if (delayCounter >= DELAY) {
222
- delayCounter = 0 ;
223
- auto start = std::chrono::high_resolution_clock::now ();
224
-
225
- if (updateBBoxCounter <= 0 ) {
226
- updateBBox (myQueue, actorBuf);
227
- updateBBoxCounter = 20 ;
228
- }
229
-
230
- updateVariations (myQueue, actorBuf);
231
- update (myQueue, actorBuf, wallsBuf, pathsBuf);
232
-
233
- auto end = std::chrono::high_resolution_clock::now ();
234
- auto duration =
235
- std::chrono::duration_cast<std::chrono::milliseconds>(
236
- end - start);
237
- executionTimes.push_back (duration.count ());
238
- // std::cout << "fps: " << (1000.0f / duration.count()) <<
239
- // std::endl;
240
-
241
- sycl::host_accessor<Actor, 1 , sycl::access::mode::read> actorHostAcc (actorBuf);
242
-
243
- draw (SCALE, render, actorHostAcc, room);
244
- updateBBoxCounter--;
245
- } else {
246
- delayCounter++;
247
- }
248
- }
249
- }
196
+ // int delayCounter = 0;
197
+ // int updateBBoxCounter = 0;
198
+ // bool isQuit = false;
199
+ // bool isPause = false;
200
+ // SDL_Event event;
201
+
202
+ // std::vector<int> executionTimes;
203
+
204
+ // while (!isQuit) {
205
+ // if (SDL_PollEvent(&event)) {
206
+ // if (event.type == SDL_QUIT) {
207
+ // isQuit = true;
208
+ // } else if (event.type == SDL_KEYDOWN &&
209
+ // event.key.keysym.sym == SDLK_SPACE) {
210
+ // isPause = !isPause;
211
+ // }
212
+ // }
250
213
251
- executionTimes.erase (executionTimes.begin ());
252
- float count = static_cast <float >(executionTimes.size ());
253
- float mean =
254
- std::accumulate (executionTimes.begin (), executionTimes.end (), 0.0 ) /
255
- count;
256
- std::cout << " Mean execution time: " << mean << std::endl;
257
-
258
- close (win, render);
259
-
260
- // // For Profiling
261
- // int updateBBoxCounterr = 0;
262
- // for (int x = 0; x < 500; x++) {
263
- // if (updateBBoxCounterr <= 0) {
264
- // updateBBox(myQueue, actorBuf);
265
- // updateBBoxCounterr = 20;
214
+ // if (!isPause) {
215
+ // if (delayCounter >= DELAY) {
216
+ // delayCounter = 0;
217
+ // auto start = std::chrono::high_resolution_clock::now();
218
+
219
+ // if (updateBBoxCounter <= 0) {
220
+ // updateBBox(myQueue, actorBuf);
221
+ // updateBBoxCounter = 20;
222
+ // }
223
+
224
+ // updateVariations(myQueue, actorBuf);
225
+ // update(myQueue, actorBuf, wallsBuf, pathsBuf);
226
+
227
+ // auto end = std::chrono::high_resolution_clock::now();
228
+ // auto duration =
229
+ // std::chrono::duration_cast<std::chrono::milliseconds>(
230
+ // end - start);
231
+ // executionTimes.push_back(duration.count());
232
+ // // std::cout << "fps: " << (1000.0f / duration.count()) <<
233
+ // // std::endl;
234
+
235
+ // sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
236
+
237
+ // draw(SCALE, render, actorHostAcc, room);
238
+ // updateBBoxCounter--;
239
+ // } else {
240
+ // delayCounter++;
241
+ // }
266
242
// }
267
- // updateVariations(myQueue, actorBuf);
268
- // update(myQueue, actorBuf, wallsBuf, pathsBuf);
269
- // sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
270
- // updateBBoxCounterr--;
271
243
// }
272
244
245
+ // executionTimes.erase(executionTimes.begin());
246
+ // float count = static_cast<float>(executionTimes.size());
247
+ // float mean =
248
+ // std::accumulate(executionTimes.begin(), executionTimes.end(), 0.0) /
249
+ // count;
250
+ // std::cout << "Mean execution time: " << mean << std::endl;
251
+
252
+ // close(win, render);
253
+
254
+ // For Profiling
255
+ int updateBBoxCounterr = 0 ;
256
+ for (int x = 0 ; x < 500 ; x++) {
257
+ if (updateBBoxCounterr <= 0 ) {
258
+ updateBBox (myQueue, actorBuf);
259
+ updateBBoxCounterr = 20 ;
260
+ }
261
+ updateVariations (myQueue, actorBuf);
262
+ update (myQueue, actorBuf, wallsBuf, pathsBuf);
263
+ sycl::host_accessor<Actor, 1 , sycl::access::mode::read> actorHostAcc (actorBuf);
264
+ updateBBoxCounterr--;
265
+ }
266
+
273
267
return 0 ;
274
268
}
0 commit comments