summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Headless/PerformanceProbe.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Headless/PerformanceProbe.fs')
-rw-r--r--src/LivingVillage.Headless/PerformanceProbe.fs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/LivingVillage.Headless/PerformanceProbe.fs b/src/LivingVillage.Headless/PerformanceProbe.fs
index 4641fb4..99d78ab 100644
--- a/src/LivingVillage.Headless/PerformanceProbe.fs
+++ b/src/LivingVillage.Headless/PerformanceProbe.fs
@@ -120,13 +120,40 @@ module PerformanceProbe =
///
/// `WorldSave.save` 提供完整且有序的快照序列化,SHA-256 只压缩输出长度,
/// 不参与模拟和性能计时;若存档格式改变,摘要也应随之改变并触发回归。
+ /// Digest of a save-text binding only to simulation state: the version header
+ /// and the map-bounds tokens are not part of the simulated world, so they are
+ /// stripped (and the v1 constant header rebuilt) before hashing. V1/V2 saves of
+ /// the same world therefore share one digest, and the legacy baseline digest
+ /// (hash over "LV_WORLD_SAVE_V1|<body>") is preserved byte-for-byte.
+ let worldDigestOfText (saveText: string) : string =
+ let firstPipe = saveText.IndexOf('|')
+ if firstPipe <= 0 then
+ use sha = SHA256.Create()
+ (saveText: string)
+ |> Encoding.UTF8.GetBytes
+ |> sha.ComputeHash
+ |> Convert.ToHexString
+ else
+ let version = saveText.Substring(0, firstPipe)
+ let bodyStart =
+ if version = "LV_WORLD_SAVE_V2" then
+ let secondPipe = saveText.IndexOf('|', firstPipe + 1)
+ if secondPipe < 0 then saveText.Length
+ else
+ let thirdPipe = saveText.IndexOf('|', secondPipe + 1)
+ if thirdPipe < 0 then saveText.Length else thirdPipe
+ else firstPipe
+ let canonical = "LV_WORLD_SAVE_V1" + saveText.Substring(bodyStart)
+ use sha = SHA256.Create()
+ canonical
+ |> Encoding.UTF8.GetBytes
+ |> sha.ComputeHash
+ |> Convert.ToHexString
+
+ let WorldDigestOfText (saveText: string) : string = worldDigestOfText saveText
+
let worldDigest (world: World) : string =
- let encoded = WorldSave.save world
- use sha = SHA256.Create()
- encoded
- |> Encoding.UTF8.GetBytes
- |> sha.ComputeHash
- |> Convert.ToHexString
+ worldDigestOfText (WorldSave.save world)
/// 对一个固定配置执行预热和单次测量。
///