Skip to content

Commit 8e0c1dd

Browse files
authored
Merge pull request #102 from SentyTek/dev
Add unit tests, improve render perf, many fixes.
2 parents 0d8056f + 8b3cef8 commit 8e0c1dd

78 files changed

Lines changed: 3605 additions & 15041 deletions

Some content is hidden

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

.github/workflows/tests.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Syngine Tests
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["main", "dev"]
8+
9+
jobs:
10+
build-and-test:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest, windows-latest]
15+
build_type: [Debug]
16+
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: false
24+
25+
- name: Init required submodules
26+
run: >
27+
git submodule update --init --recursive
28+
29+
- name: Install Ninja
30+
uses: seanmiddleditch/gha-setup-ninja@v3
31+
32+
- name: Setup MSVC Developer Command Prompt
33+
if: runner.os == 'Windows'
34+
uses: ilammy/msvc-dev-cmd@v1
35+
36+
- name: Install Linux graphics deps
37+
if: runner.os == 'Linux'
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y clang libx11-dev libgl1-mesa-dev libwayland-dev libwayland-egl-backend-dev
41+
42+
- name: Configure (Windows/MSVC)
43+
if: runner.os == 'Windows'
44+
run: >
45+
cmake -B build -S .
46+
-G Ninja
47+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
48+
-DCMAKE_C_COMPILER=cl
49+
-DCMAKE_CXX_COMPILER=cl
50+
-DSYNGINE_BUILD_TOOLS=OFF
51+
-DSYN_ENABLE_TEST_MODE=ON
52+
53+
- name: Configure (Linux/macOS)
54+
if: runner.os != 'Windows'
55+
run: >
56+
cmake -B build -S .
57+
-G Ninja
58+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
59+
-DCMAKE_C_COMPILER=clang
60+
-DCMAKE_CXX_COMPILER=clang++
61+
-DSYNGINE_BUILD_TOOLS=OFF
62+
-DSYN_ENABLE_TEST_MODE=ON
63+
${{ matrix.os != 'windows-latest' && '-DSDL_UNIX_CONSOLE_BUILD=ON' || '' }}
64+
65+
- name: Build
66+
run: cmake --build build --target engine_tests
67+
68+
- name: Run Tests
69+
run: ctest --test-dir build --output-on-failure

CMakeLists.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
# ╰──────────────────────────────────────╯
88
# Engine main CMakeLists (root/engine/CMakeLists.txt)
99

10-
1110
cmake_minimum_required(VERSION 3.16)
1211
project(Syngine)
1312
set(CMAKE_CXX_STANDARD 20)
1413
set(SYNGINE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "Syngine source dir" FORCE)
1514

15+
# Enable CTest in the engine project so standalone engine CI can discover tests.
16+
include(CTest)
17+
1618
# Generate Version.h for all engine builds (including engine-only CI).
1719
include(${CMAKE_CURRENT_LIST_DIR}/cmake/versioning.cmake)
1820
define_version()
@@ -98,10 +100,18 @@ add_library(Syngine STATIC
98100
src/Syngine/ECS/ComponentRegistry.cpp
99101
)
100102

103+
set_target_properties(Syngine PROPERTIES FOLDER "Engine")
104+
105+
# Call the testing cmake
106+
option(SYN_ENABLE_TEST_MODE "Enable test mode" OFF)
107+
if(SYN_ENABLE_TEST_MODE)
108+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests ${CMAKE_BINARY_DIR}/engine_tests EXCLUDE_FROM_ALL)
109+
endif()
110+
101111
# Uncomment to enable graphics debugging.
102112
# This is done because programs like RenderDoc do not work if window's `dbghelp.dll` is loaded, which we use for crash handling/logging.
103113
# And so this macro prevents those features from being compiled in. This also disables the Syngine Profiler, which may cause compile-time errors. Use at your own risk.
104-
# target_compile_definitions(Syngine PUBLIC SYN_DEBUG_GRAPHICS)
114+
target_compile_definitions(Syngine PUBLIC SYN_DEBUG_GRAPHICS)
105115

106116
# Apple needs OBJC++ files for Metal support
107117
if(APPLE)
@@ -197,6 +207,27 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third_party/JoltPhysics/Build ${CMAKE
197207
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib)
198208
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third_party/sol2 ${CMAKE_BINARY_DIR}/third_party/sol2 EXCLUDE_FROM_ALL)
199209

210+
if (MSVC AND TARGET Jolt)
211+
target_compile_options(Jolt PRIVATE /wd4865 /WX-) # Disable "the underlying type of ... will change when '/Zc:enumTypes' is specified on the command line" warning and don't treat as error
212+
endif()
213+
214+
# Add the third party things to respective folders
215+
set_target_properties(SDL_uclibc PROPERTIES FOLDER "ThirdParty/SDL")
216+
set_target_properties(SDL3_test PROPERTIES FOLDER "ThirdParty/SDL")
217+
set_target_properties(SDL3-static PROPERTIES FOLDER "ThirdParty/SDL")
218+
set_target_properties(bgfx PROPERTIES FOLDER "ThirdParty/bgfx")
219+
set_target_properties(bx PROPERTIES FOLDER "ThirdParty/bgfx")
220+
set_target_properties(bimg PROPERTIES FOLDER "ThirdParty/bgfx")
221+
set_target_properties(assimp PROPERTIES FOLDER "ThirdParty/assimp")
222+
set_target_properties(Jolt PROPERTIES FOLDER "ThirdParty/JoltPhysics")
223+
set_target_properties(lua PROPERTIES FOLDER "ThirdParty/sol2")
224+
if(MSVC) # these are windows only targets (i dont know man)
225+
set_target_properties(zlibstatic PROPERTIES FOLDER "ThirdParty/assimp")
226+
set_target_properties(UpdateAssimpLibsDebugSymbolsAndDLLs PROPERTIES FOLDER "Engine") # this sucks
227+
endif()
228+
229+
set_target_properties(shaderc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>/tools") # shaderc is a tool, so put it in the tools folder
230+
200231
# Allow not building SynTools if not needed
201232
option(SYNGINE_BUILD_TOOLS "Build Syngine Tools (Shader Compiler, Asset Packager)" ON)
202233
if(SYNGINE_BUILD_TOOLS)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ docs/ -> Documentation on the engine
3434
include/ -> User-facing header files
3535
src/ -> Engine source files
3636
lib/ -> Other library files not in third_party and custom libraries
37+
tests/ -> Tests
3738
third_party/ -> Third party components like SDL and Jolt
39+
tools/ -> Official tools used to make Syngine Games (asset packaging mainly)
3840
```
3941

4042
## Technologies used

cmake/GameConfig.cmake

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ include(${SYNGINE_SOURCE_DIR}/cmake/CompileShaders.cmake)
1111
include(${SYNGINE_SOURCE_DIR}/cmake/CompileMeshes.cmake)
1212
include(${SYNGINE_SOURCE_DIR}/cmake/FileBundle.cmake)
1313

14+
# Keep all staged runtime assets under the executable output tree.
15+
set(SYNGINE_STAGED_ROM_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>/bin/rom")
16+
1417
# Function to compile all shaders in a directory
1518
function(compile_collect_shaders SHADER_SRC_DIR ALL_SHADERS_LIST)
1619
set(LOCAL_SHADER_OUTPUT_DIR "${CMAKE_BINARY_DIR}/shaders")
17-
set(LOCAL_SHADER_BUNDLE_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>/rom/shaders")
20+
set(LOCAL_SHADER_BUNDLE_DIR "${SYNGINE_STAGED_ROM_DIR}/shaders")
1821
file(MAKE_DIRECTORY ${LOCAL_SHADER_OUTPUT_DIR}) # Ensure output directory exists
1922
set(LOCAL_BGFX_CORE_INCLUDE_DIR "${SYNGINE_SOURCE_DIR}/third_party/bgfx.cmake/bgfx/src")
2023

@@ -67,7 +70,7 @@ function(compile_collect_default_gizmos GIZMO_BUNDLE_OUTPUT_VAR)
6770

6871
create_file_bundle(
6972
BUNDLE_NAME "default_gizmos"
70-
OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/rom/gizmos"
73+
OUTPUT_DIRECTORY "${SYNGINE_STAGED_ROM_DIR}/gizmos"
7174
SOURCE_DIRECTORY "${DEFAULT_GIZMO_SOURCE_DIR}"
7275
INPUT_FILES ${DEFAULT_GIZMO_ENTRIES}
7376
BUNDLE_FILE_OUTPUT_VAR GENERATED_GIZMO_BUNDLE
@@ -90,7 +93,7 @@ function(compile_collect_asset_bundle ASSET_SRC_DIR BUNDLE_NAME ASSET_BUNDLE_OUT
9093

9194
create_file_bundle(
9295
BUNDLE_NAME "${BUNDLE_NAME}"
93-
OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/rom/${BUNDLE_NAME}"
96+
OUTPUT_DIRECTORY "${SYNGINE_STAGED_ROM_DIR}/${BUNDLE_NAME}"
9497
SOURCE_DIRECTORY "${ASSET_SRC_DIR}"
9598
INPUT_FILES ${ASSET_ENTRIES}
9699
BUNDLE_FILE_OUTPUT_VAR GENERATED_ASSET_BUNDLE
@@ -101,16 +104,11 @@ endfunction()
101104

102105
# Asset handling helpers
103106
function(_add_assets_win_linux target)
104-
set(ROM_DIR "$<TARGET_FILE_DIR:${target}>/rom")
105-
106107
get_target_property(COPY_ROM ${target} SYNGINE_COPY_ROM)
107108
if(COPY_ROM)
108109
add_custom_command(TARGET ${target} POST_BUILD
109-
COMMAND ${CMAKE_COMMAND} -E make_directory "${ROM_DIR}"
110-
COMMAND ${CMAKE_COMMAND} -E copy_directory
111-
"${CMAKE_BINARY_DIR}/$<CONFIG>/rom"
112-
"${ROM_DIR}"
113-
COMMENT "Copying staged rom assets to executable directory"
110+
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${target}>/rom"
111+
COMMENT "ROM assets are staged directly into executable directory"
114112
)
115113
endif()
116114
endfunction()
@@ -123,7 +121,7 @@ function(_add_assets_mac target)
123121
add_custom_command(TARGET ${target} POST_BUILD
124122
COMMAND ${CMAKE_COMMAND} -E make_directory "${ROM_DIR}"
125123
COMMAND ${CMAKE_COMMAND} -E copy_directory
126-
"${CMAKE_BINARY_DIR}/$<CONFIG>/rom"
124+
"${SYNGINE_STAGED_ROM_DIR}"
127125
"${ROM_DIR}"
128126
COMMENT "Copying staged rom assets into app Resources"
129127
)
@@ -197,6 +195,7 @@ function(add_assets target)
197195
DEPENDS "${ICON_BUNDLE_PATH}"
198196
)
199197
add_dependencies(${target} CompileMacAssets)
198+
set_target_properties(CompileMacAssets PROPERTIES FOLDER "Game")
200199

201200
# set the compiled asset bundle as a target for the app and copy it into Resources
202201
target_sources(${target} PRIVATE "${ASSET_PACKAGE}")
@@ -219,6 +218,7 @@ function(add_assets target)
219218
DEPENDS "${FINAL_PLIST_PATH}"
220219
)
221220
add_dependencies(${target} InfoPlistMerge)
221+
set_target_properties(InfoPlistMerge PROPERTIES FOLDER "Game")
222222

223223
# add the Info.plist to the target and have it depend on the icon
224224
set_property(
@@ -316,7 +316,7 @@ if(EXISTS "${GAME_ASSET_DIR}")
316316
elseif(ASSET_SUBDIR STREQUAL "meshes")
317317
compile_all_meshes(
318318
SOURCE_DIRECTORY "${GAME_ASSET_DIR}/${ASSET_SUBDIR}"
319-
OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/rom/meshes"
319+
OUTPUT_DIRECTORY "${SYNGINE_STAGED_ROM_DIR}/meshes"
320320
BUNDLE_FILES_OUTPUT_VAR ALL_BUNDLED_MESH_FILES
321321
)
322322
else()
@@ -343,27 +343,31 @@ message(STATUS "SyngineGame: Compiled default gizmo bundles for ${name}: ${ALL_B
343343
if(ALL_COMPILED_SHADER_BINARIES)
344344
add_custom_target(GameShaders ALL DEPENDS ${ALL_COMPILED_SHADER_BINARIES})
345345
add_dependencies(${name} GameShaders)
346+
set_target_properties(GameShaders PROPERTIES FOLDER "Game")
346347
message(STATUS "SyngineGame: Added GameShaders target for ${name}.")
347348
endif()
348349

349350
# Add dependency on the compiled mesh bundles
350351
if(ALL_BUNDLED_MESH_FILES)
351352
add_custom_target(GameMeshes ALL DEPENDS ${ALL_BUNDLED_MESH_FILES})
352353
add_dependencies(${name} GameMeshes)
354+
set_target_properties(GameMeshes PROPERTIES FOLDER "Game")
353355
message(STATUS "SyngineGame: Added GameMeshes target for ${name}.")
354356
endif()
355357

356358
# Add dependency on the compiled generic asset bundles
357359
if(ALL_BUNDLED_OTHER_ASSET_FILES)
358360
add_custom_target(GameAssets ALL DEPENDS ${ALL_BUNDLED_OTHER_ASSET_FILES})
359361
add_dependencies(${name} GameAssets)
362+
set_target_properties(GameAssets PROPERTIES FOLDER "Game")
360363
message(STATUS "SyngineGame: Added GameAssets target for ${name}.")
361364
endif()
362365

363366
# Add dependency on the compiled gizmo bundles
364367
if(ALL_BUNDLED_GIZMO_FILES)
365368
add_custom_target(GameGizmos ALL DEPENDS ${ALL_BUNDLED_GIZMO_FILES})
366369
add_dependencies(${name} GameGizmos)
370+
set_target_properties(GameGizmos PROPERTIES FOLDER "Game")
367371
message(STATUS "SyngineGame: Added GameGizmos target for ${name}.")
368372
endif()
369373

default/shaders/default.frag.bgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
float nightFactor = clamp(smoothstep(-0.05, 0.05, sunElevation), 0.2, 1.0);
3838
vec3 ambient = mix(col.rgb, skyColor, hemiMix) * u_materialParams1.y;
3939

40-
float shadowFactor = getShadowFactor(v_worldPos, vec3(0.0, 1.0, 0.0), N, u_lightDir, v_viewDepth);
40+
float shadowFactor = getShadowFactor(v_worldPos, vec3(0.0, 1.0, 0.0), u_lightDir, v_viewDepth);
4141

4242
float sunIntensity = smoothstep(-0.1, 0.1, sunElevation);
4343
vec3 directLight = u_sunColor.xyz * sunIntensity * NdotL * shadowFactor;

default/shaders/default_billboard.frag.bgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void main() {
3535
// Calculate view depth (distance from camera)
3636
float viewDepth = length(v_worldPos - u_viewPos.xyz);
3737
vec3 fakeNormal = vec3(0.0, 1.0, 0.0); // Assume upward facing normal
38-
float shadowFactor = getShadowFactor(v_worldPos, vec3(0.0, 1.0, 0.0), fakeNormal, u_lightDir, viewDepth);
38+
float shadowFactor = getShadowFactor(v_worldPos, fakeNormal, u_lightDir, viewDepth);
3939
lightFactor *= shadowFactor;
4040
}
4141

default/shaders/default_texture.frag.bgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
// Micro shadowing from normal map
4848
// Softer attenuation for grazing angles
4949
float microShadow = clamp(dot(Nmicro, lightDirToSun) * 2.0 + 0.3, 0.0, 1.0);
50-
float shadow = getShadowFactor(v_worldPos, vN, N, u_lightDir, v_viewDepth);
50+
float shadow = getShadowFactor(v_worldPos, vN, u_lightDir, v_viewDepth);
5151
shadow = mix(1.0, shadow, smoothstep(0.1, 0.3, sunElevation)); // Fade shadows to full light (1.0) at low sun angles
5252

5353
float sunIntensity = smoothstep(-0.1, 0.1, sunElevation);

0 commit comments

Comments
 (0)