-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (53 loc) · 3.75 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (53 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <string>
#include <iostream>
#include "Simulation.h"
#include "cxxopts.hpp"
int main(int argc, char **argv) {
cxxopts::Options options("boids", "Runs a simulation of Craig Reynolds' boids program.");
options.add_options()
("width", "Width of the window.",
cxxopts::value<int>()->default_value(std::to_string(Simulation::DEFAULT_WINDOW_WIDTH)))
("height", "Height of the window.",
cxxopts::value<int>()->default_value(std::to_string(Simulation::DEFAULT_WINDOW_HEIGHT)))
("boid_size", "The size of the boids.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_BOID_SIZE)))
("max_speed", "Maximum speed of a boid.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_MAX_SPEED)))
("max_force", "Maximum force that can be applied to a boid.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_MAX_FORCE)))
("flock_size", "Initial size of the flock.",
cxxopts::value<int>()->default_value(std::to_string(Simulation::DEFAULT_FLOCK_SIZE)))
("alignment_weight", "Weight applied to the alignment rule.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_ALIGNMENT_WEIGHT)))
("cohesion_weight", "Weight applied to the cohesion rule.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_COHESION_WEIGHT)))
("separation_weight", "Weight applied to the separation rule.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_SEPARATION_WEIGHT)))
("acceleration_scale", "Scaling factor applied to boids' acceleration.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_ACCELERATION_SCALE)))
("perception", "Boids consider other boids within this range when deciding how to act.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_PERCEPTION)))
("separation_distance", "The minimum distance boids will try to stay away from each other.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_SEPARATION_DISTANCE)))
("noise_scale", "The scaling factor that controls the amount of noise to be added to boid's movements.",
cxxopts::value<float>()->default_value(std::to_string(Simulation::DEFAULT_NOISE_SCALE)))
("num_threads", "Number of threads to use for parallelization.",
cxxopts::value<int>()->default_value(std::to_string(-1)))
("fullscreen", "Runs the simulation in a fullscreen window.")
("light_scheme", "Uses a light color scheme.")
("help", "Displays this help message.");
auto result = options.parse(argc, argv);
if (result["help"].as<bool>()) {
std::cout << options.help() << std::endl;
return EXIT_SUCCESS;
}
Simulation simulation(result["width"].as<int>(), result["height"].as<int>(), result["boid_size"].as<float>(),
result["max_speed"].as<float>(), result["max_force"].as<float>(),
result["alignment_weight"].as<float>(), result["cohesion_weight"].as<float>(),
result["separation_weight"].as<float>(), result["acceleration_scale"].as<float>(),
result["perception"].as<float>(), result["separation_distance"].as<float>(),
result["noise_scale"].as<float>(), result["fullscreen"].as<bool>(),
result["light_scheme"].as<bool>(), result["num_threads"].as<int>());
simulation.run(result["flock_size"].as<int>());
return EXIT_SUCCESS;
}