Added timer to update pool position every 30 seconds
This commit is contained in:
parent
43b4a1e179
commit
c6a83cb27c
|
@ -197,6 +197,7 @@ void AVegetationManager::BeginPlay()
|
||||||
LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld());
|
LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld());
|
||||||
FWorldDelegates::LevelAddedToWorld.AddUObject(this, &AVegetationManager::OnLevelAddedToWorld);
|
FWorldDelegates::LevelAddedToWorld.AddUObject(this, &AVegetationManager::OnLevelAddedToWorld);
|
||||||
FWorldDelegates::LevelRemovedFromWorld.AddUObject(this, &AVegetationManager::OnLevelRemovedFromWorld);
|
FWorldDelegates::LevelRemovedFromWorld.AddUObject(this, &AVegetationManager::OnLevelRemovedFromWorld);
|
||||||
|
GetWorldTimerManager().SetTimer(UpdatePoolInactiveTransformTimer, this, &AVegetationManager::UpdatePoolBasePosition, 30.0f, true, 15.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVegetationManager::Tick(float DeltaTime)
|
void AVegetationManager::Tick(float DeltaTime)
|
||||||
|
@ -610,6 +611,27 @@ AActor* AVegetationManager::CreateFoliage(const FFoliageBlueprint& BP, const FTr
|
||||||
return Actor;
|
return Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVegetationManager::UpdatePoolBasePosition()
|
||||||
|
{
|
||||||
|
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdatePoolBasePosition);
|
||||||
|
if (!IsValid(HeroVehicle))
|
||||||
|
return;
|
||||||
|
UE_LOG(LogCarla, Display, TEXT("UpdatePoolBasePosition"));
|
||||||
|
const FTransform HeroTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform());
|
||||||
|
const FVector HeroLocation = HeroTransform.GetLocation();
|
||||||
|
const FTransform PoolTransform(HeroTransform.GetRotation(), FVector(HeroLocation.X, HeroLocation.Y, -1000.0f), FVector(1.0f, 1.0f, 1.0f));
|
||||||
|
for (TPair<FString, TArray<FPooledActor>>& Element : ActorPool)
|
||||||
|
{
|
||||||
|
TArray<FPooledActor>& Pool = Element.Value;
|
||||||
|
for (FPooledActor& PooledActor : Pool)
|
||||||
|
{
|
||||||
|
if (PooledActor.InUse)
|
||||||
|
continue;
|
||||||
|
PooledActor.Actor->SetActorTransform(PoolTransform, true, nullptr, ETeleportType::ResetPhysics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
/********** TILES ***************************************************************/
|
/********** TILES ***************************************************************/
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
|
|
|
@ -85,6 +85,9 @@ public:
|
||||||
void AddVehicle(ACarlaWheeledVehicle* Vehicle);
|
void AddVehicle(ACarlaWheeledVehicle* Vehicle);
|
||||||
void RemoveVehicle(ACarlaWheeledVehicle* Vehicle);
|
void RemoveVehicle(ACarlaWheeledVehicle* Vehicle);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void UpdatePoolBasePosition();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(Category = "CARLA Vegetation Spwaner", EditDefaultsOnly)
|
UPROPERTY(Category = "CARLA Vegetation Spwaner", EditDefaultsOnly)
|
||||||
bool DebugMaterials {false};
|
bool DebugMaterials {false};
|
||||||
|
@ -157,4 +160,6 @@ private:
|
||||||
TMap<FString, FTileData> TileCache {};
|
TMap<FString, FTileData> TileCache {};
|
||||||
//Pools
|
//Pools
|
||||||
TMap<FString, TArray<FPooledActor>> ActorPool {};
|
TMap<FString, TArray<FPooledActor>> ActorPool {};
|
||||||
|
|
||||||
|
FTimerHandle UpdatePoolInactiveTransformTimer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue