2010-05-27 23:18:08 +00:00
// This code is in the public domain -- Ignacio Casta<74> o <castano@gmail.com>
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
# pragma once
2007-04-17 08:49:19 +00:00
# ifndef NV_CORE_H
# define NV_CORE_H
// Function linkage
# if NVCORE_SHARED
# ifdef NVCORE_EXPORTS
# define NVCORE_API DLL_EXPORT
# define NVCORE_CLASS DLL_EXPORT_CLASS
# else
# define NVCORE_API DLL_IMPORT
# define NVCORE_CLASS DLL_IMPORT
# endif
# else // NVCORE_SHARED
# define NVCORE_API
# define NVCORE_CLASS
# endif // NVCORE_SHARED
// Platform definitions
2009-03-01 00:18:47 +00:00
# include <posh.h>
2007-04-17 08:49:19 +00:00
// OS:
// NV_OS_WIN32
// NV_OS_WIN64
// NV_OS_MINGW
// NV_OS_CYGWIN
// NV_OS_LINUX
// NV_OS_UNIX
// NV_OS_DARWIN
2010-10-21 18:44:10 +00:00
// NV_OS_XBOX
2013-06-07 17:53:55 +00:00
// NV_OS_ORBIS
// NV_OS_IOS
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
# define NV_OS_STRING POSH_OS_STRING
2007-04-17 08:49:19 +00:00
# if defined POSH_OS_LINUX
2010-07-13 03:08:45 +00:00
# define NV_OS_LINUX 1
# define NV_OS_UNIX 1
2013-06-07 17:53:55 +00:00
# elif defined POSH_OS_ORBIS
# define NV_OS_ORBIS 1
2009-03-21 07:44:26 +00:00
# elif defined POSH_OS_FREEBSD
2010-07-13 03:08:45 +00:00
# define NV_OS_FREEBSD 1
# define NV_OS_UNIX 1
2012-09-11 16:41:02 +00:00
# elif defined POSH_OS_OPENBSD
# define NV_OS_OPENBSD 1
# define NV_OS_UNIX 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_OS_CYGWIN32
2010-07-13 03:08:45 +00:00
# define NV_OS_CYGWIN 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_OS_MINGW
2010-07-13 03:08:45 +00:00
# define NV_OS_MINGW 1
# define NV_OS_WIN32 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_OS_OSX
2010-07-13 03:08:45 +00:00
# define NV_OS_DARWIN 1
# define NV_OS_UNIX 1
2013-06-07 17:53:55 +00:00
# elif defined POSH_OS_IOS
# define NV_OS_DARWIN 1 //ACS should we keep this on IOS?
# define NV_OS_UNIX 1
# define NV_OS_IOS 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_OS_UNIX
2010-07-13 03:08:45 +00:00
# define NV_OS_UNIX 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_OS_WIN64
2015-03-24 19:14:49 +00:00
# define NV_OS_WIN32 1
2010-07-13 03:08:45 +00:00
# define NV_OS_WIN64 1
2015-03-24 19:14:49 +00:00
# elif defined POSH_OS_WIN32
# define NV_OS_WIN32 1
2010-10-21 18:44:10 +00:00
# elif defined POSH_OS_XBOX
# define NV_OS_XBOX 1
2007-04-17 08:49:19 +00:00
# else
2010-07-13 03:08:45 +00:00
# error "Unsupported OS"
2007-04-17 08:49:19 +00:00
# endif
2013-06-07 17:53:55 +00:00
// Threading:
// some platforms don't implement __thread or similar for thread-local-storage
# if NV_OS_UNIX || NV_OS_ORBIS || NV_OS_IOS //ACStodoIOS darwin instead of ios?
# define NV_OS_USE_PTHREAD 1
# if NV_OS_DARWIN || NV_OS_IOS
# define NV_OS_HAS_TLS_QUALIFIER 0
# else
# define NV_OS_HAS_TLS_QUALIFIER 1
# endif
# else
# define NV_OS_USE_PTHREAD 0
# define NV_OS_HAS_TLS_QUALIFIER 1
# endif
2007-04-17 08:49:19 +00:00
// CPUs:
// NV_CPU_X86
// NV_CPU_X86_64
// NV_CPU_PPC
2010-10-28 05:38:39 +00:00
// NV_CPU_ARM
2015-07-20 21:47:01 +00:00
// NV_CPU_AARCH64
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
# define NV_CPU_STRING POSH_CPU_STRING
2007-04-17 08:49:19 +00:00
# if defined POSH_CPU_X86_64
2015-03-24 19:14:49 +00:00
//# define NV_CPU_X86 1
2010-05-27 23:18:08 +00:00
# define NV_CPU_X86_64 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_CPU_X86
2010-05-27 23:18:08 +00:00
# define NV_CPU_X86 1
2007-04-17 08:49:19 +00:00
# elif defined POSH_CPU_PPC
2010-05-27 23:18:08 +00:00
# define NV_CPU_PPC 1
2010-10-28 05:38:39 +00:00
# elif defined POSH_CPU_STRONGARM
# define NV_CPU_ARM 1
2015-07-20 21:47:01 +00:00
# elif defined POSH_CPU_AARCH64
# define NV_CPU_AARCH64 1
2007-04-17 08:49:19 +00:00
# else
2010-05-27 23:18:08 +00:00
# error "Unsupported CPU"
2007-04-17 08:49:19 +00:00
# endif
// Compiler:
// NV_CC_GNUC
// NV_CC_MSVC
2012-03-01 03:48:05 +00:00
// NV_CC_CLANG
2007-04-17 08:49:19 +00:00
2011-09-27 17:48:46 +00:00
# if defined POSH_COMPILER_CLANG
# define NV_CC_CLANG 1
2012-02-14 16:16:27 +00:00
# define NV_CC_GNUC 1 // Clang is compatible with GCC.
2011-09-27 17:48:46 +00:00
# define NV_CC_STRING "clang"
# elif defined POSH_COMPILER_GCC
2010-05-27 23:18:08 +00:00
# define NV_CC_GNUC 1
# define NV_CC_STRING "gcc"
2007-04-17 08:49:19 +00:00
# elif defined POSH_COMPILER_MSVC
2010-05-27 23:18:08 +00:00
# define NV_CC_MSVC 1
# define NV_CC_STRING "msvc"
2007-04-17 08:49:19 +00:00
# else
2010-05-27 23:18:08 +00:00
# error "Unsupported compiler"
2007-04-17 08:49:19 +00:00
# endif
2014-11-04 17:49:29 +00:00
# if NV_CC_MSVC
2015-10-29 06:53:08 +00:00
# define NV_CC_CPP11 (__cplusplus > 199711L || _MSC_VER >= 1800) // Visual Studio 2013 has all the features we use, but doesn't advertise full C++11 support yet.
2014-11-04 17:49:29 +00:00
# else
// @@ IC: This works in CLANG, about GCC?
2015-03-24 02:05:33 +00:00
// @@ ES: Doesn't work in gcc. These 3 features are available in GCC >= 4.4.
# ifdef __clang__
2014-11-04 17:49:29 +00:00
# define NV_CC_CPP11 (__has_feature(cxx_deleted_functions) && __has_feature(cxx_rvalue_references) && __has_feature(cxx_static_assert))
2015-03-24 02:05:33 +00:00
# elif defined __GNUC__
# define NV_CC_CPP11 ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
# endif
2014-11-04 17:49:29 +00:00
# endif
2007-04-17 08:49:19 +00:00
// Endiannes:
2010-05-27 23:18:08 +00:00
# define NV_LITTLE_ENDIAN POSH_LITTLE_ENDIAN
# define NV_BIG_ENDIAN POSH_BIG_ENDIAN
# define NV_ENDIAN_STRING POSH_ENDIAN_STRING
2007-04-17 08:49:19 +00:00
2011-09-27 17:48:46 +00:00
// Define the right printf prefix for size_t arguments:
# if POSH_64BIT_POINTER
# define NV_SIZET_PRINTF_PREFIX POSH_I64_PRINTF_PREFIX
# else
# define NV_SIZET_PRINTF_PREFIX
# endif
// cmake config
# include "nvconfig.h"
2010-09-20 06:58:20 +00:00
// Type definitions:
typedef posh_u8_t uint8 ;
typedef posh_i8_t int8 ;
typedef posh_u16_t uint16 ;
typedef posh_i16_t int16 ;
typedef posh_u32_t uint32 ;
typedef posh_i32_t int32 ;
typedef posh_u64_t uint64 ;
typedef posh_i64_t int64 ;
// Aliases
typedef uint32 uint ;
2007-04-17 08:49:19 +00:00
// Version string:
# define NV_VERSION_STRING \
2010-05-27 23:18:08 +00:00
NV_OS_STRING " / " NV_CC_STRING " / " NV_CPU_STRING " / " \
NV_ENDIAN_STRING " -endian - " __DATE__ " - " __TIME__
2007-04-17 08:49:19 +00:00
2010-10-28 05:38:39 +00:00
// Disable copy constructor and assignment operator.
2014-11-04 17:49:29 +00:00
# if NV_CC_CPP11
# define NV_FORBID_COPY(C) \
C ( const C & ) = delete ; \
C & operator = ( const C & ) = delete
# else
2007-04-17 08:49:19 +00:00
# define NV_FORBID_COPY(C) \
private : \
C ( const C & ) ; \
2012-03-01 03:48:05 +00:00
C & operator = ( const C & )
2014-11-04 17:49:29 +00:00
# endif
2007-04-17 08:49:19 +00:00
2010-10-28 05:38:39 +00:00
// Disable dynamic allocation on the heap.
// See Prohibiting Heap-Based Objects in More Effective C++.
2007-04-17 08:49:19 +00:00
# define NV_FORBID_HEAPALLOC() \
2010-05-27 23:18:08 +00:00
private : \
2010-10-28 05:38:39 +00:00
void * operator new ( size_t size ) ; \
2012-03-01 03:48:05 +00:00
void * operator new [ ] ( size_t size )
2011-09-27 17:48:46 +00:00
/ / static void * operator new ( size_t size ) ; \
//static void *operator new[](size_t size);
2007-04-17 08:49:19 +00:00
// String concatenation macros.
# define NV_STRING_JOIN2(arg1, arg2) NV_DO_STRING_JOIN2(arg1, arg2)
# define NV_DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2
# define NV_STRING_JOIN3(arg1, arg2, arg3) NV_DO_STRING_JOIN3(arg1, arg2, arg3)
# define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
2009-03-01 00:18:47 +00:00
# define NV_STRING2(x) #x
# define NV_STRING(x) NV_STRING2(x)
2010-10-21 18:44:10 +00:00
2012-02-14 16:16:27 +00:00
# if NV_CC_MSVC
# define NV_MULTI_LINE_MACRO_BEGIN do {
# define NV_MULTI_LINE_MACRO_END \
__pragma ( warning ( push ) ) \
__pragma ( warning ( disable : 4127 ) ) \
} while ( false ) \
__pragma ( warning ( pop ) )
# else
# define NV_MULTI_LINE_MACRO_BEGIN do {
# define NV_MULTI_LINE_MACRO_END } while(false)
# endif
2011-09-27 17:48:46 +00:00
2014-11-04 17:49:29 +00:00
# if NV_CC_CPP11
# define nvStaticCheck(x) static_assert((x), "Static assert "#x" failed")
2011-09-27 17:48:46 +00:00
# else
# define nvStaticCheck(x) typedef char NV_STRING_JOIN2(__static_assert_,__LINE__)[(x)]
# endif
# define NV_COMPILER_CHECK(x) nvStaticCheck(x) // I like this name best.
// Make sure type definitions are fine.
NV_COMPILER_CHECK ( sizeof ( int8 ) = = 1 ) ;
NV_COMPILER_CHECK ( sizeof ( uint8 ) = = 1 ) ;
NV_COMPILER_CHECK ( sizeof ( int16 ) = = 2 ) ;
NV_COMPILER_CHECK ( sizeof ( uint16 ) = = 2 ) ;
NV_COMPILER_CHECK ( sizeof ( int32 ) = = 4 ) ;
NV_COMPILER_CHECK ( sizeof ( uint32 ) = = 4 ) ;
NV_COMPILER_CHECK ( sizeof ( int32 ) = = 4 ) ;
NV_COMPILER_CHECK ( sizeof ( uint32 ) = = 4 ) ;
2011-01-08 04:54:06 +00:00
# define NV_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
2011-10-11 18:52:24 +00:00
#if 0 // Disabled in The Witness.
2010-10-21 18:44:10 +00:00
# if NV_CC_MSVC
# define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x)
2009-10-18 08:04:25 +00:00
# else
2010-10-21 18:44:10 +00:00
# define NV_MESSAGE(x) message(x)
2009-10-18 08:04:25 +00:00
# endif
2010-10-21 18:44:10 +00:00
# else
# define NV_MESSAGE(x)
# endif
2007-04-17 08:49:19 +00:00
// Startup initialization macro.
# define NV_AT_STARTUP(some_code) \
2010-05-27 23:18:08 +00:00
namespace { \
static struct NV_STRING_JOIN2 ( AtStartup_ , __LINE__ ) { \
NV_STRING_JOIN2 ( AtStartup_ , __LINE__ ) ( ) { some_code ; } \
} \
NV_STRING_JOIN3 ( AtStartup_ , __LINE__ , Instance ) ; \
2012-03-01 03:48:05 +00:00
}
2007-04-17 08:49:19 +00:00
2010-10-28 05:38:39 +00:00
// Indicate the compiler that the parameter is not used to suppress compier warnings.
2007-04-17 08:49:19 +00:00
# define NV_UNUSED(a) ((a)=(a))
2010-10-28 05:38:39 +00:00
// Null index. @@ Move this somewhere else... it's only used by nvmesh.
2010-09-20 06:58:20 +00:00
//const unsigned int NIL = unsigned int(~0);
2011-09-27 17:48:46 +00:00
//#define NIL uint(~0)
2007-04-17 08:49:19 +00:00
2010-10-28 05:38:39 +00:00
// Null pointer.
2007-04-17 08:49:19 +00:00
# ifndef NULL
# define NULL 0
# endif
// Platform includes
# if NV_CC_MSVC
2010-05-27 23:18:08 +00:00
# if NV_OS_WIN32
# include "DefsVcWin32.h"
2010-10-21 18:44:10 +00:00
# elif NV_OS_XBOX
# include "DefsVcXBox.h"
2010-05-27 23:18:08 +00:00
# else
# error "MSVC: Platform not supported"
# endif
2007-04-17 08:49:19 +00:00
# elif NV_CC_GNUC
2010-05-27 23:18:08 +00:00
# if NV_OS_LINUX
# include "DefsGnucLinux.h"
2012-09-11 16:41:02 +00:00
# elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD
2010-05-27 23:18:08 +00:00
# include "DefsGnucDarwin.h"
# elif NV_OS_MINGW
# include "DefsGnucWin32.h"
# elif NV_OS_CYGWIN
# error "GCC: Cygwin not supported"
# else
# error "GCC: Platform not supported"
# endif
2007-04-17 08:49:19 +00:00
# endif
# endif // NV_CORE_H