From 12e8b991b399812bb4421dc6dbcad87bf55d7add Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 22:39:19 -0700 Subject: [PATCH 01/21] Move the platform identification code out of SE_InitEngine to PlatformIdentification --- Sources/Engine/Engine.cpp | 123 +++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index c07171f..dc81201 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -320,7 +320,68 @@ static void SanityCheckTypes(void) ASSERT(num == 0x01); #endif } +// don't want to export this function +void PlatformIdentification() { +#if (defined PLATFORM_WIN32) + OSVERSIONINFO osv; + memset(&osv, 0, sizeof(osv)); + osv.dwOSVersionInfoSize = sizeof(osv); + if (GetVersionEx(&osv)) { + switch (osv.dwPlatformId) { + case VER_PLATFORM_WIN32s: sys_strOS = "Win32s"; break; + case VER_PLATFORM_WIN32_WINDOWS: sys_strOS = "Win9x"; break; + case VER_PLATFORM_WIN32_NT: sys_strOS = "WinNT"; break; + default: sys_strOS = "Unknown\n"; break; + } + sys_iOSMajor = osv.dwMajorVersion; + sys_iOSMinor = osv.dwMinorVersion; + sys_iOSBuild = osv.dwBuildNumber & 0xFFFF; + sys_strOSMisc = osv.szCSDVersion; + + CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); + CPrintF(TRANSV(" Version: %d.%d, build %d\n"), + osv.dwMajorVersion, osv.dwMinorVersion, osv.dwBuildNumber & 0xFFFF); + CPrintF(TRANSV(" Misc: %s\n"), osv.szCSDVersion); + } else { + CPrintF(TRANSV("Error getting OS info: %s\n"), GetWindowsError(GetLastError()) ); + } + +#elif (defined PLATFORM_MACOSX) + STUBBED("Use some Gestalt replacement, or whatever"); + #if 0 + long osver = 0x0000; + OSErr err = Gestalt(gestaltSystemVersion, &osver); + if (err != noErr) + osver = 0x0000; + + sys_iOSMajor = ((osver & 0x0F00) >> 8) + (((osver & 0xF000) >> 12) * 10); + sys_iOSMinor = ((osver & 0x00F0) >> 4); + sys_iOSBuild = ((osver & 0x000F) >> 0); + #else + sys_iOSMajor = 10; // !!! FIXME: just flatly false. + sys_iOSMinor = 6; + sys_iOSBuild = 0; + #endif + + sys_strOS = "Mac OS X"; + sys_strOSMisc = "Mac OS"; + CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); + CPrintF(TRANSV(" Version: %d.%d.%d\n"), + (int)sys_iOSMajor, (int)sys_iOSMinor, (int)sys_iOSBuild); + +#elif (defined PLATFORM_UNIX) // !!! FIXME: rcg10082001 what to do with this? + sys_iOSMajor = 1; + sys_iOSMinor = 0; + sys_iOSBuild = 0; + sys_strOS = "Unix"; + sys_strOSMisc = "Unix"; + CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); + +#else + #error Do something with this for your platform. +#endif +} // startup engine ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) { @@ -412,67 +473,9 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) // report os info CPrintF(TRANSV("Examining underlying OS...\n")); - + + PlatformIdentfication(); // !!! FIXME: Abstract this somehow. -#if (defined PLATFORM_WIN32) - OSVERSIONINFO osv; - memset(&osv, 0, sizeof(osv)); - osv.dwOSVersionInfoSize = sizeof(osv); - if (GetVersionEx(&osv)) { - switch (osv.dwPlatformId) { - case VER_PLATFORM_WIN32s: sys_strOS = "Win32s"; break; - case VER_PLATFORM_WIN32_WINDOWS: sys_strOS = "Win9x"; break; - case VER_PLATFORM_WIN32_NT: sys_strOS = "WinNT"; break; - default: sys_strOS = "Unknown\n"; break; - } - - sys_iOSMajor = osv.dwMajorVersion; - sys_iOSMinor = osv.dwMinorVersion; - sys_iOSBuild = osv.dwBuildNumber & 0xFFFF; - sys_strOSMisc = osv.szCSDVersion; - - CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); - CPrintF(TRANSV(" Version: %d.%d, build %d\n"), - osv.dwMajorVersion, osv.dwMinorVersion, osv.dwBuildNumber & 0xFFFF); - CPrintF(TRANSV(" Misc: %s\n"), osv.szCSDVersion); - } else { - CPrintF(TRANSV("Error getting OS info: %s\n"), GetWindowsError(GetLastError()) ); - } - -#elif (defined PLATFORM_MACOSX) - STUBBED("Use some Gestalt replacement, or whatever"); - #if 0 - long osver = 0x0000; - OSErr err = Gestalt(gestaltSystemVersion, &osver); - if (err != noErr) - osver = 0x0000; - - sys_iOSMajor = ((osver & 0x0F00) >> 8) + (((osver & 0xF000) >> 12) * 10); - sys_iOSMinor = ((osver & 0x00F0) >> 4); - sys_iOSBuild = ((osver & 0x000F) >> 0); - #else - sys_iOSMajor = 10; // !!! FIXME: just flatly false. - sys_iOSMinor = 6; - sys_iOSBuild = 0; - #endif - - sys_strOS = "Mac OS X"; - sys_strOSMisc = "Mac OS"; - CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); - CPrintF(TRANSV(" Version: %d.%d.%d\n"), - (int)sys_iOSMajor, (int)sys_iOSMinor, (int)sys_iOSBuild); - -#elif (defined PLATFORM_UNIX) // !!! FIXME: rcg10082001 what to do with this? - sys_iOSMajor = 1; - sys_iOSMinor = 0; - sys_iOSBuild = 0; - sys_strOS = "Unix"; - sys_strOSMisc = "Unix"; - CPrintF(TRANSV(" Type: %s\n"), (const char*)sys_strOS); - -#else - #error Do something with this for your platform. -#endif CPrintF("\n"); From 21d4aec7f776d4874feefd7a175539fc06e80cc6 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 22:40:08 -0700 Subject: [PATCH 02/21] Follow coding conventions --- Sources/Engine/Engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index dc81201..095d584 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -321,7 +321,8 @@ static void SanityCheckTypes(void) #endif } // don't want to export this function -void PlatformIdentification() { +static void PlatformIdentification(void) +{ #if (defined PLATFORM_WIN32) OSVERSIONINFO osv; memset(&osv, 0, sizeof(osv)); From 6f901305788d5371b9842713f7d1fbd1b1a85ae2 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 22:40:36 -0700 Subject: [PATCH 03/21] Added vim swap files to the .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 42aaebd..defd53b 100644 --- a/.gitignore +++ b/.gitignore @@ -81,7 +81,9 @@ Sources/SeriousSkaStudio/Parser.cpp Sources/SeriousSkaStudio/Parser.h Sources/SeriousSkaStudio/Scanner.cpp - +# vim swap files +*.swp +*.swo From a3c5d30f217474a21d049a978d819f2101710b52 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 22:49:58 -0700 Subject: [PATCH 04/21] Move the "please abstract" seconds to separate static functions for now --- Sources/Engine/Engine.cpp | 93 ++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index 095d584..fafd30c 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -383,6 +383,56 @@ static void PlatformIdentification(void) #error Do something with this for your platform. #endif } + +static void SetupMemoryManager(void) +{ + +#if (defined PLATFORM_WIN32) // !!! FIXME: Abstract this somehow. + MEMORYSTATUS ms; + GlobalMemoryStatus(&ms); + + #define MB (1024*1024) + sys_iRAMPhys = ms.dwTotalPhys /MB; + sys_iRAMSwap = ms.dwTotalPageFile/MB; + +#elif (defined PLATFORM_UNIX) + sys_iRAMPhys = 1; // !!! FIXME: This is bad. Bad. BAD. + sys_iRAMSwap = 1; + +#else + #error Do something with this for your platform. +#endif +} + +static void SetupSecondaryStorage(void) +{ +#if (defined PLATFORM_WIN32) // !!! FIXME: Abstract this somehow. + // get info on the first disk in system + DWORD dwSerial; + DWORD dwFreeClusters; + DWORD dwClusters; + DWORD dwSectors; + DWORD dwBytes; + + char strDrive[] = "C:\\"; + strDrive[0] = strExePath[0]; + + GetVolumeInformationA(strDrive, NULL, 0, &dwSerial, NULL, NULL, NULL, 0); + GetDiskFreeSpaceA(strDrive, &dwSectors, &dwBytes, &dwFreeClusters, &dwClusters); + sys_iHDDSize = ((__int64)dwSectors)*dwBytes*dwClusters/MB; + sys_iHDDFree = ((__int64)dwSectors)*dwBytes*dwFreeClusters/MB; + sys_iHDDMisc = dwSerial; + +#elif (defined PLATFORM_UNIX) // !!! FIXME: Uhh...? + sys_iHDDSize = 1; + sys_iHDDFree = 1; + sys_iHDDMisc = 0xDEADBEEF; + +#else + #error Do something with this for your platform. +#endif +} + // startup engine ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) { @@ -491,53 +541,14 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) extern void ReportGlobalMemoryStatus(void); ReportGlobalMemoryStatus(); -#if (defined PLATFORM_WIN32) // !!! FIXME: Abstract this somehow. - MEMORYSTATUS ms; - GlobalMemoryStatus(&ms); - - #define MB (1024*1024) - sys_iRAMPhys = ms.dwTotalPhys /MB; - sys_iRAMSwap = ms.dwTotalPageFile/MB; - -#elif (defined PLATFORM_UNIX) - sys_iRAMPhys = 1; // !!! FIXME: This is bad. Bad. BAD. - sys_iRAMSwap = 1; - -#else - #error Do something with this for your platform. -#endif - + SetupMemoryManager(); // initialize zip semaphore zip_csLock.cs_iIndex = -1; // not checked for locking order // rcg10082001 Honestly, all of this is meaningless in a multitasking OS. // That includes Windows, too. -#if (defined PLATFORM_WIN32) // !!! FIXME: Abstract this somehow. - // get info on the first disk in system - DWORD dwSerial; - DWORD dwFreeClusters; - DWORD dwClusters; - DWORD dwSectors; - DWORD dwBytes; - - char strDrive[] = "C:\\"; - strDrive[0] = strExePath[0]; - - GetVolumeInformationA(strDrive, NULL, 0, &dwSerial, NULL, NULL, NULL, 0); - GetDiskFreeSpaceA(strDrive, &dwSectors, &dwBytes, &dwFreeClusters, &dwClusters); - sys_iHDDSize = ((__int64)dwSectors)*dwBytes*dwClusters/MB; - sys_iHDDFree = ((__int64)dwSectors)*dwBytes*dwFreeClusters/MB; - sys_iHDDMisc = dwSerial; - -#elif (defined PLATFORM_UNIX) // !!! FIXME: Uhh...? - sys_iHDDSize = 1; - sys_iHDDFree = 1; - sys_iHDDMisc = 0xDEADBEEF; - -#else - #error Do something with this for your platform. -#endif + SetupSecondaryStorage(); /// FIXME: does that name make sense // add console variables extern INDEX con_bNoWarnings; From b221d5fce2ad90fe949268445b33e5bf1fda3f85 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 22:53:31 -0700 Subject: [PATCH 05/21] Make it so that anything system specific is not in SE_InitEngine --- Sources/Engine/Engine.cpp | 111 ++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index fafd30c..358fe48 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -433,11 +433,61 @@ static void SetupSecondaryStorage(void) #endif } -// startup engine -ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) +static void InitIFeel(void) { - SanityCheckTypes(); +// !!! FIXME : rcg12072001 Move this somewhere else. +#ifdef PLATFORM_WIN32 + // init IFeel + HWND hwnd = NULL;//GetDesktopWindow(); + HINSTANCE hInstance = GetModuleHandle(NULL); + if(IFeel_InitDevice(hInstance,hwnd)) + { + CTString strDefaultProject = "Data\\Default.ifr"; + // get project file name for this device + CTString strIFeel = IFeel_GetProjectFileName(); + // if no file name is returned use default file + if(strIFeel.Length()==0) strIFeel = strDefaultProject; + if(!IFeel_LoadFile(strIFeel)) + { + if(strIFeel!=strDefaultProject) + { + IFeel_LoadFile(strDefaultProject); + } + } + CPrintF("\n"); + } +#endif +} + +static void InitSystemGammaSettings(void) +{ +// !!! FIXME: Move this into GfxLibrary... +#ifdef PLATFORM_WIN32 + // readout system gamma table + HDC hdc = GetDC(NULL); + BOOL bOK = GetDeviceGammaRamp( hdc, &auwSystemGamma[0]); + _pGfx->gl_ulFlags |= GLF_ADJUSTABLEGAMMA; + if( !bOK) { + _pGfx->gl_ulFlags &= ~GLF_ADJUSTABLEGAMMA; + CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n")); + } // done + ReleaseDC( NULL, hdc); +#else + // !!! FIXME : rcg01072002 This CAN be done with SDL, actually. Move this somewhere. + #ifdef PLATFORM_PANDORA + // hacked gamma support + _pGfx->gl_ulFlags |= GLF_ADJUSTABLEGAMMA; + #else + CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n")); + #endif +#endif + +} + +// System specific platform init functions +static void PlatformSpecificInit(void) +{ #if PLATFORM_UNIX extern SDL_EventType WM_SYSKEYDOWN; extern SDL_EventType WM_LBUTTONDOWN; @@ -452,6 +502,14 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) WM_RBUTTONUP = (SDL_EventType) SDL_RegisterEvents(1); WM_PAINT = (SDL_EventType) SDL_RegisterEvents(1); #endif +} + +// startup engine +ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) +{ + SanityCheckTypes(); + + PlatformSpecificInit(); const char *gamename = "UnknownGame"; if (strGameID != "") @@ -650,52 +708,13 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) _pfdDisplayFont = NULL; _pfdConsoleFont = NULL; -// !!! FIXME: Move this into GfxLibrary... -#ifdef PLATFORM_WIN32 - // readout system gamma table - HDC hdc = GetDC(NULL); - BOOL bOK = GetDeviceGammaRamp( hdc, &auwSystemGamma[0]); - _pGfx->gl_ulFlags |= GLF_ADJUSTABLEGAMMA; - if( !bOK) { - _pGfx->gl_ulFlags &= ~GLF_ADJUSTABLEGAMMA; - CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n")); - } // done - ReleaseDC( NULL, hdc); -#else - // !!! FIXME : rcg01072002 This CAN be done with SDL, actually. Move this somewhere. - #ifdef PLATFORM_PANDORA - // hacked gamma support - _pGfx->gl_ulFlags |= GLF_ADJUSTABLEGAMMA; - #else - CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n")); - #endif -#endif - -// !!! FIXME : rcg12072001 Move this somewhere else. -#ifdef PLATFORM_WIN32 - // init IFeel - HWND hwnd = NULL;//GetDesktopWindow(); - HINSTANCE hInstance = GetModuleHandle(NULL); - if(IFeel_InitDevice(hInstance,hwnd)) - { - CTString strDefaultProject = "Data\\Default.ifr"; - // get project file name for this device - CTString strIFeel = IFeel_GetProjectFileName(); - // if no file name is returned use default file - if(strIFeel.Length()==0) strIFeel = strDefaultProject; - if(!IFeel_LoadFile(strIFeel)) - { - if(strIFeel!=strDefaultProject) - { - IFeel_LoadFile(strDefaultProject); - } - } - CPrintF("\n"); - } -#endif + InitSystemGammaSettings(); + InitIFeel(); // on non win32 platforms this will be optimized out if we play our cards right } + + // shutdown entire engine ENGINE_API void SE_EndEngine(void) { From e82ad0c1319775b7ae9573d12779972b17c0e44c Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:02:39 -0700 Subject: [PATCH 06/21] Move system specific deinit to a separate function for now --- Sources/Engine/Engine.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index 358fe48..b266557 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -714,9 +714,7 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) - -// shutdown entire engine -ENGINE_API void SE_EndEngine(void) +static void PlatformSpecificDeinit(void) { // !!! FIXME: Move this into GfxLibrary... #ifdef PLATFORM_WIN32 @@ -731,6 +729,12 @@ ENGINE_API void SE_EndEngine(void) // restore default gamma system("sudo /usr/pandora/scripts/op_gamma.sh 0"); #endif +} + +// shutdown entire engine +ENGINE_API void SE_EndEngine(void) +{ + PlatformSpecificDeinit(); // free stocks delete _pEntityClassStock; _pEntityClassStock = NULL; From e5c0e4f3f4b47edd823f25046fa5962deec25add Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:02:49 -0700 Subject: [PATCH 07/21] Add better platform detection abilities --- Sources/Engine/Base/Base.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Sources/Engine/Base/Base.h b/Sources/Engine/Base/Base.h index 1e17391..e062f20 100644 --- a/Sources/Engine/Base/Base.h +++ b/Sources/Engine/Base/Base.h @@ -18,7 +18,9 @@ with this program; if not, write to the Free Software Foundation, Inc., * rcg10042001 In case these don't get defined in the project file, try to * catch them here... */ -#ifdef _MSC_VER +// be a little more discerning, using these macros will ensure that if someone +// wants to use MINGW then they can +#if (defined _WIN32) || (defined _WIN64) #ifndef PLATFORM_WIN32 #define PLATFORM_WIN32 #endif @@ -51,8 +53,29 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #endif -#endif // defined _MSC_VER +#elif (defined __linux__) + #if (defined __ANDROID__) || (defined __android__) + #error "Android current isn't supported" + #else + #define PLATFORM_LINUX + #endif +#elif (defined __APPLE__) + #include "TargetConditionals.h" + #if TARGET_OS_MAC + #define PLATFORM_MACOSX + #else + #error "Unsupported apple platform" + #endif +#else + #warning "UNKNOWN PLATFORM IDENTIFIED!!!!" + #define PLATFORM_UNKNOWN +#endif +#if (defined PLATFORM_LINUX) || (defined PLATFORM_MACOSX) + #ifndef PLATFORM_UNIX + #define PLATFORM_UNIX + #endif +#endif #ifdef PLATFORM_UNIX /* rcg10042001 */ #define ENGINE_API From 535832668fceeec3b1d9b65065c4c1d428732551 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:04:12 -0700 Subject: [PATCH 08/21] Fixed a broken function call --- Sources/Engine/Engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index b266557..5c179a4 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -583,7 +583,7 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) // report os info CPrintF(TRANSV("Examining underlying OS...\n")); - PlatformIdentfication(); + PlatformIdentification(); // !!! FIXME: Abstract this somehow. CPrintF("\n"); From 5b2933e217e5c07579de487c53db9afdcf3a2557 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:06:49 -0700 Subject: [PATCH 09/21] Defined USE_PORTABLE_C when we can't figure out the platform --- Sources/Engine/Base/Base.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Engine/Base/Base.h b/Sources/Engine/Base/Base.h index e062f20..09f17c4 100644 --- a/Sources/Engine/Base/Base.h +++ b/Sources/Engine/Base/Base.h @@ -69,6 +69,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #else #warning "UNKNOWN PLATFORM IDENTIFIED!!!!" #define PLATFORM_UNKNOWN + #warning "USING PORTABLE C!!!" + #define USE_PORTABLE_C #endif #if (defined PLATFORM_LINUX) || (defined PLATFORM_MACOSX) From 35955d20ba043ea12d040a9d05fc2df008b4c13e Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:18:23 -0700 Subject: [PATCH 10/21] use stdint.h instead of courage in Types.h --- Sources/Engine/Base/Base.h | 14 +++++++------- Sources/Engine/Base/Types.h | 34 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Sources/Engine/Base/Base.h b/Sources/Engine/Base/Base.h index 09f17c4..8850021 100644 --- a/Sources/Engine/Base/Base.h +++ b/Sources/Engine/Base/Base.h @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // wants to use MINGW then they can #if (defined _WIN32) || (defined _WIN64) #ifndef PLATFORM_WIN32 - #define PLATFORM_WIN32 + #define PLATFORM_WIN32 1 #endif #ifndef PRAGMA_ONCE @@ -57,25 +57,25 @@ with this program; if not, write to the Free Software Foundation, Inc., #if (defined __ANDROID__) || (defined __android__) #error "Android current isn't supported" #else - #define PLATFORM_LINUX + #define PLATFORM_LINUX 1 #endif #elif (defined __APPLE__) #include "TargetConditionals.h" #if TARGET_OS_MAC - #define PLATFORM_MACOSX + #define PLATFORM_MACOSX 1 #else #error "Unsupported apple platform" #endif #else #warning "UNKNOWN PLATFORM IDENTIFIED!!!!" - #define PLATFORM_UNKNOWN + #define PLATFORM_UNKNOWN 1 #warning "USING PORTABLE C!!!" - #define USE_PORTABLE_C + #define USE_PORTABLE_C #endif -#if (defined PLATFORM_LINUX) || (defined PLATFORM_MACOSX) +#if PLATFORM_LINUX || PLATFORM_MACOSX #ifndef PLATFORM_UNIX - #define PLATFORM_UNIX + #define PLATFORM_UNIX 1 #endif #endif diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index 83afcb8..ab0e1c5 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // !!! FIXME: use stdint.h for this (and other things like INDEX, too)? +#ifdef PLATFORM_WIN32 typedef signed int SLONG; typedef signed short int SWORD; typedef signed char SBYTE; @@ -36,6 +37,20 @@ typedef unsigned int ULONG; typedef unsigned short int UWORD; typedef unsigned char UBYTE; typedef unsigned int UINT; +#else +#include +// use the defined typesizes from MSDN to create an equivalent translation on +// non windows platforms +typedef int32_t SLONG; +typedef int16_t SWORD; +typedef int8_t SBYTE; +typedef int32_t SINT; + +typedef uint32_t ULONG; +typedef uint16_t UWORD; +typedef uint8_t UBYTE; +typedef uint32_t UINT; +#endif // Flip this to 1 to turn off these messages everywhere. // !!! FIXME: I have it forced off for Windows because fprintf. @@ -53,6 +68,7 @@ typedef unsigned int UINT; } while (0) #endif +// TODO: add more architecture detection routines #if __POWERPC__ /* rcg03232004 */ #define PLATFORM_BIGENDIAN 1 #define PLATFORM_LITTLEENDIAN 0 @@ -213,22 +229,22 @@ typedef unsigned int UINT; #endif } - typedef unsigned long long __uint64; + typedef uint64_t __uint64; #if (!defined __INTEL_COMPILER) - typedef long long __int64; + typedef int64_t __int64; #endif typedef char CHAR; typedef UBYTE BYTE; - typedef unsigned short WORD; - typedef unsigned int DWORD; - typedef signed int LONG; + typedef uint16_t WORD; + typedef uint32_t DWORD; + typedef int32_t LONG; typedef void *LPVOID; typedef char *LPSTR; - typedef signed long int WPARAM; - typedef signed long int LPARAM; - typedef signed short int SHORT; - typedef unsigned short int USHORT; + typedef uint32_t WPARAM; + typedef int32_t LPARAM; + typedef int16_t SHORT; + typedef uint16_t USHORT; typedef void *HWND; /* !!! FIXME this sucks. */ typedef void *HINSTANCE; /* !!! FIXME this sucks. */ From 42b282241469ec52973c5a6556272fe5da517247 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:20:59 -0700 Subject: [PATCH 11/21] More todo's --- Sources/Engine/Base/Types.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index ab0e1c5..0540257 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -99,6 +99,9 @@ typedef uint32_t UINT; #include // for PAGESIZE... #include + // TODO: move the compiler detect routines to a separate file to declutter + // things + // check for legacy defines... #if (defined __ICC) #if (!defined __INTEL_COMPILER) From c8ab519b779e1118b16045a30802e0076ef71d0a Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:26:33 -0700 Subject: [PATCH 12/21] More big endian targets to detect --- Sources/Engine/Base/Types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index 0540257..c32d2a1 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -69,7 +69,7 @@ typedef uint32_t UINT; #endif // TODO: add more architecture detection routines -#if __POWERPC__ /* rcg03232004 */ +#if __POWERPC__ || (defined __ppc64__) || (defined __alpha__) || (defined __sparc__) /* rcg03232004 */ #define PLATFORM_BIGENDIAN 1 #define PLATFORM_LITTLEENDIAN 0 #else From 8b8ec1f39afcfcadf4b813a65aff8e0156d8b5cd Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:30:48 -0700 Subject: [PATCH 13/21] Add some C++11 features into Types.h since C++11 is so cool :D --- Sources/Engine/Base/Types.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index c32d2a1..13fe3a3 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -302,12 +302,31 @@ typedef uint32_t UINT; #define MAX_UWORD ((UWORD)0xFFFF) #define MAX_UBYTE ((UBYTE)0xFF) +#ifdef PLATFORM_WIN32 typedef int BOOL; // this is for TRUE/FALSE typedef int RESULT; // for error codes typedef int INDEX; // for indexed values and quantities - +#else +#if __cplusplus <= 199711L +typedef int32_t BOOL; // this is for TRUE/FALSE +#else // c++11 and greater has nice bool support +typedef bool BOOL; +#endif +typedef int32_t RESULT; // for error codes +typedef int32_t INDEX; // for indexed values and quantities +#endif +#ifdef PLATFORM_WIN32 #define FALSE 0 #define TRUE 1 +#else + #if __cplusplus <= 199711L + #define FALSE 0 + #define TRUE 1 + #else // use boolean types when we have access to C++11 + #define FALSE false + #define TRUE true + #endif +#endif #define NONE 0 #define NOTHING ((void) 0) From 0c847ab47902413a1e0b69650dc7a8331f93532e Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:48:44 -0700 Subject: [PATCH 14/21] Move system specific includes out to a separate file --- Sources/Engine/Base/Base.h | 4 +++- Sources/Engine/Engine.h | 19 ++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Sources/Engine/Base/Base.h b/Sources/Engine/Base/Base.h index 8850021..41fa86e 100644 --- a/Sources/Engine/Base/Base.h +++ b/Sources/Engine/Base/Base.h @@ -13,7 +13,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - +#ifndef SE_INCL_ENGINE_BASE_BASE_H +#define SE_INCL_ENGINE_BASE_BASE_H /* * rcg10042001 In case these don't get defined in the project file, try to * catch them here... @@ -83,3 +84,4 @@ with this program; if not, write to the Free Software Foundation, Inc., #define ENGINE_API #endif +#endif diff --git a/Sources/Engine/Engine.h b/Sources/Engine/Engine.h index 538a294..73f7f28 100644 --- a/Sources/Engine/Engine.h +++ b/Sources/Engine/Engine.h @@ -19,11 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #endif -#ifdef _WIN32 - #ifndef PLATFORM_WIN32 - #define PLATFORM_WIN32 1 - #endif -#endif +//#include +#include // set this to 1 to enable checks whether somethig is deleted while iterating some array/container #define CHECKARRAYLOCKING 0 @@ -38,17 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // for qsort #include // for FPU control -/* rcg10042001 !!! FIXME: Move these somewhere. */ -#if (defined PLATFORM_WIN32) -#include -#include -#include -#include -#include -#include // for timers -#endif -#include +#include + #include #include From 2d8a4df68c8646f5f3cc68efed55f5a67004ca90 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:49:02 -0700 Subject: [PATCH 15/21] Add the system specific include file --- Sources/Engine/Base/SystemSpecificInclude.h | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Sources/Engine/Base/SystemSpecificInclude.h diff --git a/Sources/Engine/Base/SystemSpecificInclude.h b/Sources/Engine/Base/SystemSpecificInclude.h new file mode 100644 index 0000000..f0d277b --- /dev/null +++ b/Sources/Engine/Base/SystemSpecificInclude.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2002-2012 Croteam Ltd. +This program is free software; you can redistribute it and/or modify +it under the terms of version 2 of the GNU General Public License as published by +the Free Software Foundation + + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#ifndef SE_INCL_ENGINE_BASE_SYSTEM_SPECIFIC_INCLUDE_H +#define SE_INCL_ENGINE_BASE_SYSTEM_SPECIFIC_INCLUDE_H + +#ifdef PRAGMA_ONCE + #pragma once +#endif + +#include //blerg potential cyclic dependency :( + +#include +#include +#include +#include +#include +#include +#include +#include // for qsort +#include // for FPU control + +/* rcg10042001 !!! FIXME: Move these somewhere. */ +#if (defined PLATFORM_WIN32) +#include +#include +#include +#include +#include +#include // for timers +#endif + +#endif From a8c22df784516517bda91648aa08c093f567594f Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:49:18 -0700 Subject: [PATCH 16/21] Forgot to write Engine to disk :( --- Sources/Engine/Engine.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Sources/Engine/Engine.h b/Sources/Engine/Engine.h index 73f7f28..448d301 100644 --- a/Sources/Engine/Engine.h +++ b/Sources/Engine/Engine.h @@ -25,15 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., // set this to 1 to enable checks whether somethig is deleted while iterating some array/container #define CHECKARRAYLOCKING 0 -#include -#include -#include -#include -#include -#include -#include -#include // for qsort -#include // for FPU control #include From f8cb52f8ad28b245c6bfe3d1bff2ede04119e9d4 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Sun, 17 Apr 2016 23:50:00 -0700 Subject: [PATCH 17/21] Delete an unused include --- Sources/Engine/Engine.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Engine/Engine.h b/Sources/Engine/Engine.h index 448d301..0df14e5 100644 --- a/Sources/Engine/Engine.h +++ b/Sources/Engine/Engine.h @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #endif -//#include #include // set this to 1 to enable checks whether somethig is deleted while iterating some array/container From a4ca331de9678e5b25872a4e2c5cd90e2bc4052f Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Mon, 18 Apr 2016 00:13:30 -0700 Subject: [PATCH 18/21] Added some more todos --- Sources/Engine/Engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index 5c179a4..15021ca 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -323,6 +323,7 @@ static void SanityCheckTypes(void) // don't want to export this function static void PlatformIdentification(void) { +// !!! FIXME: Abstract this somehow. #if (defined PLATFORM_WIN32) OSVERSIONINFO osv; memset(&osv, 0, sizeof(osv)); @@ -372,6 +373,7 @@ static void PlatformIdentification(void) (int)sys_iOSMajor, (int)sys_iOSMinor, (int)sys_iOSBuild); #elif (defined PLATFORM_UNIX) // !!! FIXME: rcg10082001 what to do with this? + // FIXME: probably want to use uname function on Linux but it isn't totally applicable...hmm... sys_iOSMajor = 1; sys_iOSMinor = 0; sys_iOSBuild = 0; @@ -584,7 +586,6 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID) CPrintF(TRANSV("Examining underlying OS...\n")); PlatformIdentification(); -// !!! FIXME: Abstract this somehow. CPrintF("\n"); From 1b873d3ab430a4c73b7fd635f2367bbdcbb2035c Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Wed, 20 Apr 2016 18:50:36 -0700 Subject: [PATCH 19/21] Bool's must be 32-bits wide --- Sources/Engine/Base/Types.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index 13fe3a3..5aac032 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -307,26 +307,13 @@ typedef int BOOL; // this is for TRUE/FALSE typedef int RESULT; // for error codes typedef int INDEX; // for indexed values and quantities #else -#if __cplusplus <= 199711L typedef int32_t BOOL; // this is for TRUE/FALSE -#else // c++11 and greater has nice bool support -typedef bool BOOL; -#endif typedef int32_t RESULT; // for error codes typedef int32_t INDEX; // for indexed values and quantities #endif -#ifdef PLATFORM_WIN32 + #define FALSE 0 #define TRUE 1 -#else - #if __cplusplus <= 199711L - #define FALSE 0 - #define TRUE 1 - #else // use boolean types when we have access to C++11 - #define FALSE false - #define TRUE true - #endif -#endif #define NONE 0 #define NOTHING ((void) 0) From dbd896b58d287140920808c424c6a2a372a2cf46 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Wed, 20 Apr 2016 19:06:02 -0700 Subject: [PATCH 20/21] Use the platform independent version of ReadTSC - If I use the gnu inline version, the game runs way too fast on my cpu due to frequency scaling (I think). --- Sources/Engine/Base/Timer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Engine/Base/Timer.cpp b/Sources/Engine/Base/Timer.cpp index db603b3..56ba1c5 100755 --- a/Sources/Engine/Base/Timer.cpp +++ b/Sources/Engine/Base/Timer.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // !!! FIXME: use SDL timer code instead and rdtsc never? -#if (USE_PORTABLE_C) +#if (USE_PORTABLE_C) || PLATFORM_UNIX #define USE_GETTIMEOFDAY 1 #endif From 7f682180f303f706dd108152c45e37d265678fa5 Mon Sep 17 00:00:00 2001 From: Joshua Scoggins Date: Wed, 20 Apr 2016 19:24:51 -0700 Subject: [PATCH 21/21] Use SERIOUS_MHZ envvar for the time being --- Sources/Engine/Base/Timer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Engine/Base/Timer.cpp b/Sources/Engine/Base/Timer.cpp index 56ba1c5..0bfd970 100755 --- a/Sources/Engine/Base/Timer.cpp +++ b/Sources/Engine/Base/Timer.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // !!! FIXME: use SDL timer code instead and rdtsc never? -#if (USE_PORTABLE_C) || PLATFORM_UNIX +#if (USE_PORTABLE_C) #define USE_GETTIMEOFDAY 1 #endif