Skip to content

Commit 2d81636

Browse files
committed
Negative random number generation
1 parent f6d335e commit 2d81636

File tree

2 files changed

+73
-67
lines changed

2 files changed

+73
-67
lines changed

external/Actor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ 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 randX = float(seed) * (1.0f / 4294967296.0f);
71+
float xDirection = float(seed) > 2151000064 ? -1.0f : 1.0f;
7272
seed = randXorShift(seed);
73-
float randY = float(seed) * (1.0f / 4294967296.0f);
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;
7479
this->setVariation({randX, randY});
7580
}
7681

src/main.cpp

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -197,75 +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-
// // For Profiling
250-
// int updateBBoxCounterr = 0;
251-
// for (int x = 0; x < 500; x++) {
252-
// if (updateBBoxCounterr <= 0) {
253-
// updateBBox(myQueue, actorBuf);
254-
// 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+
// }
255246
// }
256-
// updateVariations(myQueue, actorBuf);
257-
// update(myQueue, actorBuf, wallsBuf, pathsBuf);
258-
// sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
259-
// updateBBoxCounterr--;
260247
// }
261248

262-
executionTimes.erase(executionTimes.begin());
263-
float count = static_cast<float>(executionTimes.size());
264-
float mean =
265-
std::accumulate(executionTimes.begin(), executionTimes.end(), 0.0) /
266-
count;
267-
std::cout << "Mean execution time: " << mean << std::endl;
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+
}
268270

269-
close(win, render);
270271
return 0;
271272
}

0 commit comments

Comments
 (0)