CARLA
LibCarla/source/carla/rpc/EpisodeSettings.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/MsgPack.h"
10 #include "carla/MsgPackAdaptors.h"
11 
12 #ifdef LIBCARLA_INCLUDED_FROM_UE4
16 #endif // LIBCARLA_INCLUDED_FROM_UE4
17 
18 #include <boost/optional.hpp>
19 
20 namespace carla {
21 namespace rpc {
22 
24  public:
25 
26  // =========================================================================
27  // -- Public data members --------------------------------------------------
28  // =========================================================================
29 
30  bool synchronous_mode = false;
31 
32  bool no_rendering_mode = false;
33 
34  boost::optional<double> fixed_delta_seconds;
35 
36  bool substepping = true;
37 
38  double max_substep_delta_time = 0.01;
39 
40  int max_substeps = 10;
41 
42  float max_culling_distance = 0.0f;
43 
45 
46  float tile_stream_distance = 3000.f; // 3km
47 
48  float actor_active_distance = 2000.f; // 2km
49 
50  bool spectator_as_ego = true;
51 
52  MSGPACK_DEFINE_ARRAY(synchronous_mode, no_rendering_mode, fixed_delta_seconds, substepping,
53  max_substep_delta_time, max_substeps, max_culling_distance, deterministic_ragdolls,
54  tile_stream_distance, actor_active_distance, spectator_as_ego);
55 
56  // =========================================================================
57  // -- Constructors ---------------------------------------------------------
58  // =========================================================================
59 
60  EpisodeSettings() = default;
61 
63  bool synchronous_mode,
64  bool no_rendering_mode,
65  double fixed_delta_seconds = 0.0,
66  bool substepping = true,
67  double max_substep_delta_time = 0.01,
68  int max_substeps = 10,
69  float max_culling_distance = 0.0f,
70  bool deterministic_ragdolls = true,
71  float tile_stream_distance = 3000.f,
72  float actor_active_distance = 2000.f,
73  bool spectator_as_ego = true)
74  : synchronous_mode(synchronous_mode),
75  no_rendering_mode(no_rendering_mode),
76  fixed_delta_seconds(
77  fixed_delta_seconds > 0.0 ? fixed_delta_seconds : boost::optional<double>{}),
78  substepping(substepping),
79  max_substep_delta_time(max_substep_delta_time),
80  max_substeps(max_substeps),
81  max_culling_distance(max_culling_distance),
82  deterministic_ragdolls(deterministic_ragdolls),
83  tile_stream_distance(tile_stream_distance),
84  actor_active_distance(actor_active_distance),
85  spectator_as_ego(spectator_as_ego) {}
86 
87  // =========================================================================
88  // -- Comparison operators -------------------------------------------------
89  // =========================================================================
90 
91  bool operator==(const EpisodeSettings &rhs) const {
92  return
93  (synchronous_mode == rhs.synchronous_mode) &&
94  (no_rendering_mode == rhs.no_rendering_mode) &&
95  (substepping == rhs.substepping) &&
96  (fixed_delta_seconds == rhs.fixed_delta_seconds) &&
97  (max_substep_delta_time == rhs.max_substep_delta_time) &&
98  (max_substeps == rhs.max_substeps) &&
99  (max_culling_distance == rhs.max_culling_distance) &&
100  (deterministic_ragdolls == rhs.deterministic_ragdolls) &&
101  (tile_stream_distance == rhs.tile_stream_distance) &&
102  (actor_active_distance == rhs.actor_active_distance) &&
103  (spectator_as_ego == rhs.spectator_as_ego);
104  }
105 
106  bool operator!=(const EpisodeSettings &rhs) const {
107  return !(*this == rhs);
108  }
109 
110  // =========================================================================
111  // -- Conversions to UE4 types ---------------------------------------------
112  // =========================================================================
113 
114 #ifdef LIBCARLA_INCLUDED_FROM_UE4
115 
116  EpisodeSettings(const FEpisodeSettings &Settings)
117  : EpisodeSettings(
118  Settings.bSynchronousMode,
119  Settings.bNoRenderingMode,
120  Settings.FixedDeltaSeconds.Get(0.0),
121  Settings.bSubstepping,
122  Settings.MaxSubstepDeltaTime,
123  Settings.MaxSubsteps,
124  Settings.MaxCullingDistance,
125  Settings.bDeterministicRagdolls,
126  Settings.TileStreamingDistance,
127  Settings.ActorActiveDistance,
128  Settings.SpectatorAsEgo) {
129  constexpr float CMTOM = 1.f/100.f;
130  tile_stream_distance = CMTOM * Settings.TileStreamingDistance;
131  actor_active_distance = CMTOM * Settings.ActorActiveDistance;
132  }
133 
134  operator FEpisodeSettings() const {
135  constexpr float MTOCM = 100.f;
136  FEpisodeSettings Settings;
139  if (fixed_delta_seconds.has_value()) {
141  }
142  Settings.bSubstepping = substepping;
144  Settings.MaxSubsteps = max_substeps;
147  Settings.TileStreamingDistance = MTOCM * tile_stream_distance;
148  Settings.ActorActiveDistance = MTOCM * actor_active_distance;
149  Settings.SpectatorAsEgo = spectator_as_ego;
150 
151  return Settings;
152  }
153 
154 #endif // LIBCARLA_INCLUDED_FROM_UE4
155  };
156 
157 } // namespace rpc
158 } // namespace carla
MSGPACK_DEFINE_ARRAY(synchronous_mode, no_rendering_mode, fixed_delta_seconds, substepping, max_substep_delta_time, max_substeps, max_culling_distance, deterministic_ragdolls, tile_stream_distance, actor_active_distance, spectator_as_ego)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
bool operator!=(const EpisodeSettings &rhs) const
bool operator==(const EpisodeSettings &rhs) const
EpisodeSettings(bool synchronous_mode, bool no_rendering_mode, double fixed_delta_seconds=0.0, bool substepping=true, double max_substep_delta_time=0.01, int max_substeps=10, float max_culling_distance=0.0f, bool deterministic_ragdolls=true, float tile_stream_distance=3000.f, float actor_active_distance=2000.f, bool spectator_as_ego=true)