void UAIPerceptionSystem::Tick(float DeltaSeconds) { SCOPE_CYCLE_COUNTER(STAT_AI_PerceptionSys); // if no new stimuli // and it's not time to remove stimuli from "know events" UWorld* World = GEngine->GetWorldFromContextObject(GetOuter()); check(World); if (World->bPlayersOnly == false) { // cache it CurrentTime = World->GetTimeSeconds(); bool bNeedsUpdate = false; if (bStimuliSourcesRefreshRequired == true) { // this is a bit naive, but we don't get notifications from the engine which Actor ended play, // we just know one did. Let's just refresh the map removing all no-longer-valid instances // @todo: we should be just calling senses directly here to unregister specific source // but at this point source actor is invalid already so we can't really pin and use it // this will go away once OnEndPlay broadcast passes in its instigator FPerceptionChannelWhitelist SensesToUpdate; for (auto It = RegisteredStimuliSources.CreateIterator(); It; ++It) { if (It->Value.SourceActor.IsValid() == false) { SensesToUpdate.MergeFilterIn(It->Value.RelevantSenses); It.RemoveCurrent(); } } for (FPerceptionChannelWhitelist::FConstIterator It(SensesToUpdate); It && Senses.IsValidIndex(*It); ++It) { if (Senses[*It] != nullptr) { Senses[*It]->CleanseInvalidSources(); } } bStimuliSourcesRefreshRequired = false; } if (SourcesToRegister.Num() > 0) { PerformSourceRegistration(); } { UAISense** SenseInstance = Senses.GetData(); for (int32 SenseID = 0; SenseID < Senses.Num(); ++SenseID, ++SenseInstance) { bNeedsUpdate |= *SenseInstance != nullptr && (*SenseInstance)->ProgressTime(DeltaSeconds); } } if (bNeedsUpdate) { // first update cached location of all listener, and remove invalid listeners for (AIPerception::FListenerMap::TIterator ListenerIt(ListenerContainer); ListenerIt; ++ListenerIt) { if (ListenerIt->Value.Listener.IsValid()) { ListenerIt->Value.CacheLocation(); } else { OnListenerRemoved(ListenerIt->Value); ListenerIt.RemoveCurrent(); } } UAISense** SenseInstance = Senses.GetData(); for (int32 SenseID = 0; SenseID < Senses.Num(); ++SenseID, ++SenseInstance) { if (*SenseInstance != nullptr) { (*SenseInstance)->Tick(); } } } /** no point in soring in no new stimuli was processed */ bool bStimuliDelivered = DeliverDelayedStimuli(bNeedsUpdate ? RequiresSorting : NoNeedToSort); if (bNeedsUpdate || bStimuliDelivered || bSomeListenersNeedUpdateDueToStimuliAging) { for (AIPerception::FListenerMap::TIterator ListenerIt(ListenerContainer); ListenerIt; ++ListenerIt) { check(ListenerIt->Value.Listener.IsValid()) if (ListenerIt->Value.HasAnyNewStimuli()) { ListenerIt->Value.ProcessStimuli(); } } bSomeListenersNeedUpdateDueToStimuliAging = false; } }
void AZombieCharacter::DisableDotEffectIfNecessary(bool ForceStop) { //Disables the dot effect is necessary (ie dot timer has been depleted) //If ForceStop is active it forces the dot effect to stop even if the dot timer is still active UWorld* World = GetWorld(); //Forced stop of dot effect if (ForceStop && World && OurCharacter && World->GetTimerManager().IsTimerActive(DotTimerHandle)) { GLog->Log("Stopping Dot Effect..."); World->GetTimerManager().ClearTimer(DotTimerHandle); ParticleSystemComponent->Deactivate(); //ZombieDebuffComp->SetFireParticleEnabled(false); bHasDot = false; } else { //Disable effect due to time out if (World && OurCharacter && World->GetTimerManager().IsTimerActive(DotTimerHandle) && World->GetTimeSeconds() - DotApplicationTime>=OurCharacter->DotDuration) { World->GetTimerManager().ClearTimer(DotTimerHandle); ParticleSystemComponent->Deactivate(); //ZombieDebuffComp->SetFireParticleEnabled(false); bHasDot = false; } } //ParticleSystemComponent->Deactivate(); }
void FUMGViewportClient::Draw(FViewport* InViewport, FCanvas* Canvas) { FViewport* ViewportBackup = Viewport; Viewport = InViewport ? InViewport : Viewport; // Determine whether we should use world time or real time based on the scene. float TimeSeconds; float RealTimeSeconds; float DeltaTimeSeconds; const bool bIsRealTime = true; UWorld* World = GWorld; if ( ( GetScene() != World->Scene ) || ( bIsRealTime == true ) ) { // Use time relative to start time to avoid issues with float vs double TimeSeconds = FApp::GetCurrentTime() - GStartTime; RealTimeSeconds = FApp::GetCurrentTime() - GStartTime; DeltaTimeSeconds = FApp::GetDeltaTime(); } else { TimeSeconds = World->GetTimeSeconds(); RealTimeSeconds = World->GetRealTimeSeconds(); DeltaTimeSeconds = World->GetDeltaSeconds(); } // Setup a FSceneViewFamily/FSceneView for the viewport. FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues( Canvas->GetRenderTarget(), GetScene(), EngineShowFlags) .SetWorldTimes(TimeSeconds, DeltaTimeSeconds, RealTimeSeconds) .SetRealtimeUpdate(bIsRealTime)); ViewFamily.EngineShowFlags = EngineShowFlags; //UpdateLightingShowFlags(ViewFamily.EngineShowFlags); //ViewFamily.ExposureSettings = ExposureSettings; //ViewFamily.LandscapeLODOverride = LandscapeLODOverride; FSceneView* View = CalcSceneView(&ViewFamily); //SetupViewForRendering(ViewFamily, *View); FSlateRect SafeFrame; View->CameraConstrainedViewRect = View->UnscaledViewRect; //if ( CalculateEditorConstrainedViewRect(SafeFrame, Viewport) ) //{ // View->CameraConstrainedViewRect = FIntRect(SafeFrame.Left, SafeFrame.Top, SafeFrame.Right, SafeFrame.Bottom); //} if ( IsAspectRatioConstrained() ) { // Clear the background to black if the aspect ratio is constrained, as the scene view won't write to all pixels. Canvas->Clear(FLinearColor::Black); } Canvas->Clear(BackgroundColor); GetRendererModule().BeginRenderingViewFamily(Canvas, &ViewFamily); // Remove temporary debug lines. // Possibly a hack. Lines may get added without the scene being rendered etc. if ( World->LineBatcher != NULL && ( World->LineBatcher->BatchedLines.Num() || World->LineBatcher->BatchedPoints.Num() ) ) { World->LineBatcher->Flush(); } if ( World->ForegroundLineBatcher != NULL && ( World->ForegroundLineBatcher->BatchedLines.Num() || World->ForegroundLineBatcher->BatchedPoints.Num() ) ) { World->ForegroundLineBatcher->Flush(); } //FCanvas* DebugCanvas = Viewport->GetDebugCanvas(); //UDebugDrawService::Draw(ViewFamily.EngineShowFlags, Viewport, View, DebugCanvas); // //FlushRenderingCommands(); Viewport = ViewportBackup; }
void FJavascriptUMGViewportClient::Draw(FViewport* InViewport, FCanvas* Canvas) { FViewport* ViewportBackup = Viewport; Viewport = InViewport ? InViewport : Viewport; // Determine whether we should use world time or real time based on the scene. float TimeSeconds; float RealTimeSeconds; float DeltaTimeSeconds; const bool bIsRealTime = true; UWorld* World = GWorld; if ((GetScene() != World->Scene) || (bIsRealTime == true)) { // Use time relative to start time to avoid issues with float vs double TimeSeconds = FApp::GetCurrentTime() - GStartTime; RealTimeSeconds = FApp::GetCurrentTime() - GStartTime; DeltaTimeSeconds = FApp::GetDeltaTime(); } else { TimeSeconds = World->GetTimeSeconds(); RealTimeSeconds = World->GetRealTimeSeconds(); DeltaTimeSeconds = World->GetDeltaSeconds(); } // Setup a FSceneViewFamily/FSceneView for the viewport. FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues( Canvas->GetRenderTarget(), GetScene(), EngineShowFlags) .SetWorldTimes(TimeSeconds, DeltaTimeSeconds, RealTimeSeconds) .SetRealtimeUpdate(bIsRealTime)); ViewFamily.EngineShowFlags = EngineShowFlags; //UpdateLightingShowFlags(ViewFamily.EngineShowFlags); //ViewFamily.ExposureSettings = ExposureSettings; //ViewFamily.LandscapeLODOverride = LandscapeLODOverride; FSceneView* View = CalcSceneView(&ViewFamily); //SetupViewForRendering(ViewFamily, *View); FSlateRect SafeFrame; View->CameraConstrainedViewRect = View->UnscaledViewRect; //if ( CalculateEditorConstrainedViewRect(SafeFrame, Viewport) ) //{ // View->CameraConstrainedViewRect = FIntRect(SafeFrame.Left, SafeFrame.Top, SafeFrame.Right, SafeFrame.Bottom); //} if (IsAspectRatioConstrained()) { // Clear the background to black if the aspect ratio is constrained, as the scene view won't write to all pixels. Canvas->Clear(FLinearColor::Black); } Canvas->Clear(BackgroundColor); // workaround for hacky renderer code that uses GFrameNumber to decide whether to resize render targets --GFrameNumber; GetRendererModule().BeginRenderingViewFamily(Canvas, &ViewFamily); Viewport = ViewportBackup; }
void UGameplayTask_WaitDelay::Activate() { UWorld* World = GetWorld(); TimeStarted = World->GetTimeSeconds(); // Use a dummy timer handle as we don't need to store it for later but we don't need to look for something to clear FTimerHandle TimerHandle; World->GetTimerManager().SetTimer(TimerHandle, this, &UGameplayTask_WaitDelay::OnTimeFinish, Time, false); }
void AAbilitySystemDebugHUD::DrawDebugAbilitySystemComponent(UAbilitySystemComponent *Component) { UWorld *World = GetWorld(); float GameWorldTime = World->GetTimeSeconds(); UFont* Font = GEngine->GetSmallFont(); FColor Color(38, 128, 0); float X = 20.f; float Y = 20.f; FString String = FString::Printf(TEXT("%.2f"), Component->GetWorld()->GetTimeSeconds()); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); String = FString::Printf(TEXT("%s (%d)"), *Component->GetPathName(), Component->IsDefaultSubobject()); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); String = FString::Printf(TEXT("%s == %s"), *Component->GetArchetype()->GetPathName(), *Component->GetClass()->GetDefaultObject()->GetPathName()); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); for (const UAttributeSet* Set : Component->SpawnedAttributes) { if (!Set) continue; check(Set); // Draw Attribute Set DrawWithBackground(Font, FString::Printf(TEXT("%s (%d)"), *Set->GetName(), Set->IsDefaultSubobject()), Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); String = FString::Printf(TEXT("%s == %s"), *Set->GetArchetype()->GetPathName(), *Set->GetClass()->GetDefaultObject()->GetPathName()); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); for (TFieldIterator<UProperty> PropertyIt(Set->GetClass(), EFieldIteratorFlags::IncludeSuper); PropertyIt; ++PropertyIt) { UProperty *Prop = *PropertyIt; FString ValueString; const void *PropertyValue = Prop->ContainerPtrToValuePtr<void>(Set); Prop->ExportTextItem(ValueString, PropertyValue, NULL, NULL, 0); String = FString::Printf(TEXT("%s: %s"), *Prop->GetName(), *ValueString); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); } Y+= 25; // Draw Active GameplayEffect for (FActiveGameplayEffect& Effect : &Component->ActiveGameplayEffects) { String = FString::Printf(TEXT("%s. [%d, %d] %.2f"), *Effect.Spec.ToSimpleString(), Effect.PredictionKey.Current, Effect.PredictionKey.Base, Effect.GetTimeRemaining(GameWorldTime)); DrawWithBackground(Font, String, Color, EAlignHorizontal::Left, X, EAlignVertical::Top, Y); } } }
void AZombieCharacter::ApplyDotEffect(float DamageAmount) { //Applies the damage over time effect on zombie and sets up the corresponding particle template //Moreover, initializes the dot timer handle so certain damage is applied over-time. if (!bHasDot) { AZombieController* ZCon = Cast<AZombieController>(GetController()); if (ZCon) { //Calculating the tick damage that we're going to apply in the zombie //based on the given damage amount. float DotTimer = OurCharacter->DotDuration; float TickDamage = DamageAmount / DotTimer; //The delegate that is binded to the apply damage function FTimerDelegate Delegate; Delegate.BindUFunction<AZombieCharacter, float>(this, FName("ApplyDamage"), TickDamage); //Enabling the dot effect.. UWorld* World = GetWorld(); if (World && OurCharacter) { World->GetTimerManager().SetTimer(DotTimerHandle, Delegate, DotTickInSeconds, true); DotApplicationTime = World->GetTimeSeconds(); GLog->Log("Dot application seconds:" + FString::SanitizeFloat(DotApplicationTime)); bHasDot = true; //Resets the particle system template if(ParticleSystemComponent) { ParticleSystemComponent->SetTemplate(FireEffectParticleTemplate); ParticleSystemComponent->Activate(true); //Activate the fire particles /*ParticleSystemComponent->Deactivate(); ParticleSystemComponent->Template = FireEffectParticleTemplate; ParticleSystemComponent->Activate(true);*/ //ZombieDebuffComp->SetFireParticleEnabled(true); } } } } }
float AGameState::GetServerWorldTimeSeconds() const { UWorld* World = GetWorld(); if (World) { return World->GetTimeSeconds() + ServerWorldTimeSecondsDelta; } return 0.f; }
void UGAWaitAction::Activate() { OnInitialized.Broadcast(); if (GEngine) { GEngine->AddOnScreenDebugMessage(0, 1, FColor::Red, FString("ObjectName: ") + GetName()); } if (TaskOwner && TaskOwner->GetWorld()) { UWorld* World = TaskOwner->GetWorld(); TimeStarted = World->GetTimeSeconds(); // Use a dummy timer handle as we don't need to store it for later but we don't need to look for something to clear FTimerHandle TimerHandle; World->GetTimerManager().SetTimer(TimerHandle, this, &UGAWaitAction::OnTimeFinish, Time, false); } }
void USoundNodeVehicleEngine::StoreCurrentRPM(FAudioDevice* AudioDevice, FActiveSound& ActiveSound, const FSoundParseParameters& ParseParams, float MaxRPM) { AActor* SoundOwner = ActiveSound.AudioComponent.IsValid() ? ActiveSound.AudioComponent->GetOwner() : NULL; AVehiclePlayerController* PCOwner = Cast<AVehiclePlayerController>(SoundOwner); if (PCOwner) { SoundOwner = PCOwner->GetPawn(); } UWorld* MyWorld = NULL; float DesiredRPM = 0.0f; ABuggyPawn* PawnOwner = Cast<ABuggyPawn>(SoundOwner); if (PawnOwner) { DesiredRPM = PawnOwner->GetEngineRotationSpeed(); MyWorld = PawnOwner->GetWorld(); } const float CurrTime = MyWorld ? MyWorld->GetTimeSeconds() : 0.0f; const float DeltaTime = (CurrTime - CurrentRPMStoreTime); CurrentRPMStoreTime = CurrTime; CurrentRPM = FMath::FInterpTo(CurrentRPM, FMath::Min(DesiredRPM, MaxRPM), DeltaTime, 10.0f); }
void AGameState::UpdateServerTimeSeconds() { UWorld* World = GetWorld(); if (World) { ReplicatedWorldTimeSeconds = World->GetTimeSeconds(); } }
void AEyeXPlayerController::GetEyeXActorsSortedByDistance(TArray<AEyeXActorBase*>& EyeXActorsOut) const { UWorld* World = GetWorld(); const float Time = World->GetTimeSeconds() - World->GetDeltaSeconds() - 0.1f; // Allow render time to be at least one frame behind. const float MaxDistanceSquared = MaxDistance * MaxDistance; FEyeXUtils::ActorDistanceComparer Comparer(PlayerCameraManager); for (TActorIterator<AEyeXActorBase> ActorItr(World); ActorItr; ++ActorItr) { if (ActorItr->GetLastRenderTime() < Time) // Ignore if the actor is not rendered to the screen continue; if (Comparer.DistanceSquaredToCamera(*ActorItr) > MaxDistanceSquared) // Ignore if further away than max distance continue; if (!FEyeXUtils::ActorBlocksOnChannel(*ActorItr, CollisionChannels)) // Ignore actors that aren't blocking any of the channels continue; EyeXActorsOut.Add(*ActorItr); } EyeXActorsOut.Sort(Comparer); }
void AGameState::OnRep_ReplicatedWorldTimeSeconds() { UWorld* World = GetWorld(); if (World) { ServerWorldTimeSecondsDelta = ReplicatedWorldTimeSeconds - World->GetTimeSeconds(); } }