mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Added DebugInfo
This commit is contained in:
52
src/core/DebugManager.cpp
Normal file
52
src/core/DebugManager.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "DebugManager.h"
|
||||
#include "Time.h"
|
||||
#include <iostream>
|
||||
DebugManager::DebugManager(
|
||||
const SDL_Renderer* renderer,
|
||||
const SDL_Window* window,
|
||||
//const InputState& inputState,
|
||||
UIRenderer* uiRenderer
|
||||
):
|
||||
m_renderer(renderer),
|
||||
m_window(window),
|
||||
//m_inputState(inputState),
|
||||
m_uiRenderer(uiRenderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DebugManager::~DebugManager() {
|
||||
|
||||
}
|
||||
|
||||
void DebugManager::initialize() {
|
||||
m_debugOverlay = std::make_unique<DebugOverlay>(m_debugData);
|
||||
m_debugOverlay->initialize();
|
||||
m_isDebugInfoVisible = true;
|
||||
}
|
||||
|
||||
void DebugManager::updateMousePos(int logicalX, int logicalY, const InputState& inputState) {
|
||||
m_debugData.mousePosition = {
|
||||
static_cast<int>(inputState.mouseCurrentPosition.first),
|
||||
static_cast<int>(inputState.mouseCurrentPosition.second)
|
||||
};
|
||||
m_debugData.mouseLogicalPostion = {logicalX, logicalY};
|
||||
|
||||
}
|
||||
|
||||
void DebugManager::updateDebugInfo() {
|
||||
m_debugData.currentFPS = static_cast<int>(Time::fps());
|
||||
//std::cout << "FPS: " << m_debugData.currentFPS << std::endl;
|
||||
|
||||
m_debugOverlay->updateDebugInfo();
|
||||
|
||||
}
|
||||
|
||||
void DebugManager::showDebugInfo() {
|
||||
//m_isDebugInfoVisible = !m_isDebugInfoVisible;
|
||||
if (m_isDebugInfoVisible) {
|
||||
|
||||
m_uiRenderer->renderUI(m_debugOverlay->getUIRenderData());
|
||||
}
|
||||
|
||||
}
|
||||
35
src/core/DebugManager.h
Normal file
35
src/core/DebugManager.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "ui/managers/debug/DebugOverlay.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "input/InputState.h"
|
||||
#include "graphics/ui/UIRenderer.h"
|
||||
|
||||
class DebugManager {
|
||||
public:
|
||||
DebugManager(
|
||||
const SDL_Renderer* renderer,
|
||||
const SDL_Window* window,
|
||||
//const InputState& inputState,
|
||||
UIRenderer* uiRenderer
|
||||
);
|
||||
~DebugManager();
|
||||
|
||||
void initialize();
|
||||
//void shutdown();
|
||||
|
||||
void showDebugInfo();
|
||||
|
||||
void updateMousePos(int logicalX, int logicalY, const InputState& inputState);
|
||||
void updateDebugInfo();
|
||||
|
||||
private:
|
||||
std::unique_ptr<DebugOverlay> m_debugOverlay;
|
||||
DebugData m_debugData;
|
||||
const SDL_Renderer* m_renderer = nullptr;
|
||||
const SDL_Window* m_window = nullptr;
|
||||
//const InputState& m_inputState;
|
||||
bool m_isDebugInfoVisible = false;
|
||||
|
||||
UIRenderer* m_uiRenderer = nullptr;
|
||||
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "GameApplication.h"
|
||||
#include "utils/Tools.h"
|
||||
#include "Time.h"
|
||||
GameApplication::GameApplication() {
|
||||
|
||||
}
|
||||
@@ -21,6 +22,7 @@ bool GameApplication::initialize() {
|
||||
if (!ConfigLoader::load("assets/config.json", m_config)) {
|
||||
SDL_Log("无法加载json");
|
||||
}
|
||||
Time::init();
|
||||
// 输入管理
|
||||
m_inputManager = std::make_unique<InputManager>();
|
||||
// 窗口管理
|
||||
@@ -36,7 +38,14 @@ bool GameApplication::initialize() {
|
||||
m_textRenderer = std::make_unique<TextRenderer>(m_windowManager->GetRenderer(), m_fontManager.get(), m_windowManager->getViewport());
|
||||
|
||||
m_uiRenderer = std:: make_unique<UIRenderer>(m_windowManager->GetRenderer(), m_textRenderer.get());
|
||||
|
||||
// 调试管理
|
||||
m_debugManager = std::make_unique<DebugManager>(
|
||||
m_windowManager->GetRenderer(),
|
||||
m_windowManager->GetWindow(),
|
||||
//m_inputManager->GetInputState(),
|
||||
m_uiRenderer.get()
|
||||
);
|
||||
m_debugManager->initialize();
|
||||
// 场景管理,传入窗口句柄以便 SceneManager 能获取窗口尺寸
|
||||
m_sceneManager = std::make_unique<SceneManager>(m_windowManager->GetRenderer(), m_uiRenderer.get(), m_windowManager->GetWindow());
|
||||
if (!m_sceneManager->initialize()) {
|
||||
@@ -56,8 +65,11 @@ SDL_AppResult GameApplication::handleInputEvent(SDL_Event* event) {
|
||||
m_sceneManager->handleClickCurrent(pos);
|
||||
}
|
||||
auto pos = Tools::physicalToLogical(input.mouseCurrentPosition.first, input.mouseCurrentPosition.second, m_windowManager->getViewport());
|
||||
|
||||
m_debugManager->updateMousePos(pos.first, pos.second, input);
|
||||
m_sceneManager->handleMousePosition(pos);
|
||||
m_windowManager->setFullscreen(input.isFullscreen);
|
||||
|
||||
// 改变窗口时清理旧的缓存
|
||||
if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
||||
m_windowManager->onWindowResize();
|
||||
@@ -69,16 +81,17 @@ SDL_AppResult GameApplication::handleInputEvent(SDL_Event* event) {
|
||||
}
|
||||
|
||||
void GameApplication::run() {
|
||||
|
||||
Time::update();
|
||||
m_sceneManager->updateCurrent();
|
||||
|
||||
m_debugManager->updateDebugInfo();
|
||||
m_windowManager->Clear();
|
||||
m_windowManager->beginWorld();
|
||||
m_sceneManager->renderWorld();
|
||||
m_windowManager->endWorld();
|
||||
|
||||
|
||||
m_windowManager->beginUI();
|
||||
m_sceneManager->renderUI();
|
||||
m_sceneManager->renderUI();
|
||||
m_debugManager->showDebugInfo();
|
||||
m_windowManager->endUI();
|
||||
|
||||
m_windowManager->Present();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "utils/ConfigLoader.h"
|
||||
#include "graphics/font/TextRenderer.h"
|
||||
#include "graphics/font/FontManager.h"
|
||||
|
||||
#include "core/DebugManager.h"
|
||||
|
||||
class GameApplication {
|
||||
private:
|
||||
@@ -20,7 +20,7 @@ private:
|
||||
std::unique_ptr<FontManager> m_fontManager;
|
||||
std::unique_ptr<TextRenderer> m_textRenderer;
|
||||
std::unique_ptr<UIRenderer> m_uiRenderer;
|
||||
|
||||
std::unique_ptr<DebugManager> m_debugManager;
|
||||
Config m_config;
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user