25 return static_cast<target_t &
>(data);
28 template <
typename RangeT>
31 if (!missing_ids.empty()) {
38 :
Episode(client, client.GetEpisodeInfo(), simulator) {}
49 }
catch (
const std::exception &e) {
50 log_error(
"exception trying to disconnect from episode:", e.what());
55 std::weak_ptr<Episode> weak = shared_from_this();
57 auto self = weak.lock();
58 if (
self !=
nullptr) {
61 auto next = std::make_shared<const EpisodeState>(
CastData(*data));
62 auto prev =
self->GetState();
65 bool HasMapChanged = next->HasMapChanged();
66 bool UpdateLights = next->IsLightUpdatePending();
69 if(self->_pending_exceptions) {
72 self->_pending_exceptions =
false;
75 auto exception(self->_pending_exceptions_msg);
77 self->_snapshot.SetException(std::runtime_error(exception));
81 bool episode_changed = (next->GetEpisodeId() != prev->GetEpisodeId());
84 if (prev->GetFrame() >= next->GetFrame() && !episode_changed) {
85 self->_on_tick_callbacks.Call(next);
88 }
while (!self->_state.compare_exchange(&prev, next));
90 if(UpdateLights || HasMapChanged) {
91 self->_on_light_update_callbacks.Call(next);
95 self->_should_update_map =
true;
100 self->OnEpisodeChanged();
104 self->_snapshot.SetValue(next);
107 self->_on_tick_callbacks.Call(next);
115 if (!actor.has_value()) {
117 if (!actor_list.empty()) {
118 actor = std::move(actor_list.front());
153 std::shared_ptr<WalkerNavigation> nav;
156 if (nav ==
nullptr) {
157 auto new_nav = std::make_shared<WalkerNavigation>(
_simulator);
160 }
while (nav ==
nullptr);
AtomicSharedPtr< const EpisodeState > _state
static SharedPtr< SensorData > Deserialize(Buffer &&buffer)
Holds the current episode, and the current episode state.
std::vector< rpc::Actor > GetActors()
static void log_error(Args &&... args)
This file contains definitions of common data structures used in traffic manager. ...
std::shared_ptr< WalkerNavigation > CreateNavigationIfMissing()
Represents the state of all the actors of an episode at a given frame.
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
Keeps a list of actor descriptions to avoid requesting each time the descriptions to the server...
std::vector< rpc::Actor > GetActorsById(const RangeT &range) const
Retrieve the actors matching the ids in range.
boost::optional< rpc::Actor > GetActorById(ActorId id) const
Retrieve the actor matching id, or empty optional if actor is not cached.
static auto & CastData(const sensor::SensorData &data)
void Insert(rpc::Actor actor)
Inserts an actor into the list.
Base class for all the objects containing data generated by a sensor.
void InsertRange(RangeT range)
Inserts a range containing actors.
const streaming::Token _token
boost::optional< rpc::Actor > GetActorById(ActorId id)
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &ids)
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &actor_ids)
std::shared_ptr< const EpisodeState > GetState() const
Provides communication with the rpc and streaming servers of a CARLA simulator.
std::vector< ActorId > GetMissingIds(const RangeT &range) const
Return the actor ids present in range that haven't been added to this list.
State of the episode at a given frame.
Episode(Client &client, std::weak_ptr< Simulator > simulator)
void UnSubscribeFromStream(const streaming::Token &token)
CallbackList< WorldSnapshot > _on_tick_callbacks
std::weak_ptr< Simulator > _simulator
bool HasMapChangedSinceLastCall()
static auto GetActorsById_Impl(Client &client, CachedActorList &actors, const RangeT &actor_ids)
AtomicSharedPtr< WalkerNavigation > _walker_navigation