mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Use GameApplication to cnotrol game
This commit is contained in:
@@ -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
|
||||
|
||||
)
|
||||
|
||||
# 添加可执行文件
|
||||
|
||||
@@ -1,16 +1,35 @@
|
||||
#include "GameApplication.h"
|
||||
|
||||
GameApplication::GameApplication() {
|
||||
m_gameSession = std::make_unique<GameSession>();
|
||||
m_inputManager = std::make_unique<InputManager>();
|
||||
|
||||
}
|
||||
|
||||
GameApplication::~GameApplication() {
|
||||
|
||||
}
|
||||
|
||||
bool GameApplication::initialize() {
|
||||
m_gameSession->initialize();
|
||||
m_inputManager = std::make_unique<InputManager>();
|
||||
m_windowManager = std::make_unique<WindowManager>();
|
||||
|
||||
m_windowManager->Initialize(m_config);
|
||||
m_sceneManager = std::make_unique<SceneManager>(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();
|
||||
}
|
||||
@@ -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<GameSession> m_gameSession;
|
||||
std::unique_ptr<Renderer> m_renderer;
|
||||
|
||||
std::unique_ptr<WindowManager> m_windowManager;
|
||||
std::unique_ptr<SceneManager> m_sceneManager;
|
||||
std::unique_ptr<InputManager> m_inputManager;
|
||||
GameConfig m_config;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user