gamelib

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

README

gamelib

A collection of useful things for making 2D and 3D games in Go.

Star History

Example

See the example directory for 2D canvas and 3D WebGL2 examples. The README in that directory contains instructions for compiling and running them in your browser with WebAssembly.

Quick Start

Features

Game Loop Manager & Metrics
Vector Math
Collection Management (With Safe concurrent Access)
Collision Detection (Hierarchical Spatial Hash Grid)
Polygon Collision Detection/Resolution (Convex & Concave)
Client Interpolation & Metrics

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMetrics

type ClientMetrics struct {
}

type Collection

type Collection[T any] struct {
	Items    map[uint64]T
	ToAppend []T
	ToRemove []uint64
	Lock     sync.RWMutex
}

func NewCollection

func NewCollection[T any]() (collection *Collection[T])

NewCollection creates and initializes a new Collection instance for a given type T, setting up the internal map and slices for managing items, additions, and removals.

func (*Collection[T]) Add

func (c *Collection[T]) Add(item T)

Add adds an item to the ToAppend slice of the Collection, marking it for addition to the main Items map during the next simulation tick.

func (*Collection[T]) Remove

func (c *Collection[T]) Remove(id uint64)

Remove adds an item's ID to the ToRemove slice of the Collection, marking it for removal from the main Items map during the next simulation tick.

type Game

type Game interface {
	Update(dt float64) // dt is in seconds
}

type GameMetrics

type GameMetrics struct {
	Ticks struct {
		Target, Actual float64
		// contains filtered or unexported fields
	}

	Time struct {
		Target                      float64
		Min, Mean, Median, Max, Sum float64
		// contains filtered or unexported fields
	}
}

type GameWrapper

type GameWrapper struct {
	Game         Game
	MaximumDelta float64

	Metrics *GameMetrics
	// contains filtered or unexported fields
}

func New

func New(game Game, ticksPerSecond float64) (gw *GameWrapper)

func (*GameWrapper) Start

func (gw *GameWrapper) Start()

func (*GameWrapper) Stop

func (gw *GameWrapper) Stop()

func (*GameWrapper) Wait

func (gw *GameWrapper) Wait()

Directories

Path Synopsis
example
2d/src command
3d/src command

Jump to

Keyboard shortcuts

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