package gametime
import "github.com/nsgo-dev/game/pkg/gametime"Overview
Package gametime is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides deterministic in-game calendar clocks.
Index
Types
type Clock struct {
// DayLength is the real duration of one in-game day.
DayLength time.Duration
// DaysPerSeason is the number of days before Season advances. Zero disables rollover.
DaysPerSeason int
// Season is the zero-based current season.
Season int
// Day is the one-based current day within the season.
Day int
// Minute is the current minute within the day, in [0, 1440).
Minute int
// Partial is the progress toward the next in-game minute, as the fraction Partial/DayLength of a minute, in [0, DayLength). Step keeps it so that many short steps add up to the same time as one long step, and a saved and restored clock keeps stepping as one that was never saved.
Partial time.Duration
}Clock advances a deterministic in-game calendar without reading the device clock.
func (c *Clock) SkipTo(hour int)SkipTo advances to the next occurrence of hour, or to that hour today when it has not passed yet.
func (c *Clock) Step(dt time.Duration)Step advances the clock by dt. Non-positive durations and clocks without a positive DayLength are ignored. Time shorter than an in-game minute is kept in Partial rather than dropped, so many short steps advance the clock as far as one step of their total length.