Skip to content

Commit 3c3953c

Browse files
committed
Uncomment main loop
1 parent c62d36a commit 3c3953c

File tree

1 file changed

+71
-71
lines changed

1 file changed

+71
-71
lines changed

src/main.cpp

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
uint GLOBALSEED;
2020

21-
void init(int &SCALE, int &DELAY,
21+
void init(int &SCALE, int &DELAY, SDL_Window*& win, SDL_Renderer*& render,
2222
std::vector<Actor> &actors, Room &room, std::vector<Path> &paths,
2323
int argc, char **argv) {
2424
int WIDTH;
@@ -168,8 +168,8 @@ int main(int argc, char *argv[]) {
168168
int SCALE;
169169
int DELAY;
170170

171-
// SDL_Window *win;
172-
// SDL_Renderer *render;
171+
SDL_Window *win;
172+
SDL_Renderer *render;
173173

174174
std::vector<Actor> actors;
175175
Room room = Room({});
@@ -183,7 +183,7 @@ int main(int argc, char *argv[]) {
183183

184184
sycl::queue myQueue{sycl::gpu_selector(), asyncHandler};
185185

186-
init(SCALE, DELAY, actors, room, paths, argc, argv);
186+
init(SCALE, DELAY, win, render, actors, room, paths, argc, argv);
187187

188188
// Buffer creation
189189
auto actorBuf = sycl::buffer<Actor>(actors.data(), actors.size());
@@ -193,76 +193,76 @@ int main(int argc, char *argv[]) {
193193
auto pathsBuf = sycl::buffer<Path>(paths.data(), paths.size());
194194
pathsBuf.set_final_data(nullptr);
195195

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+
}
244213

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+
}
260242
}
261-
updateVariations(myQueue, actorBuf);
262-
update(myQueue, actorBuf, wallsBuf, pathsBuf);
263-
sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
264-
updateBBoxCounterr--;
265243
}
266244

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+
267267
return 0;
268268
}

0 commit comments

Comments
 (0)