Skip to content

Commit 36c16f2

Browse files
authored
Merge pull request #1 from OKJID/okji/feat/macos-port
feat(macos): Full native macOS port via Apple Metal and 64-bit architecture refactor
2 parents ac6d9a2 + 0b06aee commit 36c16f2

351 files changed

Lines changed: 67048 additions & 12930 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ build.ninja
6565

6666
## Python
6767
__pycache__/
68-
*.pyc
68+
69+
CRCLogs/
70+
71+
# Large Game Assets
72+
Data/*.big
73+
74+
# Heavy Logs & Media
75+
Platform/MacOS/Build/Logs/
76+
*.gif
77+

.vscode/launch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "macOS: Run build_run_mac.sh (Console)",
6+
"type": "node-terminal",
7+
"request": "launch",
8+
"command": "sh build_run_mac.sh",
9+
"cwd": "${workspaceFolder}"
10+
},
11+
{
12+
"name": "macOS: Visual Debug C&C Generals",
13+
"type": "cppdbg",
14+
"request": "launch",
15+
"program": "${workspaceFolder}/build/macos/GeneralsMD/GeneralsOnlineZH.app/Contents/MacOS/GeneralsOnlineZH",
16+
"args": [
17+
"-win"
18+
],
19+
"cwd": "${workspaceFolder}",
20+
"environment": [
21+
{ "name": "GENERALS_INSTALL_PATH", "value": "/Users/okji/dev/games/Command and Conquer - Generals/" },
22+
{ "name": "GENERALS_FPS_LIMIT", "value": "60" },
23+
{ "name": "GENERALS_MAC_DEBUG", "value": "1" }
24+
],
25+
"MIMode": "lldb",
26+
"preLaunchTask": "macOS: CMake Compile Only",
27+
"externalConsole": false
28+
}
29+
]
30+
}

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
3+
"editor.formatOnSave": false,
4+
"terminal.integrated.fontSize": 12,
5+
"terminal.integrated.fontFamily": "monospace",
6+
"terminal.integrated.lineHeight": 1.2,
7+
"terminal.integrated.cursorBlinking": true,
8+
"terminal.integrated.cursorStyle": "line",
9+
"terminal.integrated.fontWeight": "normal",
10+
"terminal.integrated.fontWeightBold": "bold",
11+
"terminal.integrated.defaultProfile.osx": "zsh",
12+
"editor.rulers": [
13+
120
14+
]
15+
}

.vscode/tasks.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "macOS: Release Build + Launcher",
6+
"type": "shell",
7+
"command": "sh build_mac.sh --launcher",
8+
"group": "build",
9+
"presentation": {
10+
"reveal": "always",
11+
"panel": "new"
12+
},
13+
"problemMatcher": []
14+
},
15+
{
16+
"label": "macOS: Clean Release Build + Launcher",
17+
"type": "shell",
18+
"command": "sh build_mac.sh --clean --launcher",
19+
"group": "build",
20+
"presentation": {
21+
"reveal": "always",
22+
"panel": "new"
23+
},
24+
"problemMatcher": []
25+
},
26+
{
27+
"label": "macOS: Debug Build + Run",
28+
"type": "shell",
29+
"command": "sh build_run_mac.sh",
30+
"group": "build",
31+
"presentation": {
32+
"reveal": "always",
33+
"panel": "new"
34+
},
35+
"problemMatcher": []
36+
},
37+
{
38+
"label": "macOS: Clean Debug Build + Run",
39+
"type": "shell",
40+
"command": "sh build_run_mac.sh --clean",
41+
"group": "build",
42+
"presentation": {
43+
"reveal": "always",
44+
"panel": "new"
45+
},
46+
"problemMatcher": []
47+
},
48+
{
49+
"label": "macOS: CMake Compile Only",
50+
"type": "shell",
51+
"command": "cmake --build build/macos",
52+
"group": "build",
53+
"problemMatcher": []
54+
}
55+
]
56+
}

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ endif()
3333
# Top level project, doesn't really affect anything.
3434
project(genzh LANGUAGES C CXX)
3535

36+
if(APPLE)
37+
enable_language(OBJCXX)
38+
add_compile_options(-ffp-contract=off)
39+
endif()
40+
3641
# This file handles extra settings wanted/needed for different compilers.
3742
include(cmake/compilers.cmake)
3843

@@ -65,6 +70,8 @@ endif()
6570
include(cmake/config.cmake)
6671
include(cmake/gamespy.cmake)
6772
include(cmake/lzhl.cmake)
73+
include(cmake/curl.cmake)
74+
include(cmake/gns.cmake)
6875

6976
if (IS_VS6_BUILD)
7077
# The original max sdk does not compile against a modern compiler.
@@ -81,6 +88,10 @@ endif()
8188

8289
add_subdirectory(resources)
8390

91+
if(APPLE)
92+
add_subdirectory(Platform/MacOS)
93+
endif()
94+
8495
add_subdirectory(Core)
8596

8697
# Add main build targets

CMakePresets.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@
207207
"cacheVariables": {
208208
"RTS_BUILD_OPTION_PROFILE": "ON"
209209
}
210+
},
211+
{
212+
"name": "macos",
213+
"displayName": "macOS Release",
214+
"generator": "Ninja",
215+
"hidden": false,
216+
"binaryDir": "${sourceDir}/build/${presetName}",
217+
"cacheVariables": {
218+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
219+
"CMAKE_BUILD_TYPE": "Release"
220+
},
221+
"condition": {
222+
"type": "equals",
223+
"lhs": "${hostSystemName}",
224+
"rhs": "Darwin"
225+
}
210226
}
211227
],
212228
"buildPresets": [
@@ -306,6 +322,12 @@
306322
"configurePreset": "mingw-w64-i686-profile",
307323
"displayName": "Build MinGW-w64 32-bit (i686) Profile",
308324
"description": "Build MinGW-w64 32-bit (i686) Profile"
325+
},
326+
{
327+
"name": "macos",
328+
"configurePreset": "macos",
329+
"displayName": "Build macOS Release",
330+
"description": "Build macOS Release"
309331
}
310332
],
311333
"workflowPresets": [
@@ -503,6 +525,19 @@
503525
"name": "mingw-w64-i686-profile"
504526
}
505527
]
528+
},
529+
{
530+
"name": "macos",
531+
"steps": [
532+
{
533+
"type": "configure",
534+
"name": "macos"
535+
},
536+
{
537+
"type": "build",
538+
"name": "macos"
539+
}
540+
]
506541
}
507542
]
508543
}

Core/GameEngine/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ set(GAMEENGINE_SRC
553553
Include/GameNetwork/RankPointValue.h
554554
Include/GameNetwork/Transport.h
555555
Include/GameNetwork/udp.h
556-
Include/GameNetwork/User.h
556+
# Include/GameNetwork/User.h
557557
Include/GameNetwork/WOLBrowser/FEBDispatch.h
558558
Include/GameNetwork/WOLBrowser/WebBrowser.h
559559
# Include/Precompiled/PreRTS.h
@@ -679,6 +679,7 @@ set(GAMEENGINE_SRC
679679
# Source/Common/System/Upgrade.cpp
680680
Source/Common/System/Xfer.cpp
681681
Source/Common/System/XferCRC.cpp
682+
Source/Common/System/NativeFileSystem.cpp
682683
Source/Common/System/XferLoad.cpp
683684
Source/Common/System/XferSave.cpp
684685
# Source/Common/TerrainTypes.cpp
@@ -1143,7 +1144,7 @@ set(GAMEENGINE_SRC
11431144
Source/GameNetwork/Transport.cpp
11441145
Source/GameNetwork/udp.cpp
11451146
Source/GameNetwork/User.cpp
1146-
Source/GameNetwork/WOLBrowser/WebBrowser.cpp
1147+
# Source/GameNetwork/WOLBrowser/WebBrowser.cpp
11471148
# Source/Precompiled/PreRTS.cpp
11481149
)
11491150

@@ -1191,11 +1192,16 @@ target_link_libraries(corei_gameengine_public INTERFACE
11911192
core_compression
11921193
core_browserdispatch
11931194
#core_wwvegas
1194-
d3d8lib
11951195
gamespy::gamespy
11961196
stlport
11971197
)
11981198

1199+
if(NOT APPLE)
1200+
target_link_libraries(corei_gameengine_public INTERFACE
1201+
d3d8lib
1202+
)
1203+
endif()
1204+
11991205
# ReactOS ATL for MinGW-w64 only (MSVC uses native ATL)
12001206
if(MINGW)
12011207
target_link_libraries(corei_gameengine_public INTERFACE reactos_atl)

Core/GameEngine/Include/Common/Debug.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,49 @@ class SimpleProfiler
257257
#endif
258258

259259
// MACROS //////////////////////////////////////////////////////////////////
260+
261+
262+
263+
#ifdef __APPLE__
264+
#include <stdio.h>
265+
#include <stdlib.h>
266+
267+
#define MAC_LOG_TAG(tag, m) do { \
268+
printf("[" tag "] "); \
269+
printf m; \
270+
printf("\n"); \
271+
fflush(stdout); \
272+
} while(0)
273+
274+
#define DEBUG_CRASH_MAC(m) do { \
275+
if (getenv("GENERALS_MAC_DEBUG") && atoi(getenv("GENERALS_MAC_DEBUG")) != 0) { \
276+
MAC_LOG_TAG("DEBUG_CRASH_MAC", m); \
277+
} \
278+
} while(0)
279+
#else
280+
#define MAC_LOG_TAG(tag, m) ((void)0)
281+
#define DEBUG_CRASH_MAC(m) ((void)0)
282+
#endif
283+
284+
#define DEBUG_BUILDMAPCACHE_FLAG
285+
#define DEBUG_INFO_MAC_FLAG
286+
#define DEBUG_FILESYSTEM_MAC_FLAG
287+
288+
#ifdef DEBUG_BUILDMAPCACHE_FLAG
289+
#define DEBUG_BUILDMAPCACHE(m) MAC_LOG_TAG("DEBUG_BUILDMAPCACHE", m)
290+
#else
291+
#define DEBUG_BUILDMAPCACHE(m) ((void)0)
292+
#endif
293+
294+
#ifdef DEBUG_INFO_MAC_FLAG
295+
#define DEBUG_INFO_MAC(m) MAC_LOG_TAG("DEBUG_INFO_MAC", m)
296+
#else
297+
#define DEBUG_INFO_MAC(m) ((void)0)
298+
#endif
299+
300+
#ifdef DEBUG_FILESYSTEM_MAC_FLAG
301+
#define DEBUG_FILESYSTEM_MAC(m) MAC_LOG_TAG("DEBUG_FILESYSTEM_MAC", m)
302+
#else
303+
#define DEBUG_FILESYSTEM_MAC(m) ((void)0)
304+
#endif
305+

Core/GameEngine/Include/Common/FileSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ typedef UnsignedByte FileInstance;
107107
#endif
108108

109109

110+
#ifdef __APPLE__
111+
#define FileInfo RTSFileInfo
112+
#endif
113+
110114
struct FileInfo {
111115

112116
Int64 size() const { return (Int64)sizeHigh << 32 | sizeLow; }

Core/GameEngine/Include/Common/GameCommon.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,32 @@ const VeterancyLevelFlags VETERANCY_LEVEL_FLAGS_NONE = 0x00000000;
290290

291291
inline Bool getVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
292292
{
293+
#ifdef __APPLE__
294+
UnsignedInt bit = (dt == 0) ? 31u : (UnsignedInt)(dt - 1);
295+
return (flags & (1UL << bit)) != 0;
296+
#else
293297
return (flags & (1UL << (dt - 1))) != 0;
298+
#endif
294299
}
295300

296301
inline VeterancyLevelFlags setVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
297302
{
303+
#ifdef __APPLE__
304+
UnsignedInt bit = (dt == 0) ? 31u : (UnsignedInt)(dt - 1);
305+
return (flags | (1UL << bit));
306+
#else
298307
return (flags | (1UL << (dt - 1)));
308+
#endif
299309
}
300310

301311
inline VeterancyLevelFlags clearVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
302312
{
313+
#ifdef __APPLE__
314+
UnsignedInt bit = (dt == 0) ? 31u : (UnsignedInt)(dt - 1);
315+
return (flags & ~(1UL << bit));
316+
#else
303317
return (flags & ~(1UL << (dt - 1)));
318+
#endif
304319
}
305320

306321
// ----------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)