Updated CDTestFramework with the OPCODE Array SAP test.
Thanks Pierre Terdiman for the latest update.
This commit is contained in:
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
* ICE / OPCODE - Optimized Collision Detection
|
||||
* http://www.codercorner.com/Opcode.htm
|
||||
*
|
||||
* Copyright (c) 2001-2008 Pierre Terdiman, pierre@codercorner.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Contains all memory macros.
|
||||
@@ -25,8 +9,8 @@ subject to the following restrictions:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Include Guard
|
||||
#ifndef __ICEMEMORYMACROS_H__
|
||||
#define __ICEMEMORYMACROS_H__
|
||||
#ifndef ICEMEMORYMACROS_H
|
||||
#define ICEMEMORYMACROS_H
|
||||
|
||||
#undef ZeroMemory
|
||||
#undef CopyMemory
|
||||
@@ -40,7 +24,7 @@ subject to the following restrictions:
|
||||
//! \see StoreDwords
|
||||
//! \see CopyMemory
|
||||
//! \see MoveMemory
|
||||
inline_ void ZeroMemory(void* addr, udword size) { memset(addr, 0, size); }
|
||||
inline_ void ZeroMemory(void* addr, regsize size) { memset(addr, 0, size); }
|
||||
|
||||
//! Fills a buffer with a given byte.
|
||||
//! \param addr [in] buffer address
|
||||
@@ -50,7 +34,7 @@ subject to the following restrictions:
|
||||
//! \see ZeroMemory
|
||||
//! \see CopyMemory
|
||||
//! \see MoveMemory
|
||||
inline_ void FillMemory(void* dest, udword size, ubyte val) { memset(dest, val, size); }
|
||||
inline_ void FillMemory(void* dest, regsize size, ubyte val) { memset(dest, val, size); }
|
||||
|
||||
//! Fills a buffer with a given dword.
|
||||
//! \param addr [in] buffer address
|
||||
@@ -90,7 +74,7 @@ subject to the following restrictions:
|
||||
//! \see FillMemory
|
||||
//! \see StoreDwords
|
||||
//! \see MoveMemory
|
||||
inline_ void CopyMemory(void* dest, const void* src, udword size) { memcpy(dest, src, size); }
|
||||
inline_ void CopyMemory(void* dest, const void* src, regsize size) { memcpy(dest, src, size); }
|
||||
|
||||
//! Moves a buffer.
|
||||
//! \param addr [in] destination buffer address
|
||||
@@ -100,22 +84,97 @@ subject to the following restrictions:
|
||||
//! \see FillMemory
|
||||
//! \see StoreDwords
|
||||
//! \see CopyMemory
|
||||
inline_ void MoveMemory(void* dest, const void* src, udword size) { memmove(dest, src, size); }
|
||||
inline_ void MoveMemory(void* dest, const void* src, regsize size) { memmove(dest, src, size); }
|
||||
|
||||
#define SIZEOFOBJECT sizeof(*this) //!< Gives the size of current object. Avoid some mistakes (e.g. "sizeof(this)").
|
||||
//#define CLEAROBJECT { memset(this, 0, SIZEOFOBJECT); } //!< Clears current object. Laziness is my business. HANDLE WITH CARE.
|
||||
#define DELETESINGLE(x) if (x) { delete x; x = null; } //!< Deletes an instance of a class.
|
||||
#define DELETEARRAY(x) if (x) { delete []x; x = null; } //!< Deletes an array.
|
||||
#define SAFE_RELEASE(x) if (x) { (x)->Release(); (x) = null; } //!< Safe D3D-style release
|
||||
#define SAFE_DESTRUCT(x) if (x) { (x)->SelfDestruct(); (x) = null; } //!< Safe ICE-style release
|
||||
//! Flexible buffer copy
|
||||
//! \param src [in] source buffer address
|
||||
//! \param dst [in] destination buffer address
|
||||
//! \param nb_elem [in] number of elements to copy
|
||||
//! \param elem_size [in] size of an element
|
||||
//! \param stride [in] stride in bytes, including size of element
|
||||
inline_ void FlexiCopy(const void* src, void* dst, udword nb_elem, regsize elem_size, udword stride)
|
||||
{
|
||||
ubyte* d = (ubyte*)dst;
|
||||
const ubyte* s = (const ubyte*)src;
|
||||
const ubyte* Last = s + stride*nb_elem;
|
||||
while(s!=Last)
|
||||
{
|
||||
CopyMemory(d, s, elem_size);
|
||||
d += elem_size;
|
||||
s += stride;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ICEERROR_H__
|
||||
#define CHECKALLOC(x) if(!x) return SetIceError("Out of memory.", EC_OUT_OF_MEMORY); //!< Standard alloc checking. HANDLE WITH CARE.
|
||||
//! Gives the size of current object. This avoids some mistakes (e.g. "sizeof(this)").
|
||||
#define SIZEOFOBJECT sizeof(*this)
|
||||
|
||||
//! Clears current object. Laziness is my business! HANDLE WITH CARE. ### Removed, too dangerous, cleared too many v-tables
|
||||
//#define CLEAROBJECT { memset(this, 0, SIZEOFOBJECT); }
|
||||
|
||||
// The two macros below are here for several reasons:
|
||||
// - sometimes we write "delete x" instead of "delete []x" just because we don't pay attention. Using the macro forces you
|
||||
// to think about what you're deleting, just because you have to write the macro's name (SINGLE or ARRAY).
|
||||
// - always clearing the pointer afterwards prevents some double-deletion in various situations.
|
||||
// - deleting null is a valid operation according to the standard, yet some lame memory managers don't like it. In sake of
|
||||
// robustness, we avoid trying.
|
||||
|
||||
//! Deletes an instance of a class.
|
||||
#define DELETESINGLE(x) if (x) { delete x; x = null; }
|
||||
//! Deletes an array.
|
||||
#define DELETEARRAY(x) if (x) { delete []x; x = null; }
|
||||
|
||||
//! Safe D3D-style release
|
||||
#define SAFE_RELEASE(x) if (x) { (x)->Release(); (x) = null; }
|
||||
|
||||
//! Safe ICE-style release
|
||||
#define SAFE_DESTRUCT(x) if (x) { (x)->SelfDestruct(); (x) = null; }
|
||||
|
||||
#ifdef ICEERROR_H
|
||||
//! Standard alloc checking. HANDLE WITH CARE. Relies on strict coding rules. Probably shouldn't be used outside of ICE.
|
||||
#define CHECKALLOC(x) if(!x) return SetIceError("Out of memory.", EC_OUT_OF_MEMORY);
|
||||
#else
|
||||
#define CHECKALLOC(x) if(!x) return false;
|
||||
#endif
|
||||
|
||||
//! Standard allocation cycle
|
||||
#define SAFE_ALLOC(ptr, type, count) DELETEARRAY(ptr); ptr = new type[count]; CHECKALLOC(ptr);
|
||||
#define SAFE_ALLOC(ptr, type, count) DELETEARRAY(ptr); ptr = new type[count]; CHECKALLOC(ptr);
|
||||
#define SAFE_ICE_ALLOC(ptr, type, count) DELETEARRAY(ptr); ptr = ICE_NEW(type)[count]; CHECKALLOC(ptr);
|
||||
|
||||
#endif // __ICEMEMORYMACROS_H__
|
||||
//! Don't use inline for alloca !!!
|
||||
#ifdef WIN32
|
||||
#define StackAlloc(x) _alloca(x)
|
||||
#elif LINUX
|
||||
#define StackAlloc(x) alloca(x)
|
||||
#elif defined(__APPLE__)
|
||||
#define StackAlloc(x) alloca(x)
|
||||
#elif defined(_XBOX)
|
||||
#define StackAlloc(x) _alloca(x)
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
// #define ICE_ALLOC_TMP(x) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, #x, MEMORY_TEMP)
|
||||
// #define ICE_ALLOC(x) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, #x, MEMORY_PERSISTENT)
|
||||
#define ICE_ALLOC_TMP(x) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, "(undefined)", MEMORY_TEMP)
|
||||
#define ICE_ALLOC(x) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, "(undefined)", MEMORY_PERSISTENT)
|
||||
#define ICE_ALLOC_TMP2(x, y) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, #y, MEMORY_TEMP)
|
||||
#define ICE_ALLOC2(x, y) GetAllocator()->mallocDebug(x, __FILE__, __LINE__, #y, MEMORY_PERSISTENT)
|
||||
#else
|
||||
#define ICE_ALLOC_TMP(x) GetAllocator()->malloc(x, MEMORY_TEMP)
|
||||
#define ICE_ALLOC(x) GetAllocator()->malloc(x, MEMORY_PERSISTENT)
|
||||
#endif
|
||||
#define ICE_FREE(x) if(x) { GetAllocator()->free(x); x = null; }
|
||||
|
||||
#ifdef DONT_TRACK_MEMORY_LEAKS
|
||||
#ifdef _DEBUG
|
||||
#define ICE_NEW_TMP(x) new(__FILE__, __LINE__, #x, MEMORY_TEMP) x
|
||||
#define ICE_NEW(x) new(__FILE__, __LINE__, #x, MEMORY_PERSISTENT) x
|
||||
#else
|
||||
#define ICE_NEW_TMP(x) new(MEMORY_TEMP) x
|
||||
#define ICE_NEW(x) new(MEMORY_PERSISTENT) x
|
||||
#endif
|
||||
#else
|
||||
#define ICE_NEW_TMP(x) new x
|
||||
#define ICE_NEW(x) new x
|
||||
#endif
|
||||
|
||||
#endif // ICEMEMORYMACROS_H
|
||||
|
||||
Reference in New Issue
Block a user