diff --git a/Dependencies/Utility/Utility/compat.h b/Dependencies/Utility/Utility/compat.h new file mode 100644 index 0000000000..57ac46b8c5 --- /dev/null +++ b/Dependencies/Utility/Utility/compat.h @@ -0,0 +1,59 @@ +// TheSuperHackers +// This file contains macros to help compiling on non-windows platforms. + +#pragma once + +#ifndef _WIN32 +// For size_t +#include +// For isdigit +#include + +// __forceinline +#ifndef __forceinline +#if defined __has_attribute && __has_attribute(always_inline) +#define __forceinline __attribute__((always_inline)) inline +#else +#define __forceinline inline +#endif +#endif + +// _cdecl / __cdecl +#ifndef _cdecl +#define _cdecl +#endif +#ifndef __cdecl +#define __cdecl +#endif + +// OutputDebugString +#ifndef OutputDebugString +#define OutputDebugString(str) printf("%s\n", str) +#endif + +// _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, _MAX_EXT, _MAX_PATH +#ifndef _MAX_DRIVE +#define _MAX_DRIVE 255 +#endif +#ifndef _MAX_DIR +#define _MAX_DIR 255 +#define _MAX_DIR 255 +#endif +#ifndef _MAX_FNAME +#define _MAX_FNAME 255 +#endif +#ifndef _MAX_EXT +#define _MAX_EXT 255 +#endif +#ifndef _MAX_PATH +#define _MAX_PATH 255 +#endif + +#include "mem_compat.h" +#include "string_compat.h" +#include "tchar_compat.h" +#include "wchar_compat.h" +#include "time_compat.h" +#include "thread_compat.h" + +#endif \ No newline at end of file diff --git a/Dependencies/Utility/Utility/intrin_compat.h b/Dependencies/Utility/Utility/intrin_compat.h new file mode 100644 index 0000000000..50bdda1171 --- /dev/null +++ b/Dependencies/Utility/Utility/intrin_compat.h @@ -0,0 +1,72 @@ +#pragma once + +// VC6 macros +#if defined(_MSC_VER) && _MSC_VER < 1300 +#define __debugbreak() __asm { int 3 } +#endif + +// Non-VC6 macros +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#include + +#if !defined(_lrotl) && !defined(_WIN32) +static inline uint32_t _lrotl(uint32_t value, int shift) +{ +#if defined(__has_builtin) && __has_builtin(__builtin_rotateleft32) + return __builtin_rotateleft32(value, shift); +#else + shift &= 31; + return ((value << shift) | (value >> (32 - shift))); +#endif +} +#endif + +#ifndef _rdtsc +#ifdef _WIN32 +#include +#pragma intrinsic(__rdtsc) +#endif + +static inline uint64_t _rdtsc() +{ +#ifdef _WIN32 + return __rdtsc(); +#elif defined(__has_builtin) && __has_builtin(__builtin_readcyclecounter) + return __builtin_readcyclecounter(); +#elif defined(__has_builtin) && __has_builtin(__builtin_ia32_rdtsc) + return __builtin_ia32_rdtsc(); +#else +#error "No implementation for _rdtsc" +#endif +} +#endif + +#ifdef _MSC_VER +#include +#pragma intrinsic(_ReturnAddress) +#elif defined(__has_builtin) + #if __has_builtin(__builtin_return_address) + static inline uintptr_t _ReturnAddress() + { + return reinterpret_cast(__builtin_return_address(0)); + } + #else + #error "No implementation for _ReturnAddress" + #endif +#else +#error "No implementation for _ReturnAddress" +#endif + +#if defined(__has_builtin) + #if __has_builtin(__builtin_debugtrap) + #define __debugbreak() __builtin_debugtrap() + #elif __has_builtin(__builtin_trap) + #define __debugbreak() __builtin_trap() + #else + #error "No implementation for __debugbreak" + #endif +#elif !defined(_MSC_VER) +#error "No implementation for __debugbreak" +#endif + +#endif // defined(_MSC_VER) && _MSC_VER < 1300 diff --git a/Dependencies/Utility/Utility/mem_compat.h b/Dependencies/Utility/Utility/mem_compat.h new file mode 100644 index 0000000000..b624df0ad3 --- /dev/null +++ b/Dependencies/Utility/Utility/mem_compat.h @@ -0,0 +1,4 @@ +#pragma once + +#include +#define _alloca alloca \ No newline at end of file diff --git a/Dependencies/Utility/Utility/string_compat.h b/Dependencies/Utility/Utility/string_compat.h new file mode 100644 index 0000000000..54869b0e83 --- /dev/null +++ b/Dependencies/Utility/Utility/string_compat.h @@ -0,0 +1,19 @@ +#pragma once + +typedef const char* LPCSTR; +typedef char* LPSTR; + +// String functions +inline char *_strlwr(char *str) { + for (int i = 0; str[i] != '\0'; i++) { + str[i] = tolower(str[i]); + } + return str; +} + +#define strlwr _strlwr +#define _vsnprintf vsnprintf +#define _snprintf snprintf +#define stricmp strcasecmp +#define strnicmp strncasecmp +#define strcmpi strcasecmp \ No newline at end of file diff --git a/Dependencies/Utility/Utility/tchar_compat.h b/Dependencies/Utility/Utility/tchar_compat.h new file mode 100644 index 0000000000..c36808c374 --- /dev/null +++ b/Dependencies/Utility/Utility/tchar_compat.h @@ -0,0 +1,11 @@ +#pragma once + +// TCHAR +typedef char TCHAR; +typedef const TCHAR* LPCTSTR; +typedef TCHAR* LPTSTR; +#define _tcslen strlen +#define _tcscmp strcmp +#define _tcsicmp strcasecmp +#define _tcsclen strlen +#define _tcscpy strcpy diff --git a/Dependencies/Utility/Utility/thread_compat.h b/Dependencies/Utility/Utility/thread_compat.h new file mode 100644 index 0000000000..17d193b283 --- /dev/null +++ b/Dependencies/Utility/Utility/thread_compat.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +inline int GetCurrentThreadId() +{ + return pthread_self(); +} + +inline void Sleep(int ms) +{ + usleep(ms * 1000); +} \ No newline at end of file diff --git a/Dependencies/Utility/Utility/time_compat.h b/Dependencies/Utility/Utility/time_compat.h new file mode 100644 index 0000000000..1d2bf7033e --- /dev/null +++ b/Dependencies/Utility/Utility/time_compat.h @@ -0,0 +1,21 @@ +#pragma once +#include + +#define TIMERR_NOERROR 0 +typedef int MMRESULT; +static inline MMRESULT timeBeginPeriod(int) { return TIMERR_NOERROR; } +static inline MMRESULT timeEndPeriod(int) { return TIMERR_NOERROR; } + +inline unsigned int timeGetTime() +{ + struct timespec ts; + clock_gettime(CLOCK_BOOTTIME, &ts); + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} +inline unsigned int GetTickCount() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + // Return ms since boot + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} \ No newline at end of file diff --git a/Dependencies/Utility/Utility/wchar_compat.h b/Dependencies/Utility/Utility/wchar_compat.h new file mode 100644 index 0000000000..83bc259c4e --- /dev/null +++ b/Dependencies/Utility/Utility/wchar_compat.h @@ -0,0 +1,15 @@ +#pragma once + +// WCHAR +typedef wchar_t WCHAR; +typedef const WCHAR* LPCWSTR; +typedef WCHAR* LPWSTR; + +#define _wcsicmp wcscasecmp +#define wcsicmp wcscasecmp +#define _vsnwprintf vswprintf + +// MultiByteToWideChar +#define CP_ACP 0 +#define MultiByteToWideChar(cp, flags, mbstr, cb, wcstr, cch) mbstowcs(wcstr, mbstr, cch) +#define WideCharToMultiByte(cp, flags, wcstr, cch, mbstr, cb, defchar, used) wcstombs(mbstr, wcstr, cb) \ No newline at end of file diff --git a/Generals/Code/CMakeLists.txt b/Generals/Code/CMakeLists.txt index 480a3419a8..5d2d5af4cd 100644 --- a/Generals/Code/CMakeLists.txt +++ b/Generals/Code/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(gi_libraries_source_wwvegas_wwlib INTERFACE) add_library(gi_libraries_source_wwvegas_wwmath INTERFACE) add_library(gi_libraries_source_wwvegas_wwsaveload INTERFACE) add_library(gi_main INTERFACE) +add_library(gi_utility INTERFACE) target_include_directories(gi_gameengine INTERFACE "GameEngine") target_include_directories(gi_gameengine_include INTERFACE "GameEngine/Include") @@ -24,6 +25,10 @@ target_include_directories(gi_libraries_source_wwvegas_wwlib INTERFACE "Librarie target_include_directories(gi_libraries_source_wwvegas_wwmath INTERFACE "Libraries/Source/WWVegas/WWMath") target_include_directories(gi_libraries_source_wwvegas_wwsaveload INTERFACE "Libraries/Source/WWVegas/WWSaveLoad") target_include_directories(gi_main INTERFACE "Main") +target_link_libraries(gi_utility INTERFACE + gi_libraries_include + gz_utility +) # Contains internal libraries add_subdirectory(Libraries) diff --git a/Generals/Code/GameEngine/CMakeLists.txt b/Generals/Code/GameEngine/CMakeLists.txt index 0488662718..436b305a34 100644 --- a/Generals/Code/GameEngine/CMakeLists.txt +++ b/Generals/Code/GameEngine/CMakeLists.txt @@ -1069,7 +1069,7 @@ target_include_directories(g_gameengine PRIVATE ) target_link_libraries(g_gameengine PRIVATE - gi_libraries_include + gi_utility gi_libraries_source ) diff --git a/Generals/Code/GameEngineDevice/CMakeLists.txt b/Generals/Code/GameEngineDevice/CMakeLists.txt index 6727e578d9..92a8133bbd 100644 --- a/Generals/Code/GameEngineDevice/CMakeLists.txt +++ b/Generals/Code/GameEngineDevice/CMakeLists.txt @@ -192,7 +192,7 @@ target_include_directories(g_gameenginedevice PUBLIC ) target_link_libraries(g_gameenginedevice PRIVATE - gi_libraries_include + gi_utility gi_libraries_source gi_main ) diff --git a/Generals/Code/Libraries/Include/Lib/BaseType.h b/Generals/Code/Libraries/Include/Lib/BaseType.h index 054e0a4b81..c5b2c44c95 100644 --- a/Generals/Code/Libraries/Include/Lib/BaseType.h +++ b/Generals/Code/Libraries/Include/Lib/BaseType.h @@ -34,6 +34,8 @@ #include #include +// SuperHackers: utility macros for cross-platform compatibility +#include /* ** Turn off some unneeded warnings. @@ -126,8 +128,13 @@ typedef char Byte; // 1 byte USED TO BE "SignedByte" typedef char Char; // 1 byte of text typedef bool Bool; // // note, the types below should use "long long", but MSVC doesn't support it yet +#ifdef _MSC_VER typedef __int64 Int64; // 8 bytes typedef unsigned __int64 UnsignedInt64; // 8 bytes +#else +typedef long long Int64; // 8 bytes +typedef unsigned long long UnsignedInt64; // 8 bytes +#endif #include "Lib/trig.h" @@ -179,10 +186,15 @@ __forceinline long fast_float2long_round(float f) { long i; +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { fld [f] fistp [i] } +#else + // TheSuperHackers @fix Use simple C code instead of inline assembly + i = lroundf(f); +#endif return i; } diff --git a/Generals/Code/Libraries/Source/Compression/CMakeLists.txt b/Generals/Code/Libraries/Source/Compression/CMakeLists.txt index 3c0ad78c75..2f8946bb10 100644 --- a/Generals/Code/Libraries/Source/Compression/CMakeLists.txt +++ b/Generals/Code/Libraries/Source/Compression/CMakeLists.txt @@ -29,7 +29,7 @@ target_include_directories(g_compression INTERFACE ) target_link_libraries(g_compression PRIVATE - gi_libraries_include + gi_utility gz_config ) diff --git a/Generals/Code/Libraries/Source/Compression/EAC/huffencode.cpp b/Generals/Code/Libraries/Source/Compression/EAC/huffencode.cpp index a490c1434b..d14d5898fc 100644 --- a/Generals/Code/Libraries/Source/Compression/EAC/huffencode.cpp +++ b/Generals/Code/Libraries/Source/Compression/EAC/huffencode.cpp @@ -1050,8 +1050,8 @@ static void HUFF_pack(struct HuffEncodeContext *EC, if (!i3) HUFF_writecode(EC,dest,i); - if (((int) bptr1- (int) EC->buffer) >= (int)(EC->plen+curpc)) - curpc = (int) bptr1 - (int) EC->buffer - EC->plen; + if (((long) bptr1- (long) EC->buffer) >= (long)(EC->plen+curpc)) + curpc = (long) bptr1 - (long) EC->buffer - EC->plen; } /* write EOF ([clue] 0gn [10]) */ diff --git a/Generals/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp b/Generals/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp index 120cad13f0..4faa0d1873 100644 --- a/Generals/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp +++ b/Generals/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp @@ -47,7 +47,7 @@ Bool DecompressFile (char *infile, char *outfile) char *outBlock = NULL; LZHL_DHANDLE decompress; Int ok = 0; - UnsignedInt srcSz, dstSz; + size_t srcSz, dstSz; // Parameter checking @@ -224,7 +224,7 @@ Bool DecompressMemory (void *inBufferVoid, Int inSize, void *outBufferVoid, Int UnsignedInt rawSize = 0, compressedSize = 0; LZHL_DHANDLE decompress; Int ok = 0; - UnsignedInt srcSz, dstSz; + size_t srcSz, dstSz; // Parameter checking diff --git a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp index 54a84b84a4..7791c50a52 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp @@ -43,7 +43,11 @@ #include "wwdebug.h" +#ifdef _WIN32 #include +#else +#include +#endif //#include "win.h" can use this if allowed to see wwlib #include #include @@ -77,7 +81,11 @@ void Convert_System_Error_To_String(int id, char* buffer, int buf_len) int Get_Last_System_Error() { +#ifndef _UNIX return GetLastError(); +#else + return errno; +#endif } /*********************************************************************************************** diff --git a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp index cb049c6c5a..8e9f8e362e 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp @@ -38,11 +38,13 @@ * WWMemoryLogClass::Release_Memory -- frees memory * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - +#include "always.h" #include "wwmemlog.h" #include "wwdebug.h" #include "Vector.H" +#ifdef _WIN32 #include +#endif #if (STEVES_NEW_CATCHER || PARAM_EDITING_ON) #define DISABLE_MEMLOG 1 @@ -214,15 +216,20 @@ static bool _MemLogAllocated = false; */ void * Get_Mem_Log_Mutex(void) { +#ifdef _WIN32 if (_MemLogMutex == NULL) { _MemLogMutex=CreateMutex(NULL,false,NULL); WWASSERT(_MemLogMutex); } return _MemLogMutex; +#else + return NULL; +#endif } void Lock_Mem_Log_Mutex(void) { +#ifdef _WIN32 void * mutex = Get_Mem_Log_Mutex(); #ifdef DEBUG_CRASHING int res = @@ -230,10 +237,12 @@ void Lock_Mem_Log_Mutex(void) WaitForSingleObject(mutex,INFINITE); WWASSERT(res==WAIT_OBJECT_0); _MemLogLockCounter++; +#endif } void Unlock_Mem_Log_Mutex(void) { +#ifdef _WIN32 void * mutex = Get_Mem_Log_Mutex(); _MemLogLockCounter--; #ifdef DEBUG_CRASHING @@ -241,6 +250,7 @@ void Unlock_Mem_Log_Mutex(void) #endif ReleaseMutex(mutex); WWASSERT(res); +#endif } class MemLogMutexLockClass diff --git a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp index f6bf18bbcb..27c77005c6 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp @@ -53,8 +53,9 @@ #include "always.h" #include "wwprofile.h" #include "wwdebug.h" +#ifdef _WIN32 #include - +#endif /*********************************************************************************************** diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt b/Generals/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt index 9bd64d763e..227a090e29 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt @@ -1,7 +1,6 @@ # Set source files set(WWLIB_SRC _convert.cpp - _mono.cpp b64pipe.cpp b64straw.cpp base64.cpp @@ -15,8 +14,6 @@ set(WWLIB_SRC crc.cpp cstraw.cpp data.cpp - ddraw.cpp - dsurface.cpp ffactory.cpp gcd_lcm.cpp hash.cpp @@ -24,14 +21,10 @@ set(WWLIB_SRC ini.cpp int.cpp jshell.cpp - keyboard.cpp LaunchWeb.cpp lcw.cpp load.cpp - mono.cpp mpmath.cpp - mpu.cpp - msgloop.cpp multilist.cpp mutex.cpp nstrdup.cpp @@ -43,11 +36,9 @@ set(WWLIB_SRC random.cpp rawfile.cpp rc4.cpp - rcfile.cpp readline.cpp realcrc.cpp refcount.cpp - registry.cpp rgb.cpp rle.cpp rndstrng.cpp @@ -66,15 +57,12 @@ set(WWLIB_SRC trim.cpp vector.cpp widestring.cpp - win.cpp - WWCOMUtil.cpp wwfile.cpp wwfont.cpp wwstring.cpp xpipe.cpp xstraw.cpp xsurface.cpp - _mono.h always.h argv.h b64pipe.h @@ -98,7 +86,6 @@ set(WWLIB_SRC CRC.H cstraw.h data.h - dsurface.h ffactory.h FONT.H gcd_lcm.h @@ -112,17 +99,13 @@ set(WWLIB_SRC inisup.h INT.H iostruct.h - keyboard.h LaunchWeb.h LCW.H LISTNODE.H mempool.h mixfile.h - MONO.H MONODRVR.H MPMATH.H - MPU.H - msgloop.h multilist.h mutex.h Notify.h @@ -137,12 +120,10 @@ set(WWLIB_SRC RANDOM.H RAWFILE.H rc4.h - rcfile.h readline.h realcrc.h ref_ptr.h refcount.h - registry.h RGB.H RLE.H RNDSTRAW.H @@ -178,8 +159,6 @@ set(WWLIB_SRC visualc.h WATCOM.H widestring.h - win.h - WWCOMUtil.h WWFILE.H wwstring.h xmouse.h @@ -188,6 +167,31 @@ set(WWLIB_SRC xsurface.h ) +if(WIN32) + list(APPEND WWLIB_SRC + ddraw.cpp + dsurface.cpp + dsurface.h + keyboard.cpp + keyboard.h + mono.cpp + _mono.cpp + _mono.h + mpu.cpp + MPU.H + msgloop.cpp + msgloop.h + rcfile.cpp + rcfile.h + registry.cpp + registry.h + WWCOMUtil.cpp + WWCOMUtil.h + win.cpp + win.h + ) +endif() + # Targets to build. add_library(g_wwlib STATIC) set_target_properties(g_wwlib PROPERTIES OUTPUT_NAME wwlib) diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/CRC.H b/Generals/Code/Libraries/Source/WWVegas/WWLib/CRC.H index 79fcb2340a..688c4302fc 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/CRC.H +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/CRC.H @@ -45,6 +45,9 @@ #include "osdep.h" #endif +// SuperHackers: Use IntrinCompat for _lrotl +#include + /* ** This is a CRC engine class. It will process submitted data and generate a CRC from it. ** Well, actually, the value returned is not a true CRC. However, it shares the same strength diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp index e244f5704e..ef6271ab30 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp @@ -32,10 +32,13 @@ ******************************************************************************/ #include "LaunchWeb.h" -#include -#include #include #include +#include +#ifdef _WIN32 +#include +#include +#endif /****************************************************************************** * @@ -63,6 +66,7 @@ bool LaunchWebBrowser(const char* url) return false; } +#ifdef _WIN32 // Create a temporary file with HTML content char tempPath[MAX_PATH]; GetWindowsDirectory(tempPath, MAX_PATH); @@ -117,4 +121,7 @@ bool LaunchWebBrowser(const char* url) assert(createSuccess && "Failed to launch default WebBrowser."); return (TRUE == createSuccess); +#else + return false; +#endif } diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H b/Generals/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H index 0e6aea7164..525bee4f9a 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H @@ -145,8 +145,8 @@ class Random3Class { }; protected: - static int Mix1[20]; - static int Mix2[20]; + static unsigned int Mix1[20]; + static unsigned int Mix2[20]; int Seed; int Index; }; diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/always.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/always.h index bb91ec1dff..afd6904f6d 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/always.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/always.h @@ -43,6 +43,9 @@ #include #include +// SuperHackers: utility macros for cross-platform compatibility +#include + // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use. #pragma warning(disable : 4530) diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/convert.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/convert.cpp index f34c706973..5318094139 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/convert.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/convert.cpp @@ -37,10 +37,11 @@ #include "always.h" #include "blitblit.h" #include "Convert.h" -#include "dsurface.h" #include "hsv.h" #include "rlerle.h" - +#ifdef _WIN32 +#include "dsurface.h" +#endif ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & screenpalette, Surface const & surface) : BBP(surface.Bytes_Per_Pixel()), @@ -121,6 +122,7 @@ ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & */ //assert(surface.Is_Direct_Draw()); Translator = W3DNEWARRAY unsigned short [256]; + #ifdef _WIN32 ((DSurface &)surface).Build_Remap_Table((unsigned short *)Translator, artpalette); /* @@ -129,6 +131,10 @@ ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & */ int maskhalf = ((DSurface &)surface).Get_Halfbright_Mask(); int maskquarter = ((DSurface &)surface).Get_Quarterbright_Mask(); + #else + int maskhalf = 0; + int maskquarter = 0; + #endif /* ** Construct all the blitter objects necessary to support the functionality diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp index 63620ffe2e..3d6809ddc8 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp @@ -21,12 +21,14 @@ #include "wwdebug.h" #include "thread.h" #include "MPU.H" -#pragma warning (disable : 4201) // Nonstandard extension - nameless struct -#include #include "systimer.h" #ifdef _UNIX -# include // for time(), localtime() and timezone variable. +#include // for time(), localtime() and timezone variable. +#include +#else +#pragma warning (disable : 4201) // Nonstandard extension - nameless struct +#include #endif struct OSInfoStruct { @@ -57,7 +59,7 @@ int CPUDetectClass::ProcessorFamily; int CPUDetectClass::ProcessorModel; int CPUDetectClass::ProcessorRevision; int CPUDetectClass::ProcessorSpeed; -__int64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second +sint64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second double CPUDetectClass::InvProcessorTicksPerSecond; // 1.0 / Ticks per second unsigned CPUDetectClass::FeatureBits; @@ -125,7 +127,7 @@ const char* CPUDetectClass::Get_Processor_Manufacturer_Name() #define ASM_RDTSC _asm _emit 0x0f _asm _emit 0x31 -static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) +static unsigned Calculate_Processor_Speed(sint64& ticks_per_second) { struct { unsigned timer0_h; @@ -162,8 +164,8 @@ static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) #endif } - __int64 t=*(__int64*)&Time.timer1_h-*(__int64*)&Time.timer0_h; - ticks_per_second=(__int64)((1000.0/(double)elapsed)*(double)t); // Ticks per second + sint64 t=*(sint64*)&Time.timer1_h-*(sint64*)&Time.timer0_h; + ticks_per_second=(sint64)((1000.0/(double)elapsed)*(double)t); // Ticks per second return unsigned((double)t/(double)(elapsed*1000)); } @@ -847,7 +849,7 @@ void CPUDetectClass::Init_CPUID_Instruction() popfd pop ebx } -#elif defined(_UNIX) +#elif defined(_UNIX) && defined(__i386__) __asm__(" mov $0, __cpuid_available"); // clear flag __asm__(" push %ebx"); __asm__(" pushfd"); @@ -866,6 +868,8 @@ void CPUDetectClass::Init_CPUID_Instruction() __asm__(" push %ebx"); __asm__(" popfd"); __asm__(" pop %ebx"); +#else // _UNIX && __x86_64__ + cpuid_available=1; #endif HasCPUIDInstruction=!!cpuid_available; } @@ -917,8 +921,8 @@ void CPUDetectClass::Init_Memory() void CPUDetectClass::Init_OS() { - OSVERSIONINFO os; #ifdef WIN32 + OSVERSIONINFO os; os.dwOSVersionInfoSize = sizeof(os); GetVersionEx(&os); @@ -962,17 +966,7 @@ bool CPUDetectClass::CPUID( popad } #elif defined(_UNIX) - __asm__("pusha"); - __asm__("mov __cpuid_type, %eax"); - __asm__("xor %ebx, %ebx"); - __asm__("xor %ecx, %ecx"); - __asm__("xor %edx, %edx"); - __asm__("cpuid"); - __asm__("mov %eax, __u_eax"); - __asm__("mov %ebx, __u_ebx"); - __asm__("mov %ecx, __u_ecx"); - __asm__("mov %edx, __u_edx"); - __asm__("popa"); + __get_cpuid(cpuid_type, &u_eax, &u_ebx, &u_ecx, &u_edx); #endif u_eax_=u_eax; @@ -991,9 +985,11 @@ void CPUDetectClass::Init_Processor_Log() SYSLOG(("Operating System: ")); switch (OSVersionPlatformId) { +#ifdef _WIN32 case VER_PLATFORM_WIN32s: SYSLOG(("Windows 3.1")); break; case VER_PLATFORM_WIN32_WINDOWS: SYSLOG(("Windows 9x")); break; case VER_PLATFORM_WIN32_NT: SYSLOG(("Windows NT")); break; +#endif } SYSLOG(("\r\n")); @@ -1274,6 +1270,7 @@ void Get_OS_Info( switch (OSVersionPlatformId) { default: break; +#ifdef _WIN32 case VER_PLATFORM_WIN32_WINDOWS: { for(int i=0;i /*********************************************************************************************** * Load_Alloc_Data -- Allocates a buffer and loads the file into it. * diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/int.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/int.cpp index a7ae62cc88..c28c645148 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/int.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/int.cpp @@ -39,11 +39,18 @@ #include "MPMATH.H" #include "rng.h" +template<> int bignum::Error = 0; +template<> bool bignum::Carry = false; +template<> bool bignum::Borrow = false; +template<> +#if defined(_MSC_VER) && _MSC_VER < 1300 bignum bignum::Remainder; - +#else +bignum bignum::Remainder = {}; +#endif //BigInt Gcd(const BigInt & a, const BigInt & n); diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp index bf95b117f3..d06264569f 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp @@ -124,7 +124,7 @@ int LCW_Uncomp(void const * source, void * dest, unsigned long ) word_data = (word_data << 24) + (word_data << 16) + (word_data << 8) + word_data; source_ptr += 3; - copy_ptr = dest_ptr + 4 - ((unsigned) dest_ptr & 0x3); + copy_ptr = dest_ptr + 4 - ((unsigned long) dest_ptr & 0x3); count -= (copy_ptr - dest_ptr); while (dest_ptr < copy_ptr) *dest_ptr++ = data; diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/mempool.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/mempool.h index e22111c892..d6c8970ec3 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/mempool.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/mempool.h @@ -154,9 +154,14 @@ class AutoPoolClass ** Macro to declare the allocator for your class. Put this in the cpp file for ** the class. */ +#if defined(_MSC_VER) && _MSC_VER < 1300 #define DEFINE_AUTO_POOL(T,BLOCKSIZE) \ ObjectPoolClass AutoPoolClass::Allocator - +#else +#define DEFINE_AUTO_POOL(T,BLOCKSIZE) \ +template<>\ +ObjectPoolClass AutoPoolClass::Allocator = {} +#endif /*********************************************************************************************** diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/mmsys.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/mmsys.h index 735932bbdf..d26b23bccf 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/mmsys.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/mmsys.h @@ -44,8 +44,10 @@ ** This header just includes mmsystem.h with warning 4201 disabled */ +#ifdef _WIN32 #pragma warning(disable:4201) #include #pragma warning(default:4201) +#endif #endif // MMSYS_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp index 0e13aa1a04..7d6780b412 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp @@ -18,7 +18,9 @@ #include "mutex.h" #include "wwdebug.h" +#ifdef _WIN32 #include +#endif // ---------------------------------------------------------------------------- diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/osdep.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/osdep.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/random.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/random.cpp index 68eb39f70d..0374a38186 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/random.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/random.cpp @@ -233,7 +233,7 @@ int Random2Class::operator() (int minval, int maxval) ** that the algorithm is not vulnerable to being primed with a weak seed ** and thus prevents the algorithm from breaking down as a result. */ -int Random3Class::Mix1[20] = { +unsigned int Random3Class::Mix1[20] = { 0x0baa96887, 0x01e17d32c, 0x003bcdc3c, 0x00f33d1b2, 0x076a6491d, 0x0c570d85d, 0x0e382b1e3, 0x078db4362, 0x07439a9d4, 0x09cea8ac5, 0x089537c5c, 0x02588f55d, @@ -241,7 +241,7 @@ int Random3Class::Mix1[20] = { 0x03ea5cc8c, 0x0d26a0f74, 0x0f3a9222b, 0x048aad7e4 }; -int Random3Class::Mix2[20] = { +unsigned int Random3Class::Mix2[20] = { 0x04b0f3b58, 0x0e874f0c3, 0x06955c5a6, 0x055a7ca46, 0x04d9a9d86, 0x0fe28a195, 0x0b1ca7865, 0x06b235751, 0x09a997a61, 0x0aa6e95c8, 0x0aaa98ee1, 0x05af9154c, diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp index c73b52b354..faa8db2b40 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp @@ -54,7 +54,6 @@ #include "always.h" #include "RAWFILE.H" -#include //#include #include #include @@ -66,6 +65,8 @@ #ifdef _UNIX #include #include +#else +#include #endif @@ -575,12 +576,16 @@ bool RawFileClass::Is_Available(int forced) */ int closeok; #ifdef _UNIX - closeok=((fclose(Handle)==0)?TRUE:FALSE); + closeok=((fclose(Handle)==0)?true:false); #else closeok=CloseHandle(Handle); #endif if (! closeok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } Handle = NULL_HANDLE; @@ -616,13 +621,17 @@ void RawFileClass::Close(void) */ int closeok; #ifdef _UNIX - closeok=(fclose(Handle)==0)?TRUE:FALSE; + closeok=(fclose(Handle)==0)?true:false; #else closeok=CloseHandle(Handle); #endif if (!closeok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* @@ -688,10 +697,10 @@ int RawFileClass::Read(void * buffer, int size) while (size > 0) { bytesread = 0; - int readok=TRUE; + int readok=true; #ifdef _UNIX - readok=TRUE; + readok=true; bytesread=fread(buffer,1,size,Handle); if ((bytesread == 0)&&( ! feof(Handle))) readok=ferror(Handle); @@ -703,7 +712,11 @@ int RawFileClass::Read(void * buffer, int size) if (! readok) { size -= bytesread; total += bytesread; + #ifdef _UNIX + Error(errno, true, Filename); + #else Error(GetLastError(), true, Filename); + #endif continue; } size -= bytesread; @@ -756,17 +769,21 @@ int RawFileClass::Write(void const * buffer, int size) opened = true; } - int writeok=TRUE; + int writeok=true; #ifdef _UNIX byteswritten = fwrite(buffer, 1, size, Handle); if (byteswritten != size) - writeok = FALSE; + writeok = false; #else writeok=WriteFile(Handle, buffer, size, &(unsigned long&)byteswritten, NULL); #endif if (! writeok) { + #ifdef _UNIX + Error(errno, true, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* @@ -900,17 +917,17 @@ int RawFileClass::Size(void) if (Is_Open()) { #ifdef _UNIX - fpos_t curpos,startpos,endpos; - fgetpos(Handle,&curpos); + long curpos,startpos,endpos; + curpos = ftell(Handle); fseek(Handle,0,SEEK_SET); - fgetpos(Handle,&startpos); + startpos = ftell(Handle); fseek(Handle,0,SEEK_END); - fgetpos(Handle,&endpos); + endpos = ftell(Handle); size=endpos-startpos; - fsetpos(Handle,&curpos); + fseek(Handle,curpos, SEEK_SET); #else size = GetFileSize(Handle, NULL); #endif @@ -919,7 +936,11 @@ int RawFileClass::Size(void) ** If there was in internal error, then call the error function. */ if (size == 0xFFFFFFFF) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } } else { @@ -1031,13 +1052,17 @@ int RawFileClass::Delete(void) int deleteok; #ifdef _UNIX - deleteok=(unlink(Filename)==0)?TRUE:FALSE; + deleteok=(unlink(Filename)==0)?true:false; #else deleteok=DeleteFile(Filename); #endif if (! deleteok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif return(false); } break; @@ -1218,7 +1243,11 @@ int RawFileClass::Raw_Seek(int pos, int dir) ** If there was an error in the seek, then bail with an error condition. */ if (pos == 0xFFFFFFFF) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp index 600067f129..a102d85ccc 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp @@ -40,8 +40,8 @@ #include "refcount.h" -#include - +// SuperHackers: Cross-platform __debugbreak() implementation +#include #ifndef NDEBUG @@ -174,7 +174,7 @@ void RefCountClass::Add_Ref(void) // See if programmer set break on for a specific address. if (this == BreakOnReference) { - DebugBreak(); // trigger the debugger + __debugbreak(); // trigger the debugger } Inc_Total_Refs(this); } @@ -201,7 +201,7 @@ void RefCountClass::Dec_Total_Refs(RefCountClass * obj) // See if programmer set break on for a specific address. if (obj == BreakOnReference) { - DebugBreak(); // trigger the debugger + __debugbreak(); // trigger the debugger } } diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/sha.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/sha.h index 30a0d75671..13d767b64a 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/sha.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/sha.h @@ -43,7 +43,7 @@ ** November of '94. Until the compiler supports this, use the following ** definition. */ -#include +#include #include "always.h" #include "bool.h" #include diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/stimer.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/stimer.cpp index c861bd1160..f0ada85f1d 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/stimer.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/stimer.cpp @@ -42,7 +42,7 @@ #pragma warning (push,3) #endif -#include +#include "systimer.h" #ifdef _MSC_VER #pragma warning (pop) @@ -51,11 +51,11 @@ long SystemTimerClass::operator () (void) const { - return timeGetTime()/16; + return TIMEGETTIME()/16; } SystemTimerClass::operator long (void) const { - return timeGetTime()/16; + return TIMEGETTIME()/16; } diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/systimer.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/systimer.h index a03247ed53..127500c105 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/systimer.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/systimer.h @@ -38,10 +38,25 @@ #ifndef _SYSTIMER_H #include "always.h" +#ifdef _WIN32 #include #include "mmsys.h" #define TIMEGETTIME SystemTime.Get +#define MS_TIMER_SECOND 1000 +#else +#include + +inline unsigned long systimerGetMS(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +#define TIMEGETTIME systimerGetMS +#define MS_TIMER_SECOND 1000 +#endif /* ** Class that just wraps around timeGetTime() diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/thread.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/thread.cpp index e592a2b2f6..adfa28a701 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/thread.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/thread.cpp @@ -20,11 +20,13 @@ #include "thread.h" #include "wwdebug.h" +#ifdef _WIN32 #include #include +#endif #pragma warning ( push ) #pragma warning ( disable : 4201 ) -#include +#include "systimer.h" #pragma warning ( pop ) ThreadClass::ThreadClass() : handle(0), running(false), thread_priority(0) @@ -74,9 +76,9 @@ void ThreadClass::Stop(unsigned ms) return; #else running=false; - unsigned time=timeGetTime(); + unsigned time=TIMEGETTIME(); while (handle) { - if ((timeGetTime()-time)>ms) { + if ((TIMEGETTIME()-time)>ms) { int res=TerminateThread((HANDLE)handle,0); res; // just to silence compiler warnings WWASSERT(res); // Thread still not killed! diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp index 34105adf90..2aa4ab8ee6 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp @@ -243,7 +243,7 @@ WideStringClass::Free_String (void) // /////////////////////////////////////////////////////////////////// int _cdecl -WideStringClass::Format_Args (const WCHAR *format, const va_list & arg_list ) +WideStringClass::Format_Args (const WCHAR *format, va_list arg_list ) { // // Make a guess at the maximum length of the resulting string diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.h index b8e3ac29df..5b6c3a1cd7 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/widestring.h @@ -112,7 +112,7 @@ class WideStringClass void Erase (int start_index, int char_count); int _cdecl Format (const WCHAR *format, ...); - int _cdecl Format_Args (const WCHAR *format, const va_list & arg_list ); + int _cdecl Format_Args (const WCHAR *format, va_list arg_list ); void Convert_From (const char *text); void Convert_To (StringClass &string); void Convert_To (StringClass &string) const; diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/win.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/win.h index dd587c39ee..bdcd69ee1d 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/win.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/win.h @@ -54,6 +54,7 @@ #pragma warning(push, 3) #endif +#ifdef _WIN32 // this define should also be in the DSP just in case someone includes windows stuff directly #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -64,6 +65,7 @@ //#include //#include //#include +#endif #if (_MSC_VER >= 1200) #pragma warning(pop) diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp index b797bee7cc..32eb7d8153 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp @@ -39,6 +39,9 @@ #include #include "WWFILE.H" +// SuperHackers: For _vsnprintf +#include + #pragma warning(disable : 4514) int FileClass::Printf(char *str, ...) diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp index c371b7d4fb..fad53da7a4 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp @@ -102,7 +102,7 @@ StringClass::Get_String (int length, bool is_temp) // // Grab this unused buffer for our string // - unsigned temp_string=reinterpret_cast(m_TempStrings); + unsigned long temp_string=reinterpret_cast(m_TempStrings); temp_string+=MAX_TEMP_BYTES*MAX_TEMP_STRING; temp_string&=~(MAX_TEMP_BYTES*MAX_TEMP_STRING-1); temp_string+=index*MAX_TEMP_BYTES; @@ -185,8 +185,8 @@ StringClass::Free_String (void) { if (m_Buffer != m_EmptyString) { - unsigned buffer_base=reinterpret_cast(m_Buffer-sizeof (StringClass::_HEADER)); - unsigned temp_base=reinterpret_cast(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING); + unsigned buffer_base=reinterpret_cast(m_Buffer-sizeof (StringClass::_HEADER)); + unsigned temp_base=reinterpret_cast(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING); if ((buffer_base>>11)==(temp_base>>11)) { // @@ -224,7 +224,7 @@ StringClass::Free_String (void) // /////////////////////////////////////////////////////////////////// int _cdecl -StringClass::Format_Args (const TCHAR *format, const va_list & arg_list ) +StringClass::Format_Args (const TCHAR *format, va_list arg_list ) { // // Make a guess at the maximum length of the resulting string diff --git a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.h b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.h index dc1bcb5c0e..fae080ee32 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWLib/wwstring.h @@ -45,7 +45,9 @@ #include "mutex.h" #include #include +#ifdef _WIN32 #include +#endif #include #ifdef _UNIX #include "osdep.h" @@ -118,7 +120,7 @@ class StringClass void Erase (int start_index, int char_count); int _cdecl Format (const TCHAR *format, ...); - int _cdecl Format_Args (const TCHAR *format, const va_list & arg_list ); + int _cdecl Format_Args (const TCHAR *format, va_list arg_list ); TCHAR * Get_Buffer (int new_length); TCHAR * Peek_Buffer (void); diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp index f3470e6be6..30e50d8257 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp @@ -62,7 +62,9 @@ #include "matrix3.h" #include "matrix4.h" #include "quat.h" +#ifdef _WIN32 #include "d3dx8math.h" +#endif // some static matrices which are sometimes useful const Matrix3D Matrix3D::Identity @@ -517,7 +519,9 @@ void Matrix3D::Get_Inverse(Matrix3D & inv) const Matrix4 mat4Inv; float det; +#ifdef _WIN32 D3DXMatrixInverse((D3DXMATRIX *)&mat4Inv, &det, (D3DXMATRIX*)&mat4); +#endif inv.Row[0][0]=mat4Inv[0][0]; inv.Row[0][1]=mat4Inv[0][1]; diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h index 94f431898a..aef1baf105 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h +++ b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h @@ -43,10 +43,6 @@ #ifndef POINTERREMAP_H #define POINTERREMAP_H -#ifdef _UNIX -#include "osdep/osdep.h" -#endif - #include "always.h" #include "Vector.H" diff --git a/Generals/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp b/Generals/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp index 2202f93014..34838cda14 100644 --- a/Generals/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp @@ -119,8 +119,14 @@ bool cMiscUtil::File_Is_Read_Only(LPCSTR filename) { WWASSERT(filename != NULL); - DWORD attributes = ::GetFileAttributes(filename); - return ((attributes != 0xFFFFFFFF) && (attributes & FILE_ATTRIBUTE_READONLY)); +#ifdef _WIN32 + DWORD attributes = ::GetFileAttributes(filename); + return ((attributes != 0xFFFFFFFF) && (attributes & FILE_ATTRIBUTE_READONLY)); +#else + bool readable = access(filename, R_OK) == 0; + bool writable = access(filename, W_OK) == 0; + return (readable && !writable); +#endif } //----------------------------------------------------------------------------- @@ -165,6 +171,7 @@ void cMiscUtil::Get_File_Id_String(LPCSTR filename, StringClass & str) // WWDEBUG_SAY(("cMiscUtil::Get_File_Id_String for %s\n", filename)); +#ifdef _WIN32 // // Get size // @@ -211,7 +218,7 @@ void cMiscUtil::Get_File_Id_String(LPCSTR filename, StringClass & str) // Put all this data into a string // str.Format("%s %d %d", working_filename, filesize, time_date_stamp); - +#endif //WWDEBUG_SAY(("File id string: %s\n", str)); } @@ -220,7 +227,11 @@ void cMiscUtil::Remove_File(LPCSTR filename) { WWASSERT(filename != NULL); - ::DeleteFile(filename); +#ifdef _WIN32 + ::DeleteFile(filename); +#else + ::remove(filename); +#endif } diff --git a/Generals/Code/Main/CMakeLists.txt b/Generals/Code/Main/CMakeLists.txt index 3c435234cb..9ad959c3b6 100644 --- a/Generals/Code/Main/CMakeLists.txt +++ b/Generals/Code/Main/CMakeLists.txt @@ -17,7 +17,7 @@ target_link_libraries(g_generals PRIVATE dxguid g_gameengine g_gameenginedevice - gi_libraries_include + gi_utility gi_libraries_source imm32 milesstub diff --git a/Generals/Code/Tools/Autorun/CMakeLists.txt b/Generals/Code/Tools/Autorun/CMakeLists.txt index 4fed2854d6..85868db984 100644 --- a/Generals/Code/Tools/Autorun/CMakeLists.txt +++ b/Generals/Code/Tools/Autorun/CMakeLists.txt @@ -54,7 +54,7 @@ macro(setup_autorun appname) target_sources(${appname} PRIVATE ${AUTORUN_SRC}) target_link_libraries(${appname} PRIVATE - gi_libraries_include + gi_utility gz_config gz_utility winmm diff --git a/Generals/Code/Tools/Compress/CMakeLists.txt b/Generals/Code/Tools/Compress/CMakeLists.txt index 4a3d175cd2..58ce4a7c1e 100644 --- a/Generals/Code/Tools/Compress/CMakeLists.txt +++ b/Generals/Code/Tools/Compress/CMakeLists.txt @@ -11,7 +11,7 @@ target_sources(g_compress PRIVATE ${COMRPESS_SRC}) target_link_libraries(g_compress PRIVATE g_compression - gi_libraries_include + gi_utility gi_libraries_source gz_config ) diff --git a/Generals/Code/Tools/Compress/Compress.cpp b/Generals/Code/Tools/Compress/Compress.cpp index 70584e5408..941017341b 100644 --- a/Generals/Code/Tools/Compress/Compress.cpp +++ b/Generals/Code/Tools/Compress/Compress.cpp @@ -54,7 +54,7 @@ void dumpHelp(const char *exe) } } -void main(int argc, char **argv) +int main(int argc, char **argv) { std::string inFile = ""; std::string outFile = ""; @@ -65,7 +65,7 @@ void main(int argc, char **argv) if ( !stricmp(argv[i], "-help") ) { dumpHelp(argv[0]); - exit(0); + return EXIT_SUCCESS; } if ( !strcmp(argv[i], "-in") ) @@ -119,7 +119,7 @@ void main(int argc, char **argv) if (!fp) { DEBUG_LOG(("Cannot open '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } fseek(fp, 0, SEEK_END); int size = ftell(fp); @@ -131,14 +131,14 @@ void main(int argc, char **argv) if (numRead != 8) { DEBUG_LOG(("Cannot read header from '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } CompressionType usedType = CompressionManager::getCompressionType(data, 8); if (usedType == COMPRESSION_NONE) { DEBUG_LOG(("No compression on '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } int uncompressedSize = CompressionManager::getUncompressedSize(data, 8); @@ -147,8 +147,9 @@ void main(int argc, char **argv) inFile.c_str(), CompressionManager::getCompressionNameByType(usedType), uncompressedSize, size, size/(double)(uncompressedSize+0.1)*100.0)); - return; + return EXIT_SUCCESS; } // compress file + return EXIT_FAILURE; } diff --git a/Generals/Code/Tools/GUIEdit/CMakeLists.txt b/Generals/Code/Tools/GUIEdit/CMakeLists.txt index b4248af364..dd20337053 100644 --- a/Generals/Code/Tools/GUIEdit/CMakeLists.txt +++ b/Generals/Code/Tools/GUIEdit/CMakeLists.txt @@ -53,7 +53,7 @@ target_link_libraries(g_guiedit PRIVATE g_gameengine g_gameenginedevice g_wwvegas - gi_libraries_include + gi_utility imm32 stlport vfw32 diff --git a/Generals/Code/Tools/ImagePacker/CMakeLists.txt b/Generals/Code/Tools/ImagePacker/CMakeLists.txt index 79d9f13e55..54d8c31ad2 100644 --- a/Generals/Code/Tools/ImagePacker/CMakeLists.txt +++ b/Generals/Code/Tools/ImagePacker/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(g_imagepacker PRIVATE dbghelplib g_gameengine g_gameenginedevice - gi_libraries_include + gi_utility imm32 vfw32 winmm diff --git a/Generals/Code/Tools/MapCacheBuilder/CMakeLists.txt b/Generals/Code/Tools/MapCacheBuilder/CMakeLists.txt index 94e5333338..588436d10d 100644 --- a/Generals/Code/Tools/MapCacheBuilder/CMakeLists.txt +++ b/Generals/Code/Tools/MapCacheBuilder/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(g_mapcachebuilder PRIVATE dbghelplib g_gameengine g_gameenginedevice - gi_libraries_include + gi_utility imm32 vfw32 winmm diff --git a/Generals/Code/Tools/PATCHGET/CMakeLists.txt b/Generals/Code/Tools/PATCHGET/CMakeLists.txt index c49c6800a6..d4adf3051d 100644 --- a/Generals/Code/Tools/PATCHGET/CMakeLists.txt +++ b/Generals/Code/Tools/PATCHGET/CMakeLists.txt @@ -27,7 +27,7 @@ macro(setup_patchgrabber appname) g_gameenginedevice g_wwvegas gamespy::gamespy - gi_libraries_include + gi_utility imm32 vfw32 winmm diff --git a/Generals/Code/Tools/ParticleEditor/CMakeLists.txt b/Generals/Code/Tools/ParticleEditor/CMakeLists.txt index ba8fd219b6..85f83d385b 100644 --- a/Generals/Code/Tools/ParticleEditor/CMakeLists.txt +++ b/Generals/Code/Tools/ParticleEditor/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(g_particleeditor PRIVATE d3d8lib dbghelplib gi_gameengine_include - gi_libraries_include + gi_utility gi_libraries_source_wwvegas gi_libraries_source_wwvegas_wwlib gz_config diff --git a/Generals/Code/Tools/WorldBuilder/CMakeLists.txt b/Generals/Code/Tools/WorldBuilder/CMakeLists.txt index f43e78fed8..9fdee10827 100644 --- a/Generals/Code/Tools/WorldBuilder/CMakeLists.txt +++ b/Generals/Code/Tools/WorldBuilder/CMakeLists.txt @@ -176,7 +176,7 @@ set(WORLDBUILDER_SRC "include/TeamIdentity.h" "include/TeamReinforcement.h" "include/teamsdialog.h" - "include/terrainmaterial.h" + "include/TerrainMaterial.h" "include/TerrainModal.h" "include/TerrainSwatches.h" "include/TileTool.h" @@ -214,7 +214,7 @@ target_link_libraries(g_worldbuilder PRIVATE g_gameenginedevice gi_gameengine_include gi_gameenginedevice_include - gi_libraries_include + gi_utility imm32 vfw32 winmm diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txt index 8cd99b0cdd..0697e39c6e 100644 --- a/GeneralsMD/Code/CMakeLists.txt +++ b/GeneralsMD/Code/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(zi_libraries_source_wwvegas_wwlib INTERFACE) add_library(zi_libraries_source_wwvegas_wwmath INTERFACE) add_library(zi_libraries_source_wwvegas_wwsaveload INTERFACE) add_library(zi_main INTERFACE) +add_library(zi_utility INTERFACE) target_include_directories(zi_gameengine INTERFACE "GameEngine") target_include_directories(zi_gameengine_include INTERFACE "GameEngine/Include") @@ -24,6 +25,10 @@ target_include_directories(zi_libraries_source_wwvegas_wwlib INTERFACE "Librarie target_include_directories(zi_libraries_source_wwvegas_wwmath INTERFACE "Libraries/Source/WWVegas/WWMath") target_include_directories(zi_libraries_source_wwvegas_wwsaveload INTERFACE "Libraries/Source/WWVegas/WWSaveLoad") target_include_directories(zi_main INTERFACE "Main") +target_link_libraries(zi_utility INTERFACE + zi_libraries_include + gz_utility +) # Contains internal libraries add_subdirectory(Libraries) diff --git a/GeneralsMD/Code/GameEngine/CMakeLists.txt b/GeneralsMD/Code/GameEngine/CMakeLists.txt index fa95140e52..9abdf1d44c 100644 --- a/GeneralsMD/Code/GameEngine/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngine/CMakeLists.txt @@ -1153,7 +1153,7 @@ target_include_directories(z_gameengine PRIVATE ) target_link_libraries(z_gameengine PRIVATE - zi_libraries_include + zi_utility zi_libraries_source ) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/PerfTimer.h b/GeneralsMD/Code/GameEngine/Include/Common/PerfTimer.h index 1367fed612..f766b59016 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/PerfTimer.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/PerfTimer.h @@ -31,6 +31,8 @@ #ifndef __PERFTIMER_H__ #define __PERFTIMER_H__ +#include "Utility/intrin_compat.h" + #if defined(_DEBUG) || defined(_INTERNAL) /* NOTE NOTE NOTE: never check this in with this enabled, since there is a nonzero time penalty @@ -71,6 +73,7 @@ __forceinline void GetPrecisionTimer(Int64* t) #ifdef USE_QPF QueryPerformanceCounter((LARGE_INTEGER*)t); #else +# if defined(_MSC_VER) && _MSC_VER < 1300 // CPUID is needed to force serialization of any previous instructions. __asm { @@ -81,6 +84,9 @@ __forceinline void GetPrecisionTimer(Int64* t) MOV [ECX], EAX MOV [ECX+4], EDX } +# else + *t = _rdtsc(); +# endif #endif } #endif diff --git a/GeneralsMD/Code/GameEngine/Include/Common/crc.h b/GeneralsMD/Code/GameEngine/Include/Common/crc.h index 0fc2998f99..9e921993d3 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/crc.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/crc.h @@ -67,7 +67,8 @@ class CRC if (!buf||len<1) return; - /* C++ version left in for reference purposes +#if !(defined(_MSC_VER) && _MSC_VER < 1300) + // C++ version left in for reference purposes for (UnsignedByte *uintPtr=(UnsignedByte *)buf;len>0;len--,uintPtr++) { int hibit; @@ -84,8 +85,7 @@ class CRC crc += *uintPtr; crc += hibit; } - */ - +#else // ASM version, verified by comparing resulting data with C++ version data unsigned *crcPtr=&crc; _asm @@ -105,6 +105,7 @@ class CRC jns lp mov dword ptr [edi],ebx }; +#endif } /// Clears the CRC to 0 diff --git a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp index 0dd5628abd..3969844ebc 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp @@ -37,6 +37,7 @@ __forceinline void ProfileGetTime(__int64 &t) { +#if defined(_MSC_VER) && _MSC_VER < 1300 _asm { mov ecx,[t] @@ -48,6 +49,9 @@ __forceinline void ProfileGetTime(__int64 &t) pop edx pop eax }; +#else + t = _rdtsc(); +#endif } #ifdef _INTERNAL diff --git a/GeneralsMD/Code/GameEngineDevice/CMakeLists.txt b/GeneralsMD/Code/GameEngineDevice/CMakeLists.txt index 646c2abf2c..c1068433c2 100644 --- a/GeneralsMD/Code/GameEngineDevice/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngineDevice/CMakeLists.txt @@ -205,7 +205,7 @@ target_include_directories(z_gameenginedevice PUBLIC ) target_link_libraries(z_gameenginedevice PRIVATE - zi_libraries_include + zi_utility zi_libraries_source zi_main ) diff --git a/GeneralsMD/Code/Libraries/CMakeLists.txt b/GeneralsMD/Code/Libraries/CMakeLists.txt index 1658bfbb9e..5b1ec95ee7 100644 --- a/GeneralsMD/Code/Libraries/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/CMakeLists.txt @@ -5,7 +5,7 @@ add_subdirectory(Source/WWVegas) add_subdirectory(Source/profile) # debugging library -add_subdirectory(Source/debug) +add_subdirectory(Source/Debug) add_subdirectory(Source/EABrowserDispatch) add_subdirectory(Source/EABrowserEngine) diff --git a/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h b/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h index aae583b4e8..885a5632e6 100644 --- a/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h +++ b/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h @@ -34,6 +34,8 @@ #include #include +// SuperHackers: utility macros for cross-platform compatibility +#include /* ** Turn off some unneeded warnings. @@ -131,8 +133,13 @@ typedef char Byte; // 1 byte USED TO BE "SignedByte" typedef char Char; // 1 byte of text typedef bool Bool; // // note, the types below should use "long long", but MSVC doesn't support it yet +#ifdef _MSC_VER typedef __int64 Int64; // 8 bytes typedef unsigned __int64 UnsignedInt64; // 8 bytes +#else +typedef long long Int64; // 8 bytes +typedef unsigned long long UnsignedInt64; // 8 bytes +#endif #include "Lib/trig.h" @@ -184,10 +191,14 @@ __forceinline long fast_float2long_round(float f) { long i; +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { fld [f] fistp [i] } +#else + i = lroundf(f); +#endif return i; } @@ -196,6 +207,7 @@ __forceinline long fast_float2long_round(float f) // code courtesy of Martin Hoffesommer (grin) __forceinline float fast_float_trunc(float f) { +#if defined(_MSC_VER) && _MSC_VER < 1300 _asm { mov ecx,[f] @@ -208,6 +220,15 @@ __forceinline float fast_float_trunc(float f) and [f],eax } return f; +#else + unsigned x = *(unsigned *)&f; + unsigned char exp = x >> 23; + int mask = exp < 127 ? 0 : 0xff800000; + exp -= 127; + mask >>= exp & 31; + x &= mask; + return *(float *)&x; +#endif } // same here, fast floor function diff --git a/GeneralsMD/Code/Libraries/Source/Compression/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/Compression/CMakeLists.txt index cd14c5a5e8..b5a48ced53 100644 --- a/GeneralsMD/Code/Libraries/Source/Compression/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/Compression/CMakeLists.txt @@ -30,7 +30,7 @@ target_include_directories(z_compression INTERFACE target_link_libraries(z_compression PRIVATE gz_config - zi_libraries_include + zi_utility ) target_link_libraries(z_compression PUBLIC diff --git a/GeneralsMD/Code/Libraries/Source/Compression/EAC/huffencode.cpp b/GeneralsMD/Code/Libraries/Source/Compression/EAC/huffencode.cpp index 77ba72df50..a2707b21b6 100644 --- a/GeneralsMD/Code/Libraries/Source/Compression/EAC/huffencode.cpp +++ b/GeneralsMD/Code/Libraries/Source/Compression/EAC/huffencode.cpp @@ -1050,8 +1050,8 @@ static void HUFF_pack(struct HuffEncodeContext *EC, if (!i3) HUFF_writecode(EC,dest,i); - if (((int) bptr1- (int) EC->buffer) >= (int)(EC->plen+curpc)) - curpc = (int) bptr1 - (int) EC->buffer - EC->plen; + if (((long) bptr1- (long) EC->buffer) >= (long)(EC->plen+curpc)) + curpc = (long) bptr1 - (long) EC->buffer - EC->plen; } /* write EOF ([clue] 0gn [10]) */ diff --git a/GeneralsMD/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp b/GeneralsMD/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp index 7d006c6841..05f8ae05c3 100644 --- a/GeneralsMD/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp +++ b/GeneralsMD/Code/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp @@ -47,7 +47,7 @@ Bool DecompressFile (char *infile, char *outfile) char *outBlock = NULL; LZHL_DHANDLE decompress; Int ok = 0; - UnsignedInt srcSz, dstSz; + size_t srcSz, dstSz; // Parameter checking @@ -224,7 +224,7 @@ Bool DecompressMemory (void *inBufferVoid, Int inSize, void *outBufferVoid, Int UnsignedInt rawSize = 0, compressedSize = 0; LZHL_DHANDLE decompress; Int ok = 0; - UnsignedInt srcSz, dstSz; + size_t srcSz, dstSz; // Parameter checking diff --git a/GeneralsMD/Code/Libraries/Source/debug/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/Debug/CMakeLists.txt similarity index 96% rename from GeneralsMD/Code/Libraries/Source/debug/CMakeLists.txt rename to GeneralsMD/Code/Libraries/Source/Debug/CMakeLists.txt index 7d2bb88c4f..bd3e5c76c1 100644 --- a/GeneralsMD/Code/Libraries/Source/debug/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/Debug/CMakeLists.txt @@ -34,5 +34,5 @@ target_include_directories(z_debug INTERFACE target_link_libraries(z_debug PRIVATE gz_config - zi_libraries_include + zi_utility ) diff --git a/GeneralsMD/Code/Libraries/Source/debug/_pch.cpp b/GeneralsMD/Code/Libraries/Source/Debug/_pch.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/_pch.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/_pch.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/_pch.h b/GeneralsMD/Code/Libraries/Source/Debug/_pch.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/_pch.h rename to GeneralsMD/Code/Libraries/Source/Debug/_pch.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/compile_doxygen.bat b/GeneralsMD/Code/Libraries/Source/Debug/compile_doxygen.bat similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/compile_doxygen.bat rename to GeneralsMD/Code/Libraries/Source/Debug/compile_doxygen.bat diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug.dox b/GeneralsMD/Code/Libraries/Source/Debug/debug.dox similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug.dox rename to GeneralsMD/Code/Libraries/Source/Debug/debug.dox diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug.dsp b/GeneralsMD/Code/Libraries/Source/Debug/debug.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/debug.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug.dsw b/GeneralsMD/Code/Libraries/Source/Debug/debug.dsw similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug.dsw rename to GeneralsMD/Code/Libraries/Source/Debug/debug.dsw diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug.h b/GeneralsMD/Code/Libraries/Source/Debug/debug.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_cmd.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_cmd.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_cmd.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_cmd.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_cmd.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_debug.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_debug.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_debug.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_debug.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_debug.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_debug.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.dsp b/GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.rc b/GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.rc similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_dlg/debug_dlg.rc rename to GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/debug_dlg.rc diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_dlg/resource.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/resource.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_dlg/resource.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_dlg/resource.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_doc.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_doc.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_doc.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_doc.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_except.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_except.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_getdefaultcommands.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_getdefaultcommands.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_getdefaultcommands.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_getdefaultcommands.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_internal.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_internal.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_internal.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_internal.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_io.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_io.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_io.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io_con.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_io_con.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_io_con.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_io_con.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_io_flat.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_io_flat.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io_net.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_io_net.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_io_net.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_io_net.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io_ods.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_io_ods.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_io_ods.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_io_ods.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_macro.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_macro.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_macro.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_macro.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_purecall.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_purecall.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_purecall.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_purecall.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp b/GeneralsMD/Code/Libraries/Source/Debug/debug_stack.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/debug_stack.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_stack.h b/GeneralsMD/Code/Libraries/Source/Debug/debug_stack.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_stack.h rename to GeneralsMD/Code/Libraries/Source/Debug/debug_stack.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_stack.inl b/GeneralsMD/Code/Libraries/Source/Debug/debug_stack.inl similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/debug_stack.inl rename to GeneralsMD/Code/Libraries/Source/Debug/debug_stack.inl diff --git a/GeneralsMD/Code/Libraries/Source/debug/internal.h b/GeneralsMD/Code/Libraries/Source/Debug/internal.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/internal.h rename to GeneralsMD/Code/Libraries/Source/Debug/internal.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/internal_except.h b/GeneralsMD/Code/Libraries/Source/Debug/internal_except.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/internal_except.h rename to GeneralsMD/Code/Libraries/Source/Debug/internal_except.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/internal_io.h b/GeneralsMD/Code/Libraries/Source/Debug/internal_io.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/internal_io.h rename to GeneralsMD/Code/Libraries/Source/Debug/internal_io.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/netserv/netserv.cpp b/GeneralsMD/Code/Libraries/Source/Debug/netserv/netserv.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/netserv/netserv.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/netserv/netserv.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/netserv/netserv.dsp b/GeneralsMD/Code/Libraries/Source/Debug/netserv/netserv.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/netserv/netserv.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/netserv/netserv.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/rc_exception.inl b/GeneralsMD/Code/Libraries/Source/Debug/rc_exception.inl similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/rc_exception.inl rename to GeneralsMD/Code/Libraries/Source/Debug/rc_exception.inl diff --git a/GeneralsMD/Code/Libraries/Source/debug/test1/test1.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test1/test1.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test1/test1.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test1/test1.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test1/test1.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test1/test1.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test1/test1.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test1/test1.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/StdAfx.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test2/StdAfx.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/StdAfx.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test2/StdAfx.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/StdAfx.h b/GeneralsMD/Code/Libraries/Source/Debug/test2/StdAfx.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/StdAfx.h rename to GeneralsMD/Code/Libraries/Source/Debug/test2/StdAfx.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/default.dbgcmd b/GeneralsMD/Code/Libraries/Source/Debug/test2/default.dbgcmd similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/default.dbgcmd rename to GeneralsMD/Code/Libraries/Source/Debug/test2/default.dbgcmd diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/resource.h b/GeneralsMD/Code/Libraries/Source/Debug/test2/resource.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/resource.h rename to GeneralsMD/Code/Libraries/Source/Debug/test2/resource.h diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/test2.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test2/test2.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/test2.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test2/test2.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/test2.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test2/test2.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/test2.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test2/test2.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test2/test2.rc b/GeneralsMD/Code/Libraries/Source/Debug/test2/test2.rc similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test2/test2.rc rename to GeneralsMD/Code/Libraries/Source/Debug/test2/test2.rc diff --git a/GeneralsMD/Code/Libraries/Source/debug/test3/test3.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test3/test3.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test3/test3.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test3/test3.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test3/test3.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test3/test3.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test3/test3.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test3/test3.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test4/test4.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test4/test4.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test4/test4.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test4/test4.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test4/test4.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test4/test4.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test4/test4.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test4/test4.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test5/test5.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test5/test5.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test5/test5.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test5/test5.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test5/test5.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test5/test5.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test5/test5.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test5/test5.dsp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test6/test6.cpp b/GeneralsMD/Code/Libraries/Source/Debug/test6/test6.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test6/test6.cpp rename to GeneralsMD/Code/Libraries/Source/Debug/test6/test6.cpp diff --git a/GeneralsMD/Code/Libraries/Source/debug/test6/test6.dsp b/GeneralsMD/Code/Libraries/Source/Debug/test6/test6.dsp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/debug/test6/test6.dsp rename to GeneralsMD/Code/Libraries/Source/Debug/test6/test6.dsp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index 46b4c14714..4f0fead4ec 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -1003,6 +1003,7 @@ WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector4& color) WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color,float alpha) { +#if defined(_MSC_VER) && _MSC_VER < 1300 const float scale = 255.0; unsigned int col; @@ -1069,24 +1070,21 @@ WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color,float alpha mov col,eax } return col; +#else + return color.Convert_To_ARGB(alpha); +#endif // defined(_MSC_VER) && _MSC_VER < 1300 } // ---------------------------------------------------------------------------- // -// Clamp color vertor to [0...1] range +// Clamp color vector to [0...1] range // // ---------------------------------------------------------------------------- WWINLINE void DX8Wrapper::Clamp_Color(Vector4& color) { - if (!CPUDetectClass::Has_CMOV_Instruction()) { - for (int i=0;i<4;++i) { - float f=(color[i]<0.0f) ? 0.0f : color[i]; - color[i]=(f>1.0f) ? 1.0f : f; - } - return; - } - +#if defined(_MSC_VER) && _MSC_VER < 1300 + if (CPUDetectClass::Has_CMOV_Instruction()) { __asm { mov esi,dword ptr color @@ -1129,6 +1127,14 @@ WWINLINE void DX8Wrapper::Clamp_Color(Vector4& color) cmovnb edi,edx mov dword ptr[esi+12],edi } + return; + } +#endif // defined(_MSC_VER) && _MSC_VER < 1300 + + for (int i=0;i<4;++i) { + float f=(color[i]<0.0f) ? 0.0f : color[i]; + color[i]=(f>1.0f) ? 1.0f : f; + } } // ---------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/CMakeLists.txt index 3088325509..6005800d90 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/CMakeLists.txt @@ -17,4 +17,5 @@ target_sources(z_wwdebug PRIVATE ${WWDEBUG_SRC}) target_link_libraries(z_wwdebug PRIVATE z_wwcommon + zi_utility ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp index 53a70114a3..6b52485138 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp @@ -43,7 +43,11 @@ #include "wwdebug.h" +#ifdef _WIN32 #include +#else +#include +#endif //#include "win.h" can use this if allowed to see wwlib #include #include @@ -79,7 +83,11 @@ void Convert_System_Error_To_String(int id, char* buffer, int buf_len) int Get_Last_System_Error() { +#ifndef _UNIX return GetLastError(); +#else + return errno; +#endif } /*********************************************************************************************** @@ -313,7 +321,7 @@ void WWDebug_Assert_Fail(const char * expr,const char * file, int line) } if (code == IDRETRY) { - _asm int 3; + WWDEBUG_BREAK return; } } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h index af66350cd9..951d95ca3d 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h @@ -40,7 +40,12 @@ #ifndef WWDEBUG_H #define WWDEBUG_H - + +// TheSuperHackers @todo Recover WWDEBUG? +#ifdef WWDEBUG +#include +#endif + // The macro MESSAGE allows user to put: // #pragma MESSAGE("Hello world") // anywhere in a source file. The message: @@ -142,9 +147,13 @@ void WWDebug_DBWin32_Message_Handler( const char * message); ** the debugger... */ #ifdef WWDEBUG -#define WWDEBUG_BREAK _asm int 0x03 +# if defined(_MSC_VER) && _MSC_VER < 1300 +# define WWDEBUG_BREAK _asm int 0x03 +# else +# define WWDEBUG_BREAK __debugbreak(); +# endif #else -#define WWDEBUG_BREAK _asm int 0x03 +#define WWDEBUG_BREAK #endif /* diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp index 7a77319e2a..5cc8394d85 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp @@ -43,7 +43,9 @@ #include "wwdebug.h" #include "Vector.H" #include "FastAllocator.h" +#ifdef _WIN32 #include +#endif #define USE_FAST_ALLOCATOR diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp index 07d29788e0..0d2be9fa7d 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp @@ -53,7 +53,9 @@ #include "wwprofile.h" #include "FastAllocator.h" #include "wwdebug.h" +#ifdef _WIN32 #include +#endif //#include "systimer.h" #include "systimer.h" #include "RAWFILE.H" @@ -62,6 +64,7 @@ #include "cpudetect.h" #include "hashtemplate.h" #include +#include static SimpleDynVecClass ProfileCollectVector; static double TotalFrameTimes; @@ -101,6 +104,7 @@ inline void WWProfile_Get_Ticks(_int64 * ticks) #ifdef _UNIX *ticks = TIMEGETTIME(); #else +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { push edx; @@ -115,6 +119,9 @@ inline void WWProfile_Get_Ticks(_int64 * ticks) pop ecx; pop edx; } +#else + *ticks = _rdtsc(); +#endif // defined(_MSC_VER) && _MSC_VER < 1300 #endif } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt index 5e79ced2bc..c7432ed3c4 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CMakeLists.txt @@ -1,7 +1,6 @@ # Set source files set(WWLIB_SRC _convert.cpp - _mono.cpp argv.cpp b64pipe.cpp b64straw.cpp @@ -16,8 +15,6 @@ set(WWLIB_SRC crc.cpp cstraw.cpp data.cpp - ddraw.cpp - dsurface.cpp Except.cpp FastAllocator.cpp ffactory.cpp @@ -27,15 +24,11 @@ set(WWLIB_SRC ini.cpp int.cpp jshell.cpp - keyboard.cpp LaunchWeb.cpp lcw.cpp load.cpp mixfile.cpp - mono.cpp mpmath.cpp - mpu.cpp - msgloop.cpp multilist.cpp mutex.cpp nstrdup.cpp @@ -47,11 +40,9 @@ set(WWLIB_SRC random.cpp rawfile.cpp rc4.cpp - rcfile.cpp readline.cpp realcrc.cpp refcount.cpp - registry.cpp rgb.cpp rle.cpp rndstrng.cpp @@ -70,17 +61,13 @@ set(WWLIB_SRC thread.cpp trim.cpp vector.cpp - verchk.cpp widestring.cpp - win.cpp - WWCOMUtil.cpp wwfile.cpp wwfont.cpp wwstring.cpp xpipe.cpp xstraw.cpp xsurface.cpp - _mono.h always.h argv.h b64pipe.h @@ -104,7 +91,6 @@ set(WWLIB_SRC CRC.H cstraw.h data.h - dsurface.h FastAllocator.h ffactory.h FONT.H @@ -119,7 +105,6 @@ set(WWLIB_SRC inisup.h INT.H iostruct.h - keyboard.h LaunchWeb.h LCW.H LISTNODE.H @@ -128,8 +113,6 @@ set(WWLIB_SRC MONO.H MONODRVR.H MPMATH.H - MPU.H - msgloop.h multilist.h mutex.h notifier.h @@ -144,12 +127,10 @@ set(WWLIB_SRC RANDOM.H RAWFILE.H rc4.h - rcfile.h readline.h realcrc.h ref_ptr.h refcount.h - registry.h RGB.H RLE.H RNDSTRAW.H @@ -182,12 +163,9 @@ set(WWLIB_SRC trim.h uarray.h Vector.H - verchk.h visualc.h WATCOM.H widestring.h - win.h - WWCOMUtil.h WWFILE.H wwstring.h xmouse.h @@ -196,6 +174,33 @@ set(WWLIB_SRC xsurface.h ) +if(WIN32) + list(APPEND WWLIB_SRC + ddraw.cpp + dsurface.cpp + dsurface.h + keyboard.cpp + keyboard.h + mono.cpp + _mono.cpp + _mono.h + mpu.cpp + MPU.H + msgloop.cpp + msgloop.h + rcfile.cpp + rcfile.h + registry.cpp + registry.h + verchk.cpp + verchk.h + WWCOMUtil.cpp + WWCOMUtil.h + win.cpp + win.h + ) +endif() + # Targets to build. add_library(z_wwlib STATIC) set_target_properties(z_wwlib PROPERTIES OUTPUT_NAME wwlib) @@ -204,4 +209,5 @@ target_sources(z_wwlib PRIVATE ${WWLIB_SRC}) target_link_libraries(z_wwlib PRIVATE z_wwcommon + zi_utility ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CRC.H b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CRC.H index 6a8f8292ae..9f425c5b0b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CRC.H +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CRC.H @@ -45,6 +45,9 @@ #include "osdep.h" #endif +// SuperHackers: Use IntrinCompat for _lrotl +#include + /* ** This is a CRC engine class. It will process submitted data and generate a CRC from it. ** Well, actually, the value returned is not a true CRC. However, it shares the same strength diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp index a288146ddf..d96812a2a8 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp @@ -177,7 +177,7 @@ int __cdecl _purecall(void) ** Use int3 to cause an exception. */ WWDEBUG_SAY(("Pure Virtual Function call. Oh No!\n")); - _asm int 0x03; + WWDEBUG_BREAK #endif //_DEBUG_ASSERT return(return_code); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/FastAllocator.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/FastAllocator.cpp index a53c83f6df..f3bf1b6f3f 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/FastAllocator.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/FastAllocator.cpp @@ -17,7 +17,7 @@ */ #include "FastAllocator.h" -#include +#include static FastAllocatorGeneral* generalAllocator; //This general allocator will do all allocations for us. diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp index 57d311e156..ac45538474 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/LaunchWeb.cpp @@ -32,10 +32,13 @@ ******************************************************************************/ #include "LaunchWeb.h" -#include -#include #include #include +#include +#ifdef _WIN32 +#include +#include +#endif /****************************************************************************** * @@ -63,6 +66,7 @@ bool LaunchWebBrowser(const char* url) return false; } +#ifdef _WIN32 // Create a temporary file with HTML content char tempPath[MAX_PATH]; GetWindowsDirectory(tempPath, MAX_PATH); @@ -117,4 +121,7 @@ bool LaunchWebBrowser(const char* url) assert(createSuccess && "Failed to launch default WebBrowser."); return (TRUE == createSuccess); +#else + return false; +#endif } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H index c1a9dd8932..badfc5f9fa 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/RANDOM.H @@ -145,8 +145,8 @@ class Random3Class { }; protected: - static int Mix1[20]; - static int Mix2[20]; + static unsigned int Mix1[20]; + static unsigned int Mix2[20]; int Seed; int Index; }; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/TARGA.CPP b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/TARGA.CPP index eda03b99ce..131993f23b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/TARGA.CPP +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/TARGA.CPP @@ -76,6 +76,8 @@ #include #endif +#include +#include /**************************************************************************** * @@ -827,6 +829,7 @@ void Targa::XFlip(void) static __forceinline void _swapBytes(char *p1, char *p2, unsigned count) { +#if defined(_MSC_VER) && _MSC_VER < 1300 _asm { mov esi,[p1] @@ -865,6 +868,12 @@ static __forceinline void _swapBytes(char *p1, char *p2, unsigned count) jmp lpLessThan16 done: } +#else + for (unsigned i = 0; i < count; ++i) + { + std::swap(p1[i], p2[i]); + } +#endif } void Targa::YFlip(void) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Vector.H b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Vector.H index 4e331d2a18..4952498c79 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Vector.H +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Vector.H @@ -61,7 +61,9 @@ #include #include #include +#ifdef _WIN32 #include +#endif #ifdef _MSC_VER #pragma warning (disable : 4702) // unreachable code, happens with some uses of these templates diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h index def9795963..37b8489213 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h @@ -43,6 +43,9 @@ #include #include +// SuperHackers: utility macros for cross-platform compatibility +#include + // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use. #pragma warning(disable : 4530) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/convert.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/convert.cpp index af76cc1e91..cbb58e9b84 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/convert.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/convert.cpp @@ -37,10 +37,11 @@ #include "always.h" #include "blitblit.h" #include "Convert.h" -#include "dsurface.h" #include "hsv.h" #include "rlerle.h" - +#ifdef _WIN32 +#include "dsurface.h" +#endif ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & screenpalette, Surface const & surface) : BBP(surface.Bytes_Per_Pixel()), @@ -121,6 +122,7 @@ ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & */ //assert(surface.Is_Direct_Draw()); Translator = W3DNEWARRAY unsigned short [256]; + #ifdef _WIN32 ((DSurface &)surface).Build_Remap_Table((unsigned short *)Translator, artpalette); /* @@ -129,6 +131,10 @@ ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & */ int maskhalf = ((DSurface &)surface).Get_Halfbright_Mask(); int maskquarter = ((DSurface &)surface).Get_Quarterbright_Mask(); + #else + int maskhalf = 0; + int maskquarter = 0; + #endif /* ** Construct all the blitter objects necessary to support the functionality diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp index 001f2466bb..325c847fcf 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp @@ -21,12 +21,15 @@ #include "wwdebug.h" #include "thread.h" #include "MPU.H" -#pragma warning (disable : 4201) // Nonstandard extension - nameless struct -#include #include "systimer.h" +#include #ifdef _UNIX -# include // for time(), localtime() and timezone variable. +#include // for time(), localtime() and timezone variable. +#include +#else +#pragma warning (disable : 4201) // Nonstandard extension - nameless struct +#include #endif struct OSInfoStruct { @@ -57,7 +60,7 @@ int CPUDetectClass::ProcessorFamily; int CPUDetectClass::ProcessorModel; int CPUDetectClass::ProcessorRevision; int CPUDetectClass::ProcessorSpeed; -__int64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second +sint64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second double CPUDetectClass::InvProcessorTicksPerSecond; // 1.0 / Ticks per second unsigned CPUDetectClass::FeatureBits; @@ -125,7 +128,7 @@ const char* CPUDetectClass::Get_Processor_Manufacturer_Name() #define ASM_RDTSC _asm _emit 0x0f _asm _emit 0x31 -static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) +static unsigned Calculate_Processor_Speed(sint64& ticks_per_second) { struct { unsigned timer0_h; @@ -135,11 +138,17 @@ static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) } Time; #ifdef WIN32 +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { ASM_RDTSC; mov Time.timer0_h, eax mov Time.timer0_l, edx } +#else + uint64_t long_timer = _rdtsc(); + Time.timer0_h = long_timer >> 32; + Time.timer0_l = long_timer & 0xFFFFFFFF; +#endif // defined(_MSC_VER) && _MSC_VER < 1300 #elif defined(_UNIX) __asm__("rdtsc"); __asm__("mov %eax, __Time.timer1_h"); @@ -150,11 +159,17 @@ static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) unsigned elapsed; while ((elapsed=TIMEGETTIME()-start)<200) { #ifdef WIN32 +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { ASM_RDTSC; mov Time.timer1_h, eax mov Time.timer1_l, edx } +#else + long_timer = _rdtsc(); + Time.timer1_h = long_timer >> 32; + Time.timer1_l = long_timer & 0xFFFFFFFF; +#endif // defined(_MSC_VER) && _MSC_VER < 1300 #elif defined(_UNIX) __asm__ ("rdtsc"); __asm__("mov %eax, __Time.timer1_h"); @@ -162,8 +177,8 @@ static unsigned Calculate_Processor_Speed(__int64& ticks_per_second) #endif } - __int64 t=*(__int64*)&Time.timer1_h-*(__int64*)&Time.timer0_h; - ticks_per_second=(__int64)((1000.0/(double)elapsed)*(double)t); // Ticks per second + sint64 t=*(sint64*)&Time.timer1_h-*(sint64*)&Time.timer0_h; + ticks_per_second=(sint64)((1000.0/(double)elapsed)*(double)t); // Ticks per second return unsigned((double)t/(double)(elapsed*1000)); } @@ -826,6 +841,7 @@ void CPUDetectClass::Init_CPUID_Instruction() // because CodeWarrior seems to have problems with // the command (huh?) +#if defined(_MSC_VER) && _MSC_VER < 1300 #ifdef WIN32 __asm { @@ -847,7 +863,7 @@ void CPUDetectClass::Init_CPUID_Instruction() popfd pop ebx } -#elif defined(_UNIX) +#elif defined(_UNIX) && defined(__i386__) __asm__(" mov $0, __cpuid_available"); // clear flag __asm__(" push %ebx"); __asm__(" pushfd"); @@ -866,8 +882,14 @@ void CPUDetectClass::Init_CPUID_Instruction() __asm__(" push %ebx"); __asm__(" popfd"); __asm__(" pop %ebx"); +#else // _UNIX && __x86_64__ + cpuid_available=1; #endif HasCPUIDInstruction=!!cpuid_available; +#else + // TheSuperHackers @info Mauller 30/3/2020 All modern CPUs have the CPUID instruction, VS22 code will not run on a cpu that doesn't. + HasCPUIDInstruction = true; +#endif // defined(_MSC_VER) && _MSC_VER < 1300 } void CPUDetectClass::Init_Processor_Features() @@ -917,8 +939,8 @@ void CPUDetectClass::Init_Memory() void CPUDetectClass::Init_OS() { - OSVERSIONINFO os; #ifdef WIN32 + OSVERSIONINFO os; os.dwOSVersionInfoSize = sizeof(os); GetVersionEx(&os); @@ -947,6 +969,7 @@ bool CPUDetectClass::CPUID( unsigned u_edx; #ifdef WIN32 +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { pushad @@ -961,18 +984,16 @@ bool CPUDetectClass::CPUID( mov [u_edx], edx popad } +#else + volatile uint32_t regs[4]; + __cpuidex((int*)regs, (int)cpuid_type, (int)0x00); + u_eax = regs[0]; + u_ebx = regs[1]; + u_ecx = regs[2]; + u_edx = regs[3]; +#endif // defined(_MSC_VER) && _MSC_VER < 1300 #elif defined(_UNIX) - __asm__("pusha"); - __asm__("mov __cpuid_type, %eax"); - __asm__("xor %ebx, %ebx"); - __asm__("xor %ecx, %ecx"); - __asm__("xor %edx, %edx"); - __asm__("cpuid"); - __asm__("mov %eax, __u_eax"); - __asm__("mov %ebx, __u_ebx"); - __asm__("mov %ecx, __u_ecx"); - __asm__("mov %edx, __u_edx"); - __asm__("popa"); + __get_cpuid(cpuid_type, &u_eax, &u_ebx, &u_ecx, &u_edx); #endif u_eax_=u_eax; @@ -991,9 +1012,11 @@ void CPUDetectClass::Init_Processor_Log() SYSLOG(("Operating System: ")); switch (OSVersionPlatformId) { +#ifdef _WIN32 case VER_PLATFORM_WIN32s: SYSLOG(("Windows 3.1")); break; case VER_PLATFORM_WIN32_WINDOWS: SYSLOG(("Windows 9x")); break; case VER_PLATFORM_WIN32_NT: SYSLOG(("Windows NT")); break; +#endif } SYSLOG(("\r\n")); @@ -1274,6 +1297,7 @@ void Get_OS_Info( switch (OSVersionPlatformId) { default: break; +#ifdef _WIN32 case VER_PLATFORM_WIN32_WINDOWS: { for(int i=0;i /*********************************************************************************************** * Load_Alloc_Data -- Allocates a buffer and loads the file into it. * diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/int.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/int.cpp index e4bd7f6e58..10a7bb367d 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/int.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/int.cpp @@ -39,11 +39,18 @@ #include "MPMATH.H" #include "rng.h" +template<> int bignum::Error = 0; +template<> bool bignum::Carry = false; +template<> bool bignum::Borrow = false; +template<> +#if defined(_MSC_VER) && _MSC_VER < 1300 bignum bignum::Remainder; - +#else +bignum bignum::Remainder = {}; +#endif //BigInt Gcd(const BigInt & a, const BigInt & n); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp index 0ed1376eb4..2a6becbf65 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/lcw.cpp @@ -124,7 +124,7 @@ int LCW_Uncomp(void const * source, void * dest, unsigned long ) word_data = (word_data << 24) + (word_data << 16) + (word_data << 8) + word_data; source_ptr += 3; - copy_ptr = dest_ptr + 4 - ((unsigned) dest_ptr & 0x3); + copy_ptr = dest_ptr + 4 - ((unsigned long) dest_ptr & 0x3); count -= (copy_ptr - dest_ptr); while (dest_ptr < copy_ptr) *dest_ptr++ = data; @@ -168,7 +168,7 @@ int LCW_Uncomp(void const * source, void * dest, unsigned long ) } -#if defined(_MSC_VER) +#if defined(_MSC_VER) && defined(_M_IX86) /*********************************************************************************************** @@ -439,6 +439,6 @@ int LCW_Comp(void const * source, void * dest, int datasize) #endif return(retval); } -#endif +#endif // defined(_MSC_VER) && defined(_M_IX86) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mempool.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mempool.h index 9b1c4e5902..89059ab0ab 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mempool.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mempool.h @@ -53,7 +53,7 @@ #include "bittype.h" #include "wwdebug.h" #include "mutex.h" -#include +#include #include #include @@ -157,9 +157,14 @@ class AutoPoolClass ** Macro to declare the allocator for your class. Put this in the cpp file for ** the class. */ +#if defined(_MSC_VER) && _MSC_VER < 1300 #define DEFINE_AUTO_POOL(T,BLOCKSIZE) \ -ObjectPoolClass AutoPoolClass::Allocator; - +ObjectPoolClass AutoPoolClass::Allocator +#else +#define DEFINE_AUTO_POOL(T,BLOCKSIZE) \ +template<>\ +ObjectPoolClass AutoPoolClass::Allocator = {} +#endif /*********************************************************************************************** * ObjectPoolClass::ObjectPoolClass -- constructor for ObjectPoolClass * diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/misc.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/misc.h index e20bdad9e3..9579a70864 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/misc.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/misc.h @@ -38,11 +38,14 @@ #define MISC_H #include "win.h" +#ifdef _WIN32 #include "ddraw.h" +#endif extern unsigned char CurrentPalette[768]; extern bool Debug_Windowed; +#ifdef _WIN32 extern LPDIRECTDRAWSURFACE PaletteSurface; /*========================= C++ Routines ==================================*/ @@ -53,6 +56,7 @@ extern LPDIRECTDRAWSURFACE PaletteSurface; void Prep_Direct_Draw(void); void Process_DD_Result(HRESULT result, int display_ok_msg); bool Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel); +#endif void Reset_Video_Mode(void); unsigned Get_Free_Video_Memory(void); void Wait_Blit(void); @@ -147,8 +151,8 @@ void __cdecl Shake_Screen(int shakes); /* The following prototypes are for the file: DETPROC.ASM */ /*=========================================================================*/ -extern WORD __cdecl Processor(void); -extern WORD __cdecl Operating_System(void); +extern short __cdecl Processor(void); +extern short __cdecl Operating_System(void); extern int __cdecl Clip_Rect ( int * x , int * y , int * dw , int * dh , int width , int height ) ; @@ -161,7 +165,7 @@ extern int __cdecl Confine_Rect ( int * x , int * y , int dw , int dh , /* The following prototypes are for the file: OPSYS.ASM */ /*=========================================================================*/ -extern WORD OperationgSystem; +extern short OperationgSystem; #ifdef __cplusplus } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp index 9ec127eced..cada7f18b9 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp @@ -320,7 +320,9 @@ MixFileFactoryClass::Flush_Changes (void) // char drive[_MAX_DRIVE] = { 0 }; char dir[_MAX_DIR] = { 0 }; + #ifdef _WIN32 ::_splitpath (MixFilename, drive, dir, NULL, NULL); + #endif StringClass path = drive; path += dir; @@ -370,8 +372,10 @@ MixFileFactoryClass::Flush_Changes (void) // // Delete the old mix file and rename the new one // + #ifdef _WIN32 ::DeleteFile (MixFilename); ::MoveFile (full_path, MixFilename); + #endif // // Reset the lists @@ -398,10 +402,12 @@ MixFileFactoryClass::Get_Temp_Filename (const char *path, StringClass &full_path // for (int index = 0; index < 20; index ++) { full_path.Format ("%s%.2d.dat", (const char *)temp_path, index + 1); + #ifdef _WIN32 if (GetFileAttributes (full_path) == 0xFFFFFFFF) { retval = true; break; } + #endif } return retval; @@ -657,6 +663,7 @@ void MixFileCreator::Add_File( const char * filename, FileClass *file ) */ void Add_Files( const char * dir, MixFileCreator & mix ) { +#ifdef _WIN32 BOOL bcontinue = TRUE; HANDLE hfile_find; WIN32_FIND_DATA find_info = {0}; @@ -682,6 +689,9 @@ void Add_Files( const char * dir, MixFileCreator & mix ) // WWDEBUG_SAY(( "Adding file from %s %s\n", source, name )); } } +#else + #pragma message("Add_Files not implemented for this platform") +#endif } void Setup_Mix_File( void ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mmsys.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mmsys.h index 64b7c0c4bc..8f361b7114 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mmsys.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mmsys.h @@ -44,8 +44,10 @@ ** This header just includes mmsystem.h with warning 4201 disabled */ +#ifdef _WIN32 #pragma warning(disable:4201) #include #pragma warning(default:4201) +#endif #endif // MMSYS_H diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mpu.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mpu.cpp index d7530c6fca..bb523d34be 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mpu.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mpu.cpp @@ -40,6 +40,7 @@ #include "MPU.H" #include "math.h" #include +#include typedef union { LARGE_INTEGER LargeInt; @@ -88,12 +89,18 @@ unsigned long Get_CPU_Clock(unsigned long & high) { int h; int l; +#if defined(_MSC_VER) && _MSC_VER < 1300 __asm { _emit 0Fh _emit 31h mov [h],edx mov [l],eax } +#else + auto tsc = _rdtsc(); + h = tsc >> 32; + l = tsc & 0xFFFFFFFF; +#endif high = h; return(l); } @@ -126,12 +133,18 @@ static unsigned long TSC_High; void RDTSC(void) { +#if defined(_MSC_VER) && _MSC_VER < 1300 _asm { ASM_RDTSC; mov TSC_Low, eax mov TSC_High, edx } +#else + auto TSC = _rdtsc(); + TSC_Low = TSC & 0xFFFFFFFF; + TSC_High = TSC >> 32; +#endif } @@ -197,8 +210,12 @@ int Get_RDTSC_CPU_Speed(void) QueryPerformanceCounter(&t1); } +#if defined(_MSC_VER) && _MSC_VER < 1300 ASM_RDTSC; _asm mov stamp0, EAX +#else + stamp0 = _rdtsc(); +#endif t0.LowPart = t1.LowPart; // Reset Initial Time t0.HighPart = t1.HighPart; @@ -211,9 +228,12 @@ int Get_RDTSC_CPU_Speed(void) QueryPerformanceCounter(&t1); } +#if defined(_MSC_VER) && _MSC_VER < 1300 ASM_RDTSC; _asm mov stamp1, EAX - +#else + stamp1 = _rdtsc(); +#endif cycles = stamp1 - stamp0; // # of cycles passed between reads diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp index f63cc81e3b..946090a282 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.cpp @@ -18,8 +18,9 @@ #include "mutex.h" #include "wwdebug.h" +#ifdef _WIN32 #include - +#endif // ---------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.h index 12bb5b5ad2..e95e56fde6 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mutex.h @@ -26,6 +26,9 @@ #include "always.h" #include "thread.h" +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#include +#endif // Always use mutex or critical section when accessing the same data from multiple threads! @@ -117,11 +120,20 @@ class CriticalSectionClass class FastCriticalSectionClass { - unsigned Flag; +#if defined(_MSC_VER) && _MSC_VER < 1300 + // TheSuperHackers @info Mauller 30/03/2025 Added volatile to prevent reordering of critical sections if inlined + volatile unsigned Flag; +#else + std::atomic_flag Flag{}; +#endif public: // Name can (and usually should) be NULL. Use name only if you wish to create a globally unique mutex - FastCriticalSectionClass() : Flag(0) {} + FastCriticalSectionClass() +#if defined(_MSC_VER) && _MSC_VER < 1300 + : Flag(0) +#endif + {} class LockClass { @@ -129,7 +141,19 @@ class FastCriticalSectionClass public: __forceinline LockClass(FastCriticalSectionClass& critical_section) : cs(critical_section) { - unsigned& nFlag=cs.Flag; + lock(); + } + + ~LockClass() + { + unlock(); + } + + private: + + void lock() { +#if defined(_MSC_VER) && _MSC_VER < 1300 + volatile unsigned& nFlag=cs.Flag; #define ts_lock _emit 0xF0 assert(((unsigned)&nFlag % 4) == 0); @@ -159,14 +183,22 @@ class FastCriticalSectionClass BitSet: ; - } +#else + while (cs.Flag.test_and_set(std::memory_order_acquire)) { + cs.Flag.wait(true, std::memory_order_relaxed); + } +#endif + } - ~LockClass() - { + void unlock() { +#if defined(_MSC_VER) && _MSC_VER < 1300 cs.Flag=0; - } - - private: +#else + cs.Flag.clear(std::memory_order_release); + cs.Flag.notify_one(); +#endif + } + LockClass &operator=(const LockClass&); LockClass(const LockClass&); }; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/osdep.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/osdep.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/random.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/random.cpp index af8602b406..055598857c 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/random.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/random.cpp @@ -233,7 +233,7 @@ int Random2Class::operator() (int minval, int maxval) ** that the algorithm is not vulnerable to being primed with a weak seed ** and thus prevents the algorithm from breaking down as a result. */ -int Random3Class::Mix1[20] = { +unsigned int Random3Class::Mix1[20] = { 0x0baa96887, 0x01e17d32c, 0x003bcdc3c, 0x00f33d1b2, 0x076a6491d, 0x0c570d85d, 0x0e382b1e3, 0x078db4362, 0x07439a9d4, 0x09cea8ac5, 0x089537c5c, 0x02588f55d, @@ -241,7 +241,7 @@ int Random3Class::Mix1[20] = { 0x03ea5cc8c, 0x0d26a0f74, 0x0f3a9222b, 0x048aad7e4 }; -int Random3Class::Mix2[20] = { +unsigned int Random3Class::Mix2[20] = { 0x04b0f3b58, 0x0e874f0c3, 0x06955c5a6, 0x055a7ca46, 0x04d9a9d86, 0x0fe28a195, 0x0b1ca7865, 0x06b235751, 0x09a997a61, 0x0aa6e95c8, 0x0aaa98ee1, 0x05af9154c, diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp index 7281c6f57c..8594e650bd 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/rawfile.cpp @@ -54,7 +54,6 @@ #include "always.h" #include "RAWFILE.H" -#include //#include #include #include @@ -66,6 +65,8 @@ #ifdef _UNIX #include #include +#else +#include #endif @@ -554,12 +555,16 @@ bool RawFileClass::Is_Available(int forced) */ int closeok; #ifdef _UNIX - closeok=((fclose(Handle)==0)?TRUE:FALSE); + closeok=((fclose(Handle)==0)?true:false); #else closeok=CloseHandle(Handle); #endif if (! closeok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } Handle = NULL_HANDLE; @@ -595,13 +600,17 @@ void RawFileClass::Close(void) */ int closeok; #ifdef _UNIX - closeok=(fclose(Handle)==0)?TRUE:FALSE; + closeok=(fclose(Handle)==0)?true:false; #else closeok=CloseHandle(Handle); #endif if (!closeok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* @@ -667,10 +676,10 @@ int RawFileClass::Read(void * buffer, int size) while (size > 0) { bytesread = 0; - int readok=TRUE; + int readok=true; #ifdef _UNIX - readok=TRUE; + readok=true; bytesread=fread(buffer,1,size,Handle); if ((bytesread == 0)&&( ! feof(Handle))) readok=ferror(Handle); @@ -682,7 +691,11 @@ int RawFileClass::Read(void * buffer, int size) if (! readok) { size -= bytesread; total += bytesread; + #ifdef _UNIX + Error(errno, true, Filename); + #else Error(GetLastError(), true, Filename); + #endif continue; } size -= bytesread; @@ -735,17 +748,21 @@ int RawFileClass::Write(void const * buffer, int size) opened = true; } - int writeok=TRUE; + int writeok=true; #ifdef _UNIX byteswritten = fwrite(buffer, 1, size, Handle); if (byteswritten != size) - writeok = FALSE; + writeok = false; #else writeok=WriteFile(Handle, buffer, size, &(unsigned long&)byteswritten, NULL); #endif if (! writeok) { + #ifdef _UNIX + Error(errno, true, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* @@ -878,18 +895,18 @@ int RawFileClass::Size(void) */ if (Is_Open()) { - #ifdef _UNIX - fpos_t curpos,startpos,endpos; - fgetpos(Handle,&curpos); + #ifdef _UNIX + long curpos,startpos,endpos; + curpos = ftell(Handle); fseek(Handle,0,SEEK_SET); - fgetpos(Handle,&startpos); + startpos = ftell(Handle); fseek(Handle,0,SEEK_END); - fgetpos(Handle,&endpos); + endpos = ftell(Handle); size=endpos-startpos; - fsetpos(Handle,&curpos); + fseek(Handle,curpos, SEEK_SET); #else size = GetFileSize(Handle, NULL); #endif @@ -898,7 +915,11 @@ int RawFileClass::Size(void) ** If there was in internal error, then call the error function. */ if (size == 0xFFFFFFFF) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } } else { @@ -1010,13 +1031,17 @@ int RawFileClass::Delete(void) int deleteok; #ifdef _UNIX - deleteok=(unlink(Filename)==0)?TRUE:FALSE; + deleteok=(unlink(Filename)==0)?true:false; #else deleteok=DeleteFile(Filename); #endif if (! deleteok) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif return(false); } break; @@ -1225,7 +1250,11 @@ int RawFileClass::Raw_Seek(int pos, int dir) ** If there was an error in the seek, then bail with an error condition. */ if (pos == 0xFFFFFFFF) { + #ifdef _UNIX + Error(errno, false, Filename); + #else Error(GetLastError(), false, Filename); + #endif } /* diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp index 39dd095ef0..12f3a69f07 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/refcount.cpp @@ -40,8 +40,8 @@ #include "refcount.h" -#include - +// SuperHackers: Cross-platform __debugbreak() implementation +#include #ifndef NDEBUG @@ -174,7 +174,7 @@ void RefCountClass::Add_Ref(void) const // See if programmer set break on for a specific address. if (this == BreakOnReference) { - DebugBreak(); // trigger the debugger + __debugbreak(); // trigger the debugger } Inc_Total_Refs(this); } @@ -201,7 +201,7 @@ void RefCountClass::Dec_Total_Refs(const RefCountClass * obj) // See if programmer set break on for a specific address. if (obj == BreakOnReference) { - DebugBreak(); // trigger the debugger + __debugbreak(); // trigger the debugger } } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.h index d48cc6a89e..3bd4dc9f39 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.h @@ -43,7 +43,7 @@ ** November of '94. Until the compiler supports this, use the following ** definition. */ -#include +#include #include "always.h" #include "bool.h" #include diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/srandom.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/srandom.cpp index f96e0d0483..cf01b7c070 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/srandom.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/srandom.cpp @@ -28,7 +28,6 @@ #ifdef _UNIX #include "osdep.h" #include -#include extern "C" { int sysinfo(struct sysinfo *info); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/systimer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/systimer.h index 44d03a8ba1..4c8ea01624 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/systimer.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/systimer.h @@ -38,11 +38,25 @@ #ifndef _SYSTIMER_H #include "always.h" +#ifdef _WIN32 #include #include "mmsys.h" #define TIMEGETTIME SystemTime.Get #define MS_TIMER_SECOND 1000 +#else +#include + +inline unsigned long systimerGetMS(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +#define TIMEGETTIME systimerGetMS +#define MS_TIMER_SECOND 1000 +#endif /* ** Class that just wraps around timeGetTime() diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/thread.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/thread.cpp index c6c1f20561..dd3f355580 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/thread.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/thread.cpp @@ -21,8 +21,10 @@ #include "thread.h" #include "Except.h" #include "wwdebug.h" +#ifdef _WIN32 #include #include +#endif #pragma warning ( push ) #pragma warning ( disable : 4201 ) #include "systimer.h" diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp index c3c86376da..5ab160236f 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.cpp @@ -244,7 +244,7 @@ WideStringClass::Free_String (void) // /////////////////////////////////////////////////////////////////// int _cdecl -WideStringClass::Format_Args (const WCHAR *format, const va_list & arg_list ) +WideStringClass::Format_Args (const WCHAR *format, va_list arg_list ) { if (format == NULL) { return 0; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.h index 86a6969a50..5d31aa0d16 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/widestring.h @@ -114,7 +114,7 @@ class WideStringClass void Erase (int start_index, int char_count); int _cdecl Format (const WCHAR *format, ...); - int _cdecl Format_Args (const WCHAR *format, const va_list & arg_list ); + int _cdecl Format_Args (const WCHAR *format, va_list arg_list ); bool Convert_From (const char *text); bool Convert_To (StringClass &string); bool Convert_To (StringClass &string) const; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/win.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/win.h index cf9e4e05d8..6f44f74289 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/win.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/win.h @@ -54,6 +54,7 @@ #pragma warning(push, 3) #endif +#ifdef _WIN32 // this define should also be in the DSP just in case someone includes windows stuff directly #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -64,6 +65,7 @@ //#include //#include //#include +#endif #if (_MSC_VER >= 1200) #pragma warning(pop) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp index 8d724d7f97..621296952c 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwfile.cpp @@ -39,6 +39,9 @@ #include #include "WWFILE.H" +// SuperHackers: For _vsnprintf +#include + #pragma warning(disable : 4514) int FileClass::Printf(char *str, ...) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp index 83509c100b..0661b4df98 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.cpp @@ -102,7 +102,7 @@ StringClass::Get_String (int length, bool is_temp) // // Grab this unused buffer for our string // - unsigned temp_string=reinterpret_cast(m_TempStrings); + unsigned long temp_string=reinterpret_cast(m_TempStrings); temp_string+=MAX_TEMP_BYTES*MAX_TEMP_STRING; temp_string&=~(MAX_TEMP_BYTES*MAX_TEMP_STRING-1); temp_string+=index*MAX_TEMP_BYTES; @@ -197,8 +197,8 @@ StringClass::Free_String (void) { if (m_Buffer != m_EmptyString) { - unsigned buffer_base=reinterpret_cast(m_Buffer-sizeof (StringClass::_HEADER)); - unsigned temp_base=reinterpret_cast(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING); + unsigned long buffer_base=reinterpret_cast(m_Buffer-sizeof (StringClass::_HEADER)); + unsigned long temp_base=reinterpret_cast(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING); if ((buffer_base>>11)==(temp_base>>11)) { m_Buffer[0] = 0; @@ -238,7 +238,7 @@ StringClass::Free_String (void) // /////////////////////////////////////////////////////////////////// int _cdecl -StringClass::Format_Args (const TCHAR *format, const va_list & arg_list ) +StringClass::Format_Args (const TCHAR *format, va_list arg_list ) { // // Make a guess at the maximum length of the resulting string @@ -321,7 +321,8 @@ bool StringClass::Copy_Wide (const WCHAR *source) if (source != NULL) { int length; - BOOL unmapped; + // Use int to be compatible with the BOOL type in VC6 + int unmapped; length = WideCharToMultiByte (CP_ACP, 0 , source, -1, NULL, 0, NULL, &unmapped); if (length > 0) { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.h index a760714362..78fc40575a 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/wwstring.h @@ -46,7 +46,9 @@ #include "win.h" #include #include +#ifdef _WIN32 #include +#endif #include "trim.h" #include "wwdebug.h" #ifdef _UNIX @@ -122,7 +124,7 @@ class StringClass void Erase (int start_index, int char_count); int _cdecl Format (const TCHAR *format, ...); - int _cdecl Format_Args (const TCHAR *format, const va_list & arg_list ); + int _cdecl Format_Args (const TCHAR *format, va_list arg_list ); // Trim leading and trailing whitespace characters (values <= 32) void Trim(void); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp index 5deccc1d55..a56938e626 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp @@ -65,7 +65,9 @@ #include "matrix3.h" #include "matrix4.h" #include "quat.h" +#ifdef _WIN32 #include "d3dx8math.h" +#endif // some static matrices which are sometimes useful const Matrix3D Matrix3D::Identity @@ -520,7 +522,9 @@ void Matrix3D::Get_Inverse(Matrix3D & inv) const Matrix4x4 mat4Inv; float det; +#ifdef _WIN32 D3DXMatrixInverse((D3DXMATRIX *)&mat4Inv, &det, (D3DXMATRIX*)&mat4); +#endif inv.Row[0][0]=mat4Inv[0][0]; inv.Row[0][1]=mat4Inv[0][1]; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h index 29f97f6d61..9f3a1b8795 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h @@ -188,6 +188,7 @@ class Vector3 // Color Conversion WWINLINE unsigned long Convert_To_ABGR( void ) const; WWINLINE unsigned long Convert_To_ARGB( void ) const; + WWINLINE unsigned long Convert_To_ARGB( float alpha ) const; }; @@ -912,5 +913,13 @@ WWINLINE unsigned long Vector3::Convert_To_ARGB( void ) const (unsigned(Z*255.0f)); } +WWINLINE unsigned long Vector3::Convert_To_ARGB( float alpha ) const +{ + return (unsigned(alpha * 255)<<24) | + (unsigned(X*255.0f)<<16) | + (unsigned(Y*255.0f)<<8) | + (unsigned(Z*255.0f)); +} + #endif /* Vector3_H */ diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h index 4397cf6d31..c0e3b001f4 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h @@ -43,10 +43,6 @@ #ifndef POINTERREMAP_H #define POINTERREMAP_H -#ifdef _UNIX -#include "osdep/osdep.h" -#endif - #include "always.h" #include "Vector.H" diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp index 35cddf8fee..953ff7990e 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp @@ -46,7 +46,6 @@ #include "wwprofile.h" #pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union -#include #include "systimer.h" diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp index 8f244326bc..a27d4e3ed0 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp @@ -119,8 +119,14 @@ bool cMiscUtil::File_Is_Read_Only(LPCSTR filename) { WWASSERT(filename != NULL); +#ifdef _WIN32 DWORD attributes = ::GetFileAttributes(filename); return ((attributes != 0xFFFFFFFF) && (attributes & FILE_ATTRIBUTE_READONLY)); +#else + bool readable = access(filename, R_OK) == 0; + bool writable = access(filename, W_OK) == 0; + return (readable && !writable); +#endif } //----------------------------------------------------------------------------- @@ -165,6 +171,7 @@ void cMiscUtil::Get_File_Id_String(LPCSTR filename, StringClass & str) // WWDEBUG_SAY(("cMiscUtil::Get_File_Id_String for %s\n", filename)); +#ifdef _WIN32 // // Get size // @@ -211,7 +218,7 @@ void cMiscUtil::Get_File_Id_String(LPCSTR filename, StringClass & str) // Put all this data into a string // str.Format("%s %d %d", working_filename, filesize, time_date_stamp); - +#endif //WWDEBUG_SAY(("File id string: %s\n", str)); } @@ -220,7 +227,11 @@ void cMiscUtil::Remove_File(LPCSTR filename) { WWASSERT(filename != NULL); +#ifdef _WIN32 ::DeleteFile(filename); +#else + ::remove(filename); +#endif } diff --git a/GeneralsMD/Code/Libraries/Source/profile/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/profile/CMakeLists.txt index c6f6495ae3..5040a8a460 100644 --- a/GeneralsMD/Code/Libraries/Source/profile/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/profile/CMakeLists.txt @@ -28,5 +28,6 @@ target_include_directories(z_profile INTERFACE target_link_libraries(z_profile PRIVATE gz_config - zi_libraries_include + gz_utility + zi_utility ) diff --git a/GeneralsMD/Code/Libraries/Source/profile/internal.h b/GeneralsMD/Code/Libraries/Source/profile/internal.h index de421f4ab6..439152214c 100644 --- a/GeneralsMD/Code/Libraries/Source/profile/internal.h +++ b/GeneralsMD/Code/Libraries/Source/profile/internal.h @@ -38,13 +38,20 @@ #include "internal_cmd.h" #include "internal_result.h" +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#include +#include +#endif + class ProfileFastCS { ProfileFastCS(const ProfileFastCS&); - ProfileFastCS& operator=(const ProfileFastCS&); + ProfileFastCS& operator=(const ProfileFastCS&) {}; + + static HANDLE testEvent; +#if defined(_MSC_VER) && _MSC_VER < 1300 volatile unsigned m_Flag; - static HANDLE testEvent; void ThreadSafeSetFlag() { @@ -79,11 +86,32 @@ class ProfileFastCS m_Flag(0) { } +#else + + volatile std::atomic_flag Flag{}; + + void ThreadSafeSetFlag() + { + while (Flag.test_and_set(std::memory_order_acquire)) { + Flag.wait(true, std::memory_order_relaxed); + } + } + + void ThreadSafeClearFlag() + { + Flag.clear(std::memory_order_release); + Flag.notify_one(); + } + +public: + ProfileFastCS(void) {} + +#endif class Lock { Lock(const Lock&); - Lock& operator=(const Lock&); + Lock& operator=(const Lock&) {}; ProfileFastCS& CriticalSection; @@ -109,6 +137,7 @@ void ProfileFreeMemory(void *ptr); __forceinline void ProfileGetTime(__int64 &t) { +#if defined(_MSC_VER) && _MSC_VER < 1300 _asm { mov ecx,[t] @@ -120,6 +149,9 @@ __forceinline void ProfileGetTime(__int64 &t) pop edx pop eax }; +#else + t = static_cast<__int64>(_rdtsc()); +#endif } #endif // INTERNAL_H diff --git a/GeneralsMD/Code/Main/CMakeLists.txt b/GeneralsMD/Code/Main/CMakeLists.txt index 4c4f7638bc..8da711ed7f 100644 --- a/GeneralsMD/Code/Main/CMakeLists.txt +++ b/GeneralsMD/Code/Main/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries(z_generals PRIVATE z_gameengine z_gameenginedevice z_profile - zi_libraries_include + zi_utility zi_libraries_source ) diff --git a/GeneralsMD/Code/Tools/Autorun/CMakeLists.txt b/GeneralsMD/Code/Tools/Autorun/CMakeLists.txt index 6a0adbaac5..3ec43bcae4 100644 --- a/GeneralsMD/Code/Tools/Autorun/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/Autorun/CMakeLists.txt @@ -57,7 +57,7 @@ macro(setup_autorun appname) gz_config gz_utility winmm - zi_libraries_include + zi_utility ) if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") diff --git a/GeneralsMD/Code/Tools/CRCDiff/debug.cpp b/GeneralsMD/Code/Tools/CRCDiff/debug.cpp index 7b828e0408..94f0c942cf 100644 --- a/GeneralsMD/Code/Tools/CRCDiff/debug.cpp +++ b/GeneralsMD/Code/Tools/CRCDiff/debug.cpp @@ -20,11 +20,11 @@ // Minmal debug info // Author: Matthew D. Campbell, Sept 2002 -#include #include "debug.h" #include #ifdef DEBUG +#include void DebugLog(const char *fmt, ...) { diff --git a/GeneralsMD/Code/Tools/Compress/CMakeLists.txt b/GeneralsMD/Code/Tools/Compress/CMakeLists.txt index dc867ecb88..f10c568639 100644 --- a/GeneralsMD/Code/Tools/Compress/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/Compress/CMakeLists.txt @@ -12,7 +12,7 @@ target_sources(z_compress PRIVATE ${COMRPESS_SRC}) target_link_libraries(z_compress PRIVATE gz_config z_compression - zi_libraries_include + zi_utility zi_libraries_source ) diff --git a/GeneralsMD/Code/Tools/Compress/Compress.cpp b/GeneralsMD/Code/Tools/Compress/Compress.cpp index 3f77d2f40f..9ba1279303 100644 --- a/GeneralsMD/Code/Tools/Compress/Compress.cpp +++ b/GeneralsMD/Code/Tools/Compress/Compress.cpp @@ -54,7 +54,7 @@ void dumpHelp(const char *exe) } } -void main(int argc, char **argv) +int main(int argc, char **argv) { std::string inFile = ""; std::string outFile = ""; @@ -65,7 +65,7 @@ void main(int argc, char **argv) if ( !stricmp(argv[i], "-help") ) { dumpHelp(argv[0]); - exit(0); + return EXIT_SUCCESS; } if ( !strcmp(argv[i], "-in") ) @@ -106,7 +106,7 @@ void main(int argc, char **argv) if (inFile.empty()) { dumpHelp(argv[0]); - exit(0); + return EXIT_SUCCESS; } DEBUG_LOG(("IN:'%s' OUT:'%s' Compression:'%s'\n", @@ -119,7 +119,7 @@ void main(int argc, char **argv) if (!fp) { DEBUG_LOG(("Cannot open '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } fseek(fp, 0, SEEK_END); int size = ftell(fp); @@ -131,14 +131,14 @@ void main(int argc, char **argv) if (numRead != 8) { DEBUG_LOG(("Cannot read header from '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } CompressionType usedType = CompressionManager::getCompressionType(data, 8); if (usedType == COMPRESSION_NONE) { DEBUG_LOG(("No compression on '%s'\n", inFile.c_str())); - return; + return EXIT_FAILURE; } int uncompressedSize = CompressionManager::getUncompressedSize(data, 8); @@ -147,8 +147,9 @@ void main(int argc, char **argv) inFile.c_str(), CompressionManager::getCompressionNameByType(usedType), uncompressedSize, size, size/(double)(uncompressedSize+0.1)*100.0)); - return; + return EXIT_SUCCESS; } // compress file + return EXIT_FAILURE; } diff --git a/GeneralsMD/Code/Tools/GUIEdit/CMakeLists.txt b/GeneralsMD/Code/Tools/GUIEdit/CMakeLists.txt index 4d403462e8..3d4e599bac 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/GUIEdit/CMakeLists.txt @@ -59,7 +59,7 @@ target_link_libraries(z_guiedit PRIVATE z_gameenginedevice z_profile z_wwvegas - zi_libraries_include + zi_utility ) if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") diff --git a/GeneralsMD/Code/Tools/ImagePacker/CMakeLists.txt b/GeneralsMD/Code/Tools/ImagePacker/CMakeLists.txt index c0b5f56f0a..819c805423 100644 --- a/GeneralsMD/Code/Tools/ImagePacker/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/ImagePacker/CMakeLists.txt @@ -37,7 +37,7 @@ target_link_libraries(z_imagepacker PRIVATE z_gameengine z_gameenginedevice z_profile - zi_libraries_include + zi_utility ) if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") diff --git a/GeneralsMD/Code/Tools/MapCacheBuilder/CMakeLists.txt b/GeneralsMD/Code/Tools/MapCacheBuilder/CMakeLists.txt index 9f606aea66..ced7305a5c 100644 --- a/GeneralsMD/Code/Tools/MapCacheBuilder/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/MapCacheBuilder/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries(z_mapcachebuilder PRIVATE z_gameengine z_gameenginedevice z_profile - zi_libraries_include + zi_utility ) if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") diff --git a/GeneralsMD/Code/Tools/PATCHGET/CMakeLists.txt b/GeneralsMD/Code/Tools/PATCHGET/CMakeLists.txt index 9207a7058b..695713fe09 100644 --- a/GeneralsMD/Code/Tools/PATCHGET/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/PATCHGET/CMakeLists.txt @@ -32,7 +32,7 @@ macro(setup_patchgrabber appname) z_gameenginedevice z_profile z_wwvegas - zi_libraries_include + zi_utility ) target_compile_definitions(${appname} PRIVATE diff --git a/GeneralsMD/Code/Tools/ParticleEditor/CMakeLists.txt b/GeneralsMD/Code/Tools/ParticleEditor/CMakeLists.txt index ea36aa485d..dc9a716ec8 100644 --- a/GeneralsMD/Code/Tools/ParticleEditor/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/ParticleEditor/CMakeLists.txt @@ -48,7 +48,7 @@ target_link_libraries(z_particleeditor PRIVATE z_debug z_profile zi_gameengine_include - zi_libraries_include + zi_utility zi_libraries_source_wwvegas zi_libraries_source_wwvegas_wwlib ) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/CMakeLists.txt b/GeneralsMD/Code/Tools/WorldBuilder/CMakeLists.txt index 78b064ab92..3e00eb37e1 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/CMakeLists.txt +++ b/GeneralsMD/Code/Tools/WorldBuilder/CMakeLists.txt @@ -180,7 +180,7 @@ set(WORLDBUILDER_SRC "include/TeamIdentity.h" "include/TeamReinforcement.h" "include/teamsdialog.h" - "include/terrainmaterial.h" + "include/TerrainMaterial.h" "include/TerrainModal.h" "include/TerrainSwatches.h" "include/TileTool.h" @@ -222,7 +222,7 @@ target_link_libraries(z_worldbuilder PRIVATE z_profile zi_gameengine_include zi_gameenginedevice_include - zi_libraries_include + zi_utility ) if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") diff --git a/GeneralsMD/Code/Tools/timingTest/timingTest.cpp b/GeneralsMD/Code/Tools/timingTest/timingTest.cpp index ff21ff0d96..1c98cfb7cf 100644 --- a/GeneralsMD/Code/Tools/timingTest/timingTest.cpp +++ b/GeneralsMD/Code/Tools/timingTest/timingTest.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include double s_ticksPerSec = 0.0f; @@ -33,6 +34,7 @@ char buffer[1024]; //------------------------------------------------------------------------------------------------- void GetPrecisionTimer(INT64* t) { +#if defined(_MSC_VER) && _MSC_VER < 1300 // CPUID is needed to force serialization of any previous instructions. __asm { @@ -41,6 +43,9 @@ void GetPrecisionTimer(INT64* t) MOV [ECX], EAX MOV [ECX+4], EDX } +#else + *t = _rdtsc(); +#endif } //------------------------------------------------------------------------------------------------- diff --git a/cmake/config.cmake b/cmake/config.cmake index 1dbc33386e..937f1f8ccb 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -66,6 +66,10 @@ if(MSVC) target_compile_definitions(gz_config INTERFACE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS $<$:_DEBUG_CRT>) endif() +if(UNIX) + target_compile_definitions(gz_config INTERFACE _UNIX) +endif() + if(GENZH_BUILD_DEBUG) target_compile_definitions(gz_config INTERFACE _DEBUG WWDEBUG DEBUG) else() diff --git a/cmake/gamespy.cmake b/cmake/gamespy.cmake index ef68d1fe50..4e300925aa 100644 --- a/cmake/gamespy.cmake +++ b/cmake/gamespy.cmake @@ -8,3 +8,6 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(gamespy) +if(UNIX AND NOT APPLE) + target_compile_definitions(gscommon PUBLIC -D_LINUX) +endif() \ No newline at end of file