CellModules
main.cpp
Go to the documentation of this file.
1#include <mecacell/mecacell.h>
2// #include <mecacellviewer/viewer.h>
4#include "../modules/extraModules/sql/include/pluginSQL/PluginSQL.hpp"
5#include <fstream>
6#include <csignal>
7
8using namespace std;
9
10nlohmann::json loadJsonConfig(const string &inputFileName) {
11 nlohmann::json config;
12 ifstream i(inputFileName,ifstream::in);
13 i >> config;
14 i.close();
15 return config;
16}
17static Scenario* scenario_ptr = nullptr;
18void signal_handler(int signum) {
19 std::cerr << "Interrupt signal (" << signum << ") received.\n";
21 std::exit(signum);
22}
23
24int main(int argc, char *argv[]) {
25 std::signal(SIGTERM, signal_handler);
26 std::signal(SIGINT, signal_handler);
27
28 string configPath = argc > 1 ? argv[1] : "../config/viewer.json";
29 nlohmann::json configuration = loadJsonConfig(configPath);
30
31 Scenario scenario;
32 scenario_ptr = &scenario;
33 scenario.getWorld().benchmark = true;
34
35 PluginSQL::PluginSQL<Cell> pluginSQL(configuration["main"], true);
36 scenario.getWorld().registerPlugin(pluginSQL);
37
38 scenario.init(configuration);
39
40 while(!scenario.stop()){
41 scenario.loop();
42 }
43 scenario.showBenchmarksSummaries();
44 return 0;
45
46 // MecacellViewer::Viewer<Scenario> viewer(scenario);
47 // return viewer.exec();
48}
Defines the Scenario class for managing the simulation scenario.
bool benchmark
Definition: world.hpp:93
Manages the simulation scenario.
Definition: Scenario.hpp:24
World & getWorld()
Gets the world of the scenario.
Definition: Scenario.hpp:53
void init(nlohmann::json config)
Initializes the scenario with a configuration.
Definition: Scenario.hpp:162
void loop()
Runs the main loop of the scenario.
Definition: Scenario.hpp:176
void showBenchmarksSummaries() const
Definition: Scenario.hpp:183
bool stop()
Checks if the scenario should stop.
Definition: Scenario.hpp:197
a class to store JSON values
Definition: json.hpp:12931
Provides common mathematical functions and vector operations.
Definition: std.hpp:4
iostream cerr
Standard error stream.
Definition: std.hpp:315
int main(int argc, char *argv[])
Definition: main.cpp:24
nlohmann::json loadJsonConfig(const string &inputFileName)
Definition: main.cpp:10
static Scenario * scenario_ptr
Definition: main.cpp:17
void signal_handler(int signum)
Definition: main.cpp:18