refactor main game loop

This commit is contained in:
2025-12-19 20:07:48 +01:00
parent 783c12790d
commit 38dbc17ace
6 changed files with 1761 additions and 1948 deletions

View File

@ -31,6 +31,7 @@ find_package(nlohmann_json CONFIG REQUIRED)
set(TETRIS_SOURCES
src/main.cpp
src/app/TetrisApp.cpp
src/gameplay/core/Game.cpp
src/core/GravityManager.cpp
src/core/state/StateManager.cpp
@ -67,6 +68,7 @@ set(TETRIS_SOURCES
src/states/PlayingState.cpp
)
if(APPLE)
set(APP_ICON "${CMAKE_SOURCE_DIR}/assets/favicon/AppIcon.icns")
if(EXISTS "${APP_ICON}")

1720
src/app/TetrisApp.cpp Normal file

File diff suppressed because it is too large Load Diff

29
src/app/TetrisApp.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include <memory>
// TetrisApp is the top-level application orchestrator.
//
// Responsibilities:
// - SDL/TTF init + shutdown
// - Asset/music loading + loading screen
// - Main loop + state transitions
//
// It uses a PIMPL to keep `TetrisApp.h` light (faster builds) and to avoid leaking
// SDL-heavy includes into every translation unit.
class TetrisApp {
public:
TetrisApp();
~TetrisApp();
TetrisApp(const TetrisApp&) = delete;
TetrisApp& operator=(const TetrisApp&) = delete;
// Runs the application until exit is requested.
// Returns a non-zero exit code on initialization failure.
int run();
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};

View File

@ -14,7 +14,7 @@ namespace Config {
namespace Window {
constexpr int DEFAULT_WIDTH = 1200;
constexpr int DEFAULT_HEIGHT = 1000;
constexpr const char* DEFAULT_TITLE = "Tetris (SDL3)";
constexpr const char* DEFAULT_TITLE = "SpaceTris (SDL3)";
constexpr bool DEFAULT_VSYNC = true;
}

File diff suppressed because it is too large Load Diff

View File

@ -1297,7 +1297,7 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
const SDL_Color textCol{200, 210, 230, 255};
const SDL_Color keyCol{255, 255, 255, 255};
f->draw(renderer, x, y, "SDL3 TETRIS", 1.05f, keyCol); y += lineGap;
f->draw(renderer, x, y, "SDL3 SPACETRIS", 1.05f, keyCol); y += lineGap;
f->draw(renderer, x, y, "C++20 / SDL3 / SDL3_ttf", 0.80f, textCol); y += lineGap + 6.0f;
f->draw(renderer, x, y, "GAMEPLAY", 0.85f, SDL_Color{180,200,255,255}); y += lineGap;