Skip to content

Commit

Permalink
Merge pull request #637 from winterheart/cmake-makehogs
Browse files Browse the repository at this point in the history
Optimize making HOG files
  • Loading branch information
Lgt2x authored Oct 29, 2024
2 parents 73d2764 + 44806e7 commit f6faeaa
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 92 deletions.
31 changes: 27 additions & 4 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The build process uses [**CMake**](https://cmake.org/) and, by default, [**Ninja
git clone --recurse-submodules https://github.com/DescentDevelopers/Descent3
```
4. **Build Descent3.**
3. **Build Descent3.**
```batch
cd Descent3
Expand All @@ -49,7 +49,7 @@ The build process uses [**CMake**](https://cmake.org/) and, by default, [**Ninja
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug` or `builds\win\Descent3\Release`.
Once CMake finishes, the built files will be put in `builds\win\build\Debug` or `builds\win\build\Release`.
## Building - macOS
1. **Install the prerequisite build tools.**
Expand Down Expand Up @@ -87,7 +87,7 @@ Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug`
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug` or `builds/mac/Descent3/Release`.
Once CMake finishes, the built files will be put in `builds/mac/build/Debug` or `builds/mac/build/Release`.
## Building - Linux
1. **Install the prerequisite build tools.**
Expand Down Expand Up @@ -147,7 +147,30 @@ Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug`
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
Once CMake finishes, the built files will be put in `builds/linux/build/Debug` or `builds/linux/build/Release`.
## Cross-compilation
In order to cross-compile Descent3 to another platform (for example, Linux ARM64), you'll need to build auxiliary
tools which needed to build data files. First create build-native directory and configure project in it:
```shell
mkdir build-native
cd build-native
cmake ..
make HogMaker
```

Now you ready for cross-compilation. Create cross-compile directory and configure project in it, but this time add
`-DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake` and `-DHogMaker_DIR=<path-to-Descent3/build-native/` options. This enables
cross-compilation environment.

```shell
mkdir build-cross
cd build-cross
cmake -DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake -DHogMaker_DIR=~/src/build-native/ ..
make
```

## Build Options

Expand Down
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ if(FORCE_COLORED_OUTPUT)
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

include(GNUInstallDirs)
if(FORCE_PORTABLE_INSTALL)
set(CMAKE_INSTALL_BINDIR ".")
Expand All @@ -86,6 +88,15 @@ if(FORCE_PORTABLE_INSTALL)
set(CMAKE_INSTALL_DOCDIR ".")
endif()

# Get info about multi-config environment
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# Properly determine output directory for generated files
if(IS_MULTI_CONFIG)
set(D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/$<CONFIG>")
else ()
set(D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")
endif()

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed" CACHE PATH "Default install path" FORCE)
endif()
Expand All @@ -110,6 +121,15 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

# Define names for HOG files
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
set(HOG_NAME "linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(HOG_NAME "osx")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(HOG_NAME "win")
endif()

# rebuild d3_version.h every time
add_custom_target(get_git_hash ALL)

Expand Down
19 changes: 18 additions & 1 deletion Descent3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,24 @@ target_link_libraries(Descent3 PRIVATE
${PLATFORM_LIBS})
target_include_directories(Descent3 PRIVATE ${PROJECT_BINARY_DIR}/lib)
target_link_options(Descent3 PRIVATE $<$<PLATFORM_ID:Windows>:/DEBUG:FULL>)
add_dependencies(Descent3 get_git_hash Direct_TCP_IP_Hog Descent3_Online_TCP_IP_Hog HogFull NetgamesDir Parallax_Online_Hog)
set_target_properties(Descent3 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")
add_dependencies(Descent3
get_git_hash
Direct_TCP_IP_Hog
Descent3_Online_TCP_IP_Hog
HogFull
Parallax_Online_Hog
anarchy
coop
ctf
entropy
hoard
hyperanarchy
monsterball
roboanarchy
tanarchy
)

install(TARGETS Descent3 RUNTIME BUNDLE DESTINATION .)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:Descent3> DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
73 changes: 59 additions & 14 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,84 @@
# Descent 3 Open source usage instructions

**Important note**: This open source distribution of Descent 3 DOES NOT CONTAIN GAME ASSETS. Assets must be acquired separately from an official copy of the game, and copied as describe in the next section.
**Important note**: This open source distribution of Descent 3 DOES NOT CONTAIN
GAME ASSETS. Assets must be acquired separately from an official copy of the
game, and copied as describe in the next section.

This is the first release of the Descent 3 open source engine, that should be considered a beta version. If you find a bug that has not been reported before, please open a new ticket it on our [online issue tracker](https://github.com/DescentDevelopers/Descent3/issues).
This is the first release of the Descent 3 open source engine, that should be
considered a beta version. If you find a bug that has not been reported before,
please open a new ticket it on our [online issue tracker](https://github.com/DescentDevelopers/Descent3/issues).

1. Make sure that you have a copy of Descent 3. You can purchase a copy of
Descent 3 from [GOG](https://www.gog.com/game/descent_3_expansion) or
[Steam](https://store.steampowered.com/app/273590/Descent_3/).

1. Make sure that you have a copy of Descent 3. You can purchase a copy of Descent 3 from [GOG](https://www.gog.com/game/descent_3_expansion) or [Steam](https://store.steampowered.com/app/273590/Descent_3/).
2. Install Descent 3.
**Note for Steam users:** If you own Descent 3 on Steam, then it’s recommended that you install the Windows version of the game even if you’re running macOS or Linux, otherwise movies will not work due to [current lack of Ogv support](https://github.com/DescentDevelopers/Descent3/issues/240). You can use either [Steam Play](https://help.steampowered.com/en/faqs/view/08F7-5D56-9654-39AF) or [SteamCMD](https://developer.valvesoftware.com/wiki/SteamCMD#Cross-Platform_Installation) to install the Windows version of the game on macOS or Linux.
3. If your version of Descent 3 is older than v1.4, then [update it to v1.4](http://descent3.com/downloads.php).
4. Find the installation location of Descent 3. Using the Steam client, you can find it from the library page using the `Manage > Browse local files` context menu.
**Note for Steam users:** If you own Descent 3 on Steam, then it’s recommended
that you install the Windows version of the game even if you’re running macOS
or Linux, otherwise movies will not work due to
[current lack of OGV support](https://github.com/DescentDevelopers/Descent3/issues/240).
You can use either [Steam Play](https://help.steampowered.com/en/faqs/view/08F7-5D56-9654-39AF)
or [SteamCMD](https://developer.valvesoftware.com/wiki/SteamCMD#Cross-Platform_Installation)
to install the Windows version of the game on macOS or Linux.

3. If your version of Descent 3 is older than v1.4, then
[update it to v1.4](http://descent3.com/downloads.php).

4. Find the installation location of Descent 3. Using the Steam client, you can
find it from the library page using the `Manage > Browse local files`
context menu.

5. Create a new folder named `D3-open-source`.

6. Copy the following files from your installation of Descent 3 to `D3-open-source`:
- All `.hog` files
- The `missions` folder
- _(Optional)_ All `.pld` files
- _(Optional)_ The `movies` folder

7. Create the `custom/` folder in `D3-open-source`

8. Obtain new Descent 3 engine files:
- If you want to use pre-built binaries, then download the latest [release](https://github.com/DescentDevelopers/Descent3/releases). For a more cutting-edge experience with the latest features, use the artifacts from the latest automated build. You can find the list of automated builds [here](https://github.com/DescentDevelopers/Descent3/actions/workflows/build.yml?query=branch%3Amain+event%3Apush).
- If you want to build the engine files yourself, the follow the instructions in [BUILD.md](BUILD.md). Once you build the engine files, they’ll be put in `builds/<platform>/Descent3/<build-type>/`. For example, if you’re using Linux and you create a “Release” build, then the files will be located at `builds/linux/Descent3/Release`.
9. Copy all of the new engine files into `D3-open-source` and overwrite any conflicts.
- If you want to use pre-built binaries, then download the latest
[release](https://github.com/DescentDevelopers/Descent3/releases). For a
more cutting-edge experience with the latest features, use the artifacts
from the latest automated build. You can find the list of automated
builds [here](https://github.com/DescentDevelopers/Descent3/actions/workflows/build.yml?query=branch%3Amain+event%3Apush).
- If you want to build the engine files yourself, the follow the
instructions in [BUILD.md](BUILD.md). Once you build the engine files,
they’ll be put in `builds/<platform>/<build-type>/`. For example, if
you’re using Linux and you create a “Release” build, then the files will
be located at `builds/linux/Release`.

9. Copy all the new engine files into `D3-open-source` and overwrite any
conflicts.

10. Special notes:
- D3 Open Source compiles level scripts in their own hogfiles. Make sure you copy and overwrite `d3-{platform}.hog`.
- D3 Open Source compiles level scripts in their own hogfiles. Make sure
you copy and overwrite `d3-{platform}.hog`.

11. Run the game:
- On Windows, run `D3-open-source\Descent3.exe` from a command-line or double-click on the `Descent3` executable.
- On Linux, `cd` to `D3-open-source` and run `./Descent3`. Wayland users may need to set environement variable `SDL_VIDEODRIVER=wayland` before launching the game.
- On MacOS, the `.app` bundle is currently not signed, so your operating system will not let you run it by double-clicking it. To remediate that, open your terminal and `cd` to `D3-open-source`. Run `xattr -c ./Descent3.app` and then `chmod +x ./Descent3.app/Content/MacOS/Descent3`, then run the game using `./Descent3.app/Content/MacOS/Descent3`
- On Windows, run `D3-open-source\Descent3.exe` from a command-line or
double-click on the `Descent3` executable.
- On Linux, `cd` to `D3-open-source` and run `./Descent3`. Wayland users
may need to set environment variable `SDL_VIDEODRIVER=wayland` before
launching the game.
- On macOS, the `.app` bundle is currently not signed, so your operating
system will not let you run it by double-clicking it. To remediate that,
open your terminal and `cd` to `D3-open-source`. Run
`xattr -c ./Descent3.app` and then
`chmod +x ./Descent3.app/Content/MacOS/Descent3`, then run the game
using `./Descent3.app/Content/MacOS/Descent3`

## Troubleshooting

```
Descent 3 Message(Error: Couldn't find the string table.)
```

This error means that game data could not be found. Make sure you copied all game files to the `D3-open-source` folder, and that you're running the game from this same folder.
This error means that game data could not be found. Make sure you copied all
game files to the `D3-open-source` folder, and that you're running the game
from this same folder.

## Command line options

Expand Down
58 changes: 58 additions & 0 deletions cmake/HogMaker.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Descent 3
# Copyright (C) 2024 Descent Developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.


# - Function making a HOG file based on supplied filelist.
#
# This module provides function MakeHog() used for building HOG files.
# MakeHog() registers custom target TARGET which can be used as dependency.
#
# MakeHog(
# <TARGET target>
# <OUTPUT d3-full-win32.hog>
# <INPUT_FILE filelist.txt>
# [SEARCH_PATH additional_dirs]
# [DEPENDS additional_dependencies]
# )
#

function(MakeHog)
set(options)
set(oneValueArgs INPUT_FILE OUTPUT TARGET)
set(multiValueArgs DEPENDS SEARCH_PATH)

cmake_parse_arguments(PARSE_ARGV 0
"HOG"
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
)

# Register custom target for tracking dependencies
add_custom_target("${HOG_TARGET}"
DEPENDS "${HOG_OUTPUT}"
)

add_custom_command(OUTPUT "${HOG_OUTPUT}"
COMMAND $<TARGET_FILE:HogMaker>
"${HOG_OUTPUT}"
"${HOG_INPUT_FILE}"
"${HOG_SEARCH_PATH}"
DEPENDS HogMaker ${HOG_INPUT_FILE} ${HOG_DEPENDS}
COMMENT "Generate ${HOG_OUTPUT}"
COMMAND_EXPAND_LISTS
)
endfunction()
20 changes: 11 additions & 9 deletions netcon/descent3onlineclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Descent3_Online_TCP_IP PROPERTIES SUFFIX ".dylib")
endif()

add_custom_target(Descent3_Online_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c"
"${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Descent3_Online_TCP_IP>"
include(HogMaker)
MakeHog(
TARGET Descent3_Online_TCP_IP_Hog
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Descent3 Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Descent3_Online_TCP_IP>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Descent3_Online_TCP_IP
)

DEPENDS Descent3_Online_TCP_IP HogMaker
COMMENT "Generate 'Descent3 Online.d3c'"
install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Descent3 Online.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
1 change: 0 additions & 1 deletion netcon/descent3onlineclient/d3online.d3c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ Descent3 Online.dll
Descent3 Online.dylib
d3online_main.ogf
d3online_game.ogf

20 changes: 11 additions & 9 deletions netcon/lanclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Direct_TCP_IP PROPERTIES SUFFIX ".dylib")
endif()

add_custom_target(Direct_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c"
"${CMAKE_SOURCE_DIR}/netcon/lanclient/TCP_IP.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Direct_TCP_IP>"
include(HogMaker)
MakeHog(
TARGET Direct_TCP_IP_Hog
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Direct TCP~IP.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/lanclient/TCP_IP.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Direct_TCP_IP>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Direct_TCP_IP
)

DEPENDS Direct_TCP_IP HogMaker
COMMENT "Generate 'Direct TCP~IP.d3c'"
install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Direct TCP~IP.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
20 changes: 11 additions & 9 deletions netcon/mtclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Parallax_Online PROPERTIES SUFFIX ".dylib")
endif()

add_custom_target(Parallax_Online_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c"
"${CMAKE_SOURCE_DIR}/netcon/mtclient/Parallax_Online.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Parallax_Online>"
include(HogMaker)
MakeHog(
TARGET Parallax_Online_Hog
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Parallax Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/mtclient/Parallax_Online.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Parallax_Online>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Parallax_Online
)

DEPENDS Parallax_Online HogMaker
COMMENT "Generate 'Parallax Online.d3c'"
install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Parallax Online.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
13 changes: 0 additions & 13 deletions netgames/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,3 @@ add_subdirectory(hyperanarchy)
add_subdirectory(monsterball)
add_subdirectory(roboanarchy)
add_subdirectory(tanarchy)

add_custom_target(NetgamesDir
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:anarchy> "$<TARGET_FILE_DIR:Descent3>/netgames/Anarchy.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:coop> "$<TARGET_FILE_DIR:Descent3>/netgames/Co-op.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:ctf> "$<TARGET_FILE_DIR:Descent3>/netgames/CTF.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:entropy> "$<TARGET_FILE_DIR:Descent3>/netgames/Entropy.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:hoard> "$<TARGET_FILE_DIR:Descent3>/netgames/Hoard.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:hyperanarchy> "$<TARGET_FILE_DIR:Descent3>/netgames/Hyper-Anarchy.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:monsterball> "$<TARGET_FILE_DIR:Descent3>/netgames/Monsterball.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:roboanarchy> "$<TARGET_FILE_DIR:Descent3>/netgames/Robo-Anarchy.d3m"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:tanarchy> "$<TARGET_FILE_DIR:Descent3>/netgames/Team Anarchy.d3m"
COMMENT "Create netgames/ directory"
)
2 changes: 2 additions & 0 deletions netgames/anarchy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ add_library(${NETGAME_MODULE} MODULE ${CPPS} ${HEADERS})
set_target_properties(${NETGAME_MODULE} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
set_target_properties(${NETGAME_MODULE} PROPERTIES PREFIX "")
set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
set_target_properties(${NETGAME_MODULE} PROPERTIES LIBRARY_OUTPUT_NAME "anarchy")
set_target_properties(${NETGAME_MODULE} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:Descent3>/netgames")

target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
Expand Down
Loading

0 comments on commit f6faeaa

Please sign in to comment.