Skip to content

Commit b77ceac

Browse files
committed
Simplify negative RNG
1 parent 2d81636 commit b77ceac

File tree

2 files changed

+69
-74
lines changed

2 files changed

+69
-74
lines changed

external/Actor.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ SYCL_EXTERNAL void Actor::setSeed(uint newSeed) { seed = newSeed; }
6868
SYCL_EXTERNAL void Actor::refreshVariations() {
6969
// Previous RNG output is used as next seed
7070
seed = randXorShift(seed);
71-
float xDirection = float(seed) > 2151000064 ? -1.0f : 1.0f;
71+
float randX = (float(seed) * (2.0f / 4294967296.0f)) - 1.0f;
7272
seed = randXorShift(seed);
73-
float yDirection = float(seed) > 2151000064 ? -1.0f : 1.0f;
74-
75-
seed = randXorShift(seed);
76-
float randX = float(seed) * (1.0f / 4294967296.0f) * xDirection;
77-
seed = randXorShift(seed);
78-
float randY = float(seed) * (1.0f / 4294967296.0f) * yDirection;
73+
float randY = (float(seed) * (2.0f / 4294967296.0f)) - 1.0f;
7974
this->setVariation({randX, randY});
8075
}
8176

src/main.cpp

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -197,76 +197,76 @@ int main(int argc, char *argv[]) {
197197
auto wallsBuf = sycl::buffer<std::array<vecType, 2>>(walls.data(), walls.size());
198198
auto pathsBuf = sycl::buffer<Path>(paths.data(), paths.size());
199199

200-
// int delayCounter = 0;
201-
// int updateBBoxCounter = 0;
202-
// bool isQuit = false;
203-
// bool isPause = false;
204-
// SDL_Event event;
205-
206-
// std::vector<int> executionTimes;
207-
208-
// while (!isQuit) {
209-
// if (SDL_PollEvent(&event)) {
210-
// if (event.type == SDL_QUIT) {
211-
// isQuit = true;
212-
// } else if (event.type == SDL_KEYDOWN &&
213-
// event.key.keysym.sym == SDLK_SPACE) {
214-
// isPause = !isPause;
215-
// }
216-
// }
217-
218-
// if (!isPause) {
219-
// if (delayCounter >= DELAY) {
220-
// delayCounter = 0;
221-
// auto start = std::chrono::high_resolution_clock::now();
222-
223-
// if (updateBBoxCounter <= 0) {
224-
// updateBBox(myQueue, actorBuf);
225-
// updateBBoxCounter = 20;
226-
// }
227-
228-
// updateVariations(myQueue, actorBuf);
229-
// update(myQueue, actorBuf, wallsBuf, pathsBuf);
230-
231-
// auto end = std::chrono::high_resolution_clock::now();
232-
// auto duration =
233-
// std::chrono::duration_cast<std::chrono::milliseconds>(
234-
// end - start);
235-
// executionTimes.push_back(duration.count());
236-
// // std::cout << "fps: " << (1000.0f / duration.count()) <<
237-
// // std::endl;
238-
239-
// sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
240-
241-
// draw(SCALE, render, actorHostAcc, room);
242-
// updateBBoxCounter--;
243-
// } else {
244-
// delayCounter++;
245-
// }
246-
// }
247-
// }
200+
int delayCounter = 0;
201+
int updateBBoxCounter = 0;
202+
bool isQuit = false;
203+
bool isPause = false;
204+
SDL_Event event;
205+
206+
std::vector<int> executionTimes;
207+
208+
while (!isQuit) {
209+
if (SDL_PollEvent(&event)) {
210+
if (event.type == SDL_QUIT) {
211+
isQuit = true;
212+
} else if (event.type == SDL_KEYDOWN &&
213+
event.key.keysym.sym == SDLK_SPACE) {
214+
isPause = !isPause;
215+
}
216+
}
248217

249-
// executionTimes.erase(executionTimes.begin());
250-
// float count = static_cast<float>(executionTimes.size());
251-
// float mean =
252-
// std::accumulate(executionTimes.begin(), executionTimes.end(), 0.0) /
253-
// count;
254-
// std::cout << "Mean execution time: " << mean << std::endl;
255-
256-
// close(win, render);
257-
258-
// For Profiling
259-
int updateBBoxCounterr = 0;
260-
for (int x = 0; x < 500; x++) {
261-
if (updateBBoxCounterr <= 0) {
262-
updateBBox(myQueue, actorBuf);
263-
updateBBoxCounterr = 20;
218+
if (!isPause) {
219+
if (delayCounter >= DELAY) {
220+
delayCounter = 0;
221+
auto start = std::chrono::high_resolution_clock::now();
222+
223+
if (updateBBoxCounter <= 0) {
224+
updateBBox(myQueue, actorBuf);
225+
updateBBoxCounter = 20;
226+
}
227+
228+
updateVariations(myQueue, actorBuf);
229+
update(myQueue, actorBuf, wallsBuf, pathsBuf);
230+
231+
auto end = std::chrono::high_resolution_clock::now();
232+
auto duration =
233+
std::chrono::duration_cast<std::chrono::milliseconds>(
234+
end - start);
235+
executionTimes.push_back(duration.count());
236+
// std::cout << "fps: " << (1000.0f / duration.count()) <<
237+
// std::endl;
238+
239+
sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
240+
241+
draw(SCALE, render, actorHostAcc, room);
242+
updateBBoxCounter--;
243+
} else {
244+
delayCounter++;
245+
}
264246
}
265-
updateVariations(myQueue, actorBuf);
266-
update(myQueue, actorBuf, wallsBuf, pathsBuf);
267-
sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
268-
updateBBoxCounterr--;
269247
}
270248

249+
executionTimes.erase(executionTimes.begin());
250+
float count = static_cast<float>(executionTimes.size());
251+
float mean =
252+
std::accumulate(executionTimes.begin(), executionTimes.end(), 0.0) /
253+
count;
254+
std::cout << "Mean execution time: " << mean << std::endl;
255+
256+
close(win, render);
257+
258+
// // For Profiling
259+
// int updateBBoxCounterr = 0;
260+
// for (int x = 0; x < 500; x++) {
261+
// if (updateBBoxCounterr <= 0) {
262+
// updateBBox(myQueue, actorBuf);
263+
// updateBBoxCounterr = 20;
264+
// }
265+
// updateVariations(myQueue, actorBuf);
266+
// update(myQueue, actorBuf, wallsBuf, pathsBuf);
267+
// sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
268+
// updateBBoxCounterr--;
269+
// }
270+
271271
return 0;
272272
}

0 commit comments

Comments
 (0)