Payback 0.0.1
CK Graduation Project
로딩중...
검색중...
일치하는것 없음
TargetableQueryContext 구조체 참조

#include <TargetableQuery.h>

TargetableQueryContext에 대한 협력 다이어그램:
Collaboration graph

Public 멤버 함수

 TargetableQueryContext (UWorld *InWorld, const TArray< ITargetableInterface * > &Targetables)
 
TargetableQueryContextResetCachedResult ()
 
TargetableQueryContextCacheResult ()
 
TargetableQueryContextFilterByLineOfSight ()
 
TargetableQueryContextPickClosestFromCenter ()
 
TargetableQueryContextFilterByClassType (UClass *ClassType)
 
TargetableQueryContextGatherCandidates (float MaxLockOnDistance)
 
TargetableQueryContextFilterByArrayRange (TArray< ITargetableInterface * > Array, int32 StartIdx, int32 EndIdx)
 
TargetableQueryContextFindDistanceNearestEnemy (const FVector &Origin, float MaxRange)
 
TargetableQueryContextFindDirectionNearestEnemy (const FVector &Origin, const FVector &Direction, float MaxRange)
 
TArray< ITargetableInterface * > GetTargets (const int32 StartIdx, const int32 EndIdx)
 
TArray< ITargetableInterface * > GetTargets (const int32 Count)
 
TArray< ITargetableInterface * > GetTargets () const
 
ITargetableInterfaceGetTarget (const int32 Index=0)
 
TArray< ITargetableInterface * > GetInitialTargets () const
 
TArray< ITargetableInterface * > GetCachedTargets (const int32 StartIdx, const int32 EndIdx)
 
TArray< ITargetableInterface * > GetCachedTargets ()
 
ITargetableInterfaceGetCachedTarget (const int32 Index=0)
 
bool IsCached () const
 
template<typename TActorClass >
TargetableQueryContextFilterByClassType (TSubclassOf< TActorClass > ClassType)
 

Private 멤버 함수

bool CheckLineOfSight (ITargetableInterface *Target, TArray< FHitResult > HitResults) const
 

Private 속성

TArray< ITargetableInterface * > InitialTargets
 
TArray< ITargetableInterface * > CachedTargets
 
TArray< ITargetableInterface * > Targets
 
TObjectPtr< UWorld > World
 

생성자 & 소멸자 문서화

◆ TargetableQueryContext()

TargetableQueryContext::TargetableQueryContext ( UWorld *  InWorld,
const TArray< ITargetableInterface * > &  Targetables 
)
inline
10 {
11 InitialTargets = Targetables;
12 Targets = Targetables;
13 World = InWorld;
14 }
TArray< ITargetableInterface * > Targets
Definition TargetableQuery.h:86
TArray< ITargetableInterface * > InitialTargets
Definition TargetableQuery.h:84
TObjectPtr< UWorld > World
Definition TargetableQuery.h:87

멤버 함수 문서화

◆ CacheResult()

TargetableQueryContext & TargetableQueryContext::CacheResult ( )
225{
227 return *this;
228}
TArray< ITargetableInterface * > CachedTargets
Definition TargetableQuery.h:85
TArray< ITargetableInterface * > GetTargets() const
Definition TargetableQuery.h:38
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ CheckLineOfSight()

bool TargetableQueryContext::CheckLineOfSight ( ITargetableInterface Target,
TArray< FHitResult >  HitResults 
) const
private
312{
313 bool bIsBlocking = false;
314
315 for (const FHitResult& Hit : HitResults)
316 {
317 if (Hit.Component.IsValid() && Hit.Component->GetCollisionProfileName() == CPROFILE_CKPLAYERCAPSULE)
318 {
319 continue;
320 }
321
322 if (Hit.GetActor() != ITargetableInterface::AsActor(Target))
323 {
324 bIsBlocking = true;
325 break;
326 }
327 }
328
329 if (bIsBlocking)
330 {
331 return true;
332 }
333 else
334 {
335 return false;
336 }
337}
#define CPROFILE_CKPLAYERCAPSULE
Definition CK_Collision.h:15
static AActor * AsActor(ITargetableInterface *Interface)
Definition TargetableInterface.cpp:24
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FilterByArrayRange()

TargetableQueryContext & TargetableQueryContext::FilterByArrayRange ( TArray< ITargetableInterface * >  Array,
int32  StartIdx,
int32  EndIdx 
)
196{
197 TArray<ITargetableInterface*> Result;
198
199 if (StartIdx > EndIdx || StartIdx < 0 || EndIdx < 0 || StartIdx >= Array.Num() || Array.Num() <= EndIdx)
200 {
201 return *this;
202 }
203
204 Result.Reserve(EndIdx - StartIdx + 1);
205
206 for (int32 Idx = StartIdx; Idx <= EndIdx; ++Idx)
207 {
208 Result.Add(Array[Idx]);
209 }
210
211 Targets = Result;
212 return *this;
213}
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FilterByClassType() [1/2]

template<typename TActorClass >
TargetableQueryContext & TargetableQueryContext::FilterByClassType ( TSubclassOf< TActorClass >  ClassType)
inline
76 {
77 return FilterByClassType(ClassType.Get());
78 }
TargetableQueryContext & FilterByClassType(UClass *ClassType)
Definition TargetableQuery.cpp:288
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ FilterByClassType() [2/2]

TargetableQueryContext & TargetableQueryContext::FilterByClassType ( UClass *  ClassType)
289{
290 checkf(ClassType, TEXT("%s는 nullptr 일 수 없습니다. "), NAMEOF(UClass));
291
292 TArray<ITargetableInterface*> ResultArray;
293
294 for (ITargetableInterface* Target : Targets)
295 {
296 const AActor* TargetActor = ITargetableInterface::AsActor(Target);
297
298 if (TargetActor == nullptr || TargetActor->IsA(ClassType) == false)
299 {
300 continue;
301 }
302
303 ResultArray.Add(Target);
304 }
305
306 Targets = ResultArray;
307 return *this;
308}
#define NAMEOF(Type)
Definition CK_UE.h:30
Definition TargetableInterface.h:20
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FilterByLineOfSight()

TargetableQueryContext & TargetableQueryContext::FilterByLineOfSight ( )
232{
233 if (World == nullptr || Targets.IsEmpty())
234 {
235 return *this;
236 }
237
238 const APlayerController* PC = GEngine->GetFirstLocalPlayerController(World);
239
240 if (PC == nullptr || PC->PlayerCameraManager == nullptr)
241 {
242 return *this;
243 }
244
245 FCollisionQueryParams Params(SCENE_QUERY_STAT(FilterByLineOfSight), false);
246
247 if (IsValid(PC->GetPawn()))
248 {
249 Params.AddIgnoredActor(PC->GetPawn());
250 }
251
252 TArray<ITargetableInterface*> ResultArray;
253 const FVector Offset = FVector(100.f, 0.0f, 0.0f);
254 const FVector TraceStart = PC->PlayerCameraManager->GetCameraLocation();
255
256 for (ITargetableInterface* Target : Targets)
257 {
258 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
259 {
260 continue;
261 }
262
263 const FVector TargetLocation = Target->GetTargetedActorLocation() + Offset;
264 TArray<FHitResult> HitResults;
265
266 World->LineTraceMultiByChannel
267 (
268 HitResults,
269 TraceStart,
270 TargetLocation,
271 ECC_Visibility,
272 Params
273 );
274
275 if (CheckLineOfSight(Target, HitResults))
276 {
277 continue;
278 }
279
280 ResultArray.Add(Target);
281 }
282
283 Targets = ResultArray;
284 return *this;
285}
TargetableQueryContext & FilterByLineOfSight()
Definition TargetableQuery.cpp:231
bool CheckLineOfSight(ITargetableInterface *Target, TArray< FHitResult > HitResults) const
Definition TargetableQuery.cpp:311
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FindDirectionNearestEnemy()

TargetableQueryContext & TargetableQueryContext::FindDirectionNearestEnemy ( const FVector &  Origin,
const FVector &  Direction,
float  MaxRange 
)
112{
113 float NearestDistSq = FMath::Square(MaxRange);
114 ITargetableInterface* Result = nullptr;
115
116 for (ITargetableInterface* Target : Targets)
117 {
118 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
119 {
120 continue;
121 }
122
123 const FVector ToTarget = Target->GetTargetedActorLocation() - Origin;
124 const float DistSq = ToTarget.SizeSquared();
125
126 if (DistSq > FMath::Square(MaxRange))
127 {
128 continue;
129 }
130
131 FVector ToTargetFlat(ToTarget.X, ToTarget.Y, 0.f);
132 ToTargetFlat.Normalize();
133
134 // 입력 방향과의 각도가 임계값 미만이면 해당 방향에 없는 적으로 판정.
135 if (FVector::DotProduct(Direction, ToTargetFlat) < CK_Definitions::INPUT_DIR_THRESHOLD)
136 {
137 continue;
138 }
139
140 // 입력 방향 안에 있는 적 중 가장 가까운 적을 선택.
141 if (DistSq > NearestDistSq)
142 {
143 continue;
144 }
145
146 NearestDistSq = DistSq;
147 Result = Target;
148 }
149
150 Targets.Reset();
151
152 if (Result)
153 {
154 Targets.Add(Result);
155 }
156
157 return *this;
158}
virtual FVector GetTargetedActorLocation()
Definition TargetableInterface.cpp:95
constexpr float INPUT_DIR_THRESHOLD
Definition CK_Definitions.h:9
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ FindDistanceNearestEnemy()

TargetableQueryContext & TargetableQueryContext::FindDistanceNearestEnemy ( const FVector &  Origin,
float  MaxRange 
)
162{
163 ITargetableInterface* Result = nullptr;
164 float NearestDistSq = FMath::Square(MaxRange);
165
166 for (ITargetableInterface* Target : Targets)
167 {
168 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
169 {
170 continue;
171 }
172
173 const float DistSq = FVector::DistSquared(Target->GetTargetedActorLocation(), Origin);
174
175 if (DistSq >= NearestDistSq)
176 {
177 continue;
178 }
179
180 NearestDistSq = DistSq;
181 Result = Target;
182 }
183
184 Targets.Reset();
185
186 if (Result)
187 {
188 Targets.Add(Result);
189 }
190
191 return *this;
192}

◆ GatherCandidates()

TargetableQueryContext & TargetableQueryContext::GatherCandidates ( float  MaxLockOnDistance)
9{
10 TArray<ITargetableInterface*> ResultArray;
11
12 if (World == nullptr)
13 {
14 return *this;
15 }
16
17 const APlayerController* PC = GEngine->GetFirstLocalPlayerController(World);
18
19 if (PC == nullptr || PC->PlayerCameraManager == nullptr)
20 {
21 return *this;
22 }
23
24 const FVector CameraLocation = PC->PlayerCameraManager->GetCameraLocation();
25 const float MaxDistSq = FMath::Square(MaxLockOnDistance);
26
27 for (ITargetableInterface* Target : Targets)
28 {
29 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
30 {
31 continue;
32 }
33
34 const FVector ToTarget = Target->GetTargetedActorLocation() - CameraLocation;
35 const float DistSq = ToTarget.SizeSquared();
36
37 if (DistSq > MaxDistSq || DistSq <= KINDA_SMALL_NUMBER)
38 {
39 continue;
40 }
41
42 ResultArray.Add(Target);
43 }
44
45 Targets = ResultArray;
46 return *this;
47}

◆ GetCachedTarget()

ITargetableInterface * TargetableQueryContext::GetCachedTarget ( const int32  Index = 0)
inline
64 {
65 return CachedTargets.IsEmpty() ? nullptr : CachedTargets.IsValidIndex(Index) ? CachedTargets[Index] : nullptr;
66 }

◆ GetCachedTargets() [1/2]

TArray< ITargetableInterface * > TargetableQueryContext::GetCachedTargets ( )
inline
59 {
60 return CachedTargets;
61 }

◆ GetCachedTargets() [2/2]

TArray< ITargetableInterface * > TargetableQueryContext::GetCachedTargets ( const int32  StartIdx,
const int32  EndIdx 
)
inline
54 {
55 return FilterByArrayRange(CachedTargets, StartIdx, EndIdx).GetTargets();;
56 }
TargetableQueryContext & FilterByArrayRange(TArray< ITargetableInterface * > Array, int32 StartIdx, int32 EndIdx)
Definition TargetableQuery.cpp:195
TArray< ITargetableInterface * > GetTargets(const int32 StartIdx, const int32 EndIdx)
Definition TargetableQuery.h:28
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ GetInitialTargets()

TArray< ITargetableInterface * > TargetableQueryContext::GetInitialTargets ( ) const
inline
49 {
50 return InitialTargets;
51 }

◆ GetTarget()

ITargetableInterface * TargetableQueryContext::GetTarget ( const int32  Index = 0)
inline
44 {
45 return Targets.IsEmpty() ? nullptr : Targets.IsValidIndex(Index) ? Targets[Index] : nullptr;
46 }

◆ GetTargets() [1/3]

TArray< ITargetableInterface * > TargetableQueryContext::GetTargets ( ) const
inline
39 {
40 return Targets;
41 }
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetTargets() [2/3]

TArray< ITargetableInterface * > TargetableQueryContext::GetTargets ( const int32  Count)
inline
34 {
35 return GetTargets(0, Count);
36 }
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ GetTargets() [3/3]

TArray< ITargetableInterface * > TargetableQueryContext::GetTargets ( const int32  StartIdx,
const int32  EndIdx 
)
inline
29 {
30 return FilterByArrayRange(Targets, StartIdx, EndIdx).GetTargets();
31 }
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsCached()

bool TargetableQueryContext::IsCached ( ) const
inline
69 {
70 return !CachedTargets.IsEmpty();
71 }

◆ PickClosestFromCenter()

TargetableQueryContext & TargetableQueryContext::PickClosestFromCenter ( )
51{
52 if (Targets.IsEmpty() || World == nullptr)
53 {
54 return *this;
55 }
56
57 const APlayerController* PC = GEngine->GetFirstLocalPlayerController(World);
58
59 if (PC == nullptr || PC->PlayerCameraManager == nullptr)
60 {
61 return *this;
62 }
63
64 const FVector CameraLocation = PC->PlayerCameraManager->GetCameraLocation();
65 const FVector CameraForward = PC->PlayerCameraManager->GetCameraRotation().Vector();
66
67 ITargetableInterface* Best = nullptr;
68 float BestDot = -2.0f;
69 float BestDistSq = TNumericLimits<float>::Max();
70
71 for (ITargetableInterface* Target : Targets)
72 {
73 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
74 {
75 continue;
76 }
77
78 const FVector ToTarget = Target->GetTargetedActorLocation() - CameraLocation;
79 const float DistSq = ToTarget.SizeSquared();
80
81 if (DistSq < KINDA_SMALL_NUMBER)
82 {
83 continue;
84 }
85
86 const FVector ToTargetDir = ToTarget / FMath::Sqrt(DistSq);
87 const float Dot = FVector::DotProduct(CameraForward, ToTargetDir);
88
89 // 1순위: 화면 중앙에 더 가까운 적 (Dot이 큰 쪽)
90 // 2순위: 동률(혹은 매우 근소한 차이)일 때 더 가까운 적
91
92 if (FMath::IsNearlyEqual(Dot, BestDot, KINDA_SMALL_NUMBER) ? (DistSq < BestDistSq) : (Dot > BestDot))
93 {
94 Best = Target;
95 BestDot = Dot;
96 BestDistSq = DistSq;
97 }
98 }
99
100 Targets.Reset();
101
102 if (Best)
103 {
104 Targets.Add(Best);
105 }
106
107 return *this;
108}

◆ ResetCachedResult()

TargetableQueryContext & TargetableQueryContext::ResetCachedResult ( )
217{
219 CachedTargets.Reset();
220 return *this;
221}

멤버 데이터 문서화

◆ CachedTargets

TArray<ITargetableInterface*> TargetableQueryContext::CachedTargets
private

◆ InitialTargets

TArray<ITargetableInterface*> TargetableQueryContext::InitialTargets
private

◆ Targets

TArray<ITargetableInterface*> TargetableQueryContext::Targets
private

◆ World

TObjectPtr<UWorld> TargetableQueryContext::World
private

이 구조체에 대한 문서화 페이지는 다음의 파일들로부터 생성되었습니다.: