Skip to main content

Worldreset

Overview

The Worldreset component orchestrates the world reset workflow in Don't Starve Together, handling countdown timing, dialog visibility, network synchronization, and ultimately triggering world deletion and restart. It operates differently depending on whether it runs on the master shard, a secondary shard, or a dedicated server, and integrates closely with player count events and net sync mechanisms.

Dependencies & Tags

  • Components: none explicitly added (relies on inst already having GUID, StartUpdatingComponent, StopUpdatingComponent, and ListenForEvent/RemoveEventCallback capabilities)
  • Tags: none added or removed
  • Network variables: registers net_byte(inst.GUID, "worldreset._countdown", "countdowndirty") for countdown synchronization

Properties

The component does not define a _ctor but initializes variables in its constructor function. Public properties are minimal; most are private locals. Key public-accessible variables (implicitly exposed via self.inst) are:

PropertyTypeDefault ValueDescription
instEntitypassed-in instanceReference to the entity the component is attached to (typically a world or worldmanager entity)

Private mutable state (not public properties but crucial to behavior):

PropertyTypeDefault ValueDescription
_shownbooleanfalseWhether the world reset dialog is currently visible
_updatingbooleanfalseWhether the countdown update loop is active
_resettingbooleanfalseWhether a reset is in progress or queued
_countdownfnumbernilFloat countdown timer (in seconds)
_lastcountdownnumbernilLast integer countdown value sent to clients
_dtoverridenumber0Delta time adjustment used for fast-forwarding on non-master shards
_instantbooleanfalseWhether reset should be immediate upon all-ghost condition
_countdownmaxnumber0Configured countdown duration (non-loading)
_countdownloadingmaxnumbersame as _countdownmaxCountdown duration during loading screen
_syncperiodnumber5Interval (in seconds) for syncing countdown on master shard
_cancelwhenemptybooleanfalseWhether to cancel countdown when player count hits zero
_wasemptybooleantrueWhether the shard was empty (zero players) in previous player count event

Main Functions

OnUpdate(dt)

  • Description: Main update loop for countdown timing. Handles delta-time accumulation, countdown decrement, network sync (master shard only), and triggering the final world reset when countdown reaches zero.
  • Parameters:
    • dt (number): Delta time since last frame.

OnPostInit()

  • Description: Runs after component initialization. Executes one-time setup: triggers initial countdown handling via OnCountdownDirty(), and applies a one-time delta time override (adds 4 seconds) for non-master shards to compensate for network packet processing delays.
  • Parameters: None.

Events & Listeners

  • Listens for:

    • "countdowndirty"OnCountdownDirty(): Triggers countdown update when network countdown variable changes.
    • "playeractivated" (non-dedicated, non-master-sim) → OnRefreshDialog(): Refreshes dialog visibility when a player logs in.
    • "entercharacterselect" (non-dedicated, non-master-sim) → OnRefreshDialog(): Refreshes dialog visibility on character select.
    • "ms_worldreset" (master shard only) → OnWorldResetFromSim(): Halts countdown update if world reset is initiated from sim.
    • "ms_setworldresettime" (master shard only) → OnSetWorldResetTime(): Sets reset timing parameters (instant flag, countdown durations).
    • "ms_playercounts" (master shard only) → OnPlayerCounts(): Responds to player count changes (e.g., cancel reset if non-ghost players exist).
  • Triggers (PushEvent):

    • "worldresettick" with { time = time }: Broadcasts countdown tick to UI and other systems.
    • "showworldreset": Requests world reset dialog to appear.
    • "hideworldreset": Requests world reset dialog to disappear.
    • "master_worldresetupdate" with { countdown = value }: Sends current countdown to all shards from master.
  • Network variable updates:

    • Sets worldreset._countdown via _countdown:set(value) or _countdown:set_local(value): Synchronizes countdown state across shards. Triggers "countdowndirty" on listeners.