bit

package module
v0.0.0-...-8db044c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 17 Imported by: 0

README

bit

Go Reference

An experimental 2D game engine I'm writing just for fun.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeClock

func MakeClock(fps FPS) (start func() (ticks <-chan Tick, stop func()))

func WithDurationMetric

func WithDurationMetric(m *DurationMetric, f func())

func WithDurationMetricResult

func WithDurationMetricResult[T any](m *DurationMetric, f func() T) T

Types

type App

type App[GameState any] struct {
	FPS              FPS
	Size             image.Point
	InitialGameState GameState
	Update           func(Tick, GameState) (GameState, RenderState)
	DebugEnabled     bool
}

func NewApp

func NewApp[GameState any](size image.Point, initialGameState GameState, update func(Tick, GameState) (GameState, RenderState)) *App[GameState]

func (*App[GameState]) Debug

func (a *App[GameState]) Debug() *App[GameState]

func (*App[GameState]) Main

func (a *App[GameState]) Main()

type DurationMetric

type DurationMetric struct {
	Count         uint64
	TotalDuration time.Duration
}

func (DurationMetric) AverageDuration

func (m DurationMetric) AverageDuration() time.Duration

func (DurationMetric) AverageFPS

func (m DurationMetric) AverageFPS() float64

func (*DurationMetric) Load

func (m *DurationMetric) Load() DurationMetric

func (*DurationMetric) PutEvent

func (m *DurationMetric) PutEvent(d time.Duration)

func (DurationMetric) String

func (m DurationMetric) String() string

type Engine

type Engine[GameState, RenderState any] struct {
	StartClock func() (ticks <-chan Tick, stop func())
	Update     func(Tick, GameState) (GameState, RenderState)
	Render     func(RenderState, *image.NRGBA)
	StartDraw  func(ReadBuffer) error
	Size       image.Point
	Metrics    EngineMetrics
}

func (*Engine[GameState, RenderState]) Run

func (e *Engine[GameState, RenderState]) Run(ctx context.Context, initialGameState GameState) error

type EngineMetrics

type EngineMetrics struct {
	Start, Stop    time.Time
	LoopCount      uint64
	Update, Render DurationMetric
}

func MakeEngineMetrics

func MakeEngineMetrics(now time.Time) EngineMetrics

func (*EngineMetrics) Load

func (m *EngineMetrics) Load() EngineMetrics

func (EngineMetrics) Loop

func (m EngineMetrics) Loop() DurationMetric

func (EngineMetrics) LoopAt

func (m EngineMetrics) LoopAt(now time.Time) DurationMetric

type FPS

type FPS float64

func (FPS) Duration

func (fps FPS) Duration() time.Duration

type ReadBuffer

type ReadBuffer interface {
	Front() *image.NRGBA
	Next() (img *image.NRGBA, changed bool)
}

type RenderState

type RenderState []image.Rectangle

RenderState is whatever we send to the render function to draw on the image buffer.

type Sprite

type Sprite struct{ *image.NRGBA }

type Tick

type Tick [3]time.Time

func NewTick

func NewTick(t time.Time) Tick

func (Tick) Age

func (t Tick) Age() time.Duration

func (Tick) Delta

func (t Tick) Delta() time.Duration

func (Tick) Step

func (t Tick) Step(now time.Time) Tick

func (Tick) Zero

func (t Tick) Zero() time.Time

Directories

Path Synopsis
cmd
bit

Jump to

Keyboard shortcuts

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