- **Visual Effects**: Upgraded line clear particles to use the game's block texture instead of simple circles, matching the reference web game's aesthetic. - **Particle Physics**: Tuned particle velocity, gravity, and fade rates for a more dynamic explosion effect. - **Rendering Integration**: Updated [main.cpp](cci:7://file:///d:/Sites/Work/tetris/src/main.cpp:0:0-0:0) and `GameRenderer` to pass the block texture to the effect system and correctly trigger animations upon line completion. - **Menu UI**: Fixed [MenuState](cci:1://file:///d:/Sites/Work/tetris/src/states/MenuState.cpp:19:0-19:55) layout calculations to use fixed logical dimensions (1200x1000), ensuring consistent centering and alignment of the logo, buttons, and settings icon across different window sizes. - **Code Cleanup**: Refactored `PlayingState` to delegate effect triggering to the rendering layer where correct screen coordinates are available.
173 lines
6.1 KiB
CMake
173 lines
6.1 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
|
|
# Integrate vcpkg toolchain if available
|
|
if(DEFINED ENV{VCPKG_ROOT})
|
|
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
|
|
elseif(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
|
|
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
|
|
elseif(EXISTS "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake")
|
|
set(CMAKE_TOOLCHAIN_FILE "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
|
|
endif()
|
|
|
|
# The toolchain file must be set before calling project()
|
|
if(DEFINED CMAKE_TOOLCHAIN_FILE)
|
|
message(STATUS "Using vcpkg toolchain: ${CMAKE_TOOLCHAIN_FILE}")
|
|
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "" FORCE)
|
|
endif()
|
|
|
|
project(tetris_sdl3 LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Find SDL3 (via package manager or a local build)
|
|
# vcpkg example: vcpkg install sdl3
|
|
# Homebrew: brew install sdl3
|
|
find_package(SDL3 CONFIG REQUIRED)
|
|
find_package(SDL3_ttf CONFIG REQUIRED)
|
|
|
|
add_executable(tetris
|
|
src/main.cpp
|
|
src/gameplay/core/Game.cpp
|
|
src/core/GravityManager.cpp
|
|
src/core/state/StateManager.cpp
|
|
# New core architecture classes
|
|
src/core/application/ApplicationManager.cpp
|
|
src/core/input/InputManager.cpp
|
|
src/core/assets/AssetManager.cpp
|
|
src/core/GlobalState.cpp
|
|
src/graphics/renderers/RenderManager.cpp
|
|
src/persistence/Scores.cpp
|
|
src/graphics/effects/Starfield.cpp
|
|
src/graphics/effects/Starfield3D.cpp
|
|
src/graphics/ui/Font.cpp
|
|
src/graphics/renderers/GameRenderer.cpp
|
|
src/audio/Audio.cpp
|
|
src/gameplay/effects/LineEffect.cpp
|
|
src/audio/SoundEffect.cpp
|
|
# State implementations (new)
|
|
src/states/LoadingState.cpp
|
|
src/states/MenuState.cpp
|
|
src/states/LevelSelectorState.cpp
|
|
src/states/PlayingState.cpp
|
|
)
|
|
|
|
if (WIN32)
|
|
# Embed the application icon into the executable
|
|
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
|
|
target_sources(tetris PRIVATE src/app_icon.rc)
|
|
endif()
|
|
|
|
if (WIN32)
|
|
# Ensure favicon.ico is available in the build directory for the resource compiler
|
|
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
|
|
set(FAVICON_DEST "${CMAKE_BINARY_DIR}/favicon.ico")
|
|
if(EXISTS ${FAVICON_SRC})
|
|
add_custom_command(
|
|
OUTPUT ${FAVICON_DEST}
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} ${FAVICON_DEST}
|
|
DEPENDS ${FAVICON_SRC}
|
|
COMMENT "Copy favicon.ico to build dir for resource compilation"
|
|
)
|
|
add_custom_target(copy_favicon ALL DEPENDS ${FAVICON_DEST})
|
|
add_dependencies(tetris copy_favicon)
|
|
else()
|
|
message(WARNING "Favicon not found at ${FAVICON_SRC}; app icon may not compile")
|
|
endif()
|
|
|
|
# Also copy favicon into the runtime output folder (same dir as exe)
|
|
add_custom_command(TARGET tetris POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} $<TARGET_FILE_DIR:tetris>/favicon.ico
|
|
COMMENT "Copy favicon.ico next to executable"
|
|
)
|
|
endif()
|
|
|
|
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf)
|
|
|
|
if (WIN32)
|
|
target_link_libraries(tetris PRIVATE mfplat mfreadwrite mfuuid)
|
|
endif()
|
|
|
|
# Include production build configuration
|
|
include(cmake/ProductionBuild.cmake)
|
|
|
|
# Enable CTest so `add_test` registers tests for `ctest`
|
|
enable_testing()
|
|
|
|
# Unit tests (simple runner)
|
|
find_package(Catch2 CONFIG REQUIRED)
|
|
add_executable(tetris_tests
|
|
tests/GravityTests.cpp
|
|
src/core/GravityManager.cpp
|
|
)
|
|
target_include_directories(tetris_tests PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
|
target_link_libraries(tetris_tests PRIVATE Catch2::Catch2WithMain)
|
|
add_test(NAME GravityTests COMMAND tetris_tests)
|
|
|
|
if(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-windows/include")
|
|
target_include_directories(tetris_tests PRIVATE "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-windows/include")
|
|
endif()
|
|
|
|
# Add new src subfolders to include path so old #includes continue to work
|
|
target_include_directories(tetris PRIVATE
|
|
${CMAKE_SOURCE_DIR}/src
|
|
${CMAKE_SOURCE_DIR}/src/audio
|
|
${CMAKE_SOURCE_DIR}/src/gameplay
|
|
${CMAKE_SOURCE_DIR}/src/graphics
|
|
${CMAKE_SOURCE_DIR}/src/persistence
|
|
${CMAKE_SOURCE_DIR}/src/core
|
|
${CMAKE_SOURCE_DIR}/src/states
|
|
)
|
|
|
|
# Experimental refactored version (for testing new architecture)
|
|
add_executable(tetris_refactored
|
|
src/main_new.cpp
|
|
src/gameplay/core/Game.cpp
|
|
src/core/GravityManager.cpp
|
|
src/core/state/StateManager.cpp
|
|
# New core architecture classes
|
|
src/core/application/ApplicationManager.cpp
|
|
src/core/input/InputManager.cpp
|
|
src/core/assets/AssetManager.cpp
|
|
src/core/GlobalState.cpp
|
|
src/graphics/renderers/RenderManager.cpp
|
|
src/persistence/Scores.cpp
|
|
src/graphics/effects/Starfield.cpp
|
|
src/graphics/effects/Starfield3D.cpp
|
|
src/graphics/ui/Font.cpp
|
|
src/graphics/renderers/GameRenderer.cpp
|
|
src/audio/Audio.cpp
|
|
src/gameplay/effects/LineEffect.cpp
|
|
src/audio/SoundEffect.cpp
|
|
# State implementations
|
|
src/states/LoadingState.cpp
|
|
src/states/MenuState.cpp
|
|
src/states/LevelSelectorState.cpp
|
|
src/states/PlayingState.cpp
|
|
)
|
|
|
|
if (WIN32)
|
|
# Embed the application icon into the refactored executable too
|
|
target_sources(tetris_refactored PRIVATE src/app_icon.rc)
|
|
add_dependencies(tetris_refactored copy_favicon)
|
|
add_custom_command(TARGET tetris_refactored POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} $<TARGET_FILE_DIR:tetris_refactored>/favicon.ico
|
|
COMMENT "Copy favicon.ico next to refactored executable"
|
|
)
|
|
endif()
|
|
|
|
target_link_libraries(tetris_refactored PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf)
|
|
|
|
if (WIN32)
|
|
target_link_libraries(tetris_refactored PRIVATE mfplat mfreadwrite mfuuid)
|
|
endif()
|
|
|
|
target_include_directories(tetris_refactored PRIVATE
|
|
${CMAKE_SOURCE_DIR}/src
|
|
${CMAKE_SOURCE_DIR}/src/audio
|
|
${CMAKE_SOURCE_DIR}/src/gameplay
|
|
${CMAKE_SOURCE_DIR}/src/graphics
|
|
${CMAKE_SOURCE_DIR}/src/persistence
|
|
${CMAKE_SOURCE_DIR}/src/core
|
|
${CMAKE_SOURCE_DIR}/src/states
|
|
) |