CARLA
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
UActorDispatcher Class Reference

Object in charge of binding ActorDefinitions to spawn functions, as well as keeping the registry of all the actors spawned. More...

#include <ActorDispatcher.h>

+ Inheritance diagram for UActorDispatcher:

Public Types

using SpawnFunctionType = TFunction< FActorSpawnResult(const FTransform &, const FActorDescription &)>
 

Public Member Functions

void Bind (ACarlaActorFactory &ActorFactory)
 Bind all the definitions of ActorFactory to its spawn function.
 
void Bind (FActorDefinition Definition, SpawnFunctionType SpawnFunction)
 Bind a definition to a spawn function.
 
void BindNewDefinitions (ACarlaActorFactory &ActorFactory)
 Bind the definitions of ActorFactory that are not bound yet.
 
bool DestroyActor (FCarlaActor::IdType ActorId)
 Destroys an actor, properly removing it from the registry.
 
const TArray< FActorDefinition > & GetActorDefinitions () const
 
FActorRegistry & GetActorRegistry ()
 
const FActorRegistry & GetActorRegistry () const
 
void PutActorToSleep (FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)
 
FCarlaActor * RegisterActor (AActor &Actor, FActorDescription ActorDescription, FActorRegistry::IdType DesiredId=0)
 Register an actor that was not created using "SpawnActor" function but that should be kept in the registry.
 
void ReleaseContentPack (const FString &MountPoint)
 Forget the classes of every definition that refers to content under MountPoint (a content pack being unmounted).
 
AActor * ReSpawnActor (const FTransform &Transform, FActorDescription ActorDescription)
 ReSpawns an actor based on ActorDescription at Transform.
 
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActor (const FTransform &Transform, FActorDescription ActorDescription, FCarlaActor::IdType DesiredId=0)
 Spawns an actor based on ActorDescription at Transform.
 
void WakeActorUp (FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)
 

Private Member Functions

void OnActorDestroyed (AActor *Actor)
 

Private Attributes

TMap< FString, TSubclassOf< AActor > > Classes
 
TArray< FActorDefinition > Definitions
 UPROPERTY so the garbage collector clears the class references when a content pack's classes are destroyed; a plain array kept dangling TSubclassOf pointers that ReleaseContentPack then dereferenced.
 
FActorRegistry Registry
 
TArray< SpawnFunctionType > SpawnFunctions
 

Detailed Description

Object in charge of binding ActorDefinitions to spawn functions, as well as keeping the registry of all the actors spawned.

Definition at line 26 of file ActorDispatcher.h.

Member Typedef Documentation

◆ SpawnFunctionType

using UActorDispatcher::SpawnFunctionType = TFunction<FActorSpawnResult(const FTransform &, const FActorDescription &)>

Definition at line 32 of file ActorDispatcher.h.

Member Function Documentation

◆ Bind() [1/2]

void UActorDispatcher::Bind ( ACarlaActorFactory &  ActorFactory)

Bind all the definitions of ActorFactory to its spawn function.

Warning
Invalid definitions are ignored.

Definition at line 78 of file ActorDispatcher.cpp.

References Bind(), ACarlaActorFactory::GetDefinitions(), and ACarlaActorFactory::SpawnActor().

◆ Bind() [2/2]

void UActorDispatcher::Bind ( FActorDefinition  Definition,
SpawnFunctionType  SpawnFunction 
)

Bind a definition to a spawn function.

When SpawnActor is called with a matching description Functor is called.

Warning
Invalid definitions are ignored.

Definition at line 26 of file ActorDispatcher.cpp.

References UActorBlueprintFunctionLibrary::CheckActorDefinition(), FActorDefinition::Class, Classes, Definitions, FActorDefinition::Id, SpawnFunctions, and FActorDefinition::UId.

Referenced by Bind(), and BindNewDefinitions().

◆ BindNewDefinitions()

void UActorDispatcher::BindNewDefinitions ( ACarlaActorFactory &  ActorFactory)

Bind the definitions of ActorFactory that are not bound yet.

Definitions are normally bound once, when the episode registers its factories. A content pack mounted later brings new catalog entries, and its blueprints must become available without waiting for a world load.

Definition at line 62 of file ActorDispatcher.cpp.

References Bind(), Definitions, ACarlaActorFactory::GetDefinitions(), FActorDefinition::Id, and ACarlaActorFactory::SpawnActor().

◆ DestroyActor()

bool UActorDispatcher::DestroyActor ( FCarlaActor::IdType  ActorId)

Destroys an actor, properly removing it from the registry.

Return true if the Actor is destroyed or already marked for destruction, false if indestructible or nullptr.

Definition at line 176 of file ActorDispatcher.cpp.

References FActorRegistry::Deregister(), FActorInfo::Description, FActorRegistry::FindCarlaActor(), FCarlaActor::GetActor(), FCarlaActor::GetActorInfo(), FActorDescription::Id, Registry, and Success.

◆ GetActorDefinitions()

const TArray< FActorDefinition > & UActorDispatcher::GetActorDefinitions ( ) const
inline

Definition at line 96 of file ActorDispatcher.h.

◆ GetActorRegistry() [1/2]

FActorRegistry & UActorDispatcher::GetActorRegistry ( )
inline

Definition at line 106 of file ActorDispatcher.h.

◆ GetActorRegistry() [2/2]

const FActorRegistry & UActorDispatcher::GetActorRegistry ( ) const
inline

Definition at line 101 of file ActorDispatcher.h.

Referenced by UCarlaEpisode::SerializeActorWithPrimaryIds().

◆ OnActorDestroyed()

void UActorDispatcher::OnActorDestroyed ( AActor *  Actor)
private

◆ PutActorToSleep()

void UActorDispatcher::PutActorToSleep ( FCarlaActor::IdType  Id,
UCarlaEpisode *  CarlaEpisode 
)

Definition at line 325 of file ActorDispatcher.cpp.

References FActorRegistry::PutActorToSleep(), and Registry.

◆ RegisterActor()

FCarlaActor * UActorDispatcher::RegisterActor ( AActor &  Actor,
FActorDescription  ActorDescription,
FActorRegistry::IdType  DesiredId = 0 
)

Register an actor that was not created using "SpawnActor" function but that should be kept in the registry.

Definition at line 221 of file ActorDispatcher.cpp.

References ActorROS2Handler::FlattenSteeringCurve(), FCarlaActor::GetActorId(), carla::ros2::ROS2::GetInstance(), FActorDescription::Id, OnActorDestroyed(), FActorRegistry::Register(), Registry, and FActorDescription::Variations.

Referenced by UCarlaEpisode::InitializeAtBeginPlay(), and SpawnActor().

◆ ReleaseContentPack()

void UActorDispatcher::ReleaseContentPack ( const FString &  MountPoint)

Forget the classes of every definition that refers to content under MountPoint (a content pack being unmounted).

Slots are kept so UIds stay valid; spawning such a definition fails until the next episode.

Definition at line 41 of file ActorDispatcher.cpp.

References Classes, ACarlaActorFactory::DefinitionReferencesPath(), Definitions, and FActorDefinition::Id.

◆ ReSpawnActor()

AActor * UActorDispatcher::ReSpawnActor ( const FTransform &  Transform,
FActorDescription  ActorDescription 
)

ReSpawns an actor based on ActorDescription at Transform.

To properly despawn an actor created with this function call DestroyActor. Used to respawn dormant actors.

Returns
The actor to be respawned

Definition at line 138 of file ActorDispatcher.cpp.

References FActorSpawnResult::Actor, FActorDescription::Class, Classes, FActorDescription::Id, SpawnFunctions, FActorSpawnResult::Status, and FActorDescription::UId.

◆ SpawnActor()

TPair< EActorSpawnResultStatus, FCarlaActor * > UActorDispatcher::SpawnActor ( const FTransform &  Transform,
FActorDescription  ActorDescription,
FCarlaActor::IdType  DesiredId = 0 
)

Spawns an actor based on ActorDescription at Transform.

To properly despawn an actor created with this function call DestroyActor.

Returns
A pair containing the result of the spawn function and a view over the actor and its properties. If the status is different of Success the view is invalid.

Definition at line 88 of file ActorDispatcher.cpp.

References FActorSpawnResult::Actor, FActorDescription::Class, Classes, FActorDescription::Id, FActorSpawnResult::IsValid(), RegisterActor(), SpawnFunctions, FActorSpawnResult::Status, ATagger::TagActor(), and FActorDescription::UId.

Referenced by UCarlaEpisode::SpawnActorWithInfo().

◆ WakeActorUp()

void UActorDispatcher::WakeActorUp ( FCarlaActor::IdType  Id,
UCarlaEpisode *  CarlaEpisode 
)

Definition at line 330 of file ActorDispatcher.cpp.

References Registry, and FActorRegistry::WakeActorUp().

Member Data Documentation

◆ Classes

TMap<FString, TSubclassOf<AActor> > UActorDispatcher::Classes
private

Definition at line 125 of file ActorDispatcher.h.

Referenced by Bind(), ReleaseContentPack(), ReSpawnActor(), and SpawnActor().

◆ Definitions

TArray<FActorDefinition> UActorDispatcher::Definitions
private

UPROPERTY so the garbage collector clears the class references when a content pack's classes are destroyed; a plain array kept dangling TSubclassOf pointers that ReleaseContentPack then dereferenced.

Definition at line 120 of file ActorDispatcher.h.

Referenced by Bind(), BindNewDefinitions(), and ReleaseContentPack().

◆ Registry

FActorRegistry UActorDispatcher::Registry
private

◆ SpawnFunctions

TArray<SpawnFunctionType> UActorDispatcher::SpawnFunctions
private

Definition at line 122 of file ActorDispatcher.h.

Referenced by Bind(), ReSpawnActor(), and SpawnActor().


The documentation for this class was generated from the following files: