Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 14 additions & 11 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,18 @@ cmake --preset linux -DBUILD_TESTING=ON

You can also use the [cmake-gui](https://cmake.org/cmake/help/latest/manual/cmake-gui.1.html) front-end to easily set and view CMake cache variable values, and generate build

| Option | Description | Default |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| `CMAKE_BUILD_TYPE` | `Debug` builds are generally larger, slower and contain extra correctness checks that will validate game data and interrupt gameplay when problems are detected.<br>`Release` builds are optimized for size and speed and do not include debugging information, which makes it harder to find problems. The build type can also be set using the `--config` argument with a preset. | `Debug` |
| `BUILD_EDITOR` | _(Windows-only)_ Build internal editor. | `OFF` |
| `BUILD_TESTING` | Enable testing. Requires GTest. | `OFF` |
| `ENABLE_LOGGER` | Enable logging to the terminal. | `OFF` |
| `ENABLE_MEM_RTL` | Enable Real-time library memory management functions (disable to verbose memory allocations). | `ON` |
| `FORCE_COLORED_OUTPUT` | Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja). | `OFF` |
| `FORCE_PORTABLE_INSTALL` | Install all files into local directory defined by `CMAKE_INSTALL_PREFIX`. | `ON` |
| Option | Description | Default |
|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| `CMAKE_BUILD_TYPE` | `Debug` builds are generally larger, slower and contain extra correctness checks that will validate game data and interrupt gameplay when problems are detected.<br>`Release` builds are optimized for size and speed and do not include debugging information, which makes it harder to find problems. The build type can also be set using the `--config` argument with a preset. | `Debug` |
| `BUILD_EDITOR` | _(Windows-only)_ Build internal editor. | `OFF` |
| `BUILD_TESTING` | Enable testing. Requires GTest. | `OFF` |
| `DEFAULT_ADDITIONAL_DIRS` | A semi-colon separated list of paths that Descent 3 will use as read-only base directories (see [USAGE.md’s Base directories section][1]). Each item in this list is placed between quotation marks in order to form a C++ expression. This will cause issues if the items in the list are not properly escaped. You can use C++ escape sequences in order to embed special characters (like `\`, `"` and `;`) in paths. Example: `C:\\Games\\Descent3\\;D:\\` | A list with one item in it. The item is an empty string. |
| `ENABLE_LOGGER` | Enable logging to the terminal. | `OFF` |
| `ENABLE_MEM_RTL` | Enable Real-time library memory management functions (disable to verbose memory allocations). | `ON` |
| `FORCE_COLORED_OUTPUT` | Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja). | `OFF` |
| `FORCE_PORTABLE_INSTALL` | Install all files into local directory defined by `CMAKE_INSTALL_PREFIX`. | `ON` |
| `OFF` |
| `USE_VCPKG` | Explicitly control whether or not to use vcpkg for dependency resolution. `ON` requires the environment variable `VCPKG_ROOT` to be set. | Determined by the existence of `VCPKG_ROOT` in the environment: If it exists, vcpkg is used. |
| `CODESIGN_IDENTITY` | Sets the macOS code signing identity. If set to something besides the empty string, then the dynamic libraries put into the hog files will be signed using this identity. | The empty string, `""`. |
| `USE_VCPKG` | Explicitly control whether or not to use vcpkg for dependency resolution. `ON` requires the environment variable `VCPKG_ROOT` to be set. | Determined by the existence of `VCPKG_ROOT` in the environment: If it exists, vcpkg is used. |
| `CODESIGN_IDENTITY` | Sets the macOS code signing identity. If set to something besides the empty string, then the dynamic libraries put into the hog files will be signed using this identity. | The empty string, `""`. |

[1]: ./USAGE.md#base-directories
4 changes: 4 additions & 0 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
* Copyright (C) 2024–2025 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
Expand Down Expand Up @@ -1424,6 +1425,9 @@ void InitIOSystems(bool editor) {
LOG_INFO << "Setting writable preference path " << pref_path;
cf_AddBaseDirectory(pref_path);

// Set the default base directories
cf_AddDefaultBaseDirectories();

// Additional paths
int additionaldirarg = 0;
while (0 != (additionaldirarg = FindArg("-additionaldir", additionaldirarg))) {
Expand Down
7 changes: 4 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ Descent 3 has two types of base directories:
- The writable base directory can contain both read-write files and read-only files. There is only one writeable base directory. By default, the writable base directory gets set to the current working directory.
- The read-only base directories can only contain read-only files. There can be any number of read-only base directories. By default, Descent 3 uses zero read-only base directories.

You can set the writable base directory and the list of read-only base directories using the `-setdir`, `-useexedir` and `-additionaldir` command-line options (see [the next section](#command-line-options)).
You can set the writable base directory and the list of read-only base directories using the `-setdir`, `-useexedir` and `-additionaldir` command-line options (see [the next section](#command-line-options)). Descent 3 also has a list of default read-only base directories. Normally, the list of default read-only base directories is empty, but you can change it by using the `DEFAULT_ADDITIONAL_DIRS` CMake option when compiling Descent 3 (see [BUILD.md’s Build Options section](./BUILD.md#build-options)).

When Descent 3 tries to find a read-only file, then it will look through the list of base directories in this order:

- the last read-only base directory that was specified on the command-line,
- the second-to-last read-only base directory that was specified on the command-line,
- the third-to-last read-only base directory that was specified on the command-line,
- …
- the first read-only base directory that was specified on the command-line and, finally,
- the first read-only base directory that was specified on the command-line,
- all of the items on the `DEFAULT_ADDITIONAL_DIRS` list in reverse order, and, finally,
- the writable base directory.

Files that are in base directories that are higher on that list will override files that are in base directories that are lower on that list. For example, lets say that you run Descent 3 like this:
Files that are in base directories that are higher on that list will override files that are in base directories that are lower on that list. For example, lets say that the `DEFAULT_ADDITIONAL_DIRS` list is empty and that you run Descent 3 like this:

```
Descent3 -setdir /home/user/my-writable-base-directory -additionaldir /home/user/my-read-only-base-directory
Expand Down
13 changes: 13 additions & 0 deletions cfile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(HEADERS
cfile.h
default_base_directories.h
hogfile.h
inffile.h)
set(CPPS
Expand All @@ -8,6 +9,17 @@ set(CPPS
inffile.cpp
)

set(DEFAULT_ADDITIONAL_DIRS "" CACHE STRING "A list of directories that Descent 3 will use as read-only base directories.")
string(REPLACE ";" "\",\n \"" DEFAULT_ADDITIONAL_DIRS_CPP_EXPR "${DEFAULT_ADDITIONAL_DIRS}")
string(PREPEND DEFAULT_ADDITIONAL_DIRS_CPP_EXPR "\"")
string(APPEND DEFAULT_ADDITIONAL_DIRS_CPP_EXPR "\"")

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/default_base_directories.h.in
${CMAKE_CURRENT_BINARY_DIR}/default_base_directories.h
@ONLY
)

add_library(cfile STATIC ${HEADERS} ${CPPS})
target_link_libraries(cfile PRIVATE
ddebug
Expand All @@ -20,6 +32,7 @@ target_include_directories(cfile PUBLIC
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/cfile
>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # For default_base_directories.h
)

if(BUILD_TESTING)
Expand Down
13 changes: 13 additions & 0 deletions cfile/cfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
* Copyright (C) 2024–2025 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
Expand Down Expand Up @@ -30,6 +31,7 @@
#include "byteswap.h"
#include "crossplat.h"
#include "cfile.h"
#include "default_base_directories.h"
#include "ddio.h"
#include "hogfile.h" //info about library file
#include "log.h"
Expand Down Expand Up @@ -75,6 +77,17 @@
// The message for unexpected end of file
const char *eof_error = "Unexpected end of file";

/* The user can specify a list of default read-only base directories by setting
* the -DDEFAULT_ADDITIONAL_DIRS CMake option. This function adds those base
* directories to the list of base directories that the game is currently
* using.
*/
void cf_AddDefaultBaseDirectories() {
for (const auto &base_directory : D3::Default_read_only_base_directories) {
cf_AddBaseDirectory(base_directory);
}
}

/* This function should be called at least once before you use anything else
* from this module.
*/
Expand Down Expand Up @@ -142,14 +155,14 @@

std::vector<std::filesystem::path> cf_LocatePathMultiplePathsHelper(const std::filesystem::path &relative_path,
bool stop_after_first_result) {
ASSERT(("realative_path should be a relative path.", relative_path.is_relative()));

Check warning on line 158 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Debug

left operand of comma operator has no effect [-Wunused-value]

Check warning on line 158 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Debug

left operand of comma operator has no effect [-Wunused-value]
std::vector<std::filesystem::path> return_value = { };
for (auto base_directories_iterator = Base_directories.rbegin();
base_directories_iterator != Base_directories.rend();
++base_directories_iterator) {
ASSERT(("base_directory should be an absolute path.", base_directories_iterator->is_absolute()));

Check warning on line 163 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Debug

left operand of comma operator has no effect [-Wunused-value]

Check warning on line 163 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Debug

left operand of comma operator has no effect [-Wunused-value]
auto to_append = cf_LocatePathCaseInsensitiveHelper(relative_path, *base_directories_iterator);
ASSERT(("to_append should be either empty or an absolute path.", to_append.empty() || to_append.is_absolute()));

Check warning on line 165 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Debug

left operand of comma operator has no effect [-Wunused-value]
if (std::filesystem::exists(to_append)) {
return_value.push_back(to_append);
if (stop_after_first_result) {
Expand Down Expand Up @@ -256,7 +269,7 @@
fseek(fp, HOG_HDR_SIZE, SEEK_SET);

// read in index table
for (i = 0; i < lib->nfiles; i++) {

Check warning on line 272 in cfile/cfile.cpp

View workflow job for this annotation

GitHub Actions / Build for PR / Linux-x64, Release

comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
if (!ReadHogEntry(fp, &entry)) {
fclose(fp);
return 0;
Expand Down
8 changes: 8 additions & 0 deletions cfile/cfile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
* Copyright (C) 2024–2025 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
Expand Down Expand Up @@ -155,6 +156,13 @@ extern std::vector<std::filesystem::path> Base_directories;
*/
void cf_AddBaseDirectory(const std::filesystem::path &base_directory);

/* The user can specify a list of default read-only base directories by setting
* the -DDEFAULT_ADDITIONAL_DIRS CMake option. This function adds those base
* directories to the list of base directories that the game is currently
* using.
*/
void cf_AddDefaultBaseDirectories();

/* After you call this function, you must call cf_AddBaseDirectory() at least
* once before you use anything else from this module.
*/
Expand Down
30 changes: 30 additions & 0 deletions cfile/default_base_directories.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Descent 3
* Copyright (C) 2024–2025 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/>.
*/
#ifndef DEFAULT_ADDITIONAL_DIRECTORIES_H
#define DEFAULT_ADDITIONAL_DIRECTORIES_H

#include <filesystem>
#include <initializer_list>

namespace D3 {
const std::initializer_list<std::filesystem::path> Default_read_only_base_directories = {
@DEFAULT_ADDITIONAL_DIRS_CPP_EXPR@
};
} // namespace D3

#endif
Loading