18
18
19
19
uint GLOBALSEED;
20
20
21
- void init (int &SCALE, int &DELAY,
21
+ void init (int &SCALE, int &DELAY, SDL_Window*& win, SDL_Renderer*& render,
22
22
std::vector<Actor> &actors, Room &room, std::vector<Path> &paths,
23
23
int argc, char **argv) {
24
24
int WIDTH;
@@ -168,8 +168,8 @@ int main(int argc, char *argv[]) {
168
168
int SCALE;
169
169
int DELAY;
170
170
171
- // SDL_Window *win;
172
- // SDL_Renderer *render;
171
+ SDL_Window *win;
172
+ SDL_Renderer *render;
173
173
174
174
std::vector<Actor> actors;
175
175
Room room = Room ({});
@@ -183,7 +183,7 @@ int main(int argc, char *argv[]) {
183
183
184
184
sycl::queue myQueue{sycl::gpu_selector (), asyncHandler};
185
185
186
- init (SCALE, DELAY, actors, room, paths, argc, argv);
186
+ init (SCALE, DELAY, win, render, actors, room, paths, argc, argv);
187
187
188
188
// Buffer creation
189
189
auto actorBuf = sycl::buffer<Actor>(actors.data (), actors.size ());
@@ -193,76 +193,76 @@ int main(int argc, char *argv[]) {
193
193
auto pathsBuf = sycl::buffer<Path>(paths.data (), paths.size ());
194
194
pathsBuf.set_final_data (nullptr );
195
195
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
- // }
213
-
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
- // }
242
- // }
243
- // }
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
+ }
244
213
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 ;
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
+ }
260
242
}
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
243
}
266
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
+
267
267
return 0 ;
268
268
}
0 commit comments