summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Kernel/WorldSave.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-21 14:55:37 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-21 14:55:37 +0800
commitab19df0ebad8da972cd30f89f7cfd8ef38b8c0ae (patch)
treebaa466d7afd04517d31cb3a1ab0fee04da0bcc5e /src/LivingVillage.Kernel/WorldSave.fs
parent655c22afe53b740e795f66c4da57714985ddccec (diff)
downloadliving-village-ab19df0ebad8da972cd30f89f7cfd8ef38b8c0ae.tar.gz
feat(kernel): 地图边界参数化与存档 v2
Sim 地图边界由常量 52 改为可配置(configureBounds,默认 64x48 = 与全部基线一致);Sim.step 裁剪、initialWorld 中心出生时点按当前边界读取;WorldSave 升级 V2 头携带 width/height 两字段,V1 旧存档照常读入并自动回退到 64x48;回归:512x384 边界裁剪/初界转正/双份存档往返/案例 v1 档兼容读。修复前一段中报错已修正的测试代码(Ensure saved-file timeouts)。
Diffstat (limited to 'src/LivingVillage.Kernel/WorldSave.fs')
-rw-r--r--src/LivingVillage.Kernel/WorldSave.fs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/LivingVillage.Kernel/WorldSave.fs b/src/LivingVillage.Kernel/WorldSave.fs
index 8a47c7d..e68a45f 100644
--- a/src/LivingVillage.Kernel/WorldSave.fs
+++ b/src/LivingVillage.Kernel/WorldSave.fs
@@ -469,7 +469,9 @@ module WorldSave =
let save (world: World) : string =
let tokens = ResizeArray<string>()
- add tokens formatVersion
+ add tokens "LV_WORLD_SAVE_V2"
+ addInt tokens mapWidthTiles
+ addInt tokens mapHeightTiles
addInt64 tokens world.Tick
addFloat tokens world.Time
addUInt64 tokens world.Rng.State
@@ -492,8 +494,12 @@ module WorldSave =
try
let tokens = text.Split([| '|' |], StringSplitOptions.None)
let reader = TokenReader(tokens)
- if reader.Take("format") <> formatVersion then
- invalid "unsupported save format"
+ match reader.Take("format") with
+ | "LV_WORLD_SAVE_V2" ->
+ configureBounds (readInt reader "bounds.w") (readInt reader "bounds.h")
+ | v1 when v1 = formatVersion ->
+ configureBounds 64 48
+ | _ -> invalid "unsupported save format"
let tick = readInt64 reader "tick"
let time = readFloat reader "time"
let rng = { State = readUInt64 reader "rng" }