engine

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package engine is what the host needs from something that runs a game: a libretro core in production, a small built-in core in tests.

Index

Constants

View Source
const (
	Format0RGB1555 = 0
	FormatXRGB8888 = 1
	FormatRGB565   = 2
)

Pixel formats, numbered as libretro numbers them.

View Source
const (
	ButtonB = iota
	ButtonY
	ButtonSelect
	ButtonStart
	ButtonUp
	ButtonDown
	ButtonLeft
	ButtonRight
	ButtonA
	ButtonX
	ButtonL
	ButtonR
	ButtonL2
	ButtonR2
	ButtonL3
	ButtonR3
)

RetroPad buttons, as bit numbers in PadState.Buttons.

View Source
const MaxPorts = 8

MaxPorts is how many players the protocol carries input for.

Variables

This section is empty.

Functions

func BytesPerPixel

func BytesPerPixel(format int) int

BytesPerPixel for a pixel format.

Types

type AVInfo

type AVInfo struct {
	BaseWidth, BaseHeight int
	MaxWidth, MaxHeight   int
	Aspect                float64
	FPS                   float64
	SampleRate            float64
}

AVInfo is what an engine says about its output.

type Cheats added in v0.3.3

type Cheats interface {
	CheatReset()
	CheatSet(index int, enabled bool, code string)
}

Cheats is an engine that takes cheat codes.

type DeviceType added in v0.3.3

type DeviceType struct {
	ID   uint32
	Name string
}

DeviceType is a kind of controller a game can have plugged in.

type Devices added in v0.3.3

type Devices interface {
	ControllerPorts() []PortDevices
	SetDevice(port int, id uint32)
}

Devices is an engine that offers a choice of controller for its ports.

type Discs added in v0.3.3

type Discs interface {
	Disc() (index, count int)
	ChangeDisc(index int) bool
}

Discs is what an engine has if it can change discs: the game may ask for the next one, and the player has to be able to put it in.

type Engine

type Engine interface {
	SystemInfo() SystemInfo
	LoadGame(path string) (AVInfo, error)
	Run()
	Reset()
	SaveState() []byte
	LoadState(b []byte) bool
	SaveRAM() []byte // the engine's own memory; nil when the game has none
	Close()
}

Engine runs one game. Every method is called from one locked OS thread.

type Handlers

type Handlers struct {
	Video func(data []byte, width, height, stride, format int)
	// VideoFlipped is Video for a frame whose first row in memory is the bottom
	// of the picture, as OpenGL reads them.
	VideoFlipped func(data []byte, width, height, stride, format int)
	Dupe         func() // the previous frame again
	Audio        func(stereo []int16)
	Input        func() *[MaxPorts]PadState // once a frame
	Pointer      func() PointerState        // once a frame
	Touches      func() []PointerState      // every finger on a touch screen, once a frame; the first is Pointer's
	// Motion, for a game that reads a device's movement. MotionOffered says the engine can read it
	// at all; MotionWanted that the game wants it from this player now, or no longer, and how often.
	MotionOffered func()
	MotionWanted  func(port int, accel, gyro bool, hz int)
	Motion        func(port int) MotionState
	LED           func(index, state int) // a light the game turns on or off, or to a brightness
	Rumble        func(port, effect, strength int)
	Message       func(text string)
	Log           func(level int, text string)
	Geometry      func(width, height int, aspect float64)
	Rotation      func(quarterTurns int)
	AVInfo        func(info AVInfo)
	Shutdown      func()
	Trace         func(text string) // everything a core says and is refused; only set when testing
}

Handlers receive what an engine produces. All are called on the thread running Run, and slices are only valid during the call. Any may be nil.

type MotionState added in v0.3.5

type MotionState struct {
	Accel, Gyro [3]float32
}

MotionState is one player's motion: accelerometer in metres a second squared, gyroscope in radians a second, X, Y and Z, as libretro's cores take them.

type Option added in v0.3.3

type Option struct {
	Key      string
	Label    string
	Info     string // a longer description
	Category string // the heading it belongs under
	Choices  []string
	Labels   []string // the name of each choice, when the core gives them
	Default  string
	Value    string
	Hidden   bool // the core says it doesn't apply just now
}

Option is one setting an engine offers. The first choice is its default.

type Options added in v0.3.3

type Options interface {
	Options() []Option
	SetOption(key, value string) bool
}

Options is an engine with settings of its own. SetOption refuses a key or a value the engine didn't offer.

type OptionsChanged added in v0.3.3

type OptionsChanged interface {
	OptionsChanged() bool
}

OptionsChanged is an engine whose options can change on their own: it says when they have.

type Output added in v0.3.3

type Output interface {
	SetOutput(video, audio, fastForward bool)
}

Output tells an engine what's wanted from the next frame, so that one which can skip drawing or mixing saves the work.

type PadState

type PadState struct {
	Buttons uint16
	LX, LY  int16
	RX, RY  int16
	L2, R2  uint8 // how far the analog triggers are held; 0 when only their buttons are known
}

PadState is one player's input.

type PointerState added in v0.3.3

type PointerState struct {
	X, Y    int16
	Pressed bool
}

PointerState is a touch screen or mouse. X and Y run from -32767 to 32767 across the picture, as libretro counts them.

type PortDevices added in v0.3.3

type PortDevices struct {
	Port    int
	Types   []DeviceType
	Current uint32
}

PortDevices is what can be plugged into one player's port.

type ProbeDetails added in v0.3.3

type ProbeDetails struct {
	NoGame, HWRender bool
	Options          int
}

ProbeDetails is what a test-load finds out beyond SystemInfo.

type Prober added in v0.3.3

type Prober interface {
	ProbeDetails() ProbeDetails
}

Prober is an engine that noticed more while loading than SystemInfo says.

type StateInto added in v0.3.3

type StateInto interface {
	SaveStateInto(buf []byte) []byte
}

StateInto is an engine that can save a state into a buffer it's given, for taking one every frame without making garbage. It returns nil when it can't.

type SystemInfo

type SystemInfo struct {
	Name, Version string
	Extensions    []string
	NeedFullPath  bool
	BlockExtract  bool
}

SystemInfo is an engine's description of itself.

Jump to

Keyboard shortcuts

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