CARLA
 
载入中...
搜索中...
未找到
CarlaGameModeBase.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
9#include "CoreMinimal.h"
10#include "GameFramework/GameModeBase.h"
11
13#include <boost/optional.hpp>
14#include <carla/rpc/Texture.h>
17
30
31#include "CarlaGameModeBase.generated.h"
32
33/// Base class for the CARLA Game Mode.
34UCLASS(HideCategories=(ActorTick))
35class CARLA_API ACarlaGameModeBase : public AGameModeBase
36{
37 GENERATED_BODY()
38
39public:
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
99 ALargeMapManager* GetLMManager() const {
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 // Gravitational acceleration. Default is earth one, which is approximately 9.81 m/s^2
116 UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Sensor Gravity")
117 float IMUISensorGravity = 9.81f;
118
119protected:
120
121 void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override;
122
123 void RestartPlayer(AController *NewPlayer) override;
124
125 void BeginPlay() override;
126
127 void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
128
129 void Tick(float DeltaSeconds) override;
130
131private:
132
133 void SpawnActorFactories();
134
135 void StoreSpawnPoints();
136
137 void GenerateSpawnPoints();
138
139 void ParseOpenDrive();
140
141 void RegisterEnvironmentObjects();
142
143 void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray<FName>& OutLevelNames);
144
145 void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings);
146
147 UPROPERTY()
148 UCarlaGameInstance *GameInstance = nullptr;
149
150 UPROPERTY()
151 UTaggerDelegate *TaggerDelegate = nullptr;
152
153 UPROPERTY()
154 UCarlaSettingsDelegate *CarlaSettingsDelegate = nullptr;
155
156 UPROPERTY()
157 UCarlaEpisode *Episode = nullptr;
158
159 UPROPERTY()
160 ACarlaRecorder *Recorder = nullptr;
161
162 UPROPERTY()
163 UObjectRegister* ObjectRegister = nullptr;
164
165 /// The class of Weather to spawn.
166 UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
167 TSubclassOf<AWeather> WeatherClass;
168
169 /// List of actor spawners that will be used to define and spawn the actors
170 /// available in game.
171 UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
172 TSet<TSubclassOf<ACarlaActorFactory>> ActorFactories;
173
174 UPROPERTY()
175 TArray<FTransform> SpawnPointsTransforms;
176
177 UPROPERTY()
178 TArray<ACarlaActorFactory *> ActorFactoryInstances;
179
180 UPROPERTY()
181 ATrafficLightManager* TrafficLightManager = nullptr;
182
183 UPROPERTY()
184 ALargeMapManager* LMManager = nullptr;
185
186 FDelegateHandle OnEpisodeSettingsChangeHandle;
187
188 boost::optional<carla::road::Map> Map;
189
190 int PendingLevelsToLoad = 0;
191 int PendingLevelsToUnLoad = 0;
192
193 bool ReadyToRegisterObjects = false;
194
195 // We keep a global uuid to allow the load/unload layer methods to be called
196 // in the same tick
197 int32 LatentInfoUUID = 0;
198
199};
Base class for Carla actor factories.
Base class for the CARLA Game Mode.
const UCarlaEpisode & GetCarlaEpisode() const
const boost::optional< carla::road::Map > & GetMap() const
Recorder for the simulation
Class In charge of creating and assigning traffic light groups, controllers and components.
A simulation episode.
The game instance contains elements that must be kept alive in between levels.
Used to set settings for every actor that is spawned into the world.
Used to tag every actor that is spawned into the world.
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133