CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
client
detail
Episode.h
Go to the documentation of this file.
1
// Copyright (c) 2026 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/AtomicSharedPtr.h
"
10
#include "
carla/NonCopyable.h
"
11
#include "
carla/RecurrentSharedFuture.h
"
12
#include "
carla/client/Timestamp.h
"
13
#include "
carla/client/WorldSnapshot.h
"
14
#include "
carla/client/detail/CachedActorList.h
"
15
#include "
carla/client/detail/CallbackList.h
"
16
#include "
carla/client/detail/EpisodeState.h
"
17
#include "
carla/client/detail/EpisodeProxy.h
"
18
#include "
carla/rpc/EpisodeInfo.h
"
19
20
#include <atomic>
21
#include <memory>
22
#include <vector>
23
24
namespace
carla
{
25
namespace
client
{
26
namespace
detail
{
27
28
class
Client
;
29
class
WalkerNavigation
;
30
31
/// Holds the current episode, and the current episode state.
32
///
33
/// The episode state changes in the background each time a world tick is
34
/// received. The episode may change with any background update if the
35
/// simulator has loaded a new episode.
36
class
Episode
37
:
public
std::enable_shared_from_this<Episode>,
38
private
NonCopyable
{
39
public
:
40
41
explicit
Episode
(
Client
&
client
, std::weak_ptr<Simulator> simulator);
42
43
~Episode
();
44
45
void
Listen
();
46
47
auto
GetId
()
const
{
48
return
GetState
()->GetEpisodeId();
49
}
50
51
/// Whether OnEpisodeChanged has finished for the episode GetId() returns.
52
bool
IsEpisodeChangeHandled
()
const
{
53
return
_handled_episode_id
->load() ==
GetId
();
54
}
55
56
std::shared_ptr<const EpisodeState>
GetState
()
const
{
57
return
_state
.load();
58
}
59
60
void
RegisterActor
(
rpc::Actor
actor) {
61
_actors
.
Insert
(std::move(actor));
62
}
63
64
std::optional<rpc::Actor>
GetActorById
(
ActorId
id
);
65
66
std::vector<rpc::Actor>
GetActorsById
(
const
std::vector<ActorId> &actor_ids);
67
68
std::vector<rpc::Actor>
GetActors
();
69
70
std::optional<WorldSnapshot>
WaitForState
(
time_duration
timeout) {
71
return
_snapshot
.WaitFor(timeout);
72
}
73
74
size_t
RegisterOnTickEvent
(std::function<
void
(
WorldSnapshot
)> callback) {
75
return
_on_tick_callbacks
.Push(std::move(callback));
76
}
77
78
void
RemoveOnTickEvent
(
size_t
id
) {
79
_on_tick_callbacks
.Remove(
id
);
80
}
81
82
size_t
RegisterOnMapChangeEvent
(std::function<
void
(
WorldSnapshot
)> callback) {
83
return
_on_map_change_callbacks
.Push(std::move(callback));
84
}
85
86
void
RemoveOnMapChangeEvent
(
size_t
id
) {
87
_on_map_change_callbacks
.Remove(
id
);
88
}
89
90
size_t
RegisterLightUpdateChangeEvent
(std::function<
void
(
WorldSnapshot
)> callback) {
91
return
_on_light_update_callbacks
.Push(std::move(callback));
92
}
93
94
void
RemoveLightUpdateChangeEvent
(
size_t
id
) {
95
_on_light_update_callbacks
.Remove(
id
);
96
}
97
98
void
SetPedestriansCrossFactor
(
float
percentage);
99
100
void
SetPedestriansSeed
(
unsigned
int
seed);
101
102
void
AddPendingException
(std::string e) {
103
_pending_exceptions
=
true
;
104
_pending_exceptions_msg
= e;
105
}
106
107
bool
HasMapChangedSinceLastCall
();
108
109
std::shared_ptr<WalkerNavigation>
CreateNavigationIfMissing
();
110
111
private
:
112
113
Episode
(
Client
&
client
,
const
rpc::EpisodeInfo
&info, std::weak_ptr<Simulator> simulator);
114
115
void
OnEpisodeStarted
();
116
117
void
OnEpisodeChanged
(uint64_t episode_id);
118
119
Client
&
_client
;
120
121
AtomicSharedPtr<const EpisodeState>
_state
;
122
123
std::string
_pending_exceptions_msg
;
124
125
CachedActorList
_actors
;
126
127
CallbackList<WorldSnapshot>
_on_tick_callbacks
;
128
129
CallbackList<WorldSnapshot>
_on_map_change_callbacks
;
130
131
CallbackList<WorldSnapshot>
_on_light_update_callbacks
;
132
133
RecurrentSharedFuture<WorldSnapshot>
_snapshot
;
134
135
AtomicSharedPtr<WalkerNavigation>
_walker_navigation
;
136
137
const
streaming::Token
_token
;
138
139
bool
_pending_exceptions
=
false
;
140
141
bool
_should_update_map
=
true
;
142
143
std::weak_ptr<Simulator>
_simulator
;
144
145
/// Shared with the TM reset thread, which may outlive this Episode.
146
std::shared_ptr<std::atomic<uint64_t>>
_handled_episode_id
;
147
};
148
149
}
// namespace detail
150
}
// namespace client
151
}
// namespace carla
AtomicSharedPtr.h
CachedActorList.h
CallbackList.h
EpisodeInfo.h
EpisodeProxy.h
EpisodeState.h
NonCopyable.h
RecurrentSharedFuture.h
Timestamp.h
WorldSnapshot.h
carla::AtomicSharedPtr
A very simple atomic shared ptr with release-acquire memory order.
Definition
AtomicSharedPtr.h:15
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::RecurrentSharedFuture
This class is meant to be used similar to a shared future, but the value can be set any number of tim...
Definition
RecurrentSharedFuture.h:43
carla::client::WorldSnapshot
Definition
WorldSnapshot.h:18
carla::client::detail::CachedActorList
Keeps a list of actor descriptions to avoid requesting each time the descriptions to the server.
Definition
CachedActorList.h:30
carla::client::detail::CachedActorList::Insert
void Insert(rpc::Actor actor)
Inserts an actor into the list.
Definition
CachedActorList.h:66
carla::client::detail::CallbackList
Definition
CallbackList.h:20
carla::client::detail::Client
Provides communication with the rpc and streaming servers of a CARLA simulator.
Definition
client/detail/Client.h:72
carla::client::detail::Episode::RemoveOnTickEvent
void RemoveOnTickEvent(size_t id)
Definition
Episode.h:78
carla::client::detail::Episode::_snapshot
RecurrentSharedFuture< WorldSnapshot > _snapshot
Definition
Episode.h:133
carla::client::detail::Episode::RegisterLightUpdateChangeEvent
size_t RegisterLightUpdateChangeEvent(std::function< void(WorldSnapshot)> callback)
Definition
Episode.h:90
carla::client::detail::Episode::_state
AtomicSharedPtr< const EpisodeState > _state
Definition
Episode.h:121
carla::client::detail::Episode::_actors
CachedActorList _actors
Definition
Episode.h:125
carla::client::detail::Episode::_simulator
std::weak_ptr< Simulator > _simulator
Definition
Episode.h:143
carla::client::detail::Episode::_on_tick_callbacks
CallbackList< WorldSnapshot > _on_tick_callbacks
Definition
Episode.h:127
carla::client::detail::Episode::AddPendingException
void AddPendingException(std::string e)
Definition
Episode.h:102
carla::client::detail::Episode::RegisterActor
void RegisterActor(rpc::Actor actor)
Definition
Episode.h:60
carla::client::detail::Episode::RegisterOnTickEvent
size_t RegisterOnTickEvent(std::function< void(WorldSnapshot)> callback)
Definition
Episode.h:74
carla::client::detail::Episode::CreateNavigationIfMissing
std::shared_ptr< WalkerNavigation > CreateNavigationIfMissing()
Definition
Episode.cpp:178
carla::client::detail::Episode::IsEpisodeChangeHandled
bool IsEpisodeChangeHandled() const
Whether OnEpisodeChanged has finished for the episode GetId() returns.
Definition
Episode.h:52
carla::client::detail::Episode::WaitForState
std::optional< WorldSnapshot > WaitForState(time_duration timeout)
Definition
Episode.h:70
carla::client::detail::Episode::GetActorsById
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &actor_ids)
Definition
Episode.cpp:149
carla::client::detail::Episode::_pending_exceptions_msg
std::string _pending_exceptions_msg
Definition
Episode.h:123
carla::client::detail::Episode::_handled_episode_id
std::shared_ptr< std::atomic< uint64_t > > _handled_episode_id
Shared with the TM reset thread, which may outlive this Episode.
Definition
Episode.h:146
carla::client::detail::Episode::RegisterOnMapChangeEvent
size_t RegisterOnMapChangeEvent(std::function< void(WorldSnapshot)> callback)
Definition
Episode.h:82
carla::client::detail::Episode::GetState
std::shared_ptr< const EpisodeState > GetState() const
Definition
Episode.h:56
carla::client::detail::Episode::GetActorById
std::optional< rpc::Actor > GetActorById(ActorId id)
Definition
Episode.cpp:137
carla::client::detail::Episode::OnEpisodeChanged
void OnEpisodeChanged(uint64_t episode_id)
Definition
Episode.cpp:164
carla::client::detail::Episode::_token
const streaming::Token _token
Definition
Episode.h:137
carla::client::detail::Episode::_walker_navigation
AtomicSharedPtr< WalkerNavigation > _walker_navigation
Definition
Episode.h:135
carla::client::detail::Episode::RemoveLightUpdateChangeEvent
void RemoveLightUpdateChangeEvent(size_t id)
Definition
Episode.h:94
carla::client::detail::Episode::OnEpisodeStarted
void OnEpisodeStarted()
Definition
Episode.cpp:157
carla::client::detail::Episode::GetId
auto GetId() const
Definition
Episode.h:47
carla::client::detail::Episode::_should_update_map
bool _should_update_map
Definition
Episode.h:141
carla::client::detail::Episode::_pending_exceptions
bool _pending_exceptions
Definition
Episode.h:139
carla::client::detail::Episode::_client
Client & _client
Definition
Episode.h:119
carla::client::detail::Episode::SetPedestriansSeed
void SetPedestriansSeed(unsigned int seed)
carla::client::detail::Episode::RemoveOnMapChangeEvent
void RemoveOnMapChangeEvent(size_t id)
Definition
Episode.h:86
carla::client::detail::Episode::HasMapChangedSinceLastCall
bool HasMapChangedSinceLastCall()
Definition
Episode.cpp:170
carla::client::detail::Episode::GetActors
std::vector< rpc::Actor > GetActors()
Definition
Episode.cpp:153
carla::client::detail::Episode::SetPedestriansCrossFactor
void SetPedestriansCrossFactor(float percentage)
carla::client::detail::Episode::_on_light_update_callbacks
CallbackList< WorldSnapshot > _on_light_update_callbacks
Definition
Episode.h:131
carla::client::detail::Episode::_on_map_change_callbacks
CallbackList< WorldSnapshot > _on_map_change_callbacks
Definition
Episode.h:129
carla::client::detail::Episode::Episode
Episode(Client &client, std::weak_ptr< Simulator > simulator)
Definition
Episode.cpp:39
carla::client::detail::Episode::Listen
void Listen()
Definition
Episode.cpp:57
carla::client::detail::WalkerNavigation
Definition
WalkerNavigation.h:27
carla::rpc::Actor
Definition
rpc/Actor.h:20
carla::rpc::EpisodeInfo
Definition
EpisodeInfo.h:19
carla::streaming::Token
A token that uniquely identify a stream.
Definition
Token.h:17
carla::time_duration
Positive time duration up to milliseconds resolution.
Definition
Time.h:20
carla::client::detail
Definition
AtomicList.h:18
carla::client
Definition
BasicAgent.h:24
carla::traffic_manager::ActorId
carla::ActorId ActorId
Definition
AtomicActorSet.h:21
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0