Documentation ¶
Overview ¶
Package gloop implements a game loop.
Index ¶
Constants ¶
Hz60Delay is 1/60th of a second.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LatencySample ¶
LatencySample is a measure of how far behind simulate() or render() are.
type Loop ¶
type Loop struct { // Render is an elastic-step function. Render LoopFn // Simulate is a fixed-step function. Simulate LoopFn // RenderRate controls how often Render will be called. // This is the time delay between calls. RenderLatency time.Duration // SimulationRate controls how often Simulate will be called. // This is the time delay between calls. SimulationLatency time.Duration // contains filtered or unexported fields }
Loop is a game loop.
func NewLoop ¶
func NewLoop(Render, Simulate LoopFn, RenderLatency, SimulationLatency time.Duration) (*Loop, error)
NewLoop creates a new game loop.
func (*Loop) Done ¶
func (l *Loop) Done() <-chan interface{}
Done returns a chan that indicates when the loop is stopped. When this finishes, you should do cleanup.
func (*Loop) Err ¶
Err returns the the reason why the loop closed if there was an error. Err will return nil if the loop has not yet run, is currently running, or closed without an error.
func (*Loop) Heartbeat ¶
func (l *Loop) Heartbeat() <-chan LatencySample
Heartbeat returns the heartbeat channel which can be used to monitor the health of the game loop. A pulse will be sent every second with current simulation and render latency.
func (*Loop) Start ¶
Start initiates a game loop. This call does not block. To stop the loop, close the done chan. To get notified before Simulate or Render are called, pull items from the heartbeat channel. If either Render or Simulate throw an error, the error will be made available on the output error channel and the loop will stop.
type LoopError ¶
type LoopError struct { Inner error Message string StackTrace string ErrorSource TokenSource Misc map[string]interface{} }
LoopError is thrown when a gogameloop function returns an error.
type LoopFn ¶
LoopFn is a function that is called inside the game loop. step should be treated as if it was the amount of time that elapsed since the last call.
type TokenSource ¶
type TokenSource int
TokenSource is the creator for the token (metrics or errors).
const ( // TokenLoop is something generated by the game loop package directly. TokenLoop TokenSource = iota // TokenRender concerns Render(). TokenRender TokenSource = iota // TokenSimulate concerns Simulate(). TokenSimulate TokenSource = iota )