3.4 KiB
3.4 KiB
Game Skeleton
本文档记录当前游戏骨架如何优先复用 Frostbite2D 引擎能力。目标是让游戏层只负责游戏语义,不重复实现引擎已经提供的资源、归档、音频、存档、场景和渲染基础设施。
当前接入状态
Application 基础服务
由引擎 Application::init() 负责:
Asset工作目录和资源路径解析。SaveSystem初始化。- SDL video/events/controller 初始化。
- Window / Renderer / Camera 初始化。
- PixelArt2D 渲染风格和虚拟分辨率。
TaskSystem初始化。
由引擎 Application::shutdown() 负责:
SceneManager清理。Renderer清理。AudioSystem清理。NpkArchive/PvfArchive/SoundPackArchive清理。- 平台资源清理。
GameServices
游戏层新增 GameServices,只做游戏项目需要的引擎服务接入和状态记录:
- 初始化
AudioSystem。 - 探测并打开可选
Script.pvf。 - 初始化
NpkArchive。 - 初始化
SoundPackArchive。 - 探测并加载可选
AudioDatabase。 - 记录
SaveSystem是否已由引擎初始化。
这些服务是可选能力。缺少 Script.pvf、ImagePacks2、SoundPacks 或 audio.xml 时,游戏仍然使用当前 PNG/白盒 fallback 启动。
地图资源入口
新增 StageMapResource 和 StageMapLoader:
LoadStageMapResource("map/stage_01.map")
LoadStageMap("map/stage_01.map")
读取优先级:
Asset普通文本资源:map/stage_01.mapAssetfallback:assets/map/stage_01.mapPvfArchive二进制脚本:map/stage_01.mapPvfArchive文本内容:map/stage_01.map
当前状态:
game/assets/map/stage_01.map已接管第一关主数据。StageMapLoader会把.map文本解析成LevelDefinition。- 已迁移世界尺寸、玩家出生点、相机边界、碰撞平台、视觉层、props、battle zone 和 spawn point。
CreateWhiteboxLevel()优先读取.map,读取或解析失败时才使用 C++ 白盒 fallback。- Windows 和 Switch 构建会把
game/assets/*复制到产物assets/,保证运行时assets/map/stage_01.map路径可用。
.map 当前支持的命令:
map <id>
world <width> <height>
camera <x> <y> <width> <height>
player_spawn <x> <y>
collision <x> <y> <width> <height>
layer <id> <BackgroundFar|BackgroundMid|LevelVisual|PropsBack|PropsFront> <parallax>
rect <x> <y> <width> <height> <r> <g> <b> <a>
rect_sprite <x> <y> <width> <height> <r> <g> <b> <a> <texture>
rect_sprite_src <x> <y> <width> <height> <r> <g> <b> <a> <texture> <sx> <sy> <sw> <sh>
endlayer
battle_zone <id> <trigger_x> <trigger_y> <trigger_w> <trigger_h> <camera_x> <camera_y> <camera_w> <camera_h>
spawn <id> <x> <y>
endbattle_zone
仍待迁移的能力
- 玩家动画:从手写 spritesheet 帧切换迁移到引擎
Animation/ PVF ANI。 - 场景视觉资源:如果素材进入 NPK,迁移到
NpkArchive/Sprite::createFromNpk。 - 音频:使用
AudioSystem、Sound、Music、AudioDatabase。 - 地图:后续可把
.map扩展为工具导出格式或 PVF 脚本格式,当前 C++ 地图只作为 fallback。 - 输入配置:通过
Asset或 PVF 读取InputConfig。
原则
- 优先使用引擎能力。
- 游戏层只做数据转换和玩法语义。
- 外部资源统一走
Asset/PvfArchive。 - C++ 白盒数据只保留为 fallback。