Seed zones from a stable name hash instead of string.GetHashCode (Cut 10)
Closes the 8a follow-up. string.GetHashCode is stable on Mono but randomized per process on .NET Core, so a headless sim that generates zones would get different zones on every run. - Extensions.StableHash folds a string's UTF-8 bytes through CultMath's pcg from the FNV-1a offset basis. No new CultMath API. - ZoneGenerator seeds from `Name.StableHash() ^ pcg3d(Position).x`. - Zone seeds from `Name.StableHash() ?? 1337u`. CultMath's Random maps seed 0 to its default, and the abs/Convert.ToUInt32 pair that threw on int.MinValue is gone. Old runs are discarded, so a different galaxy per seed costs nothing. Tests: StableHashIsNotProcessRandomized pins "Adrasteia" to 2427892944, the value an independent Add-Type transcription of CultMath's pcg produced. It fails with GetHashCode substituted back in. Builds: headless, 15 tests pass, Unity batchmode compile reports no error CS. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
00f62acc34
commit
65a007e509
4 changed files with 18 additions and 3 deletions
|
|
@ -45,7 +45,7 @@ public static class ZoneGenerator
|
|||
var pack = new ZonePack();
|
||||
var cache = itemManager.ItemData;
|
||||
|
||||
var random = new Random(unchecked((uint) galaxyZone.Name.GetHashCode()) ^ (uint) pcg3d(galaxyZone.Position).x);
|
||||
var random = new Random(galaxyZone.Name.StableHash() ^ (uint) pcg3d(galaxyZone.Position).x);
|
||||
|
||||
var density = saturate(galaxy.Background.CloudDensity(galaxyZone.Position)/2);
|
||||
pack.Radius = zoneSettings.ZoneRadius.Evaluate(density);
|
||||
|
|
|
|||
Loading…
Reference in a new issue