From 5011f248daafb04a397df00083194c76e316f240 Mon Sep 17 00:00:00 2001 From: JoseMartinez <44341347+JoseM98@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:47:27 +0100 Subject: [PATCH] Commandlet iterates over all tiles of the map. --- ...perPositionForWorldPartitionCommandlet.cpp | 71 ++++++++++++------- ...roperPositionForWorldPartitionCommandlet.h | 2 + 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/Commandlet/SetProperPositionForWorldPartitionCommandlet.cpp b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/Commandlet/SetProperPositionForWorldPartitionCommandlet.cpp index 3462197ba..d56b4f82e 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/Commandlet/SetProperPositionForWorldPartitionCommandlet.cpp +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/Commandlet/SetProperPositionForWorldPartitionCommandlet.cpp @@ -16,6 +16,8 @@ #include "EditorLevelLibrary.h" #include "MapGen/LargeMapManager.h" + + DEFINE_LOG_CATEGORY(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet); @@ -42,41 +44,33 @@ int32 USetProperPositionForWorldPartitionCommandlet::Main(const FString &Params) ParseCommandLine(*Params, Tokens, Switches, ParamsMap ); FString BaseLevelName = ParamsMap["BaseLevelName"]; - FIntVector CurrentTilesInXY = FIntVector(FCString::Atof(*ParamsMap["CTileX"]),FCString::Atof(*ParamsMap["CTileY"]), 0); - UEditorLevelLibrary::LoadLevel(*BaseLevelName); - UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Valid Map loaded")); - UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("MapName %s"), *BaseLevelName); + UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Valid Map loaded, MapName %s"), *BaseLevelName); AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass()); if (QueryActor != nullptr) { ALargeMapManager* LmManager = Cast(QueryActor); - FIntVector NumTilesInXY = LmManager->GetNumTilesInXY(); - float TileSize = LmManager->GetTileSize(); - FVector Tile0Offset = LmManager->GetTile0Offset(); - - FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY); - UEditorLevelLibrary::SaveCurrentLevel(); - - UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString())); + + const FIntVector NumTilesInXY = LmManager->GetNumTilesInXY(); + const float TileSize = LmManager->GetTileSize(); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString())); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("TileSize is %f"), (TileSize)); - UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile0Offset is %s"), *(Tile0Offset.ToString())); - UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name)); - - UEditorLevelLibrary::LoadLevel(CarlaTile.Name); - - FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f); - FVector MaxPosition = FVector((CurrentTilesInXY.X + 1.0f) * TileSize, (CurrentTilesInXY.Y + 1.0f) * -TileSize, 0.0f); - - - TArray FoundActors; - UGameplayStatics::GetAllActorsOfClass(GEditor->GetEditorWorldContext().World(), AActor::StaticClass(), FoundActors); - - for (AActor* CA : FoundActors) + + UEditorLevelLibrary::SaveCurrentLevel(); + + for(int TileX = 0; TileX < NumTilesInXY.X; TileX++) { - CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics); + for(int TileY = 0; TileY < NumTilesInXY.Y; TileY++) + { + if(TileX != 0 || TileY != 0) + { + UEditorLevelLibrary::LoadLevel(*BaseLevelName); + UEditorLevelLibrary::SaveCurrentLevel(); + ProcessTile(FIntVector(TileX, TileY, 0), TileSize); + } + } } + } else { UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Error, TEXT("Largemapmanager not found ")); @@ -88,4 +82,29 @@ int32 USetProperPositionForWorldPartitionCommandlet::Main(const FString &Params) return 0; } +void USetProperPositionForWorldPartitionCommandlet::ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize) +{ + AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass()); + if (QueryActor != nullptr) + { + ALargeMapManager* LmManager = Cast(QueryActor); + UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString())); + const FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY); + + UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name)); + UEditorLevelLibrary::LoadLevel(CarlaTile.Name); + + const FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f); + + TArray FoundActors; + UGameplayStatics::GetAllActorsOfClass(GEditor->GetEditorWorldContext().World(), AActor::StaticClass(), FoundActors); + for (AActor* CA : FoundActors) + { + CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics); + } + + UEditorLevelLibrary::SaveCurrentLevel(); + } +} + #endif diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/Commandlet/SetProperPositionForWorldPartitionCommandlet.h b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/Commandlet/SetProperPositionForWorldPartitionCommandlet.h index 11c9305d8..3c7055c36 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/Commandlet/SetProperPositionForWorldPartitionCommandlet.h +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/Commandlet/SetProperPositionForWorldPartitionCommandlet.h @@ -38,5 +38,7 @@ public: virtual int32 Main(const FString &Params) override; + void ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize); + #endif // WITH_EDITORONLY_DATA };