Change GameConfig to WindowConfig

This commit is contained in:
2025-12-23 15:59:42 +08:00
parent 473666f95c
commit 067d35b4e5

View File

@@ -1,8 +1,8 @@
#pragma once
#include <string>
#include<SDL3/SDL.h>
// 统一管理配置
struct GameConfig {
struct WindowConfig {
/*
tileSize: 16x16 每个格子的逻辑大小(像素)
屏幕 = 20 × 11 tiles = 320x176 逻辑分辨率
@@ -15,6 +15,7 @@ struct GameConfig {
bool vsync = true;
int scale = 2;
/*
1280x720 scale 4
1920x1080 scale 6
@@ -46,4 +47,28 @@ namespace UI
constexpr int UI_SMALL_FONT_SIZE = 8;
constexpr int UI_NORMAL_FONT_SIZE = 12;
constexpr int UI_LARGE_FONT_SIZE = 16;
}
// Viewport 描述的是:
// 「当前这一帧,逻辑画面是如何映射到窗口上的」
//
// ⚠️ 这是只读数据,其它系统只能用,不能改
struct Viewport {
// ===== 窗口相关 =====
int windowWidth = 0; // 窗口实际宽度(像素)
int windowHeight = 0; // 窗口实际高度(像素)
// ===== 逻辑分辨率 =====
int logicalWidth = 0; // 游戏内部使用的宽度(如 320
int logicalHeight = 0; // 游戏内部使用的高度(如 180
// ===== 缩放 =====
int scale = 1; // 整数缩放倍数(像素游戏核心)
// ===== 实际渲染区域 =====
// 逻辑画面被放大后,在窗口中的位置和大小
// 用于 SDL_RenderTexture / 输入坐标转换
SDL_FRect dst{};
};