Documentation
¶
Overview ¶
Package tickloop provides a fixed-timestep simulation scheduler with optional 2× sub-tick lanes. Subsystems register against either lane and are invoked in registration order each tick. The scheduler tracks overrun (caps catch-up steps), invokes a Recorder for metrics, and shuts down cleanly on context cancellation.
Allocation-free in steady state after warmup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Rate is sim ticks per second (e.g. 30).
Rate int
// SubRate is sub-ticks per second; must be a positive multiple of Rate
// or 0 to disable.
SubRate int
// MaxCatchup bounds catch-up step count when behind schedule.
MaxCatchup int
// Recorder receives per-tick metrics; nil → NoopRecorder.
Recorder Recorder
// Clock; nil → wall clock.
Clock func() time.Time
}
Config controls scheduler rates and behaviour.
type NoopRecorder ¶
type NoopRecorder struct{}
NoopRecorder satisfies Recorder without observing anything.
func (NoopRecorder) OnOverrun ¶
func (NoopRecorder) OnOverrun(int)
func (NoopRecorder) OnSubtick ¶
func (NoopRecorder) OnSubtick(SubtickFrame, time.Duration)
type Recorder ¶
type Recorder interface {
OnTick(frame Frame, took time.Duration)
OnSubtick(frame SubtickFrame, took time.Duration)
OnOverrun(missedTicks int)
}
Recorder receives metrics callbacks. Implementations should be cheap; they're invoked every tick.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler ticks Subsystems on a fixed schedule.
type SubtickFrame ¶
SubtickFrame extends Frame with a sub-index for double-rate lanes.
type SubtickSubsystem ¶
type SubtickSubsystem interface {
Subsystem
SubStep(frame SubtickFrame)
}
SubtickSubsystem runs on the higher-rate sub-tick lane.