Skip to content

[GEN][ZH] Add compilation for Linux #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e7afd1b
[ZH] Replace inline asm in non VS6 builds
xezon Mar 21, 2025
ab55998
[ZH] Move intrin_compat.h to Dependencies #479
xezon Mar 26, 2025
92cf142
[ZH] Use std::atomic_flag for FastCriticalSectionClass #479
xezon Mar 26, 2025
a8aa2d2
[ZH] Fix shift mask in _lrotl #479
xezon Mar 26, 2025
f949c55
[ZH] Simplify _swapBytes #479
xezon Mar 26, 2025
eec5299
[ZH] Add cpp replacement code in Get_CPU_Clock #479
xezon Mar 26, 2025
064df8f
[ZH] Refactor to simplify code a bit in DX8Wrapper::Clamp_Color #479
xezon Mar 26, 2025
f07ea2b
[ZH] Greatly simplify fast_float_trunc with zzambers version #479
xezon Mar 26, 2025
ef29406
[ZH] Replace asm in timingTest tool #479
xezon Mar 28, 2025
1b178f0
[ZH] Replace inline ASM in profile library #479
Mauller Mar 29, 2025
3abd567
[ZH] Small corrections to previous commits #479
Mauller Mar 29, 2025
bf53cf4
[ZH] Replace CPU profiling and CPU ID ASM with intrinsic functions #479
Mauller Mar 30, 2025
e163943
[Compat] Fix compilation of CLI tools on linux
feliwir Mar 27, 2025
0b6667b
[Compat] Fix ZH WWLib compilation
feliwir Mar 28, 2025
214e621
[Compat] Fix ZH WWMath compilation
feliwir Mar 28, 2025
e28d04a
[Compat] Fix ZH WWSaveLoad compilation
feliwir Mar 28, 2025
40e4fb5
[Compat] Fix Generals compression tool compilation
feliwir Mar 29, 2025
83e3c8c
[Compat] Fix Generals WWLib compilation
feliwir Mar 29, 2025
6b74684
[Compat] Fix VS2022 compilation
feliwir Mar 29, 2025
0effd20
[Compat] Fix GEN WWDebug compilation
feliwir Mar 30, 2025
1e8b8ad
[Compat] Fix GEN WWMath compilation
feliwir Mar 30, 2025
f70ae59
[Compat] adjust compat header naming
feliwir Mar 30, 2025
3bdd169
[Compat] Fix ZH WWUtil compilation
feliwir Mar 30, 2025
820c397
[Compat] Fix Generals WWUtil compilation
feliwir Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Dependencies/Utility/Utility/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// TheSuperHackers
// This file contains macros to help compiling on non-windows platforms.

#pragma once

#ifndef _WIN32
// For size_t
#include <cstddef>
// For isdigit
#include <cctype>

// __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
72 changes: 72 additions & 0 deletions Dependencies/Utility/Utility/intrin_compat.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

#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 <intrin.h>
#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 <intrin.h>
#pragma intrinsic(_ReturnAddress)
#elif defined(__has_builtin)
#if __has_builtin(__builtin_return_address)
static inline uintptr_t _ReturnAddress()
{
return reinterpret_cast<uintptr_t>(__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
4 changes: 4 additions & 0 deletions Dependencies/Utility/Utility/mem_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#include <alloca.h>
#define _alloca alloca
19 changes: 19 additions & 0 deletions Dependencies/Utility/Utility/string_compat.h
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Dependencies/Utility/Utility/tchar_compat.h
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions Dependencies/Utility/Utility/thread_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include <pthread.h>
#include <unistd.h>

inline int GetCurrentThreadId()
{
return pthread_self();
}

inline void Sleep(int ms)
{
usleep(ms * 1000);
}
21 changes: 21 additions & 0 deletions Dependencies/Utility/Utility/time_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <time.h>

#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;
}
15 changes: 15 additions & 0 deletions Dependencies/Utility/Utility/wchar_compat.h
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions Generals/Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ target_include_directories(g_gameengine PRIVATE
)

target_link_libraries(g_gameengine PRIVATE
gi_libraries_include
gi_utility
gi_libraries_source
)

Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngineDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
12 changes: 12 additions & 0 deletions Generals/Code/Libraries/Include/Lib/BaseType.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <math.h>
#include <string.h>
// SuperHackers: utility macros for cross-platform compatibility
#include <Utility/compat.h>

/*
** Turn off some unneeded warnings.
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/Libraries/Source/Compression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target_include_directories(g_compression INTERFACE
)

target_link_libraries(g_compression PRIVATE
gi_libraries_include
gi_utility
gz_config
)

Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/Libraries/Source/Compression/EAC/huffencode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@


#include "wwdebug.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <errno.h>
#endif
//#include "win.h" can use this if allowed to see wwlib
#include <stdlib.h>
#include <stdarg.h>
Expand Down Expand Up @@ -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
}

/***********************************************************************************************
Expand Down
Loading