Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ Checks: "bugprone-*,
-llvm-header-guard,
-llvm-else-after-return,
-*-unhandled-self-assignment,
-*-use-enum-class,
-*-use-ranges,
-readability-else-after-return,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-cstyle-cast,
-readability-redundant-declaration,
-*-return-braced-init-list"
WarningsAsErrors: "*"
8 changes: 6 additions & 2 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
clang-tidy:
name: Run clang-tidy and upload report
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -40,6 +40,10 @@ jobs:
id: run
shell: bash
run: |
sudo apt update
sudo add-apt-repository universe
sudo apt update
sudo apt install libncurses5-dev libtinfo5
set -o pipefail
# Collect sources (mirror Makefile exclusions)
mapfile -t FILES < <(find src/ \( -name "*.cpp" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" -o -name "*.c" -o -name "*.h" \) \
Expand All @@ -54,7 +58,7 @@ jobs:
for f in "${FILES[@]}"; do
echo "=== ${f} ===" | tee -a clang-tidy.log
# Use project-local .clang-tidy implicitly
if ! clang-tidy -p build --quiet --fix-notes -header-filter=^src/ "$f" 2>>clang-tidy-errors.log | tee -a clang-tidy.log; then
if ! sudo clang-tidy -p build -extra-arg=-std=c++17 --quiet --fix-notes -header-filter=^src/ "$f" 2>>clang-tidy-errors.log | tee -a clang-tidy.log; then
echo "clang-tidy reported non-zero status for $f" >> clang-tidy-errors.log
fi
done
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ godot-cpp/CMakeFiles/godot-cpp.dir/gen/src/classes
/Testing/


build-*/
build-*/
/.codex
11 changes: 6 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git
branch = 4.3
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git
branch = 4.3
[submodule "vendor/gut"]
path = vendor/gut
url = https://github.com/bitwes/Gut.git
path = vendor/gut
url = https://github.com/bitwes/Gut.git
ignore = dirty
40 changes: 33 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.17)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_EXTENSIONS ON)
SET(CMAKE_COLOR_DIAGNOSTICS ON)
OPTION(LIBMASZYNA_DEBUG "If the build should contain custom library logger" OFF)
# Do not hard‑force a generator; allow users to select one suitable for cross‑compiling.
# Silence unused variable warning when specified from toolchain
IF (CMAKE_C_COMPILER)
ENDIF ()
SET(CMAKE_GENERATOR Ninja)

# Allow selecting platform via -DGODOTCPP_PLATFORM=android|windows|linux|macos|ios|web
IF (DEFINED GODOTCPP_PLATFORM AND NOT CMAKE_SYSTEM_NAME)
STRING(TOLOWER "${GODOTCPP_PLATFORM}" _req_platform)
Expand All @@ -15,10 +18,10 @@ IF (DEFINED GODOTCPP_PLATFORM AND NOT CMAKE_SYSTEM_NAME)
# 1) Explicit toolchain file provided by user
IF (DEFINED ANDROID_NDK_TOOLCHAIN)
SET(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK_TOOLCHAIN}" CACHE FILEPATH "Android NDK toolchain (manual)" FORCE)
# 2) NDK root directory provided by user
# 2) NDK root directory provided by user
ELSEIF (DEFINED ANDROID_NDK_ROOT)
SET(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" CACHE FILEPATH "Android NDK toolchain (from ANDROID_NDK_ROOT)" FORCE)
# 3) Environment variables commonly used
# 3) Environment variables commonly used
ELSEIF (DEFINED ENV{ANDROID_NDK})
SET(CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK}/build/cmake/android.toolchain.cmake" CACHE FILEPATH "Android NDK toolchain (from ANDROID_NDK)" FORCE)
ELSEIF (DEFINED ENV{ANDROID_NDK_HOME})
Expand All @@ -44,21 +47,21 @@ IF (DEFINED GODOTCPP_PLATFORM AND NOT CMAKE_SYSTEM_NAME)
ENDIF ()
ELSEIF (_req_platform STREQUAL "windows")
# Windows cross‑compile via MinGW (recommended from non‑Windows hosts)
IF (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
IF (NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_HOST_WIN32)
# Best effort: if cross compilers are present, set them. This must be before project().
FIND_PROGRAM(MINGW_C "x86_64-w64-mingw32-gcc")
FIND_PROGRAM(MINGW_CXX "x86_64-w64-mingw32-g++")
IF (MINGW_C AND MINGW_CXX)
SET(CMAKE_SYSTEM_NAME Windows CACHE STRING "" FORCE)
SET(CMAKE_C_COMPILER ${MINGW_C} CACHE FILEPATH "" FORCE)
SET(CMAKE_C_COMPILER ${MINGW_C} CACHE FILEPATH "" FORCE)
SET(CMAKE_CXX_COMPILER ${MINGW_CXX} CACHE FILEPATH "" FORCE)
MESSAGE(STATUS "Configuring cross‑compile for Windows using MinGW (x86_64).")
ELSE()
ELSE ()
# Fallback: still set system name; user must provide a toolchain or compilers.
SET(CMAKE_SYSTEM_NAME Windows CACHE STRING "" FORCE)
MESSAGE(WARNING "GODOTCPP_PLATFORM=windows set but no MinGW cross compiler auto‑detected. Provide a toolchain file or set CMAKE_C_COMPILER/CMAKE_CXX_COMPILER.")
ENDIF ()
ELSE()
ELSEIF (NOT CMAKE_HOST_WIN32)
SET(CMAKE_SYSTEM_NAME Windows CACHE STRING "" FORCE)
MESSAGE(STATUS "Configuring cross‑compile for Windows using specified toolchain: ${CMAKE_TOOLCHAIN_FILE}")
ENDIF ()
Expand Down Expand Up @@ -88,6 +91,12 @@ PROJECT(Maszyna-API-Wrapper
LANGUAGES CXX
)

IF (MSVC)
# /utf-8: Set source and execution character sets to UTF-8
# /bigobj: Increase the number of addressable sections in an .obj file
ADD_COMPILE_OPTIONS(/utf-8 /bigobj)
ENDIF ()

FILE(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS "src/*.cpp" "src/*.hpp")

ADD_LIBRARY(${LIBNAME} SHARED ${SRC_FILES})
Expand Down Expand Up @@ -156,11 +165,28 @@ IF (GODOTCPP_TARGET STREQUAL "template_debug")
SET(DEBUG_SUFFIX ".debug")
ENDIF ()

IF (LIBMASZYNA_DEBUG)
TARGET_COMPILE_DEFINITIONS(${LIBNAME} PRIVATE LIBMASZYNA_DEBUG)
ENDIF ()

SET(_OUTPUT_NAME "${LIBNAME}${DEBUG_SUFFIX}${ARCH_SUFFIX}")
SET(GODOT_PROJECT_BINARY_DIR "${PROJECT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/libmaszyna/${GODOTCPP_PLATFORM}")

SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES OUTPUT_NAME "${_OUTPUT_NAME}" LIBRARY_OUTPUT_DIRECTORY "${GODOT_PROJECT_BINARY_DIR}")

# For multi-config generators (like Visual Studio), ensure output directory doesn't have a config subfolder
GET_PROPERTY(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
IF (IS_MULTI_CONFIG)
FOREACH (CONFIG ${CMAKE_CONFIGURATION_TYPES})
STRING(TOUPPER ${CONFIG} CONFIG)
SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${CONFIG} "${GODOT_PROJECT_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${GODOT_PROJECT_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} "${GODOT_PROJECT_BINARY_DIR}"
)
ENDFOREACH ()
ENDIF ()

SET(ADDONS_DEMO_DIR "${PROJECT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/addons")
ADD_CUSTOM_COMMAND(TARGET ${LIBNAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${ADDONS_DEMO_DIR}"
Expand Down
35 changes: 24 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

GITREV=$(shell git rev-parse --abbrev-ref HEAD | sed -e 's/[^A-Za-z0-9]//g')
DATE=$(shell date +"%Y%m%d")
CMAKE_BUILD_JOBS=$(shell cores=$$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1); if [ "$$cores" -gt 2 ]; then echo $$((cores - 2)); else echo 1; fi)
LIBMASZYNA_DEBUG:=""

docs:
cd demo && godot --doctool .. --gdextension-docs
Expand All @@ -14,14 +16,25 @@ cleanup:
rm -rf demo/addons/gut


cleanup-build-debug:
rm -rf build-debug


cleanup-build-release:
rm -rf build-release


cleanup-builds: cleanup-build-debug cleanup-build-release


compile-debug:
cmake -B build-debug -DGODOTCPP_TARGET=template_debug
cmake --build build-debug
cmake -B build-debug -DGODOTCPP_TARGET=template_debug -DLIBMASZYNA_DEBUG=$(LIBMASZYNA_DEBUG)
cmake --build build-debug --parallel $(CMAKE_BUILD_JOBS)


compile-release:
cmake -B build-release -DGODOTCPP_TARGET=template_release
cmake --build build-release
cmake --build build-release --parallel $(CMAKE_BUILD_JOBS)


compile-all: compile-debug compile-release
Expand All @@ -30,35 +43,35 @@ compile-all: compile-debug compile-release
cross-compile-release:
cmake -B build-linux64 \
-DGODOTCPP_TARGET="template_release"
cmake --build build-linux64
cmake --build build-linux64 --parallel $(CMAKE_BUILD_JOBS)
cmake -B build-win64 \
-DGODOTCPP_TARGET="template_release" \
-DGODOTCPP_PLATFORM=windows \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DCMAKE_SIZEOF_VOID_P=8
cmake --build build-win64
cmake --build build-win64 --parallel $(CMAKE_BUILD_JOBS)


cross-compile-debug:
cmake -B build-linux64 \
-DGODOTCPP_TARGET="template_debug"
cmake --build build-linux64
-DGODOTCPP_TARGET="template_debug" -DLIBMASZYNA_DEBUG=ON
cmake --build build-linux64 --parallel $(CMAKE_BUILD_JOBS)
cmake -B build-win64 \
-DGODOTCPP_TARGET="template_debug" \
-DGODOTCPP_PLATFORM=windows \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DCMAKE_SIZEOF_VOID_P=8
cmake --build build-win64
cmake --build build-win64 --parallel $(CMAKE_BUILD_JOBS)


release-linux:
cmake -B build-linux64 \
-DGODOTCPP_TARGET="template_release"
cmake --build build-linux64
cmake --build build-linux64 --parallel $(CMAKE_BUILD_JOBS)
cd demo && godot --headless --export-release "linux_x86_64" ../bin/linux/reloaded.zip && mv ../bin/linux/reloaded.zip ../bin/linux/reloaded-$(GITREV)-$(DATE)-linux.zip


Expand All @@ -70,7 +83,7 @@ release-windows:
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DCMAKE_SIZEOF_VOID_P=8
cmake --build build-win64
cmake --build build-win64 --parallel $(CMAKE_BUILD_JOBS)
cd demo && godot --headless --export-release "windows_x86_64" ../bin/windows/reloaded.zip && mv ../bin/windows/reloaded.zip ../bin/windows/reloaded-$(GITREV)-$(DATE)-windows.zip


Expand Down Expand Up @@ -113,4 +126,4 @@ docker-run-tests: docker-build-tests


run-tests: compile
godot --path demo --headless -s addons/gut/gut_cmdln.gd -gdir=res://tests/ -gexit
godot --path demo --headless -s addons/gut/gut_cmdln.gd -gdir=res://tests/,res://addons/gnd_sfx/tests/ -gexit
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ git submodule update --init --recursive
For build system setup,
please take a look at [official Godot Engine documentation for Android development](https://docs.godotengine.org/en/4.3/tutorials/export/exporting_for_android.html)
### Compiling
> [!IMPORTANT]
> If you are using DEBUG macro, you should build CMake project with flag `-DLIBMASZYNA_DEBUG=ON` and then compile it.
> When using make ,add `LIBMASZYNA_DEBUG=ON` to a command line, i.e. `make compile-debug LIBMASZYNA_DEBUG=ON`. You can
> also turn off DEBUG using `LIBMASZYNA_DEBUG=OFF`.

```bash
cmake -B build-<platform> \
-DGODOTCPP_TARGET="template_release"
Expand All @@ -49,6 +54,55 @@ Cross-compiling (for Windows on Linux):
-DCMAKE_SIZEOF_VOID_P=8
cmake --build build-win64
```

#### Makefile

You can use Makefile targets as shortcuts.

For debug compilation:

```
make compile-debug
```

or just simply

```
make
```

For release compilation:

```
make compile-release
```

For cross compilation linux/windows:

```
make cross-compile-debug
```

or

```
make cross-compile-release
```

#### Parallel compilation

To enable parallel compilation add `--parallel <num_jobs>` argument to cmake calls, for example:

```bash
cmake -B build-linux64 \
-DGODOTCPP_TARGET="template_release"
--parallel 4
cmake --build build-linux64 --parallel 4
```

If you're using `Makefile`, number of parralel jobs will be set automatically to `<cores count> - 2` for system with at
least two cores.

### Compatibility

| Plugin Version | Godot Engine version | Windows | Linux | Mac OS | Android | iOS | C++ Standard | MaSzyna Version |
Expand Down Expand Up @@ -83,7 +137,7 @@ git submodule update --init
Then run tests from the command line (if you have `make` installed, you can use shortcut `make run-tests`):

```bash
godot --path demo --headless -s addons/gut/gut_cmdln.gd -gdir=res://tests/ -gexit
godot --path demo --headless -s addons/gut/gut_cmdln.gd -gdir=res://tests/,res://addons/gnd_sfx/tests/ -gexit
```


Expand Down
8 changes: 8 additions & 0 deletions addons/libmaszyna/cabin/base_cabin_tool_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func _process_dirty(delta):
func _process_tool(delta):
pass

func get_cabin() -> Cabin3D:
var node = get_parent()
while node:
if node is Cabin3D:
return node
node = node.get_parent()
return null

func _process(delta):
if _dirty:
_dirty = false
Expand Down
7 changes: 7 additions & 0 deletions addons/libmaszyna/cabin/cabin_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var _dirty = true
var _cabin_ready:bool = false
var _e3d_instances:Array[E3DModelInstance] = []
var _e3d_loaded_count:int = 0
var controller: TrainController


@export_node_path("TrainController") var controller_path:NodePath = NodePath(""):
set(x):
Expand All @@ -18,11 +20,16 @@ var _e3d_loaded_count:int = 0
@export var camera_bound_max = Vector3.ZERO
@export var camera_bound_enabled:bool = false
@export var driver_position = Vector3.ZERO
@export var sound_bank:SfxBank

func get_camera_transform():
return global_transform.translated_local(driver_position)

func is_cabin_ready() -> bool:
return _cabin_ready

func _propagate_train_controller(node: Node, controller: TrainController):
self.controller = controller
for child in node.get_children():
_propagate_train_controller(child, controller)
if "controller_path" in child:
Expand Down
4 changes: 2 additions & 2 deletions addons/libmaszyna/cabin/cabin_blinker.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[ext_resource type="Script" uid="uid://ccmsi0wq5sq3s" path="res://addons/libmaszyna/cabin/cabin_blinker.gd" id="1_q1beh"]

[node name="Blinker" type="Node3D" unique_id=212943250]
[node name="Blinker" type="Node3D" unique_id=447458378]
script = ExtResource("1_q1beh")

[node name="Timer" type="Timer" parent="." unique_id=114747919]
[node name="Timer" type="Timer" parent="." unique_id=666450899]

[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
Loading
Loading