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 ¶
- func At(at time.Duration) cond.Word[Moment]
- func Every(period, offset time.Duration) cond.Word[Moment]
- func Simulate(c *Clock, ctx goke.RunCtx, step time.Duration, block Block)
- type Block
- type Clock
- func (c *Clock) Behind(behind bool)
- func (c *Clock) Faster()
- func (c *Clock) OnSync(settle func())
- func (c *Clock) Pending(d time.Duration)
- func (c *Clock) Read() *Read
- func (c *Clock) Replay(ctx goke.RunCtx, step time.Duration)
- func (c *Clock) Replayed(f func())
- func (c *Clock) SetTempo(tempo float32)
- func (c *Clock) Settling(ctx goke.RunCtx) goke.RunCtx
- func (c *Clock) Simulate(_ goke.RunCtx, block Block)
- func (c *Clock) Slower()
- func (c *Clock) System() goke.System
- func (c *Clock) TogglePause()
- type Config
- type Moment
- type Phase
- type Read
- func (r *Read) Entity() uid.UID64
- func (r *Read) Fork() *Read
- func (r *Read) HUD() render.Renderer
- func (r *Read) In(phase tag.Tag[Phase]) bool
- func (r *Read) Reporter() render.Reporter
- func (r *Read) Shown() time.Duration
- func (r *Read) State() State
- func (r *Read) Steps() uint64
- func (r *Read) Tempos() []float32
- func (r *Read) Time() time.Duration
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
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 (*Clock) Behind ¶
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 ¶
Pending tells the clock how much real time the engine holds toward its next tick, each frame.
func (*Clock) Replay ¶
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) Settling ¶ added in v0.4.0
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 ¶
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) 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 ¶
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 ¶
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.
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
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
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
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
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
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
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) Steps ¶ added in v0.4.0
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.