Files
UnrealEngineUWP/Engine/Source/Runtime/AIModule/Private/EnvironmentQuery/EnvQuery.cpp

188 lines
6.0 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "EnvironmentQuery/EnvQuery.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "UObject/UnrealType.h"
#include "DataProviders/AIDataProvider.h"
#include "DataProviders/AIDataProvider_QueryParams.h"
#include "EnvironmentQuery/EnvQueryGenerator.h"
#include "EnvironmentQuery/EnvQueryTest.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "EnvironmentQuery/EnvQueryOption.h"
namespace FEQSParamsExporter
{
bool HasNamedValue(const FName& ParamName, const TArray<FAIDynamicParam>& NamedValues)
{
for (int32 ValueIndex = 0; ValueIndex < NamedValues.Num(); ValueIndex++)
{
if (NamedValues[ValueIndex].ParamName == ParamName)
{
return true;
}
}
return false;
}
void AddNamedValue(UObject& QueryOwner, const FName& ParamName, const EAIParamType ParamType, float Value, TArray<FAIDynamicParam>& NamedValues, TArray<FName>& RequiredParams)
{
check(ParamName.IsNone() == false);
if (HasNamedValue(ParamName, NamedValues) == false)
{
FAIDynamicParam& NewValue = NamedValues[NamedValues.Add(FAIDynamicParam())];
NewValue.ParamName = ParamName;
NewValue.ParamType = ParamType;
NewValue.Value = Value;
NewValue.ConfigureBBKey(QueryOwner);
}
RequiredParams.AddUnique(ParamName);
}
#define GET_STRUCT_NAME_CHECKED(StructName) \
((void)sizeof(StructName), TEXT(#StructName))
void AddNamedValuesFromObject(UObject& QueryOwner, const UEnvQueryNode& QueryNode, TArray<FAIDynamicParam>& NamedValues, TArray<FName>& RequiredParams)
{
for (FProperty* TestProperty = QueryNode.GetClass()->PropertyLink; TestProperty; TestProperty = TestProperty->PropertyLinkNext)
{
FArrayProperty* TestArray = CastField<FArrayProperty>(TestProperty);
if (TestArray)
{
FObjectPropertyBase* ArrayInnerProperty = CastField<FObjectPropertyBase>(TestArray->Inner);
if (ArrayInnerProperty == nullptr)
{
continue;
}
if (ArrayInnerProperty->PropertyClass == nullptr || ArrayInnerProperty->PropertyClass->IsChildOf<UEnvQueryNode>() == false)
{
continue;
}
FScriptArrayHelper ArrayHelper(TestArray, TestArray->ContainerPtrToValuePtr<void>(&QueryNode));
for (int32 SubNodeIndex = 0; SubNodeIndex < ArrayHelper.Num(); ++SubNodeIndex)
{
const UEnvQueryNode** SubNode = reinterpret_cast<const UEnvQueryNode**>(ArrayHelper.GetRawPtr(SubNodeIndex));
if (SubNode && *SubNode)
{
AddNamedValuesFromObject(QueryOwner, **SubNode, NamedValues, RequiredParams);
}
}
}
FStructProperty* TestStruct = CastField<FStructProperty>(TestProperty);
if (TestStruct == NULL)
{
continue;
}
const FString TypeDesc = TestStruct->GetCPPType(NULL, CPPF_None);
if (TypeDesc.Contains(GET_STRUCT_NAME_CHECKED(FAIDataProviderIntValue)))
{
const FAIDataProviderIntValue* PropertyValue = TestStruct->ContainerPtrToValuePtr<FAIDataProviderIntValue>(&QueryNode);
const UAIDataProvider_QueryParams* QueryParamProvider = PropertyValue ? Cast<const UAIDataProvider_QueryParams>(PropertyValue->DataBinding) : nullptr;
if (QueryParamProvider && !QueryParamProvider->ParamName.IsNone())
{
AddNamedValue(QueryOwner, QueryParamProvider->ParamName, EAIParamType::Int, *((float*)&PropertyValue->DefaultValue), NamedValues, RequiredParams);
}
}
else if (TypeDesc.Contains(GET_STRUCT_NAME_CHECKED(FAIDataProviderFloatValue)))
{
const FAIDataProviderFloatValue* PropertyValue = TestStruct->ContainerPtrToValuePtr<FAIDataProviderFloatValue>(&QueryNode);
const UAIDataProvider_QueryParams* QueryParamProvider = PropertyValue ? Cast<const UAIDataProvider_QueryParams>(PropertyValue->DataBinding) : nullptr;
if (QueryParamProvider && !QueryParamProvider->ParamName.IsNone())
{
AddNamedValue(QueryOwner, QueryParamProvider->ParamName, EAIParamType::Float, PropertyValue->DefaultValue, NamedValues, RequiredParams);
}
}
else if (TypeDesc.Contains(GET_STRUCT_NAME_CHECKED(FAIDataProviderBoolValue)))
{
const FAIDataProviderBoolValue* PropertyValue = TestStruct->ContainerPtrToValuePtr<FAIDataProviderBoolValue>(&QueryNode);
const UAIDataProvider_QueryParams* QueryParamProvider = PropertyValue ? Cast<const UAIDataProvider_QueryParams>(PropertyValue->DataBinding) : nullptr;
if (QueryParamProvider && !QueryParamProvider->ParamName.IsNone())
{
AddNamedValue(QueryOwner, QueryParamProvider->ParamName, EAIParamType::Bool, PropertyValue->DefaultValue ? 1.0f : -1.0f, NamedValues, RequiredParams);
}
}
}
}
#undef GET_STRUCT_NAME_CHECKED
}
UEnvQuery::UEnvQuery(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
void UEnvQuery::CollectQueryParams(UObject& QueryOwner, TArray<FAIDynamicParam>& NamedValues) const
{
TArray<FName> RequiredParams;
// collect all params
for (int32 OptionIndex = 0; OptionIndex < Options.Num(); OptionIndex++)
{
const UEnvQueryOption* Option = Options[OptionIndex];
if (Option->Generator == nullptr)
{
continue;
}
FEQSParamsExporter::AddNamedValuesFromObject(QueryOwner, *(Option->Generator), NamedValues, RequiredParams);
for (int32 TestIndex = 0; TestIndex < Option->Tests.Num(); TestIndex++)
{
const UEnvQueryTest* TestOb = Option->Tests[TestIndex];
if (TestOb)
{
FEQSParamsExporter::AddNamedValuesFromObject(QueryOwner, *TestOb, NamedValues, RequiredParams);
}
}
}
// remove unnecessary params
for (int32 ValueIndex = NamedValues.Num() - 1; ValueIndex >= 0; ValueIndex--)
{
if (!RequiredParams.Contains(NamedValues[ValueIndex].ParamName))
{
NamedValues.RemoveAt(ValueIndex);
}
}
}
Copying //UE4/Dev-Frame to //UE4/Main #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2775736 on 2015/11/20 by Richard.Hinckley Fix for Paper2D issue with repeated imports in one edutor session. Paper2D import process now creates a new importer at the end. This prevents the sprite sheet import process from leaving frame data around, causing subsequent imports (including imports of different sprite sheets) to include this data inappropriately. #codereview michael.noland Change 2776352 on 2015/11/20 by Zak.Middleton #ue4 - Avoid useless DetachFromParent() for the same pending AttachParent during registration. Added missing UpdateOverlaps() when detaching from object simulating physics. #rb Marc.Audy, Ori.Cohen #codereview James.Golding Change 2776401 on 2015/11/20 by Mieszko.Zielinski Implemented a way to do batched points projection to navmesh, where every point can declare a custom projection box #UE4 The biggest advantage here is that projection box is independent from projected point - no more manual offsetting of projected point to achieve "100uu up and 500uu down"-like functionality #jira UE-23705 #rb Lukasz.Furman Change 2777450 on 2015/11/23 by Martin.Wilson Bake additive data into animations during cooking to avoid doing additive calculations and extra pose extraction and blending at runtime #rb Thomas.Sarkanen Change 2777698 on 2015/11/23 by Mieszko.Zielinski Gameplay debugging tools fixes #UE4 Fixes: - made newly added logs respect Log Visualizer's filters - added handling of invalid data when trying to draw EGameplayDebuggerShapeElement::Cylinder in AGameplayDebuggingHUDComponent::DrawPerception. This is a patch, root cause to be found. - fixed Log Visualizer resetting it's data while trying to serialize invalid objects. This is a patch, root cause to be addressed. In addition - while at it removed bunch of 'auto' and 'class' keywords from the files I've touched #rb Lukasz.Furman Change 2777762 on 2015/11/23 by Mieszko.Zielinski Removed BlackboardComponent's functionality deprecated since 4.7 #UE4 #rb Lukasz.Furman Change 2777839 on 2015/11/23 by Zak.Middleton #ue4 - Wrap all vector library calls to math functions through our FMath versions, so they benefit from fixes or improvements therein. Added Exp2() function. #rb Laurent.Delayen Change 2777840 on 2015/11/23 by Zak.Middleton #ue4 - Fix up uses of library math functions to go through our FMath namespace. #rb Laurent.Delayen Change 2778287 on 2015/11/23 by Stan.Melax deprecation of FCollisionQueryParams(bool) See 2774707 description for the whole story #OR-9936 #codereview marc.audy Changes to kite will have to be in a separate check-in I couldn't submit to all files from the framework branch addition fixes have their files are shelved in cl 2778299 Change 2778507 on 2015/11/23 by Marc.Audy Eliminate spurious cook warnings for known missing packages #rb Michael.Noland Change 2778546 on 2015/11/23 by Aaron.McLeran Moving occlusion feature settings from audio component to sound attenuation settings struct. - Sound attenuation setting struct is used for all sounds that do 3d spatialization so it make sense for the occlusion feature settings to be there. - Kept old low-pass frequency filter setting values on audio component (where HighFrequencyAttenuation used to be) #rb Zak.Middleton Change 2778664 on 2015/11/23 by Zak.Middleton #ue4 - Clarify some comparison functions (IsZero, IsNearlyZero, Equals) in FRotator to explain that they compare as orientations, not other interpretations such as rotational speed, winding, etc. #rb Aaron.Mcleran #codereview Frank.Gigliotti Change 2779335 on 2015/11/24 by Mieszko.Zielinski Another VisualLog patch to avoid crashing due to a core bug that remains to be investigated #UE4 Again, the core bug here is related visual log trying to serialize invalid objects on a regular basis. #rb Lukasz.Furman Change 2779338 on 2015/11/24 by Benn.Gallagher Fixed crash in Persona when focus is taken from a different window #jira UE-22516 #rb Ben.Cosh Change 2779375 on 2015/11/24 by Benn.Gallagher Fix for deadlock in destructibles. Aquiring actor buffer without releasing causes an infinite wait on next aquire. #rb Ori.Cohen Change 2779753 on 2015/11/24 by Zak.Middleton #ue4 - FMath::Atan2() no longer calls atan2f() because of some compiler or library bugs causing it to randomly return NaN for valid input. It now uses a high-precision minimax approximation instead, measured to be 2x faster than the stock C version. #rb Brian.Karis Change 2779853 on 2015/11/24 by Marc.Audy
2015-12-02 16:42:06 -05:00
void UEnvQuery::PostInitProperties()
{
Super::PostInitProperties();
QueryName = GetFName();
}
void UEnvQuery::PostLoad()
{
Super::PostLoad();
if (QueryName == NAME_None || QueryName.IsValid() == false)
{
QueryName = GetFName();
}
Copying //UE4/Dev-Framework to Dev-Main (//UE4/Dev-Main) @ 2910422 #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2860430 on 2016/02/09 by Aaron.McLeran UE-26216 EQ Settings are incorrect, unable to produce a LPF setting - Fix is to expose the xaudio2 eq effect parameters actually used - Added support for real-time previewing of EQ parameter changes (interpolates from current to new values) Platform code: - CoreAudio's EQ AU effects have identical settings as well, translated the params to the mac code - PS4 code was disabled before -- this change is a first-pass implementation for PS4, but its still not enabled Change 2867932 on 2016/02/15 by Aaron.McLeran Some adjustments and cleanups to recent dev-framework features - Removing change to ObjectVersion in favor of a TaggedPropertyRedirect in BaseEngine.ini for EQSettings variables - Adding bIsTraceDelegateBound bool for flagging need to add delegate binding for async traces - Reverse iteratoing through PendingSoundsToDelete for deferred delete for async occlusion checks and using RemoveAtAtSwap #rb marc.audy Change 2894543 on 2016/03/04 by Ori.Cohen When doing stricmp only convert to lower if characters are not already equal #rb Robert.Manuszewski Change 2896383 on 2016/03/06 by Mieszko.Zielinski Fixed duplicating EQS queries copying query name as well #UE4 #rb Lukasz.Furman Change 2897688 on 2016/03/07 by Ori.Cohen Fix particle emitter post load not calling post load on its modules. #rb Olaf.Piesche #JIRA UE-27778 Change 2897806 on 2016/03/07 by Zak.Middleton #ue4 - Protect against MTD sometimes returning negative distance when it should be positive. #rb Jeff.Farris Change 2897815 on 2016/03/07 by Zak.Middleton #ue4 - Avoid multiple iterations with axis flipping in FindTeleportSpot unless we are spawning something. Otherwise the teleport spot could be placed on the other side of a wall. Also avoid using a partial MTD result in EncroachingBlockingGeometry() when one of the MTD tests fails. #rb Jeff.Farris, Matt.Oelfke Change 2897819 on 2016/03/07 by Zak.Middleton #ue4 - FInterpTo() now treats negative values as instant speed as well as zero, consistent with other *InterpTo() functions. Previously it only treated zero as instant, and negative speeds returned the "Current" value. #rb Laurent.Delayen Change 2898891 on 2016/03/08 by Marc.Audy Don't dirty level when launching standalone from editor Rework spawning temporary spawn here player start when launching standalone from editor to use a transaction and undo it rather than spawn and destroy Add a mechanism to squelch notification messages Add the ability for a undo to say that the transaction cannot be undone #jira UE-25702 #rb Nick.Darnell Change 2898902 on 2016/03/08 by Ori.Cohen Fix budget mode not showing up #rb Gil.Gribb Change 2898968 on 2016/03/08 by Tom.Looman Added OnComponentTransformChanged delegate to editor. (UE-27305) #rb marc.audy Change 2899511 on 2016/03/08 by Joe.Graf Changed AllocateNameEntry to be template based instead of branching off of whether the string is ansi or wide in multiple places Removed the load time hashing of FNameEntry as they are loaded which improves FLinkerLoad::SerializeNameMap() perf #rb: robert.manuszewski, ori.cohen #test: everything since this is FName, PS4 Change 2899525 on 2016/03/08 by Marc.Audy Add an IsGamepadAttached function to Platform and Slate Application. Implemented for XInputInterface and PS4/WinDualShock plugin #jira UE-25059 Change 2899672 on 2016/03/08 by Marc.Audy Expose setting vertical alignment for text render component to blueprints Change 2899693 on 2016/03/08 by Ori.Cohen - Increase name bucket count to 65k - Increase name pool alocator to 256kb #rb Gil.Gribb Change 2901383 on 2016/03/09 by Jurre.deBaare Adding Alembic TPS file #codereview Wes.Hunt Change 2901520 on 2016/03/09 by Zak.Middleton #ue4 - Make "checkCode(Code)" macro work without requiring a semicolon in the code block. Example: checkCode(ensure(SomeTest);); // previous requirement: checkCode(ensure(SomeTest)); // now supported #rb Dan.OConnor Change 2901532 on 2016/03/09 by Zak.Middleton #ue4 - Add DiagnosticCheckNaN() version taking a string to FRotator and FQuat. [CL 2910439 by Marc Audy in Main branch]
2016-03-15 14:49:07 -04:00
}
#if WITH_EDITOR
void UEnvQuery::PostRename(UObject* OldOuter, const FName OldName)
{
Super::PostRename(OldOuter, OldName);
QueryName = GetFName();
}
Copying //UE4/Dev-Framework to Dev-Main (//UE4/Dev-Main) @ 2910422 #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2860430 on 2016/02/09 by Aaron.McLeran UE-26216 EQ Settings are incorrect, unable to produce a LPF setting - Fix is to expose the xaudio2 eq effect parameters actually used - Added support for real-time previewing of EQ parameter changes (interpolates from current to new values) Platform code: - CoreAudio's EQ AU effects have identical settings as well, translated the params to the mac code - PS4 code was disabled before -- this change is a first-pass implementation for PS4, but its still not enabled Change 2867932 on 2016/02/15 by Aaron.McLeran Some adjustments and cleanups to recent dev-framework features - Removing change to ObjectVersion in favor of a TaggedPropertyRedirect in BaseEngine.ini for EQSettings variables - Adding bIsTraceDelegateBound bool for flagging need to add delegate binding for async traces - Reverse iteratoing through PendingSoundsToDelete for deferred delete for async occlusion checks and using RemoveAtAtSwap #rb marc.audy Change 2894543 on 2016/03/04 by Ori.Cohen When doing stricmp only convert to lower if characters are not already equal #rb Robert.Manuszewski Change 2896383 on 2016/03/06 by Mieszko.Zielinski Fixed duplicating EQS queries copying query name as well #UE4 #rb Lukasz.Furman Change 2897688 on 2016/03/07 by Ori.Cohen Fix particle emitter post load not calling post load on its modules. #rb Olaf.Piesche #JIRA UE-27778 Change 2897806 on 2016/03/07 by Zak.Middleton #ue4 - Protect against MTD sometimes returning negative distance when it should be positive. #rb Jeff.Farris Change 2897815 on 2016/03/07 by Zak.Middleton #ue4 - Avoid multiple iterations with axis flipping in FindTeleportSpot unless we are spawning something. Otherwise the teleport spot could be placed on the other side of a wall. Also avoid using a partial MTD result in EncroachingBlockingGeometry() when one of the MTD tests fails. #rb Jeff.Farris, Matt.Oelfke Change 2897819 on 2016/03/07 by Zak.Middleton #ue4 - FInterpTo() now treats negative values as instant speed as well as zero, consistent with other *InterpTo() functions. Previously it only treated zero as instant, and negative speeds returned the "Current" value. #rb Laurent.Delayen Change 2898891 on 2016/03/08 by Marc.Audy Don't dirty level when launching standalone from editor Rework spawning temporary spawn here player start when launching standalone from editor to use a transaction and undo it rather than spawn and destroy Add a mechanism to squelch notification messages Add the ability for a undo to say that the transaction cannot be undone #jira UE-25702 #rb Nick.Darnell Change 2898902 on 2016/03/08 by Ori.Cohen Fix budget mode not showing up #rb Gil.Gribb Change 2898968 on 2016/03/08 by Tom.Looman Added OnComponentTransformChanged delegate to editor. (UE-27305) #rb marc.audy Change 2899511 on 2016/03/08 by Joe.Graf Changed AllocateNameEntry to be template based instead of branching off of whether the string is ansi or wide in multiple places Removed the load time hashing of FNameEntry as they are loaded which improves FLinkerLoad::SerializeNameMap() perf #rb: robert.manuszewski, ori.cohen #test: everything since this is FName, PS4 Change 2899525 on 2016/03/08 by Marc.Audy Add an IsGamepadAttached function to Platform and Slate Application. Implemented for XInputInterface and PS4/WinDualShock plugin #jira UE-25059 Change 2899672 on 2016/03/08 by Marc.Audy Expose setting vertical alignment for text render component to blueprints Change 2899693 on 2016/03/08 by Ori.Cohen - Increase name bucket count to 65k - Increase name pool alocator to 256kb #rb Gil.Gribb Change 2901383 on 2016/03/09 by Jurre.deBaare Adding Alembic TPS file #codereview Wes.Hunt Change 2901520 on 2016/03/09 by Zak.Middleton #ue4 - Make "checkCode(Code)" macro work without requiring a semicolon in the code block. Example: checkCode(ensure(SomeTest);); // previous requirement: checkCode(ensure(SomeTest)); // now supported #rb Dan.OConnor Change 2901532 on 2016/03/09 by Zak.Middleton #ue4 - Add DiagnosticCheckNaN() version taking a string to FRotator and FQuat. [CL 2910439 by Marc Audy in Main branch]
2016-03-15 14:49:07 -04:00
void UEnvQuery::PostDuplicate(bool bDuplicateForPIE)
{
if (bDuplicateForPIE == false)
{
QueryName = GetFName();
}
Super::PostDuplicate(bDuplicateForPIE);
}
#endif // WITH_EDITOR