Files
Workspace/Assets/Demos/Demo2/Docs/ARCHITECTURE.md
T
2026-08-18 02:03:34 +08:00

33 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 架构与确定性契约
## 版本边界
- Unity2022.3.62f3
- Entities1.0.11
- 模拟协议:1
- 固定频率:20 Hz
- 地图:32 × 20
Demo2 创建独立 `World`,不接管默认 World,也不依赖 Entities Graphics。机器与传送带使用池化 SpriteRenderer 代理;物料状态只存在于 ECS,并通过 `Graphics.DrawMeshInstanced` 批量绘制。
界面使用运行时 UI Toolkit`UI/Demo2.uxml` 定义结构,`UI/Demo2.uss` 定义 1920×1080 基准下的响应式布局,`UIDocument` 通过 `PanelSettings` 适配 16:9、16:10、4:3 和安全区。工厂中央的 UI Toolkit 输入面只拦截网格区域,侧栏和工具栏不会把指针事件穿透给工厂。
## 固定系统顺序
1. `Demo2BuildCommandSystem`:复制指令缓冲后处理建造/拆除和幂等令牌。
2. `Demo2ExtractionSystem`:采集器与能量站按整数 Tick 产出。
3. `Demo2ConveyorSystem`:物料以千分位子格进度移动。
4. `Demo2InputAllocationSystem`:把同格物料送入机器并计算物流条件。
5. `Demo2ProcessingSystem`:按整数加工时间消耗输入。
6. `Demo2OutputSystem`:创建批量物料实体。
7. `Demo2RuleTriggerSystem`:防御结算时按槽位顺序解释规则指令。
8. `Demo2TurretLoadingSystem`:按稳定 ID 选定装填目标,不依赖实体迭代顺序。
9. `Demo2CycleStatisticsSystem`:提交周期统计并递增模拟 Tick。
10. `Demo2StateHashSystem`:按稳定 ID 排序后计算 FNV-1a 风格 64 位状态哈希。
模拟不使用浮点数保存传送、产量、倍率、加工时间或随机状态。倍率以 1000 为 1.0;长整型运算使用饱和加法/乘法。状态哈希包含经济、核心、周期统计、机器、物料和炮塔弹药。快照恢复后继续 Tick 必须得到相同哈希。
## 性能验收
`Demo2EcsTests.StressTick_HandlesTenThousandItemsAndOneThousandMachines` 创建至少 10,000 个物料和 1,000 个机器实体,记录单 Tick 时间与当前线程托管分配。`SameSeedAndCommands_RemainIdenticalForTenThousandTicks` 对两个同种子 World 连续运行 10,000 Tick 并比较最终哈希。