Skip to content

Commit 67901ee

Browse files
authored
Merge pull request #119
Simple game engine
2 parents ca42702 + 0e9721e commit 67901ee

File tree

147 files changed

+71576
-8
lines changed

Some content is hidden

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

147 files changed

+71576
-8
lines changed

README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ It also contains Vulkan usage clarifications, improved synchronization and new c
2626
The repository is organized into several important directories:
2727

2828
* `en/` - Contains the tutorial content in English, organized by chapters
29+
** The main tutorial covers fundamental Vulkan concepts (chapters 00-17)
30+
** The "Building a Simple Engine" section builds upon these fundamentals to create a structured rendering engine
2931
* `attachments/` - Contains code examples, shader files, and resources used in the tutorial
3032
* `images/` - Contains illustrations, diagrams, and screenshots used in the tutorial
3133
* `scripts/` - Contains utility scripts, including dependency installation scripts

attachments/CMake/Findnlohmann_json.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if(NOT nlohmann_json_INCLUDE_DIR)
4747
FetchContent_Declare(
4848
nlohmann_json
4949
GIT_REPOSITORY https://github.com/nlohmann/json.git
50-
GIT_TAG v3.11.2 # Use a specific tag for stability
50+
GIT_TAG v3.12.0 # Use a specific tag for stability
5151
)
5252

5353
# Set policy to suppress the deprecation warning

attachments/CMake/Findtinygltf.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
find_package(nlohmann_json QUIET)
1717
if(NOT nlohmann_json_FOUND)
1818
include(FetchContent)
19-
message(STATUS "nlohmann_json not found, fetching from GitHub...")
19+
message(STATUS "nlohmann_json not found, fetching v3.12.0 from GitHub...")
2020
FetchContent_Declare(
2121
nlohmann_json
2222
GIT_REPOSITORY https://github.com/nlohmann/json.git
23-
GIT_TAG v3.11.2 # Use a specific tag for stability
23+
GIT_TAG v3.12.0 # Use a specific tag for stability
2424
)
2525
FetchContent_MakeAvailable(nlohmann_json)
2626
endif()
71.1 KB
Binary file not shown.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
cmake_minimum_required(VERSION 3.29)
2+
3+
# Enable C++ module dependency scanning
4+
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
5+
6+
project(SimpleEngine VERSION 1.0.0 LANGUAGES CXX C)
7+
8+
# Add CMake module path for custom find modules
9+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../CMake")
10+
11+
# Find required packages
12+
find_package (glfw3 REQUIRED)
13+
find_package (glm REQUIRED)
14+
find_package (Vulkan REQUIRED)
15+
find_package (tinygltf REQUIRED)
16+
find_package (KTX REQUIRED)
17+
find_package (OpenAL REQUIRED)
18+
19+
# set up Vulkan C++ module
20+
add_library(VulkanCppModule)
21+
add_library(Vulkan::cppm ALIAS VulkanCppModule)
22+
23+
target_compile_definitions(VulkanCppModule
24+
PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
25+
)
26+
target_include_directories(VulkanCppModule
27+
PRIVATE
28+
"${Vulkan_INCLUDE_DIR}"
29+
)
30+
target_link_libraries(VulkanCppModule
31+
PUBLIC
32+
Vulkan::Vulkan
33+
)
34+
35+
set_target_properties(VulkanCppModule PROPERTIES CXX_STANDARD 20)
36+
37+
target_sources(VulkanCppModule
38+
PUBLIC
39+
FILE_SET cxx_modules TYPE CXX_MODULES
40+
BASE_DIRS
41+
"${Vulkan_INCLUDE_DIR}"
42+
FILES
43+
"${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm"
44+
)
45+
46+
47+
48+
# Platform-specific settings
49+
if(ANDROID)
50+
# Android-specific settings
51+
add_definitions(-DPLATFORM_ANDROID)
52+
else()
53+
# Desktop-specific settings
54+
add_definitions(-DPLATFORM_DESKTOP)
55+
endif()
56+
57+
# Shader compilation
58+
# Find Slang shaders
59+
file(GLOB SLANG_SHADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.slang)
60+
61+
# Find slangc executable (optional)
62+
find_program(SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK}/bin)
63+
64+
if(SLANGC_EXECUTABLE)
65+
# Ensure the output directory for compiled shaders exists
66+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders)
67+
68+
# Compile Slang shaders using slangc
69+
foreach(SHADER ${SLANG_SHADER_SOURCES})
70+
get_filename_component(SHADER_NAME ${SHADER} NAME)
71+
get_filename_component(SHADER_NAME_WE ${SHADER_NAME} NAME_WE)
72+
string(REGEX REPLACE "\.slang$" "" OUTPUT_NAME ${SHADER_NAME})
73+
add_custom_command(
74+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv
75+
COMMAND ${SLANGC_EXECUTABLE} ${SHADER} -target spirv -profile spirv_1_4 -emit-spirv-directly -o ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv
76+
DEPENDS ${SHADER}
77+
COMMENT "Compiling Slang shader ${SHADER_NAME} with slangc"
78+
)
79+
list(APPEND SHADER_SPVS ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv)
80+
endforeach()
81+
82+
add_custom_target(shaders DEPENDS ${SHADER_SPVS})
83+
else()
84+
message(STATUS "slangc not found. Skipping shader compilation step.")
85+
add_custom_target(shaders)
86+
endif()
87+
88+
# Source files
89+
set(SOURCES
90+
main.cpp
91+
engine.cpp
92+
scene_loading.cpp
93+
platform.cpp
94+
renderer_core.cpp
95+
renderer_rendering.cpp
96+
renderer_pipelines.cpp
97+
renderer_compute.cpp
98+
renderer_utils.cpp
99+
renderer_resources.cpp
100+
memory_pool.cpp
101+
resource_manager.cpp
102+
entity.cpp
103+
component.cpp
104+
transform_component.cpp
105+
mesh_component.cpp
106+
camera_component.cpp
107+
model_loader.cpp
108+
audio_system.cpp
109+
physics_system.cpp
110+
imgui_system.cpp
111+
imgui/imgui.cpp
112+
imgui/imgui_draw.cpp
113+
vulkan_device.cpp
114+
pipeline.cpp
115+
descriptor_manager.cpp
116+
renderdoc_debug_system.cpp
117+
mikktspace.c
118+
)
119+
120+
# Create executable
121+
add_executable(SimpleEngine ${SOURCES})
122+
add_dependencies(SimpleEngine shaders)
123+
set_target_properties (SimpleEngine PROPERTIES CXX_STANDARD 20)
124+
125+
# Link libraries
126+
target_link_libraries(SimpleEngine PRIVATE
127+
Vulkan::cppm
128+
glm::glm
129+
tinygltf::tinygltf
130+
KTX::ktx
131+
OpenAL::OpenAL
132+
)
133+
134+
if(NOT ANDROID)
135+
target_link_libraries(SimpleEngine PRIVATE glfw)
136+
endif()
137+
138+
# Copy model and texture files if they exist
139+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/models)
140+
add_custom_command(TARGET SimpleEngine POST_BUILD
141+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/models ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/models
142+
COMMENT "Copying models to output directory"
143+
)
144+
endif()
145+
146+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/textures)
147+
add_custom_command(TARGET SimpleEngine POST_BUILD
148+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/textures ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/textures
149+
COMMENT "Copying textures to output directory"
150+
)
151+
endif()
152+
153+
# Add packaging configuration
154+
include(CPack)
155+
156+
# Set package properties
157+
set(CPACK_PACKAGE_NAME "SimpleEngine")
158+
set(CPACK_PACKAGE_VENDOR "SimpleEngine Team")
159+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A simple game engine built with Vulkan")
160+
set(CPACK_PACKAGE_VERSION "1.0.0")
161+
set(CPACK_PACKAGE_VERSION_MAJOR "1")
162+
set(CPACK_PACKAGE_VERSION_MINOR "0")
163+
set(CPACK_PACKAGE_VERSION_PATCH "0")
164+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "SimpleEngine")
165+
166+
# Set platform-specific package generators
167+
if(WIN32)
168+
set(CPACK_GENERATOR "ZIP;NSIS")
169+
set(CPACK_NSIS_PACKAGE_NAME "SimpleEngine")
170+
set(CPACK_NSIS_DISPLAY_NAME "SimpleEngine")
171+
set(CPACK_NSIS_HELP_LINK "https://github.com/yourusername/SimpleEngine")
172+
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/yourusername/SimpleEngine")
173+
set(CPACK_NSIS_CONTACT "your.email@example.com")
174+
set(CPACK_NSIS_MODIFY_PATH ON)
175+
elseif(APPLE)
176+
set(CPACK_GENERATOR "ZIP;DragNDrop")
177+
set(CPACK_DMG_VOLUME_NAME "SimpleEngine")
178+
set(CPACK_DMG_FORMAT "UDBZ")
179+
else()
180+
set(CPACK_GENERATOR "ZIP;DEB")
181+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Your Name <your.email@example.com>")
182+
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
183+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libvulkan1, libglfw3, libglm-dev, libktx-dev")
184+
endif()
185+
186+
# Include binary and resource directories in the package
187+
install(TARGETS SimpleEngine DESTINATION bin)
188+
if(SLANGC_EXECUTABLE)
189+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders DESTINATION share/SimpleEngine)
190+
endif()
191+
192+
# Install models and textures if they exist
193+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/models)
194+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/models DESTINATION share/SimpleEngine)
195+
endif()
196+
197+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/textures)
198+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/textures DESTINATION share/SimpleEngine)
199+
endif()
200+
201+
# Install README if it exists
202+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
203+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION share/SimpleEngine)
204+
endif()

0 commit comments

Comments
 (0)