miaoda-game-offline-time-core
v0.1.1
Published
Injected-clock offline elapsed-time policy with wall/monotonic anchors, rollback detection, clamping, and deterministic scheduler targets.
Maintainers
Readme
miaoda-game-offline-time-core
Convert an injected clock sample into an explicit, bounded offline-time result for idle, strategy, management, and
long-running progression games. The package does not read Date, performance, browser storage, or engine state.
pnpm add miaoda-game-offline-time-coreconst anchor = captureOfflineAnchor(scheduler.now, trustedClock);
// Persist `anchor` beside scheduler.snapshot().
const offline = resumeOffline(savedAnchor, trustedClock, {
maxElapsedMs: 24 * 60 * 60 * 1_000,
rollbackPolicy: 'zero',
});
let catchUp;
do {
catchUp = scheduler.advanceTo(offline.targetDomainTime, 500);
for (const occurrence of catchUp.events) dispatch(toCommand(occurrence));
} while (catchUp.exhausted);
// Persist only after the game accepts the catch-up result.
savedAnchor = offline.nextAnchor;ClockSource.sample() must return wall and monotonic integer milliseconds atomically plus a sessionId identifying
the monotonic clock lifetime. In the same session, monotonic elapsed time wins and wall-clock skew is reported. After
a restart, wall time is used. Negative elapsed time is either zeroed or rejected, and every resume requires an
explicit maximum window.
The host decides whether the wall sample comes from a server, a signed platform service, or the local device. Local
wall time is useful for ordinary offline progress but is not cheat-resistant. offline-time-core reports policy
facts; it does not claim that an injected source is trustworthy, invoke game rules, or mutate the scheduler.
