diff --git a/main.cpp b/main.cpp index d247b91..150f01c 100644 --- a/main.cpp +++ b/main.cpp @@ -60,12 +60,30 @@ Pedestrian *init_pedestrians(int n_p) { int main(int argc, const char *argv[]) { - Obstacle obs[] = {}; - Board board = Board(BOARD_LENGTH, BOARD_WIDTH, 0, obs); + // Check command line arguments + if (argc < 3) { + printf("Usage: ./sim \n"); + printf(" number_of_iterations: each iteration = %.2f seconds of simulation time\n", dt); + return 1; + } + // Parse command line arguments int n_p = atoi(argv[1]); int n_iter = atoi(argv[2]); + if (n_p <= 0) { + printf("Error: must be a positive integer, got '%s'\n", argv[1]); + return 1; + } + + if (n_iter <= 0) { + printf("Error: must be a positive integer, got '%s'\n", argv[2]); + return 1; + } + + Obstacle obs[] = {}; + Board board = Board(BOARD_LENGTH, BOARD_WIDTH, 0, obs); + // Logic to get/dump the simulation data const int dump_interval = 50; // dump every 5 iterations -> 20 fps (since dt = 0.01) const char *dump_path = (argc >= 4) ? argv[3] : nullptr; @@ -123,6 +141,9 @@ int main(int argc, const char *argv[]) { // p.curr_pos = p.curr_pos + p.curr_vel * dt; + // # 10 flops = 5 ADDs, 2 DIVs, 1 SQRT, 2 MULTs + p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm(); + // how to handle if a pedestrian reached the end of our simulation/end of the hallway // The option we do here is to just "teleport" the person back to the beginning // the good thing is we will have a constant flow of pedestrians and in the simulation we should see how lines build up @@ -136,9 +157,6 @@ int main(int argc, const char *argv[]) { // p.destination.y = p.curr_pos.y; } - // # 10 flops = 5 ADDs, 2 DIVs, 1 SQRT, 2 MULTs - p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm(); - // if we have a dump path/file we wanna save the data for visualisation if (dump_path && (t % dump_interval == 0)) { samples.emplace_back(t, i, p.curr_pos.x, p.curr_pos.y, p.color);