FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file world.h
10 * @brief Header file for the World class in the simulator.
11 */
12
13#pragma once
14
15#include <memory>
16#include <queue>
17#include <string>
18#include <unordered_map>
19#include <vector>
20
22#include "core/sim_events.h"
23#include "core/sim_id.h"
25#include "radar/platform.h"
26#include "radar/receiver.h"
27#include "radar/target.h"
28#include "radar/transmitter.h"
29#include "signal/radar_signal.h"
31
32namespace core
33{
34 /**
35 * @class World
36 * @brief The World class manages the simulator environment.
37 */
38 class World
39 {
40 public:
41 World() = default;
42
43 ~World() noexcept = default;
44
45 World(const World&) = delete;
46
47 World& operator=(const World&) = delete;
48
49 World(World&&) = delete;
50
51 World& operator=(World&&) = delete;
52
53 /**
54 * @brief Adds a radar platform to the simulation world.
55 *
56 * @param plat A unique pointer to a Platform object.
57 */
58 void add(std::unique_ptr<radar::Platform> plat) noexcept;
59
60 /**
61 * @brief Adds a radar transmitter to the simulation world.
62 *
63 * @param trans A unique pointer to a Transmitter object.
64 */
65 void add(std::unique_ptr<radar::Transmitter> trans) noexcept;
66
67 /**
68 * @brief Adds a radar receiver to the simulation world.
69 *
70 * @param recv A unique pointer to a Receiver object.
71 */
72 void add(std::unique_ptr<radar::Receiver> recv) noexcept;
73
74 /**
75 * @brief Adds a radar target to the simulation world.
76 *
77 * @param target A unique pointer to a Target object.
78 */
79 void add(std::unique_ptr<radar::Target> target) noexcept;
80
81 /**
82 * @brief Adds a radar signal (waveform) to the simulation world.
83 *
84 * @param waveform A unique pointer to a RadarSignal object.
85 * @throws std::runtime_error if a waveform with the same ID already exists.
86 */
87 void add(std::unique_ptr<fers_signal::RadarSignal> waveform);
88
89 /**
90 * @brief Adds an antenna to the simulation world.
91 *
92 * @param antenna A unique pointer to an Antenna object.
93 * @throws std::runtime_error if an antenna with the same ID already exists.
94 */
95 void add(std::unique_ptr<antenna::Antenna> antenna);
96
97 /**
98 * @brief Adds a timing source to the simulation world.
99 *
100 * @param timing A unique pointer to a PrototypeTiming object.
101 * @throws std::runtime_error if a timing source with the same ID already exists.
102 */
103 void add(std::unique_ptr<timing::PrototypeTiming> timing);
104
105 /**
106 * @brief Finds a radar signal by ID.
107 *
108 * @param id The ID of the radar signal to find.
109 * @return A pointer to the RadarSignal if found, or nullptr if not found.
110 */
111 [[nodiscard]] fers_signal::RadarSignal* findWaveform(const SimId id);
112
113 /**
114 * @brief Finds an antenna by ID.
115 *
116 * @param id The ID of the antenna to find.
117 * @return A pointer to the Antenna if found, or nullptr if not found.
118 */
119 [[nodiscard]] antenna::Antenna* findAntenna(const SimId id);
120
121 /**
122 * @brief Finds a timing source by ID.
123 *
124 * @param id The ID of the timing source to find.
125 * @return A pointer to the PrototypeTiming if found, or nullptr if not found.
126 */
127 [[nodiscard]] timing::PrototypeTiming* findTiming(const SimId id);
128
129 /**
130 * @brief Finds a platform by ID.
131 *
132 * @param id The ID of the platform to find.
133 * @return A pointer to the Platform if found, or nullptr if not found.
134 */
135 [[nodiscard]] radar::Platform* findPlatform(const SimId id);
136
137 /**
138 * @brief Finds a transmitter by ID.
139 *
140 * @param id The ID of the transmitter to find.
141 * @return A pointer to the Transmitter if found, or nullptr if not found.
142 */
143 [[nodiscard]] radar::Transmitter* findTransmitter(const SimId id);
144
145 /**
146 * @brief Finds a receiver by ID.
147 *
148 * @param id The ID of the receiver to find.
149 * @return A pointer to the Receiver if found, or nullptr if not found.
150 */
151 [[nodiscard]] radar::Receiver* findReceiver(const SimId id);
152
153 /**
154 * @brief Finds a target by ID.
155 *
156 * @param id The ID of the target to find.
157 * @return A pointer to the Target if found, or nullptr if not found.
158 */
159 [[nodiscard]] radar::Target* findTarget(const SimId id);
160
161 /**
162 * @brief Replaces an existing target, updating internal pointers.
163 * @param target Unique pointer to the new target.
164 */
165 void replace(std::unique_ptr<radar::Target> target);
166
167 /**
168 * @brief Replaces an existing antenna, updating internal pointers.
169 * @param antenna Unique pointer to the new antenna.
170 */
171 void replace(std::unique_ptr<antenna::Antenna> antenna);
172
173 /**
174 * @brief Replaces an existing waveform, updating internal pointers.
175 * @param waveform Unique pointer to the new waveform.
176 */
177 void replace(std::unique_ptr<fers_signal::RadarSignal> waveform);
178
179 /**
180 * @brief Replaces an existing timing prototype and refreshes dependent radar timing models.
181 * @param timing Unique pointer to the new timing prototype.
182 */
183 void replace(std::unique_ptr<timing::PrototypeTiming> timing);
184
185 /**
186 * @brief Retrieves the list of platforms.
187 *
188 * @return A const reference to a vector of unique pointers to Platform objects.
189 */
190 [[nodiscard]] const std::vector<std::unique_ptr<radar::Platform>>& getPlatforms() const noexcept
191 {
192 return _platforms;
193 }
194
195 /**
196 * @brief Retrieves the list of radar targets.
197 *
198 * @return A const reference to a vector of unique pointers to Target objects.
199 */
200 [[nodiscard]] const std::vector<std::unique_ptr<radar::Target>>& getTargets() const noexcept
201 {
202 return _targets;
203 }
204
205 /**
206 * @brief Retrieves the list of radar receivers.
207 *
208 * @return A const reference to a vector of unique pointers to Receiver objects.
209 */
210 [[nodiscard]] const std::vector<std::unique_ptr<radar::Receiver>>& getReceivers() const noexcept
211 {
212 return _receivers;
213 }
214
215 /**
216 * @brief Retrieves the list of radar transmitters.
217 *
218 * @return A const reference to a vector of unique pointers to Transmitter objects.
219 */
220 [[nodiscard]] const std::vector<std::unique_ptr<radar::Transmitter>>& getTransmitters() const noexcept
221 {
222 return _transmitters;
223 }
224
225 /**
226 * @brief Retrieves the map of radar signals (waveforms).
227 * @return A const reference to the map of signal names to RadarSignal objects.
228 */
229 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<fers_signal::RadarSignal>>&
230 getWaveforms() const noexcept
231 {
232 return _waveforms;
233 }
234
235 /**
236 * @brief Retrieves the map of antennas.
237 * @return A const reference to the map of antenna names to Antenna objects.
238 */
239 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<antenna::Antenna>>& getAntennas() const noexcept
240 {
241 return _antennas;
242 }
243
244 /**
245 * @brief Retrieves the map of timing prototypes.
246 * @return A const reference to the map of timing names to PrototypeTiming objects.
247 */
248 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<timing::PrototypeTiming>>&
249 getTimings() const noexcept
250 {
251 return _timings;
252 }
253
254 /**
255 * @brief Clears all objects and assets from the simulation world.
256 */
257 void clear() noexcept;
258
259 /**
260 * @brief Populates the event queue with the initial events for the simulation.
261 * This method should be called after all simulation objects have been parsed and added to the world.
262 */
264
265 /**
266 * @brief Dumps the current state of the event queue to a string for debugging.
267 * @return A formatted string representing the contents of the event queue.
268 */
269 [[nodiscard]] std::string dumpEventQueue() const;
270
271 /**
272 * @brief Gets a mutable reference to the global event queue.
273 * @return A reference to the priority queue of events.
274 */
275 [[nodiscard]] std::priority_queue<Event, std::vector<Event>, EventComparator>& getEventQueue() noexcept
276 {
277 return _event_queue;
278 }
279
280 /**
281 * @brief Gets a mutable reference to the global simulation state.
282 * @return A reference to the SimulationState object.
283 */
284 [[nodiscard]] SimulationState& getSimulationState() noexcept { return _simulation_state; }
285
286 private:
287 std::vector<std::unique_ptr<radar::Platform>> _platforms;
288
289 std::vector<std::unique_ptr<radar::Transmitter>> _transmitters;
290
291 std::vector<std::unique_ptr<radar::Receiver>> _receivers;
292
293 std::vector<std::unique_ptr<radar::Target>> _targets;
294
295 std::unordered_map<SimId, std::unique_ptr<fers_signal::RadarSignal>> _waveforms;
296
297 std::unordered_map<SimId, std::unique_ptr<antenna::Antenna>> _antennas;
298
299 std::unordered_map<SimId, std::unique_ptr<timing::PrototypeTiming>> _timings;
300
301 std::priority_queue<Event, std::vector<Event>, EventComparator> _event_queue;
302
303 SimulationState _simulation_state;
304 };
305}
Header file defining various types of antennas and their gain patterns.
The World class manages the simulator environment.
Definition world.h:39
void scheduleInitialEvents()
Populates the event queue with the initial events for the simulation.
Definition world.cpp:256
World()=default
void add(std::unique_ptr< radar::Platform > plat) noexcept
Adds a radar platform to the simulation world.
Definition world.cpp:38
void replace(std::unique_ptr< radar::Target > target)
Replaces an existing target, updating internal pointers.
Definition world.cpp:128
fers_signal::RadarSignal * findWaveform(const SimId id)
Finds a radar signal by ID.
Definition world.cpp:76
~World() noexcept=default
const std::vector< std::unique_ptr< radar::Target > > & getTargets() const noexcept
Retrieves the list of radar targets.
Definition world.h:200
radar::Target * findTarget(const SimId id)
Finds a target by ID.
Definition world.cpp:120
const std::unordered_map< SimId, std::unique_ptr< antenna::Antenna > > & getAntennas() const noexcept
Retrieves the map of antennas.
Definition world.h:239
radar::Receiver * findReceiver(const SimId id)
Finds a receiver by ID.
Definition world.cpp:112
radar::Transmitter * findTransmitter(const SimId id)
Finds a transmitter by ID.
Definition world.cpp:104
void clear() noexcept
Clears all objects and assets from the simulation world.
Definition world.cpp:243
const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms() const noexcept
Retrieves the map of radar signals (waveforms).
Definition world.h:230
timing::PrototypeTiming * findTiming(const SimId id)
Finds a timing source by ID.
Definition world.cpp:88
SimulationState & getSimulationState() noexcept
Gets a mutable reference to the global simulation state.
Definition world.h:284
antenna::Antenna * findAntenna(const SimId id)
Finds an antenna by ID.
Definition world.cpp:82
const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & getTimings() const noexcept
Retrieves the map of timing prototypes.
Definition world.h:249
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms() const noexcept
Retrieves the list of platforms.
Definition world.h:190
std::string dumpEventQueue() const
Dumps the current state of the event queue to a string for debugging.
Definition world.cpp:338
radar::Platform * findPlatform(const SimId id)
Finds a platform by ID.
Definition world.cpp:94
std::priority_queue< Event, std::vector< Event >, EventComparator > & getEventQueue() noexcept
Gets a mutable reference to the global event queue.
Definition world.h:275
const std::vector< std::unique_ptr< radar::Transmitter > > & getTransmitters() const noexcept
Retrieves the list of radar transmitters.
Definition world.h:220
const std::vector< std::unique_ptr< radar::Receiver > > & getReceivers() const noexcept
Retrieves the list of radar receivers.
Definition world.h:210
Defines the Platform class used in radar simulation.
Header file for the PrototypeTiming class.
Classes for handling radar waveforms and signals.
Radar Receiver class for managing signal reception and response handling.
Defines the core structures for the event-driven simulation engine.
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
Defines the global state for the event-driven simulation engine.
A custom comparator for the event priority queue.
Definition sim_events.h:57
Represents a single event in the simulation's time-ordered queue.
Definition sim_events.h:43
Holds the dynamic global state of the simulation.
Defines classes for radar targets and their Radar Cross-Section (RCS) models.
Header file for the Transmitter class in the radar namespace.