CARLA
 
载入中...
搜索中...
未找到
ActorDispatcher.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
13
14#include "Containers/Array.h"
15#include "Templates/Function.h"
16
17#include "ActorDispatcher.generated.h"
18
20
21/// Object in charge of binding ActorDefinitions to spawn functions, as well as
22/// keeping the registry of all the actors spawned.
23UCLASS()
24class CARLA_API UActorDispatcher : public UObject
25{
26 GENERATED_BODY()
27
28public:
29
30 using SpawnFunctionType = TFunction<FActorSpawnResult(const FTransform &, const FActorDescription &)>;
31
32 /// Bind a definition to a spawn function. When SpawnActor is called with a
33 /// matching description @a Functor is called.
34 ///
35 /// @warning Invalid definitions are ignored.
36 void Bind(FActorDefinition Definition, SpawnFunctionType SpawnFunction);
37
38 /// Bind all the definitions of @a ActorFactory to its spawn function.
39 ///
40 /// @warning Invalid definitions are ignored.
41 void Bind(ACarlaActorFactory &ActorFactory);
42
43 /// Spawns an actor based on @a ActorDescription at @a Transform. To properly
44 /// despawn an actor created with this function call DestroyActor.
45 ///
46 /// @return A pair containing the result of the spawn function and a view over
47 /// the actor and its properties. If the status is different of Success the
48 /// view is invalid.
49 TPair<EActorSpawnResultStatus, FCarlaActor*> SpawnActor(
50 const FTransform &Transform,
51 FActorDescription ActorDescription,
52 FCarlaActor::IdType DesiredId = 0);
53
54 /// ReSpawns an actor based on @a ActorDescription at @a Transform. To properly
55 /// despawn an actor created with this function call DestroyActor.
56 /// Used to respawn dormant actors.
57 ///
58 /// @return The actor to be respawned
59 AActor* ReSpawnActor(
60 const FTransform &Transform,
61 FActorDescription ActorDescription);
62
63 void PutActorToSleep(FCarlaActor::IdType Id, UCarlaEpisode* CarlaEpisode);
64
65 void WakeActorUp(FCarlaActor::IdType Id, UCarlaEpisode* CarlaEpisode);
66
67 /// Destroys an actor, properly removing it from the registry.
68 ///
69 /// Return true if the @a Actor is destroyed or already marked for
70 /// destruction, false if indestructible or nullptr.
71 //bool DestroyActor(AActor *Actor);
72
73 bool DestroyActor(FCarlaActor::IdType ActorId);
74
75 /// Register an actor that was not created using "SpawnActor" function but
76 /// that should be kept in the registry.
77 FCarlaActor* RegisterActor(
78 AActor &Actor,
79 FActorDescription ActorDescription,
80 FActorRegistry::IdType DesiredId = 0);
81
82 const TArray<FActorDefinition> &GetActorDefinitions() const
83 {
84 return Definitions;
85 }
86
88 {
89 return Registry;
90 }
91
93 {
94 return Registry;
95 }
96
97private:
98
99 UFUNCTION()
100 void OnActorDestroyed(AActor *Actor);
101
102 TArray<FActorDefinition> Definitions;
103
104 TArray<SpawnFunctionType> SpawnFunctions;
105
106 TArray<TSubclassOf<AActor>> Classes;
107
109
110};
Base class for Carla actor factories.
virtual FActorSpawnResult SpawnActor(const FTransform &SpawnAtTransform, const FActorDescription &ActorDescription)
Spawn an actor based on ActorDescription and Transform.
A registry of all the Carla actors.
FCarlaActor::IdType IdType
A view over an actor and its properties.
Definition CarlaActor.h:25
uint32 IdType
Definition CarlaActor.h:28
Object in charge of binding ActorDefinitions to spawn functions, as well as keeping the registry of a...
const FActorRegistry & GetActorRegistry() const
TFunction< FActorSpawnResult(const FTransform &, const FActorDescription &)> SpawnFunctionType
const TArray< FActorDefinition > & GetActorDefinitions() const
FActorRegistry & GetActorRegistry()
A simulation episode.
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
Result of an actor spawn function.