clock

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clock is the tactical clock of a world: the one game time everything that simulates goes by, kept by the world and saved with the game.

Time and the tempo

Game time is the sum of the simulation's steps (Read.Time): it stands still in the tactical pause and goes at the clock's tempo, ½, 1, 2 or 4 by default (Config.Tempos). In a tick the clock replays the simulation as many times as the tempo says (Clock.Replay), each time over the same step, so the game runs the same at any tempo; a Config.BiggerStep clock replays once over a longer step instead. Read.Steps numbers the steps, for what goes every so many. What is drawn goes by Read.Shown, game time run on past the last tick by the real time the engine holds toward the next, so animations move every frame.

Interface and simulation

In its RunPlan a plugin runs at once whatever is interface (commands, selecting, planning) and hands the clock whatever simulates (Clock.Simulate): movement, collisions, effects, sight, the weather. The clock replays those pieces after the game's Update, in the order they came, so selecting and orders work in the tactical pause and never speed up.

Commands, phases and the display

Clock.TogglePause is the tactical pause, Clock.Faster and Clock.Slower move the tempo, which the world's commands ask. The clock's entity carries a family of Phase tags that effects cast on it switch on and off; a rule asks Read.In whether a phase holds. A rule of the clock's Moment fires once every step of the simulation; its words At and Every (cond.Self.If(clock.Every(period, offset))) hold in the step reaching a time. Read.Reporter is a telemetry line, Read.HUD a screen layer showing the game time.

Vocabulary

Moments, for a role's rules: Moment (the clock's own entity, once a step; its words At, Every). Commands: none of its own; the world's Pause, Faster and Slower drive it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func At

func At(at time.Duration) cond.Word[Moment]

At is the word of the step the clock's time reaches at in.

func Every

func Every(period, offset time.Duration) cond.Word[Moment]

Every is the word of each step the clock's time reaches another period in, the first at offset: a calendar's every day at an hour is Every(calendar.Daily(hour)), every winter Every(calendar.Seasonal(Winter)).

func Simulate

func Simulate(c *Clock, ctx goke.RunCtx, step time.Duration, block Block)

Simulate hands block to c, or runs it at once over step where c is nil (a module run without a world).

Types

type Block

type Block func(ctx goke.RunCtx, step time.Duration)

Block is a piece of the simulation: what a plugin runs under Simulate, as many times a tick as the clock says, each time over step.

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock is the tactical clock of a world: the one time everything that simulates goes by. A plugin hands it what simulates (Simulate) and the engine replays it as many times as the tempo says (Replay), none in the tactical pause.

func New

func New(cfg Config) *Clock

New makes a clock at tempo 1, not paused, of cfg.

func (*Clock) Behind

func (c *Clock) Behind(behind bool)

Behind tells the clock the engine could not run every tick this frame: a tempo above 1 held for a while past that comes down a notch, and the report says so.

func (*Clock) Faster

func (c *Clock) Faster()

Faster moves the tempo a notch up the Config's list, Slower a notch down; neither past its end.

func (*Clock) OnSync added in v0.4.0

func (c *Clock) OnSync(settle func())

OnSync has settle run after every Sync of what Replay runs or Settling hands, and as each Replay ends: for what reads goke's memory where it lies, which a Sync may move.

func (*Clock) Pending

func (c *Clock) Pending(d time.Duration)

Pending tells the clock how much real time the engine holds toward its next tick, each frame.

func (*Clock) Read added in v0.4.0

func (c *Clock) Read() *Read

Read reads the clock on the game's goroutine.

func (*Clock) Replay

func (c *Clock) Replay(ctx goke.RunCtx, step time.Duration)

Replay runs every piece handed to Simulate this tick as many times as the tempo says, over step, moving game time on with each. A BiggerStep clock runs them once, over step times the tempo.

func (*Clock) Replayed added in v0.4.0

func (c *Clock) Replayed(f func())

Replayed has f run as each Replay ends, after OnSync's settle, in the order given: for what takes the simulation's state once a tick, on the game's goroutine.

func (*Clock) SetTempo

func (c *Clock) SetTempo(tempo float32)

SetTempo sets the tempo to the Config's nearest to tempo.

func (*Clock) Settling added in v0.4.0

func (c *Clock) Settling(ctx goke.RunCtx) goke.RunCtx

Settling is ctx running OnSync's settle after every Sync, for a plan to hand what it runs outside Replay; ctx itself where OnSync gave none or ctx already settles.

func (*Clock) Simulate

func (c *Clock) Simulate(_ goke.RunCtx, block Block)

Simulate hands the clock a piece of the simulation for this tick: block runs at Replay, as many times as the tempo says, in the order the pieces came.

func (*Clock) Slower

func (c *Clock) Slower()

Slower — see Faster.

func (*Clock) System

func (c *Clock) System() goke.System

System is the clock's own system, for the world to register in the interface part of its tick: it keeps the clock's entity and the State on it.

func (*Clock) TogglePause

func (c *Clock) TogglePause()

TogglePause holds the simulation in the tactical pause, or lets it go on.

type Config

type Config struct {
	Tempos     []float32
	BiggerStep bool
}

Config is how the clock goes: the Tempos it can be set to, in order, with 1 among them (½, 1, 2 and 4 by default), and whether a tempo above 1 is BiggerStep, one longer step rather than as many steps of the same length.

type Moment

type Moment struct {
	Last, Now time.Duration
	Clock     uid.UID64
}

Moment is one step of the simulation on the clock's time, from Last to Now: what a rule of the clock fires on, once every step. It is the moment of the clock's own entity, Clock, where an effect a rule applies lands.

func (Moment) Who

func (m Moment) Who() uid.UID64

Who is the clock's entity: whose moment it is, for a rule.

type Phase

type Phase struct{}

Phase is the family of the clock's tags, which effects cast on the clock switch on and off for a rule to run only while one holds (Read.In). A game defines its phases with world.Kinds.DefineTag[clock.Phase].

type Read added in v0.4.0

type Read struct {
	// contains filtered or unexported fields
}

Read reads the clock on one goroutine at a time: the clock's own through its system's query, a Fork's through a query of its own.

func (*Read) Entity added in v0.4.0

func (r *Read) Entity() uid.UID64

Entity is the clock's entity — what a Phase is granted to, by an effect cast on it; 0 before the game is set up.

func (*Read) Fork added in v0.4.0

func (r *Read) Fork() *Read

Fork reads the same clock through a query of its own, for another goroutine; made before the clock's system is set up, it gets it then.

func (*Read) HUD added in v0.4.0

func (r *Read) HUD() render.Renderer

HUD is a screen renderer showing the clock in the window's bottom-left corner, for a ui.Drawer: a plugin.Publisher, reading the clock after the ticks.

func (*Read) In added in v0.4.0

func (r *Read) In(phase tag.Tag[Phase]) bool

In reports whether the clock is in phase: its entity carries the tag, as of this step of the simulation — an effect granting it in one step is seen in the next.

func (*Read) Reporter added in v0.4.0

func (r *Read) Reporter() render.Reporter

Reporter is the clock's line for the telemetry panel: the game time as minutes and seconds, and whether it stands or goes at another tempo.

func (*Read) Shown added in v0.4.0

func (r *Read) Shown() time.Duration

Shown is the game time what is drawn goes by: Time run on by the real time held toward the next tick at the tempo, so it moves every frame.

func (*Read) State added in v0.4.0

func (r *Read) State() State

State is the clock as it stands: what its entity carries.

func (*Read) Steps added in v0.4.0

func (r *Read) Steps() uint64

Steps is how many steps of the simulation have gone by: in a step, its number from 0. What goes every so many steps counts by it; it is not saved.

func (*Read) Tempos added in v0.4.0

func (r *Read) Tempos() []float32

Tempos are the tempos the clock can be set to, the Config's, in order.

func (*Read) Time added in v0.4.0

func (r *Read) Time() time.Duration

Time is the game time gone by.

type State

type State struct {
	Time   time.Duration
	Tempo  float32
	Paused bool
}

State is the tactical clock as it stands, saved on the clock's entity: the game time gone by, the tempo it goes at, and whether it stands in the tactical pause.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL