diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6e4a74ba7..758b4c8d5 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -14,6 +14,14 @@ on:
permissions: {}
+# A newer push to a pull request makes the run for its older commit pointless, so that run is
+# cancelled (sonar.yml then marks the analysis of the older commit as skipped). A push to master
+# gets a group of its own, its commit, so the runs on master are neither cancelled nor held back
+# by one another.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }}
+ cancel-in-progress: true
+
jobs:
build:
name: Build under Build Wrapper
@@ -23,18 +31,26 @@ jobs:
env:
BUILD_WRAPPER_OUT_DIR: bw-output
steps:
- - uses: actions/checkout@v5
+ - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
fetch-depth: 0
submodules: recursive
- name: Set up Python 3.14
- uses: actions/setup-python@v6
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: '3.14'
+ # A mirror that stops answering used to hold this step for over an hour.
+ # Time out each download, retry it, and give up on the whole step early.
- name: Install build dependencies
+ timeout-minutes: 15
run: |
+ printf '%s\n' \
+ 'Acquire::Retries "3";' \
+ 'Acquire::http::Timeout "60";' \
+ 'Acquire::https::Timeout "60";' \
+ | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null
sudo apt-get update -y
sudo apt-get install -y \
build-essential \
@@ -103,10 +119,11 @@ jobs:
--exclude='*.o' \
--exclude='*.a' \
--exclude='*.so' \
+ --exclude='*.so.*' \
-C "$GITHUB_WORKSPACE" .
- name: Upload analysis input
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sonar-input
path: /tmp/workspace.tar.gz
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index 8c900b8f5..d3c33f032 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -27,9 +27,17 @@ jobs:
# Windows / MSVC
# ============================================================
+ # A newer push to the same branch or pull request cancels the build of the older commit. The
+ # groups are set on the build jobs rather than on the workflow, so a publish job that is already
+ # running is left to finish; with a build cancelled the publish job of that run is skipped. A push
+ # to master gets a group of its own, its commit, so the builds of master are never cancelled.
+
windows:
name: Windows x64 / MSVC / ${{ matrix.variant.name }}
runs-on: windows-2022
+ concurrency:
+ group: ${{ github.workflow }}-windows-${{ github.event_name }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
+ cancel-in-progress: true
strategy:
fail-fast: false
@@ -44,18 +52,27 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v6
+ uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
submodules: recursive
- name: Setup Python 3.14
id: python
- uses: actions/setup-python@v6
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.14"
architecture: "x64"
+ # the cab screens are drawn with Pillow; CMake copies this Python's Lib, site-packages included, next to the
+ # executable as python64\Lib, so Pillow has to be installed here to come with the build (as on Linux)
+ - name: Install Pillow for the screens
+ shell: pwsh
+ run: |
+ $pythonExe = "${{ steps.python.outputs.python-path }}"
+ & $pythonExe -m pip install --no-cache-dir Pillow
+ & $pythonExe -c "from PIL import Image; print('Pillow:', Image.__version__)"
+
- name: Show environment
shell: pwsh
run: |
@@ -78,6 +95,27 @@ jobs:
run: |
call setup.bat
+ # the unit tests run at the end of the build and load lua51.dll (the Lua screens), but ref/luajit has only its import
+ # library. LuaJIT of the same 2.0 line is built here and put on PATH for them; it doesn't go into the uploaded build
+ - name: Build lua51.dll for the unit tests
+ shell: cmd
+ run: |
+ for /f "usebackq delims=" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSDIR=%%i"
+ call "%VSDIR%\VC\Auxiliary\Build\vcvars64.bat" || exit /b 1
+ git init -q "%RUNNER_TEMP%\LuaJIT" || exit /b 1
+ cd /d "%RUNNER_TEMP%\LuaJIT"
+ rem the v2.0 branch of LuaJIT, pinned
+ git fetch -q --depth 1 https://github.com/LuaJIT/LuaJIT.git b83bcba6ea300d4eb16e8257ddf80bcdef1f938b || exit /b 1
+ git checkout -q FETCH_HEAD || exit /b 1
+ cd src
+ rem msvcbuild.bat runs the tools it builds (minilua, buildvm) from the current folder
+ set NoDefaultCurrentDirectoryInExePath=
+ call .\msvcbuild.bat || exit /b 1
+ if not exist lua51.dll exit /b 1
+ mkdir "%RUNNER_TEMP%\lua51"
+ copy /y lua51.dll "%RUNNER_TEMP%\lua51\" || exit /b 1
+ echo %RUNNER_TEMP%\lua51>> "%GITHUB_PATH%"
+
- name: Configure
shell: pwsh
run: |
@@ -100,7 +138,7 @@ jobs:
--config $env:CONFIG_WIN `
--parallel
- - name: Copy shaders
+ - name: Copy shaders and translations
shell: pwsh
run: |
$output = "build/bin/$env:CONFIG_WIN"
@@ -116,8 +154,31 @@ jobs:
-Recurse `
-Force
+ New-Item `
+ -ItemType Directory `
+ -Force `
+ -Path "$output/lang" | Out-Null
+
+ Copy-Item `
+ -Path "lang/*" `
+ -Destination "$output/lang" `
+ -Recurse `
+ -Force
+
+ # the Python 3 version of the module every cab screen builds on; the game data still has the Python 2 one
+ New-Item `
+ -ItemType Directory `
+ -Force `
+ -Path "$output/python/local" | Out-Null
+
+ Copy-Item `
+ -Path "staticFiles/python/local/*" `
+ -Destination "$output/python/local" `
+ -Recurse `
+ -Force
+
- name: Upload Windows build
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: maszyna-windows-x64-${{ matrix.variant.suffix }}-${{ env.CONFIG_WIN }}
path: |
@@ -126,7 +187,7 @@ jobs:
retention-days: 14
- name: Upload Windows debug symbols
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: maszyna-windows-x64-symbols-${{ matrix.variant.suffix }}-${{ env.CONFIG_WIN }}
path: |
@@ -143,26 +204,43 @@ jobs:
linux:
name: Linux x64 / GCC
runs-on: ubuntu-24.04
+ # see the note above the windows job
+ concurrency:
+ group: ${{ github.workflow }}-linux-${{ github.event_name }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
+ cancel-in-progress: true
steps:
- name: Checkout repository
- uses: actions/checkout@v6
+ uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
submodules: recursive
- name: Setup Python 3.14
id: python
- uses: actions/setup-python@v6
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.14"
+ # A mirror that stops answering used to hold this step for over an hour.
+ # Time out each download, retry it, and give up on the whole step early.
- name: Install Linux dependencies
+ timeout-minutes: 15
run: |
+ printf '%s\n' \
+ 'Acquire::Retries "3";' \
+ 'Acquire::http::Timeout "60";' \
+ 'Acquire::https::Timeout "60";' \
+ | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null
sudo apt-get update
+ # libasound2-dev, libpulse-dev and libpipewire-0.3-dev: the headers of OpenAL Soft's audio backends (built below).
+ # Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound.
sudo apt-get install -y \
build-essential \
+ libasound2-dev \
+ libpulse-dev \
+ libpipewire-0.3-dev \
libgl1-mesa-dev \
libglew-dev \
libglfw3-dev \
@@ -171,6 +249,7 @@ jobs:
libluajit-5.1-dev \
libserialport-dev \
libsndfile1-dev \
+ libcurl4-openssl-dev \
xorg-dev \
libxkbcommon-dev \
libwayland-dev \
@@ -188,12 +267,17 @@ jobs:
https://github.com/kcat/openal-soft.git \
/tmp/openal-soft
+ # the backends are loaded with dlopen at run time (ALSOFT_DLOPEN), so the bundled library needs none of them;
+ # REQUIRE makes a missing header fail the build instead of shipping a library without sound
cmake \
-S /tmp/openal-soft \
-B /tmp/openal-soft/build \
-DCMAKE_BUILD_TYPE=Release \
-DALSOFT_EXAMPLES=OFF \
- -DALSOFT_UTILS=OFF
+ -DALSOFT_UTILS=OFF \
+ -DALSOFT_REQUIRE_PIPEWIRE=ON \
+ -DALSOFT_REQUIRE_PULSEAUDIO=ON \
+ -DALSOFT_REQUIRE_ALSA=ON
cmake \
--build /tmp/openal-soft/build \
@@ -229,7 +313,31 @@ jobs:
cmake \
--build build \
--parallel "$(nproc)"
-
+
+ # the build copies the shared libraries next to the game (CMake_modules/bundle_runtime_libs.cmake) and the
+ # game looks for them there first ($ORIGIN): each one it loads from outside build/bin has to be one of the system
+ - name: Check the bundled libraries
+ run: |
+ GAME="$(find build/bin -maxdepth 1 -type f -name 'eu07*' -perm -u+x | head -n 1)"
+ test -n "$GAME"
+ echo "Game: $GAME"
+ readelf -d "$GAME" | grep -E 'R(UN)?PATH'
+ readelf -d "$GAME" | grep -q 'Library rpath: \[\$ORIGIN\]'
+ cat build/bin/bundled_libs.txt
+ ldd "$GAME"
+ if ldd "$GAME" | grep -q 'not found'; then
+ echo "::error::the game needs a library that is neither bundled nor in the system"
+ exit 1
+ fi
+ while read -r name; do
+ [ -n "$name" ] || continue
+ loaded="$(ldd "$GAME" | awk -v n="$name" '$1 == n { print $3 }')"
+ if [ -z "$loaded" ] || [ "$(realpath "$loaded")" != "$(realpath "build/bin/$name")" ]; then
+ echo "::error::$name is bundled, but the game loads it from '$loaded'"
+ exit 1
+ fi
+ done < build/bin/bundled_libs.txt
+
- name: Prepare Linux Python environment
run: |
PYTHON_ROOT="$(python -c 'import sys; print(sys.base_prefix)')"
@@ -251,16 +359,96 @@ jobs:
"$PYTHON_HOME/bin/python" -c "from PIL import Image; print('Pillow:', Image.__version__)"
- - name: Copy shaders
+ - name: Copy shaders and translations
run: |
- mkdir -p build/bin/shaders
+ mkdir -p build/bin/shaders build/bin/lang build/bin/python/local
cp -R shaders/. build/bin/shaders/
+ cp -R lang/. build/bin/lang/
+ # the Python 3 version of the module every cab screen builds on; the game data still has the Python 2 one
+ cp -R staticFiles/python/local/. build/bin/python/local/
- name: Upload Linux build
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: maszyna-linux-x64-${{ env.CONFIG_LINUX }}
path: |
build/bin/
if-no-files-found: error
retention-days: 14
+
+
+ # ============================================================
+ # Public download: release assets need no GitHub account
+ # ============================================================
+
+ publish:
+ name: Publish public download
+ needs: [windows, linux]
+ if: github.event_name != 'pull_request'
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: write
+ concurrency:
+ group: publish-${{ github.ref }}
+ cancel-in-progress: false
+
+ steps:
+ - name: Download Windows build
+ uses: actions/download-artifact@v4
+ with:
+ name: maszyna-windows-x64-${{ env.CONFIG_WIN }}
+ path: dist/maszyna-windows-x64
+
+ - name: Download Linux build
+ uses: actions/download-artifact@v4
+ with:
+ name: maszyna-linux-x64-${{ env.CONFIG_LINUX }}
+ path: dist/maszyna-linux-x64
+
+ - name: Pack
+ run: |
+ cd dist
+
+ find maszyna-linux-x64 -type f -exec sh -c 'file -b "$1" | grep -q "^ELF" && chmod +x "$1"' _ {} \;
+ if [ -d maszyna-linux-x64/linuxpython64/bin ]; then
+ chmod +x maszyna-linux-x64/linuxpython64/bin/*
+ fi
+
+ (cd maszyna-windows-x64 && zip -qr9 ../maszyna-windows-x64.zip .)
+ tar -czf maszyna-linux-x64.tar.gz -C maszyna-linux-x64 .
+ ls -la
+
+ - name: Publish rolling release of the branch
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ BRANCH: ${{ github.ref_name }}
+ SHA: ${{ github.sha }}
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ run: |
+ slug="$(printf '%s' "$BRANCH" | tr '/ ' '--' | tr -cd '[:alnum:]._-')"
+ tag="build-$slug"
+ base="${{ github.server_url }}/${{ github.repository }}/releases/download/$tag"
+
+ notes="$(printf '%s\n' \
+ "Automatic build of branch \`$BRANCH\`, commit $SHA, replaced by every push to the branch." \
+ "" \
+ "Download without a GitHub account:" \
+ "- Windows: $base/maszyna-windows-x64.zip" \
+ "- Linux: $base/maszyna-linux-x64.tar.gz" \
+ "" \
+ "Unpack over a MaSzyna installation (the game data isn't included). Build log: $RUN_URL")"
+
+ gh release delete "$tag" --yes --cleanup-tag || true
+ gh release create "$tag" \
+ dist/maszyna-windows-x64.zip \
+ dist/maszyna-linux-x64.tar.gz \
+ --target "$SHA" \
+ --prerelease \
+ --latest=false \
+ --title "Build: $BRANCH" \
+ --notes "$notes"
+
+ echo "### Public download" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Windows: $base/maszyna-windows-x64.zip" >> "$GITHUB_STEP_SUMMARY"
+ echo "- Linux: $base/maszyna-linux-x64.tar.gz" >> "$GITHUB_STEP_SUMMARY"
diff --git a/.github/workflows/build_cleanup.yml b/.github/workflows/build_cleanup.yml
new file mode 100644
index 000000000..8b20be0da
--- /dev/null
+++ b/.github/workflows/build_cleanup.yml
@@ -0,0 +1,21 @@
+name: Remove public build of a deleted branch
+
+on:
+ delete:
+
+permissions:
+ contents: write
+
+jobs:
+ cleanup:
+ if: github.event.ref_type == 'branch'
+ runs-on: ubuntu-24.04
+ steps:
+ - name: Delete the rolling release of the branch
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ BRANCH: ${{ github.event.ref }}
+ run: |
+ slug="$(printf '%s' "$BRANCH" | tr '/ ' '--' | tr -cd '[:alnum:]._-')"
+ gh release delete "build-$slug" --yes --cleanup-tag || true
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
new file mode 100644
index 000000000..d2f00bccd
--- /dev/null
+++ b/.github/workflows/coverage.yml
@@ -0,0 +1,135 @@
+# .github/workflows/coverage.yml
+# UNTRUSTED CONTEXT. This workflow runs fork-authored code.
+# It must never reference `secrets.*`. It only builds, runs the unit tests and
+# uploads a report; nothing here feeds the SonarQube Cloud analysis.
+#
+# Coverage of the game's core library (eu07_core) by the unit tests, measured with
+# gcov on a GCC build: the report goes to the summary of the run and to an artifact.
+# It is not sent to SonarQube Cloud on purpose: the project's quality gate ("Sonar
+# way") fails a pull request whose new code is covered in less than 80%, a condition
+# that isn't evaluated as long as sonar-project.properties excludes every file from
+# coverage. Wiring this report in would turn that condition on.
+
+name: Coverage
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ types: [ opened, reopened, synchronize ]
+
+permissions: {}
+
+# A newer push to a pull request cancels the run for its older commit; a push to master
+# gets a group of its own (its commit), so the runs on master are never cancelled.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }}
+ cancel-in-progress: true
+
+jobs:
+ coverage:
+ name: Unit test coverage (GCC)
+ runs-on: ubuntu-24.04
+ timeout-minutes: 60
+ permissions:
+ contents: read
+ steps:
+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
+ with:
+ submodules: recursive
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.14'
+
+ # the same packages as the Build workflow: the game is configured as a whole,
+ # though only the unit tests and the core library they link are built
+ - name: Install build dependencies
+ run: |
+ sudo apt-get update -y
+ sudo apt-get install -y \
+ build-essential \
+ libgl1-mesa-dev libglew-dev libglfw3-dev \
+ libpng-dev libopenal-dev libluajit-5.1-dev \
+ libserialport-dev libsndfile1-dev \
+ xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols
+ python3 -m pip install --no-cache-dir --only-binary :all: gcovr==8.3
+
+ - name: Build current OpenAL Soft
+ run: |
+ git clone --depth 1 --branch 1.24.2 https://github.com/kcat/openal-soft.git /tmp/openal-soft
+ cmake -S /tmp/openal-soft -B /tmp/openal-soft/build \
+ -DCMAKE_BUILD_TYPE=Release -DALSOFT_EXAMPLES=OFF -DALSOFT_UTILS=OFF
+ cmake --build /tmp/openal-soft/build -j"$(nproc)"
+ sudo cmake --install /tmp/openal-soft/build
+ sudo ldconfig
+
+ # see the Build workflow
+ - name: Patch GLM for GCC
+ run: |
+ sed -i 's/GLM_FUNC_QUALIFIER std::string format(const char\* message, \.\.\.)/inline std::string format(const char* message, ...)/' \
+ ref/glm/glm/gtx/string_cast.inl
+ grep -n "std::string format(const char\* message" ref/glm/glm/gtx/string_cast.inl
+
+ # unoptimised, so every line keeps its own code and the counts are those of the source
+ - name: Configure (CMake)
+ run: |
+ cmake -S . -B build \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DWITH_BETTER_RENDERER=OFF \
+ -DWITH_ZMQ=OFF -DWITH_OPENVR=OFF -DUSE_LTO=OFF \
+ -DCMAKE_CXX_FLAGS="--coverage -O0 -Wno-attributes -fno-inline-functions-called-once" \
+ -DPython3_EXECUTABLE="$(which python3)"
+
+ # the tests alone: the game itself isn't linked, so they aren't run by its build
+ - name: Build the unit tests
+ run: cmake --build build --target eu07_unit_tests -j"$(nproc)"
+
+ - name: Run the unit tests
+ run: ./build/tests/unit/eu07_unit_tests
+
+ # the game's own sources only: no submodules, no vendored code, not the tests themselves.
+ # betterRenderer/ is left out for its thirdparty/yaml-cpp, which every target of the game links and so builds here
+ - name: Coverage report
+ run: |
+ # a failure of gcovr fails the step, though its output goes through tee
+ set -o pipefail
+ mkdir -p coverage-report/html
+ gcovr --root . build \
+ --exclude 'ref/' --exclude 'imgui/' --exclude 'stb/' --exclude 'betterRenderer/' \
+ --exclude 'tests/' --exclude 'build/' \
+ --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \
+ --gcov-ignore-errors=no_working_dir_found \
+ --print-summary \
+ --txt coverage-report/coverage.txt \
+ --html-details coverage-report/html/index.html \
+ --sonarqube coverage-report/coverage-sonarqube.xml \
+ --json-summary-pretty --json-summary coverage-report/coverage-summary.json \
+ | tee coverage-report/summary.txt
+ {
+ echo '## Unit test coverage of the core library'
+ echo
+ echo 'GCC, unoptimised build, `eu07_unit_tests`. Lines run by the tests, per source file of the game the tests compile.'
+ echo
+ echo '```'
+ grep -E '^(lines|functions|branches):' coverage-report/summary.txt
+ echo '```'
+ echo
+ echo 'Per file
'
+ echo
+ echo '```'
+ cat coverage-report/coverage.txt
+ echo '```'
+ echo
+ echo ' '
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Upload the coverage report
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: unit-test-coverage
+ path: coverage-report
+ retention-days: 14
+ if-no-files-found: error
diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml
index 8140317ea..b29511894 100644
--- a/.github/workflows/sonar.yml
+++ b/.github/workflows/sonar.yml
@@ -64,7 +64,7 @@ jobs:
if: github.event.action == 'completed' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-24.04
permissions:
- contents: read # checkout trusted config
+ contents: read # fetch trusted config
actions: read # download artifact from the Build run
statuses: write # post the commit status
pull-requests: read # verify PR head sha via the API
@@ -83,16 +83,23 @@ jobs:
-f description="Analysis in progress" \
-f target_url="$RUN_URL"
- # Trusted copy of the repo config, used to overwrite anything the PR
- # might have tampered with (sonar-project.properties etc).
- - name: Checkout trusted config from master
- uses: actions/checkout@v5
- with:
- ref: master
- path: .trusted
+ # Trusted copy of the scanner config, used to overwrite anything the PR
+ # might have tampered with. Fetched as a single file through the API rather
+ # than with actions/checkout: nothing gets checked out in this privileged
+ # context. Kept outside the workspace, so the archive can't overwrite it.
+ - name: Fetch trusted config from master
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ set -euo pipefail
+ url="repos/${{ github.repository }}/contents/sonar-project.properties?ref=master"
+ if ! gh api -H "Accept: application/vnd.github.raw" "$url" > /tmp/trusted-sonar-project.properties; then
+ echo "::warning::no sonar-project.properties on master"
+ rm -f /tmp/trusted-sonar-project.properties
+ fi
- name: Download analysis input
- uses: actions/download-artifact@v4
+ uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: sonar-input
path: /tmp/sonar-input
@@ -102,12 +109,20 @@ jobs:
- name: Unpack analysis input
run: |
set -euo pipefail
+ # The archive holds the whole PR workspace and is unpacked over this one.
+ # Nothing may be written outside the workspace: reject absolute members and
+ # any member reaching through a parent directory before unpacking anything.
+ tar -tzf /tmp/sonar-input/workspace.tar.gz > /tmp/archive-members.txt
+ if grep -qE '^/|(^|/)[.][.](/|$)' /tmp/archive-members.txt; then
+ echo "::error::archive contains paths outside the workspace"
+ exit 1
+ fi
tar -xzf /tmp/sonar-input/workspace.tar.gz -C "$GITHUB_WORKSPACE"
# Strip PR-controlled scanner configuration, restore the trusted one.
rm -f "$GITHUB_WORKSPACE/sonar-project.properties" \
"$GITHUB_WORKSPACE/.sonarcloud.properties"
- if [ -f "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" ]; then
- cp "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" "$GITHUB_WORKSPACE/"
+ if [ -f /tmp/trusted-sonar-project.properties ]; then
+ cp /tmp/trusted-sonar-project.properties "$GITHUB_WORKSPACE/sonar-project.properties"
fi
- name: Resolve and verify PR metadata
diff --git a/.gitignore b/.gitignore
index 5186ceaee..70a6d1c68 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,5 @@ vcpkg.json
# Local Python (setup.bat / CMake) for embedding
tools/python314/
+__pycache__/
+*.pyc
diff --git a/.gitmodules b/.gitmodules
index df7f5ddaa..55d108a70 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -32,3 +32,7 @@
[submodule "betterRenderer/thirdparty/bvh"]
path = betterRenderer/thirdparty/bvh
url = https://github.com/madmann91/bvh.git
+[submodule "ref/wamr"]
+ path = ref/wamr
+ url = https://github.com/bytecodealliance/wasm-micro-runtime
+ shallow = true
diff --git a/AGENTS.md b/AGENTS.md
new file mode 100644
index 000000000..3b52f36ee
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,172 @@
+# MaSzyna: notes for coding agents
+
+These are the instructions for every coding agent that works in this repository: Claude Code, OpenAI Codex, Gemini CLI and any
+other tool that reads `AGENTS.md`. `CLAUDE.md` and `GEMINI.md` only point to this file, so a rule is added or changed here, never
+there.
+
+## The code builds and works with GCC, not only MSVC
+
+The Linux CI (`.github/workflows/build.yml`) builds with GCC 13 on ubuntu-24.04, through the Sonar build-wrapper, and `sonar.yml`
+analyses that build once it has passed. A change that compiles with MSVC only fails there, and a failed GCC build also leaves Sonar
+without an analysis of the PR. So every change has to compile with GCC, and behave the same with it, as well as with MSVC. The CI
+builds with `-DWITH_BETTER_RENDERER=OFF` and Sonar excludes `betterRenderer/`, so that part is neither built on CI nor analysed.
+
+Where no GCC is at hand, read the new code for what MSVC lets through and GCC doesn't:
+
+- `constexpr` initialised from a floating or class-type constant declared only `const`: make the source `constexpr` too.
+- Standard headers MSVC pulls in through others: include them yourself. For example, `` for `std::views`, ``,
+ ``, ``, ``, `` and ``.
+- `typename` and `this->` where a template needs them.
+- A temporary bound to a non-const reference.
+- Explicit specialisations inside a class.
+- A name a class uses and then declares again in its own body (GCC: "changes meaning").
+- A nested type with default member initialisers used as a default argument inside the class that encloses it.
+- A declaration changed in a header (`const`, parameters) without its definition, or a new member function defined but not declared.
+- `std::ifstream` / `std::ofstream` opened with a `std::wstring`.
+- MSVC-only functions: `_stricmp`, `sprintf_s`, `fopen_s`, `localtime_s` and the like.
+- Designated initialisers out of declaration order.
+- `emplace_back(a, b, c)` with parenthesised aggregate initialisation is fine on GCC 13, but not for `std::array`. There is no brace
+ elision in parentheses, so build a named local instead.
+
+The same behaviour needs portable code. Don't rely on the order arguments are evaluated in, on the signedness of `char`, on the size of
+`wchar_t`, or on `long` being 32 bits.
+
+## SonarCloud: the PR passes the quality gate
+
+SonarCloud (`sonar.yml`, `sonar-project.properties`) analyses each PR. A PR has to pass Sonar's quality gate. The gate rates the new
+code: reliability, security and maintainability have to be A, duplication is at most 3% and the security hotspots are reviewed.
+Any bug or vulnerability on the new code lowers its rating below A, so each one gets fixed (or gets a NOSONAR when it is a false
+positive). Code smells count only together, through the maintainability rating, so a single one rarely fails the gate, but many in a
+large PR can. A hotspot is reviewed by marking it in SonarCloud as safe or fixed, which is the user's step there, not a reason to
+rewrite the code. A remark that doesn't fail the gate doesn't have to be fixed. Leave large restructurings that only answer such a
+remark (splitting a class or a file, rewriting a working algorithm) out of the PR. The analysis runs on the GCC build, so a PR that
+fails to build with GCC gets no analysis at all, and so it doesn't pass the gate.
+
+Fixing a remark must not change what the code does:
+
+- Keep the order of side effects, the conditions and the floating-point results as they were.
+- Text in `STR(...)`, `STR_C(...)` and `_(...)` is looked up in the translations (`lang/*.po`), so it stays byte for byte the same.
+ The same goes for what is written to the log.
+- `// NOSONAR: ` is only for a real false positive, or where a fix would change behaviour. Use it rarely, always with the
+ reason.
+
+To keep the gate passing, write new code so that it doesn't raise the rules that keep coming up:
+
+- **S134** (nesting deeper than 3 `if` / `for` / `while` / `switch` / `try`) and **S3776** (cognitive complexity over 25):
+ - use early `continue` / `return`;
+ - move loop bodies and branches into named helpers, preferably free functions in the anonymous namespace;
+ - group the state of a long algorithm in a small struct with methods.
+
+ Every `else if`, every `&&` / `||` sequence and every nested lambda adds to the complexity.
+- **S1188**: a lambda over 20 lines becomes a named function.
+- **S107**: a function with more than 7 parameters takes a struct.
+- **S3608**: lambdas capture explicitly (`[this, &points]`, not `[&]` or `[=]`). The only exception is `[&]` on a lambda passed
+ straight to a standard algorithm; `[=]` is flagged even there, and so is `[&]` passed to one of our own functions.
+- **S6197** / **S5566**: use the `std::ranges::` algorithm that takes the container rather than a begin/end pair or a hand-written
+ loop.
+- **S6165**: use `std::erase_if` rather than erase-remove.
+- **S6004**: a variable used only by the condition is declared in the `if (init; condition)`.
+- **S3358**: no nested `?:`; use an `if` or a small function.
+- **S1121**: no assignment inside an expression, chained ones included (`a = b = c`).
+- **S1117**: no declaration shadowing a local, a member or an enumerator.
+- **S6003**: `v.emplace_back(a, b, c)` rather than `v.push_back({a, b, c})`. For a `std::array` element, push a named local instead
+ (see the GCC notes above).
+- **S6012**: let class template argument deduction work: `std::vector values{1.0, 2.0}`.
+- **S5945**: `std::array` / `std::vector` / `std::string`, not C arrays.
+- **S1659**: one declaration per statement.
+- **S6009**: `std::string_view` rather than `std::string const &` for a string parameter that is only read.
+- **S6185** / **S6494**: `std::format` rather than concatenation or `snprintf`.
+- **S924**: at most one `break` per loop.
+- **S886**: a `for` whose counter changes in its body becomes a `while`.
+- **S5997**: `std::scoped_lock` rather than `std::lock_guard`.
+- **S6168**: `std::jthread` rather than `std::thread`. A `std::jthread` joins in its destructor where a `std::thread` would
+ terminate, so in existing code switch only where the thread is always joined or detached before it is destroyed.
+- **S6177**: `using enum` where a function names many enumerators.
+- **S5350** / **S995**: `const` on references and pointers that aren't written through.
+- **S5817**: `const` on member functions that change nothing.
+- **S2193**: no `float` loop counters.
+- **S5421**: no non-const globals.
+- **S6179**: `std::lerp` rather than a hand-written interpolation, in new code. In existing code only where it gives the very same
+ result.
+- **S6164**: `std::numbers::pi` rather than a literal, in new code. In existing code only where it gives the very same result.
+
+The project is C++20 (`CMAKE_CXX_STANDARD 20`), so no C++23 library addition is available on any compiler. That rules out
+`std::ranges::to`, `views::zip`, `views::enumerate`, `ranges::contains`, `std::print` and `std::expected`.
+
+## Renderers: the move to OpenGL 4.6 and Vulkan
+
+The renderers on `master` are to be replaced. `feat/gl46-migration` (PR #216, a draft with milestone 27.04, to be merged after the
+26.11 release) replaces the OpenGL 3.3 renderer with an OpenGL 4.6 core one and adds a Vulkan 1.4 renderer beside it. It also
+removes the legacy OpenGL 2.1, the OpenGL ES / ANGLE and the NVRHI (`betterRenderer/`) paths.
+
+- `betterRenderer/` will be removed. Don't put work into it.
+- On that branch, of the `rendering/opengl*` files only `openglcamera.*` and `openglmatrixstack.*` stay. The whole
+ `rendering/opengl33*` family and the rest of the legacy `rendering/opengl*` go, and the new renderers are in
+ `rendering/opengl46/`, `rendering/vulkan14/` and `rendering/common/`. The shared `rendering/renderer.*`, `geometrybank.*`,
+ `particles.*` and the like stay. The shaders move from `shaders/` to `shaders/ogl46/` and `shaders/vk14/`.
+- So a change on `master` to the code that goes away, or to the shaders, may be pointless. Keep it to fixes and to what a feature
+ on `master` needs in order to be drawn at all. For such a change, say in the PR where `feat/gl46-migration` has the counterpart,
+ or that the branch already carries the change.
+
+## Building, testing and running
+
+- The unit tests (`tests/unit`) run at the end of the build, which prints `Unit tests: N/N passed` and fails on any failed case.
+ `-DWITH_TESTS=OFF` builds the game without them.
+- A new feature goes on its own branch from `master`, not on whatever branch is checked out. Say which branch the work lands on
+ before the first edit. A fresh worktree has empty submodules, so it doesn't build until they are filled.
+- The editor runs a script when `EU07_EDITOR_SELFTEST=` is set: one command per line, `#` for comments. The commands are in
+ `application/editormodeselftest*.cpp` (`camera`, `wait`, `select`, `lay`, `screenshot`, `save`, `quit` and many more).
+ - Run it on a copy of the scenery, never on the original, and delete the copy afterwards.
+ - Give every run a timeout and keep an eye on its memory. A loop gone wrong can fill the RAM of the whole machine.
+ - `screenshot` only queues the grab and waits 3 frames; the image is written later on another thread. A click right after it
+ has been seen to lose the selection, so leave a `wait` of about 15 frames after a `screenshot` before clicking.
+- At run time the editor's texts load from `lang/editor_.po` in the game folder (`utilities/translation.cpp`), not from
+ the build. New strings of a branch show in English until that file has them. Without the `fonts` folder Polish letters show as `?`.
+- When a build runs on a copy of the game data made of links to the real folders, turn off whatever writes into the data
+ (`convertmodels 0` in `eu07.ini`), or the run changes the real game folder through the links.
+- A test of code that moves, migrates or deletes files in the user's profile (`%APPDATA%`, `%LOCALAPPDATA%`, caches) gets its own
+ test folder. Never point it at the real profile.
+- A GPU hang (Windows TDR) can freeze the whole machine, not just the game. Don't test a hang hypothesis by running it. Guard the
+ code against what causes it (degenerate geometry, NaN in the camera or in transforms) and read the `LiveKernelEvent` / watchdog
+ dumps instead.
+- PowerShell variable names are case-insensitive: `$Track` and `$track` are the same variable.
+
+## Game data and backward compatibility
+
+The code and the game data live apart. The assets (sceneries, vehicles with their `.fiz` and `.mmd`, models, textures, sounds,
+timetables, most of `lang` and the shipped `eu07.ini`) are in a separate SVN repository, `https://svn.eu07.pl/pctga`. It needs an
+account; there is no anonymous checkout. Of `lang/`, only `editor_pl.po` is in this repository. Players install and
+launch the game through Steam, GOG and the like, and run new builds on the data they already have.
+
+The official starter is StarterNG (`https://github.com/MaSzyna-EU07/StarterNG`), a separate repository; the older
+`MaSzyna-EU07/Starter` is not the one in use. `launcher/` in this repository is the simulator's built-in scenario and vehicle
+picker (`launcher_mode`), not StarterNG.
+
+- Every existing file must still be read the way it was. Don't rename or drop a keyword, change the meaning or the unit of a value,
+ or make an optional entry required. This holds for every format the game reads: for example `.scn` and its includes, `.fiz`,
+ `.mmd`, `.e3d` / `.t3d`, `.mat`, the `.txt` timetables and track profiles, `eu07.ini` and the Python screens.
+- A bug fix may change what an existing file leads to, such as how a vehicle from its `.fiz` behaves, as long as the PR says so.
+- Something new in a format is optional, and without it the code does exactly what it did before. A file that loaded correctly
+ before doesn't get new warnings or errors in the log. A real fault that is newly detected may be logged.
+- A code change must not need a change in the SVN to work. Where it uses new or changed assets, it falls back to the old behaviour
+ without them, and the PR says what is to be added to the SVN and in what order the two go in.
+- A change that uses new or changed assets (and falls back without them, see above) says so plainly in its commit message: which
+ files, and what is to change in them. It is never left implied. Before such a commit, either make the asset change right away in
+ the user's SVN working copy, or get the user's agreement to leave it for later. Ask the user where their SVN working copy is; the
+ installed game folder is not one. Pushing to git and committing to the SVN both need the user's consent.
+- A scenery saved by the editor without using a new feature holds nothing the current release can't read. The entries of a new
+ feature (such as a new kind of node) appear only where that feature was used, and the PR says that the release doesn't read
+ them.
+- Saving patches the scenery files by byte spans: unchanged definitions stay byte for byte, and an edited node is written anew by
+ its `export_as_text`. A change to saving must not widen what gets rewritten, nor make `export_as_text` drop more of an edited
+ node (comments, unknown tokens) than it did before.
+- A new feature that changes what the simulator does or shows with existing sceneries and vehicles can be turned off in
+ `eu07.ini`, and turned off, the simulator behaves as it did before the feature. Editor tools and new optional entries of a
+ format are covered by the points above. The key is parsed in `utilities/Globals.cpp` (`global_settings::ConfigParse*`) and
+ written by `global_settings::export_as_text`, which puts the settings in the log at start. `eu07.ini` is read from the user's
+ profile (`user_config_path`), and from the game folder only when the profile has none; test the switch in the file that is
+ actually read.
+- A feature doesn't make existing sceneries and vehicles look suddenly different after an update. A change to how things look is
+ something the player turns on, or comes in gradually.
+- When a format really has to change, read both the old and the new form, and say in the PR what changes for the data and for
+ the people who make it.
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 000000000..bbbaa3835
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,5 @@
+# MaSzyna: notes for Claude Code
+
+The instructions for every coding agent in this repository are in `AGENTS.md`. Add or change rules there, not here.
+
+@AGENTS.md
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56cf1bce2..e97e41d03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,12 +72,15 @@ option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON)
option(WITH_PYTHON "Python 3.14 embedded scripting" ON)
option(WITH_UART "Compile with libserialport" ON)
option(WITH_LUA "Compile with lua scripting support" ON)
+option(WITH_WASM "WebAssembly script screens (wasmscreen:, wasmdestinationsign:), run by the WAMR interpreter in ref/wamr" ON)
option(WITH_OPENVR "Compile with OpenVR" OFF)
option(WITH_ZMQ "Compile with cppzmq" OFF)
option(WITH_CRASHPAD "Compile with crashpad" OFF)
option(WITH_DISCORD_RPC "Compile with DISCORD RICH PRESENCE" ON)
option(USE_LTO "Use link-time optimization" OFF)
-option(WITH_BETTER_RENDERER "Experimental multi-backend renderer based on NVRHI" ON)
+option(WITH_TESTS "Build and run the unit tests with the game, a failing test fails the build" ON)
+option(WITH_EDITOR_SELFTESTS "Run the scripts of the editor and launcher self-tests named by the EU07_EDITOR_SELFTEST and EU07_LAUNCHER_SELFTEST variables" OFF)
+option(WITH_BETTER_RENDERER "Experimental multi-backend renderer based on NVRHI" OFF)
option(GENERATE_PDB "Generate executable with program debugging symbols" ON)
option(ENABLE_MCC "Enable multicore compilation" ON)
option(WITHDUMPGEN "Enable generating DMP files on crash" ON)
@@ -95,6 +98,24 @@ set(SOURCES
"model/Texture.cpp"
"utilities/Timer.cpp"
"world/Track.cpp"
+"world/TrackSleepers.cpp"
+"world/SleeperPaths.cpp"
+"world/SleeperFeatures.cpp"
+"world/SleeperLines.cpp"
+"world/SleeperLayout.cpp"
+"world/SleeperModels.cpp"
+"world/SleeperWorker.cpp"
+"world/GaugeLine.cpp"
+"world/RailCrossings.cpp"
+"world/RailMaterials.cpp"
+"world/RailProfile.cpp"
+"world/RailPlan.cpp"
+"world/RailCarve.cpp"
+"world/RailLayer.cpp"
+"world/TrackUneven.cpp"
+"world/Road.cpp"
+"world/Sweep.cpp"
+"world/RoadPoint.cpp"
"world/Traction.cpp"
"world/TractionPower.cpp"
"vehicle/Train.cpp"
@@ -108,21 +129,18 @@ set(SOURCES
"vehicle/DynObj.cpp"
"EU07.cpp"
"export_e3d_standalone.cpp"
+"export_btf_standalone.cpp"
+"nodebank_previews_standalone.cpp"
"world/Event.cpp"
"world/EvLaunch.cpp"
"utilities/Float3d.cpp"
"vehicle/Gauge.cpp"
"utilities/Globals.cpp"
"utilities/Logs.cpp"
-"McZapkie/friction.cpp"
-"McZapkie/hamulce.cpp"
-"McZapkie/Mover.cpp"
-"McZapkie/Oerlikon_ESt.cpp"
"model/MdlMngr.cpp"
"world/MemCell.cpp"
"model/Model3d.cpp"
"world/mtable.cpp"
-"utilities/parser.cpp"
"rendering/nullrenderer.cpp"
"rendering/renderer.cpp"
"model/ResourceManager.cpp"
@@ -150,15 +168,16 @@ set(SOURCES
"scene/scene.cpp"
"scene/scenenode.cpp"
"simulation/simulation.cpp"
+"simulation/blackboxrecorder.cpp"
"model/vertex.cpp"
"audio/audio.cpp"
"audio/audiorenderer.cpp"
"utilities/motiontelemetry.cpp"
-"utilities/utilities.cpp"
"application/uitranscripts.cpp"
"world/station.cpp"
"application/application.cpp"
"simulation/simulationtime.cpp"
+"simulation/simulationtest.cpp"
"scene/sceneeditor.cpp"
"rendering/screenshot.cpp"
"input/driverkeyboardinput.cpp"
@@ -167,15 +186,99 @@ set(SOURCES
"application/driveruipanels.cpp"
"input/editorkeyboardinput.cpp"
"editor/editorSettings.cpp"
+"editor/editorModelSets.cpp"
+"editor/editorTrackPresets.cpp"
+"editor/editorIncludeInfo.cpp"
"editor/editorTerrain.cpp"
+"editor/editorTrack.cpp"
+"editor/editorTrackTrace.cpp"
+"editor/editorFouling.cpp"
+"editor/editorRoad.cpp"
+"editor/editorAlignment.cpp"
+"editor/editorTrackShape.cpp"
+"editor/editorGroundFollow.cpp"
+"editor/editorAlignmentStore.cpp"
+"editor/editorSwitchStore.cpp"
+"editor/editorSwitchCurve.cpp"
+"editor/editorKilometrage.cpp"
+"editor/editorStation.cpp"
+"editor/editorSwitchDesign.cpp"
+"editor/editorConnections.cpp"
+"application/editormodeconnection.cpp"
+"application/editormodeconnectioncurve.cpp"
+"application/editormodedigitize.cpp"
+"editor/editorSpeed.cpp"
+"editor/editorProfile.cpp"
+"editor/editorGauge.cpp"
+"editor/editorInfra.cpp"
"editor/editorTerrainStreamer.cpp"
+"editor/editorOrthophoto.cpp"
+"editor/editorHttp.cpp"
+"editor/editorNmt.cpp"
+"editor/editorGeoMap.cpp"
+"editor/editorPreviews.cpp"
+"editor/editorIcons.cpp"
+"editor/editorClips.cpp"
"application/editormode.cpp"
+"application/editormodetrack.cpp"
+"application/editormoderoute.cpp"
+"application/editormodestraights.cpp"
+"application/editormodelay.cpp"
+"application/editormodeswitchplace.cpp"
+"application/editormodetrackgizmo.cpp"
+"application/editormoderecords.cpp"
+"application/editormodeswitchdrive.cpp"
+"application/editormodeswitchtool.cpp"
+"application/editormodeswitchtemplate.cpp"
+"application/editormodenmt.cpp"
+"application/editormodegradeline.cpp"
+"application/editormodeswitchslide.cpp"
+"application/editormodeswitchdesign.cpp"
+"application/editormodetrackbed.cpp"
+"application/editormodetrackux.cpp"
+"application/editormodetrackprops.cpp"
+"application/editormoderoad.cpp"
+"application/editormodeprofile.cpp"
+"application/editormodetextures.cpp"
+"application/editormodegauge.cpp"
+"application/editormoderide.cpp"
+"application/editormodeminimap.cpp"
+"application/editormodeinfra.cpp"
+"application/editormodespeed.cpp"
+"application/editormodesrk.cpp"
+"application/editormodekm.cpp"
+"application/editormodejoints.cpp"
+"application/editormodeparallel.cpp"
+"application/editormodelineside.cpp"
+"application/editormodevehicle.cpp"
+"application/editormodeselection.cpp"
+"application/editormodeviewport.cpp"
+"application/editormodesignal.cpp"
+"application/editormodesweep.cpp"
+"application/editormodeturntable.cpp"
+"application/editormodeselftest.cpp"
+"application/editormodeselftestscene.cpp"
+"application/editormodeselftestsleepers.cpp"
+"application/editormodeselftestsweep.cpp"
+"application/editormodeselftesttrack.cpp"
+"application/editormodeselftestswitch.cpp"
+"application/editormodeselftestjoin.cpp"
+"application/editormodeselftestsignal.cpp"
+"application/editormodeselftestterrain.cpp"
+"application/editormodeselftestrails.cpp"
+"application/editormodeselftestmonkey.cpp"
+"application/scriptedinput.cpp"
"input/editormouseinput.cpp"
"application/editoruilayer.cpp"
"application/editoruipanels.cpp"
"application/scenarioloadermode.cpp"
"application/scenarioloaderuilayer.cpp"
"scene/scenenodegroups.cpp"
+"scene/scenelayers.cpp"
+"scene/scenelayerssave.cpp"
+"scene/sceneterrain.cpp"
+"scene/heightmapterrain.cpp"
+"scene/scenemodelentries.cpp"
"simulation/simulationenvironment.cpp"
"simulation/simulationstateserializer.cpp"
"rendering/precipitation.cpp"
@@ -183,7 +286,6 @@ set(SOURCES
"utilities/dictionary.cpp"
"rendering/particles.cpp"
"utilities/headtrack.cpp"
-"scripting/ladderlogic.cpp"
"rendering/geometrybank.cpp"
"rendering/openglcolor.cpp"
"simulation/simulationsounds.cpp"
@@ -205,6 +307,7 @@ set(SOURCES
"${DEPS_DIR}/glad/src/glad.c"
"${DEPS_DIR}/dds-ktx/src/dds-ktx.c"
+"${DEPS_DIR}/zstd/zstd.c"
"gl/shader.cpp"
"gl/vao.cpp"
@@ -223,6 +326,7 @@ set(SOURCES
"imgui/imgui_demo.cpp"
"imgui/imgui_draw.cpp"
"imgui/imgui_widgets.cpp"
+"imgui/imgui_tables.cpp"
"imgui/imgui_impl_glfw.cpp"
"imgui/ImGuizmo.cpp"
@@ -235,6 +339,7 @@ set(SOURCES
"launcher/keymapper.cpp"
"launcher/textures_scanner.cpp"
"launcher/scenery_scanner.cpp"
+"launcher/scenery_wizard.cpp"
"vr/vr_interface.cpp"
)
@@ -282,6 +387,16 @@ if (WITH_LUA)
set(SOURCES ${SOURCES} "scripting/lua.cpp")
endif()
+# the script screens (scripting/scriptscreens.cpp), with the Lua and the WebAssembly runtime when they're built
+set(SOURCES ${SOURCES} "scripting/scriptscreens.cpp")
+if (WITH_LUA)
+ set(SOURCES ${SOURCES} "scripting/luaprogram.cpp")
+endif()
+if (WITH_WASM)
+ set(DEFINITIONS ${DEFINITIONS} "WITH_WASM")
+ set(SOURCES ${SOURCES} "scripting/wasmprogram.cpp")
+endif()
+
if (WITHDUMPGEN)
set(DEFINITIONS ${DEFINITIONS} "WITHDUMPGEN")
endif()
@@ -293,6 +408,8 @@ if (WITH_OPENGL_MODERN)
"rendering/opengl33skydome.cpp"
"rendering/opengl33precipitation.cpp"
"rendering/opengl33particles.cpp"
+ "rendering/opengl33terrain.cpp"
+ "rendering/opengl33screenpost.cpp"
"rendering/opengl33renderer.cpp")
set(DEFINITIONS ${DEFINITIONS} "WITH_OPENGL_MODERN")
endif()
@@ -343,6 +460,14 @@ endif()
configure_file("${CMAKE_SOURCE_DIR}/version_info.h.in" "${CMAKE_BINARY_DIR}/geninc/version_info.h")
+# the icons of the editor are built into the executable: the png is written out as the bytes of an array, see editor/editorIcons.cpp
+set(EDITOR_ICONS "${CMAKE_SOURCE_DIR}/editor/icons/editor_icons.png")
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${EDITOR_ICONS}")
+file(READ "${EDITOR_ICONS}" EDITOR_ICONS_HEX HEX)
+string(REGEX REPLACE "(................................)" "\\1\n" EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}")
+string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}")
+file(CONFIGURE OUTPUT "${CMAKE_BINARY_DIR}/geninc/editor_icons_png.inc" CONTENT "${EDITOR_ICONS_HEX}\n")
+
set (PREFIX "")
set (SUFFIX "")
@@ -401,17 +526,53 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_compile_options("/utf-8")
endif()
+# the build settings of the game: include dirs, definitions, compile options and libraries. the game,
+# its core library and the unit tests all build with the same ones
+add_library(eu07_settings INTERFACE)
+
+# the parts of the simulation the game shares with the unit tests: the vehicle physics, the vehicle
+# definition parser, the helpers they use and the rules of the test mode. built once, and tested as the game uses them
+set(CORE_SOURCES
+"McZapkie/friction.cpp"
+"McZapkie/hamulce.cpp"
+"McZapkie/Mover.cpp"
+"McZapkie/couplerphysics.cpp"
+"McZapkie/Oerlikon_ESt.cpp"
+"utilities/parser.cpp"
+"utilities/utilities.cpp"
+"scripting/ladderlogic.cpp"
+"scripting/scriptscreenrules.cpp"
+"scripting/scriptscreenkernels.cpp"
+"scripting/scriptscreendrawing.cpp"
+"simulation/simulationtestrules.cpp"
+"vehicle/blackbox.cpp"
+"vehicle/enginestart.cpp"
+"vehicle/brakesetting.cpp"
+"vehicle/handover.cpp"
+"vehicle/horn.cpp"
+"vehicle/linebreaker.cpp"
+"vehicle/smoke.cpp"
+"vehicle/odometer.cpp"
+)
+add_library(eu07_core STATIC ${CORE_SOURCES})
+target_link_libraries(eu07_core PUBLIC eu07_settings)
+set_target_properties(eu07_core PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ FOLDER "libraries")
+
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
+target_link_libraries(${PROJECT_NAME} eu07_core)
-target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINITIONS})
+target_compile_definitions(eu07_settings INTERFACE ${DEFINITIONS})
-target_include_directories(${PROJECT_NAME} PRIVATE
+target_include_directories(eu07_settings INTERFACE
"."
"Console"
"McZapkie"
"gl"
"${DEPS_DIR}/glad/include"
"${DEPS_DIR}/dds-ktx/include"
+ "${DEPS_DIR}/zstd"
"${CMAKE_BINARY_DIR}/geninc"
"${GLOBAL_INCLUDE_DIR}")
@@ -425,7 +586,7 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
# /wd4996: disable "deprecation" warnings
# /wd4244: disable warnings for conversion with possible loss of data
# /wd5033: disable because it is all over Python headers
- set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4996 /wd4244 /wd5033")
+ target_compile_options(eu07_settings INTERFACE /wd4996 /wd4244 /wd5033)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/LARGEADDRESSAWARE")
endif()
@@ -441,7 +602,7 @@ set_target_properties( ${PROJECT_NAME}
check_cxx_symbol_exists(__GNUC__ "" COMPILER_HAVE_GNUC)
if (COMPILER_HAVE_GNUC)
- set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
+ target_compile_options(eu07_settings INTERFACE -fvisibility=hidden)
endif()
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
@@ -449,19 +610,20 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
if (USE_PCH)
target_precompile_headers(${PROJECT_NAME} PRIVATE "$<$:${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h>")
- set_source_files_properties("/glad/src/glad.c" "ref/dds-ktx/src/dds-ktx.c" "stb/stb_image.c"
- "imgui/imgui.cpp" "imgui/imgui_demo.cpp" "imgui/imgui_draw.cpp" "imgui/imgui_widgets.cpp" "imgui/imgui_impl_glfw.cpp" "imgui/ImGuizmo.cpp"
+ target_precompile_headers(eu07_core PRIVATE "$<$:${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h>")
+ set_source_files_properties("/glad/src/glad.c" "ref/dds-ktx/src/dds-ktx.c" "ref/zstd/zstd.c" "stb/stb_image.c"
+ "imgui/imgui.cpp" "imgui/imgui_demo.cpp" "imgui/imgui_draw.cpp" "imgui/imgui_widgets.cpp" "imgui/imgui_tables.cpp" "imgui/imgui_impl_glfw.cpp" "imgui/ImGuizmo.cpp"
PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
endif()
endif()
if (USE_LTO)
- set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+ set_property(TARGET ${PROJECT_NAME} eu07_core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if (WITH_OPENVR)
- target_include_directories(${PROJECT_NAME} PRIVATE ${OPENVR_INCLUDE_DIR})
- target_link_libraries(${PROJECT_NAME} ${OPENVR_LIBRARY})
+ target_include_directories(eu07_settings INTERFACE ${OPENVR_INCLUDE_DIR})
+ target_link_libraries(eu07_settings INTERFACE ${OPENVR_LIBRARY})
endif()
if (WITH_CRASHPAD)
@@ -476,12 +638,12 @@ if (WITH_CRASHPAD)
endif()
endif()
-target_link_libraries(${PROJECT_NAME} glfw)
+target_link_libraries(eu07_settings INTERFACE glfw)
if(WITH_PYTHON)
find_package(Python3 3.14 REQUIRED COMPONENTS Development)
- target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
- target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES})
+ target_include_directories(eu07_settings INTERFACE ${Python3_INCLUDE_DIRS})
+ target_link_libraries(eu07_settings INTERFACE ${Python3_LIBRARIES})
if(WIN32)
# Python3_ROOT_DIR is only an input hint and is not populated by
@@ -499,74 +661,94 @@ endif()
if (NOT WIN32)
find_package(PNG 1.6 REQUIRED)
- target_link_libraries(${PROJECT_NAME} PNG::PNG)
+ target_link_libraries(eu07_settings INTERFACE PNG::PNG)
else()
include_directories(${PNG_INCLUDE_DIRS})
- target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
+ target_link_libraries(eu07_settings INTERFACE ${PNG_LIBRARIES})
endif()
find_package(Threads REQUIRED)
-target_link_libraries(${PROJECT_NAME} Threads::Threads)
+target_link_libraries(eu07_settings INTERFACE Threads::Threads)
find_package(GLM REQUIRED)
-target_include_directories(${PROJECT_NAME} PRIVATE ${GLM_INCLUDE_DIR})
+target_include_directories(eu07_settings INTERFACE ${GLM_INCLUDE_DIR})
# JSON lib
add_subdirectory(ref/json)
-target_link_libraries(${PROJECT_NAME} nlohmann_json::nlohmann_json)
-target_include_directories(${PROJECT_NAME} PRIVATE ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR})
+target_link_libraries(eu07_settings INTERFACE nlohmann_json::nlohmann_json)
+target_include_directories(eu07_settings INTERFACE ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR})
if (WITH_DISCORD_RPC)
add_subdirectory(ref/discord-rpc)
set_target_properties(discord-rpc PROPERTIES FOLDER "libraries")
- target_link_libraries(${PROJECT_NAME} discord-rpc)
+ target_link_libraries(eu07_settings INTERFACE discord-rpc)
# Add the include directory so the compiler can find discord_rpc.h
- target_include_directories(${PROJECT_NAME} PUBLIC
+ target_include_directories(eu07_settings INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/ref/discord-rpc/include"
)
- target_compile_definitions(${PROJECT_NAME} PUBLIC WITH_DISCORD_RPC=1)
+ target_compile_definitions(eu07_settings INTERFACE WITH_DISCORD_RPC=1)
else()
- target_compile_definitions(${PROJECT_NAME} PUBLIC WITH_DISCORD_RPC=0)
+ target_compile_definitions(eu07_settings INTERFACE WITH_DISCORD_RPC=0)
+endif()
+
+if(WITH_EDITOR_SELFTESTS)
+ target_compile_definitions(eu07_settings INTERFACE WITH_EDITOR_SELFTESTS=1)
+else()
+ target_compile_definitions(eu07_settings INTERFACE WITH_EDITOR_SELFTESTS=0)
endif()
find_package(OpenAL REQUIRED)
if (TARGET OpenAL::OpenAL)
- target_link_libraries(${PROJECT_NAME} OpenAL::OpenAL)
+ target_link_libraries(eu07_settings INTERFACE OpenAL::OpenAL)
else()
- target_include_directories(${PROJECT_NAME} PRIVATE ${OPENAL_INCLUDE_DIR})
- target_link_libraries(${PROJECT_NAME} ${OPENAL_LIBRARY})
+ target_include_directories(eu07_settings INTERFACE ${OPENAL_INCLUDE_DIR})
+ target_link_libraries(eu07_settings INTERFACE ${OPENAL_LIBRARY})
endif()
find_package(SndFile REQUIRED)
-target_link_libraries(${PROJECT_NAME} SndFile::sndfile)
+target_link_libraries(eu07_settings INTERFACE SndFile::sndfile)
if (WITH_LUA)
find_package(LuaJIT REQUIRED)
- target_include_directories(${PROJECT_NAME} PRIVATE ${LUAJIT_INCLUDE_DIR})
- target_link_libraries(${PROJECT_NAME} ${LUAJIT_LIBRARIES})
+ target_include_directories(eu07_settings INTERFACE ${LUAJIT_INCLUDE_DIR})
+ target_link_libraries(eu07_settings INTERFACE ${LUAJIT_LIBRARIES})
endif()
if (WITH_UART)
find_package(libserialport REQUIRED)
- target_include_directories(${PROJECT_NAME} PRIVATE ${libserialport_INCLUDE_DIR})
- target_link_libraries(${PROJECT_NAME} ${libserialport_LIBRARY})
+ target_include_directories(eu07_settings INTERFACE ${libserialport_INCLUDE_DIR})
+ target_link_libraries(eu07_settings INTERFACE ${libserialport_LIBRARY})
endif()
find_package(ASIO REQUIRED)
-target_link_libraries(${PROJECT_NAME} asio::asio)
+target_link_libraries(eu07_settings INTERFACE asio::asio)
if (WIN32)
- target_link_libraries(${PROJECT_NAME} ws2_32)
+ target_link_libraries(eu07_settings INTERFACE ws2_32)
+endif()
+
+# http client of the editor, for the orthophoto, the terrain model and the topo map of geoportal.gov.pl: WinHTTP on Windows,
+# libcurl elsewhere when available
+if (WIN32)
+ target_link_libraries(eu07_settings INTERFACE winhttp)
+else()
+ find_package(CURL QUIET)
+ if (CURL_FOUND)
+ target_link_libraries(eu07_settings INTERFACE CURL::libcurl)
+ target_compile_definitions(eu07_settings INTERFACE EU07_WITH_CURL)
+ else()
+ message(STATUS "libcurl not found: the editor's orthophoto and terrain model will only show what's cached, its topo map nothing")
+ endif()
endif()
if (WITH_ZMQ)
find_package(cppzmq REQUIRED)
- target_include_directories(${PROJECT_NAME} PRIVATE ${cppzmq_INCLUDE_DIR})
- target_link_libraries(${PROJECT_NAME} ${cppzmq_LIBRARY})
+ target_include_directories(eu07_settings INTERFACE ${cppzmq_INCLUDE_DIR})
+ target_link_libraries(eu07_settings INTERFACE ${cppzmq_LIBRARY})
endif()
if (WIN32)
@@ -576,15 +758,71 @@ if (WIN32)
)
endif ()
-if(WIN32 AND WITH_PYTHON)
- add_custom_command(
- TARGET ${PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_DLL}" "$"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_ZLIB}" "$"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${EU07_PY_LIBDIR}" "$/python64/Lib"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${EU07_PY_DLLSDIR}" "$/python64/DLLs"
- )
+# Linux: the game loads its shared libraries from its own folder first ($ORIGIN), and the build copies them there,
+# so the folder runs on a system that doesn't have them, or has other versions. the RPATH is a DT_RPATH rather
+# than a DT_RUNPATH, because only that one is also used for the libraries the copied ones load (libsndfile's codecs)
+if (UNIX AND NOT APPLE)
+ option(BUNDLE_RUNTIME_LIBS "Linux: copy the shared libraries the game needs next to it and load them from there" ON)
endif()
+if (UNIX AND NOT APPLE AND BUNDLE_RUNTIME_LIBS)
+ set_target_properties(${PROJECT_NAME} PROPERTIES
+ BUILD_WITH_INSTALL_RPATH TRUE
+ INSTALL_RPATH "$ORIGIN")
+ target_link_options(${PROJECT_NAME} PRIVATE "LINKER:--disable-new-dtags")
+
+ # the RPATH no longer leads to libraries outside the system folders (Python from setup-python, an OpenAL Soft
+ # in /usr/local), so their folders are given to the script as well
+ set(EU07_BUNDLE_SEARCH_DIRS "")
+ foreach(library IN LISTS Python3_LIBRARIES OPENAL_LIBRARY LUAJIT_LIBRARIES libserialport_LIBRARY)
+ if (IS_ABSOLUTE "${library}")
+ get_filename_component(library_dir "${library}" DIRECTORY)
+ list(APPEND EU07_BUNDLE_SEARCH_DIRS "${library_dir}")
+ endif()
+ endforeach()
+ list(APPEND EU07_BUNDLE_SEARCH_DIRS ${Python3_LIBRARY_DIRS})
+ list(REMOVE_DUPLICATES EU07_BUNDLE_SEARCH_DIRS)
+ string(REPLACE ";" "|" EU07_BUNDLE_SEARCH_DIRS "${EU07_BUNDLE_SEARCH_DIRS}")
+
+ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ -DGAME=$
+ -DSEARCH_DIRS=${EU07_BUNDLE_SEARCH_DIRS}
+ -DCMAKE_OBJDUMP=${CMAKE_OBJDUMP}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/CMake_modules/bundle_runtime_libs.cmake"
+ COMMENT "Copying the shared libraries next to the game"
+ VERBATIM)
+endif()
+
+if(WIN32 AND WITH_PYTHON)
+ # the Python runtime next to the game, copied when it isn't there yet or the Python install changed, rather
+ # than after every link of the game: the library alone is thousands of files. the folder is the game's
+ # RUNTIME_OUTPUT_DIRECTORY, spelled out: $ here would make this target depend on the game
+ get_property(EU07_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if (EU07_MULTI_CONFIG)
+ set(EU07_PY_TARGET_DIR "${CMAKE_BINARY_DIR}/bin/$")
+ else()
+ set(EU07_PY_TARGET_DIR "${CMAKE_BINARY_DIR}/bin")
+ endif()
+ set(EU07_PY_STAMP "${EU07_PY_TARGET_DIR}/python64/python_runtime.stamp")
+ add_custom_command(
+ OUTPUT "${EU07_PY_STAMP}"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_DLL}" "${EU07_PY_TARGET_DIR}"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_ZLIB}" "${EU07_PY_TARGET_DIR}"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${EU07_PY_LIBDIR}" "${EU07_PY_TARGET_DIR}/python64/Lib"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${EU07_PY_DLLSDIR}" "${EU07_PY_TARGET_DIR}/python64/DLLs"
+ COMMAND ${CMAKE_COMMAND} -E touch "${EU07_PY_STAMP}"
+ DEPENDS "${EU07_PY_DLL}" "${EU07_PY_ZLIB}"
+ COMMENT "Copying the Python runtime next to the game"
+ VERBATIM)
+ add_custom_target(eu07_python_runtime DEPENDS "${EU07_PY_STAMP}")
+ set_target_properties(eu07_python_runtime PROPERTIES FOLDER "libraries")
+ add_dependencies(${PROJECT_NAME} eu07_python_runtime)
+endif()
+
+if (WITH_WASM)
+ add_subdirectory("CMake_modules/wamr" "${CMAKE_CURRENT_BINARY_DIR}/wamr")
+ target_link_libraries(${PROJECT_NAME} eu07_wamr)
+endif ()
if (WITH_BETTER_RENDERER)
add_subdirectory("betterRenderer")
@@ -592,6 +830,13 @@ if (WITH_BETTER_RENDERER)
target_link_libraries(${PROJECT_NAME} "betterRenderer")
endif ()
+# yaml-cpp, for the descriptions of scenery templates edited in the scenery editor.
+# the experimental renderer brings in the same copy on its own, when enabled
+if (NOT TARGET yaml-cpp)
+ add_subdirectory("betterRenderer/thirdparty/yaml-cpp" "${CMAKE_CURRENT_BINARY_DIR}/yaml-cpp" EXCLUDE_FROM_ALL)
+endif ()
+target_link_libraries(eu07_settings INTERFACE yaml-cpp)
+
# Enable compiling with debug symbols
if(GENERATE_PDB)
@@ -605,7 +850,7 @@ if(GENERATE_PDB)
add_link_options(/DEBUG /MAP)
# Ensure that the PCH is built with the correct runtime library for each configuration
- set_target_properties(${PROJECT_NAME} PROPERTIES
+ set_target_properties(${PROJECT_NAME} eu07_core PROPERTIES
COMPILE_OPTIONS "$<$:/MDd>$<$:/MD>")
else()
# GCC/Clang (ensure -g is set for all configurations)
@@ -621,8 +866,27 @@ endif()
if(ENABLE_AVX2)
message(STATUS "Enabling AVX2 instruction set.")
if (MSVC)
- target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2)
+ target_compile_options(eu07_settings INTERFACE /arch:AVX2)
else()
- target_compile_options(${PROJECT_NAME} PRIVATE -mavx2)
+ target_compile_options(eu07_settings INTERFACE -mavx2)
endif()
-endif()
\ No newline at end of file
+endif()
+
+if(WITH_TESTS)
+ enable_testing()
+ add_subdirectory(tests/unit)
+ # the unit tests run at the end of building the game, once it's linked: a failing one fails the build
+ # (and removes the game binary, so the next build links it again and reruns them)
+ add_dependencies(${PROJECT_NAME} eu07_unit_tests)
+ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ -DTESTS=$
+ -DGAME=$
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/run_tests.cmake"
+ COMMENT "Running the unit tests"
+ VERBATIM)
+ # a change of the tests alone links the game again, so they run (Ninja and Makefile generators;
+ # Visual Studio builds rerun them with the next change of the game)
+ set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_DEPENDS
+ $ ${UNIT_TEST_DATA} "${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/run_tests.cmake")
+endif()
diff --git a/CMake_modules/bundle_runtime_libs.cmake b/CMake_modules/bundle_runtime_libs.cmake
new file mode 100644
index 000000000..a0f71543e
--- /dev/null
+++ b/CMake_modules/bundle_runtime_libs.cmake
@@ -0,0 +1,75 @@
+# copies the shared libraries the game needs next to it, where its RPATH ($ORIGIN) finds them first. Linux only:
+# cmake -DGAME= -DSEARCH_DIRS= [-DCMAKE_OBJDUMP=] -P bundle_runtime_libs.cmake
+#
+# the libraries of the system itself stay out: the C library and the loader, the GPU driver stack (libGL and its
+# kin come with the driver), X11 / Wayland, the sound servers, libstdc++ (the GPU drivers bring their own need of a
+# newer one) and a few more every distribution has. what a library left out depends on isn't bundled either
+
+get_filename_component(game_folder "${GAME}" DIRECTORY)
+set(manifest "${game_folder}/bundled_libs.txt")
+
+# the libraries copied by the previous build go first: the game's RPATH would find them in its folder, and then
+# a library updated in the system would never be copied again
+if(EXISTS "${manifest}")
+ file(STRINGS "${manifest}" previous)
+ foreach(name IN LISTS previous)
+ if(NOT name STREQUAL "")
+ file(REMOVE "${game_folder}/${name}")
+ endif()
+ endforeach()
+ file(REMOVE "${manifest}")
+endif()
+
+string(REPLACE "|" ";" search_dirs "${SEARCH_DIRS}")
+if(DEFINED ENV{LD_LIBRARY_PATH})
+ string(REPLACE ":" ";" ld_library_path "$ENV{LD_LIBRARY_PATH}")
+ list(APPEND search_dirs ${ld_library_path})
+endif()
+list(REMOVE_ITEM search_dirs "")
+list(REMOVE_DUPLICATES search_dirs)
+
+set(system_libraries
+ "^ld-linux"
+ "^linux-vdso"
+ "^lib(c|m|dl|rt|pthread|resolv|util|mvec|anl|nsl|crypt|BrokenLocale|thread_db)\\.so"
+ "^libstdc\\+\\+\\.so"
+ "^libgcc_s\\.so"
+ "^lib(GL|GLX|EGL|OpenGL|GLdispatch|GLESv1_CM|GLESv2|GLU|gbm|drm|vulkan)\\.so"
+ "^libX[A-Za-z0-9_-]*\\.so"
+ "^libxcb"
+ "^libxkbcommon"
+ "^libwayland-"
+ "^libdecor"
+ "^lib(asound|pulse|pulse-simple|jack|pipewire-[0-9.]+)\\.so"
+ "^lib(udev|systemd|dbus-1)\\.so"
+ "^libz\\.so"
+ "^lib(fontconfig|freetype|harfbuzz|expat|uuid)\\.so")
+
+file(GET_RUNTIME_DEPENDENCIES
+ EXECUTABLES "${GAME}"
+ RESOLVED_DEPENDENCIES_VAR resolved
+ UNRESOLVED_DEPENDENCIES_VAR unresolved
+ DIRECTORIES ${search_dirs}
+ PRE_EXCLUDE_REGEXES ${system_libraries})
+
+if(unresolved)
+ list(JOIN unresolved ", " unresolved_text)
+ message(WARNING "Bundled libraries: not found, so not copied next to the game: ${unresolved_text}")
+endif()
+
+# each library is copied under the name the game asks for (libpng16.so.16), as a file rather than the chain of
+# symlinks it is in the system: the build artifacts don't keep symlinks
+set(names "")
+foreach(library IN LISTS resolved)
+ get_filename_component(name "${library}" NAME)
+ file(REAL_PATH "${library}" source)
+ file(COPY_FILE "${source}" "${game_folder}/${name}")
+ list(APPEND names "${name}")
+endforeach()
+
+list(SORT names)
+list(JOIN names "\n" manifest_text)
+file(WRITE "${manifest}" "${manifest_text}\n")
+list(LENGTH names count)
+list(JOIN names " " names_text)
+message("Bundled libraries (${count}): ${names_text}")
diff --git a/CMake_modules/wamr/CMakeLists.txt b/CMake_modules/wamr/CMakeLists.txt
new file mode 100644
index 000000000..d12d48cd4
--- /dev/null
+++ b/CMake_modules/wamr/CMakeLists.txt
@@ -0,0 +1,67 @@
+# The WebAssembly Micro Runtime (ref/wamr) for the WebAssembly script screens (scripting/wasmprogram.cpp).
+#
+# Built here, in a directory of its own, because the WAMR build scripts set their configuration with
+# add_definitions() and include_directories(): kept in this directory, none of it reaches the game's sources.
+# Only the interpreter is built (see WAMR_BUILD_FAST_INTERP), with instruction metering so that a screen stuck in a loop
+# can't hang the worker thread, and without the signal-based bounds checks, which would compete with the
+# game's own crash handling.
+
+if (WIN32)
+ set(WAMR_BUILD_PLATFORM "windows")
+elseif (APPLE)
+ set(WAMR_BUILD_PLATFORM "darwin")
+else ()
+ set(WAMR_BUILD_PLATFORM "linux")
+endif ()
+
+set(WAMR_ROOT_DIR "${CMAKE_SOURCE_DIR}/ref/wamr")
+
+set(WAMR_BUILD_INTERP 1)
+# the fast interpreter counts the instructions only where it dispatches with computed gotos (GCC, Clang): built with
+# MSVC it would let a screen stuck in a loop hang the worker. the classic interpreter counts them everywhere
+if (MSVC)
+ set(WAMR_BUILD_FAST_INTERP 0)
+else ()
+ set(WAMR_BUILD_FAST_INTERP 1)
+endif ()
+set(WAMR_BUILD_AOT 0)
+set(WAMR_BUILD_JIT 0)
+set(WAMR_BUILD_FAST_JIT 0)
+set(WAMR_BUILD_LIBC_BUILTIN 0)
+set(WAMR_BUILD_LIBC_WASI 0)
+set(WAMR_BUILD_MULTI_MODULE 0)
+set(WAMR_BUILD_LIB_PTHREAD 0)
+set(WAMR_BUILD_LIB_WASI_THREADS 0)
+set(WAMR_BUILD_THREAD_MGR 0)
+set(WAMR_BUILD_SIMD 0)
+set(WAMR_BUILD_BULK_MEMORY 1)
+set(WAMR_BUILD_REF_TYPES 1)
+set(WAMR_BUILD_MINI_LOADER 0)
+set(WAMR_BUILD_INSTRUCTION_METERING 1)
+# NOTE: the calls into the natives use WAMR's assembler invokeNative (MASM with MSVC). its C version
+# (WAMR_BUILD_INVOKE_NATIVE_GENERAL) crashes on Windows x64 as soon as a module runs
+set(WAMR_DISABLE_HW_BOUND_CHECK 1)
+set(WAMR_DISABLE_STACK_HW_BOUND_CHECK 1)
+
+find_package(Threads REQUIRED)
+include("${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake")
+
+add_library(eu07_wamr STATIC ${WAMR_RUNTIME_LIB_SOURCE})
+target_include_directories(eu07_wamr INTERFACE "${WAMR_ROOT_DIR}/core/iwasm/include")
+# with MSVC the WAMR headers declare the API dllimport unless told otherwise; the library is linked statically
+target_compile_definitions(eu07_wamr INTERFACE "WASM_RUNTIME_API_EXTERN=")
+target_link_libraries(eu07_wamr PRIVATE Threads::Threads)
+if (WIN32)
+ target_link_libraries(eu07_wamr PRIVATE ws2_32 ntdll)
+else ()
+ target_link_libraries(eu07_wamr PRIVATE m ${CMAKE_DL_LIBS})
+endif ()
+if (MSVC)
+ # third-party code: its warnings are not ours to fix
+ target_compile_options(eu07_wamr PRIVATE /W0)
+else ()
+ target_compile_options(eu07_wamr PRIVATE -w)
+endif ()
+set_target_properties(eu07_wamr PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ FOLDER "libraries")
diff --git a/Console.h b/Console.h
index e99beb4b9..1f7f9e2b1 100644
--- a/Console.h
+++ b/Console.h
@@ -20,7 +20,8 @@ class TLPT;
class TKeyTrans
{ // przekodowanie kodu naciśnięcia i zwolnienia klawisza
public:
- short int iDown, iUp;
+ short int iDown;
+ short int iUp;
};
class Console
diff --git a/EU07.cpp b/EU07.cpp
index e1be85847..20f24aa5a 100644
--- a/EU07.cpp
+++ b/EU07.cpp
@@ -19,8 +19,14 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
#include "stdafx.h"
#include "application/application.h"
+#include "simulation/simulationtest.h"
+#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include
+#include
+#include
+#include
+#include
#ifdef WITHDUMPGEN
#ifdef _WIN32
#include
@@ -33,6 +39,8 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
#endif
void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic);
+int export_btf_standalone(std::string in, std::string out);
+int generate_nodebank_previews(int Argc, char *Argv[]);
#include
#include
@@ -68,7 +76,9 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo)
MINIDUMP_TYPE dumpType = MINIDUMP_TYPE(MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules | MiniDumpWithIndirectlyReferencedMemory |
MiniDumpWithFullMemoryInfo | MiniDumpWithTokenInformation);
- MessageBoxA(nullptr, "Simulator crash occured :(\n", "Simulator crashed :(", MB_ICONERROR);
+ // in test mode nobody is there to close the box, and the run would wait for it until killed
+ if (false == Global.test.enabled)
+ MessageBoxA(nullptr, "Simulator crash occured :(\n", "Simulator crashed :(", MB_ICONERROR);
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, dumpType, &dumpInfo, nullptr, nullptr);
CloseHandle(hFile);
@@ -79,6 +89,55 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo)
#endif
+namespace
+{
+
+// the log is written by a thread of its own, which the closing of the application stops and waits for. on the ways
+// out that skip the closing (a failed start, an exception) what was logged last would be lost with the process
+void finish_log()
+{
+ StopLogService();
+ if (auto const logservice{Global.threads.find("LogService")};
+ logservice != Global.threads.end() && logservice->second.joinable() && logservice->second.get_id() != std::this_thread::get_id())
+ logservice->second.join();
+}
+
+// ends a test run with its verdict on the standard output and in the exit code. a test the simulator didn't end
+// (a failed start, an exception) ends with the error and Reason
+[[noreturn]] void end_test_run(std::string_view const Reason)
+{
+ simulation::test().conclude(simulation::test_result::error, Reason);
+ finish_log();
+ fflush(stdout);
+ fflush(stderr);
+ // skip destructors, there are ordering errors which causes segfaults
+ std::_Exit(simulation::test().exit_code());
+}
+
+// a test run (--test): whatever stops it, it ends with its verdict. any other run never gets here and ends as
+// it always has
+[[noreturn]] void run_test(int argc, char *argv[])
+{
+ // for what doesn't reach the catch below: an exception leaving a noexcept function, or on Linux one leaving
+ // a thread (on Windows the handler is the main thread's only)
+ std::set_terminate([] { end_test_run(simulation::describe_exception(std::current_exception())); });
+ try
+ {
+ if (Application.init(argc, argv) == 0)
+ {
+ Application.run();
+ Application.exit();
+ }
+ }
+ catch (...)
+ {
+ end_test_run(simulation::describe_exception(std::current_exception()));
+ }
+ end_test_run("the simulator stopped before the test ended");
+}
+
+} // namespace
+
int main(int argc, char *argv[])
{
#ifdef WITHDUMPGEN
@@ -98,6 +157,41 @@ int main(int argc, char *argv[])
int dynamic = std::stoi(std::string(argv[5]));
export_e3d_standalone(in, out, flags, dynamic);
}
+ // standalone generation of preview images of the node bank models: -generate-nodebank-previews [options]
+ else if (argc >= 2 && std::string(argv[1]) == "-generate-nodebank-previews")
+ {
+ auto const result{generate_nodebank_previews(argc, argv)};
+ fflush(stdout);
+ fflush(stderr);
+ std::_Exit(result);
+ }
+ // standalone conversion of text terrain file to binary format: -btf -s [-o ]
+ else if (argc >= 4 && std::string(argv[1]) == "-btf")
+ {
+ std::string in;
+ std::string out;
+ for (int i = 2; i + 1 < argc; i += 2)
+ {
+ std::string const option(argv[i]);
+ if (option == "-s")
+ {
+ in = argv[i + 1];
+ }
+ else if (option == "-o")
+ {
+ out = argv[i + 1];
+ }
+ }
+ auto const result{export_btf_standalone(in, out)};
+ fflush(stdout);
+ fflush(stderr);
+ std::_Exit(result);
+ }
+ // unattended test run of a scenery, which says its result in the exit code (eu07/maszyna#541)
+ else if (simulation::parse_test_command_line(std::vector(argv, argv + argc)).enabled)
+ {
+ run_test(argc, argv);
+ }
else
{
try
diff --git a/GEMINI.md b/GEMINI.md
new file mode 100644
index 000000000..bf28f3062
--- /dev/null
+++ b/GEMINI.md
@@ -0,0 +1,5 @@
+# MaSzyna: notes for Gemini CLI
+
+The instructions for every coding agent in this repository are in `AGENTS.md`. Add or change rules there, not here.
+
+@./AGENTS.md
diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h
index a66584941..b619ba7de 100644
--- a/McZapkie/MOVER.h
+++ b/McZapkie/MOVER.h
@@ -10,9 +10,15 @@ http://mozilla.org/MPL/2.0/.
#pragma once
//---------------------------------------------------------------------------
// Q: 20160805 - odlaczenie pliku fizyki .pas od kompilacji
+#include
#include