CARLA
CarlaStatics.h
Go to the documentation of this file.
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 "Kismet/GameplayStatics.h"
15 #include "Kismet/BlueprintFunctionLibrary.h"
16 
17 #include "CarlaStatics.generated.h"
18 
19 // =============================================================================
20 // -- UCarlaStatics declaration ------------------------------------------------
21 // =============================================================================
22 
23 UCLASS()
24 class CARLA_API UCarlaStatics : public UBlueprintFunctionLibrary
25 {
26  GENERATED_BODY()
27 
28 public:
29 
30  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
31  static ACarlaGameModeBase *GetGameMode(const UObject *WorldContextObject);
32 
33  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
34  static UCarlaGameInstance *GetGameInstance(const UObject *WorldContextObject);
35 
36  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
37  static UCarlaEpisode *GetCurrentEpisode(const UObject *WorldContextObject);
38 
39  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
40  static UCarlaSettings *GetCarlaSettings(const UObject *WorldContextObject);
41 
42  UFUNCTION(BlueprintPure, Category="CARLA")
43  static TArray<FString> GetAllMapNames();
44 
45  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
46  static ACarlaRecorder* GetRecorder(const UObject *WorldContextObject);
47 
48  static CarlaReplayer* GetReplayer(const UObject *WorldContextObject);
49 
50  UFUNCTION(BlueprintPure, Category="CARLA", meta=(WorldContext="WorldContextObject"))
51  static ALargeMapManager* GetLargeMapManager(const UObject *WorldContextObject);
52 };
53 
54 // =============================================================================
55 // -- UCarlaStatics implementation ---------------------------------------------
56 // =============================================================================
57 
59 {
60  return Cast<ACarlaGameModeBase>(UGameplayStatics::GetGameMode(WorldContext));
61 }
62 
64 {
65  return Cast<UCarlaGameInstance>(UGameplayStatics::GetGameInstance(WorldContext));
66 }
67 
69 {
70  auto GameInstance = GetGameInstance(WorldContext);
71  return GameInstance != nullptr ? GameInstance->GetCarlaEpisode() : nullptr;
72 }
73 
75 {
76  auto GameInstance = GetGameInstance(WorldContext);
77  return GameInstance != nullptr ? GameInstance->GetCARLASettings() : nullptr;
78 }
79 
80 inline ACarlaRecorder* UCarlaStatics::GetRecorder(const UObject *WorldContextObject)
81 {
82  auto* Episode = UCarlaStatics::GetCurrentEpisode(WorldContextObject);
83  if (Episode)
84  {
85  return Episode->GetRecorder();
86  }
87  return nullptr;
88 }
89 
90 inline CarlaReplayer* UCarlaStatics::GetReplayer(const UObject *WorldContextObject)
91 {
92  auto* Episode = UCarlaStatics::GetCurrentEpisode(WorldContextObject);
93  if (Episode)
94  {
95  return Episode->GetReplayer();
96  }
97  return nullptr;
98 }
99 
101 {
102  ACarlaGameModeBase* GameMode = GetGameMode(WorldContextObject);
103  if (GameMode)
104  {
105  return GameMode->GetLMManager();
106  }
107  return nullptr;
108 }
The game instance contains elements that must be kept alive in between levels.
static UCarlaSettings * GetCarlaSettings(const UObject *WorldContextObject)
Definition: CarlaStatics.h:74
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:58
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
Definition: CarlaStatics.h:63
A simulation episode.
Definition: CarlaEpisode.h:38
Recorder for the simulation.
Definition: CarlaRecorder.h:76
Global settings for CARLA.
Definition: CarlaSettings.h:21
ALargeMapManager * GetLMManager() const
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:68
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
Definition: CarlaStatics.h:100
static CarlaReplayer * GetReplayer(const UObject *WorldContextObject)
Definition: CarlaStatics.h:90
Base class for the CARLA Game Mode.
static ACarlaRecorder * GetRecorder(const UObject *WorldContextObject)
Definition: CarlaStatics.h:80