engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine interface {
	common.Delegate[Engine]

	// Window returns the underlying window.
	//
	// Returns:
	//   - window.Window: the window instance
	Window() window.Window

	// EnableProfiler enables performance profiling output to the log.
	EnableProfiler()

	// DisableProfiler disables performance profiling output.
	DisableProfiler()

	// SetTickRate sets the engine tick rate in frames per second.
	// The tick callback will be called at this rate for game logic updates.
	//
	// Parameters:
	//   - fps: target frames per second (defaults to 60 if <= 0)
	SetTickRate(fps float64)

	// SetTickCallback registers the function called each engine tick.
	// Use this for game logic, physics, input processing, and animation updates.
	//
	// Parameters:
	//   - callback: function to call at the configured tick rate, receiving the delta time in seconds
	SetTickCallback(callback func(deltaTime float32))

	// SetRenderCallback registers the function called each render frame.
	// Use this for GPU buffer updates and scene rendering.
	//
	// Parameters:
	//   - callback: function to call each render frame, receiving the delta time in seconds
	SetRenderCallback(callback func(deltaTime float32))

	// SetRenderFrameLimit sets an optional render frame rate cap in frames per second.
	// Pass 0 to uncap the render loop (default).
	//
	// Parameters:
	//   - fps: maximum render frames per second (0 = uncapped)
	SetRenderFrameLimit(fps float64)

	// AddScene registers a scene at the given z-index key.
	// Scenes are rendered in ascending key order during the render loop.
	//
	// Parameters:
	//   - key: the z-index determining render order (lower renders first)
	//   - s: the Scene to register
	AddScene(key int, s scene.Scene)

	// RemoveScene removes the scene at the given z-index key.
	//
	// Parameters:
	//   - key: the z-index of the scene to remove
	RemoveScene(key int)

	// Scene retrieves the scene registered at the given z-index key.
	// Returns nil if no scene exists at that key.
	//
	// Parameters:
	//   - key: the z-index of the scene to retrieve
	//
	// Returns:
	//   - scene.Scene: the scene at the key, or nil if not found
	Scene(key int) scene.Scene

	// Scenes returns a copy of all registered scenes keyed by z-index.
	//
	// Returns:
	//   - map[int]scene.Scene: a copy of the scenes map
	Scenes() map[int]scene.Scene

	// Run starts the main engine loop (blocks until window closes).
	Run()

	// Quit signals all engine goroutines to stop and shuts down the engine.
	// This is an alternative to submitting a MessageShutdown message.
	// Safe to call multiple times; subsequent calls are no-ops.
	Quit()
}

Engine is the main entry point for the engine. It orchestrates the engine loop, render loop, and window management.

func NewEngine

func NewEngine(options ...EngineBuilderOption) Engine

NewEngine creates a new Engine instance with the provided options. Initializes message channels and profiler with sensible defaults. Options are applied directly to the engine struct via the option-builder pattern.

Parameters:

  • options: functional options for engine configuration (profiling, tick rate, etc.)

Returns:

  • Engine: the newly created engine

type EngineBuilderOption

type EngineBuilderOption func(*engine)

EngineBuilderOption is a functional option for configuring an Engine. Use the With* functions to create options that are applied directly to the engine instance.

func WithProfiling

func WithProfiling(enabled bool) EngineBuilderOption

WithProfiling enables or disables performance profiling output.

Parameters:

  • enabled: if true, enables performance profiling

Returns:

  • EngineBuilderOption: option function to apply

func WithRenderFrameLimit

func WithRenderFrameLimit(fps float64) EngineBuilderOption

WithRenderFrameLimit sets an optional render frame rate cap in frames per second. Pass 0 to uncap the render loop (default).

Parameters:

  • fps: maximum render frames per second (0 = uncapped)

Returns:

  • EngineBuilderOption: option function to apply

func WithScene

func WithScene(key int, s scene.Scene) EngineBuilderOption

WithScene registers a scene at the given z-index key during engine construction. Scenes are rendered in ascending key order during the render loop.

Parameters:

  • key: the z-index determining render order (lower renders first)
  • s: the Scene to register

Returns:

  • EngineBuilderOption: option function to apply

func WithTickRate

func WithTickRate(fps float64) EngineBuilderOption

WithTickRate sets the engine tick rate in frames per second. The tick callback will be called at this rate for game logic updates. Values <= 0 will be treated as the default (60Hz).

Parameters:

  • fps: target ticks per second (default 60)

Returns:

  • EngineBuilderOption: option function to apply

func WithWindow

func WithWindow(w window.Window) EngineBuilderOption

WithWindow sets a custom configured window for the engine to use rather than allowing the engine to create and manage one internally.

Parameters:

  • w: a pre-configured Window instance

Returns:

  • EngineBuilderOption: option function to apply

Directories

Path Synopsis
gltf_types.go contains glTF 2.0 spec data structures for JSON deserialization.
gltf_types.go contains glTF 2.0 spec data structures for JSON deserialization.
shader
annotations.go defines the annotation types, argument constants, and parser for the Oxy WGSL shader pre-processor.
annotations.go defines the annotation types, argument constants, and parser for the Oxy WGSL shader pre-processor.

Jump to

Keyboard shortcuts

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