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 WithScenes() 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) AddSystemToGroup(phase core.Phase, group, 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) SetGroupEnabled(group string, enabled bool) 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 enables animation updates during fixed updates. Without it, animated sprites do not advance.
func WithBindings ¶ added in v0.0.3
WithBindings configures the game's input bindings.
func WithCollision ¶ added in v0.1.0
func WithCollision() option
WithCollision enables collision processing during fixed updates. Without it, colliders do not produce contacts. Passing it more than once, or with WithDefaultSystems, has no additional effect.
func WithDefaultSystems ¶ added in v0.1.0
func WithDefaultSystems() option
WithDefaultSystems enables animation, collision, and timer processing. It is equivalent to passing WithAnimation, WithCollision, WithTimer, and WithScenes.
func WithFilesystem ¶ added in v0.0.3
WithFilesystem sets the filesystem used to resolve game assets. Built-in assets under "builtin/" remain available.
func WithFixedTPS ¶
func WithFixedTPS(tps int) option
WithFixedTPS sets the fixed simulation rate in ticks per second. The default is 60. New returns an error if the rate is invalid.
func WithMaxFrameTime ¶
WithMaxFrameTime sets the maximum elapsed time accepted for one frame. The default is 250 ms. New returns an error if d is not positive.
func WithMaxTicksPerFrame ¶
func WithMaxTicksPerFrame(n int) option
WithMaxTicksPerFrame sets the maximum number of fixed ticks run in one display frame. The default is 5. New returns an error if n is not positive.
func WithScenes ¶ added in v0.3.0
func WithScenes() option
WithScenes enables the scene system and provides a scene Director resource.
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game owns a game's world, configuration, and update schedules. A Runner supplies the platform loop, window, draw surface, and input.
func New ¶
New creates a Game with default options overridden by opts. It returns an error if the resulting configuration is invalid.
The asset loader resolves engine-shipped assets under "builtin/" alongside the configured filesystem.
func (*Game) AddSystem ¶
AddSystem registers an ungrouped system under name in phase's schedule. Systems run in registration order. It returns an error if name is empty.
func (*Game) AddSystemToGroup ¶ added in v0.3.0
AddSystemToGroup registers a system under name in phase's schedule, optionally assigning it to group. Systems run in registration order.
An empty group leaves the system ungrouped. The name appears in error messages; an empty name returns an error. Named groups start enabled and retain their state when systems are registered later.
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 default camera created by New, positioned at the world origin with zoom 1. Set its core.Transform to move it. A user-spawned primary camera takes precedence.
func (*Game) Options ¶
Options returns a copy of the game's configuration. Runners use it to read the game title.
func (*Game) Pause ¶ added in v0.2.0
func (g *Game) Pause()
Pause stops fixed updates and stops adding time to the fixed-loop accumulator. Frame updates still run, so input and rendering can continue. The change takes effect on the next Game.Advance call.
Pausing does not change Game.TimeScale or discard the accumulator. Game.Resume continues from where the game stopped. Audio is not paused automatically.
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 clears the paused state. The next Game.Advance continues fixed updates from the accumulator position preserved by Game.Pause.
func (*Game) SetGroupEnabled ¶ added in v0.3.0
SetGroupEnabled enables or disables a registered group across all phases. The state also applies to systems registered in the group later. It returns an error if group is empty or has no registered systems. A change affects subsequent systems, including later systems in the current phase.
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 fixed updates while preserving the accumulator.
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 title displayed by the runner.
Title string
// Filesystem supplies game asset files. Engine-shipped assets under
// "builtin/" are available alongside it. If nil, game assets resolve from
// the current working directory.
Filesystem fs.FS
// FixedTPS is the number of fixed simulation ticks per second.
FixedTPS int
// MaxFrameTime is the maximum elapsed time accepted for one frame.
MaxFrameTime time.Duration
// MaxTicksPerFrame is the maximum number of fixed ticks run in one display
// frame.
MaxTicksPerFrame int
// InputBindings configures the engine-owned [input.ActionMap]. If nil, no
// action map is created, but the runner's raw input snapshot remains
// available.
InputBindings input.Bindings
// contains filtered or unexported fields
}
Options contains the configuration used to create a Game. Use New with option constructors to apply defaults and validate values.
Window and graphics settings belong to the runner.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package animation provides animation components, clip storage, and a system that advances sprite playback on fixed ticks and emits a Completed signal when an animation finishes its clip.
|
Package animation provides animation components, clip storage, and a system that advances sprite playback on fixed ticks and emits a Completed signal when an animation finishes its clip. |
|
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 builtin provides engine-shipped assets, currently the Go Regular font.
|
Package builtin provides engine-shipped assets, currently the Go Regular font. |
|
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 debug provides the world-owned Panel used to show status readouts, recent messages, and built-in frame and tick rates in the development overlay.
|
Package debug provides the world-owned Panel used to show status readouts, recent messages, and built-in frame and tick rates in the development overlay. |
|
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. |
|
scenes
command
Command scenes demonstrates scene transitions and entity queries.
|
Command scenes demonstrates scene transitions and entity queries. |
|
signal-salvage
command
Command signal-salvage is a small, asset-free game built from Castrum's scenes, signals, collision, timers, system groups, and built-in font.
|
Command signal-salvage is a small, asset-free game built from Castrum's scenes, signals, collision, timers, system groups, and built-in font. |
|
signals
command
Command signals demonstrates reacting to an existing signal and authoring new ones, as one repeating cycle of a small launch sequence.
|
Command signals demonstrates reacting to an existing signal and authoring new ones, as one repeating cycle of a small launch sequence. |
|
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 the debug overlay draws its rates 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 the debug overlay draws its rates above the engine-rendered world. |
|
your-first-game
command
Command your-first-game is the companion program to the getting-started tutorial.
|
Command your-first-game is the companion program to the getting-started tutorial. |
|
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 scene defines scene blueprints and manages their runtime instances.
|
Package scene defines scene blueprints and manages their runtime instances. |
|
Package signal provides typed, pull-based broadcasts for systems.
|
Package signal provides typed, pull-based broadcasts for systems. |
|
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. |