19#include "GameFramework/Pawn.h"
20#include "Materials/MaterialParameterCollectionInstance.h"
32#include "CarlaEpisode.generated.h"
37UCLASS(BlueprintType, Blueprintable)
38class CARLA_API UCarlaEpisode :
public UObject
48 UCarlaEpisode(const FObjectInitializer &ObjectInitializer);
61 UFUNCTION(BlueprintCallable)
62 bool LoadNewEpisode(const FString &MapString,
bool ResetSettings =
true);
68 bool LoadNewOpendriveEpisode(
69 const FString &OpenDriveString,
70 const
carla::rpc::OpendriveGenerationParameters &Params);
76 UFUNCTION(BlueprintCallable)
77 UFUNCTION(BlueprintCallable)
80 return EpisodeSettings;
83 UFUNCTION(BlueprintCallable)
97 UFUNCTION(BlueprintCallable)
98 const FString &GetMapName()
const
104 double GetElapsedGameTime()
const
106 return ElapsedGameTime;
110 double GetVisualGameTime()
const
112 return VisualGameTime;
116 void SetVisualGameTime(
double Time)
118 VisualGameTime = Time;
120 if (MaterialParameters)
122 MaterialParameters->SetScalarParameterValue(FName(
"VisualTime"), VisualGameTime);
127 UFUNCTION(BlueprintCallable)
128 const TArray<FActorDefinition> &GetActorDefinitions()
const
130 return ActorDispatcher->GetActorDefinitions();
134 UFUNCTION(BlueprintCallable)
135 TArray<FTransform> GetRecommendedSpawnPoints()
const;
140 return MapGeoReference;
147 UFUNCTION(BlueprintCallable)
148 APawn *GetSpectatorPawn()
const
153 UFUNCTION(BlueprintCallable)
161 return ActorDispatcher->GetActorRegistry();
166 return ActorDispatcher->GetActorRegistry();
179 return ActorDispatcher->GetActorRegistry().FindCarlaActor(ActorId);
187 return ActorDispatcher->GetActorRegistry().FindCarlaActor(
Actor);
195 return ActorDispatcher->GetActorRegistry().GetDescriptionFromStream(StreamId);
206 TPair<EActorSpawnResultStatus, FCarlaActor*> SpawnActorWithInfo(
207 const FTransform &Transform,
215 AActor* ReSpawnActorWithInfo(
216 AActor* ReSpawnActorWithInfo(
217 const FTransform &Transform,
221 auto result = ActorDispatcher->ReSpawnActor(NewTransform, thisActorDescription);
222 if (Recorder->IsEnabled())
234 UFUNCTION(BlueprintCallable)
235 UFUNCTION(BlueprintCallable)
237 const FTransform &Transform,
242 return SpawnActorWithInfo(Transform, std::move(ActorDescription)).Value->GetActor();
251 const FString& SocketName =
"");
254 UFUNCTION(BlueprintCallable)
262 return DestroyActor(ActorId);
271 if (bIsPrimaryServer)
273 GetFrameData().AddEvent(
277 if (Recorder->IsEnabled())
281 Recorder->AddEvent(std::move(RecEvent));
284 return ActorDispatcher->DestroyActor(ActorId);
289 ActorDispatcher->PutActorToSleep(ActorId,
this);
294 ActorDispatcher->WakeActorUp(ActorId,
this);
324 return Recorder->GetReplayer();
327 std::string StartRecorder(std::string name,
bool AdditionalData);
329 FIntVector GetCurrentMapOrigin()
const {
return CurrentMapOrigin; }
331 void SetCurrentMapOrigin(
const FIntVector& NewOrigin) { CurrentMapOrigin = NewOrigin; }
333 FFrameData& GetFrameData() {
return FrameData; }
337 bool bIsPrimaryServer =
true;
344 void InitializeAtBeginPlay()
350 ActorDispatcher->Bind(ActorFactory);
353 std::pair<int, FCarlaActor&> TryToCreateReplayerActor(
357 unsigned int desiredId);
359 bool SetActorSimulatePhysics(
FCarlaActor &CarlaActor,
bool bEnabled);
361 bool SetActorCollisions(
FCarlaActor &CarlaActor,
bool bEnabled);
367void TickTimers(
float DeltaSeconds)
370 ElapsedGameTime += DeltaSeconds;
372 SetVisualGameTime(VisualGameTime + DeltaSeconds);
373 #if defined(WITH_ROS2)
375 if (ROS2->IsEnabled())
376 ROS2->SetTimestamp(GetElapsedGameTime());
384double ElapsedGameTime = 0.0;
387double VisualGameTime = 0.0;
390UPROPERTY(VisibleAnywhere)
394UPROPERTY(VisibleAnywhere)
398UPROPERTY(VisibleAnywhere)
402UPROPERTY(VisibleAnywhere)
403APawn *Spectator =
nullptr;
406UPROPERTY(VisibleAnywhere)
410UPROPERTY(VisibleAnywhere)
411UMaterialParameterCollectionInstance *MaterialParameters =
nullptr;
420FIntVector CurrentMapOrigin;
FString CarlaGetRelevantTagAsString(const TSet< crp::CityObjectLabel > &SemanticTags)
const FCarlaActor * FindCarlaActor(const AActor *Actor) const
void WakeActorUp(IdType Id, UCarlaEpisode *CarlaEpisode)
void PutActorToSleep(IdType Id, UCarlaEpisode *CarlaEpisode)
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld Actor
Recorder for the simulation
IdType GetActorId() const
负责将ActorDefinitions绑定到生成函数,以及 维护所有已生成参与者的注册表
static std::shared_ptr< ROS2 > GetInstance()
geom::Transform Transform
uint32_t stream_id_type
流ID的类型定义。