Merge changes from the-witness.
This commit is contained in:
@ -120,46 +120,46 @@ namespace nv
|
||||
|
||||
|
||||
/// Const element access.
|
||||
const T & operator[]( uint index ) const
|
||||
NV_FORCEINLINE const T & operator[]( uint index ) const
|
||||
{
|
||||
nvDebugCheck(index < m_size);
|
||||
return m_buffer[index];
|
||||
}
|
||||
const T & at( uint index ) const
|
||||
NV_FORCEINLINE const T & at( uint index ) const
|
||||
{
|
||||
nvDebugCheck(index < m_size);
|
||||
return m_buffer[index];
|
||||
}
|
||||
|
||||
/// Element access.
|
||||
T & operator[] ( uint index )
|
||||
NV_FORCEINLINE T & operator[] ( uint index )
|
||||
{
|
||||
nvDebugCheck(index < m_size);
|
||||
return m_buffer[index];
|
||||
}
|
||||
T & at( uint index )
|
||||
NV_FORCEINLINE T & at( uint index )
|
||||
{
|
||||
nvDebugCheck(index < m_size);
|
||||
return m_buffer[index];
|
||||
}
|
||||
|
||||
/// Get vector size.
|
||||
uint size() const { return m_size; }
|
||||
NV_FORCEINLINE uint size() const { return m_size; }
|
||||
|
||||
/// Get vector size.
|
||||
uint count() const { return m_size; }
|
||||
NV_FORCEINLINE uint count() const { return m_size; }
|
||||
|
||||
/// Get const vector pointer.
|
||||
const T * buffer() const { return m_buffer; }
|
||||
NV_FORCEINLINE const T * buffer() const { return m_buffer; }
|
||||
|
||||
/// Get vector pointer.
|
||||
T * mutableBuffer() { return m_buffer; }
|
||||
NV_FORCEINLINE T * mutableBuffer() { return m_buffer; }
|
||||
|
||||
/// Is vector empty.
|
||||
bool isEmpty() const { return m_size == 0; }
|
||||
NV_FORCEINLINE bool isEmpty() const { return m_size == 0; }
|
||||
|
||||
/// Is a null vector.
|
||||
bool isNull() const { return m_buffer == NULL; }
|
||||
NV_FORCEINLINE bool isNull() const { return m_buffer == NULL; }
|
||||
|
||||
|
||||
/// Push an element at the end of the vector.
|
||||
@ -179,17 +179,17 @@ namespace nv
|
||||
new(m_buffer+new_size-1) T(val);
|
||||
}
|
||||
}
|
||||
void pushBack( const T & val )
|
||||
NV_FORCEINLINE void pushBack( const T & val )
|
||||
{
|
||||
push_back(val);
|
||||
}
|
||||
void append( const T & val )
|
||||
NV_FORCEINLINE void append( const T & val )
|
||||
{
|
||||
push_back(val);
|
||||
}
|
||||
|
||||
/// Qt like push operator.
|
||||
Array<T> & operator<< ( T & t )
|
||||
NV_FORCEINLINE Array<T> & operator<< ( T & t )
|
||||
{
|
||||
push_back(t);
|
||||
return *this;
|
||||
@ -201,41 +201,41 @@ namespace nv
|
||||
nvDebugCheck( m_size > 0 );
|
||||
resize( m_size - 1 );
|
||||
}
|
||||
void popBack()
|
||||
NV_FORCEINLINE void popBack()
|
||||
{
|
||||
pop_back();
|
||||
}
|
||||
|
||||
/// Get back element.
|
||||
const T & back() const
|
||||
NV_FORCEINLINE const T & back() const
|
||||
{
|
||||
nvDebugCheck( m_size > 0 );
|
||||
return m_buffer[m_size-1];
|
||||
}
|
||||
|
||||
/// Get back element.
|
||||
T & back()
|
||||
NV_FORCEINLINE T & back()
|
||||
{
|
||||
nvDebugCheck( m_size > 0 );
|
||||
return m_buffer[m_size-1];
|
||||
}
|
||||
|
||||
/// Get front element.
|
||||
const T & front() const
|
||||
NV_FORCEINLINE const T & front() const
|
||||
{
|
||||
nvDebugCheck( m_size > 0 );
|
||||
return m_buffer[0];
|
||||
}
|
||||
|
||||
/// Get front element.
|
||||
T & front()
|
||||
NV_FORCEINLINE T & front()
|
||||
{
|
||||
nvDebugCheck( m_size > 0 );
|
||||
return m_buffer[0];
|
||||
}
|
||||
|
||||
/// Return true if element found.
|
||||
bool find(const T & element, uint * index) const
|
||||
NV_FORCEINLINE bool find(const T & element, uint * index) const
|
||||
{
|
||||
return find(element, 0, m_size, index);
|
||||
}
|
||||
@ -253,7 +253,7 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Check if the given element is contained in the array.
|
||||
bool contains(const T & e) const
|
||||
NV_FORCEINLINE bool contains(const T & e) const
|
||||
{
|
||||
return find(e, NULL);
|
||||
}
|
||||
@ -301,7 +301,7 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Append the given data to our vector.
|
||||
void append(const Array<T> & other)
|
||||
NV_FORCEINLINE void append(const Array<T> & other)
|
||||
{
|
||||
append(other.m_buffer, other.m_size);
|
||||
}
|
||||
@ -324,7 +324,7 @@ namespace nv
|
||||
void replaceWithLast(uint index)
|
||||
{
|
||||
nvDebugCheck( index < m_size );
|
||||
swap(m_buffer[index], back());
|
||||
nv::swap(m_buffer[index], back());
|
||||
//m_buffer[index] = back();
|
||||
(m_buffer+m_size-1)->~T();
|
||||
m_size--;
|
||||
@ -409,13 +409,13 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Clear the buffer.
|
||||
void clear()
|
||||
NV_FORCEINLINE void clear()
|
||||
{
|
||||
resize(0);
|
||||
}
|
||||
|
||||
/// Shrink the allocated vector.
|
||||
void shrink()
|
||||
NV_FORCEINLINE void shrink()
|
||||
{
|
||||
if (m_size < m_buffer_size) {
|
||||
allocate(m_size);
|
||||
@ -423,7 +423,7 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Preallocate space.
|
||||
void reserve(uint desired_size)
|
||||
NV_FORCEINLINE void reserve(uint desired_size)
|
||||
{
|
||||
if (desired_size > m_buffer_size) {
|
||||
allocate( desired_size );
|
||||
@ -440,7 +440,7 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Assignment operator.
|
||||
Array<T> & operator=( const Array<T> & a )
|
||||
NV_FORCEINLINE Array<T> & operator=( const Array<T> & a )
|
||||
{
|
||||
copy(a.m_buffer, a.m_size);
|
||||
return *this;
|
||||
@ -470,15 +470,15 @@ namespace nv
|
||||
// Array enumerator.
|
||||
typedef uint PseudoIndex;
|
||||
|
||||
PseudoIndex start() const { return 0; }
|
||||
bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; };
|
||||
void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; }
|
||||
NV_FORCEINLINE PseudoIndex start() const { return 0; }
|
||||
NV_FORCEINLINE bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; };
|
||||
NV_FORCEINLINE void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; }
|
||||
|
||||
#if NV_CC_MSVC
|
||||
T & operator[]( const PseudoIndexWrapper & i ) {
|
||||
NV_FORCEINLINE T & operator[]( const PseudoIndexWrapper & i ) {
|
||||
return m_buffer[i(this)];
|
||||
}
|
||||
const T & operator[]( const PseudoIndexWrapper & i ) const {
|
||||
NV_FORCEINLINE const T & operator[]( const PseudoIndexWrapper & i ) const {
|
||||
return m_buffer[i(this)];
|
||||
}
|
||||
#endif
|
||||
@ -510,7 +510,7 @@ namespace nv
|
||||
|
||||
// realloc the buffer
|
||||
else {
|
||||
m_buffer = (T *) realloc( m_buffer, sizeof(T) * m_buffer_size );
|
||||
m_buffer = realloc<T>(m_buffer, m_buffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,13 @@
|
||||
# pragma comment(lib,"dbghelp.lib")
|
||||
#endif
|
||||
|
||||
#if NV_OS_XBOX
|
||||
# include <Xtl.h>
|
||||
# ifdef _DEBUG
|
||||
# include <xbdm.h>
|
||||
# endif //_DEBUG
|
||||
#endif //NV_OS_XBOX
|
||||
|
||||
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H)
|
||||
# include <signal.h>
|
||||
#endif
|
||||
@ -419,7 +426,7 @@ namespace
|
||||
|
||||
#if NV_OS_WIN32 //&& NV_CC_MSVC
|
||||
|
||||
/** Win32 asset handler. */
|
||||
/** Win32 assert handler. */
|
||||
struct Win32AssertHandler : public AssertHandler
|
||||
{
|
||||
// Code from Daniel Vogel.
|
||||
@ -491,10 +498,50 @@ namespace
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
#elif NV_OS_XBOX
|
||||
|
||||
/** Xbox360 assert handler. */
|
||||
struct Xbox360AssertHandler : public AssertHandler
|
||||
{
|
||||
static bool isDebuggerPresent()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
return DmIsDebuggerPresent() == TRUE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Assert handler method.
|
||||
virtual int assertion( const char * exp, const char * file, int line, const char * func/*=NULL*/ )
|
||||
{
|
||||
int ret = NV_ABORT_EXIT;
|
||||
|
||||
StringBuilder error_string;
|
||||
if( func != NULL ) {
|
||||
error_string.format( "*** Assertion failed: %s\n On file: %s\n On function: %s\n On line: %d\n ", exp, file, func, line );
|
||||
nvDebug( error_string.str() );
|
||||
}
|
||||
else {
|
||||
error_string.format( "*** Assertion failed: %s\n On file: %s\n On line: %d\n ", exp, file, line );
|
||||
nvDebug( error_string.str() );
|
||||
}
|
||||
|
||||
if (isDebuggerPresent()) {
|
||||
return NV_ABORT_DEBUG;
|
||||
}
|
||||
|
||||
if( ret == NV_ABORT_EXIT ) {
|
||||
// Exit cleanly.
|
||||
throw "Assertion failed";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
#else
|
||||
|
||||
/** Unix asset handler. */
|
||||
/** Unix assert handler. */
|
||||
struct UnixAssertHandler : public AssertHandler
|
||||
{
|
||||
bool isDebuggerPresent()
|
||||
@ -552,11 +599,13 @@ namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
/// Handle assertion through the asset handler.
|
||||
/// Handle assertion through the assert handler.
|
||||
int nvAbort(const char * exp, const char * file, int line, const char * func/*=NULL*/)
|
||||
{
|
||||
#if NV_OS_WIN32 //&& NV_CC_MSVC
|
||||
static Win32AssertHandler s_default_assert_handler;
|
||||
#elif NV_OS_XBOX
|
||||
static Xbox360AssertHandler s_default_assert_handler;
|
||||
#else
|
||||
static UnixAssertHandler s_default_assert_handler;
|
||||
#endif
|
||||
@ -585,7 +634,7 @@ void NV_CDECL nvDebugPrint(const char *msg, ...)
|
||||
/// Dump debug info.
|
||||
void debug::dumpInfo()
|
||||
{
|
||||
#if NV_OS_WIN32 || (defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H))
|
||||
#if (NV_OS_WIN32 && NV_CC_MSVC) || (defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H))
|
||||
if (hasStackTrace())
|
||||
{
|
||||
void * trace[64];
|
||||
|
@ -13,7 +13,6 @@
|
||||
#define NV_CDECL __cdecl
|
||||
#define NV_STDCALL __stdcall
|
||||
#define NV_FASTCALL __fastcall
|
||||
#define NV_FORCEINLINE __forceinline
|
||||
#define NV_DEPRECATED
|
||||
|
||||
#define NV_PURE
|
||||
@ -43,6 +42,7 @@
|
||||
#endif
|
||||
|
||||
#define NV_NOINLINE __declspec(noinline)
|
||||
#define NV_FORCEINLINE __forceinline
|
||||
|
||||
/*
|
||||
// Type definitions
|
||||
|
@ -7,6 +7,8 @@
|
||||
//#include <shlwapi.h> // PathFileExists
|
||||
#include <windows.h> // GetFileAttributes
|
||||
#include <direct.h> // _mkdir
|
||||
#elif NV_OS_XBOX
|
||||
#include <Xtl.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@ -23,7 +25,7 @@ bool FileSystem::exists(const char * path)
|
||||
return access(path, F_OK|R_OK) == 0;
|
||||
//struct stat buf;
|
||||
//return stat(path, &buf) == 0;
|
||||
#elif NV_OS_WIN32
|
||||
#elif NV_OS_WIN32 || NV_OS_XBOX
|
||||
// PathFileExists requires linking to shlwapi.lib
|
||||
//return PathFileExists(path) != 0;
|
||||
return GetFileAttributesA(path) != 0xFFFFFFFF;
|
||||
@ -39,8 +41,8 @@ bool FileSystem::exists(const char * path)
|
||||
|
||||
bool FileSystem::createDirectory(const char * path)
|
||||
{
|
||||
#if NV_OS_WIN32
|
||||
return _mkdir(path) != -1;
|
||||
#if NV_OS_WIN32 || NV_OS_XBOX
|
||||
return CreateDirectory(path, NULL) != 0;
|
||||
#else
|
||||
return mkdir(path, 0777) != -1;
|
||||
#endif
|
||||
@ -50,6 +52,9 @@ bool FileSystem::changeDirectory(const char * path)
|
||||
{
|
||||
#if NV_OS_WIN32
|
||||
return _chdir(path) != -1;
|
||||
#elif NV_OS_XBOX
|
||||
// Xbox doesn't support Current Working Directory!
|
||||
return false;
|
||||
#else
|
||||
return chdir(path) != -1;
|
||||
#endif
|
||||
|
@ -6,6 +6,8 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRALEAN
|
||||
#include <windows.h>
|
||||
#elif NV_OS_XBOX
|
||||
#include <Xtl.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
@ -16,6 +18,8 @@ void * nvLoadLibrary(const char * name)
|
||||
{
|
||||
#if NV_OS_WIN32
|
||||
return (void *)LoadLibraryExA( name, NULL, 0 );
|
||||
#elif NV_OS_XBOX
|
||||
return (void *)LoadLibraryA( name );
|
||||
#else
|
||||
return dlopen(name, RTLD_LAZY);
|
||||
#endif
|
||||
@ -24,7 +28,7 @@ void * nvLoadLibrary(const char * name)
|
||||
void nvUnloadLibrary(void * handle)
|
||||
{
|
||||
nvDebugCheck(handle != NULL);
|
||||
#if NV_OS_WIN32
|
||||
#if NV_OS_WIN32 || NV_OS_XBOX
|
||||
FreeLibrary((HMODULE)handle);
|
||||
#else
|
||||
dlclose(handle);
|
||||
@ -33,7 +37,7 @@ void nvUnloadLibrary(void * handle)
|
||||
|
||||
void * nvBindSymbol(void * handle, const char * symbol)
|
||||
{
|
||||
#if NV_OS_WIN32
|
||||
#if NV_OS_WIN32 || NV_OS_XBOX
|
||||
return (void *)GetProcAddress((HMODULE)handle, symbol);
|
||||
#else
|
||||
return (void *)dlsym(handle, symbol);
|
||||
|
@ -44,7 +44,7 @@ namespace nv {
|
||||
}
|
||||
|
||||
template <typename T> void free(const T * ptr) {
|
||||
::free((T *)ptr);
|
||||
::free((void *)ptr);
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
@ -15,17 +15,17 @@ namespace
|
||||
{
|
||||
static char * strAlloc(uint size)
|
||||
{
|
||||
return static_cast<char *>(malloc(size));
|
||||
return malloc<char>(size);
|
||||
}
|
||||
|
||||
static char * strReAlloc(char * str, uint size)
|
||||
{
|
||||
return static_cast<char *>(realloc(str, size));
|
||||
return realloc<char>(str, size);
|
||||
}
|
||||
|
||||
static void strFree(const char * str)
|
||||
{
|
||||
return free(const_cast<char *>(str));
|
||||
return free<char>(str);
|
||||
}
|
||||
|
||||
/*static char * strDup( const char * str )
|
||||
|
@ -33,6 +33,7 @@
|
||||
// NV_OS_LINUX
|
||||
// NV_OS_UNIX
|
||||
// NV_OS_DARWIN
|
||||
// NV_OS_XBOX
|
||||
|
||||
#define NV_OS_STRING POSH_OS_STRING
|
||||
|
||||
@ -56,6 +57,8 @@
|
||||
# define NV_OS_WIN32 1
|
||||
#elif defined POSH_OS_WIN64
|
||||
# define NV_OS_WIN64 1
|
||||
#elif defined POSH_OS_XBOX
|
||||
# define NV_OS_XBOX 1
|
||||
#else
|
||||
# error "Unsupported OS"
|
||||
#endif
|
||||
@ -148,12 +151,17 @@ typedef uint32 uint;
|
||||
#define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
|
||||
#define NV_STRING2(x) #x
|
||||
#define NV_STRING(x) NV_STRING2(x)
|
||||
#if NV_CC_GNUC
|
||||
//#define NV_FILE_LINE __FILE__ ":" NV_STRING(__LINE__) ": "
|
||||
#define NV_FILE_LINE
|
||||
|
||||
#if 1
|
||||
#if NV_CC_MSVC
|
||||
#define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x)
|
||||
#else
|
||||
#define NV_FILE_LINE __FILE__ "(" NV_STRING(__LINE__) ") : "
|
||||
#define NV_MESSAGE(x) message(x)
|
||||
#endif
|
||||
#else
|
||||
#define NV_MESSAGE(x)
|
||||
#endif
|
||||
|
||||
|
||||
// Startup initialization macro.
|
||||
#define NV_AT_STARTUP(some_code) \
|
||||
@ -180,6 +188,8 @@ typedef uint32 uint;
|
||||
#if NV_CC_MSVC
|
||||
# if NV_OS_WIN32
|
||||
# include "DefsVcWin32.h"
|
||||
# elif NV_OS_XBOX
|
||||
# include "DefsVcXBox.h"
|
||||
# else
|
||||
# error "MSVC: Platform not supported"
|
||||
# endif
|
||||
|
Reference in New Issue
Block a user