SpaceDwarves Wiki
Documents game v0.10.0

The Core Game Loop

SpaceDwarves is an idle game, which means the colony keeps working whether you are watching or not. Two things drive everything: a fixed-step simulation that advances the world in small, even slices of time, and an offline catch-up pass that fast-forwards the colony when you return after a break. On top of that sits the strategic gameplay loop — mine → refine → build → research → expand — that you steer over hours, days and weeks.

This page explains exactly how the simulation works and which numbers govern it. All constants below come straight from the game’s loop code (client/js/core/loop.js).

The Fixed-Tick Simulation

Every game system (production, consumption, training, expeditions, recovery, and so on) is advanced by a single shared clock. That clock ticks at a fixed interval so that results are deterministic and consistent regardless of your device’s frame rate.

Constant Value Meaning
SIM_STEP_MS 250 ms One simulation step (tick). Every system receives this as its dt (delta-time) and advances exactly 250 ms of game time.
MAX_LIVE_DELTA_MS 5,000 ms Tab-wake clamp. The most real time that can be applied in a single catch-up burst during live play.

While the game is open and visible, rendering runs on the browser’s animation frame, but the simulation only advances in whole 250 ms steps. If several steps’ worth of time has elapsed since the last tick (for example, the browser briefly throttled the tab), the loop runs the missing steps back-to-back to stay caught up.

The tab-wake clamp

When a background tab is throttled or your machine sleeps for a few seconds, the loop could otherwise try to apply a huge delta all at once. To prevent a runaway burst, each live update is clamped to MAX_LIVE_DELTA_MS (5 seconds) of real time per pass. Anything longer than that is not lost — it is handled by the offline progression path instead (see below), which is purpose-built for long gaps. A background-tab setInterval fallback also keeps the simulation ticking when the browser throttles animation frames on hidden tabs.

In short: small hitches are smoothed over live; genuine absences are resolved by the offline system.

Live vs. Offline Progression

The simulation runs in one of two modes:

  • Live progression — the game is open. Systems tick every 250 ms, and the last-tick timestamp is written into your save on every step so the game always knows the exact moment it was last running.
  • Offline progression — you closed the tab, locked your device, or were away long enough to trip the live clamp. On your next load, the loop computes how long you were gone and fast-forwards the colony in one pass before live play resumes.

Because the last-tick timestamp is stored inside your save (see Persistence & Saves), offline progress survives a save-and-reload cycle and is calculated from the real moment you stopped playing.

Offline Fast-Forward

When you return, the loop runs offline progression once, before the live loop starts. Rather than simulating every 250 ms step across a multi-hour gap (which could be over a million iterations and freeze the page), it advances the world in much larger chunks.

Constant Value Meaning
OFFLINE_STEP_MS 60,000 ms (60 s) Chunk size used to fast-forward systems during catch-up.

Production and consumption are linear in time and clamp to your storage caps, so a coarse 60-second chunk produces the same result as thousands of fine steps — just far cheaper. For a 72-hour absence that is only ~4,320 chunks, which resolves near-instantly.

Wall-clock timers resolve correctly

Some events are scheduled against the real clock rather than accumulated time — expedition stage deadlines, injury heal times, training completions, and ale-buff expiries. These are stored as absolute timestamps, and the systems that own them check against the real wall clock during catch-up. The practical effect: an injury that should have healed while you were away comes back healed, a finished training session is applied, a completed research node pops, and expired ale buffs are cleared — all resolved correctly in a single pass, no matter the chunk size.

When catch-up finishes, the game shows a summary of what happened while you were gone, and the last-tick timestamp is re-anchored to “now” so an immediate second reload correctly sees roughly zero elapsed time (no double-counting).

The Offline Cap & Diminishing Returns

Offline earnings are deliberately bounded so that an idle player and an always-online player don’t drift too far apart, and so that very long absences don’t trivialise the game. Two limits apply: a diminishing-returns curve and an absolute hard ceiling.

Constant Value Meaning
OFFLINE_CAP_MS 72 hours Absolute hard ceiling. Offline time can never exceed this no matter what.
OFFLINE_HALFLIFE_MS 24 hours Half-life of the diminishing-returns curve.
OFFLINE_CAP_BASE_HOURS 8 hours The effective cap before any research raises it.

How the effective elapsed time is computed

The amount of offline time you actually receive is calculated with a smooth diminishing-returns curve that asymptotically approaches the cap, then scaled by any income bonus and re-clamped to the cap:

rawElapsed     = max(0, now − lastTickTimestamp)        // clamp clock skew to 0
diminished     = cap × (1 − e^(−rawElapsed / OFFLINE_HALFLIFE_MS))
effectiveTime  = min(cap, diminished × offlineIncomeMultiplier)

Where cap is your current effective cap (see next section), and offlineIncomeMultiplier is any research / mega-project bonus to offline income. Note the curve uses a 24-hour half-life: each additional hour away returns a little less effective time than the hour before it, so there is a strong reason to check in regularly — but you are never punished for a long break, you simply plateau near the cap.

Clock-skew safety: if your device clock moves backwards, rawElapsed is clamped to zero rather than producing negative or absurd time. Very short gaps (under one simulation step) are ignored entirely and the timestamp is just re-anchored.

Raising the cap

The base effective cap is 8 hours. The Guild Administration research branch raises it through its offlineSimulationCapHours upgrades, and full sector automation (see Automation & QoL) pushes it toward the 72-hour hard ceiling. The effective cap is always the lesser of your researched hours and the 72-hour ceiling, so research can extend your offline window but never break the absolute limit.

The Strategic Loop: Mine → Refine → Build → Research → Expand

The tick model is the engine; the gameplay loop is what you actually do with it. Every session, however short, advances some part of this cycle:

  1. Mine — Mine Shafts on your asteroids extract raw ore (Iron, Ice, Copper and more). This is the base of everything. See Resources and the Production Chain.
  2. Refine — Refineries and factories turn raw ore into refined goods and then manufactured components (Iron → Steel → Machine Parts → Electronics → Components). Higher tiers are worth more and unlock bigger projects. See Production Buildings.
  3. Build — Spend resources and credits to construct and upgrade buildings, accommodations, and stations that boost output and house more dwarves.
  4. Research — Bank Research Points to unlock permanent improvements and new systems across the research tree — better mining, automation, station specialisations and sector access.
  5. Expand — Claim more asteroids, launch expeditions for loot and rare crew, and unlock new sectors and eventually new galaxies. The empire only ever grows — there is no prestige reset.

Each turn of this loop feeds the next: more mining funds more building, which unlocks more research, which opens more of the map, which yields richer mining and expedition rewards. Idle progress (live and offline) keeps the early stages of the loop turning while you focus your attention on the newest, most hands-on systems — expeditions, research and expansion — which is exactly what the automation tiers are designed to enable.

Quick Reference

Constant Value Role
SIM_STEP_MS 250 ms Fixed simulation tick
MAX_LIVE_DELTA_MS 5,000 ms Live tab-wake clamp
OFFLINE_STEP_MS 60,000 ms Offline fast-forward chunk size
OFFLINE_CAP_BASE_HOURS 8 h Base effective offline cap (pre-research)
OFFLINE_HALFLIFE_MS 24 h Diminishing-returns half-life
OFFLINE_CAP_MS 72 h Absolute hard ceiling on offline time

Where to Next

Documents SpaceDwarves v0.10.0 · Changelog