deltat

package
v0.0.0-...-909c535 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package deltat ("delta T") implements simple "elapsed-time" loop helpers. The "delta" can be any number type, and the calculation provided arbitrarily. deltat also provides basic implementations of this

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loop

func Loop[D constraints.Integer | constraints.Float](
	clock WallClock,
	calcDelta DeltaCalculator[D],
	do DeltaFn[D],
)

The Loop calculates the elapsed D between prev and now using the provided DeltaCalculator, then passes that value to the provided DeltaFn. It exits when the DeltaFn returns `false`.

Types

type DeltaCalculator

type DeltaCalculator[D Numeric] func(prev, now time.Time) (delta D)

A DeltaCalculator returns the elapsed D between prev and now

func ByElapsed

func ByElapsed() DeltaCalculator[time.Duration]

ByElapsed is a DeltaCalculator that simply returns the elapsed time.Duration since the previous iteration.

func ByTick

func ByTick(tps float32) DeltaCalculator[float32]

ByTick is a DeltaCalculator that returns how many ticks have elapsed since the last iteration. tps sets this value.

type DeltaFn

type DeltaFn[D Numeric] func(now time.Time, delta D) (cont bool)

A DeltaFn performs some action based on the delta provided. It returns whether it should continue into the next iteration.

type Numeric

type Numeric interface {
	constraints.Float | constraints.Integer
}

A Numeric is any float or int type.

type WallClock

type WallClock func() time.Time

A WallClock returns the current system time.

func DefaultClock

func DefaultClock() WallClock

The DefaultClock is a WallClock that returns the result of time.Now

Jump to

Keyboard shortcuts

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