29#ifndef SC_CONTACT_REPORT_BUFFER_H
30#define SC_CONTACT_REPORT_BUFFER_H
32#include "foundation/Px.h"
33#include "common/PxProfileZone.h"
44 ,mCurrentBufferIndex(0)
45 ,mCurrentBufferSize(initialSize)
46 ,mDefaultBufferSize(initialSize)
48 ,mAllocationLocked(noResizeAllowed)
50 mBuffer = allocateBuffer(initialSize);
62 PX_FORCE_INLINE PxU8* allocateNotThreadSafe(PxU32 size, PxU32& index, PxU32 alignment= 16);
63 PX_FORCE_INLINE PxU8* reallocateNotThreadSafe(PxU32 size, PxU32& index, PxU32 alignment= 16, PxU32 lastIndex = 0xFFFFFFFF);
64 PX_FORCE_INLINE PxU8* getData(
const PxU32& index)
const {
return mBuffer+index; }
66 PX_FORCE_INLINE PxU32 getDefaultBufferSize()
const {
return mDefaultBufferSize;}
73 PxU32 mCurrentBufferIndex;
74 PxU32 mCurrentBufferSize;
75 PxU32 mDefaultBufferSize;
76 PxU32 mLastBufferIndex;
77 bool mAllocationLocked;
86 mCurrentBufferIndex = 0;
87 mLastBufferIndex = 0xFFFFFFFF;
92 void Sc::ContactReportBuffer::flush()
94 mCurrentBufferIndex = 0;
95 mLastBufferIndex = 0xFFFFFFFF;
97 if(mCurrentBufferSize != mDefaultBufferSize)
101 mBuffer = allocateBuffer(mDefaultBufferSize);
104 mCurrentBufferSize = mDefaultBufferSize;
110 PxU8* Sc::ContactReportBuffer::allocateNotThreadSafe(PxU32 size, PxU32& index ,PxU32 alignment)
112 PX_ASSERT(PxIsPowerOfTwo(alignment));
115 PxU32 pad = ((mCurrentBufferIndex+alignment-1)&~(alignment-1)) - mCurrentBufferIndex;
117 index = mCurrentBufferIndex + pad;
119 if (index + size > mCurrentBufferSize)
121 PX_PROFILE_ZONE(
"ContactReportBuffer::Resize", 0);
122 if(mAllocationLocked)
125 PxU32 oldBufferSize = mCurrentBufferSize;
126 while(index + size > mCurrentBufferSize)
128 mCurrentBufferSize *= 2;
131 PxU8* tempBuffer = allocateBuffer(mCurrentBufferSize);
133 PxMemCopy(tempBuffer,mBuffer,oldBufferSize);
137 mBuffer = tempBuffer;
141 PxU8* ptr = mBuffer + index;
142 mLastBufferIndex = index;
143 PX_ASSERT((
size_t(ptr)&(alignment-1)) == 0);
144 mCurrentBufferIndex += size + pad;
150 PxU8* Sc::ContactReportBuffer::reallocateNotThreadSafe(PxU32 size, PxU32& index ,PxU32 alignment, PxU32 lastIndex)
152 if(lastIndex != mLastBufferIndex)
154 return allocateNotThreadSafe(size,index,alignment);
158 mCurrentBufferIndex = mLastBufferIndex;
159 return allocateNotThreadSafe(size,index,alignment);
165 PX_FORCE_INLINE PxU8* Sc::ContactReportBuffer::allocateBuffer(PxU32 size)
167 return (
static_cast<PxU8*
>(PX_ALLOC(size,
"ContactReportBuffer")));
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition PxMemory.h:83