CARLA
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:
+ Collaboration diagram for UActorDispatcher:

Public Types

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

Public Member Functions

void Bind (FActorDefinition Definition, SpawnFunctionType SpawnFunction)
 Bind a definition to a spawn function. More...
 
void Bind (ACarlaActorFactory &ActorFactory)
 Bind all the definitions of ActorFactory to its spawn function. More...
 
bool DestroyActor (FCarlaActor::IdType ActorId)
 Destroys an actor, properly removing it from the registry. More...
 
const TArray< FActorDefinition > & GetActorDefinitions () const
 
const FActorRegistryGetActorRegistry () const
 
FActorRegistryGetActorRegistry ()
 
void PutActorToSleep (FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)
 
FCarlaActorRegisterActor (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. More...
 
AActorReSpawnActor (const FTransform &Transform, FActorDescription ActorDescription)
 ReSpawns an actor based on ActorDescription at Transform. More...
 
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActor (const FTransform &Transform, FActorDescription ActorDescription, FCarlaActor::IdType DesiredId=0)
 Spawns an actor based on ActorDescription at Transform. More...
 
void WakeActorUp (FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)
 

Private Member Functions

void OnActorDestroyed (AActor *Actor)
 

Private Attributes

TArray< TSubclassOf< AActor > > Classes
 
TArray< FActorDefinitionDefinitions
 
FActorRegistry Registry
 
TArray< SpawnFunctionTypeSpawnFunctions
 

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 24 of file ActorDispatcher.h.

Member Typedef Documentation

◆ SpawnFunctionType

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

Definition at line 30 of file ActorDispatcher.h.

Member Function Documentation

◆ Bind() [1/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 23 of file ActorDispatcher.cpp.

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

Referenced by Bind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Bind() [2/2]

void UActorDispatcher::Bind ( ACarlaActorFactory ActorFactory)

Bind all the definitions of ActorFactory to its spawn function.

Warning
Invalid definitions are ignored.

Definition at line 38 of file ActorDispatcher.cpp.

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

+ Here is the call graph for this function:

◆ 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 117 of file ActorDispatcher.cpp.

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

+ Here is the call graph for this function:

◆ GetActorDefinitions()

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

Definition at line 82 of file ActorDispatcher.h.

◆ GetActorRegistry() [1/2]

const FActorRegistry& UActorDispatcher::GetActorRegistry ( ) const
inline

Definition at line 87 of file ActorDispatcher.h.

◆ GetActorRegistry() [2/2]

FActorRegistry& UActorDispatcher::GetActorRegistry ( )
inline

Definition at line 92 of file ActorDispatcher.h.

◆ OnActorDestroyed()

void UActorDispatcher::OnActorDestroyed ( AActor Actor)
private

Definition at line 234 of file ActorDispatcher.cpp.

References FActorRegistry::Deregister(), FActorRegistry::FindCarlaActor(), FCarlaActor::GetActorId(), carla::ros2::ROS2::GetInstance(), FCarlaActor::IsActive(), and Registry.

Referenced by RegisterActor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PutActorToSleep()

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

Definition at line 224 of file ActorDispatcher.cpp.

References FActorRegistry::PutActorToSleep(), and Registry.

+ Here is the call graph for this function:

◆ 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 162 of file ActorDispatcher.cpp.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 86 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 48 of file ActorDispatcher.cpp.

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

Referenced by UCarlaEpisode::SpawnActorWithInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WakeActorUp()

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

Definition at line 229 of file ActorDispatcher.cpp.

References Registry, and FActorRegistry::WakeActorUp().

+ Here is the call graph for this function:

Member Data Documentation

◆ Classes

TArray<TSubclassOf<AActor> > UActorDispatcher::Classes
private

Definition at line 106 of file ActorDispatcher.h.

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

◆ Definitions

TArray<FActorDefinition> UActorDispatcher::Definitions
private

Definition at line 102 of file ActorDispatcher.h.

Referenced by Bind().

◆ Registry

FActorRegistry UActorDispatcher::Registry
private

◆ SpawnFunctions

TArray<SpawnFunctionType> UActorDispatcher::SpawnFunctions
private

Definition at line 104 of file ActorDispatcher.h.

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


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