From 94ca3bb097e85dbb2c988b276c0f26dc5a7a47c6 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 14 Jun 2012 20:41:45 -0400 Subject: [PATCH] Merge core-CoreLib headers Merge hsTypes.h, hsUtils.h, and hsWindows.h into a single header to cut down on confusion and to simplify doxygen graphs. hsRefCnt's implementation details were moved into another file in preparation for making HeadSpin.h a precompiled header. --- Sources/Plasma/CoreLib/CMakeLists.txt | 5 +- Sources/Plasma/CoreLib/HeadSpin.cpp | 578 ++++++++++++++++- Sources/Plasma/CoreLib/HeadSpin.h | 604 +++++++++++++++++- .../CoreLib/{hsWindows.h => hsRefCnt.cpp} | 82 +-- Sources/Plasma/CoreLib/hsTypes.h | 414 ------------ Sources/Plasma/CoreLib/hsUtils.cpp | 591 ----------------- Sources/Plasma/CoreLib/hsUtils.h | 285 --------- Sources/Plasma/NucleusLib/pnNetProtocol/Pch.h | 2 +- 8 files changed, 1172 insertions(+), 1389 deletions(-) rename Sources/Plasma/CoreLib/{hsWindows.h => hsRefCnt.cpp} (51%) delete mode 100644 Sources/Plasma/CoreLib/hsTypes.h delete mode 100644 Sources/Plasma/CoreLib/hsUtils.cpp delete mode 100644 Sources/Plasma/CoreLib/hsUtils.h diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index d99906de..ecbc18e4 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -24,6 +24,7 @@ set(CoreLib_SOURCES hsMatrix44.cpp hsMemory.cpp hsQuat.cpp + hsRefCnt.cpp hsSafeRefCnt.cpp hsSTLStream.cpp hsStlUtils.cpp @@ -31,7 +32,6 @@ set(CoreLib_SOURCES hsStringTokenizer.cpp hsTemplates.cpp hsThread.cpp - hsUtils.cpp hsWide.cpp pcSmallRect.cpp plGeneric.cpp @@ -77,10 +77,7 @@ set(CoreLib_HEADERS hsStringTokenizer.h hsTemplates.h hsThread.h - hsTypes.h - hsUtils.h hsWide.h - hsWindows.h pcSmallRect.h plGeneric.h plLoadMask.h diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 356109c4..933a6108 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -40,15 +40,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" -#include "hsRefCnt.h" -#include "hsStlUtils.h" -#include "hsExceptions.h" -#include #ifdef _MSC_VER # include #endif +#include "hsStlUtils.h" +#include "hsTemplates.h" + /////////////////////////////////////////////////////////////////////////// /////////////////// For Status Messages /////////////////////////////////// @@ -122,7 +121,7 @@ void ErrorAssert(int line, const char file[], const char fmt[], ...) { if(_CrtDbgReport(_CRT_ASSERT, file, line, NULL, msg)) DebugBreak(); - } else + } else #endif // HS_DEBUGGING if (DebugIsDebuggerPresent()) { char str[] = "-------\nASSERTION FAILED:\nFile: %s Line: %i\nMessage: %s\n-------"; @@ -146,7 +145,7 @@ bool DebugIsDebuggerPresent() void DebugBreakIfDebuggerPresent() { #ifdef _MSC_VER - __try + __try { __debugbreak(); } __except(EXCEPTION_EXECUTE_HANDLER) { @@ -175,30 +174,6 @@ void DebugMsg(const char fmt[], ...) } } -/////////////////////////////////////////////////////////////////// - - -hsRefCnt::~hsRefCnt() -{ - hsDebugCode(hsThrowIfFalse(fRefCnt == 1);) -} - -void hsRefCnt::Ref() -{ - fRefCnt++; -} - -void hsRefCnt::UnRef() -{ - hsDebugCode(hsThrowIfFalse(fRefCnt >= 1);) - - if (fRefCnt == 1) // don't decrement if we call delete - delete this; - else - --fRefCnt; -} - - //////////////////////////////////////////////////////////////////////////// #ifndef PLASMA_EXTERNAL_RELEASE @@ -237,4 +212,547 @@ void hsStatusMessageF(const char * fmt, ...) va_end(args); } +char * hsFormatStr(const char * fmt, ...) +{ + va_list args; + va_start(args,fmt); + char * result = hsFormatStrV(fmt,args); + va_end(args); + return result; +} + +char * hsFormatStrV(const char * fmt, va_list args) +{ + std::string buf; + xtl::formatv(buf,fmt,args); + return hsStrcpy(buf.c_str()); +} + +static char hsStrBuf[100]; + +char *hsScalarToStr(float s) +{ + sprintf(hsStrBuf, "%f", s); + return hsStrBuf; +} + +class hsMinimizeClientGuard +{ +#ifdef CLIENT + hsWindowHndl fWnd; + +public: + hsMinimizeClientGuard() + { +#ifdef HS_BUILD_FOR_WIN32 + fWnd = GetActiveWindow(); + // If the application's topmost window is fullscreen, minimize it before displaying an error + if ((GetWindowLong(fWnd, GWL_STYLE) & WS_POPUP) != 0) + ShowWindow(fWnd, SW_MINIMIZE); +#endif // HS_BUILD_FOR_WIN32 + } + + ~hsMinimizeClientGuard() + { +#ifdef HS_BUILD_FOR_WIN32 + ShowWindow(fWnd, SW_RESTORE); +#endif // HS_BUILD_FOR_WIN32 + } +#endif // CLIENT +}; + +bool hsMessageBox_SuppressPrompts = false; + +int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon) +{ + if (hsMessageBox_SuppressPrompts) + return hsMBoxOk; + +#if HS_BUILD_FOR_WIN32 + uint32_t flags = 0; + + if (kind == hsMessageBoxNormal) + flags |= MB_OK; + else if (kind == hsMessageBoxAbortRetyIgnore) + flags |= MB_ABORTRETRYIGNORE; + else if (kind == hsMessageBoxOkCancel) + flags |= MB_OKCANCEL; + else if (kind == hsMessageBoxRetryCancel) + flags |= MB_RETRYCANCEL; + else if (kind == hsMessageBoxYesNo) + flags |= MB_YESNO; + else if (kind == hsMessageBoxYesNoCancel) + flags |= MB_YESNOCANCEL; + else + flags |= MB_OK; + + if (icon == hsMessageBoxIconError) + flags |= MB_ICONERROR; + else if (icon == hsMessageBoxIconQuestion) + flags |= MB_ICONQUESTION; + else if (icon == hsMessageBoxIconExclamation) + flags |= MB_ICONEXCLAMATION; + else if (icon == hsMessageBoxIconAsterisk) + flags |= MB_ICONASTERISK; + else + flags |= MB_ICONERROR; + + hsMinimizeClientGuard guard; + int ans = MessageBox(owner, message, caption, flags); + + switch (ans) + { + case IDOK: return hsMBoxOk; + case IDCANCEL: return hsMBoxCancel; + case IDABORT: return hsMBoxAbort; + case IDRETRY: return hsMBoxRetry; + case IDIGNORE: return hsMBoxIgnore; + case IDYES: return hsMBoxYes; + case IDNO: return hsMBoxNo; + default: return hsMBoxCancel; + } + +#endif +} + +int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon) +{ + if (hsMessageBox_SuppressPrompts) + return hsMBoxOk; + +#if HS_BUILD_FOR_WIN32 + uint32_t flags = 0; + + if (kind == hsMessageBoxNormal) + flags |= MB_OK; + else if (kind == hsMessageBoxAbortRetyIgnore) + flags |= MB_ABORTRETRYIGNORE; + else if (kind == hsMessageBoxOkCancel) + flags |= MB_OKCANCEL; + else if (kind == hsMessageBoxRetryCancel) + flags |= MB_RETRYCANCEL; + else if (kind == hsMessageBoxYesNo) + flags |= MB_YESNO; + else if (kind == hsMessageBoxYesNoCancel) + flags |= MB_YESNOCANCEL; + else + flags |= MB_OK; + + if (icon == hsMessageBoxIconError) + flags |= MB_ICONERROR; + else if (icon == hsMessageBoxIconQuestion) + flags |= MB_ICONQUESTION; + else if (icon == hsMessageBoxIconExclamation) + flags |= MB_ICONEXCLAMATION; + else if (icon == hsMessageBoxIconAsterisk) + flags |= MB_ICONASTERISK; + else + flags |= MB_ICONERROR; + + hsMinimizeClientGuard guard; + int ans = MessageBoxW(owner, message, caption, flags); + + switch (ans) + { + case IDOK: return hsMBoxOk; + case IDCANCEL: return hsMBoxCancel; + case IDABORT: return hsMBoxAbort; + case IDRETRY: return hsMBoxRetry; + case IDIGNORE: return hsMBoxIgnore; + case IDYES: return hsMBoxYes; + case IDNO: return hsMBoxNo; + default: return hsMBoxCancel; + } + +#endif +} + +int hsMessageBox(const char message[], const char caption[], int kind, int icon) +{ + return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); +} + +int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon) +{ + return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); +} + +inline hsBool hsCompare(float a, float b, float delta) +{ + return (fabs(a - b) < delta); +} + + +/* Generic psuedo RNG used in ANSI C. */ +static unsigned long SEED = 1; +int hsRand() +{ + register int temp; + SEED = SEED * 1103515245 + 12345; + temp = (int)((SEED/65536)&32767); + return (temp); +} + +void hsRandSeed(int seed) +{ + SEED = seed; +} +/**************************************/ +int hsStrlen(const char src[]) +{ + if (src==nil) + return 0; + + int i = 0; + while (src[i]) + i++; + return i; +} + +char* hsStrcpy(char dst[], const char src[]) +{ + if (src) + { + if (dst == nil) + { + int count = hsStrlen(src); + dst = (char *)malloc(count + 1); + memcpy(dst, src, count); + dst[count] = 0; + return dst; + } + + int32_t i; + for (i = 0; src[i] != 0; i++) + dst[i] = src[i]; + dst[i] = 0; + } + + return dst; +} + +bool hsStrEQ(const char s1[], const char s2[]) +{ + if (s1 && s2) + { + while (*s1) + if(*s1++ != *s2++) + return false; + return *s2 == 0; + } + + return (!s1 && !s2); +} + +bool hsStrCaseEQ(const char* s1, const char* s2) +{ + if (s1 && s2) + { + while (*s1) + if(tolower(*s1++) != tolower(*s2++)) + return false; + return *s2 == 0; + } + + return (!s1 && !s2); +} + +void hsStrcat(char dst[], const char src[]) +{ + if (src && dst) + { + dst += hsStrlen(dst); + while(*src) + *dst++ = *src++; + *dst = 0; + } +} + +void hsStrLower(char *s) +{ + if (s) + { + int i; + for (i = 0; i < hsStrlen(s); i++) + s[i] = tolower(s[i]); + } +} + +char* hsP2CString(const uint8_t pstring[], char cstring[]) +{ + char* cstr = cstring; + const uint8_t* stop = &pstring[1] + pstring[0]; + + pstring += 1; // skip length byte + while (pstring < stop) + *cstr++ = *pstring++; + *cstr = 0; + return cstring; +} + +uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]) +{ + int i; + + for (i = 1; *cstring; i++) + pstring[i] = *cstring++; + pstring[0] = i - 1; + return pstring; +} + +//// IStringToWString ///////////////////////////////////////////////////////// +// Converts a char * string to a wchar_t * string + +wchar_t *hsStringToWString( const char *str ) +{ + // convert the char string to a wchar_t string + int len = strlen(str); + wchar_t *wideString = new wchar_t[len+1]; + for (int i=0; i versionStrs; + OSVERSIONINFOEX osvi; + BOOL bOsVersionInfoEx; + + // Try calling GetVersionEx using the OSVERSIONINFOEX structure. + // + // If that fails, try using the OSVERSIONINFO structure. + + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + + if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) + { + // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. + + osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) + return FALSE; + } + + switch (osvi.dwPlatformId) + { + case VER_PLATFORM_WIN32_NT: + + // Test for the product. + + if ( osvi.dwMajorVersion <= 4 ) + versionStrs.Append(hsStrcpy("Microsoft Windows NT ")); + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) + versionStrs.Append(hsStrcpy ("Microsoft Windows 2000 ")); + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) + versionStrs.Append(hsStrcpy ("Microsoft Windows XP ")); + + // Test for product type. + + if( bOsVersionInfoEx ) + { + if ( osvi.wProductType == VER_NT_WORKSTATION ) + { + if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) + versionStrs.Append(hsStrcpy ( "Personal " )); + else + versionStrs.Append(hsStrcpy ( "Professional " )); + } + + else if ( osvi.wProductType == VER_NT_SERVER ) + { + if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) + versionStrs.Append(hsStrcpy ( "DataCenter Server " )); + else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) + versionStrs.Append(hsStrcpy ( "Advanced Server " )); + else + versionStrs.Append(hsStrcpy ( "Server " )); + } + } + else + { + HKEY hKey; + char szProductType[80]; + DWORD dwBufLen; + + RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", + 0, KEY_QUERY_VALUE, &hKey ); + RegQueryValueEx( hKey, "ProductType", NULL, NULL, + (LPBYTE) szProductType, &dwBufLen); + RegCloseKey( hKey ); + if ( lstrcmpi( "WINNT", szProductType) == 0 ) + versionStrs.Append(hsStrcpy( "Professional " )); + if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) + versionStrs.Append(hsStrcpy( "Server " )); + if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) + versionStrs.Append(hsStrcpy( "Advanced Server " )); + } + + // Display version, service pack (if any), and build number. + + if ( osvi.dwMajorVersion <= 4 ) + { + versionStrs.Append(hsStrcpy (xtl::format("version %d.%d %s (Build %d)\n", + osvi.dwMajorVersion, + osvi.dwMinorVersion, + osvi.szCSDVersion, + osvi.dwBuildNumber & 0xFFFF).c_str())); + } + else + { + versionStrs.Append(hsStrcpy (xtl::format("%s (Build %d)\n", + osvi.szCSDVersion, + osvi.dwBuildNumber & 0xFFFF).c_str())); + } + break; + + case VER_PLATFORM_WIN32_WINDOWS: + + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) + { + versionStrs.Append(hsStrcpy ("Microsoft Windows 95 ")); + if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) + versionStrs.Append(hsStrcpy("OSR2 " )); + } + + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) + { + versionStrs.Append(hsStrcpy ("Microsoft Windows 98 ")); + if ( osvi.szCSDVersion[1] == 'A' ) + versionStrs.Append(hsStrcpy("SE " )); + } + + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) + { + versionStrs.Append(hsStrcpy ("Microsoft Windows Me ")); + } + break; + + case VER_PLATFORM_WIN32s: + + versionStrs.Append(hsStrcpy ("Microsoft Win32s ")); + break; + } + + versionStrs.Append(nil); // terminator + + return versionStrs.DetachArray(); +#else + return nil; +#endif +} + #endif // not PLASMA_EXTERNAL_RELEASE diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 8c91e1dd..b8347441 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -46,10 +46,604 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # define HS_DEBUGGING #endif // defined(_DEBUG) || defined(UNIX_DENUG) -// Internal Headers -// These are only ever included here :) -#include "hsTypes.h" -#include "hsWindows.h" -#include "hsUtils.h" +//====================================== +// Winblows Hacks +//====================================== +#ifdef HS_BUILD_FOR_WIN32 + // 4244: Conversion + // 4305: Truncation + // 4503: 'identifier' : decorated name length exceeded, name was truncated + // 4018: signed/unsigned mismatch + // 4786: 255 character debug limit + // 4284: STL template defined operator-> for a class it doesn't make sense for (int, etc) + // 4800: 'int': forcing value to bool 'true' or 'false' (performance warning) +# ifdef _MSC_VER +# pragma warning( disable : 4305 4503 4018 4786 4284 4800) +# endif // _MSC_VER + + // Terrible hacks for MinGW because they don't have a reasonable + // default for the Windows version. We cheat and say it's XP. +# ifdef __MINGW32__ +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# undef _WIN32_IE +# define _WIN32_IE 0x400 +# endif + + // Windows.h includes winsock.h (winsocks 1), so we need to manually include winsock2 + // and tell Windows.h to only bring in modern headers +# include +# include + +# define WIN32_LEAN_AND_MEAN +# ifndef NOMINMAX +# define NOMINMAX // Needed to prevent NxMath conflicts +# endif +# include + + // Just some fun typedefs... + typedef HWND hsWindowHndl; + typedef HINSTANCE hsWindowInst; +#else + typedef int32_t* hsWindowHndl; + typedef int32_t* hsWindowInst; +#endif // HS_BUILD_FOR_WIN32 + +//====================================== +// We don't want the Windows.h min/max! +//====================================== +#ifdef max +# undef max +#endif + +#ifdef min +# undef min +#endif + +//====================================== +// Some standard includes +//====================================== +#include +#include +#include +#include +#include +#include +#include +#include + + +//====================================== +// Basic macros +//====================================== +#ifdef __cplusplus + #define hsCTypeDefStruct(foo) +#else + #define hsCTypeDefStruct(foo) typedef struct foo foo; +#endif + +#ifdef HS_BUILD_FOR_WIN32 +# ifndef CDECL +# define CDECL __cdecl +# endif +#else +# define CDECL +#endif + +#define kPosInfinity16 (32767) +#define kNegInfinity16 (-32768) + +#define kPosInfinity32 (0x7fffffff) +#define kNegInfinity32 (0x80000000) + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#ifdef __cplusplus + typedef int hsBool; +#endif + +#ifndef nil +# define nil (0) +#endif + +typedef int32_t hsError; +typedef uint32_t hsGSeedValue; + +#define hsOK 0 +#define hsFail -1 +#define hsFailed(r) ((hsError)(r)=hsOK) + +#define hsLongAlign(n) (((n) + 3) & ~3L) + +#define hsMaximum(a, b) ((a) > (b) ? (a) : (b)) +#define hsMinimum(a, b) ((a) < (b) ? (a) : (b)) +#define hsABS(x) ((x) < 0 ? -(x) : (x)) +#define hsSGN(x) (((x) < 0) ? -1 : ( ((x) > 0) ? 1 : 0 )) + +#define hsBitTst2Bool(value, mask) (((value) & (mask)) != 0) + +#define hsFourByteTag(a, b, c, d) (((uint32_t)(a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d)) + + +//====================================== +// Endian swap funcitions +//====================================== +inline uint16_t hsSwapEndian16(uint16_t value) +{ + return (value >> 8) | (value << 8); +} +inline uint32_t hsSwapEndian32(uint32_t value) +{ + return ((value) << 24) | + ((value & 0x0000ff00) << 8) | + ((value & 0x00ff0000) >> 8) | + ((value) >> 24); +} +inline uint64_t hsSwapEndian64(uint64_t value) +{ + return ((value) << 56) | + ((value & 0x000000000000ff00) << 40) | + ((value & 0x0000000000ff0000) << 24) | + ((value & 0x00000000ff000000) << 8) | + ((value & 0x000000ff00000000) >> 8) | + ((value & 0x0000ff0000000000) >> 24) | + ((value & 0x00ff000000000000) >> 40) | + ((value) >> 56); +} +inline float hsSwapEndianFloat(float fvalue) +{ + uint32_t value = *(uint32_t*)&fvalue; + value = hsSwapEndian32(value); + return *(float*)&value; +} +inline double hsSwapEndianDouble(double dvalue) +{ + uint64_t value = *(uint64_t*)&dvalue; + value = hsSwapEndian64(value); + return *(double*)&value; +} + +#if LITTLE_ENDIAN + #define hsToBE16(n) hsSwapEndian16(n) + #define hsToBE32(n) hsSwapEndian32(n) + #define hsToBE64(n) hsSwapEndian64(n) + #define hsToBEFloat(n) hsSwapEndianFloat(n) + #define hsToBEDouble(n) hsSwapEndianDouble(n) + #define hsToLE16(n) (n) + #define hsToLE32(n) (n) + #define hsToLE64(n) (n) + #define hsToLEFloat(n) (n) + #define hsToLEDouble(n) (n) +#else + #define hsToBE16(n) (n) + #define hsToBE32(n) (n) + #define hsToBE64(n) (n) + #define hsToBEFloat(n) (n) + #define hsToBEDouble(n) (n) + #define hsToLE16(n) hsSwapEndian16(n) + #define hsToLE32(n) hsSwapEndian32(n) + #define hsToLE64(n) hsSwapEndian64(n) + #define hsToLEFloat(n) hsSwapEndianFloat(n) + #define hsToLEDouble(n) hsSwapEndianDouble(n) +#endif + +inline void hsSwap(int32_t& a, int32_t& b) +{ + int32_t c = a; + a = b; + b = c; +} + +inline void hsSwap(uint32_t& a, uint32_t& b) +{ + uint32_t c = a; + a = b; + b = c; +} + +inline void hsSwap(float& a, float& b) +{ + float c = a; + a = b; + b = c; +} + +//====================================== +// Color32 Type +//====================================== +struct hsColor32 { + + uint8_t b, g, r, a; + + inline void SetARGB(uint8_t aa, uint8_t rr, uint8_t gg, uint8_t bb) + { + this->a = aa; + this->r = rr; + this->g = gg; + this->b = bb; + } + + // Compatibility inlines, should be depricated + inline void Set(uint8_t rr, uint8_t gg, uint8_t bb) + { + this->r = rr; + this->g = gg; + this->b = bb; + } + inline void Set(uint8_t aa, uint8_t rr, uint8_t gg, uint8_t bb) + { + this->SetARGB(aa, rr, gg, bb); + } + + int operator==(const hsColor32& aa) const + { + return *(uint32_t*)&aa == *(uint32_t*)this; + } + int operator!=(const hsColor32& aa) { return !(aa == *this); } +}; +hsCTypeDefStruct(hsColor32) +typedef hsColor32 hsRGBAColor32; + + +//=========================================================================== +// Define a NOOP (null) statement +//=========================================================================== +#ifdef _MSC_VER +# define NULL_STMT __noop +#else +# define NULL_STMT ((void)0) +#endif + + +//=========================================================================== +// Old COMPILER_ASSERT Macro +// This DEPRECATED. Use static_assert instead! +//=========================================================================== +#define COMPILER_ASSERT(expr) static_assert(expr, "old compiler assert failure") +#define COMPILER_ASSERT_HEADER(prefix,expr) static_assert(expr, "old compiler assert failure") + +//=========================================================================== +template +inline T max (const T & a, const T & b) { + return (a > b) ? a : b; +} + +//=========================================================================== +inline unsigned max (int a, unsigned b) { + return ((unsigned)a > b) ? a : b; +} + +//=========================================================================== +inline unsigned max (unsigned a, int b) { + return (a > (unsigned)b) ? a : b; +} + +//=========================================================================== +template +inline T min (const T & a, const T & b) { + return (a < b) ? a : b; +} + +//=========================================================================== +inline unsigned min (int a, unsigned b) { + return ((unsigned)a < b) ? a : b; +} + +//=========================================================================== +inline unsigned min (unsigned a, int b) { + return (a < (unsigned)b) ? a : b; +} + + +/**************************************************************************** +* +* MAX/MIN macros +* These are less safe than the inline function versions, since they +* evaluate parameters twice. However, they can be used to produce +* compile-time constants. +* +***/ +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + + +/**************************************************************************** +* +* SWAP +* Swaps the values of two variables +* +***/ + +//=========================================================================== +template +void SWAP (T & a, T & b) { + T temp = a; + a = b; + b = temp; +} + + +/**************************************************************************** +* +* AUTO_INIT_FUNC +* Declares a function that is automatically called at program startup time +* +* Example: +* +* AUTO_INIT_FUNC(BuildLookupTables) { +* ... +* } +* +***/ + +#define AUTO_INIT_FUNC(name) namespace { struct name { name (); } name##_instance; } name::name () + + +/**************************************************************************** +* +* arrsize +* arrsize returns the number of elements in an array variable +* +* Example: +* +* StrPrintf(buffer, arrsize(buffer), "%u", value); +* +***/ +#define arrsize(a) (sizeof(a) / sizeof((a)[0])) + + +/**************************************************************************** +* +* IS_POW2 +* +***/ +#define IS_POW2(val) (!((val) & ((val) - 1))) + +#ifdef PLASMA_EXTERNAL_RELEASE +# define hsStatusMessage(x) NULL_STMT +# define hsStatusMessageF(x, ...) NULL_STMT +#else + void hsStatusMessage(const char message[]); + void hsStatusMessageF(const char * fmt, ...); +#endif // PLASMA_EXTERNAL_RELEASE + +int hsStrlen(const char src[]); +char* hsStrcpy(char dstOrNil[], const char src[]); +void hsStrcat(char dst[], const char src[]); +bool hsStrEQ(const char s1[], const char s2[]); +bool hsStrCaseEQ(const char* s1, const char* s2); +char* hsScalarToStr(float); +int hsRemove(const char* filename); +void hsCPathToMacPath(char* dst, char* fname); +void hsStrLower(char *s); +char * hsFormatStr(const char * fmt, ...); // You are responsible for returned memory. +char * hsFormatStrV(const char * fmt, va_list args); // You are responsible for returned memory. + +// Use "correct" stricmp based on the selected compiler / library +#if HS_BUILD_FOR_WIN32 +# define stricmp _stricmp +# define strnicmp _strnicmp +# define wcsicmp _wcsicmp +# define wcsnicmp _wcsnicmp +# define strlwr _strlwr +#else +# define stricmp strcasecmp +# define strnicmp strncasecmp +# define wcsicmp wcscasecmp +# define wcsnicmp wcsncasecmp +# define strlwr hsStrLower +#endif + + +// A pstring has a length uint8_t at the beginning, and no trailing 0 +char* hsP2CString(const uint8_t pstring[], char cstring[]); +uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]); + +inline char* hsStrcpy(const char src[]) +{ + return hsStrcpy(nil, src); +} + +inline char *hsStrncpy(char *strDest, const char *strSource, size_t count) +{ + char *temp = strncpy(strDest, strSource, count-1); + strDest[count-1] = 0; + return temp; +} + +wchar_t *hsStringToWString( const char *str ); +char *hsWStringToString( const wchar_t *str ); + +enum { // Kind of MessageBox...passed to hsMessageBox + hsMessageBoxAbortRetyIgnore, + hsMessageBoxNormal, // Just Ok + hsMessageBoxOkCancel, + hsMessageBoxRetryCancel, + hsMessageBoxYesNo, + hsMessageBoxYesNoCancel, +}; + +enum { + hsMessageBoxIconError, + hsMessageBoxIconQuestion, + hsMessageBoxIconExclamation, + hsMessageBoxIconAsterisk, +}; + +enum { // RETURN VALUES FROM hsMessageBox + hsMBoxOk = 1, // OK button was selected. + hsMBoxCancel, // Cancel button was selected. + hsMBoxAbort, // Abort button was selected. + hsMBoxRetry, // Retry button was selected. + hsMBoxIgnore, // Ignore button was selected. + hsMBoxYes, // Yes button was selected. + hsMBoxNo // No button was selected. +}; + +extern bool hsMessageBox_SuppressPrompts; +int hsMessageBox(const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); + +inline hsBool hsCompare(float a, float b, float delta=0.0001); + +// flag testing / clearing +#define hsCheckBits(f,c) ((f & c)==c) +#define hsTestBits(f,b) ( (f) & (b) ) +#define hsSetBits(f,b) ( (f) |= (b) ) +#define hsClearBits(f,b) ( (f) &= ~(b) ) +#define hsToggleBits(f,b) ( (f) ^= (b) ) +#define hsChangeBits(f,b,t) ( t ? hsSetBits(f,b) : hsClearBits(f,b) ) + + +#if HS_BUILD_FOR_WIN32 + // This is for Windows +# define hsVsnprintf _vsnprintf +# define hsVsnwprintf _vsnwprintf +# define hsSnprintf _snprintf +# define hsSnwprintf _snwprintf + +# define snprintf _snprintf +# define snwprintf _snwprintf +# define swprintf _snwprintf + +# ifndef fileno +# define fileno(__F) _fileno(__F) +# endif + +# define hsWFopen(name, mode) _wfopen(name, mode) +#else + // This is for Unix, Linux, OSX, etc. +# define hsVsnprintf vsnprintf +# define hsVsnwprintf vswprintf +# define hsSnprintf snprintf +# define hsSnwprintf swprintf + +# define hsWFopen(name, mode) fopen(hsWStringToString(name), hsWStringToString(mode)) + +# include +# define MAX_PATH PATH_MAX +#endif + +// Useful floating point utilities +inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); } +inline float hsRadiansToDegrees(float rad) { return float(rad * (180 / M_PI)); } +#define hsInvert(a) (1 / (a)) + +#include +#define NEWZERO(t) new(calloc(sizeof(t), 1)) t + +#ifdef _MSC_VER +# define ALIGN(n) __declspec(align(n)) +#else +# define ALIGN(n) __atribute__(aligned(n)) +#endif + +///////////////////////////// +// Physical memory functions +///////////////////////////// +enum MemSpec +{ + kBlows = 0, // Less than 128 + kAcceptable, // Less than 256 + kOptimal // 256 or greater +}; + +uint32_t hsPhysicalMemory(); +MemSpec hsMemorySpec(); + +inline int hsRandMax() { return 32767; } +inline float hsRandNorm() { return 1.f / 32767.f; } // multiply by hsRand to get randoms ranged [0..1] +int hsRand(void); +void hsRandSeed(int seed); + +#define hsFopen(name, mode) fopen(name, mode) + +char** DisplaySystemVersion(); + +/************************ Debug/Error Macros **************************/ + +typedef void (*hsDebugMessageProc)(const char message[]); +extern hsDebugMessageProc gHSDebugProc; +#define HSDebugProc(m) { if (gHSDebugProc) gHSDebugProc(m); } +hsDebugMessageProc hsSetDebugMessageProc(hsDebugMessageProc newProc); + +extern hsDebugMessageProc gHSStatusProc; +hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); + +void ErrorEnableGui (bool enabled); +void ErrorAssert (int line, const char file[], const char fmt[], ...); + +bool DebugIsDebuggerPresent (); +void DebugBreakIfDebuggerPresent (); +void DebugMsg(const char fmt[], ...); + +#ifdef HS_DEBUGGING + + void hsDebugMessage(const char message[], long refcon); + #define hsDebugCode(code) code + #define hsIfDebugMessage(expr, msg, ref) (void)( ((expr) != 0) || (hsDebugMessage(msg, ref), 0) ) + #define hsAssert(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) ) + #define ASSERT(expr) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, #expr), 0) ) + #define ASSERTMSG(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) ) + #define FATAL(msg) ErrorAssert(__LINE__, __FILE__, msg) + #define DEBUG_MSG DebugMsg + #define DEBUG_BREAK_IF_DEBUGGER_PRESENT DebugBreakIfDebuggerPresent + +#else /* Not debugging */ + + #define hsDebugMessage(message, refcon) NULL_STMT + #define hsDebugCode(code) /* empty */ + #define hsIfDebugMessage(expr, msg, ref) NULL_STMT + #define hsAssert(expr, msg) NULL_STMT + #define ASSERT(expr) NULL_STMT + #define ASSERTMSG(expr, msg) NULL_STMT + #define FATAL(msg) NULL_STMT + #define DEBUG_MSG (void) + #define DEBUG_MSGV NULL_STMT + #define DEBUG_BREAK_IF_DEBUGGER_PRESENT NULL_STMT + +#endif // HS_DEBUGGING + + +#ifdef _MSC_VER +#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); __assume(0); break; +#else +#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; +#endif + +/***************************************************************************** +* +* Atomic Operations +* +***/ + +// *value += increment; return original value of *value; thread safe +inline long AtomicAdd(long* value, long increment) +{ +#ifdef HS_BUILD_FOR_WIN32 + return InterlockedExchangeAdd(value, increment); +#elif __GNUC__ + return __sync_fetch_and_add(value, increment); +#else +# error "No Atomic Set support on this architecture" +#endif +} + +// *value = value; return original value of *value; thread safe +inline long AtomicSet(long* value, long set) +{ +#ifdef HS_BUILD_FOR_WIN32 + return InterlockedExchange(value, set); +#elif __GNUC__ + return __sync_lock_test_and_set(value, set); +#else +# error "No Atomic Set support on this architecture" +#endif +} #endif diff --git a/Sources/Plasma/CoreLib/hsWindows.h b/Sources/Plasma/CoreLib/hsRefCnt.cpp similarity index 51% rename from Sources/Plasma/CoreLib/hsWindows.h rename to Sources/Plasma/CoreLib/hsRefCnt.cpp index b683c73c..3ed939d6 100644 --- a/Sources/Plasma/CoreLib/hsWindows.h +++ b/Sources/Plasma/CoreLib/hsRefCnt.cpp @@ -40,62 +40,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ -#ifdef _HSWINDOWS_H -# error "Do not include hsWindows.h directly--use HeadSpin.h" -#endif // _HSWINDOWS_H -#define _HSWINDOWS_H - -#if HS_BUILD_FOR_WIN32 - - // 4244: Conversion - // 4305: Truncation - // 4503: 'identifier' : decorated name length exceeded, name was truncated - // 4018: signed/unsigned mismatch - // 4786: 255 character debug limit - // 4284: STL template defined operator-> for a class it doesn't make sense for (int, etc) - // 4800: 'int': forcing value to bool 'true' or 'false' (performance warning) -# ifdef _MSC_VER -# pragma warning( disable : 4305 4503 4018 4786 4284 4800) -# endif // _MSC_VER - - // Terrible hacks for MinGW because they don't have a reasonable - // default for the Windows version. We cheat and say it's XP. -# ifdef __MINGW32__ -# undef _WIN32_WINNT -# define _WIN32_WINNT 0x501 -# undef _WIN32_IE -# define _WIN32_IE 0x400 -# endif - - // Windows.h includes winsock.h (winsocks 1), so we need to manually include winsock2 - // and tell Windows.h to only bring in modern headers -# ifndef MAXPLUGINCODE -# include -# include -# endif // MAXPLUGINCODE -# define WIN32_LEAN_AND_MEAN -# ifndef NOMINMAX -# define NOMINMAX // Needed to prevent NxMath conflicts -# endif -# include - - typedef HWND hsWindowHndl; - typedef HINSTANCE hsWindowInst; -#else - typedef int32_t* hsWindowHndl; - typedef int32_t* hsWindowInst; -#endif // HS_BUILD_FOR_WIN32 - -/**************************************************************************** -* -* max/min inline functions -* -***/ - -#ifdef max -#undef max -#endif - -#ifdef min -#undef min -#endif +#include "HeadSpin.h" +#include "hsExceptions.h" +#include "hsRefCnt.h" + +hsRefCnt::~hsRefCnt() +{ + hsDebugCode(hsThrowIfFalse(fRefCnt == 1);) +} + +void hsRefCnt::Ref() +{ + fRefCnt++; +} + +void hsRefCnt::UnRef() +{ + hsDebugCode(hsThrowIfFalse(fRefCnt >= 1);) + + if (fRefCnt == 1) // don't decrement if we call delete + delete this; + else + --fRefCnt; +} diff --git a/Sources/Plasma/CoreLib/hsTypes.h b/Sources/Plasma/CoreLib/hsTypes.h deleted file mode 100644 index ed2ec9f9..00000000 --- a/Sources/Plasma/CoreLib/hsTypes.h +++ /dev/null @@ -1,414 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifdef _HSTYPES_H -# error "Do not include hsTypes.h directly--use HeadSpin.h" -#endif // _HSTYPES_H -#define _HSTYPES_H - - -/************************** Other Includes *****************************/ -#include -#include -#include -#include - - -/************************** Basic Macros *****************************/ - -#ifdef __cplusplus - #define hsCTypeDefStruct(foo) -#else - #define hsCTypeDefStruct(foo) typedef struct foo foo; -#endif - -#ifdef HS_BUILD_FOR_WIN32 -# ifndef CDECL -# define CDECL __cdecl -# endif -#else -# define CDECL -#endif - -/************************** Basic Types *****************************/ - -#if defined(_MSC_VER) && _MSC_VER < 1600 - typedef signed char int8_t; - typedef unsigned char uint8_t; - typedef signed short int int16_t; - typedef unsigned short int uint16_t; - typedef signed int int32_t; - typedef unsigned int uint32_t; - typedef signed long long int64_t; - typedef unsigned long long uint64_t; -#else - #include -#endif - -#define kPosInfinity16 (32767) -#define kNegInfinity16 (-32768) - -#define kPosInfinity32 (0x7fffffff) -#define kNegInfinity32 (0x80000000) - -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -#ifdef __cplusplus - -typedef int hsBool; - -#endif - -#ifndef nil -#define nil (0) -#endif - -typedef int32_t hsError; -typedef uint32_t hsGSeedValue; - -#define hsOK 0 -#define hsFail -1 -#define hsFailed(r) ((hsError)(r)=hsOK) - -#define hsLongAlign(n) (((n) + 3) & ~3L) - -#define hsMaximum(a, b) ((a) > (b) ? (a) : (b)) -#define hsMinimum(a, b) ((a) < (b) ? (a) : (b)) -#define hsABS(x) ((x) < 0 ? -(x) : (x)) -#define hsSGN(x) (((x) < 0) ? -1 : ( ((x) > 0) ? 1 : 0 )) - -#define hsBitTst2Bool(value, mask) (((value) & (mask)) != 0) - -#define hsFourByteTag(a, b, c, d) (((uint32_t)(a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d)) - - -/************************** Swap Macros *****************************/ - - inline uint16_t hsSwapEndian16(uint16_t value) - { - return (value >> 8) | (value << 8); - } - inline uint32_t hsSwapEndian32(uint32_t value) - { - return ((value) << 24) | - ((value & 0x0000ff00) << 8) | - ((value & 0x00ff0000) >> 8) | - ((value) >> 24); - } - inline uint64_t hsSwapEndian64(uint64_t value) - { - return ((value) << 56) | - ((value & 0x000000000000ff00) << 40) | - ((value & 0x0000000000ff0000) << 24) | - ((value & 0x00000000ff000000) << 8) | - ((value & 0x000000ff00000000) >> 8) | - ((value & 0x0000ff0000000000) >> 24) | - ((value & 0x00ff000000000000) >> 40) | - ((value) >> 56); - } - inline float hsSwapEndianFloat(float fvalue) - { - uint32_t value = *(uint32_t*)&fvalue; - value = hsSwapEndian32(value); - return *(float*)&value; - } - inline double hsSwapEndianDouble(double dvalue) - { - uint64_t value = *(uint64_t*)&dvalue; - value = hsSwapEndian64(value); - return *(double*)&value; - } - - #if LITTLE_ENDIAN - #define hsToBE16(n) hsSwapEndian16(n) - #define hsToBE32(n) hsSwapEndian32(n) - #define hsToBE64(n) hsSwapEndian64(n) - #define hsToBEFloat(n) hsSwapEndianFloat(n) - #define hsToBEDouble(n) hsSwapEndianDouble(n) - #define hsToLE16(n) (n) - #define hsToLE32(n) (n) - #define hsToLE64(n) (n) - #define hsToLEFloat(n) (n) - #define hsToLEDouble(n) (n) - #else - #define hsToBE16(n) (n) - #define hsToBE32(n) (n) - #define hsToBE64(n) (n) - #define hsToBEFloat(n) (n) - #define hsToBEDouble(n) (n) - #define hsToLE16(n) hsSwapEndian16(n) - #define hsToLE32(n) hsSwapEndian32(n) - #define hsToLE64(n) hsSwapEndian64(n) - #define hsToLEFloat(n) hsSwapEndianFloat(n) - #define hsToLEDouble(n) hsSwapEndianDouble(n) - #endif - - inline void hsSwap(int32_t& a, int32_t& b) - { - int32_t c = a; - a = b; - b = c; - } - - inline void hsSwap(uint32_t& a, uint32_t& b) - { - uint32_t c = a; - a = b; - b = c; - } - - inline void hsSwap(float& a, float& b) - { - float c = a; - a = b; - b = c; - } - -/************************** Color32 Type *****************************/ - -struct hsColor32 { - - uint8_t b, g, r, a; - - void SetARGB(uint8_t aa, uint8_t rr, uint8_t gg, uint8_t bb) - { - this->a = aa; this->r = rr; this->g = gg; this->b = bb; - } - - // Compatibility inlines, should be depricated - void Set(uint8_t rr, uint8_t gg, uint8_t bb) - { - this->r = rr; this->g = gg; this->b = bb; - } - void Set(uint8_t aa, uint8_t rr, uint8_t gg, uint8_t bb) - { - this->SetARGB(aa, rr, gg, bb); - } - - int operator==(const hsColor32& aa) const - { - return *(uint32_t*)&aa == *(uint32_t*)this; - } - int operator!=(const hsColor32& aa) { return !(aa == *this); } -}; -hsCTypeDefStruct(hsColor32) - -typedef hsColor32 hsRGBAColor32; - - -/**************************************************************************** -* -* NULL_STMT -* Declares a null statement -* -* Example: -* -* for (; *str && (*str != ch); ++str) -* NULL_STMT; -* -***/ - - -#ifdef _MSC_VER -# define NULL_STMT __noop -#else -# define NULL_STMT ((void)0) -#endif - - -/**************************************************************************** -* -* UNIQUE_SYMBOL -* Creates a symbol that is unique within a file -* -***/ - -#define UNIQUE_SYMBOL_EXPAND_1(prefix,line) UNIQUE_SYMBOL_##prefix##_##line -#define UNIQUE_SYMBOL_EXPAND_0(prefix,line) UNIQUE_SYMBOL_EXPAND_1(prefix,line) -#define UNIQUE_SYMBOL(prefix) UNIQUE_SYMBOL_EXPAND_0(prefix,__LINE__) - - - -/**************************************************************************** -* -* COMPILER_ASSERT -* Performs a "compile-time" assertion -* Can be used at function or file scope -* Upon assertion failure, creates a negative subscript error -* Use COMPILER_ASSERT_HEADER in header files to prevent symbol collision -* -***/ - -#define COMPILER_ASSERT(expr) static char UNIQUE_SYMBOL(a)[(expr) ? 1 : -1] -#define COMPILER_ASSERT_HEADER(prefix,expr) static char UNIQUE_SYMBOL(prefix)[(expr) ? 1 : -1] -#define COMPILER_ASSERT_SYMBOL(symbol,expr) static char symbol[(expr) ? 1 : -1] - - -/**************************************************************************** -* -* max/min inline functions -* -***/ - -#ifdef max -#undef max -#endif - -#ifdef min -#undef min -#endif - -//=========================================================================== -template -inline T max (const T & a, const T & b) { - return (a > b) ? a : b; -} - -//=========================================================================== -inline unsigned max (int a, unsigned b) { - return ((unsigned)a > b) ? a : b; -} - -//=========================================================================== -inline unsigned max (unsigned a, int b) { - return (a > (unsigned)b) ? a : b; -} - -//=========================================================================== -template -inline T min (const T & a, const T & b) { - return (a < b) ? a : b; -} - -//=========================================================================== -inline unsigned min (int a, unsigned b) { - return ((unsigned)a < b) ? a : b; -} - -//=========================================================================== -inline unsigned min (unsigned a, int b) { - return (a < (unsigned)b) ? a : b; -} - - -/**************************************************************************** -* -* MAX/MIN macros -* These are less safe than the inline function versions, since they -* evaluate parameters twice. However, they can be used to produce -* compile-time constants. -* -***/ - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - - -/**************************************************************************** -* -* SWAP -* Swaps the values of two variables -* -***/ - -//=========================================================================== -template -void SWAP (T & a, T & b) { - T temp = a; - a = b; - b = temp; -} - - -/**************************************************************************** -* -* AUTO_INIT_FUNC -* Declares a function that is automatically called at program startup time -* -* Example: -* -* AUTO_INIT_FUNC(BuildLookupTables) { -* ... -* } -* -***/ - -#define AUTO_INIT_FUNC(name) namespace { struct name { name (); } name##_instance; } name::name () - - -/**************************************************************************** -* -* arrsize -* arrsize returns the number of elements in an array variable -* -* Example: -* -* StrPrintf(buffer, arrsize(buffer), "%u", value); -* -***/ - -#define arrsize(a) (sizeof(a) / sizeof((a)[0])) - - -/**************************************************************************** -* -* IS_POW2 -* -***/ - -#define IS_POW2(val) (!((val) & ((val) - 1))) - -#ifdef PLASMA_EXTERNAL_RELEASE - - #define hsStatusMessage(x) NULL_STMT - #define hsStatusMessageF(x, ...) NULL_STMT - -#else /* Not external release */ - - void hsStatusMessage(const char message[]); - void hsStatusMessageF(const char * fmt, ...); - -#endif // PLASMA_EXTERNAL_RELEASE - diff --git a/Sources/Plasma/CoreLib/hsUtils.cpp b/Sources/Plasma/CoreLib/hsUtils.cpp deleted file mode 100644 index 45e5f0e0..00000000 --- a/Sources/Plasma/CoreLib/hsUtils.cpp +++ /dev/null @@ -1,591 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#include "HeadSpin.h" -#include "hsStlUtils.h" -#include "hsTemplates.h" -#include - - -char * hsFormatStr(const char * fmt, ...) -{ - va_list args; - va_start(args,fmt); - char * result = hsFormatStrV(fmt,args); - va_end(args); - return result; -} - -char * hsFormatStrV(const char * fmt, va_list args) -{ - std::string buf; - xtl::formatv(buf,fmt,args); - return hsStrcpy(buf.c_str()); -} - -static char hsStrBuf[100]; - -char *hsScalarToStr(float s) -{ - sprintf(hsStrBuf, "%f", s); - return hsStrBuf; -} - -class hsMinimizeClientGuard -{ -#ifdef CLIENT - hsWindowHndl fWnd; - -public: - hsMinimizeClientGuard() - { -#ifdef HS_BUILD_FOR_WIN32 - fWnd = GetActiveWindow(); - // If the application's topmost window is fullscreen, minimize it before displaying an error - if ((GetWindowLong(fWnd, GWL_STYLE) & WS_POPUP) != 0) - ShowWindow(fWnd, SW_MINIMIZE); -#endif // HS_BUILD_FOR_WIN32 - } - - ~hsMinimizeClientGuard() - { -#ifdef HS_BUILD_FOR_WIN32 - ShowWindow(fWnd, SW_RESTORE); -#endif // HS_BUILD_FOR_WIN32 - } -#endif // CLIENT -}; - -bool hsMessageBox_SuppressPrompts = false; - -int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon) -{ - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - -#if HS_BUILD_FOR_WIN32 - uint32_t flags = 0; - - if (kind == hsMessageBoxNormal) - flags |= MB_OK; - else if (kind == hsMessageBoxAbortRetyIgnore) - flags |= MB_ABORTRETRYIGNORE; - else if (kind == hsMessageBoxOkCancel) - flags |= MB_OKCANCEL; - else if (kind == hsMessageBoxRetryCancel) - flags |= MB_RETRYCANCEL; - else if (kind == hsMessageBoxYesNo) - flags |= MB_YESNO; - else if (kind == hsMessageBoxYesNoCancel) - flags |= MB_YESNOCANCEL; - else - flags |= MB_OK; - - if (icon == hsMessageBoxIconError) - flags |= MB_ICONERROR; - else if (icon == hsMessageBoxIconQuestion) - flags |= MB_ICONQUESTION; - else if (icon == hsMessageBoxIconExclamation) - flags |= MB_ICONEXCLAMATION; - else if (icon == hsMessageBoxIconAsterisk) - flags |= MB_ICONASTERISK; - else - flags |= MB_ICONERROR; - - hsMinimizeClientGuard guard; - int ans = MessageBox(owner, message, caption, flags); - - switch (ans) - { - case IDOK: return hsMBoxOk; - case IDCANCEL: return hsMBoxCancel; - case IDABORT: return hsMBoxAbort; - case IDRETRY: return hsMBoxRetry; - case IDIGNORE: return hsMBoxIgnore; - case IDYES: return hsMBoxYes; - case IDNO: return hsMBoxNo; - default: return hsMBoxCancel; - } - -#endif -} - -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon) -{ - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - -#if HS_BUILD_FOR_WIN32 - uint32_t flags = 0; - - if (kind == hsMessageBoxNormal) - flags |= MB_OK; - else if (kind == hsMessageBoxAbortRetyIgnore) - flags |= MB_ABORTRETRYIGNORE; - else if (kind == hsMessageBoxOkCancel) - flags |= MB_OKCANCEL; - else if (kind == hsMessageBoxRetryCancel) - flags |= MB_RETRYCANCEL; - else if (kind == hsMessageBoxYesNo) - flags |= MB_YESNO; - else if (kind == hsMessageBoxYesNoCancel) - flags |= MB_YESNOCANCEL; - else - flags |= MB_OK; - - if (icon == hsMessageBoxIconError) - flags |= MB_ICONERROR; - else if (icon == hsMessageBoxIconQuestion) - flags |= MB_ICONQUESTION; - else if (icon == hsMessageBoxIconExclamation) - flags |= MB_ICONEXCLAMATION; - else if (icon == hsMessageBoxIconAsterisk) - flags |= MB_ICONASTERISK; - else - flags |= MB_ICONERROR; - - hsMinimizeClientGuard guard; - int ans = MessageBoxW(owner, message, caption, flags); - - switch (ans) - { - case IDOK: return hsMBoxOk; - case IDCANCEL: return hsMBoxCancel; - case IDABORT: return hsMBoxAbort; - case IDRETRY: return hsMBoxRetry; - case IDIGNORE: return hsMBoxIgnore; - case IDYES: return hsMBoxYes; - case IDNO: return hsMBoxNo; - default: return hsMBoxCancel; - } - -#endif -} - -int hsMessageBox(const char message[], const char caption[], int kind, int icon) -{ - return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); -} - -int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon) -{ - return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); -} - -inline hsBool hsCompare(float a, float b, float delta) -{ - return (fabs(a - b) < delta); -} - - -/* Generic psuedo RNG used in ANSI C. */ -static unsigned long SEED = 1; -int hsRand() -{ - register int temp; - SEED = SEED * 1103515245 + 12345; - temp = (int)((SEED/65536)&32767); - return (temp); -} - -void hsRandSeed(int seed) -{ - SEED = seed; -} -/**************************************/ -int hsStrlen(const char src[]) -{ - if (src==nil) - return 0; - - int i = 0; - while (src[i]) - i++; - return i; -} - -char* hsStrcpy(char dst[], const char src[]) -{ - if (src) - { - if (dst == nil) - { - int count = hsStrlen(src); - dst = (char *)malloc(count + 1); - memcpy(dst, src, count); - dst[count] = 0; - return dst; - } - - int32_t i; - for (i = 0; src[i] != 0; i++) - dst[i] = src[i]; - dst[i] = 0; - } - - return dst; -} - -bool hsStrEQ(const char s1[], const char s2[]) -{ - if (s1 && s2) - { - while (*s1) - if(*s1++ != *s2++) - return false; - return *s2 == 0; - } - - return (!s1 && !s2); -} - -bool hsStrCaseEQ(const char* s1, const char* s2) -{ - if (s1 && s2) - { - while (*s1) - if(tolower(*s1++) != tolower(*s2++)) - return false; - return *s2 == 0; - } - - return (!s1 && !s2); -} - -void hsStrcat(char dst[], const char src[]) -{ - if (src && dst) - { - dst += hsStrlen(dst); - while(*src) - *dst++ = *src++; - *dst = 0; - } -} - -void hsStrLower(char *s) -{ - if (s) - { - int i; - for (i = 0; i < hsStrlen(s); i++) - s[i] = tolower(s[i]); - } -} - -char* hsP2CString(const uint8_t pstring[], char cstring[]) -{ - char* cstr = cstring; - const uint8_t* stop = &pstring[1] + pstring[0]; - - pstring += 1; // skip length byte - while (pstring < stop) - *cstr++ = *pstring++; - *cstr = 0; - return cstring; -} - -uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]) -{ - int i; - - for (i = 1; *cstring; i++) - pstring[i] = *cstring++; - pstring[0] = i - 1; - return pstring; -} - -//// IStringToWString ///////////////////////////////////////////////////////// -// Converts a char * string to a wchar_t * string - -wchar_t *hsStringToWString( const char *str ) -{ - // convert the char string to a wchar_t string - int len = strlen(str); - wchar_t *wideString = new wchar_t[len+1]; - for (int i=0; i versionStrs; - OSVERSIONINFOEX osvi; - BOOL bOsVersionInfoEx; - - // Try calling GetVersionEx using the OSVERSIONINFOEX structure. - // - // If that fails, try using the OSVERSIONINFO structure. - - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - - if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) - { - // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. - - osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) - return FALSE; - } - - switch (osvi.dwPlatformId) - { - case VER_PLATFORM_WIN32_NT: - - // Test for the product. - - if ( osvi.dwMajorVersion <= 4 ) - versionStrs.Append(hsStrcpy("Microsoft Windows NT ")); - - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) - versionStrs.Append(hsStrcpy ("Microsoft Windows 2000 ")); - - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) - versionStrs.Append(hsStrcpy ("Microsoft Windows XP ")); - - // Test for product type. - - if( bOsVersionInfoEx ) - { - if ( osvi.wProductType == VER_NT_WORKSTATION ) - { - if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) - versionStrs.Append(hsStrcpy ( "Personal " )); - else - versionStrs.Append(hsStrcpy ( "Professional " )); - } - - else if ( osvi.wProductType == VER_NT_SERVER ) - { - if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) - versionStrs.Append(hsStrcpy ( "DataCenter Server " )); - else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) - versionStrs.Append(hsStrcpy ( "Advanced Server " )); - else - versionStrs.Append(hsStrcpy ( "Server " )); - } - } - else - { - HKEY hKey; - char szProductType[80]; - DWORD dwBufLen; - - RegOpenKeyEx( HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", - 0, KEY_QUERY_VALUE, &hKey ); - RegQueryValueEx( hKey, "ProductType", NULL, NULL, - (LPBYTE) szProductType, &dwBufLen); - RegCloseKey( hKey ); - if ( lstrcmpi( "WINNT", szProductType) == 0 ) - versionStrs.Append(hsStrcpy( "Professional " )); - if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) - versionStrs.Append(hsStrcpy( "Server " )); - if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) - versionStrs.Append(hsStrcpy( "Advanced Server " )); - } - - // Display version, service pack (if any), and build number. - - if ( osvi.dwMajorVersion <= 4 ) - { - versionStrs.Append(hsStrcpy (xtl::format("version %d.%d %s (Build %d)\n", - osvi.dwMajorVersion, - osvi.dwMinorVersion, - osvi.szCSDVersion, - osvi.dwBuildNumber & 0xFFFF).c_str())); - } - else - { - versionStrs.Append(hsStrcpy (xtl::format("%s (Build %d)\n", - osvi.szCSDVersion, - osvi.dwBuildNumber & 0xFFFF).c_str())); - } - break; - - case VER_PLATFORM_WIN32_WINDOWS: - - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) - { - versionStrs.Append(hsStrcpy ("Microsoft Windows 95 ")); - if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) - versionStrs.Append(hsStrcpy("OSR2 " )); - } - - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) - { - versionStrs.Append(hsStrcpy ("Microsoft Windows 98 ")); - if ( osvi.szCSDVersion[1] == 'A' ) - versionStrs.Append(hsStrcpy("SE " )); - } - - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) - { - versionStrs.Append(hsStrcpy ("Microsoft Windows Me ")); - } - break; - - case VER_PLATFORM_WIN32s: - - versionStrs.Append(hsStrcpy ("Microsoft Win32s ")); - break; - } - - versionStrs.Append(nil); // terminator - - return versionStrs.DetachArray(); -#else - return nil; -#endif -} diff --git a/Sources/Plasma/CoreLib/hsUtils.h b/Sources/Plasma/CoreLib/hsUtils.h deleted file mode 100644 index 8bf36fef..00000000 --- a/Sources/Plasma/CoreLib/hsUtils.h +++ /dev/null @@ -1,285 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifdef _HSUTILS_H -# error "Do not include hsUtils.h directly--use HeadSpin.h" -#endif // _HSUTILS_H -#define _HSUTILS_H - -#include "HeadSpin.h" -#include -#include -#include - -int hsStrlen(const char src[]); -char* hsStrcpy(char dstOrNil[], const char src[]); -void hsStrcat(char dst[], const char src[]); -bool hsStrEQ(const char s1[], const char s2[]); -bool hsStrCaseEQ(const char* s1, const char* s2); -char* hsScalarToStr(float); -int hsRemove(const char* filename); -void hsCPathToMacPath(char* dst, char* fname); -void hsStrLower(char *s); -char * hsFormatStr(const char * fmt, ...); // You are responsible for returned memory. -char * hsFormatStrV(const char * fmt, va_list args); // You are responsible for returned memory. - -// Use "correct" stricmp based on the selected compiler / library -#if HS_BUILD_FOR_WIN32 -# define stricmp _stricmp -# define strnicmp _strnicmp -# define wcsicmp _wcsicmp -# define wcsnicmp _wcsnicmp -# define strlwr _strlwr -#else -# define stricmp strcasecmp -# define strnicmp strncasecmp -# define wcsicmp wcscasecmp -# define wcsnicmp wcsncasecmp -# define strlwr hsStrLower -#endif - - -// A pstring has a length uint8_t at the beginning, and no trailing 0 -char* hsP2CString(const uint8_t pstring[], char cstring[]); -uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]); - -inline char* hsStrcpy(const char src[]) -{ - return hsStrcpy(nil, src); -} - -inline char *hsStrncpy(char *strDest, const char *strSource, size_t count) -{ - char *temp = strncpy(strDest, strSource, count-1); - strDest[count-1] = 0; - return temp; -} - -wchar_t *hsStringToWString( const char *str ); -char *hsWStringToString( const wchar_t *str ); - -enum { // Kind of MessageBox...passed to hsMessageBox - hsMessageBoxAbortRetyIgnore, - hsMessageBoxNormal, // Just Ok - hsMessageBoxOkCancel, - hsMessageBoxRetryCancel, - hsMessageBoxYesNo, - hsMessageBoxYesNoCancel, -}; - -enum { - hsMessageBoxIconError, - hsMessageBoxIconQuestion, - hsMessageBoxIconExclamation, - hsMessageBoxIconAsterisk, -}; - -enum { // RETURN VALUES FROM hsMessageBox - hsMBoxOk = 1, // OK button was selected. - hsMBoxCancel, // Cancel button was selected. - hsMBoxAbort, // Abort button was selected. - hsMBoxRetry, // Retry button was selected. - hsMBoxIgnore, // Ignore button was selected. - hsMBoxYes, // Yes button was selected. - hsMBoxNo // No button was selected. -}; - -extern bool hsMessageBox_SuppressPrompts; -int hsMessageBox(const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); - -inline hsBool hsCompare(float a, float b, float delta=0.0001); - -// flag testing / clearing -#define hsCheckBits(f,c) ((f & c)==c) -#define hsTestBits(f,b) ( (f) & (b) ) -#define hsSetBits(f,b) ( (f) |= (b) ) -#define hsClearBits(f,b) ( (f) &= ~(b) ) -#define hsToggleBits(f,b) ( (f) ^= (b) ) -#define hsChangeBits(f,b,t) ( t ? hsSetBits(f,b) : hsClearBits(f,b) ) - - -#if HS_BUILD_FOR_WIN32 -// This is for Windows -# define hsVsnprintf _vsnprintf -# define hsVsnwprintf _vsnwprintf -# define hsSnprintf _snprintf -# define hsSnwprintf _snwprintf - -# define snprintf _snprintf -# define snwprintf _snwprintf -# define swprintf _snwprintf - -# ifndef fileno -# define fileno(__F) _fileno(__F) -# endif - -# define hsWFopen(name, mode) _wfopen(name, mode) -#else -// This is for Unix, Linux, OSX, etc. -# define hsVsnprintf vsnprintf -# define hsVsnwprintf vswprintf -# define hsSnprintf snprintf -# define hsSnwprintf swprintf - -# define hsWFopen(name, mode) fopen(hsWStringToString(name), hsWStringToString(mode)) - -# include -# define MAX_PATH PATH_MAX -#endif - -// Useful floating point utilities -inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); } -inline float hsRadiansToDegrees(float rad) { return float(rad * (180 / M_PI)); } -#define hsInvert(a) (1 / (a)) - -#include -#define NEWZERO(t) new(calloc(sizeof(t), 1)) t - -#ifdef _MSC_VER -# define ALIGN(n) __declspec(align(n)) -#else -# define ALIGN(n) __atribute__(aligned(n)) -#endif - -///////////////////////////// -// Physical memory functions -///////////////////////////// -enum MemSpec -{ - kBlows = 0, // Less than 128 - kAcceptable, // Less than 256 - kOptimal // 256 or greater -}; - -uint32_t hsPhysicalMemory(); -MemSpec hsMemorySpec(); - -inline int hsRandMax() { return 32767; } -inline float hsRandNorm() { return 1.f / 32767.f; } // multiply by hsRand to get randoms ranged [0..1] -int hsRand(void); -void hsRandSeed(int seed); - -#define hsFopen(name, mode) fopen(name, mode) - -char** DisplaySystemVersion(); - -/************************ Debug/Error Macros **************************/ - -typedef void (*hsDebugMessageProc)(const char message[]); -extern hsDebugMessageProc gHSDebugProc; -#define HSDebugProc(m) { if (gHSDebugProc) gHSDebugProc(m); } -hsDebugMessageProc hsSetDebugMessageProc(hsDebugMessageProc newProc); - -extern hsDebugMessageProc gHSStatusProc; -hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); - -void ErrorEnableGui (bool enabled); -void ErrorAssert (int line, const char file[], const char fmt[], ...); - -bool DebugIsDebuggerPresent (); -void DebugBreakIfDebuggerPresent (); -void DebugMsg(const char fmt[], ...); - -#ifdef HS_DEBUGGING - - void hsDebugMessage(const char message[], long refcon); - #define hsDebugCode(code) code - #define hsIfDebugMessage(expr, msg, ref) (void)( ((expr) != 0) || (hsDebugMessage(msg, ref), 0) ) - #define hsAssert(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) ) - #define ASSERT(expr) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, #expr), 0) ) - #define ASSERTMSG(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) ) - #define FATAL(msg) ErrorAssert(__LINE__, __FILE__, msg) - #define DEBUG_MSG DebugMsg - #define DEBUG_BREAK_IF_DEBUGGER_PRESENT DebugBreakIfDebuggerPresent - -#else /* Not debugging */ - - #define hsDebugMessage(message, refcon) NULL_STMT - #define hsDebugCode(code) /* empty */ - #define hsIfDebugMessage(expr, msg, ref) NULL_STMT - #define hsAssert(expr, msg) NULL_STMT - #define ASSERT(expr) NULL_STMT - #define ASSERTMSG(expr, msg) NULL_STMT - #define FATAL(msg) NULL_STMT - #define DEBUG_MSG (void) - #define DEBUG_MSGV NULL_STMT - #define DEBUG_BREAK_IF_DEBUGGER_PRESENT NULL_STMT - -#endif // HS_DEBUGGING - - -#ifdef _MSC_VER -#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); __assume(0); break; -#else -#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; -#endif - -/***************************************************************************** -* -* Atomic Operations -* -***/ - -// *value += increment; return original value of *value; thread safe -inline long AtomicAdd(long* value, long increment) { -#ifdef HS_BUILD_FOR_WIN32 - return InterlockedExchangeAdd(value, increment); -#elif HS_BUILD_FOR_UNIX - return __sync_fetch_and_add(value, increment); -#else -#error "No Atomic Set support on this architecture" -#endif -} - -// *value = value; return original value of *value; thread safe -inline long AtomicSet(long* value, long set) { -#ifdef HS_BUILD_FOR_WIN32 - return InterlockedExchange(value, set); -#elif HS_BUILD_FOR_UNIX - return __sync_lock_test_and_set(value, set); -#else -#error "No Atomic Set support on this architecture" -#endif -} diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Pch.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Pch.h index 546aca50..7799fb55 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Pch.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Pch.h @@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETPROTOCOL_PCH_H - +#include "HeadSpin.h" #include "pnUtils/pnUtils.h" #include "pnNetBase/pnNetBase.h" #include "pnAsyncCore/pnAsyncCore.h"