Table of Contents

Class SceneInstanceLifetime

Namespace
FishMMO.Server.Implementation.World.SceneServer
Assembly
FishMMO.Server.dll

The arithmetic of a scene instance's lifetime cap, its closing warnings and its idle timeout.

public static class SceneInstanceLifetime
Inheritance
SceneInstanceLifetime
Inherited Members

Remarks

Every time here is seconds on this process's MonotonicClock. These are all durations, and a duration measured on the host's wall clock moves when that clock is stepped: a forward step of N minutes used to close, on one pulse, every instance within N minutes of its cap, with its players still inside.

The one input that does not start in this process is the instance's age when its row was dequeued. The database measures that against the clock that stamped the row, and CreatedAt(double, double) turns it into a point on the monotonic clock, so no host clock takes part in the comparison at all.

Pure and static so the rules are pinned by tests without a scene server.

Methods

CreatedAt(double, double)

Where a scene row's creation falls on the monotonic clock.

public static double CreatedAt(double observedAt, double ageSeconds)

Parameters

observedAt double

Monotonic time at which the age was read.

ageSeconds double

The row's age at that moment, by the database clock. Negative or not a number reads as zero: "created in the future" is not an age anything can be measured from.

Returns

double

IsExpired(double, double, double)

Whether an instance has reached its lifetime cap.

public static bool IsExpired(double now, double createdAt, double lifetimeSeconds)

Parameters

now double
createdAt double
lifetimeSeconds double

Returns

bool

IsIdleExpired(double, double, double)

Whether an empty scene has been empty for at least its idle timeout.

public static bool IsIdleExpired(double now, double lastExitAt, double timeoutSeconds)

Parameters

now double
lastExitAt double
timeoutSeconds double

Returns

bool

RemainingSeconds(double, double, double)

Seconds left before an instance reaches its lifetime cap. Zero or less once it has.

public static double RemainingSeconds(double now, double createdAt, double lifetimeSeconds)

Parameters

now double
createdAt double
lifetimeSeconds double

Returns

double

ResolveExpiryWarning(double, IReadOnlyList<int>, ISet<int>)

Which closing warning, if any, is due now.

public static int ResolveExpiryWarning(double remainingSeconds, IReadOnlyList<int> marks, ISet<int> announced)

Parameters

remainingSeconds double

Time left before the instance closes.

marks IReadOnlyList<int>

Remaining-time marks, in seconds, at which occupants are warned. Any order.

announced ISet<int>

Marks already dealt with for this instance. Updated in place: the mark warned for, and every larger one, are added.

Returns

int

The time to announce in seconds, rounded up to a whole minute, or 0 when nothing is due.

Remarks

The tightest mark crossed wins, and every larger one is retired with it. Warning for the first unannounced mark instead told players a dungeon "closes in 10 minutes" with four left, whenever an instance crossed more than one mark between two checks: one whose difficulty allows less than ten minutes in total, one that spent most of its life queued and loading, or one whose checks were held up. The next check then said "5 minutes", when it had fewer.

The time announced is what is actually left, rounded up to the minute, which in the ordinary case (a mark crossed on the check just after it) is the mark itself.