@@ -155,3 +155,75 @@ void UAsyncKdtreeBPLibrary::CollectFromKdtreeAsync(const UObject* WorldContextOb
155155 }
156156 }
157157}
158+
159+ struct FCollectFromKdtreeBoxTaskParams
160+ {
161+ const FKdtree* Tree;
162+ FBox Box;
163+ TArray<int >* Indices;
164+ TArray<FVector>* Data;
165+ };
166+
167+ class FCollectFromKdtreeBoxTask : public FNonAbandonableTask
168+ {
169+ public:
170+ FCollectFromKdtreeBoxTask (const FCollectFromKdtreeBoxTaskParams& InParams) : Params(InParams)
171+ {
172+ }
173+
174+ void DoWork ()
175+ {
176+ KdtreeInternal::CollectFromKdtree (Params.Tree ->Internal , Params.Box , Params.Indices );
177+ for (int Index = 0 ; Index < Params.Indices ->Num (); ++Index)
178+ {
179+ Params.Data ->Add (Params.Tree ->Internal .Data [(*Params.Indices )[Index]]);
180+ }
181+ }
182+
183+ FORCEINLINE TStatId GetStatId () const
184+ {
185+ RETURN_QUICK_DECLARE_CYCLE_STAT (FCollectFromKdtreeBoxTask, STATGROUP_ThreadPoolAsyncTasks);
186+ }
187+
188+ private:
189+ FCollectFromKdtreeBoxTaskParams Params;
190+ };
191+
192+ class FCollectFromKdtreeBoxAction : public FPendingLatentAction
193+ {
194+ public:
195+ FLatentActionInfo LatentInfo;
196+ FAsyncTask<FCollectFromKdtreeBoxTask>* Task;
197+
198+ FCollectFromKdtreeBoxAction (const FLatentActionInfo& InLatentInfo, const FKdtree* Tree, const FBox Box,
199+ TArray<int >* Indices, TArray<FVector>* Data)
200+ : LatentInfo(InLatentInfo), Task(nullptr )
201+ {
202+ FCollectFromKdtreeBoxTaskParams Params;
203+ Params.Tree = Tree;
204+ Params.Box = Box;
205+ Params.Indices = Indices;
206+ Params.Data = Data;
207+ Task = new FAsyncTask<FCollectFromKdtreeBoxTask>(Params);
208+ Task->StartBackgroundTask ();
209+ }
210+
211+ void UpdateOperation (FLatentResponse& Response) override
212+ {
213+ Response.FinishAndTriggerIf (Task->IsDone (), LatentInfo.ExecutionFunction , LatentInfo.Linkage , LatentInfo.CallbackTarget );
214+ }
215+ };
216+
217+ void UAsyncKdtreeBPLibrary::CollectFromKdtreeAsyncBox (const UObject* WorldContextObject, const FKdtree& Tree, const FBox Box,
218+ TArray<int >& Indices, TArray<FVector>& Data, FLatentActionInfo LatentInfo)
219+ {
220+ if (UWorld* World = GEngine->GetWorldFromContextObject (WorldContextObject, EGetWorldErrorMode::LogAndReturnNull))
221+ {
222+ FLatentActionManager& LatentManager = World->GetLatentActionManager ();
223+ if (LatentManager.FindExistingAction <FCollectFromKdtreeBoxAction>(LatentInfo.CallbackTarget , LatentInfo.UUID ) == nullptr )
224+ {
225+ FCollectFromKdtreeBoxAction* NewAction = new FCollectFromKdtreeBoxAction (LatentInfo, &Tree, Box, &Indices, &Data);
226+ LatentManager.AddNewAction (LatentInfo.CallbackTarget , LatentInfo.UUID , NewAction);
227+ }
228+ }
229+ }
0 commit comments