From 23a5241a7d674d636b795d29d793ebcf4b55012d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 13 Jun 2026 07:36:08 +0100 Subject: [PATCH] Remove runtime serializer hash residue --- .../CultCache/CollectionExtensions.cs | 12 +-- .../ServerShared/Narrative/StoryProcessor.cs | 16 +--- Assets/Shaders/Compute/Slime/Slime.cs | 83 ++++++++++++++++--- docs/aetheria-perfect-machine-map.md | 6 +- 4 files changed, 80 insertions(+), 37 deletions(-) diff --git a/Assets/Scripts/ServerShared/CultCache/CollectionExtensions.cs b/Assets/Scripts/ServerShared/CultCache/CollectionExtensions.cs index ebb949302..18e3500fd 100644 --- a/Assets/Scripts/ServerShared/CultCache/CollectionExtensions.cs +++ b/Assets/Scripts/ServerShared/CultCache/CollectionExtensions.cs @@ -1,20 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography; using System.Threading.Tasks; public static class CollectionExtensions { - // https://stackoverflow.com/a/800469 - public static string GetHashSHA1(this byte[] data) - { - using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider()) - { - return string.Concat(sha1.ComputeHash(data).Select(x => x.ToString("X2"))); - } - } - // https://stackoverflow.com/a/3188835 public static T MaxBy(this IEnumerable items, Func selector) { @@ -73,4 +63,4 @@ public static class AsyncAwaitExtensions { await task; } -} \ No newline at end of file +} diff --git a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs b/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs index 21b13a53d..c3f9593d1 100644 --- a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs +++ b/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs @@ -106,20 +106,6 @@ public class StoryProcessor : IZoneResolver, IFactionResolver // If the story has already been read / compiled, return it directly if (_processedStories.ContainsKey(fileName)) return _processedStories[fileName]; - // var compiledFileName = Path.Combine(inkFile.Directory.FullName, $"{fileName}.json"); - // - // // Calculate a hash of the ink file - // var hash = File.ReadAllBytes(inkFile.FullName).GetHashSHA1(); - // - // if (File.Exists(compiledFileName) && // If a compiled version of the ink file exists - // Settings.HashedStoryFiles.ContainsKey(fileName) && // And its hash has been saved - // hash == Settings.HashedStoryFiles[fileName]) // And the saved hash matches the current hash - // { - // // Load the story from the existing compiled JSON representation - // return new Story(File.ReadAllText(compiledFileName)); - // } - // - // Settings.HashedStoryFiles[fileName] = hash; var compiler = new Compiler(File.ReadAllText(inkFile.FullName), new Compiler.Options { countAllVisits = true, @@ -255,4 +241,4 @@ public class StoryProcessor : IZoneResolver, IFactionResolver return contentTags; } -} \ No newline at end of file +} diff --git a/Assets/Shaders/Compute/Slime/Slime.cs b/Assets/Shaders/Compute/Slime/Slime.cs index ffd067938..919854fb9 100644 --- a/Assets/Shaders/Compute/Slime/Slime.cs +++ b/Assets/Shaders/Compute/Slime/Slime.cs @@ -3,7 +3,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using MessagePack; using Unity.Mathematics; using UnityEngine; using UnityEngine.Experimental.Rendering; @@ -50,7 +49,8 @@ public class Slime : MonoBehaviour private int _particleKernel; private int _trailKernel; private int _geometryKernel; - private string _settingsHash; + private bool _settingsInitialized; + private SlimeSettings _currentSettings; private int _spawnBufferSize = 1; private int IndexBufferSize => ParticleCount * 6 * (TrailPoints - 1); @@ -161,11 +161,10 @@ public class Slime : MonoBehaviour void UpdateSettings() { - RegisterResolver.Register(); - var hash = MessagePackSerializer.Serialize(SlimeSettings).GetHashSHA1(); - if(hash != _settingsHash) + if (!_settingsInitialized || !SlimeSettings.Equals(_currentSettings)) { - _settingsHash = hash; + _settingsInitialized = true; + _currentSettings = SlimeSettings; _parameterBuffer.SetData(new[] {SlimeSettings}); } } @@ -278,8 +277,8 @@ public class Slime : MonoBehaviour } } -[Serializable, MessagePackObject(keyAsPropertyName:true)] -public struct SlimeSettings +[Serializable] +public struct SlimeSettings : IEquatable { public SlimeParameter Deposition; public SlimeParameter Diffusion; @@ -291,10 +290,47 @@ public struct SlimeSettings public SlimeParameter SensorSpread; public SlimeParameter TrailDamping; public SlimeParameter Intensity; + + public bool Equals(SlimeSettings other) + { + return Deposition.Equals(other.Deposition) + && Diffusion.Equals(other.Diffusion) + && Decay.Equals(other.Decay) + && TurnSpeed.Equals(other.TurnSpeed) + && Speed.Equals(other.Speed) + && Drive.Equals(other.Drive) + && SensorDistance.Equals(other.SensorDistance) + && SensorSpread.Equals(other.SensorSpread) + && TrailDamping.Equals(other.TrailDamping) + && Intensity.Equals(other.Intensity); + } + + public override bool Equals(object obj) + { + return obj is SlimeSettings other && Equals(other); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = Deposition.GetHashCode(); + hashCode = (hashCode * 397) ^ Diffusion.GetHashCode(); + hashCode = (hashCode * 397) ^ Decay.GetHashCode(); + hashCode = (hashCode * 397) ^ TurnSpeed.GetHashCode(); + hashCode = (hashCode * 397) ^ Speed.GetHashCode(); + hashCode = (hashCode * 397) ^ Drive.GetHashCode(); + hashCode = (hashCode * 397) ^ SensorDistance.GetHashCode(); + hashCode = (hashCode * 397) ^ SensorSpread.GetHashCode(); + hashCode = (hashCode * 397) ^ TrailDamping.GetHashCode(); + hashCode = (hashCode * 397) ^ Intensity.GetHashCode(); + return hashCode; + } + } } -[Serializable, MessagePackObject(keyAsPropertyName:true)] -public struct SlimeParameter +[Serializable] +public struct SlimeParameter : IEquatable { public float SlopeThreshold; public float SlopeBlend; @@ -306,4 +342,31 @@ public struct SlimeParameter { return lerp(LowValue, HighValue, pow(smoothstep(SlopeThreshold - SlopeBlend, SlopeThreshold + SlopeBlend, slope), Exponent)); } + + public bool Equals(SlimeParameter other) + { + return SlopeThreshold.Equals(other.SlopeThreshold) + && SlopeBlend.Equals(other.SlopeBlend) + && HighValue.Equals(other.HighValue) + && LowValue.Equals(other.LowValue) + && Exponent.Equals(other.Exponent); + } + + public override bool Equals(object obj) + { + return obj is SlimeParameter other && Equals(other); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = SlopeThreshold.GetHashCode(); + hashCode = (hashCode * 397) ^ SlopeBlend.GetHashCode(); + hashCode = (hashCode * 397) ^ HighValue.GetHashCode(); + hashCode = (hashCode * 397) ^ LowValue.GetHashCode(); + hashCode = (hashCode * 397) ^ Exponent.GetHashCode(); + return hashCode; + } + } } diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 8c11e5913..c8d1a7d2a 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -63,7 +63,11 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. - MessagePack is no longer used as a runtime object-cloning shortcut for `EntitySettings`, and UI/player-settings startup no longer registers the old MessagePack resolver. Resolver registration is confined to legacy catalog - deserialization and non-state compute hashing. + deserialization. The slime compute settings path no longer serializes its + local parameter struct for change detection. +- The dead story compiled-JSON cache sketch and its SHA helper are deleted; + story compilation currently reads Ink source directly until a typed Verse + story/cache document exists. - Runtime UI is old Unity UI/uGUI prefabs plus `MonoBehaviour` scripts under `Assets/Scripts/UI/` and `Assets/Prefabs/UI/`. - Aetheria already has Unity UIElements support available through