This commit is contained in:
HP
2026-06-07 14:38:42 +08:00
parent 0defa04eef
commit 964a11a215
31 changed files with 1308 additions and 683 deletions
+31 -1
View File
@@ -11,7 +11,7 @@ src/
Core/ # FrameBuffer、DepthBuffer、Renderer、Timer
Draw2D/ # Core::DrawContext
Math/ # Vector、Matrix、MathUtil
Platform/ # IDisplay、SDLDisplay、FBDisplay、ITimeSource
Platform/ # 显示、时间、音频、按键等平台接口和后端
Rasterizer/ # 线段和三角形光栅化
RenderData/ # Color、Image、Triangle、Tilemap 等数据结构
Scene/ # Camera、Transform、Mesh、Model
@@ -58,6 +58,7 @@ Core 只提供底层能力:
- 提供基础数学、颜色、图片、三角形、tilemap 等数据结构。
- 封装 SDL2 / framebuffer 显示提交。
- 提供独立时间源 `Platform::ITimeSource`。
- 提供音频输入、音频输出和按键输入的抽象接口。
- 使用离线转换后的运行时资源,不在热路径解码 PNG/TTF。
Core 不做:
@@ -112,6 +113,8 @@ ctx.present(display);
## 显示后端
平台层采用“抽象接口 + 多套后端实现”的模式。
显示层通过 `Platform::IDisplay` 抽象:
```text
@@ -120,6 +123,33 @@ Platform::IDisplay
FBDisplay # Linux /dev/fb0 后端
```
音频输入通过 `Platform::IAudioInput` 抽象:
```text
Platform::IAudioInput
SdlAudioInput # PC / SDL2 麦克风后端
AlsaAudioInput # Linux ALSA 录音后端
```
音频输出通过 `Platform::IAudioOutput` 抽象:
```text
Platform::IAudioOutput
SdlAudioOutput # PC / SDL2 扬声器后端
AlsaAudioOutput # Linux ALSA 播放后端
```
按键输入通过 `Platform::IButtonInput` 抽象:
```text
Platform::IButtonInput
SdlKeyboardButtonInput # PC / SDL2 键盘后端,默认空格键
EvdevButtonInput # Linux evdev 按键后端
```
游戏代码只能依赖这些 `I*` 接口。ALSA、evdev、SDL2、`/dev/fb0` 等平台细节只能出现在 `src/Core/Platform` 或明确的平台适配代码中。
如果只需要当前构建平台的默认后端,可以使用 `Platform::DefaultAudioInput`、`Platform::DefaultAudioOutput` 和 `Platform::DefaultButtonInput`。
CMake 通过 `USE_FRAMEBUFFER` 选择实现:
```cmake