inactive pool elements moved by world origin event.

This commit is contained in:
LuisPoveda 2022-10-31 12:33:23 +01:00 committed by bernat
parent de74c1b1ce
commit 0bb9b1789a
2 changed files with 21 additions and 8 deletions

View File

@ -219,7 +219,8 @@ 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); FCoreDelegates::PostWorldOriginOffset.AddUObject(this, &AVegetationManager::PostWorldOriginOffset);
//GetWorldTimerManager().SetTimer(UpdatePoolInactiveTransformTimer, this, &AVegetationManager::UpdatePoolBasePosition, PoolTranslationTimer, true, PoolTranslationTimer);
} }
void AVegetationManager::Tick(float DeltaTime) void AVegetationManager::Tick(float DeltaTime)
@ -665,11 +666,11 @@ AActor* AVegetationManager::CreateFoliage(const FFoliageBlueprint& BP, const FTr
void AVegetationManager::UpdatePoolBasePosition() void AVegetationManager::UpdatePoolBasePosition()
{ {
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdatePoolBasePosition); TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdatePoolBasePosition);
if (!IsValid(HeroVehicle)) //if (!IsValid(HeroVehicle))
return; // return;
const FTransform HeroTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform()); //const FTransform HeroTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform());
const FVector HeroLocation = HeroTransform.GetLocation(); //const FVector HeroLocation = HeroTransform.GetLocation();
const FTransform PoolTransform(HeroTransform.GetRotation(), FVector(HeroLocation.X, HeroLocation.Y, -1000.0f), FVector(1.0f, 1.0f, 1.0f)); //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) for (TPair<FString, TArray<FPooledActor>>& Element : ActorPool)
{ {
TArray<FPooledActor>& Pool = Element.Value; TArray<FPooledActor>& Pool = Element.Value;
@ -677,13 +678,13 @@ void AVegetationManager::UpdatePoolBasePosition()
{ {
if (PooledActor.InUse) if (PooledActor.InUse)
continue; continue;
PooledActor.Actor->SetActorTransform(PoolTransform, true, nullptr, ETeleportType::ResetPhysics); PooledActor.Actor->SetActorTransform(InactivePoolTransform, true, nullptr, ETeleportType::ResetPhysics);
} }
} }
} }
/********************************************************************************/ /********************************************************************************/
/********** TILES ***************************************************************/ /********** EVENTS **************************************************************/
/********************************************************************************/ /********************************************************************************/
void AVegetationManager::OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld) void AVegetationManager::OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld)
{ {
@ -698,6 +699,15 @@ void AVegetationManager::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorl
FreeTileCache(InLevel); FreeTileCache(InLevel);
} }
void AVegetationManager::PostWorldOriginOffset(UWorld*, FIntVector, FIntVector InDstOrigin)
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::PostWorldOriginOffset);
InactivePoolTransform.SetLocation(FVector(InDstOrigin.X, InDstOrigin.Y, InDstOrigin.Z));
}
/********************************************************************************/
/********** TILES ***************************************************************/
/********************************************************************************/
bool AVegetationManager::IsFoliageTypeEnabled(const FString& Path) const bool AVegetationManager::IsFoliageTypeEnabled(const FString& Path) const
{ {
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::IsFoliageTypeEnabled); TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::IsFoliageTypeEnabled);

View File

@ -151,6 +151,7 @@ private:
void OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld); void OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld);
void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld); void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld);
void PostWorldOriginOffset(UWorld*, FIntVector, FIntVector InDstOrigin);
void CreatePoolForBPClass(const FFoliageBlueprint& BP); void CreatePoolForBPClass(const FFoliageBlueprint& BP);
AActor* CreateFoliage(const FFoliageBlueprint& BP, const FTransform& Transform) const; AActor* CreateFoliage(const FFoliageBlueprint& BP, const FTransform& Transform) const;
@ -158,6 +159,8 @@ private:
void GetSketalTemplates(); void GetSketalTemplates();
private: private:
float PoolTranslationTimer {30.0f};
FTransform InactivePoolTransform { FQuat(1.0f, 1.0f, 1.0f, 1.0f), FVector(1.0f, 1.0f, 1.0f), FVector(1.0f, 1.0f, 1.0f)};
//Actors //Actors
ALargeMapManager* LargeMap {nullptr}; ALargeMapManager* LargeMap {nullptr};
ACarlaWheeledVehicle* HeroVehicle {nullptr}; ACarlaWheeledVehicle* HeroVehicle {nullptr};