Documentation ¶
Overview ¶
Package oak is a game engine. It provides scene control, control over windows and what is drawn to them, propagates regular events to evaluate game logic, and so on.
A minimal oak app follows:
func main() { oak.AddScene("myApp", scene.Scene{Start: func(ctx *scene.Context) { // ... ctx.Draw(...), event.Bind(ctx, ...) }}) oak.Init("myApp") }
Index ¶
- Variables
- func AddScene(name string, sc scene.Scene) error
- func Bounds() intgeom.Point2
- func GetCursorPosition() (x, y float64)
- func HideCursor() error
- func Init(scene string, configOptions ...ConfigOption) error
- func IsDown(k key.Code) bool
- func IsHeld(k key.Code) (bool, time.Duration)
- func MoveWindow(x, y, w, h int) error
- func ScreenShot() *image.RGBA
- func SetBackground(b Background)
- func SetBorderless(bs bool) error
- func SetColorBackground(img image.Image)
- func SetFS(filesystem fs.FS)
- func SetFullScreen(fs bool) error
- func SetIcon(icon image.Image) error
- func SetLoadingRenderable(r render.Renderable)
- func SetTitle(title string) error
- func SetTopMost(on bool) error
- func SetViewport(pt intgeom.Point2)
- func SetViewportBounds(rect intgeom.Rect2)
- func ShiftViewport(pt intgeom.Point2)
- func UpdateViewSize(w, h int) error
- type Assets
- type Background
- type BatchLoadOptions
- type Config
- type ConfigOption
- type Debug
- type Driver
- type InputType
- type Screen
- type Viewport
- type Window
- func (w *Window) AddScene(name string, s scene.Scene) error
- func (w *Window) Bounds() intgeom.Point2
- func (w *Window) ChangeWindow(width, height int) error
- func (w *Window) ClearScreenFilter()
- func (w *Window) DoBetweenDraws(f func())
- func (w *Window) EventHandler() event.Handler
- func (w *Window) GetBackgroundImage() image.Image
- func (w *Window) GoToScene(nextScene string)
- func (w *Window) InFocus() bool
- func (w *Window) Init(firstScene string, configOptions ...ConfigOption) error
- func (w *Window) MostRecentInput() InputType
- func (w *Window) NextScene()
- func (w *Window) Propagate(ev event.EventID[*mouse.Event], me mouse.Event)
- func (w *Window) Quit()
- func (w *Window) RecordGIF(hundredths int) (stop func() *gif.GIF)
- func (w *Window) RemoveViewportBounds()
- func (w *Window) ScreenShot() *image.RGBA
- func (w *Window) SetAspectRatio(xToY float64)
- func (w *Window) SetBackground(b Background)
- func (w *Window) SetColorBackground(img image.Image)
- func (w *Window) SetDrawFilter(screenFilter mod.Filter)
- func (w *Window) SetLoadingRenderable(r render.Renderable)
- func (w *Window) SetLogicHandler(h event.Handler)
- func (w *Window) SetPalette(palette color.Palette)
- func (w *Window) SetViewport(pt intgeom.Point2)
- func (w *Window) SetViewportBounds(rect intgeom.Rect2)
- func (w *Window) ShiftViewport(delta intgeom.Point2)
- func (w *Window) TriggerKeyDown(e okey.Event)
- func (w *Window) TriggerKeyHeld(e okey.Event)
- func (w *Window) TriggerKeyUp(e okey.Event)
- func (w *Window) TriggerMouseEvent(mevent omouse.Event)
- func (w *Window) UpdateViewSize(width, height int) error
- func (w *Window) Viewport() intgeom.Point2
- func (w *Window) ViewportBounds() (rect intgeom.Rect2, ok bool)
Constants ¶
This section is empty.
Variables ¶
var ( // ViewportUpdate is triggered when the position of of the viewport changes ViewportUpdate = event.RegisterEvent[intgeom.Point2]() // OnStop is triggered when the engine is stopped, e.g. when a window's close // button is clicked. OnStop = event.RegisterEvent[struct{}]() // FocusGain is triggered when a window gains focus FocusGain = event.RegisterEvent[struct{}]() // FocusLoss is triggered when a window loses focus FocusLoss = event.RegisterEvent[struct{}]() // InputChange is triggered when the most recent input device changes (e.g. keyboard to joystick or vice versa). It // is only sent if Config.TrackInputChanges is true when Init is called. InputChange = event.RegisterEvent[InputType]() )
The following block defines events generated by oak during scene execution
Functions ¶
func GetCursorPosition ¶
func GetCursorPosition() (x, y float64)
GetCursorPosition calls GetCursorPosition on the default window.
func Init ¶
func Init(scene string, configOptions ...ConfigOption) error
Init calls Init on the default window. The default window will be set to use render.GlobalDrawStack and event.DefaultBus.
func MoveWindow ¶
MoveWindow calls MoveWindow on the default window.
func SetBackground ¶
func SetBackground(b Background)
SetBackground calls SetBackground on the default window.
func SetBorderless ¶
SetBorderless calls SetBorderless on the default window.
func SetColorBackground ¶
SetColorBackground calls SetColorBackground on the default window.
func SetFS ¶
SetFS updates all calls oak or oak's subpackages will make to read from the given filesystem. By default, this is set to os.DirFS(".")
func SetFullScreen ¶
SetFullScreen calls SetFullScreen on the default window.
func SetLoadingRenderable ¶
func SetLoadingRenderable(r render.Renderable)
SetLoadingRenderable calls SetLoadingRenderable on the default window.
func SetViewport ¶
SetViewport calls SetViewport on the default window.
func SetViewportBounds ¶
SetViewportBounds calls SetViewportBounds on the default window.
func ShiftViewport ¶
ShiftViewport calls ShiftViewport on the default window.
func UpdateViewSize ¶
UpdateViewSize calls UpdateViewSize on the default window.
Types ¶
type Background ¶
A Background can be used as a background draw layer. Backgrounds will be drawn as the first element in each frame, and are expected to cover up data drawn on the previous frame.
type BatchLoadOptions ¶
type BatchLoadOptions struct { BlankOutAudio bool `json:"blankOutAudio"` MaxImageFileSize int64 `json:"maxImageFileSize"` }
BatchLoadOptions is a json type storing customizations for batch loading. These settings do not take effect unless Config.BatchLoad is true.
type Config ¶
type Config struct { Driver Driver `json:"-"` // Assets defines where assets should be loaded from by default. Defaults to // 'assets/audio' and 'assets/images'. Assets Assets `json:"assets"` Debug Debug `json:"debug"` Screen Screen `json:"screen"` BatchLoadOptions BatchLoadOptions `json:"batchLoadOptions"` // FrameRate, representing the rate enter frame events are triggered, defaults to 60. FrameRate int `json:"frameRate"` // DrawFrameRate is ignored on JS. It defaults to 60. DrawFrameRate int `json:"drawFrameRate"` // IdleDrawFrameRate defaults to 60. When a window goes out of focus, this setting can be lowered to // reduce resource consumption by drawing. IdleDrawFrameRate int `json:"idleDrawFrameRate"` // Language defines the language oak logs are attempted to be translated to. Defaults to English. Language string `json:"language"` // Title defaults to 'Oak Window'. Title string `json:"title"` BatchLoad bool `json:"batchLoad"` GestureSupport bool `json:"gestureSupport"` LoadBuiltinCommands bool `json:"loadBuiltinCommands"` TrackInputChanges bool `json:"trackInputChanges"` // EnableDebugConsole is ignored on JS. EnableDebugConsole bool `json:"enableDebugConsole"` TopMost bool `json:"topmost"` Borderless bool `json:"borderless"` Fullscreen bool `json:"fullscreen"` SkipRNGSeed bool `json:"skip_rng_seed"` // UnlimitedDrawFrameRate is ignored on JS (it is effectively always true). UnlimitedDrawFrameRate bool `json:"unlimitedDrawFrameRate"` }
A Config defines the settings oak accepts on initialization. Some of these settings may be ignored depending on the target platform.
func NewConfig ¶
func NewConfig(opts ...ConfigOption) (Config, error)
NewConfig creates a config from a set of transformation options.
type ConfigOption ¶
A ConfigOption transforms a Config object.
func FileConfig ¶
func FileConfig(filePath string) ConfigOption
FileConfig loads a config file, that could exist inside oak's binary data storage (see fileutil), to SetupConfig
func ReaderConfig ¶
func ReaderConfig(r io.Reader) ConfigOption
ReaderConfig reads a Config as json from the given reader.
type Driver ¶
A Driver is a function which can take in our lifecycle function and initialize oak with the OS interfaces it needs.
type InputType ¶
type InputType int32
InputType expresses some form of input to the engine to represent a player
type Screen ¶
type Screen struct { X int `json:"X"` Y int `json:"Y"` Height int `json:"height"` Width int `json:"width"` Scale float64 `json:"scale"` }
Screen is a json type storing the starting screen width and height
type Window ¶
type Window struct { // The keyboard state this window is aware of. key.State // the driver.Window embedded in this window exposes at compile time the OS level // options one has to manipulate this. *driver.Window // ScreenWidth is the width of the screen ScreenWidth int // ScreenHeight is the height of the screen ScreenHeight int // FrameRate is the current logical frame rate. // Changing this won't directly effect frame rate, that // requires changing the LogicTicker, but it will take // effect next scene FrameRate int // DrawFrameRate is the equivalent to FrameRate for // the rate at which the screen is drawn. DrawFrameRate int // IdleDrawFrameRate is how often the screen will be redrawn // when the window is out of focus. IdleDrawFrameRate int // DrawTicker is the parallel to LogicTicker to set the draw framerate DrawTicker *time.Ticker // SceneMap is a global map of scenes referred to when scenes advance to // determine what the next scene should be. // It can be replaced or modified so long as these modifications happen // during a scene or before the controller has started. SceneMap *scene.Map // Driver is the driver oak will call during initialization Driver Driver // LoadingR is a renderable that is displayed during loading screens. LoadingR render.Renderable // ErrorScene is a scene string that will be entered if the scene handler // fails to enter some other scene, for example, because it's name was // undefined in the scene map. If the scene map does not have ErrorScene // as well, it will fall back to panicking. ErrorScene string CallerMap *event.CallerMap MouseTree *collision.Tree CollisionTree *collision.Tree DrawStack *render.DrawStack // LastMouseEvent is the last triggered mouse event, // tracked for continuous mouse responsiveness on events // that don't take in a mouse event LastMouseEvent mouse.Event LastRelativeMouseEvent mouse.Event // LastPress is the last triggered mouse event, // where the mouse event was a press. // If TrackMouseClicks is set to false then this will not be tracked LastMousePress mouse.Event FirstSceneInput interface{} ControllerID int32 ParentContext context.Context // UseAspectRatio determines whether new window changes will distort or // maintain the relative width to height ratio of the screen buffer. UseAspectRatio bool // contains filtered or unexported fields }
func (*Window) Bounds ¶
Width returns the absolute bounds of a window in pixels. It does not include window elements outside of the client area (OS provided title bars).
func (*Window) ChangeWindow ¶
ChangeWindow sets the width and height of the game window. Although exported, calling it without a size event will probably not act as expected.
func (*Window) ClearScreenFilter ¶
func (w *Window) ClearScreenFilter()
ClearScreenFilter resets the draw function to no longer filter the screen before publishing it to the window.
func (*Window) DoBetweenDraws ¶
func (w *Window) DoBetweenDraws(f func())
DoBetweenDraws will execute the given function in-between draw frames. It will prevent draws from happening until the provided function has terminated. DoBetweenDraws will block until the provided function is called within the draw loop's schedule, but will not wait for that function itself to terminate.
func (*Window) EventHandler ¶
EventHandler returns this window's event handler.
func (*Window) GetBackgroundImage ¶
GetBackgroundImage returns the image this window will display as its background
func (*Window) Init ¶
func (w *Window) Init(firstScene string, configOptions ...ConfigOption) error
Init initializes the oak engine. After the configuration options have been parsed and validated, this will run concurrent routines drawing to an OS window or app, forwarding OS inputs to this window's configured event handler, and running scenes: first the predefined 'loading' scene, then firstScene as provided here, then scenes following commands sent to the window or returned by ending scenes.
func (*Window) MostRecentInput ¶
MostRecentInput returns the most recent input type (e.g keyboard/mouse or joystick) recognized by the window. This value will only change if the window is set to TrackInputChanges
func (*Window) NextScene ¶
func (w *Window) NextScene()
NextScene causes this window to immediately end the current scene.
func (*Window) Quit ¶
func (w *Window) Quit()
Quit sends a signal to the window to close itself, closing the window and any spun up resources. It should not be called before Init. After it is called, it must not be called again.
func (*Window) RecordGIF ¶
RecordGIF will start recording frames via screen shots with the given time delay (in 1/100ths of a second) between frames. When the returned stop function is called, the frames will be compiled into a gif.
func (*Window) RemoveViewportBounds ¶
func (w *Window) RemoveViewportBounds()
RemoveViewportBounds removes restrictions on the viewport's movement. It will not cause the viewport to update immediately.
func (*Window) ScreenShot ¶
ScreenShot takes a snap shot of the window's image content. ScreenShot is not safe to call while an existing ScreenShot call has yet to finish executing. This could change in the future.
func (*Window) SetAspectRatio ¶
SetAspectRatio will enforce that the displayed window does not distort the input screen away from the given x:y ratio. The screen will not use these settings until a new size event is received from the OS.
func (*Window) SetBackground ¶
func (w *Window) SetBackground(b Background)
SetBackground sets this window's background.
func (*Window) SetColorBackground ¶
SetColorBackground sets this window's background to be a standard image.Image, commonly a uniform color.
func (*Window) SetDrawFilter ¶
SetDrawFilter will filter the screen by the given modification function prior to publishing the screen's rgba to be displayed.
func (*Window) SetLoadingRenderable ¶
func (w *Window) SetLoadingRenderable(r render.Renderable)
SetLoadingRenderable sets what renderable should display between scenes during loading phases.
func (*Window) SetLogicHandler ¶
SetLogicHandler swaps the logic system of the engine with some other implementation. If this is never called, it will use event.DefaultBus
func (*Window) SetPalette ¶
SetPalette tells oak to conform the screen to the input color palette before drawing.
func (*Window) SetViewport ¶
SetViewport positions the viewport to be at x,y
func (*Window) SetViewportBounds ¶
SetViewportBounds sets the minimum and maximum position of the viewport, including screen dimensions
func (*Window) ShiftViewport ¶
ShiftViewport shifts the viewport by x,y
func (*Window) TriggerKeyDown ¶
TriggerKeyDown triggers a software-emulated keypress. This should be used cautiously when the keyboard is in use. From the perspective of the event handler this is indistinguishable from a real keypress.
func (*Window) TriggerKeyHeld ¶
TriggerKeyHeld triggers a software-emulated key hold signal. This should be used cautiously when the keyboard is in use. From the perspective of the event handler this is indistinguishable from a real key hold signal.
func (*Window) TriggerKeyUp ¶
TriggerKeyUp triggers a software-emulated key release. This should be used cautiously when the keyboard is in use. From the perspective of the event handler this is indistinguishable from a real key release.
func (*Window) TriggerMouseEvent ¶
TriggerMouseEvent triggers a software-emulated mouse event. This should be used cautiously when the mouse is in use. From the perspective of the event handler this is indistinguishable from a real key mouse press or movement.
func (*Window) UpdateViewSize ¶
UpdateViewSize updates the size of this window's viewport. If the window has yet to be initialized, it will update ScreenWidth and ScreenHeight, and then exit.
func (*Window) Viewport ¶
Viewport returns the viewport's position. Its width and height are the window's width and height. This position plus width/height cannot exceed ViewportBounds.
func (*Window) ViewportBounds ¶
ViewportBounds returns the boundary of this window's viewport, or the rectangle that the viewport is not allowed to exit as it moves around. It often represents the total size of the world within a given scene. If bounds are not enforced, ok will be false.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package alg provides algorithms and math utilities.
|
Package alg provides algorithms and math utilities. |
floatgeom
Package floatgeom provides primitives for floating point geometry.
|
Package floatgeom provides primitives for floating point geometry. |
intgeom
Package intgeom provides primitives for integer geometry.
|
Package intgeom provides primitives for integer geometry. |
span
Package span provides helper constructs to represent ranges of values, to poll from or clamp to
|
Package span provides helper constructs to represent ranges of values, to poll from or clamp to |
Package audio provides utilities for playing or writing audio streams to OS consumers
|
Package audio provides utilities for playing or writing audio streams to OS consumers |
format
Package format provides audio file and format parsers
|
Package format provides audio file and format parsers |
format/ceol
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files).
|
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files). |
format/dls
Package dls contains data structures for DLS (.dls) file types.
|
Package dls contains data structures for DLS (.dls) file types. |
format/flac
Package flac provides functionality to handle .flac files and .flac encoded data.
|
Package flac provides functionality to handle .flac files and .flac encoded data. |
format/mp3
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data.
|
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data. |
format/riff
Package riff reads and umarshalls RIFF files.
|
Package riff reads and umarshalls RIFF files. |
format/wav
Package wav provides functionality to handle .wav files and .wav encoded data.
|
Package wav provides functionality to handle .wav files and .wav encoded data. |
pcm
Package pcm provides a interface for interacting with PCM audio streams
|
Package pcm provides a interface for interacting with PCM audio streams |
synth
Package synth provides functions and types to support waveform synthesis.
|
Package synth provides functions and types to support waveform synthesis. |
Package collision provides collision tree and space structures along with hit detection functions on spaces.
|
Package collision provides collision tree and space structures along with hit detection functions on spaces. |
ray
Package ray holds utilities for performing iterative collision checks or raycasts
|
Package ray holds utilities for performing iterative collision checks or raycasts |
Package debugstream provides an interface for custom debug commands to assist in program development.
|
Package debugstream provides an interface for custom debug commands to assist in program development. |
Package debugtools provides structures to aid in development debugging of graphical programs.
|
Package debugtools provides structures to aid in development debugging of graphical programs. |
inputviz
Package inputviz provides components that enable visualization of user input (e.g.
|
Package inputviz provides components that enable visualization of user input (e.g. |
Package dlog provides basic logging functions.
|
Package dlog provides basic logging functions. |
Package entities provides common entity constructor functions
|
Package entities provides common entity constructor functions |
x
Package x provides experimental utilities
|
Package x provides experimental utilities |
x/btn/grid
Package grid provides structures for aligning grids of buttons
|
Package grid provides structures for aligning grids of buttons |
Package event provides structures to propagate event occurrences to subscribed system entities.
|
Package event provides structures to propagate event occurrences to subscribed system entities. |
examples
|
|
Package fileutil provides functionality to replace os and io calls with custom filesystems.
|
Package fileutil provides functionality to replace os and io calls with custom filesystems. |
Package joystick provides utilities for querying and reacting to joystick or gamepad inputs.
|
Package joystick provides utilities for querying and reacting to joystick or gamepad inputs. |
Package key enumerates keystrings for use in bindings.
|
Package key enumerates keystrings for use in bindings. |
Package mouse handles the propagation of mouse events though clickable regions.
|
Package mouse handles the propagation of mouse events though clickable regions. |
Package oakerr stores errors returned throughout oak.
|
Package oakerr stores errors returned throughout oak. |
Package physics provides vector types and trivial physics manipulation for them.
|
Package physics provides vector types and trivial physics manipulation for them. |
Package render provides structures for organizing graphics to draw to a window and essential graphical primitives.
|
Package render provides structures for organizing graphics to draw to a window and essential graphical primitives. |
mod
Package mod stores modification functions for images.
|
Package mod stores modification functions for images. |
particle
Package particle provides options for generating renderable particle sources.
|
Package particle provides options for generating renderable particle sources. |
Package scene provides definitions for interacting with game loop scenes.
|
Package scene provides definitions for interacting with game loop scenes. |
Package shake provides methods for rapidly shifting graphical components' positions
|
Package shake provides methods for rapidly shifting graphical components' positions |
Package shape provides 2D shaping utilities.
|
Package shape provides 2D shaping utilities. |
Package shiny provides interfaces and drivers for instantiating and managing application windows
|
Package shiny provides interfaces and drivers for instantiating and managing application windows |
driver
Package driver exposes screen implementation for various platforms
|
Package driver exposes screen implementation for various platforms |
driver/internal/drawer
Package drawer provides functions that help implement screen.Drawer methods.
|
Package drawer provides functions that help implement screen.Drawer methods. |
driver/internal/errscreen
Package errscreen provides a stub Screen implementation.
|
Package errscreen provides a stub Screen implementation. |
driver/internal/event
Package event provides an infinitely buffered double-ended queue of events.
|
Package event provides an infinitely buffered double-ended queue of events. |
driver/internal/lifecycler
Package lifecycler tracks a window's lifecycle state.
|
Package lifecycler tracks a window's lifecycle state. |
driver/internal/swizzle
Package swizzle provides functions for converting between RGBA pixel formats.
|
Package swizzle provides functions for converting between RGBA pixel formats. |
driver/internal/x11key
Package x11key contains X11 numeric codes for the keyboard and mouse.
|
Package x11key contains X11 numeric codes for the keyboard and mouse. |
driver/jsdriver
Package jsdriver provides a WASM/JS driver for accessing a screen.
|
Package jsdriver provides a WASM/JS driver for accessing a screen. |
driver/mtldriver
Package mtldriver provides a Metal driver for accessing a screen.
|
Package mtldriver provides a Metal driver for accessing a screen. |
driver/mtldriver/internal/appkit
Package appkit provides access to Apple's AppKit API (https://developer.apple.com/documentation/appkit).
|
Package appkit provides access to Apple's AppKit API (https://developer.apple.com/documentation/appkit). |
driver/mtldriver/internal/coreanim
Package coreanim provides access to Apple's Core Animation API (https://developer.apple.com/documentation/quartzcore).
|
Package coreanim provides access to Apple's Core Animation API (https://developer.apple.com/documentation/quartzcore). |
driver/noop
Package noop provides a nonfunctional testing driver for accessing a screen.
|
Package noop provides a nonfunctional testing driver for accessing a screen. |
driver/windriver
Package windriver provides the Windows driver for accessing a screen.
|
Package windriver provides the Windows driver for accessing a screen. |
driver/x11driver
Package x11driver provides the X11 driver for accessing a screen.
|
Package x11driver provides the X11 driver for accessing a screen. |
screen
Package screen provides interfaces for portable two-dimensional graphics and input events.
|
Package screen provides interfaces for portable two-dimensional graphics and input events. |
Package timing provides utilities for time.
|
Package timing provides utilities for time. |
Package window provides a common interface for oak-created windows.
|
Package window provides a common interface for oak-created windows. |