Table of Contents

Class PortalActivationStore

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

The portal activations a process knows: each character's own (bit sets per scene, the waypoint shape) and the world's (one PortalWorldState per scene and index), with what the database has and has not confirmed.

public sealed class PortalActivationStore
Inheritance
PortalActivationStore
Inherited Members

Remarks

Plain data, no I/O. The scene server's interactable system owns the live store, fills it from the database (RestoreCharacterPage(long, string, int, ulong), RestoreWorldScene(string, IReadOnlyList<(int Index, PortalWorldState State)>)) and drains what is dirty into it; PortalGate reads and writes it through Current. Until a server installs one, Current is a store that treats every record as loaded and keeps them in memory only — so a portal behaves the same in a harness or a sim, it just forgets on restart.

Loaded is tracked separately from empty. A character with no rows and a character not read yet both have no bits; only the first may be answered "closed" (see PortalActivationRules). Likewise per scene for world rows.

Persistence without versions. Character bits reuse WaypointUnlockMask: set-only bits whose database merge is an OR, so dirty is activated & ~persisted and a bit set while a write is in flight stays dirty on its own. World openings are tracked by Covers(PortalWorldState): a confirmation clears the mark only if what was written covers what is held now. A released character whose bits are still unconfirmed keeps its entry, unloaded, until a write confirms them; a reload ORs the database rows back in.

Record keys. A per-character record is keyed by a string that is the scene name for portals, and the scene name plus KeySuffix for the sites a character has discovered: the same bit pages, persisted by the same rows.

Main thread only.

Constructors

PortalActivationStore(bool)

public PortalActivationStore(bool assumeLoaded)

Parameters

assumeLoaded bool

Fields

AssumeLoaded

When true every record counts as loaded: the memory-only store.

public readonly bool AssumeLoaded

Field Value

bool

Clock

Unix milliseconds now. Replaceable for tests.

public Func<long> Clock

Field Value

Func<long>

Properties

CharacterRecordCount

Number of character records held, loaded or released. Diagnostics and tests.

public int CharacterRecordCount { get; }

Property Value

int

Current

The store PortalGate uses. A server installs its own on start and clears it on stop; otherwise a process-local, memory-only store.

public static PortalActivationStore Current { get; set; }

Property Value

PortalActivationStore

NowUnixMs

The store's notion of now.

public long NowUnixMs { get; }

Property Value

long

UnconfirmedWorldCount

Number of world openings awaiting confirmation. Diagnostics and tests.

public int UnconfirmedWorldCount { get; }

Property Value

int

Methods

ActivateForCharacter(long, string, int)

Records a per-character activation and raises CharacterActivated when new.

public bool ActivateForCharacter(long characterID, string sceneName, int portalIndex)

Parameters

characterID long
sceneName string
portalIndex int

Returns

bool

True when newly activated.

ActivateForWorld(string, int, PortalWorldState)

Merges an opening into a portal's world state, marks it unconfirmed, and raises WorldActivated when the state grew.

public bool ActivateForWorld(string sceneName, int portalIndex, PortalWorldState opening)

Parameters

sceneName string
portalIndex int
opening PortalWorldState

Returns

bool

True when the state grew.

CollectDirtyCharacters(List<long>)

Appends every character with unconfirmed bits, loaded or released.

public void CollectDirtyCharacters(List<long> results)

Parameters

results List<long>

CollectDirtyPages(long, List<WaypointPageSnapshot>)

Appends a character's pages with unconfirmed bits.

public void CollectDirtyPages(long characterID, List<WaypointPageSnapshot> results)

Parameters

characterID long
results List<WaypointPageSnapshot>

CollectDirtyWorld(List<(string Scene, int Index, PortalWorldState State)>)

Appends every world opening the database has not confirmed.

public void CollectDirtyWorld(List<(string Scene, int Index, PortalWorldState State)> results)

Parameters

results List<(string Scene, int Index, PortalWorldState State)>

IsCharacterActive(long, string, int)

Whether a character activated a portal; null when its record is not loaded.

public bool? IsCharacterActive(long characterID, string sceneName, int portalIndex)

Parameters

characterID long
sceneName string
portalIndex int

Returns

bool?

IsCharacterLoaded(long)

Whether a character's activations have been read.

public bool IsCharacterLoaded(long characterID)

Parameters

characterID long

Returns

bool

IsSceneLoaded(string)

Whether a scene's world rows have been read.

public bool IsSceneLoaded(string sceneName)

Parameters

sceneName string

Returns

bool

MarkCharacterLoaded(long)

Marks a character's record as read, so decisions may use it.

public void MarkCharacterLoaded(long characterID)

Parameters

characterID long

MarkCharacterPersisted(long, string, int, ulong)

Records that the database holds these bits. A released character's record goes once it is clean.

public void MarkCharacterPersisted(long characterID, string sceneName, int page, ulong writtenMask)

Parameters

characterID long
sceneName string
page int
writtenMask ulong

MarkWorldPersisted(string, int, PortalWorldState)

Records that the database holds an opening; the mark clears only if the write covers what is pending.

public void MarkWorldPersisted(string sceneName, int portalIndex, PortalWorldState written)

Parameters

sceneName string
portalIndex int
written PortalWorldState

ReleaseCharacter(long)

Forgets a character that left. Its record is kept, unloaded, while any bit is unconfirmed, so the next flush can still write it.

public void ReleaseCharacter(long characterID)

Parameters

characterID long

ReleaseScene(string)

Forgets a scene's rows (its last copy unloaded). Unconfirmed openings are kept for the flush.

public void ReleaseScene(string sceneName)

Parameters

sceneName string

RequestLoad(long, string)

Asks the owner to load a record a decision needed. Raised by PortalGate.

public void RequestLoad(long characterID, string sceneName)

Parameters

characterID long
sceneName string

RestoreCharacterPage(long, string, int, ulong)

Installs a persisted page: activated and confirmed. The load path.

public void RestoreCharacterPage(long characterID, string sceneName, int page, ulong mask)

Parameters

characterID long
sceneName string
page int
mask ulong

RestoreWorldScene(string, IReadOnlyList<(int Index, PortalWorldState State)>)

Installs a scene's rows (merged with anything held) and marks the scene loaded. The load path, and the periodic refresh that picks up other servers' openings.

public List<int> RestoreWorldScene(string sceneName, IReadOnlyList<(int Index, PortalWorldState State)> rows)

Parameters

sceneName string
rows IReadOnlyList<(int Index, PortalWorldState State)>

Returns

List<int>

The indices whose state grew, so the caller can tell players.

WorldState(string, int)

A portal's world state; default when none, null when the scene is not loaded.

public PortalWorldState? WorldState(string sceneName, int portalIndex)

Parameters

sceneName string
portalIndex int

Returns

PortalWorldState?

Events

CharacterActivated

A character activated a per-character portal (newly). Parameters: character ID, scene, index.

public event Action<long, string, int> CharacterActivated

Event Type

Action<long, string, int>

LoadRequested

A decision needed a record that is not loaded. Parameters: character ID (0 for none), scene (null for none).

public event Action<long, string> LoadRequested

Event Type

Action<long, string>

WorldActivated

A world portal's opening grew. Parameters: scene, index, the merged state.

public event Action<string, int, PortalWorldState> WorldActivated

Event Type

Action<string, int, PortalWorldState>