Class representing the simulation environment. More...
#include <simulator.h>
Public Member Functions | |
| Simulation (Configuration &_config) | |
| Constructs a Simulation object. | |
| virtual | ~Simulation () |
| Destructor. | |
| void | init_all () |
| Initializes the simulation components. | |
| void | create_robots () |
| Creates the robot instances. | |
| void | create_objects () |
| Creates objects in the simulation. | |
| void | create_arena () |
| Creates the arena from a CSV file. | |
| void | create_walls () |
| Creates arena walls. | |
| void | init_box2d () |
| Initializes the Box2D world. | |
| void | init_config () |
| Initializes the simulation configuration. | |
| void | init_SDL () |
| Initializes SDL and related subsystems. | |
| void | speed_up () |
| Speeds up the simulation GUI. | |
| void | speed_down () |
| Slows down the simulation GUI. | |
| void | pause () |
| Toggles the simulation pause state. | |
| void | help_message () |
| Displays a help message with GUI keyboard shortcuts. | |
| void | handle_SDL_events () |
| Handles SDL events. | |
| void | compute_neighbors () |
| Computes neighboring robots. | |
| void | init_callbacks () |
| Initializes simulation callbacks. | |
| void | init_data_logger () |
| Initializes the data logger. | |
| void | init_console_logger () |
| Initializes the console logger. | |
| void | draw_scale_bar () |
| Draws a scale bar on the GUI. | |
| void | render_all () |
| Renders all simulation components. | |
| void | export_frames () |
| Exports the current frame to a PNG file. | |
| void | export_data () |
| Exports simulation data from the current robot. | |
| void | main_loop () |
| Runs the main simulation loop. | |
| void | stop_simulation_main_loop () |
| Stops the main simulation loop. | |
| void | delete_old_data () |
| Deletes old data files. | |
| Configuration & | get_config () |
| Retrieves the current configuration. | |
| DataLogger * | get_data_logger () |
| Retrieves the data logger. | |
| LightLevelMap * | get_light_map () |
| Retrieves the light map. | |
| arena_polygons_t const & | get_arena_geometry () |
| Retrieve the arena geometry. | |
| boundary_condition_t const & | get_boundary_condition () |
| Retrieve the arena boundary conditions. | |
| void | apply_periodic_wrapping () |
| Wrap objects position to have period boundary conditions. | |
| uint32_t | get_nb_robots () const |
| Returns the number of robots in the simulation. | |
Public Attributes | |
| bool | current_robot_enable_data_logging |
| Flag to enable data logging on the current robot. | |
Class representing the simulation environment.
The Simulation class encapsulates the configuration, SDL window and renderer, Box2D world, robots, arena geometry, data logging, and GUI event handling for the simulation.
| Simulation::Simulation | ( | Configuration & | _config | ) |
Constructs a Simulation object.
Initializes the simulation configuration, console logging, Box2D world, and SDL subsystems.
| _config | Reference to a Configuration object. |
|
virtual |
Destructor.
Cleans up fonts, SDL, and Box2D world resources.
| void Simulation::apply_periodic_wrapping | ( | ) |
Wrap objects position to have period boundary conditions.
| void Simulation::compute_neighbors | ( | ) |
Computes neighboring robots.
Updates each robot's neighbor list based on their positions and communication radius.
| void Simulation::create_arena | ( | ) |
Creates the arena from a CSV file.
Reads the arena polygons from a CSV file, computes the bounding box, creates walls, and adjusts visualization scaling.
| void Simulation::create_objects | ( | ) |
Creates objects in the simulation.
| void Simulation::create_robots | ( | ) |
Creates the robot instances.
Generates initial positions for robots based on the configuration, creates Robot objects, and initializes their user code.
| void Simulation::create_walls | ( | ) |
Creates arena walls.
Defines static bodies for arena boundaries using Box2D.
| void Simulation::delete_old_data | ( | ) |
Deletes old data files.
Deletes files with a specified extension from the frames directory if configured to do so.
| void Simulation::draw_scale_bar | ( | ) |
Draws a scale bar on the GUI.
Renders a horizontal scale bar along with a label indicating the scale in millimeters.
| void Simulation::export_data | ( | ) |
Exports simulation data from the current robot.
Iterates over all robots, logs their state to the DataLogger, and saves the data row.
| void Simulation::export_frames | ( | ) |
Exports the current frame to a PNG file.
Saves the current window content to a PNG file if the frame export period has elapsed.
|
inline |
Retrieve the arena geometry.
|
inline |
Retrieve the arena boundary conditions.
| Configuration & Simulation::get_config | ( | ) |
Retrieves the current configuration.
| DataLogger * Simulation::get_data_logger | ( | ) |
Retrieves the data logger.
| LightLevelMap * Simulation::get_light_map | ( | ) |
Retrieves the light map.
|
inline |
Returns the number of robots in the simulation.
| void Simulation::handle_SDL_events | ( | ) |
Handles SDL events.
Processes SDL events such as keyboard input, mouse movement, and window events, and updates simulation state accordingly.
| void Simulation::help_message | ( | ) |
Displays a help message with GUI keyboard shortcuts.
| void Simulation::init_all | ( | ) |
Initializes the simulation components.
Calls functions to create the arena and robots
| void Simulation::init_box2d | ( | ) |
Initializes the Box2D world.
Creates a Box2D world with zero gravity.
| void Simulation::init_callbacks | ( | ) |
Initializes simulation callbacks.
Currently initializes the data logger.
| void Simulation::init_config | ( | ) |
Initializes the simulation configuration.
Reads configuration parameters and initializes global variables such as window size, arena dimensions, robot radius, and GUI settings.
| void Simulation::init_console_logger | ( | ) |
Initializes the console logger.
Sets up file-based logging if enabled in the configuration.
| std::runtime_error | if the console filename is empty when logging is enabled. |
| void Simulation::init_data_logger | ( | ) |
Initializes the data logger.
Sets up the DataLogger schema based on configuration and opens the data file.
| std::runtime_error | if required configuration values are missing. |
| void Simulation::init_SDL | ( | ) |
Initializes SDL and related subsystems.
Sets up the SDL window, renderer, font, and initializes fpng for image exporting.
| std::runtime_error | if SDL initialization fails. |
| void Simulation::main_loop | ( | ) |
Runs the main simulation loop.
Processes SDL events, updates robot states, steps the Box2D world, computes neighbors, logs data, renders frames, and manages simulation timing until the simulation time is reached or exit is requested.
| void Simulation::pause | ( | ) |
Toggles the simulation pause state.
| void Simulation::render_all | ( | ) |
Renders all simulation components.
Clears the renderer, draws the arena walls, robots, current time, and scale bar.
| void Simulation::speed_down | ( | ) |
Slows down the simulation GUI.
Decreases the GUI speed-up factor and logs the new value.
| void Simulation::speed_up | ( | ) |
Speeds up the simulation GUI.
Increases the GUI speed-up factor and logs the new value.
| void Simulation::stop_simulation_main_loop | ( | ) |
Stops the main simulation loop.
| bool Simulation::current_robot_enable_data_logging |
Flag to enable data logging on the current robot.