Skip to content

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).

C#
public sealed class StateHasher

Inheritance

object ← StateHasher

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()

C#
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.

C#
public IReadOnlyList<SectionHash> Sections { get; }

Property Value

IReadOnlyList<SectionHash>

Value

The hash of everything added so far.

C#
public ulong Value { get; }

Property Value

ulong

Methods

Add(byte)

Adds a byte.

C#
public void Add(byte value)

Parameters

value byte

Add(bool)

Adds a boolean (one byte, 0 or 1).

C#
public void Add(bool value)

Parameters

value bool

Add(int)

Adds a 32-bit integer.

C#
public void Add(int value)

Parameters

value int

Add(long)

Adds a 64-bit integer.

C#
public void Add(long value)

Parameters

value long

Add(ulong)

Adds an unsigned 64-bit integer.

C#
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.

C#
public void Add(float value)

Parameters

value float

Add(double)

Adds a double by its bits.

C#
public void Add(double value)

Parameters

value double

Add(Vector2)

Adds both components of a vector, x first.

C#
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.

C#
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).

C#
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.

C#
public void Add(IStateHashed? value)

Parameters

value IStateHashed?

Reset()

Forgets everything added, to hash another step with the same instance.

C#
public void Reset()

Section(string)

Starts the section name: the values added next are hashed under it.

C#
public void Section(string name)

Parameters

name string

Exceptions

ArgumentNullException

name is null.

ArgumentException

name holds a tab or a line break (traces are written one step per line).