ebitrun

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 32 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ebitrun provides the default Ebitengine-backed Runner for castrum. The runner owns the window, draw surface, and input; castrum.Game owns configuration, schedules, and the fixed loop.

Index

Constants

View Source
const AudioSystemName = audio.SystemName

AudioSystemName is the name of the game's audio reconciler.

Variables

This section is empty.

Functions

func NewAssetCodecs added in v0.4.0

func NewAssetCodecs() *asset.Codecs

NewAssetCodecs returns Castrum's defaults with JSON codecs for DisplayPreferences. Use it for preference loaders and savers before constructing a runner.

Each call returns independent codecs. Custom registrations are visible to facades built from these codecs, including ones built earlier. Audio data decoders are installed on these codecs by New at the effective audio sample rate, for each format that has no decoder yet; a decoder set before New is kept.

func NewDisplayPreferences added in v0.4.0

func NewDisplayPreferences() (*settings.Group[DisplayPreferences], error)

NewDisplayPreferences returns a group with the runner's default window settings. Changes do not affect a runner that has already been constructed.

func Run added in v0.4.0

func Run(g *castrum.Game, opts ...option)

Run creates a Runner with opts and runs g. It is the one-call form of New followed by Runner.Run and panics like both.

func WithAudioSampleRate added in v0.0.4

func WithAudioSampleRate(sampleRate int) option

WithAudioSampleRate sets the sample rate in Hz for the audio context created by the runner. An existing Ebitengine audio context is reused instead. Audio sources are resampled to this rate when decoded. The default is 44100; invalid values are reported by New.

func WithDebugOverlay added in v0.1.0

func WithDebugOverlay() option

WithDebugOverlay draws a development overlay in the window's top-left corner: fps counts the display frames rendered per second, tps counts the fixed simulation ticks the engine advances per second, and the game's paused state and time scale appear whenever they depart from running at full speed. The overlay draws only - it never changes simulation timing or game state - and is off unless the option is passed.

func WithDisplayPreferences added in v0.4.0

func WithDisplayPreferences(prefs DisplayPreferences) option

WithDisplayPreferences sets the runner's startup window settings. Later options can override these settings. Invalid values are reported by New.

func WithFullscreen added in v0.4.0

func WithFullscreen() option

WithFullscreen enables fullscreen mode. Default is windowed.

func WithLogicalSize

func WithLogicalSize(width, height int) option

WithLogicalSize sets the internal render resolution in pixels. Default is 1280x720. Invalid values are reported by New.

func WithResizable

func WithResizable() option

WithResizable enables window resizing. Default is a fixed-size window.

func WithWindowSize

func WithWindowSize(width, height int) option

WithWindowSize sets the window size in pixels. Default is 1280x720. Invalid values are reported by New.

func WithoutBordered added in v0.4.0

func WithoutBordered() option

WithoutBordered disables window decorations such as the title bar and border. Default is on.

func WithoutVSync

func WithoutVSync() option

WithoutVSync disables vsync. Default is on.

Types

type DisplayPreferences added in v0.4.0

type DisplayPreferences struct {
	// Window is the initial window size in pixels.
	Window Size `json:"window"`
	// Resizable permits window resizing.
	Resizable bool `json:"resizable"`
	// VSync enables vertical synchronization.
	VSync bool `json:"vsync"`
}

DisplayPreferences holds JSON-serializable desired startup window settings.

func (DisplayPreferences) Validate added in v0.4.0

func (p DisplayPreferences) Validate() error

Validate reports an error if the window size is not positive.

type DrawFunc

type DrawFunc func(ctx *core.Context, screen *ebiten.Image, alpha float64) error

DrawFunc renders one frame to the runner's Ebitengine canvas.

type FontProvider added in v0.1.0

type FontProvider struct {
	// contains filtered or unexported fields
}

FontProvider caches Ebitengine drawing faces for loaded fonts. Text measurements come from asset.FontData.Measure, keeping drawing aligned with the engine's measured bounds.

New provides FontProvider as a resource for the engine renderer and user draw functions.

func (*FontProvider) Face added in v0.1.0

func (p *FontProvider) Face(font asset.ID, size float64) (*text.GoTextFace, error)

Face returns the cached drawing face for font at size, creating it from the loaded font asset as needed. Errors identify the font.

type Options

type Options struct {
	// Window is the initial window size in pixels.
	Window Size
	// Resizable controls whether the window can be resized.
	Resizable bool
	// VSync enables vertical synchronization.
	VSync bool
	// Bordered controls whether the window has decorations such
	// as a title bar and border.
	Bordered bool
	// Fullscreen controls whether the window starts in fullscreen mode.
	Fullscreen bool
	// Logical is the internal render size in pixels.
	Logical Size
	// SampleRate is the audio context's mixing rate in Hz, used when the
	// runner creates the context.
	SampleRate int
	// DebugOverlay draws the frame and tick rates in the window's
	// top-left corner. Default is off.
	DebugOverlay bool
}

Options configures the Ebitengine window, logical render size, and audio context.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner drives a castrum.Game with Ebitengine.

Start the game with Runner.Run.

func New

func New(opts ...option) *Runner

New creates a Runner with opts applied over the defaults. It panics for an invalid option and performs no other setup until Runner.Run.

func (*Runner) AddDraw

func (r *Runner) AddDraw(f DrawFunc)

AddDraw appends f to the user draw callbacks. They run in registration order, after the engine renders the world.

func (*Runner) Draw

func (r *Runner) Draw(screen *ebiten.Image)

Draw renders the engine's world, then the registered user callbacks, with the current interpolation alpha. It runs every callback even if one fails; the first error is returned by Runner.Update on the next frame.

func (*Runner) Layout

func (r *Runner) Layout(outsideWidth, outsideHeight int) (int, int)

Layout returns the current logical render size, independent of the window size, and records the window size in the render.Window resource.

func (*Runner) Run

func (r *Runner) Run(g *castrum.Game)

Run binds g, applies the window settings, starts the game, and blocks in the Ebitengine loop until it quits. It panics on a running failure.

func (*Runner) Update

func (r *Runner) Update() error

Update advances the game by elapsed platform time and reports quit requests to Ebitengine. Errors from Runner.Draw are returned here on the next frame because Ebitengine's Draw callback cannot return an error.

type Size

type Size struct {
	// Width is the horizontal dimension in pixels.
	Width int `json:"width"`
	// Height is the vertical dimension in pixels.
	Height int `json:"height"`
}

Size is a pixel dimension used for window or logical resolution.

type TextureProvider

type TextureProvider struct {
	// contains filtered or unexported fields
}

TextureProvider is the runner's GPU half of the asset pipeline: it converts decoded textures to ebiten images at most once per texture path and materializes subimages at most once per path and rect. Sheet files resolve through the same loader as their textures; memory references retain sheet metadata directly.

Texture and SubImageRect map one-to-one onto the DrawItem source variants the collector produces: an empty Rect routes to Texture, a populated one to SubImageRect.

New provides the provider as a resource; the engine renderer and user DrawFuncs resolve it through the locator.

func (*TextureProvider) SubImage

func (p *TextureProvider) SubImage(source asset.SheetRef, regionName string) (*ebiten.Image, error)

SubImage resolves a sheet region to its GPU subimage. The sheet texture is converted on first use and shared by all its regions; errors name the document, missing region, or texture path.

func (*TextureProvider) SubImageRect

func (p *TextureProvider) SubImageRect(texturePath asset.ID, rect image.Rectangle) (*ebiten.Image, error)

SubImageRect returns the GPU subimage of texturePath at rect, in pixel coordinates. The rect must be non-empty and lie within the texture; all rectangles are validated here. Errors name the texture path and the rect.

func (*TextureProvider) Texture

func (p *TextureProvider) Texture(path asset.ID) (*ebiten.Image, error)

Texture returns the whole GPU image for a texture path, converting it from the loader's decoded cache on first use. Errors name the path.

type ViewportChanged added in v0.4.0

type ViewportChanged struct {
	OldWidth  int
	OldHeight int
	NewWidth  int
	NewHeight int
}

ViewportChanged is emitted when the window's viewport changes size. It contains the old and new logical dimensions of the viewport.

It is emitted by the Runner when the window's layout changes.

Jump to

Keyboard shortcuts

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