clock

package
v0.0.0-...-793ea6c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

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

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

func (c *Clock) AvgFrameRate() float64

AvgFrameRate returns the average number of frames per second that have occured over the last AvgSamples frames.

func (*Clock) AvgSamples

func (c *Clock) AvgSamples() int

AvgSamples returns the number of previous frames that are samples each frame to determine the average frame rate.

func (*Clock) Delta

func (c *Clock) Delta() time.Duration

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

func (c *Clock) Dt() float64

Dt is short-hand for:

dt := float64(c.Delta()) / float64(time.Second)

which is useful for applying movement over time.

func (*Clock) FixedDelta

func (c *Clock) FixedDelta() time.Duration

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

func (c *Clock) FrameCount() uint64

FrameCount returns the number of frames that have rendered in total.

func (*Clock) FrameRate

func (c *Clock) FrameRate() float64

FrameRate returns the number of frames per second according to this Clock.

func (*Clock) FrameRateDeviation

func (c *Clock) FrameRateDeviation() float64

FrameRateDeviation returns the standard deviation of the frame times that have occured over the last AvgSamples frames.

func (*Clock) LastFrame

func (c *Clock) LastFrame() time.Duration

LastFrame returns the time at which the last frame began, in time since the program started.

func (*Clock) MaxDelta

func (c *Clock) MaxDelta() time.Duration

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

func (c *Clock) MaxFrameRate() float64

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

func (c *Clock) SetAvgSamples(n int)

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

func (c *Clock) SetFixedDelta(delta time.Duration)

SetFixedDelta specifies an explicit duration to be handed out via calls to the Delta method instead of the actual calculated delta.

func (*Clock) SetFrameCount

func (c *Clock) SetFrameCount(count uint64)

SetFrameCount specifies the current number of frames that have rendered.

func (*Clock) SetMaxDelta

func (c *Clock) SetMaxDelta(max time.Duration)

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

func (c *Clock) SetMaxFrameRate(max float64)

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.

func (*Clock) Tick

func (c *Clock) Tick()

Tick signals to this Clock that an new frame has just begun.

func (*Clock) Time

func (c *Clock) Time() time.Duration

Time returns the duration of time that has passed since this clock started or was last reset.

Jump to

Keyboard shortcuts

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