CARLA
Loading...
Searching...
No Matches
ActorRegistry.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
10
11#include <util/ue-header-guard-begin.h>
12#include "Containers/Map.h"
13#include <util/ue-header-guard-end.h>
14
15#include <unordered_map>
16
17/// A registry of all the Carla actors.
19{
20public:
21
23 using ValueType = TSharedPtr<FCarlaActor>;
24
25private:
26
27 // using DatabaseType = std::unordered_map<IdType, FCarlaActor>;
28 using DatabaseType = TMap<IdType, TSharedPtr<FCarlaActor>>;
29
30 // ===========================================================================
31 /// @name Actor registry functions
32 // ===========================================================================
33 /// @{
34public:
35
36 /// Register the @a Actor in the database. A new ID will be assign to this
37 /// actor.
38 ///
39 /// @warning Undefined if an actor is registered more than once.
40 FCarlaActor* Register(AActor &Actor, FActorDescription Description, IdType DesiredId = 0);
41
42 void Deregister(IdType Id);
43
44 void Deregister(AActor *Actor);
45
46 /// @}
47 // ===========================================================================
48 /// @name Look up functions
49 // ===========================================================================
50 /// @{
51
52 int32 Num() const
53 {
54 return Actors.Num();
55 }
56
57 bool IsEmpty() const
58 {
59 return Num() == 0;
60 }
61
62 bool Contains(uint32 Id) const
63 {
64 return ActorDatabase.Find(Id) != nullptr;
65 }
66
68 {
69 ValueType* CarlaActorPtr = ActorDatabase.Find(Id);
70 return CarlaActorPtr ? CarlaActorPtr->Get() : nullptr;
71 }
72
74 {
75 const ValueType* CarlaActorPtr = ActorDatabase.Find(Id);
76 return CarlaActorPtr ? CarlaActorPtr->Get() : nullptr;
77 }
78
80 {
81 IdType* PtrToId = Ids.Find(Actor);
82 return PtrToId ? FindCarlaActor(*PtrToId) : nullptr;
83 }
84
85 const FCarlaActor* FindCarlaActor(const AActor *Actor) const
86 {
87 const IdType* PtrToId = Ids.Find(Actor);
88 return PtrToId ? FindCarlaActor(*PtrToId) : nullptr;
89 }
90
91 /// Returns the sensor whose data stream has id @a Id, or nullptr.
93
95
96 void PutActorToSleep(IdType Id, UCarlaEpisode* CarlaEpisode);
97
98 void WakeActorUp(IdType Id, UCarlaEpisode* CarlaEpisode);
99
100 /// @}
101 // ===========================================================================
102 /// @name Range iteration support
103 // ===========================================================================
104 /// @{
105public:
106
107 auto begin() const noexcept
108 {
109 return ActorDatabase.begin();
110 }
111
112 auto end() const noexcept
113 {
114 return ActorDatabase.end();
115 }
116
117 /// @}
118private:
119
120 TSharedPtr<FCarlaActor> MakeCarlaActor(
121 IdType Id,
122 AActor &Actor,
123 FActorDescription Description,
124 carla::rpc::ActorState InState) const;
125
127 AActor &Actor) const;
128
129 TMap<IdType, AActor *> Actors;
130
131 TMap<AActor *, IdType> Ids;
132
134
136};
A registry of all the Carla actors.
FString GetDescriptionFromStream(carla::streaming::detail::stream_id_type Id)
TMap< AActor *, IdType > Ids
int32 Num() const
TSharedPtr< FCarlaActor > MakeCarlaActor(IdType Id, AActor &Actor, FActorDescription Description, carla::rpc::ActorState InState) const
static IdType ID_COUNTER
FCarlaActor * FindCarlaActorFromStream(carla::streaming::detail::stream_id_type Id)
Returns the sensor whose data stream has id Id, or nullptr.
bool Contains(uint32 Id) const
FCarlaActor::IdType IdType
bool IsEmpty() const
FCarlaActor * FindCarlaActor(const AActor *Actor)
auto begin() const noexcept
FCarlaActor * Register(AActor &Actor, FActorDescription Description, IdType DesiredId=0)
Register the Actor in the database.
TMap< IdType, AActor * > Actors
TSharedPtr< FCarlaActor > ValueType
const FCarlaActor * FindCarlaActor(const AActor *Actor) const
FCarlaActor MakeFakeActor(AActor &Actor) const
DatabaseType ActorDatabase
void Deregister(IdType Id)
FCarlaActor * FindCarlaActor(IdType Id)
void PutActorToSleep(IdType Id, UCarlaEpisode *CarlaEpisode)
const FCarlaActor * FindCarlaActor(IdType Id) const
auto end() const noexcept
TMap< IdType, TSharedPtr< FCarlaActor > > DatabaseType
void WakeActorUp(IdType Id, UCarlaEpisode *CarlaEpisode)
A view over an actor and its properties.
Definition CarlaActor.h:25
uint32 IdType
Definition CarlaActor.h:28
A simulation episode.
A description of a Carla Actor with all its variation.