27 virtual VIPRA_MAP_INIT = 0;
28 virtual VIPRA_MAP_RESET = 0;
36 _objectiveTypes.clear();
40 virtual void objective_added(std::string
const& type,
44 virtual void area_added(std::string
const& name,
49 [[nodiscard]]
virtual auto collision(
VIPRA::f3d point)
const ->
bool
51 return std::any_of(_obstacles.begin(), _obstacles.end(), [&](
auto const& obstacle) {
52 return obstacle.is_point_inside(point);
58 if ( collision(radius.center()) )
return true;
60 return std::any_of(_obstacles.begin(), _obstacles.end(),
62 return Geometry::do_intersect(obstacle, radius);
66 [[nodiscard]]
virtual auto ray_hit(
VIPRA::f3d start,
69 VIPRA::f_pnt hit = std::numeric_limits<VIPRA::f_pnt>::max();
70 for (
auto const& obstacle : _obstacles ) {
71 for (
auto const& edge : obstacle.sides() ) {
72 if ( ! edge.does_intersect({start, end}) )
continue;
73 auto intersection = edge.intersection_point({start, end});
74 hit = std::min(hit, start.distance_to(intersection));
83 obstacle.center().y, obstacle.center().z);
84 _obstacles.push_back(obstacle);
86 if ( _initialized ) obstacle_added(obstacle);
91 objective.center().y, objective.center().z);
92 if ( ! _objectives.contains(type) ) _objectives[type] = {};
94 _objectives[type].push_back(objective);
96 if ( _initialized ) objective_added(type, objective);
100 VIPRA::Log::debug(
"Adding Spawn at {}, {}, {}", spawn.center().x, spawn.center().y,
102 _spawns.push_back(spawn);
106 VIPRA::Log::debug(
"Adding Area at {}, {}, {}", polygon.center().x, polygon.center().y,
108 _areas[name] = polygon;
110 if ( _initialized ) area_added(name, polygon);
113 [[nodiscard]]
auto get_objectives()
const
114 -> std::map<std::string, std::vector<VIPRA::Geometry::Polygon>>
const&
118 [[nodiscard]]
auto get_objectives(std::string
const& type)
const
119 -> std::vector<VIPRA::Geometry::Polygon>
const&
121 auto iter = _objectives.find(type);
122 if ( iter == _objectives.end() ) {
123 VIPRA_BASE_MODULE_ERROR(
"Map",
"Map does NOT have objectives of type: {}", type);
129 [[nodiscard]]
auto get_dimensions()
const ->
VIPRA::f3d {
return _dimensions; }
130 [[nodiscard]]
auto get_objective_types()
const -> std::vector<std::string>
const&
132 return _objectiveTypes;
134 [[nodiscard]]
auto get_obstacles()
const -> std::vector<VIPRA::Geometry::Polygon>
const&
138 [[nodiscard]]
auto get_spawns()
const -> std::vector<VIPRA::Geometry::Polygon>
const&
142 [[nodiscard]]
auto get_areas()
const -> std::map<std::string, VIPRA::Geometry::Polygon>
153 VIPRA_BASE_MODULE_ERROR(
"Map",
"Input Module failed to load map obstacles");
157 VIPRA_BASE_MODULE_ERROR(
"Map",
"Input Module failed to load map objectives");
161 VIPRA_BASE_MODULE_ERROR(
"Map",
162 "Input Module failed to load map pedestrians spawn areas");
166 VIPRA_BASE_MODULE_ERROR(
"Map",
"Input Module failed to load map areas");
168 _obstacles = std::move(obstacles.value());
169 _objectives = std::move(objectives.value());
170 _spawns = std::move(spawns.value());
171 _areas = std::move(areas.value());
173 for (
auto const& [type, _] : _objectives ) {
174 _objectiveTypes.push_back(type);
177 find_dimensions(_obstacles, _objectives, _spawns, _areas);
179 _spawns.size(), _areas.size());
182 init_step(_obstacles, _objectives, _spawns, _areas);
188 std::vector<VIPRA::Geometry::Polygon> _obstacles;
189 std::map<std::string, std::vector<VIPRA::Geometry::Polygon>> _objectives;
190 std::vector<VIPRA::Geometry::Polygon> _spawns;
191 std::map<std::string, VIPRA::Geometry::Polygon> _areas;
192 std::vector<std::string> _objectiveTypes;
194 bool _initialized{
false};
197 void find_dimensions(
198 std::vector<VIPRA::Geometry::Polygon>
const& obstacles,
199 std::map<std::string, std::vector<VIPRA::Geometry::Polygon>>
const& objectives,
200 std::vector<VIPRA::Geometry::Polygon>
const& spawns,
201 std::map<std::string, VIPRA::Geometry::Polygon>
const& areas)
203 auto setToMax = [&](
auto const& polygon) {
204 for (
auto const& edge : polygon.sides() ) {
205 _dimensions.x = std::max({_dimensions.x, edge.start.x, edge.end.x});
206 _dimensions.y = std::max({_dimensions.y, edge.start.y, edge.end.y});
207 _dimensions.z = std::max({_dimensions.z, edge.start.z, edge.end.z});
211 auto setToAllMax = [&](
auto const& polygons) {
212 for (
auto const& polygon : polygons ) {
217 setToAllMax(obstacles);
220 for (
auto const& [_, polygons] : objectives ) {
221 setToAllMax(polygons);
224 for (
auto const& [_, polygon] : areas ) {
233 virtual ~Map() =
default;
235 Map(
const Map&) =
default;
236 Map(Map&&)
noexcept =
default;
237 auto operator=(
const Map&) -> Map& =
default;
238 auto operator=(Map&&)
noexcept -> Map& =
default;