refactor main game loop
This commit is contained in:
@ -31,6 +31,7 @@ find_package(nlohmann_json CONFIG REQUIRED)
|
|||||||
|
|
||||||
set(TETRIS_SOURCES
|
set(TETRIS_SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/app/TetrisApp.cpp
|
||||||
src/gameplay/core/Game.cpp
|
src/gameplay/core/Game.cpp
|
||||||
src/core/GravityManager.cpp
|
src/core/GravityManager.cpp
|
||||||
src/core/state/StateManager.cpp
|
src/core/state/StateManager.cpp
|
||||||
@ -67,6 +68,7 @@ set(TETRIS_SOURCES
|
|||||||
src/states/PlayingState.cpp
|
src/states/PlayingState.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(APP_ICON "${CMAKE_SOURCE_DIR}/assets/favicon/AppIcon.icns")
|
set(APP_ICON "${CMAKE_SOURCE_DIR}/assets/favicon/AppIcon.icns")
|
||||||
if(EXISTS "${APP_ICON}")
|
if(EXISTS "${APP_ICON}")
|
||||||
|
|||||||
1720
src/app/TetrisApp.cpp
Normal file
1720
src/app/TetrisApp.cpp
Normal file
File diff suppressed because it is too large
Load Diff
29
src/app/TetrisApp.h
Normal file
29
src/app/TetrisApp.h
Normal 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_;
|
||||||
|
};
|
||||||
@ -14,7 +14,7 @@ namespace Config {
|
|||||||
namespace Window {
|
namespace Window {
|
||||||
constexpr int DEFAULT_WIDTH = 1200;
|
constexpr int DEFAULT_WIDTH = 1200;
|
||||||
constexpr int DEFAULT_HEIGHT = 1000;
|
constexpr int DEFAULT_HEIGHT = 1000;
|
||||||
constexpr const char* DEFAULT_TITLE = "Tetris (SDL3)";
|
constexpr const char* DEFAULT_TITLE = "SpaceTris (SDL3)";
|
||||||
constexpr bool DEFAULT_VSYNC = true;
|
constexpr bool DEFAULT_VSYNC = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1954
src/main.cpp
1954
src/main.cpp
File diff suppressed because it is too large
Load Diff
@ -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 textCol{200, 210, 230, 255};
|
||||||
const SDL_Color keyCol{255, 255, 255, 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, "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;
|
f->draw(renderer, x, y, "GAMEPLAY", 0.85f, SDL_Color{180,200,255,255}); y += lineGap;
|
||||||
|
|||||||
Reference in New Issue
Block a user