From 79e54af4fa8764340723ffa9d0c53f7047bf7616 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 12 Jul 2022 09:27:22 +0200 Subject: [PATCH] Removed static variable of SavePath --- .../Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp | 7 ++++--- .../Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp index ec2613473..6b5c5f441 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp @@ -25,7 +25,6 @@ constexpr float ParticleDiameter = 0.04f; constexpr float TerrainDepth = 0.40f; -static FString SavePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()); std::string FParticle::ToString() const{ return std::string(carla::rpc::FromFString(FString::Printf(TEXT("%.2lf %.2lf %.2lf %.2lf "), @@ -101,7 +100,7 @@ void FHeightMapData::Clear() } void FDenseTile::InitializeTile(float ParticleSize, float Depth, - FDVector TileOrigin, FDVector TileEnd, const FHeightMapData &HeightMap) + FDVector TileOrigin, FDVector TileEnd, const FString& SavePath, const FHeightMapData &HeightMap) { std::string FileName = std::string(TCHAR_TO_UTF8(*( SavePath + TileOrigin.ToString() + ".tile" ) ) ); @@ -272,7 +271,7 @@ FDenseTile& FSparseHighDetailMap::InitializeRegion(uint64_t TileId) Tile.InitializeTile( ParticleDiameter, TerrainDepth, TileCenter, TileCenter + FDVector(TileSize, TileSize, 0.f), - Heightmap); + SavePath, Heightmap); return Tile; } @@ -451,6 +450,7 @@ void UCustomTerrainPhysicsComponent::BeginPlay() FString LevelName = GetWorld()->GetMapName(); LevelName.RemoveFromStart(GetWorld()->StreamingLevelsPrefix); SavePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()) + LevelName + "_Terrain/"; + SparseMap.SavePath = SavePath; // Creating the FileManager IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile(); #undef CreateDirectory @@ -497,6 +497,7 @@ void UCustomTerrainPhysicsComponent::TickComponent(float DeltaTime, GetOwner()->SetActorLocation(LocationVector); LastUpdatedPosition = GetOwner()->GetActorLocation(); + SparseMap.Update( LastUpdatedPosition, Radius.X, Radius.Y ); for (ACarlaWheeledVehicle* Vehicle : Vehicles) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h index 321d6a357..daf0c529c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h @@ -48,7 +48,7 @@ struct FHeightMapData struct FDenseTile { void InitializeTile(float ParticleSize, float Depth, - FDVector TileOrigin, FDVector TileEnd, const FHeightMapData &HeightMap); + FDVector TileOrigin, FDVector TileEnd, const FString& SavePath, const FHeightMapData &HeightMap); std::vector GetParticlesInRadius(FDVector Position, float Radius); // Format DenseTile to "PosX PosY PosZ\n Particles" @@ -96,6 +96,7 @@ public: void Clear(); + FString SavePath; private: std::unordered_map Map; std::unordered_map TilesToWrite; @@ -159,6 +160,8 @@ public: FString NeuralModelFile = ""; FVector LastUpdatedPosition; + + FString SavePath; private: void ApplyForces();