32 if (
nullptr != Cast<ACarlaWheeledVehicle>(Actor))
36 else if (
nullptr != Cast<ACharacter>(Actor))
40 else if (
nullptr != Cast<ATrafficLightBase>(Actor))
44 else if (
nullptr != Cast<ATrafficSignBase>(Actor))
48 else if (
nullptr != Cast<ASensor>(Actor))
60 for (
auto &&Tag : SemanticTags)
62 if ((Tag != crp::CityObjectLabel::None) && (Tag != crp::CityObjectLabel::Other))
65 return (Str.EndsWith(TEXT(
"s")) ? Str.LeftChop(1) : Str);
68 return TEXT(
"unknown");
75 bool IsDormant = CarlaActor && (CarlaActor->
IsDormant());
79 Actors.Add(DesiredId, &Actor);
80 Ids.Add(&Actor, DesiredId);
86 if (DesiredId != 0 && Id != DesiredId) {
88 if (!
Actors.Contains(DesiredId))
96 Actors.Emplace(Id, &Actor);
97 if (
Ids.Contains(&Actor))
102 TEXT(
"This actor's memory address is already registered, "
103 "either you forgot to deregister the actor "
104 "or the actor was garbage collected."));
113 StaleActor->TheActor =
nullptr;
119 Ids.Emplace(&Actor, Id);
123 for (
const auto& Elem : Description.
Variations)
125 const FString& Key = Elem.Key;
129 FString TagString = Key + TEXT(
":") + Attribute.
Value;
133 constexpr int32 MaxTagLength = 1000;
134 if (TagString.Len() > MaxTagLength)
135 TagString = TagString.Left(MaxTagLength) + TEXT(
"...");
136 Actor.Tags.Add(FName(*TagString));
139 TSharedPtr<FCarlaActor> View =
140 MakeCarlaActor(Id, Actor, std::move(Description), crp::ActorState::Active);
142 TSharedPtr<FCarlaActor>& Result =
ActorDatabase.Emplace(Id, MoveTemp(View));
152 if(!CarlaActor)
return;
167 check(Actor !=
nullptr);
169 check(CarlaActor->
GetActor() == Actor);
179 auto Info = MakeShared<FActorInfo>();
180 Info->Description = std::move(Description);
184 if (Info->Description.Id.IsEmpty())
190 Info->SerializedData.id = Id;
191 Info->SerializedData.description = Info->Description;
192 Info->SerializedData.bounding_box = Info->BoundingBox;
193 Info->SerializedData.semantic_tags.reserve(Info->SemanticTags.Num());
194 for (
auto &&Tag : Info->SemanticTags)
196 using tag_t =
decltype(Info->SerializedData.semantic_tags)::value_type;
197 Info->SerializedData.semantic_tags.emplace_back(
static_cast<tag_t
>(Tag));
199 auto *Sensor = Cast<ASensor>(&Actor);
200 if (Sensor !=
nullptr)
202 const auto &Token = Sensor->GetToken();
203 Info->SerializedData.stream_token =
decltype(Info->SerializedData.stream_token)(
204 std::begin(Token.data),
205 std::end(Token.data));
208 TSharedPtr<FCarlaActor> CarlaActor =
211 std::move(Info), Type,
212 InState, Actor.GetWorld());
260 UE_LOG(LogCarla, Error, TEXT(
"Failed to attach actor %d to %d during wake up"), Id, CarlaActor->
GetParent());
274 const ASensor *Sensor = Cast<ASensor>(Item.Value->GetActor());
275 if (Sensor ==
nullptr)
283 return Item.Value.Get();
292 if (CarlaActor ==
nullptr)
FString CarlaGetRelevantTagAsString(const TSet< crp::CityObjectLabel > &SemanticTags)
static FCarlaActor::ActorType FActorRegistry_GetActorType(const AActor *Actor)
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
static void GetTagsOfTaggedActor(const AActor &Actor, TSet< crp::CityObjectLabel > &Tags)
Retrieve the tags of an already tagged actor.
static FString GetTagAsString(crp::CityObjectLabel Tag)
Transform a CityObjectLabel into a string.
FString GetDescriptionFromStream(carla::streaming::detail::stream_id_type Id)
TMap< AActor *, IdType > Ids
TSharedPtr< FCarlaActor > MakeCarlaActor(IdType Id, AActor &Actor, FActorDescription Description, carla::rpc::ActorState InState) const
FCarlaActor * FindCarlaActorFromStream(carla::streaming::detail::stream_id_type Id)
Returns the sensor whose data stream has id Id, or nullptr.
FCarlaActor::IdType IdType
FCarlaActor * Register(AActor &Actor, FActorDescription Description, IdType DesiredId=0)
Register the Actor in the database.
TMap< IdType, AActor * > Actors
DatabaseType ActorDatabase
void Deregister(IdType Id)
FCarlaActor * FindCarlaActor(IdType Id)
void PutActorToSleep(IdType Id, UCarlaEpisode *CarlaEpisode)
void WakeActorUp(IdType Id, UCarlaEpisode *CarlaEpisode)
A view over an actor and its properties.
carla::rpc::AttachmentType GetAttachmentType() const
static TSharedPtr< FCarlaActor > ConstructCarlaActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, ActorType Type, carla::rpc::ActorState InState, UWorld *World)
TWeakObjectPtr< AActor > TheActor
Weak: World Partition can stream out (destroy) the actor without going through the episode,...
const FActorInfo * GetActorInfo() const
IdType GetActorId() const
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
const TArray< IdType > & GetChildren() const
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
static FBoundingBox GetActorBoundingBox(const AActor *Actor, uint8 InTagQueried=0xFF)
Compute the bounding box of the given Carla actor.
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid)
Attach Child to Parent.
Serializes a stream endpoint.
const auto & get_stream_id() const
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
A description of a Carla Actor with all its variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
FString Id
Display ID that identifies the actor.
FActorDescription Description