From 1a1e783e944d4066741e93ba53cfe2ef49f0106d Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sat, 6 Dec 2025 18:40:16 +0800 Subject: [PATCH] Use GameApplication to cnotrol game --- CMakeLists.txt | 7 ++++++- src/core/GameApplication.cpp | 27 +++++++++++++++++++++++---- src/core/GameApplication.h | 8 +++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 554373a..1506115 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,18 @@ add_subdirectory(third_party/SDL3) set(SOURCE_FILES src/main.cpp src/core/GameApplication.cpp + src/core/WindowManager.cpp src/game/GameSession.cpp src/game/Board.cpp src/game/Piece.cpp src/game/Rule.cpp src/game/ComponentManager.cpp src/input/InputManager.cpp - src/core/WindowManager.cpp + src/scenes/base/SceneManager.cpp + src/scenes/gameplay/GameScene.cpp + src/graphics/GameRenderer.cpp + src/graphics/CoordinateConverter.cpp + ) # 添加可执行文件 diff --git a/src/core/GameApplication.cpp b/src/core/GameApplication.cpp index f95797a..1f88584 100644 --- a/src/core/GameApplication.cpp +++ b/src/core/GameApplication.cpp @@ -1,16 +1,35 @@ #include "GameApplication.h" GameApplication::GameApplication() { - m_gameSession = std::make_unique(); - m_inputManager = std::make_unique(); + +} + +GameApplication::~GameApplication() { } bool GameApplication::initialize() { - m_gameSession->initialize(); + m_inputManager = std::make_unique(); + m_windowManager = std::make_unique(); + + m_windowManager->Initialize(m_config); + m_sceneManager = std::make_unique(m_windowManager->GetRenderer()); + return true; } SDL_AppResult GameApplication::handleInputEvent(SDL_Event* event) { - + auto result = m_inputManager->handleInputEvent(event); + // 只有当事件是鼠标左键按下时,才触发点击逻辑 + if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN && + event->button.button == SDL_BUTTON_LEFT) { + InputState input = m_inputManager->GetInputState(); + m_sceneManager->handleClickCurrent(input.mouseCilckOn); + } + return result; +} + +void GameApplication::run() { + m_sceneManager->updateCurrent(); + m_sceneManager->renderCurrent(); } \ No newline at end of file diff --git a/src/core/GameApplication.h b/src/core/GameApplication.h index 58953bf..c11bd81 100644 --- a/src/core/GameApplication.h +++ b/src/core/GameApplication.h @@ -1,7 +1,8 @@ #pragma once -#include "game/GameSession.h" +#include "WindowManager.h" +#include "scenes/base/SceneManager.h" #include "input/InputManager.h" #include "utils/Config.h" @@ -9,8 +10,9 @@ class GameApplication { private: - std::unique_ptr m_gameSession; - std::unique_ptr m_renderer; + + std::unique_ptr m_windowManager; + std::unique_ptr m_sceneManager; std::unique_ptr m_inputManager; GameConfig m_config;