Skip to content

Commit 0526867

Browse files
feliwirFighter19
andcommitted
[Compat] Fix ZH WWLib compilation
Co-authored-by: Patrick Zacharias <[email protected]>
1 parent fee9ff4 commit 0526867

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+349
-117
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ if(MSVC)
9696
target_compile_definitions(gz_config INTERFACE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS $<$<CONFIG:DEBUG>:_DEBUG_CRT>)
9797
endif()
9898

99+
if(UNIX)
100+
target_compile_definitions(gz_config INTERFACE _UNIX)
101+
endif()
102+
99103
if(GENZH_BUILD_DEBUG)
100104
target_compile_definitions(gz_config INTERFACE _DEBUG WWDEBUG DEBUG)
101105
else()

Dependencies/Utility/Utility/Compat.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// TheSuperHackers
2+
// This file contains macros to help compiling on non-windows platforms.
3+
4+
#pragma once
5+
6+
#ifndef _WIN32
7+
// For size_t
8+
#include <cstddef>
9+
// For isdigit
10+
#include <cctype>
11+
12+
// __forceinline
13+
#ifndef __forceinline
14+
#if defined __has_attribute && __has_attribute(always_inline)
15+
#define __forceinline __attribute__((always_inline)) inline
16+
#else
17+
#define __forceinline inline
18+
#endif
19+
#endif
20+
21+
// _cdecl / __cdecl
22+
#ifndef _cdecl
23+
#define _cdecl
24+
#endif
25+
#ifndef __cdecl
26+
#define __cdecl
27+
#endif
28+
29+
// OutputDebugString
30+
#ifndef OutputDebugString
31+
#define OutputDebugString(str) printf("%s\n", str)
32+
#endif
33+
34+
// _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, _MAX_EXT, _MAX_PATH
35+
#ifndef _MAX_DRIVE
36+
#define _MAX_DRIVE 255
37+
#endif
38+
#ifndef _MAX_DIR
39+
#define _MAX_DIR 255
40+
#define _MAX_DIR 255
41+
#endif
42+
#ifndef _MAX_FNAME
43+
#define _MAX_FNAME 255
44+
#endif
45+
#ifndef _MAX_EXT
46+
#define _MAX_EXT 255
47+
#endif
48+
#ifndef _MAX_PATH
49+
#define _MAX_PATH 255
50+
#endif
51+
52+
#include "MemCompat.h"
53+
#include "StringCompat.h"
54+
#include "TCharCompat.h"
55+
#include "WCharCompat.h"
56+
#include "TimeCompat.h"
57+
#include "ThreadCompat.h"
58+
59+
#endif

Dependencies/Utility/Utility/CompatMacros.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

Dependencies/Utility/Utility/intrin_compat.h renamed to Dependencies/Utility/Utility/IntrinCompat.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#pragma once
22

3-
#if !(defined(_MSC_VER) && _MSC_VER < 1300)
3+
// VC6 macros
4+
#if defined(_MSC_VER) && _MSC_VER < 1300
5+
#define __debugbreak __asm { int 3 }
6+
#endif
47

8+
// Non-VC6 macros
9+
#if !(defined(_MSC_VER) && _MSC_VER < 1300)
510
#include <cstdint>
611

712
#if !defined(_lrotl) && !defined(_WIN32)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#include <alloca.h>
4+
#define _alloca alloca
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
typedef const char* LPCSTR;
4+
typedef char* LPSTR;
5+
6+
// String functions
7+
#define _vsnprintf vsnprintf
8+
#define _snprintf snprintf
9+
#define stricmp strcasecmp
10+
#define strnicmp strncasecmp
11+
#define strcmpi strcasecmp
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
// TCHAR
4+
typedef char TCHAR;
5+
typedef const TCHAR* LPCTSTR;
6+
typedef TCHAR* LPTSTR;
7+
#define _tcslen strlen
8+
#define _tcscmp strcmp
9+
#define _tcsicmp strcasecmp
10+
#define _tcsclen strlen
11+
#define _tcscpy strcpy
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include <pthread.h>
3+
#include <unistd.h>
4+
5+
inline int GetCurrentThreadId()
6+
{
7+
return pthread_self();
8+
}
9+
10+
inline void Sleep(int ms)
11+
{
12+
usleep(ms * 1000);
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <time.h>
3+
4+
#define TIMERR_NOERROR 0
5+
typedef int MMRESULT;
6+
static inline MMRESULT timeBeginPeriod(int) { return TIMERR_NOERROR; }
7+
static inline MMRESULT timeEndPeriod(int) { return TIMERR_NOERROR; }
8+
9+
inline unsigned int timeGetTime()
10+
{
11+
struct timespec ts;
12+
clock_gettime(CLOCK_BOOTTIME, &ts);
13+
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
14+
}
15+
inline unsigned int GetTickCount()
16+
{
17+
struct timespec ts;
18+
clock_gettime(CLOCK_MONOTONIC, &ts);
19+
// Return ms since boot
20+
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
// WCHAR
4+
typedef wchar_t WCHAR;
5+
typedef const WCHAR* LPCWSTR;
6+
typedef WCHAR* LPWSTR;
7+
8+
#define _wcsicmp wcscasecmp
9+
#define wcsicmp wcscasecmp
10+
#define _vsnwprintf vswprintf
11+
12+
// MultiByteToWideChar
13+
#define CP_ACP 0
14+
#define MultiByteToWideChar(cp, flags, mbstr, cb, wcstr, cch) mbstowcs(wcstr, mbstr, cch)
15+
#define WideCharToMultiByte(cp, flags, wcstr, cch, mbstr, cb, defchar, used) wcstombs(mbstr, wcstr, cb)

Generals/Code/Libraries/Include/Lib/BaseType.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#include <math.h>
3636
#include <string.h>
37-
// SuperHackers: Standard integer types & utility macros for cross-platform compatibility
38-
#include <Utility/CompatMacros.h>
37+
// SuperHackers: utility macros for cross-platform compatibility
38+
#include <Utility/Compat.h>
3939

4040
/*
4141
** Turn off some unneeded warnings.
@@ -186,10 +186,15 @@ __forceinline long fast_float2long_round(float f)
186186
{
187187
long i;
188188

189+
#if defined(_MSC_VER) && _MSC_VER < 1300
189190
__asm {
190191
fld [f]
191192
fistp [i]
192193
}
194+
#else
195+
// TheSuperHackers @fix Use simple C code instead of inline assembly
196+
i = lroundf(f);
197+
#endif
193198

194199
return i;
195200
}

GeneralsMD/Code/GameEngine/Include/Common/PerfTimer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#ifndef __PERFTIMER_H__
3232
#define __PERFTIMER_H__
3333

34-
#include "Utility/intrin_compat.h"
34+
#include "Utility/IntrinCompat.h"
3535

3636
#if defined(_DEBUG) || defined(_INTERNAL)
3737
/*

GeneralsMD/Code/Libraries/Include/Lib/BaseType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#include <math.h>
3636
#include <string.h>
37-
// SuperHackers: Standard integer types & utility macros for cross-platform compatibility
38-
#include <Utility/CompatMacros.h>
37+
// SuperHackers: utility macros for cross-platform compatibility
38+
#include <Utility/Compat.h>
3939

4040
/*
4141
** Turn off some unneeded warnings.

GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343

4444

4545
#include "wwdebug.h"
46+
#ifdef _WIN32
4647
#include <windows.h>
48+
#else
49+
#include <errno.h>
50+
#endif
4751
//#include "win.h" can use this if allowed to see wwlib
4852
#include <stdlib.h>
4953
#include <stdarg.h>
@@ -79,7 +83,11 @@ void Convert_System_Error_To_String(int id, char* buffer, int buf_len)
7983

8084
int Get_Last_System_Error()
8185
{
86+
#ifndef _UNIX
8287
return GetLastError();
88+
#else
89+
return errno;
90+
#endif
8391
}
8492

8593
/***********************************************************************************************

GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
// TheSuperHackers @todo Recover WWDEBUG?
4545
#ifdef WWDEBUG
46-
#include <Utility/intrin_compat.h>
46+
#include <Utility/IntrinCompat.h>
4747
#endif
4848

4949
// The macro MESSAGE allows user to put:

GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
#include "wwdebug.h"
4444
#include "Vector.H"
4545
#include "FastAllocator.h"
46+
#ifdef _WIN32
4647
#include <windows.h>
48+
#endif
4749

4850
#define USE_FAST_ALLOCATOR
4951

GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwprofile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
#include "wwprofile.h"
5454
#include "FastAllocator.h"
5555
#include "wwdebug.h"
56+
#ifdef _WIN32
5657
#include <windows.h>
58+
#endif
5759
//#include "systimer.h"
5860
#include "systimer.h"
5961
#include "RAWFILE.H"

0 commit comments

Comments
 (0)