KernelAPI reference
Class StateHasher
Namespace: MicroEngine.Kernel
Assembly: MicroEngine.Kernel.dll
Guide: Modules and the frame schedule
Accumulates a 64-bit hash (FNV-1a) of simulation state in named sections. Values are encoded in a fixed binary form
(little-endian; floats by their bits, so -0 and NaN payloads count; strings length-prefixed), so the same
values in the same order give the same hash on every machine and run. Nothing is read by reflection: the engine and
the game add what they choose (IStateHashed).
public sealed class StateHasherInheritance
Remarks
A section lasts until the next Section; values added before the first one form a section with an empty name. The whole hash covers every value and every section name; each section’s hash covers only its own values, so two runs that differ can be told apart by the section that changed.
Constructors
StateHasher()
public StateHasher()Properties
Sections
The hash of each section so far, in the order they were started (the current one included); a new list each time.
public IReadOnlyList<SectionHash> Sections { get; }Property Value
Value
The hash of everything added so far.
public ulong Value { get; }Property Value
Methods
Add(byte)
Adds a byte.
public void Add(byte value)Parameters
value byte
Add(bool)
Adds a boolean (one byte, 0 or 1).
public void Add(bool value)Parameters
value bool
Add(int)
Adds a 32-bit integer.
public void Add(int value)Parameters
value int
Add(long)
Adds a 64-bit integer.
public void Add(long value)Parameters
value long
Add(ulong)
Adds an unsigned 64-bit integer.
public void Add(ulong value)Parameters
value ulong
Add(float)
Adds a float by its bits: 0 and -0, or two NaNs with different payloads, are different values.
public void Add(float value)Parameters
value float
Add(double)
Adds a double by its bits.
public void Add(double value)Parameters
value double
Add(Vector2)
Adds both components of a vector, x first.
public void Add(Vector2 value)Parameters
value Vector2
Add(string?)
Adds a string as its length then its UTF-16 code units; null is told apart from empty.
public void Add(string? value)Parameters
value string?
Add(ReadOnlySpan<byte>)
Adds raw bytes, preceded by their count (tile maps, grids and other bulk state).
public void Add(ReadOnlySpan<byte> bytes)Parameters
bytes ReadOnlySpan<byte>
Add(IStateHashed?)
Adds an object’s own state (HashState), preceded by whether it is there.
public void Add(IStateHashed? value)Parameters
value IStateHashed?
Reset()
Forgets everything added, to hash another step with the same instance.
public void Reset()Section(string)
Starts the section name: the values added next are hashed under it.
public void Section(string name)Parameters
name string
Exceptions
name is null.
name holds a tab or a line break (traces are written one step per line).