Remove runtime serializer hash residue

This commit is contained in:
Meta Vens 2026-06-13 07:36:08 +01:00
commit 23a5241a7d
4 changed files with 80 additions and 37 deletions

View file

@ -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<T, U>(this IEnumerable<T> items, Func<T, U> selector)
{
@ -73,4 +63,4 @@ public static class AsyncAwaitExtensions
{
await task;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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<SlimeSettings>
{
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<SlimeParameter>
{
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;
}
}
}

View file

@ -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