castrum

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 14 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.

README

castrum

Castrum is a game engine designed to provide a flexible and efficient framework for developing games. It focuses on a clear separation between configuration, simulation, and rendering, allowing developers to fine-tune their game's behavior and performance.

You declare what your game contains - an entity with a position and a picture, an entity with a looping music file - and the engine renders it, advances it, and plays it every frame. There is no draw loop to write and no play call to make.

Castrum uses Ebitengine as its underlying rendering and window management library, leveraging its capabilities to handle graphics, input, and other low-level tasks efficiently. To facilitate this, castrum wraps Ebitengine functionality within its own abstractions, providing a more structured and game-focused interface for developers.

Why Castrum

Area What works
Rendering Sprites, shapes, and text from one pipeline: standalone textures and grid atlases, fonts, a camera, interpolated motion between ticks, viewport culling, layer/sort-order/Y ordering, overlays on top of the world
Simulation A fixed-timestep loop (60 ticks per second by default) with slow-frame guards, startup/frame/fixed phases
Input Named bindings across keyboard, mouse, and gamepad - and raw per-frame polling when a game wants a key, not an action
Animation Atlas-frame clips with looping, pause, and playback rate, advanced by the engine
Collision Overlap detection for boxes and circles over layer bitmasks, with contacts as component state - detection only, no solver
Timers One-shot and repeating timers as components, with tick-stamped completion you read as state
Audio Sound effects (decoded and shared) and music (streamed from the file), a master and two group volume buses, per-play pause behavior
Structure Entities, components, queries over the world, typed resources

See the roadmap for the proposed feature sets, known gaps, and longer-term directions. Release targets are planning proposals rather than dated commitments; the guides and API reference describe what the current version actually supports.

Start here

  • Documentation - choose the introduction, concepts, first-game tutorial, or the full guides from there.
  • Examples - run complete programs covering rendering, shapes, input, animation, and audio.
  • API reference - browse exported types and methods.

Status

Castrum is pre-1.0 and moving: the API is unstable, the docs evolve with it, and the examples are kept current. Treat every release as a breaking change until the version says otherwise. See the changelog.

The name

A castrum (Latin) was a Roman fortified camp: a garrison built to a standard layout from local materials, quickly, wherever the legions needed to hold ground. The name fits an engine that aims to be the standard-built base your game stands on - small, planned, and hard to knock over.

How this is made

Castrum is developed using an AI-assisted workflow: a person owns the design, the direction, and every line that lands; AI helps implement, test, and document it; the person reviews the whole diff, and nothing merges without passing gates nobody can talk past - vet, tests, coverage, and benchmarks. The contribution policy in CONTRIBUTING.md draws the same line for others: AI assistance is welcome, delegation is not.

We declare this because it is true, and because we would rather read a one-line "built with AI assistance, reviewed by me" than guess. If castrum is part of something you make, transparency in your own style is encouraged - say what the machine did and what you did. The tooling has changed how software gets written and honesty and integrity is how we as a community build trust in each other, and in the projects we create.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAnimation added in v0.1.0

func WithAnimation() option

WithAnimation registers the engine's animation system in the fixed schedule, under animation.SystemName. Without it, animations never advance and sprites keep their current drawable. Idempotent.

func WithBindings added in v0.0.3

func WithBindings(bindings input.Bindings) option

WithBindings sets the input bindings for the game. These bindings are used to create an engine-owned ActionMap, which is provided as a resource in the world and drives input handling automatically.

func WithCollision added in v0.1.0

func WithCollision() option

WithCollision registers the engine's collision system in the fixed schedule, under collision.SystemName. Without it, colliders never produce collision.Contacts. Idempotent: passing it twice, or together with WithDefaultSystems, registers the system once.

func WithDefaultSystems added in v0.1.0

func WithDefaultSystems() option

WithDefaultSystems registers all of the engine's optional systems: animation, collision, and timer. It is equivalent to passing WithAnimation, WithCollision, and WithTimer together.

func WithFilesystem added in v0.0.3

func WithFilesystem(filesystem fs.FS) option

WithFilesystem sets the fs.FS asset paths resolve against. The default is the game's working directory.

func WithFixedTPS

func WithFixedTPS(tps int) option

WithFixedTPS sets the fixed simulation rate in ticks per second. Default is 60. Invalid values are reported by New.

func WithMaxFrameTime

func WithMaxFrameTime(d time.Duration) option

WithMaxFrameTime sets the per-frame accumulator clamp, the spiral-of-death guard. Default is 250ms. Invalid values are reported by New.

func WithMaxTicksPerFrame

func WithMaxTicksPerFrame(n int) option

WithMaxTicksPerFrame sets how many fixed ticks may run in one display frame before excess accumulated time is dropped. Default is 5. Invalid values are reported by New.

func WithTimer added in v0.1.0

func WithTimer() option

WithTimer registers the engine's timer system in the fixed schedule, under timer.SystemName. Without it, timer.Timer components never advance. Idempotent.

func WithTitle

func WithTitle(title string) option

WithTitle sets the game title. The active runner displays it.

Types

type Game

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

Game is the core engine: configuration, schedules, and the fixed loop. It is runner-agnostic: a Runner drives it and owns the window, the draw surface, and input.

func New

func New(opts ...option) (*Game, error)

New creates a Game from defaults overridden by opts. The option constructors never fail; all validation happens here in a single pass, and New returns an error for invalid values, leaving no half-built game behind.

func (*Game) AddSystem

func (g *Game) AddSystem(phase core.Phase, name string, system core.System) error

AddSystem binds systems to a schedule under a name. Systems run in registration order. The name identifies the registration in error messages and will serve as the handle for future ordering constraints; Returns an error if the name is empty.

func (*Game) Advance

func (g *Game) Advance(elapsed time.Duration) error

Advance runs one display frame: ScheduleFrame, then every fixed tick due for elapsed, clamped to MaxFrameTime. Runners call it once per platform frame with the time since the previous call.

func (*Game) Alpha

func (g *Game) Alpha() float64

Alpha returns the fixed-loop remainder over the tick interval, in [0, 1).

func (*Game) Context

func (g *Game) Context() *core.Context

Context returns the live context. Runners use it when running their draw systems; game code receives it as a system argument.

func (*Game) MainCamera added in v0.0.3

func (g *Game) MainCamera() *core.Entity

MainCamera returns the engine.s default camera entity: zoom 1 at the world origin, spawned by New. Move it by writing its Transform. Spawning your own Camera with Primary set replaces the view entirely - the collector prefers user-spawned primaries.

func (*Game) Options

func (g *Game) Options() Options

Options returns a copy of the converged configuration. The runner reads game identity (title) from it.

func (*Game) Quit

func (g *Game) Quit()

Quit requests termination. The active runner observes it and stops.

func (*Game) Quitting

func (g *Game) Quitting() bool

Quitting reports whether Quit was called.

func (*Game) Run

func (g *Game) Run(r Runner) error

Run hands control to r. It may be called once; a second call returns an error.

func (*Game) Startup

func (g *Game) Startup() error

Startup runs the ScheduleStartup systems once. Runners call it before entering the platform loop; a second call returns an error.

func (*Game) World

func (g *Game) World() *core.World

World returns the game's world: entities and resources live there.

type Options

type Options struct {
	// Title is the game's identity; the runner displays it.
	Title string

	// Filesystem is the fs.FS asset paths resolve against: embed.FS
	// for single-binary distribution, os.DirFS for development
	// layouts. nil - the zero value - is the game's working
	// directory.
	Filesystem fs.FS

	// Simulation contract: developer decisions, not player preferences.
	FixedTPS         int
	MaxFrameTime     time.Duration
	MaxTicksPerFrame int

	// InputBindings is the mapping from user actions to physical inputs.
	// It provides an engine-native way to map raw inputs to high-level actions.
	//
	// When provided, the bindings can be accessed on the Context through [core.Context.Actions].
	//
	// If nil, no engine-owned ActionMap is created, and input must be polled manually through [core.Context.Input].
	InputBindings input.Bindings
	// contains filtered or unexported fields
}

Options is the pure-data configuration New converges option values into. It carries only data, never callbacks or handles, so a future file-backed Config type can map onto it 1:1. Populate it through New and the [With*] constructors; direct construction skips defaults and validation.

Window and graphics settings do not live here: they belong to the runner.

func (Options) FixedDT

func (o Options) FixedDT() time.Duration

FixedDT returns the derived interval between fixed ticks.

type Runner

type Runner interface {
	Run() error
}

Runner drives a Game: it owns the platform loop, the draw surface, and input, and calls the Game loop hooks. Run blocks until the game quits.

Directories

Path Synopsis
Package animation provides animation components, clip storage, and a system that advances sprite playback on fixed ticks.
Package animation provides animation components, clip storage, and a system that advances sprite playback on fixed ticks.
Package asset loads, decodes, and caches typed assets from an fs.FS.
Package asset loads, decodes, and caches typed assets from an fs.FS.
Package audio defines backend-independent audio playback.
Package audio defines backend-independent audio playback.
Package collision detects overlaps between entity colliders and records them in Contacts.
Package collision detects overlaps between entity colliders and records them in Contacts.
Package core provides World-owned entities and resources, Query iteration over components, and the System and Context contracts for updating a game.
Package core provides World-owned entities and resources, Query iteration over components, and the System and Context contracts for updating a game.
Package ebitrun provides the default Ebitengine-backed Runner for castrum.
Package ebitrun provides the default Ebitengine-backed Runner for castrum.
examples
animate command
Command animate demonstrates frame animation: a torch flickers through a grid-atlas clip at a fixed frame rate, driven entirely by engine wiring - the game only registers the atlas, the clip, and the entity; the renderer stays animation-blind.
Command animate demonstrates frame animation: a torch flickers through a grid-atlas clip at a fixed frame rate, driven entirely by engine wiring - the game only registers the atlas, the clip, and the entity; the renderer stays animation-blind.
audio command
Command audio demonstrates audio playback end to end: SPACE plays a sound effect (eager, decoded once and shared), a music track loops from the file (streamed, never fully in memory), the arrow keys sweep the master and music volumes, and ENTER toggles the global pause - the music holds while the effect plays through, because each play states its own pause behavior.
Command audio demonstrates audio playback end to end: SPACE plays a sound effect (eager, decoded once and shared), a music track loops from the file (streamed, never fully in memory), the arrow keys sweep the master and music volumes, and ENTER toggles the global pause - the music holds while the effect plays through, because each play states its own pause behavior.
collision command
Command collision demonstrates the collision stack: circle and rect colliders, layered masks, trigger pickups, a rotation-aware narrow phase, and the Contacts lifecycle read as component state - bar hits drain health and speed once per enter edge, pickups heal.
Command collision demonstrates the collision stack: circle and rect colliders, layered masks, trigger pickups, a rotation-aware narrow phase, and the Contacts lifecycle read as component state - bar hits drain health and speed once per enter edge, pickups heal.
input command
Command input demonstrates bindings-driven input: WASD, arrows, or a stick drive a tank, the mouse aims the turret, QE zooms.
Command input demonstrates bindings-driven input: WASD, arrows, or a stick drive a tank, the mouse aims the turret, QE zooms.
primitive command
Command primitive demonstrates the shape drawables as a spectrum: one row per shape kind - rect, circle/ellipse, line - and one column per variant - filled, outlined, spinning, stretched by the transform's scale, half-faded.
Command primitive demonstrates the shape drawables as a spectrum: one row per shape kind - rect, circle/ellipse, line - and one column per variant - filled, outlined, spinning, stretched by the transform's scale, half-faded.
text command
Command text demonstrates text rendering: a static label, a per-tick counter whose string updates like a score display, and tinted and scaled text.
Command text demonstrates text rendering: a static label, a per-tick counter whose string updates like a score display, and tinted and scaled text.
timer command
Command timer demonstrates the timer component as observable state.
Command timer demonstrates the timer component as observable state.
wander command
Command wander demonstrates the engine renderer: an atlas sprite wanders to random screen points at fixed ticks, the engine renders it interpolated between ticks, and a user DrawFunc draws an overlay above the engine-rendered world.
Command wander demonstrates the engine renderer: an atlas sprite wanders to random screen points at fixed ticks, the engine renders it interpolated between ticks, and a user DrawFunc draws an overlay above the engine-rendered world.
your-first-game command
Command your-first-game is the companion program to the getting started tutorial: a tank that drives with the keyboard and aims its turret at the mouse, from a camera that follows it.
Command your-first-game is the companion program to the getting started tutorial: a tank that drives with the keyboard and aims its turret at the mouse, from a camera that follows it.
Package geom provides Vector2 and the shapes Circle, Rect, and Segment, with methods for common spatial calculations.
Package geom provides Vector2 and the shapes Circle, Rect, and Segment, with methods for common spatial calculations.
Package input provides backend-independent keyboard, mouse, and gamepad types.
Package input provides backend-independent keyboard, mouse, and gamepad types.
internal
ecs
Package ecs stores entities in archetypes grouped by component type sets.
Package ecs stores entities in archetypes grouped by component type sets.
runtime
Package runtime provides ordered execution of systems for a core phase.
Package runtime provides ordered execution of systems for a core phase.
spatial
Package spatial provides a uniform grid for broad-phase spatial queries.
Package spatial provides a uniform grid for broad-phase spatial queries.
Package render defines drawable components and camera state, then resolves them into ordered DrawList values for a renderer to draw.
Package render defines drawable components and camera state, then resolves them into ordered DrawList values for a renderer to draw.
Package timer provides countdowns as Timer components.
Package timer provides countdowns as Timer components.

Jump to

Keyboard shortcuts

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