CARLA
 
载入中...
搜索中...
未找到
ActorRegistry.h
浏览该文件的文档.
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
10
11#include "Containers/Map.h"
12
14#include <carla/Iterator.h>
16
17#include <unordered_map>
18
19/// A registry of all the Carla actors.
21{
22public:
23
25 using ValueType = TSharedPtr<FCarlaActor>;
26
27private:
28
29 // using DatabaseType = std::unordered_map<IdType, FCarlaActor>;
30 using DatabaseType = TMap<IdType, TSharedPtr<FCarlaActor>>;
31
32 // ===========================================================================
33 /// @name Actor registry functions
34 // ===========================================================================
35 /// @{
36public:
37
38 /// Register the @a Actor in the database. A new ID will be assign to this
39 /// actor.
40 ///
41 /// @warning Undefined if an actor is registered more than once.
42 FCarlaActor* Register(AActor &Actor, FActorDescription Description, IdType DesiredId = 0);
43
44 void Deregister(IdType Id);
45
46 void Deregister(AActor *Actor);
47
48 /// @}
49 // ===========================================================================
50 /// @name Look up functions
51 // ===========================================================================
52 /// @{
53
54 int32 Num() const
55 {
56 return Actors.Num();
57 }
58
59 bool IsEmpty() const
60 {
61 return Num() == 0;
62 }
63
64 bool Contains(uint32 Id) const
65 {
66 return ActorDatabase.Find(Id) != nullptr;
67 }
68
70 {
71 ValueType* CarlaActorPtr = ActorDatabase.Find(Id);
72 return CarlaActorPtr ? CarlaActorPtr->Get() : nullptr;
73 }
74
76 {
77 const ValueType* CarlaActorPtr = ActorDatabase.Find(Id);
78 return CarlaActorPtr ? CarlaActorPtr->Get() : nullptr;
79 }
80
82 {
83 IdType* PtrToId = Ids.Find(Actor);
84 return PtrToId ? FindCarlaActor(*PtrToId) : nullptr;
85 }
86
87 const FCarlaActor* FindCarlaActor(const AActor *Actor) const
88 {
89 const IdType* PtrToId = Ids.Find(Actor);
90 return PtrToId ? FindCarlaActor(*PtrToId) : nullptr;
91 }
92
94
95 void PutActorToSleep(IdType Id, UCarlaEpisode* CarlaEpisode);
96
97 void WakeActorUp(IdType Id, UCarlaEpisode* CarlaEpisode);
98
99 /// @}
100 // ===========================================================================
101 /// @name Range iteration support
102 // ===========================================================================
103 /// @{
104public:
105
106 auto begin() const noexcept
107 {
108 return ActorDatabase.begin();
109 }
110
111 auto end() const noexcept
112 {
113 return ActorDatabase.end();
114 }
115
116 /// @}
117private:
118
119 TSharedPtr<FCarlaActor> MakeCarlaActor(
120 IdType Id,
121 AActor &Actor,
122 FActorDescription Description,
123 carla::rpc::ActorState InState) const;
124
126 AActor &Actor) const;
127
128 TMap<IdType, AActor *> Actors;
129
130 TMap<AActor *, IdType> Ids;
131
133
135};
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
TMap< IdType, TSharedPtr< FCarlaActor > > DatabaseType
static IdType ID_COUNTER
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
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.
uint32_t stream_id_type
Definition Types.h:18
A description of a Carla Actor with all its variation.