CARLA
CarlaGameModeBase.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 
9 #include "CoreMinimal.h"
10 #include "GameFramework/GameModeBase.h"
11 
13 #include <boost/optional.hpp>
14 #include <carla/rpc/Texture.h>
17 
28 #include "Carla/Weather/Weather.h"
29 #include "MapGen/LargeMapManager.h"
30 
31 #include "CarlaGameModeBase.generated.h"
32 
33 /// Base class for the CARLA Game Mode.
34 UCLASS(HideCategories=(ActorTick))
35 class CARLA_API ACarlaGameModeBase : public AGameModeBase
36 {
37  GENERATED_BODY()
38 
39 public:
40 
41  ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer);
42 
44  {
45  check(Episode != nullptr);
46  return *Episode;
47  }
48 
49  const boost::optional<carla::road::Map>& GetMap() const {
50  return Map;
51  }
52 
53  const FString GetFullMapPath() const;
54 
55  // get path relative to Content folder
56  const FString GetRelativeMapPath() const;
57 
58  UFUNCTION(Exec, Category = "CARLA Game Mode")
59  void DebugShowSignals(bool enable);
60 
61  UFUNCTION(BlueprintCallable, Category = "CARLA Game Mode")
62  ATrafficLightManager* GetTrafficLightManager();
63 
64  UFUNCTION(Category = "Carla Game Mode", BlueprintCallable)
65  const TArray<FTransform>& GetSpawnPointsTransforms() const{
66  return SpawnPointsTransforms;
67  }
68 
69  UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
70  TArray<FBoundingBox> GetAllBBsOfLevel(uint8 TagQueried = 0xFF) const;
71 
72  UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
73  TArray<FEnvironmentObject> GetEnvironmentObjects(uint8 QueriedTag = 0xFF) const
74  {
75  return ObjectRegister->GetEnvironmentObjects(QueriedTag);
76  }
77 
78  void EnableEnvironmentObjects(const TSet<uint64>& EnvObjectIds, bool Enable);
79 
80  void EnableOverlapEvents();
81 
82  void CheckForEmptyMeshes();
83 
84  UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
85  void LoadMapLayer(int32 MapLayers);
86 
87  UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
88  void UnLoadMapLayer(int32 MapLayers);
89 
90  UFUNCTION(Category = "Carla Game Mode")
91  ULevel* GetULevelFromName(FString LevelName);
92 
93  UFUNCTION(BlueprintCallable, Category = "Carla Game Mode")
94  void OnLoadStreamLevel();
95 
96  UFUNCTION(BlueprintCallable, Category = "Carla Game Mode")
97  void OnUnloadStreamLevel();
98 
100  return LMManager;
101  }
102 
103  AActor* FindActorByName(const FString& ActorName);
104 
105  UTexture2D* CreateUETexture(const carla::rpc::TextureColor& Texture);
106  UTexture2D* CreateUETexture(const carla::rpc::TextureFloatColor& Texture);
107 
108  void ApplyTextureToActor(
109  AActor* Actor,
110  UTexture2D* Texture,
111  const carla::rpc::MaterialParameter& TextureParam);
112 
113  TArray<FString> GetNamesOfAllActors();
114 
115 protected:
116 
117  void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override;
118 
119  void RestartPlayer(AController *NewPlayer) override;
120 
121  void BeginPlay() override;
122 
123  void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
124 
125  void Tick(float DeltaSeconds) override;
126 
127 private:
128 
129  void SpawnActorFactories();
130 
131  void StoreSpawnPoints();
132 
133  void GenerateSpawnPoints();
134 
135  void ParseOpenDrive();
136 
137  void RegisterEnvironmentObjects();
138 
139  void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray<FName>& OutLevelNames);
140 
141  void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings);
142 
143  UPROPERTY()
144  UCarlaGameInstance *GameInstance = nullptr;
145 
146  UPROPERTY()
147  UTaggerDelegate *TaggerDelegate = nullptr;
148 
149  UPROPERTY()
150  UCarlaSettingsDelegate *CarlaSettingsDelegate = nullptr;
151 
152  UPROPERTY()
153  UCarlaEpisode *Episode = nullptr;
154 
155  UPROPERTY()
156  ACarlaRecorder *Recorder = nullptr;
157 
158  UPROPERTY()
159  UObjectRegister* ObjectRegister = nullptr;
160 
161  /// The class of Weather to spawn.
162  UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
163  TSubclassOf<AWeather> WeatherClass;
164 
165  /// List of actor spawners that will be used to define and spawn the actors
166  /// available in game.
167  UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
168  TSet<TSubclassOf<ACarlaActorFactory>> ActorFactories;
169 
170  UPROPERTY()
171  TArray<FTransform> SpawnPointsTransforms;
172 
173  UPROPERTY()
174  TArray<ACarlaActorFactory *> ActorFactoryInstances;
175 
176  UPROPERTY()
177  ATrafficLightManager* TrafficLightManager = nullptr;
178 
179  ALargeMapManager* LMManager = nullptr;
180 
181  FDelegateHandle OnEpisodeSettingsChangeHandle;
182 
183  boost::optional<carla::road::Map> Map;
184 
185  int PendingLevelsToLoad = 0;
186  int PendingLevelsToUnLoad = 0;
187 
188  bool ReadyToRegisterObjects = false;
189 
190  // We keep a global uuid to allow the load/unload layer methods to be called
191  // in the same tick
192  int32 LatentInfoUUID = 0;
193 
194 };
Base class for Carla actor factories.
Used to tag every actor that is spawned into the world.
The game instance contains elements that must be kept alive in between levels.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
Used to set settings for every actor that is spawned into the world.
carla::SharedPtr< cc::Actor > Actor
A simulation episode.
Definition: CarlaEpisode.h:38
Recorder for the simulation.
Definition: CarlaRecorder.h:76
const boost::optional< carla::road::Map > & GetMap() const
ALargeMapManager * GetLMManager() const
Base class for the CARLA Game Mode.
const UCarlaEpisode & GetCarlaEpisode() const
Class In charge of creating and assigning traffic light groups, controllers and components.