//----------------------------------------------------------------------//
// GameplayTasksComponent-related functions
//----------------------------------------------------------------------//
void UGameplayTask::ActivateInTaskQueue()
{
	switch(TaskState)
	{
	case EGameplayTaskState::Uninitialized:
		UE_VLOG(GetGameplayTasksComponent(), LogGameplayTasks, Error
			, TEXT("UGameplayTask::ActivateInTaskQueue Task %s passed for activation withouth having InitTask called on it!")
			, *GetName());
		break;
	case EGameplayTaskState::AwaitingActivation:
		PerformActivation();
		break;
	case EGameplayTaskState::Paused:
		// resume
		Resume();
		break;
	case EGameplayTaskState::Active:
		// nothing to do here
		break;
	case EGameplayTaskState::Finished:
		// If a task has finished, and it's being revived let's just treat the same as AwaitingActivation
		PerformActivation();
		break;
	default:
		checkNoEntry(); // looks like unhandled value! Probably a new enum entry has been added
		break;
	}
}
void UGameplayTask::PauseInTaskQueue()
{
	switch (TaskState)
	{
	case EGameplayTaskState::Uninitialized:
		UE_VLOG(GetGameplayTasksComponent(), LogGameplayTasks, Error
			, TEXT("UGameplayTask::PauseInTaskQueue Task %s passed for pausing withouth having InitTask called on it!")
			, *GetName());
		break;
	case EGameplayTaskState::AwaitingActivation:
		// nothing to do here. Don't change the state to indicate this task has never been run before
		break;
	case EGameplayTaskState::Paused:
		// nothing to do here. Already paused
		break;
	case EGameplayTaskState::Active:
		// pause!
		Pause();
		break;
	case EGameplayTaskState::Finished:
		// nothing to do here. But sounds odd, so let's log this, just in case
		UE_VLOG(GetGameplayTasksComponent(), LogGameplayTasks, Log
			, TEXT("UGameplayTask::PauseInTaskQueue Task %s being pause while already marked as Finished")
			, *GetName());
		break;
	default:
		checkNoEntry(); // looks like unhandled value! Probably a new enum entry has been added
		break;
	}
}
void FExrImageWrapper::Compress( int32 Quality )
{
	check(RawData.Num() != 0);
	check(Width > 0);
	check(Height > 0);
	check(RawBitDepth == 8 || RawBitDepth == 16 || RawBitDepth == 32);

	const int32 MaxComponents = 4;

	bUseCompression = (Quality != ImageCompression::CompressionQuality::Uncompressed);

	switch (RawBitDepth)
	{
		case 8:
			CompressRaw<Imf::HALF>(&RawData[0], false);
		break;
		case 16:
			CompressRaw<Imf::HALF>((const FFloat16*)&RawData[0], false);
		break;
		case 32:
			CompressRaw<Imf::FLOAT>((const float*)&RawData[0], false);
		break;
		default:
			checkNoEntry();
	}
}
Exemplo n.º 4
0
const char* FExrImageWrapper::GetRawChannelName(int ChannelIndex) const
{
	const int32 MaxChannels = 4;
	static const char* RGBAChannelNames[] = { "R", "G", "B", "A" };
	static const char* BGRAChannelNames[] = { "B", "G", "R", "A" };
	static const char* GrayChannelNames[] = { "G" };
	check(ChannelIndex < MaxChannels);

	const char** ChannelNames = BGRAChannelNames;

	switch (RawFormat)
	{
		case ERGBFormat::RGBA:
		{
			ChannelNames = RGBAChannelNames;
		}
		break;
		case ERGBFormat::BGRA:
		{
			ChannelNames = BGRAChannelNames;
		}
		break;
		case ERGBFormat::Gray:
		{
			check(ChannelIndex < ARRAY_COUNT(GrayChannelNames));
			ChannelNames = GrayChannelNames;
		}
		break;
		default:
			checkNoEntry();
	}
	return ChannelNames[ChannelIndex];
}
void UAblSetShaderParameterTask::InternalSetShaderValue(UMaterialInstanceDynamic* DynMaterial, UAblSetParameterValue* Value, UAblSetParameterValue* PreviousValue, float BlendAlpha) const
{
	check(DynMaterial);
	check(Value);
	check(PreviousValue);

#if !(UE_BUILD_SHIPPING)
	if (IsVerbose())
	{
		PrintVerbose(FString::Printf(TEXT("Setting material parameter %s on Material %s to %s with a blend of %1.4f."), *m_ParameterName.ToString(), *DynMaterial->GetName(), *Value->ToString(), BlendAlpha));
	}
#endif

	if (UAblSetScalarParameterValue* ScalarValue = Cast<UAblSetScalarParameterValue>(Value))
	{
		UAblSetScalarParameterValue* PreviousScalarValue = CastChecked<UAblSetScalarParameterValue>(PreviousValue);
		float InterpolatedValue = FMath::Lerp(PreviousScalarValue->GetScalar(), ScalarValue->GetScalar(), BlendAlpha);
		DynMaterial->SetScalarParameterValue(m_ParameterName, InterpolatedValue);
	}
	else if (UAblSetVectorParameterValue* VectorValue = Cast<UAblSetVectorParameterValue>(Value))
	{
		UAblSetVectorParameterValue* PreviousVectorValue = CastChecked<UAblSetVectorParameterValue>(PreviousValue);
		FVector InterpolatedValue = FMath::Lerp(PreviousVectorValue->GetVector(), VectorValue->GetVector(), BlendAlpha);
		DynMaterial->SetVectorParameterValue(m_ParameterName, InterpolatedValue);
	}
	else if (UAblSetTextureParameterValue* TextureValue = Cast<UAblSetTextureParameterValue>(Value))
	{
		// No Lerping allowed.
		DynMaterial->SetTextureParameterValue(m_ParameterName, TextureValue->GetTexture());
	}
	else
	{
		checkNoEntry();
	}
}
FVector UAblAbilityTargetingFilterSortByDistance::GetSourceLocation(const UAblAbilityContext& Context, EAblAbilityTargetType SourceType) const
{
	FVector ReturnVal(0.0f, 0.0f, 0.0f);
	if (SourceType == EAblAbilityTargetType::Self)
	{
		if (AActor* Owner = Context.GetSelfActor())
		{
			ReturnVal = Owner->GetActorLocation();
		}
	}
	else if (SourceType == EAblAbilityTargetType::Instigator)
	{
		if (AActor* Instigator = Context.GetInstigator())
		{
			ReturnVal = Instigator->GetActorLocation();
		}
	}
	else if (SourceType == EAblAbilityTargetType::Owner)
	{
		if (AActor* Owner = Context.GetOwner())
		{
			ReturnVal = Owner->GetActorLocation();
		}
	}
	else if (SourceType == EAblAbilityTargetType::TargetActor)
	{
		UE_LOG(LogAble, Error, TEXT("Targeting Filter has source set as 'TargetActor' or 'TargetComponent'. This is invalid as the target has not been found yet."));
	}
	else
	{
		checkNoEntry();
	}

	return ReturnVal;
}
FText SLandscapeEditor::GetErrorText() const
{
	const FEdModeLandscape* LandscapeEdMode = GetEditorMode();
	ELandscapeEditingState EditState = LandscapeEdMode->GetEditingState();
	switch (EditState)
	{
		case ELandscapeEditingState::SIEWorld:
		{

			if (LandscapeEdMode->NewLandscapePreviewMode != ENewLandscapePreviewMode::None)
			{
				return LOCTEXT("IsSimulatingError_create", "Can't create landscape while simulating!");
			}
			else
			{
				return LOCTEXT("IsSimulatingError_edit", "Can't edit landscape while simulating!");
			}
			break;
		}
		case ELandscapeEditingState::PIEWorld:
		{
			if (LandscapeEdMode->NewLandscapePreviewMode != ENewLandscapePreviewMode::None)
			{
				return LOCTEXT("IsPIEError_create", "Can't create landscape in PIE!");
			}
			else
			{
				return LOCTEXT("IsPIEError_edit", "Can't edit landscape in PIE!");
			}
			break;
		}
		case ELandscapeEditingState::BadFeatureLevel:
		{
			if (LandscapeEdMode->NewLandscapePreviewMode != ENewLandscapePreviewMode::None)
			{
				return LOCTEXT("IsFLError_create", "Can't create landscape with a feature level less than SM4!");
			}
			else
			{
				return LOCTEXT("IsFLError_edit", "Can't edit landscape with a feature level less than SM4!");
			}
			break;
		}
		case ELandscapeEditingState::NoLandscape:
		{
			return LOCTEXT("NoLandscapeError", "No Landscape!");
		}
		case ELandscapeEditingState::Enabled:
		{
			return FText::GetEmpty();
		}
		default:
			checkNoEntry();
	}

	return FText::GetEmpty();
}
void UGameplayTasksComponent::ProcessTaskEvents()
{
	static const int32 MaxIterations = 16;
	bInEventProcessingInProgress = true;

	int32 IterCounter = 0;
	while (TaskEvents.Num() > 0)
	{
		IterCounter++;
		if (IterCounter > MaxIterations)
		{
			UE_VLOG(this, LogGameplayTasks, Error, TEXT("UGameplayTasksComponent::ProcessTaskEvents has exceeded allowes number of iterations. Check your GameplayTasks for logic loops!"));
			break;
		}

		for (int32 EventIndex = 0; EventIndex < TaskEvents.Num(); ++EventIndex)
		{
			UE_VLOG(this, LogGameplayTasks, Verbose, TEXT("UGameplayTasksComponent::ProcessTaskEvents: %s event %s")
				, *TaskEvents[EventIndex].RelatedTask.GetName(), GetGameplayTaskEventName(TaskEvents[EventIndex].Event));

			if (TaskEvents[EventIndex].RelatedTask.IsPendingKill())
			{
				UE_VLOG(this, LogGameplayTasks, Verbose, TEXT("%s is PendingKill"), *TaskEvents[EventIndex].RelatedTask.GetName());
				// we should ignore it, but just in case run the removal code.
				RemoveTaskFromPriorityQueue(TaskEvents[EventIndex].RelatedTask);
				continue;
			}

			switch (TaskEvents[EventIndex].Event)
			{
			case EGameplayTaskEvent::Add:
				if (TaskEvents[EventIndex].RelatedTask.TaskState != EGameplayTaskState::Finished)
				{
					AddTaskToPriorityQueue(TaskEvents[EventIndex].RelatedTask);
				}
				else
				{
					UE_VLOG(this, LogGameplayTasks, Error, TEXT("UGameplayTasksComponent::ProcessTaskEvents trying to add a finished task to priority queue!"));
				}
				break;
			case EGameplayTaskEvent::Remove:
				RemoveTaskFromPriorityQueue(TaskEvents[EventIndex].RelatedTask);
				break;
			default:
				checkNoEntry();
				break;
			}
		}

		TaskEvents.Reset();
		UpdateTaskActivations();

		// task activation changes may create new events, loop over to check it
	}

	bInEventProcessingInProgress = false;
}
SGraphEditor* SBehaviorTreeDiff::GetGraphEditorForGraph(UEdGraph* Graph) const
{
	if(PanelOld.GraphEditor.Pin()->GetCurrentGraph() == Graph)
	{
		return PanelOld.GraphEditor.Pin().Get();
	}
	else if(PanelNew.GraphEditor.Pin()->GetCurrentGraph() == Graph)
	{
		return PanelNew.GraphEditor.Pin().Get();
	}
	checkNoEntry();
	return NULL;
}
Exemplo n.º 10
0
void UAITask_MoveTo::PerformMove()
{
	UPathFollowingComponent* PFComp = OwnerController ? OwnerController->GetPathFollowingComponent() : nullptr;
	if (PFComp == nullptr)
	{
		FinishMoveTask(EPathFollowingResult::Invalid);
		return;
	}

	ResetObservers();
	ResetTimers();

	// start new move request
	FNavPathSharedPtr FollowedPath;
	const FPathFollowingRequestResult ResultData = OwnerController->MoveTo(MoveRequest, &FollowedPath);

	switch (ResultData.Code)
	{
	case EPathFollowingRequestResult::Failed:
		FinishMoveTask(EPathFollowingResult::Invalid);
		break;

	case EPathFollowingRequestResult::AlreadyAtGoal:
		MoveRequestID = ResultData.MoveId;
		OnRequestFinished(ResultData.MoveId, FPathFollowingResult(EPathFollowingResult::Success, FPathFollowingResultFlags::AlreadyAtGoal));
		break;

	case EPathFollowingRequestResult::RequestSuccessful:
		MoveRequestID = ResultData.MoveId;
		PathFinishDelegateHandle = PFComp->OnRequestFinished.AddUObject(this, &UAITask_MoveTo::OnRequestFinished);
		SetObservedPath(FollowedPath);

		if (TaskState == EGameplayTaskState::Finished)
		{
			UE_VLOG(GetGameplayTasksComponent(), LogGameplayTasks, Error, TEXT("%s> re-Activating Finished task!"), *GetName());
		}
		break;

	default:
		checkNoEntry();
		break;
	}
}
Exemplo n.º 11
0
//----------------------------------------------------------------------//
// FEQSConfigurableQueryParam
//----------------------------------------------------------------------//
void FAIDynamicParam::ConfigureBBKey(UObject &QueryOwner)
{
	BBKey.AllowNoneAsValue(true);

	switch (ParamType)
	{
	case EAIParamType::Float:
	case EAIParamType::Int:
		BBKey.AddFloatFilter(&QueryOwner, ParamName);
		BBKey.AddIntFilter(&QueryOwner, ParamName);
		break;
	case EAIParamType::Bool:
		BBKey.AddBoolFilter(&QueryOwner, ParamName);
		break;
	default:
		checkNoEntry();
		break;
	}
};
UAblSetParameterValue* UAblSetShaderParameterTask::CacheShaderValue(UAblSetShaderParameterTaskScratchPad* ScratchPad, UMaterialInstanceDynamic* DynMaterial) const
{
	check(DynMaterial);
	UAblSetParameterValue* Value = nullptr;
	if (m_Value->GetType() == UAblSetParameterValue::Scalar)
	{
		float Scalar = 0.0f;
		if (DynMaterial->GetScalarParameterValue(m_ParameterName, Scalar))
		{
			UAblSetScalarParameterValue* ScalarValue = NewObject<UAblSetScalarParameterValue>(ScratchPad);
			ScalarValue->SetScalar(Scalar);
			Value = ScalarValue;
		}
	}
	else if (m_Value->GetType() == UAblSetParameterValue::Vector)
	{
		FLinearColor VectorParam;
		if (DynMaterial->GetVectorParameterValue(m_ParameterName, VectorParam))
		{
			UAblSetVectorParameterValue* VectorValue = NewObject<UAblSetVectorParameterValue>(ScratchPad);
			VectorValue->SetVector(FVector(VectorParam));
			Value = VectorValue;
		}
	}
	else if (m_Value->GetType() == UAblSetParameterValue::Texture)
	{
		UTexture* Texture = nullptr;
		if (DynMaterial->GetTextureParameterValue(m_ParameterName, Texture))
		{
			UAblSetTextureParameterValue* TextureValue = NewObject<UAblSetTextureParameterValue>(ScratchPad);
			TextureValue->SetTexture(Texture);
			Value = TextureValue;
		}
	}
	else
	{
		checkNoEntry();
	}

	return Value;
}
Exemplo n.º 13
0
void UAITask_MoveTo::Activate()
{
	Super::Activate();

	FAIMoveRequest MoveRequest = (MoveGoalActor != nullptr) ? FAIMoveRequest(MoveGoalActor) : FAIMoveRequest(RealGoalLocation);

	MoveRequest.SetAllowPartialPath(bShouldAcceptPartialPath)
		.SetAcceptanceRadius(MoveAcceptanceRadius)
		.SetStopOnOverlap(bShouldStopOnOverlap)
		.SetUsePathfinding(bShouldUsePathfinding);

	const EPathFollowingRequestResult::Type RequestResult = OwnerController->MoveTo(MoveRequest);

	switch (RequestResult)
	{
	case EPathFollowingRequestResult::Failed:
		{
			EndTask();
			OnRequestFailed.Broadcast();
		}
		break;
	case EPathFollowingRequestResult::AlreadyAtGoal:
		{
			EndTask();
			OnMoveFinished.Broadcast(EPathFollowingResult::Success);
		}
		break;
	case EPathFollowingRequestResult::RequestSuccessful:
		if (OwnerController->GetPathFollowingComponent())
		{
			MoveRequestID = OwnerController->GetPathFollowingComponent()->GetCurrentRequestId();
			OwnerController->GetPathFollowingComponent()->OnMoveFinished.AddUObject(this, &UAITask_MoveTo::HandleMoveFinished);
		}
		break;
	default:
		checkNoEntry();
		break;
	}
}
void UProjectileMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	QUICK_SCOPE_CYCLE_COUNTER( STAT_ProjectileMovementComponent_TickComponent );

	// skip if don't want component updated when not rendered or updated component can't move
	if (HasStoppedSimulation() || ShouldSkipUpdate(DeltaTime))
	{
		return;
	}

	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	AActor* ActorOwner = UpdatedComponent->GetOwner();
	if ( !ActorOwner || !CheckStillInWorld() )
	{
		return;
	}

	if (UpdatedComponent->IsSimulatingPhysics())
	{
		return;
	}

	float RemainingTime	= DeltaTime;
	uint32 NumBounces = 0;
	int32 Iterations = 0;
	FHitResult Hit(1.f);
	
	while( RemainingTime >= MIN_TICK_TIME && (Iterations < MaxSimulationIterations) && !ActorOwner->IsPendingKill() && !HasStoppedSimulation() )
	{
		Iterations++;

		// subdivide long ticks to more closely follow parabolic trajectory
		const float TimeTick = ShouldUseSubStepping() ? GetSimulationTimeStep(RemainingTime, Iterations) : RemainingTime;
		RemainingTime -= TimeTick;

		Hit.Time = 1.f;
		const FVector OldVelocity = Velocity;
		const FVector MoveDelta = ComputeMoveDelta(OldVelocity, TimeTick);

		const FRotator NewRotation = (bRotationFollowsVelocity && !OldVelocity.IsNearlyZero(0.01f)) ? OldVelocity.Rotation() : ActorOwner->GetActorRotation();

		// Move the component
		if (bShouldBounce)
		{
			// If we can bounce, we are allowed to move out of penetrations, so use SafeMoveUpdatedComponent which does that automatically.
			SafeMoveUpdatedComponent( MoveDelta, NewRotation, true, Hit );
		}
		else
		{
			// If we can't bounce, then we shouldn't adjust if initially penetrating, because that should be a blocking hit that causes a hit event and stop simulation.
			TGuardValue<EMoveComponentFlags> ScopedFlagRestore(MoveComponentFlags, MoveComponentFlags | MOVECOMP_NeverIgnoreBlockingOverlaps);
			MoveUpdatedComponent(MoveDelta, NewRotation, true, &Hit );
		}
		
		// If we hit a trigger that destroyed us, abort.
		if( ActorOwner->IsPendingKill() || HasStoppedSimulation() )
		{
			return;
		}

		// Handle hit result after movement
		if( !Hit.bBlockingHit )
		{
			PreviousHitTime = 1.f;
			bIsSliding = false;

			// Only calculate new velocity if events didn't change it during the movement update.
			if (Velocity == OldVelocity)
			{
				Velocity = ComputeVelocity(Velocity, TimeTick);				
			}
		}
		else
		{
			// Only calculate new velocity if events didn't change it during the movement update.
			if (Velocity == OldVelocity)
			{
				// re-calculate end velocity for partial time
				Velocity = (Hit.Time > KINDA_SMALL_NUMBER) ? ComputeVelocity(OldVelocity, TimeTick * Hit.Time) : OldVelocity;
			}

			// Handle blocking hit
			float SubTickTimeRemaining = TimeTick * (1.f - Hit.Time);
			const EHandleBlockingHitResult HandleBlockingResult = HandleBlockingHit(Hit, TimeTick, MoveDelta, SubTickTimeRemaining);
			if (HandleBlockingResult == EHandleBlockingHitResult::Abort || HasStoppedSimulation())
			{
				break;
			}
			else if (HandleBlockingResult == EHandleBlockingHitResult::Deflect)
			{
				NumBounces++;
				HandleDeflection(Hit, OldVelocity, NumBounces, SubTickTimeRemaining);
				PreviousHitTime = Hit.Time;
				PreviousHitNormal = ConstrainNormalToPlane(Hit.Normal);
			}
			else if (HandleBlockingResult == EHandleBlockingHitResult::AdvanceNextSubstep)
			{
				// Reset deflection logic to ignore this hit
				PreviousHitTime = 1.f;
			}
			else
			{
				// Unhandled EHandleBlockingHitResult
				checkNoEntry();
			}
			
			
			// A few initial bounces should add more time and iterations to complete most of the simulation.
			if (NumBounces <= 2 && SubTickTimeRemaining >= MIN_TICK_TIME)
			{
				RemainingTime += SubTickTimeRemaining;
				Iterations--;
			}
		}
	}

	UpdateComponentVelocity();
}
Exemplo n.º 15
0
void FRCPassPostProcessUpscale::Process(FRenderingCompositePassContext& Context)
{
    SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessUpscale);
    const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0);

    if(!InputDesc)
    {
        // input is not hooked up correctly
        return;
    }

    const FSceneView& View = Context.View;
    const FSceneViewFamily& ViewFamily = *(View.Family);

    FIntRect SrcRect = View.ViewRect;
    FIntRect DestRect = View.UnscaledViewRect;
    FIntPoint SrcSize = InputDesc->Extent;

    const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);

    // Set the view family's render target/viewport.
    SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
    Context.SetViewportAndCallRHI(DestRect);

    bool bTessellatedQuad = PaniniConfig.D >= 0.01f;

    // with distortion (bTessellatedQuad) we need to clear the background
    FIntRect ExcludeRect = bTessellatedQuad ? FIntRect() : DestRect;

    Context.RHICmdList.Clear(true, FLinearColor::Black, false, 1.0f, false, 0, ExcludeRect);

    // set the state
    Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
    Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
    Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());

    FShader* VertexShader = 0;

    if(bTessellatedQuad)
    {
        switch (UpscaleQuality)
        {
        case 0:
            VertexShader = SetShader<0, 1>(Context, PaniniConfig);
            break;
        case 1:
            VertexShader = SetShader<1, 1>(Context, PaniniConfig);
            break;
        case 2:
            VertexShader = SetShader<2, 1>(Context, PaniniConfig);
            break;
        case 3:
            VertexShader = SetShader<3, 1>(Context, PaniniConfig);
            break;
        default:
            checkNoEntry();
            break;
        }
    }
    else
    {
        switch (UpscaleQuality)
        {
        case 0:
            VertexShader = SetShader<0, 0>(Context, PaniniParams::Default);
            break;
        case 1:
            VertexShader = SetShader<1, 0>(Context, PaniniParams::Default);
            break;
        case 2:
            VertexShader = SetShader<2, 0>(Context, PaniniParams::Default);
            break;
        case 3:
            VertexShader = SetShader<3, 0>(Context, PaniniParams::Default);
            break;
        default:
            checkNoEntry();
            break;
        }
    }

    // Draw a quad, a triangle or a tessellated quad
    DrawRectangle(
        Context.RHICmdList,
        0, 0,
        DestRect.Width(), DestRect.Height(),
        SrcRect.Min.X, SrcRect.Min.Y,
        SrcRect.Width(), SrcRect.Height(),
        DestRect.Size(),
        SrcSize,
        VertexShader,
        bTessellatedQuad ? EDRF_UseTesselatedIndexBuffer: EDRF_UseTriangleOptimization);

    Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
}
Exemplo n.º 16
0
void FReverbSettings::PostSerialize(const FArchive& Ar)
{
	if( Ar.UE4Ver() < VER_UE4_REVERB_EFFECT_ASSET_TYPE )
	{
		FString ReverbAssetName;
		switch(ReverbType_DEPRECATED)
		{
			case REVERB_Default:
				// No replacement asset for default reverb type
				return;

			case REVERB_Bathroom:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Bathroom.Bathroom");
				break;

			case REVERB_StoneRoom:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/StoneRoom.StoneRoom");
				break;

			case REVERB_Auditorium:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Auditorium.Auditorium");
				break;

			case REVERB_ConcertHall:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/ConcertHall.ConcertHall");
				break;

			case REVERB_Cave:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Cave.Cave");
				break;

			case REVERB_Hallway:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Hallway.Hallway");
				break;

			case REVERB_StoneCorridor:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/StoneCorridor.StoneCorridor");
				break;

			case REVERB_Alley:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Alley.Alley");
				break;

			case REVERB_Forest:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Forest.Forest");
				break;

			case REVERB_City:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/City.City");
				break;

			case REVERB_Mountains:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Mountains.Mountains");
				break;

			case REVERB_Quarry:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Quarry.Quarry");
				break;

			case REVERB_Plain:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Plain.Plain");
				break;

			case REVERB_ParkingLot:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/ParkingLot.ParkingLot");
				break;

			case REVERB_SewerPipe:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/SewerPipe.SewerPipe");
				break;

			case REVERB_Underwater:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Underwater.Underwater");
				break;

			case REVERB_SmallRoom:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/SmallRoom.SmallRoom");
				break;

			case REVERB_MediumRoom:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/MediumRoom.MediumRoom");
				break;

			case REVERB_LargeRoom:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/LargeRoom.LargeRoom");
				break;

			case REVERB_MediumHall:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/MediumHall.MediumHall");
				break;

			case REVERB_LargeHall:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/LargeHall.LargeHall");
				break;

			case REVERB_Plate:
				ReverbAssetName = TEXT("/Engine/EngineSounds/ReverbSettings/Plate.Plate");
				break;

			default:
				// This should cover every type of reverb preset
				checkNoEntry();
				break;
		}

		ReverbEffect = LoadObject<UReverbEffect>(NULL, *ReverbAssetName);
		check( ReverbEffect );
	}
}
void UEnvQueryTest_Distance::RunTest(FEnvQueryInstance& QueryInstance) const
{
	UObject* QueryOwner = QueryInstance.Owner.Get();
	if (QueryOwner == nullptr)
	{
		return;
	}

	FloatValueMin.BindData(QueryOwner, QueryInstance.QueryID);
	float MinThresholdValue = FloatValueMin.GetValue();

	FloatValueMax.BindData(QueryOwner, QueryInstance.QueryID);
	float MaxThresholdValue = FloatValueMax.GetValue();

	// don't support context Item here, it doesn't make any sense
	TArray<FVector> ContextLocations;
	if (!QueryInstance.PrepareContext(DistanceTo, ContextLocations))
	{
		return;
	}

	switch (TestMode)
	{
		case EEnvTestDistance::Distance3D:	
			for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It)
			{
				const FVector ItemLocation = GetItemLocation(QueryInstance, It.GetIndex());
				for (int32 ContextIndex = 0; ContextIndex < ContextLocations.Num(); ContextIndex++)
				{
					const float Distance = CalcDistance3D(ItemLocation, ContextLocations[ContextIndex]);
					It.SetScore(TestPurpose, FilterType, Distance, MinThresholdValue, MaxThresholdValue);
				}
			}
			break;

		case EEnvTestDistance::Distance2D:	
			for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It)
			{
				const FVector ItemLocation = GetItemLocation(QueryInstance, It.GetIndex());
				for (int32 ContextIndex = 0; ContextIndex < ContextLocations.Num(); ContextIndex++)
				{
					const float Distance = CalcDistance2D(ItemLocation, ContextLocations[ContextIndex]);
					It.SetScore(TestPurpose, FilterType, Distance, MinThresholdValue, MaxThresholdValue);
				}
			}
			break;

		case EEnvTestDistance::DistanceZ:	
			for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It)
			{
				const FVector ItemLocation = GetItemLocation(QueryInstance, It.GetIndex());
				for (int32 ContextIndex = 0; ContextIndex < ContextLocations.Num(); ContextIndex++)
				{
					const float Distance = CalcDistanceZ(ItemLocation, ContextLocations[ContextIndex]);
					It.SetScore(TestPurpose, FilterType, Distance, MinThresholdValue, MaxThresholdValue);
				}
			}
			break;

		case EEnvTestDistance::DistanceAbsoluteZ:
			for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It)
			{
				const FVector ItemLocation = GetItemLocation(QueryInstance, It.GetIndex());
				for (int32 ContextIndex = 0; ContextIndex < ContextLocations.Num(); ContextIndex++)
				{
					const float Distance = CalcDistanceAbsoluteZ(ItemLocation, ContextLocations[ContextIndex]);
					It.SetScore(TestPurpose, FilterType, Distance, MinThresholdValue, MaxThresholdValue);
				}
			}
			break;

		default:
			checkNoEntry();
			return;
	}
}
void UAblAbilityTargetingFilter::Filter(UAblAbilityContext& Context, const UAblTargetingBase& TargetBase) const
{
	checkNoEntry();
}
Exemplo n.º 19
0
int32 FEQSParametrizedQueryExecutionRequest::Execute(AActor& QueryOwner, const UBlackboardComponent* BlackboardComponent, FQueryFinishedSignature& QueryFinishedDelegate)
{
	if (bUseBBKeyForQueryTemplate)
	{
		check(BlackboardComponent);

		// set QueryTemplate to contents of BB key
		UObject* QueryTemplateObject = BlackboardComponent->GetValue<UBlackboardKeyType_Object>(EQSQueryBlackboardKey.GetSelectedKeyID());
		QueryTemplate = Cast<UEnvQuery>(QueryTemplateObject);

		UE_CVLOG(QueryTemplate == nullptr, &QueryOwner, LogBehaviorTree, Warning, TEXT("Trying to run EQS query configured to use BB key, but indicated key (%s) doesn't contain EQS template pointer")
			, *EQSQueryBlackboardKey.SelectedKeyName.ToString());
	}

	if (QueryTemplate != nullptr)
	{
		FEnvQueryRequest QueryRequest(QueryTemplate, &QueryOwner);
		if (QueryConfig.Num() > 0)
		{
			// resolve 
			for (FAIDynamicParam& RuntimeParam : QueryConfig)
			{
				// check if given param requires runtime resolve, like reading from BB
				if (RuntimeParam.BBKey.IsSet())
				{
					check(BlackboardComponent && "If BBKey.IsSet and there's no BB component then we\'re in the error land!");

					// grab info from BB
					switch (RuntimeParam.ParamType)
					{
					case EAIParamType::Float:
					{
						const float Value = BlackboardComponent->GetValue<UBlackboardKeyType_Float>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetFloatParam(RuntimeParam.ParamName, Value);
					}
					break;
					case EAIParamType::Int:
					{
						const int32 Value = BlackboardComponent->GetValue<UBlackboardKeyType_Int>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetIntParam(RuntimeParam.ParamName, Value);
					}
					break;
					case EAIParamType::Bool:
					{
						const bool Value = BlackboardComponent->GetValue<UBlackboardKeyType_Bool>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetBoolParam(RuntimeParam.ParamName, Value);
					}
					break;
					default:
						checkNoEntry();
						break;
					}
				}
				else
				{
					switch (RuntimeParam.ParamType)
					{
					case EAIParamType::Float:
					{
						QueryRequest.SetFloatParam(RuntimeParam.ParamName, RuntimeParam.Value);
					}
					break;
					case EAIParamType::Int:
					{
						QueryRequest.SetIntParam(RuntimeParam.ParamName, RuntimeParam.Value);
					}
					break;
					case EAIParamType::Bool:
					{
						bool Result = RuntimeParam.Value > 0;
						QueryRequest.SetBoolParam(RuntimeParam.ParamName, Result);
					}
					break;
					default:
						checkNoEntry();
						break;
					}
				}
			}
		}

		return QueryRequest.Execute(RunMode, QueryFinishedDelegate);
	}

	return INDEX_NONE;
}
void UEnvQueryTest::UpdatePreviewData()
{
#if WITH_EDITORONLY_DATA && WITH_EDITOR
	PreviewData.Samples.Reset(FEnvQueryTestScoringPreview::DefaultSamplesCount);

	switch (ScoringEquation)
	{
	case EEnvTestScoreEquation::Linear:
	{
		for (int32 SampleIndex = 0; SampleIndex < FEnvQueryTestScoringPreview::DefaultSamplesCount; ++SampleIndex)
		{
			PreviewData.Samples.Add(static_cast<float>(SampleIndex) / (FEnvQueryTestScoringPreview::DefaultSamplesCount - 1));
		}
	}
		break;
	case EEnvTestScoreEquation::Square:
	{
		for (int32 SampleIndex = 0; SampleIndex < FEnvQueryTestScoringPreview::DefaultSamplesCount; ++SampleIndex)
		{
			PreviewData.Samples.Add(FMath::Square(static_cast<float>(SampleIndex) / (FEnvQueryTestScoringPreview::DefaultSamplesCount - 1)));
		}
	}
		break;
	case EEnvTestScoreEquation::InverseLinear:
	{
		for (int32 SampleIndex = 0; SampleIndex < FEnvQueryTestScoringPreview::DefaultSamplesCount; ++SampleIndex)
		{
			PreviewData.Samples.Add(1.f - static_cast<float>(SampleIndex) / (FEnvQueryTestScoringPreview::DefaultSamplesCount - 1));
		}
	}
		break;
	case EEnvTestScoreEquation::SquareRoot:
	{
		for (int32 SampleIndex = 0; SampleIndex < FEnvQueryTestScoringPreview::DefaultSamplesCount; ++SampleIndex)
		{
			PreviewData.Samples.Add(FMath::Sqrt(static_cast<float>(SampleIndex) / (FEnvQueryTestScoringPreview::DefaultSamplesCount - 1)));
		}
	}
		break;
	case EEnvTestScoreEquation::Constant:
	{
		for (int32 SampleIndex = 0; SampleIndex < FEnvQueryTestScoringPreview::DefaultSamplesCount; ++SampleIndex)
		{
			PreviewData.Samples.Add(0.5f);
		}
	}
		break;
	default:
		checkNoEntry();
		break;
	}

	const bool bInversed = ScoringFactor.GetValue() < 0.0f;
	if (bInversed)
	{
		for (float& Sample : PreviewData.Samples)
		{
			Sample = 1.f - Sample;
		}
	}


	PreviewData.bShowClampMin = (ClampMinType != EEnvQueryTestClamping::None);
	PreviewData.bShowClampMax = (ClampMaxType != EEnvQueryTestClamping::None);
	const bool bCanFilter = (TestPurpose != EEnvTestPurpose::Score);
	PreviewData.bShowFilterHigh = ((FilterType == EEnvTestFilterType::Maximum) || (FilterType == EEnvTestFilterType::Range)) && bCanFilter;
	PreviewData.bShowFilterLow = ((FilterType == EEnvTestFilterType::Minimum) || (FilterType == EEnvTestFilterType::Range)) && bCanFilter;

	PreviewData.FilterLow = 0.2f;
	PreviewData.FilterHigh = 0.8f;
	PreviewData.ClampMin = (ClampMinType == EEnvQueryTestClamping::FilterThreshold) ? PreviewData.FilterLow : 0.3f;
	PreviewData.ClampMax = (ClampMaxType == EEnvQueryTestClamping::FilterThreshold) ? PreviewData.FilterHigh : 0.7f;

	if (PreviewData.bShowClampMin)
	{
		const int32 FixedIdx = FMath::FloorToInt(PreviewData.ClampMin * PreviewData.Samples.Num());
		for (int32 Idx = 0; Idx < FixedIdx; Idx++)
		{
			PreviewData.Samples[Idx] = PreviewData.Samples[FixedIdx];
		}
	}

	if (PreviewData.bShowClampMax)
	{
		const int32 FixedIdx = FMath::CeilToInt(PreviewData.ClampMax * PreviewData.Samples.Num());
		for (int32 Idx = FixedIdx + 1; Idx < PreviewData.Samples.Num(); Idx++)
		{
			PreviewData.Samples[Idx] = PreviewData.Samples[FixedIdx];
		}
	}
#endif
}