7 #include "CoreMinimal.h" 9 #include "GameFramework/Actor.h" 11 #include "Engine/LevelStreamingDynamic.h" 15 #include "LargeMapManager.generated.h" 29 const FTransform& InTransform)
30 : CarlaActor(InCarlaActor),
31 WorldLocation(
FDVector(InTransform.GetTranslation())),
32 Rotation(InTransform.GetRotation()) {}
41 USTRUCT(BlueprintType)
46 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category =
"Carla Map Tile")
50 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Carla Map Tile")
54 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category =
"Carla Map Tile")
55 ULevelStreamingDynamic* StreamingLevel =
nullptr;
57 bool TilesSpawned = false;
76 virtual void BeginPlay()
override;
78 void PreWorldOriginOffset(UWorld* InWorld, FIntVector InSrcOrigin, FIntVector InDstOrigin);
79 void PostWorldOriginOffset(UWorld* InWorld, FIntVector InSrcOrigin, FIntVector InDstOrigin);
81 void OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld);
82 void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld);
86 void RegisterInitialObjects();
90 UFUNCTION(Category=
"Large Map Manager")
91 void OnActorDestroyed(
AActor* DestroyedActor);
94 void Tick(
float DeltaTime) override;
96 UFUNCTION(BlueprintCallable, Category = "Large Map Manager")
97 void GenerateMap(FString InAssetsPath);
99 UFUNCTION(BlueprintCallable, Category = "Large Map Manager")
100 void GenerateLargeMap();
102 void GenerateMap(TArray<TPair<FString, FIntVector>> MapPathsIds);
104 UFUNCTION(BlueprintCallable, CallInEditor, Category = "Large Map Manager")
105 void ClearWorldAndTiles();
107 UFUNCTION(BlueprintCallable, CallInEditor, Category = "Large Map Manager")
108 void GenerateMap_Editor()
110 if (!LargeMapTilePath.IsEmpty()) GenerateMap(LargeMapTilePath);
115 UFUNCTION(BlueprintCallable, Category =
"Large Map Manager")
116 FIntVector GetNumTilesInXY()
const;
118 UFUNCTION(BlueprintCallable, Category =
"Large Map Manager")
119 int GetNumTiles()
const 121 return MapTiles.Num();
124 UFUNCTION(BlueprintCallable, Category =
"Large Map Manager")
125 bool IsLevelOfTileLoaded(FIntVector InTileID)
const;
129 return CurrentTilesLoaded.Contains(TileId);
134 return IsTileLoaded(GetTileID(Location));
139 return IsTileLoaded(GetTileID(Location));
142 FTransform GlobalToLocalTransform(
const FTransform& InTransform)
const;
143 FVector GlobalToLocalLocation(
const FVector& InLocation)
const;
145 FTransform LocalToGlobalTransform(
const FTransform& InTransform)
const;
146 FVector LocalToGlobalLocation(
const FVector& InLocation)
const;
148 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Large Map Manager")
149 FString LargeMapTilePath = "/Game/Carla/Maps/testmap";
150 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
151 FString LargeMapName = "testmap";
153 void SetTile0Offset(const FVector& Offset);
155 void SetTileSize(
float Size);
159 FVector GetTile0Offset();
161 void SetLayerStreamingDistance(
float Distance);
163 void SetActorStreamingDistance(
float Distance);
165 float GetLayerStreamingDistance() const;
167 float GetActorStreamingDistance() const;
169 UFUNCTION(BlueprintCallable, Category = "Large Map Manager")
170 FIntVector GetTileVectorID(FVector TileLocation) const;
172 FIntVector GetTileVectorID(
FDVector TileLocation) const;
178 UFUNCTION(BlueprintCallable, Category = "Large Map Manager")
179 FVector GetTileLocation(FIntVector TileVectorID) const;
183 FDVector GetTileLocationD(FIntVector TileVectorID) const;
186 TileID GetTileID(FVector TileLocation) const;
190 TileID GetTileID(FIntVector TileVectorID) const;
196 UFUNCTION(BlueprintCallable, Category = "Large Map Manager")
207 bool SpectatorAsEgo = false;
208 void ConsiderSpectatorAsEgo(
bool _SpectatorAsEgo);
212 void RemoveLandscapeCollisionIfHaveTerraMechanics(ULevel* InLevel);
214 void UpdateTilesState();
216 void RemovePendingActorsToRemove();
221 void CheckActiveActors();
224 void ConvertActiveToDormantActors();
229 void CheckDormantActors();
232 void ConvertDormantToActiveActors();
234 void CheckIfRebaseIsNeeded();
236 void GetTilesToConsider(
237 const
AActor* ActorToConsider,
238 TSet<
TileID>& OutTilesToConsider);
240 void GetTilesThatNeedToChangeState(
241 const TSet<
TileID>& InTilesToConsider,
242 TSet<
TileID>& OutTilesToBeVisible,
243 TSet<
TileID>& OutTilesToHidde);
245 void UpdateTileState(
246 const TSet<
TileID>& InTilesToUpdate,
247 bool InShouldBlockOnLoad,
248 bool InShouldBeLoaded,
249 bool InShouldBeVisible);
251 void UpdateCurrentTilesLoaded(
252 const TSet<
TileID>& InTilesToBeVisible,
253 const TSet<
TileID>& InTilesToHidde);
255 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
261 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
264 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
279 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
280 TSet<uint64> CurrentTilesLoaded;
283 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
284 FIntVector CurrentOriginInt{ 0 };
288 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Large Map Manager")
289 FVector Tile0Offset = FVector(0,0,0);
291 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
292 float TickInterval = 0.0f;
294 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
295 float LayerStreamingDistance = 3.0f * 1000.0f * 100.0f;
297 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
298 float ActorStreamingDistance = 2.0f * 1000.0f * 100.0f;
300 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
301 float RebaseOriginDistance = 2.0f * 1000.0f * 100.0f;
303 float LayerStreamingDistanceSquared = LayerStreamingDistance * LayerStreamingDistance;
304 float ActorStreamingDistanceSquared = ActorStreamingDistance * ActorStreamingDistance;
305 float RebaseOriginDistanceSquared = RebaseOriginDistance * RebaseOriginDistance;
307 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
308 float TileSide = 2.0f * 1000.0f * 100.0f;
310 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
311 FVector LocalTileOffset = FVector(0,0,0);
313 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
314 bool ShouldTilesBlockOnLoad = false;
317 void RegisterTilesInWorldComposition();
321 FString TileIDToString(TileID TileID);
323 void DumpTilesTable() const;
327 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Large Map Manager")
328 FString AssetsPath = "";
330 FString BaseTileMapPath = "/Game/Carla/Maps/LargeMap/EmptyTileBase";
332 FColor PositonMsgColor = FColor::Purple;
334 const int32 TilesDistMsgIndex = 100;
335 const int32 MaxTilesDistMsgIndex = TilesDistMsgIndex + 10;
337 const int32 ClientLocMsgIndex = 200;
338 const int32 MaxClientLocMsgIndex = ClientLocMsgIndex + 10;
340 UPROPERTY(EditAnywhere, Category = "Large Map Manager")
341 float MsgTime = 1.0f;
343 UPROPERTY(EditAnywhere, Category = "Large Map Manager")
344 bool bPrintMapInfo = true;
346 UPROPERTY(EditAnywhere, Category = "Large Map Manager")
347 bool bPrintErrors = false;
349 UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
350 bool bHasTerramechanics = false;
const FCarlaActor * CarlaActor
bool IsTileLoaded(FVector Location) const
FActiveActor(const FCarlaActor *InCarlaActor, const FTransform &InTransform)
bool IsTileLoaded(FDVector Location) const
Base class for CARLA wheeled vehicles.
geom::Transform Transform
bool IsTileLoaded(TileID TileId) const
A view over an actor and its properties.