Documentation
¶
Index ¶
- func WithAnimation() option
- func WithBindings(bindings input.Bindings) option
- func WithCollision() option
- func WithDefaultSystems() option
- func WithFilesystem(filesystem fs.FS) option
- func WithFixedTPS(tps int) option
- func WithMaxFrameTime(d time.Duration) option
- func WithMaxTicksPerFrame(n int) option
- func WithTimer() option
- func WithTitle(title string) option
- type Game
- func (g *Game) AddSystem(phase core.Phase, name string, system core.System) error
- func (g *Game) Advance(elapsed time.Duration) error
- func (g *Game) Alpha() float64
- func (g *Game) Context() *core.Context
- func (g *Game) MainCamera() *core.Entity
- func (g *Game) Options() Options
- func (g *Game) Pause()
- func (g *Game) Paused() bool
- func (g *Game) Quit()
- func (g *Game) Quitting() bool
- func (g *Game) Resume()
- func (g *Game) Run(r Runner) error
- func (g *Game) SetTimeScale(scale float64) error
- func (g *Game) Startup() error
- func (g *Game) TimeScale() float64
- func (g *Game) World() *core.World
- type Options
- type Runner
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 github.com/Leonard-Atorough/castrum/animation.SystemName. Without it, animations never advance and sprites keep their current drawable. Idempotent.
func WithBindings ¶ added in v0.0.3
WithBindings sets the input bindings for the game. These bindings are used to create an engine-owned input.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 github.com/Leonard-Atorough/castrum/collision.SystemName. Without it, colliders never produce github.com/Leonard-Atorough/castrum/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
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 ¶
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 github.com/Leonard-Atorough/castrum/timer.SystemName. Without it, github.com/Leonard-Atorough/castrum/timer.Timer components never advance. Idempotent.
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 ¶
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 ¶
AddSystem binds systems to a schedule under a name. Systems run in registration order. The name identifies the registration in error messages. AddSystem returns an error if the name is empty.
func (*Game) Advance ¶
Advance runs one display frame: core.PhaseFrame, then every fixed tick due for elapsed, clamped to MaxFrameTime. Runners call it once per platform frame with the time since the previous call.
While the game is paused (see Game.Pause), the frame phase still runs and DeltaTime still reports unscaled wall-clock elapsed time, but no time is accumulated and no fixed ticks run. Time scaling (see Game.SetTimeScale) multiplies only the elapsed time contributed to the fixed-loop accumulator; DeltaTime and the frame phase are unaffected. Both controls take effect on the next call.
func (*Game) Alpha ¶
Alpha returns the fixed-loop remainder over the tick interval, in [0, 1).
While the game is paused, the accumulator holds its value, so Alpha stays fixed; renderers keep the last interpolated position instead of jumping.
func (*Game) 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
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 ¶
Options returns a copy of the converged configuration. The runner reads game identity (title) from it.
func (*Game) Pause ¶ added in v0.2.0
func (g *Game) Pause()
Pause stops fixed updates: no time accumulates and no fixed ticks run. Frame updates, input polling, and rendering continue, so pause menus and overlays keep working; the frame phase sees unscaled wall-clock time. Pause takes effect on the next Game.Advance call.
Pause is not the same as a time scale of zero: pausing does not touch Game.TimeScale, and the accumulator resumes from where it stopped. Timers and animation advance with the fixed tick and therefore pause automatically; audio is not auto-paused - games opt in through the Mixer.
func (*Game) Paused ¶ added in v0.2.0
Paused reports whether fixed updates are stopped by Game.Pause.
func (*Game) Quit ¶
func (g *Game) Quit()
Quit requests termination. The active runner observes it and stops.
func (*Game) Resume ¶ added in v0.2.0
func (g *Game) Resume()
Resume reverses Game.Pause. Fixed updates continue from the exact accumulator position they stopped at, so no paused time is recovered.
func (*Game) SetTimeScale ¶ added in v0.2.0
SetTimeScale sets the multiplier applied to the time accumulated toward fixed ticks. It returns an error for a scale of zero or less; use Game.Pause to stop the simulation, a zero scale would silently discard accumulated time on resume.
The scale multiplies only the accumulator's time contribution; the frame phase and core.Context.DeltaTime during frame updates are unaffected. The new scale takes effect on the next Game.Advance call.
func (*Game) Startup ¶
Startup runs the core.PhaseStartup systems once. Runners call it before entering the platform loop; a second call returns an error.
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
// FixedTPS is the fixed simulation rate in ticks per second.
FixedTPS int
// MaxFrameTime limits the elapsed time accumulated in one frame.
MaxFrameTime time.Duration
// MaxTicksPerFrame limits catch-up ticks before the backlog is dropped.
MaxTicksPerFrame int
// InputBindings configures the engine-owned [input.ActionMap].
// If nil, no action map is created; the runner's raw input snapshot
// remains available.
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 option constructors; direct construction skips defaults and validation.
Window and graphics settings do not live here: they belong to the runner.
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
Package audioassets embeds the recordings shared by the audio examples.
|
Package audioassets embeds the recordings shared by the audio examples. |
|
audio/balance
command
Command balance demonstrates live per-source stereo balance.
|
Command balance demonstrates live per-source stereo balance. |
|
audio/mixing
command
Command mixing demonstrates master/group volume and global pause policies.
|
Command mixing demonstrates master/group volume and global pause policies. |
|
audio/playback
command
Command playback demonstrates eagerly cached OneShots and a persistent, streamed music source.
|
Command playback demonstrates eagerly cached OneShots and a persistent, streamed music source. |
|
camera
command
Command camera demonstrates camera rotation, zoom, and bounds.
|
Command camera demonstrates camera rotation, zoom, and bounds. |
|
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 or the wheel zooms.
|
Command input demonstrates bindings-driven input: WASD, arrows, or a stick drive a tank, the mouse aims the turret, QE or the wheel 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. |
|
time-control
command
Command time-control demonstrates game-level time control: two bodies orbit a marker on simulation time, and the keyboard retimes that simulation.
|
Command time-control demonstrates game-level time control: two bodies orbit a marker on simulation time, and the keyboard retimes that simulation. |
|
timer
command
Command timer demonstrates the timer component as observable state.
|
Command timer demonstrates the timer component as observable state. |
|
tween
command
Command tween demonstrates fixed-time movement and frame-time tint changes.
|
Command tween demonstrates fixed-time movement and frame-time tint changes. |
|
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 for spatial calculations, along with Lerp and easing curves for interpolation.
|
Package geom provides Vector2 and the shapes Circle, Rect, and Segment for spatial calculations, along with Lerp and easing curves for interpolation. |
|
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. |
|
Package tween provides caller-advanced Tween playheads for duration-based transitions.
|
Package tween provides caller-advanced Tween playheads for duration-based transitions. |