Skip to content

Commit 0b0588e

Browse files
committed
Config options through JSOn
1 parent b3671e4 commit 0b0588e

File tree

8 files changed

+40
-52
lines changed

8 files changed

+40
-52
lines changed

external/Actor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "Actor.hpp"
22

3-
Actor::Actor(vecType pPos, vecType pVelocity, float pDesiredSpeed, std::array<vecType, PATHALLOCATIONSIZE> pPath, int pPathSize, float pMass, float pRadius, bool pAtDestination, std::array<int, 3> pColor):
3+
Actor::Actor(vecType pPos, vecType pVelocity, float pDesiredSpeed, std::array<vecType, PATHALLOCATIONSIZE> pPath, int pPathSize, float pMass, float pRadius, bool pAtDestination, std::array<int, 3> pColor, bool pHeatmapEnabled):
44
pos(pPos), velocity(pVelocity), desiredSpeed(pDesiredSpeed),
55
path(pPath), pathSize(pPathSize), mass(pMass), radius(pRadius),
6-
atDestination(pAtDestination), color(pColor) {
6+
atDestination(pAtDestination), color(pColor), heatmapEnabled(pHeatmapEnabled) {
77
variation = {0, 0};
88
destinationIndex = 0;
99
}
@@ -48,6 +48,10 @@ SYCL_EXTERNAL std::array<int, 3> Actor::getColor() const {
4848
return color;
4949
}
5050

51+
SYCL_EXTERNAL bool Actor::getHeatmapEnabled() const {
52+
return heatmapEnabled;
53+
}
54+
5155
SYCL_EXTERNAL void Actor::setPos(vecType newPos) {
5256
pos = newPos;
5357
}

external/Actor.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class Actor {
2323
float radius;
2424
bool atDestination;
2525
std::array<int, 3> color;
26+
bool heatmapEnabled;
2627

2728
public:
28-
Actor(vecType pPos, vecType pVelocity, float pdesiredSpeed, std::array<vecType, PATHALLOCATIONSIZE> pPath, int pathSize, float pMass, float pRadius, bool pAtDestination, std::array<int, 3> pColor);
29+
Actor(vecType pPos, vecType pVelocity, float pdesiredSpeed, std::array<vecType, PATHALLOCATIONSIZE> pPath, int pathSize, float pMass, float pRadius, bool pAtDestination, std::array<int, 3> pColor, bool pHeatmapEnabled);
2930

3031
SYCL_EXTERNAL vecType getPos() const;
3132
SYCL_EXTERNAL vecType getVelocity() const;
@@ -37,6 +38,7 @@ class Actor {
3738
SYCL_EXTERNAL float getRadius() const;
3839
SYCL_EXTERNAL bool getAtDestination() const;
3940
SYCL_EXTERNAL std::array<int, 3> getColor() const;
41+
SYCL_EXTERNAL bool getHeatmapEnabled() const;
4042

4143
SYCL_EXTERNAL void setPos(vecType newPos);
4244
SYCL_EXTERNAL void setVelocity(vecType newVelocity);

external/CreateEnv.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
99
2.0f,
1010
{{6.5f + (i * 0.5f), 6.5f + (j * 0.5f)}},
1111
1,
12-
50, 0.05, false, {255, 0, 0}});
12+
50, 0.05, false, {255, 0, 0}, true});
1313
}
1414
}
1515

@@ -20,7 +20,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
2020
2.0f,
2121
{{0.5f + (i * 0.5f), 6.5f + (j * 0.5f)}},
2222
1,
23-
50, 0.05, false, {0, 255, 0}});
23+
50, 0.05, false, {0, 255, 0}, true});
2424
}
2525
}
2626

@@ -31,7 +31,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
3131
2.0f,
3232
{{0.5f + (i * 0.5f), 0.5f + (j * 0.5f)}},
3333
1,
34-
50, 0.05, false, {0, 0, 255}});
34+
50, 0.05, false, {0, 0, 255}, true});
3535
}
3636
}
3737

@@ -42,7 +42,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
4242
2.0f,
4343
{{6.5f + (i * 0.5f), 0.5f + (j * 0.5f)}},
4444
1,
45-
50, 0.05, false, {150, 150, 150}});
45+
50, 0.05, false, {150, 150, 150}, true});
4646
}
4747
}
4848

@@ -77,7 +77,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
7777
2.0f,
7878
{vecType({0.5, 4.1}), vecType({-5, 4.1})},
7979
2,
80-
50, 0.05, false, {255, 0, 0}));
80+
50, 0.05, false, {255, 0, 0}, true));
8181
}
8282
}
8383

@@ -98,7 +98,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
9898
2.0f,
9999
{vecType({-1, 4.1})},
100100
1,
101-
50, 0.05, false, {255, 0, 0}));
101+
50, 0.05, false, {255, 0, 0}, true));
102102
}
103103
}
104104

@@ -109,7 +109,7 @@ void createEnv(Room &room, std::vector<Actor> &actors, RoomConfgurations type) {
109109
2.0f,
110110
{vecType({10, 6.2})},
111111
1,
112-
50, 0.05, false, {0, 255, 0}));
112+
50, 0.05, false, {0, 255, 0}, true));
113113
}
114114
}
115115

external/DifferentialEq.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SYCL_EXTERNAL void differentialEq(int currentIndex, sycl::accessor<Actor, 1, syc
4444
vecType forceSum = personalImpulse + peopleForces + wallForces;
4545
forceSum += currentActor->getVariation();
4646

47-
if (HEATMAPENABLED) {
47+
if (currentActor->getHeatmapEnabled()) {
4848
auto colorVal = std::fabs((forceSum[0] + forceSum[1]) / 700.0f);
4949
if (colorVal > 1) { colorVal = 1.0f; }
5050
auto color = findColor(colorVal);

external/DifferentialEq.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ constexpr float Ti = 0.5;
1717

1818
constexpr float TIMESTEP = 0.001;
1919

20-
constexpr bool HEATMAPENABLED = true;
21-
2220
SYCL_EXTERNAL void differentialEq(int currentIndex, sycl::accessor<Actor, 1, sycl::access::mode::read_write> actors, sycl::accessor<std::array<vecType, 2>, 1, sycl::access::mode::read> walls, sycl::stream out);
2321

2422
#endif

external/ParseInputFile.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void validateParameters(rapidjson::Document& jsonDoc) {
1313
else {
1414
auto& config = jsonDoc["config"];
1515
auto configParams = {
16-
"width", "height", "scale", "delay", "heatmap"
16+
"width", "height", "scale", "delay"
1717
};
1818
for (auto p : configParams) {
1919
if (!config.HasMember(p)) missingParameters += std::string(p) + " ";
@@ -24,7 +24,7 @@ void validateParameters(rapidjson::Document& jsonDoc) {
2424
if (jsonDoc["actors"].GetArray().Size() > 0) {
2525
auto actorParams = {
2626
"pos", "velocity", "desiredSpeed", "path",
27-
"pathSize", "mass", "radius"
27+
"pathSize", "mass", "radius", "heatmapEnabled"
2828
};
2929
for (auto& a : jsonDoc["actors"].GetArray()) {
3030
for (auto p : actorParams) {
@@ -39,7 +39,7 @@ void validateParameters(rapidjson::Document& jsonDoc) {
3939
}
4040
}
4141

42-
void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room) {
42+
void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room, int &WIDTH, int &HEIGHT, int &SCALE, int &DELAY) {
4343
std::ifstream jsonFile(filename);
4444
if (!jsonFile.is_open()) {
4545
throw JSONException("Error opening file " + filename);
@@ -55,11 +55,10 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room
5555

5656
// Config
5757
auto& config = jsonDoc["config"];
58-
int width = config["width"].GetInt();
59-
int height = config["height"].GetInt();
60-
int scale = config["scale"].GetInt();
61-
int delay = config["delay"].GetInt();
62-
bool heatmap = config["heatmap"].GetBool();
58+
WIDTH = config["width"].GetInt();
59+
HEIGHT = config["height"].GetInt();
60+
SCALE = config["scale"].GetInt();
61+
DELAY = config["delay"].GetInt();
6362

6463
// Environment
6564
auto jsonWalls = jsonDoc["environment"]["walls"].GetArray();
@@ -90,23 +89,8 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room
9089
auto jsonColor = a["color"].GetArray();
9190
std::array<int, 3> color = {jsonColor[0].GetInt(), jsonColor[1].GetInt(), jsonColor[2].GetInt()};
9291

93-
actors.push_back(Actor(pos, velocity, desiredSpeed, path, pathSize, mass, radius, atDestination, color));
94-
}
95-
96-
// std::cout << "Config: " << std::endl;
97-
// std::cout << "width: " << width << ", height: " << height << ", scale: " << scale << ", delay: " << delay << ", heatmap: " << heatmap << std::endl << std::endl;
92+
bool heatmapEnabled = a["heatmapEnabled"].GetBool();
9893

99-
// std::cout << "Environment:" << std::endl;
100-
// for (auto w : walls) {
101-
// std::cout << "{{" << w[0][0] << ", " << w[0][1] << "}, {" << w[1][0] << ", " << w[1][1] << "}}" << std::endl;
102-
// }
103-
104-
// std::cout << std::endl << "Actors:" << std::endl;
105-
// for (auto a : actors) {
106-
// std::cout << "pos: {" << a.getPos()[0] << ", " << a.getPos()[1] << "}, velocity: {" << a.getVelocity()[0] << ", " << a.getVelocity()[1] << "}, desiredSpeed: " << a.getDesiredSpeed() << ", path: ";
107-
// for (auto p : a.getPath()) {
108-
// std::cout << "{" << p[0] << ", " << p[1] << "}, ";
109-
// }
110-
// std::cout << std::endl << ", mass: " << a.getMass() << ", radius: " << a.getRadius() << ", atDestination: " << a.getAtDestination() << ", color: [" << a.getColor()[0] << ", " << a.getColor()[1] << ", " << a.getColor()[2] << "]" << std::endl;
111-
// }
94+
actors.push_back(Actor(pos, velocity, desiredSpeed, path, pathSize, mass, radius, atDestination, color, heatmapEnabled));
95+
}
11296
}

external/ParseInputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class JSONException : public std::runtime_error {
2020

2121
void validateParameters(rapidjson::Document& jsonDoc);
2222

23-
void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room);
23+
void parseInputFile(std::string filename, std::vector<Actor> &actors, Room &room, int &WIDTH, int &HEIGHT, int &SCALE, int &DELAY);
2424

2525
#endif

src/main.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
#include "CreateEnv.hpp"
1414
#include "ParseInputFile.hpp"
1515

16-
constexpr int WIDTH = 9; // metres
17-
constexpr int HEIGHT = 9; // metres
18-
constexpr int SCALE = 100;
19-
constexpr int DELAY = 0;
16+
int WIDTH; // metres
17+
int HEIGHT; // metres
18+
int SCALE;
19+
int DELAY;
2020

2121
void init(SDL_Window* &win, SDL_Renderer* &render, std::vector<Actor> &actors, Room &room, int argc, char **argv) {
22-
SDL_Init(SDL_INIT_VIDEO);
23-
win = SDL_CreateWindow("SYCL Crowd Simulation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE, HEIGHT * SCALE, SDL_WINDOW_SHOWN);
24-
render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
25-
2622
if (argc > 1) {
2723
std::string inputPath = argv[1];
28-
parseInputFile(inputPath, actors, room);
24+
parseInputFile(inputPath, actors, room, WIDTH, HEIGHT, SCALE, DELAY);
2925
}
26+
27+
SDL_Init(SDL_INIT_VIDEO);
28+
win = SDL_CreateWindow("SYCL Crowd Simulation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE, HEIGHT * SCALE, SDL_WINDOW_SHOWN);
29+
render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
3030
}
3131

3232
void drawCircle(SDL_Renderer* &render, SDL_Point center, int radius, SDL_Color color) {
@@ -109,9 +109,9 @@ int main(int argc, char *argv[]) {
109109
bool isQuit = false;
110110
SDL_Event event;
111111

112-
const float dt = 0.00001f;
113-
float accumulator = 0.0f;
114-
float currentTime = SDL_GetTicks();
112+
// const float dt = 0.00001f;
113+
// float accumulator = 0.0f;
114+
// float currentTime = SDL_GetTicks();
115115

116116
while(!isQuit) {
117117
if (SDL_PollEvent(&event)) {

0 commit comments

Comments
 (0)