Documentation ¶
Overview ¶
Package clock measures frame-based application performance.
Typically you create a single Clock object for each "renderer" and invoke Tick on it at the start of each frame.
When using a maximum frame rate, Tick blocks just long enough to ensure that the application is at max running at MaxFrameRate.
Index ¶
- type Clock
- func (c *Clock) AvgFrameRate() float64
- func (c *Clock) AvgSamples() int
- func (c *Clock) Delta() time.Duration
- func (c *Clock) Dt() float64
- func (c *Clock) FixedDelta() time.Duration
- func (c *Clock) FrameCount() uint64
- func (c *Clock) FrameRate() float64
- func (c *Clock) FrameRateDeviation() float64
- func (c *Clock) LastFrame() time.Duration
- func (c *Clock) MaxDelta() time.Duration
- func (c *Clock) MaxFrameRate() float64
- func (c *Clock) Reset()
- func (c *Clock) ResetFrameCount()
- func (c *Clock) ResetLastFrame()
- func (c *Clock) SetAvgSamples(n int)
- func (c *Clock) SetFixedDelta(delta time.Duration)
- func (c *Clock) SetFrameCount(count uint64)
- func (c *Clock) SetMaxDelta(max time.Duration)
- func (c *Clock) SetMaxFrameRate(max float64)
- func (c *Clock) Tick()
- func (c *Clock) Time() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a high resolution clock for measuring real-time application statistics.
func New ¶
func New() *Clock
New initializes and returns a new Clock. The returned clock has it's start time set to the current time, has it's maximum frame rate set to 75, and it's number of average frame rate samples set to 120.
A maximum frame rate of 75 is a good choice because it is slightly above the refresh rate of most screens, and not all hardware supports high resolution clocks so the limit also ensures that Delta never returns values equal to zero.
func (*Clock) AvgFrameRate ¶
AvgFrameRate returns the average number of frames per second that have occured over the last AvgSamples frames.
func (*Clock) AvgSamples ¶
AvgSamples returns the number of previous frames that are samples each frame to determine the average frame rate.
func (*Clock) Delta ¶
Delta returns the time between the start of the current frame and the start of the last frame. If the clock is using a fixed delta value then that value is returned instead.
The value returned will be clamped to MaxDelta.
The duration returned will never be less than zero as long as Tick has been called at least once.
func (*Clock) Dt ¶
Dt is short-hand for:
dt := float64(c.Delta()) / float64(time.Second)
which is useful for applying movement over time.
func (*Clock) FixedDelta ¶
FixedDelta returns the duration which is to be handed out via calls to the Delta method instead of the actual calculated delta.
If time.Duration(0) is returned, then there is no fixed delta specified currently.
func (*Clock) FrameCount ¶
FrameCount returns the number of frames that have rendered in total.
func (*Clock) FrameRate ¶
FrameRate returns the number of frames per second according to this Clock.
func (*Clock) FrameRateDeviation ¶
FrameRateDeviation returns the standard deviation of the frame times that have occured over the last AvgSamples frames.
func (*Clock) LastFrame ¶
LastFrame returns the time at which the last frame began, in time since the program started.
func (*Clock) MaxDelta ¶
MaxDelta returns the duration which serves as the maximum duration returned by the Delta method. Zero implies that there is no maximum delta duration.
func (*Clock) MaxFrameRate ¶
MaxFrameRate returns the maximum frame rate of this Clock, as it was set previously by a call to the SetMaxFrameRate method.
func (*Clock) Reset ¶
func (c *Clock) Reset()
Reset resets this clock's starting time, as if it had just been created.
func (*Clock) ResetFrameCount ¶
func (c *Clock) ResetFrameCount()
ResetFrameCount resets the frame counter of this Clock to zero.
Short hand for Clock.SetFrameCount(0)
func (*Clock) ResetLastFrame ¶
func (c *Clock) ResetLastFrame()
ResetLastFrame resets this Clock's last frame time to the current real time, as if the frame had just begun.
func (*Clock) SetAvgSamples ¶
SetAvgSamples specifies the number of previous frames to sample each frame to determine the average frame rate.
Note: This means allocating an []float64 of size n, so be thoughtful.
func (*Clock) SetFixedDelta ¶
SetFixedDelta specifies an explicit duration to be handed out via calls to the Delta method instead of the actual calculated delta.
func (*Clock) SetFrameCount ¶
SetFrameCount specifies the current number of frames that have rendered.
func (*Clock) SetMaxDelta ¶
SetMaxDelta specifies a duration which will serve as the maximum duration returned by the Delta method. Zero implies that there should be no maximum delta duration.
func (*Clock) SetMaxFrameRate ¶
SetMaxFrameRate specifies an maximum frame rate. Calls to the Tick method will block for whatever time is significant enough to ensure that the frame rate is at max this number. Zero implies that there is no maximum frame rate.
If max is less than zero, an panic occurs.