RavEngine
Loading...
Searching...
No Matches
PxReportCallback.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_REPORT_CALLBACK_H
30#define PX_REPORT_CALLBACK_H
31
36#include "common/PxPhysXCommonConfig.h"
37#include "foundation/PxArray.h"
38
39#if !PX_DOXYGEN
40namespace physx
41{
42#endif
43
58 template<class T>
60 {
61 public:
62 PxReportCallback(T* buffer=NULL, PxU32 capacity=0) : mBuffer(buffer), mCapacity(capacity), mSize(0) {}
63 virtual ~PxReportCallback() {}
64
65 T* mBuffer; // Destination buffer for writing results. if NULL, the system will use its internal buffer and set that pointer as it sees fit.
66 // Otherwise users can set it to where they want the results to be written.
67 PxU32 mCapacity; // Capacity of mBuffer. If mBuffer is NULL, this controls how many items are reported to users at the same time (with a limit of 256).
68 PxU32 mSize;
69
80 virtual bool flushResults(PxU32 nbItems, const T* items) = 0;
81 };
82
97 template<class T>
99 {
100 public:
101 PxRegularReportCallback(const PxU32 capacity=1)
102 {
103 PX_ASSERT(capacity<=256);
104 this->mCapacity = capacity;
105 }
106
107 virtual bool flushResults(PxU32 nbItems, const T* items)
108 {
109 PX_ASSERT(nbItems<=this->mCapacity);
110 PX_ASSERT(items==this->mBuffer);
111 return processResults(nbItems, items);
112 }
113
122 virtual bool processResults(PxU32 nbItems, const T* items) = 0;
123 };
124
137 template<class T, const PxU32 capacityT>
139 {
140 T mLocalStorage[capacityT];
141
142 public:
144 {
145 this->mBuffer = mLocalStorage;
146 this->mCapacity = capacityT;
147 }
148
149 virtual bool flushResults(PxU32 nbItems, const T* items)
150 {
151 PX_ASSERT(items==mLocalStorage);
152 PX_ASSERT(nbItems<=this->mCapacity);
153 return processResults(nbItems, items);
154 }
155
164 virtual bool processResults(PxU32 nbItems, const T* items) = 0;
165 };
166
184 template<class T>
186 {
187 public:
188 PxExternalStorageReportCallback(T* buffer, PxU32 capacity)
189 {
190 this->mBuffer = buffer;
191 this->mCapacity = capacity;
192 }
193
194 virtual bool flushResults(PxU32 nbItems, const T* items)
195 {
196 PX_ASSERT(items==this->mBuffer);
197 PX_ASSERT(nbItems<=this->mCapacity);
198 return processResults(nbItems, items);
199 }
200
209 virtual bool processResults(PxU32 nbItems, const T* items) = 0;
210 };
211
223 template<class T>
225 {
226 public:
227 PxDynamicArrayReportCallback(PxArray<T>& results) : mResults(results)
228 {
229 mResults.reserve(32);
230 this->mBuffer = mResults.begin();
231 this->mCapacity = mResults.capacity();
232 }
233
234 virtual bool flushResults(PxU32 nbItems, const T* /*items*/)
235 {
236 const PxU32 size = mResults.size();
237 const PxU32 capa = mResults.capacity();
238 const PxU32 newSize = size+nbItems;
239 PX_ASSERT(newSize<=capa);
240 mResults.forceSize_Unsafe(newSize);
241 if(newSize==capa)
242 {
243 const PxU32 newCapa = capa*2;
244 mResults.reserve(newCapa);
245 this->mBuffer = mResults.begin() + newSize;
246 this->mCapacity = mResults.capacity() - newSize;
247 }
248 return true;
249 }
250
251 PxArray<T>& mResults;
252 };
253
254#if !PX_DOXYGEN
255}
256#endif
257
259#endif
Definition PxArray.h:53
Dynamic array report callback.
Definition PxReportCallback.h:225
virtual bool flushResults(PxU32 nbItems, const T *)
Reports query results to users.
Definition PxReportCallback.h:234
External storage report callback.
Definition PxReportCallback.h:186
virtual bool processResults(PxU32 nbItems, const T *items)=0
Reports query results to users.
virtual bool flushResults(PxU32 nbItems, const T *items)
Reports query results to users.
Definition PxReportCallback.h:194
Local storage report callback.
Definition PxReportCallback.h:139
virtual bool flushResults(PxU32 nbItems, const T *items)
Reports query results to users.
Definition PxReportCallback.h:149
virtual bool processResults(PxU32 nbItems, const T *items)=0
Reports query results to users.
Regular report callback.
Definition PxReportCallback.h:99
virtual bool processResults(PxU32 nbItems, const T *items)=0
Reports query results to users.
virtual bool flushResults(PxU32 nbItems, const T *items)
Reports query results to users.
Definition PxReportCallback.h:107
Base class for callback reporting an unknown number of items to users.
Definition PxReportCallback.h:60
PxU32 mSize
Current number of items in the buffer. This is entirely managed by the system.
Definition PxReportCallback.h:68
virtual bool flushResults(PxU32 nbItems, const T *items)=0
Reports query results to users.
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39