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.
Example ¶
Use oak to display a scene with a single movable character
AddScene("basicScene", scene.Scene{Start: func(*scene.Context) { char := entities.NewMoving(100, 100, 16, 32, render.NewColorBox(16, 32, color.RGBA{255, 0, 0, 255}), nil, 0, 0) render.Draw(char.R) }}) Init("basicScene")
Output:
Index ¶
- func AddScene(name string, sc scene.Scene) error
- func GetBackgroundImage() image.Image
- func GetCursorPosition() (x, y float64, err error)
- func Height() int
- func HideCursor() error
- func Init(scene string, configOptions ...ConfigOption) error
- func IsDown(key string) bool
- func IsHeld(key string) (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 SetDown(key string)
- func SetFS(filesystem fs.FS)
- func SetFullScreen(fs bool) error
- func SetLoadingRenderable(r render.Renderable)
- func SetScreen(x, y int)
- func SetTitle(title string) error
- func SetTopMost(on bool) error
- func SetTrayIcon(icon string) error
- func SetUp(key string)
- func SetViewportBounds(rect intgeom.Rect2)
- func ShiftScreen(x, y int)
- func ShowNotification(title, msg string, icon bool) error
- func UpdateViewSize(w, h int) error
- func Width() int
- type Assets
- type Background
- type BatchLoadOptions
- type Config
- type ConfigOption
- type Debug
- type Driver
- type Duration
- type InputType
- type Screen
- type Window
- func (w *Window) AddScene(name string, s scene.Scene) error
- func (w *Window) ChangeWindow(width, height int) error
- func (w *Window) ClearScreenFilter()
- func (w *Window) CollisionTrees() (mouseTree, collisionTree *collision.Tree)
- func (w *Window) DoBetweenDraws(f func())
- func (w *Window) EventHandler() event.Handler
- func (w *Window) GetBackgroundImage() image.Image
- func (w *Window) GetCursorPosition() (x, y float64, err error)
- func (w *Window) GetViewportBounds() (rect intgeom.Rect2, ok bool)
- func (w *Window) GoToScene(nextScene string)
- func (w *Window) Height() int
- func (w *Window) HideCursor() error
- func (w *Window) InFocus() bool
- func (w *Window) Init(firstScene string, configOptions ...ConfigOption) error
- func (w *Window) MostRecentInput() InputType
- func (w *Window) MoveWindow(x, y, wd, h int) error
- func (w *Window) NextScene()
- func (w *Window) Propagate(eventName string, 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) SetBorderless(on bool) error
- func (w *Window) SetColorBackground(img image.Image)
- func (w *Window) SetFullScreen(on bool) error
- func (w *Window) SetLoadingRenderable(r render.Renderable)
- func (w *Window) SetLogicHandler(h event.Handler)
- func (w *Window) SetPalette(palette color.Palette)
- func (w *Window) SetScreen(x, y int)
- func (w *Window) SetScreenFilter(screenFilter mod.Filter)
- func (w *Window) SetTitle(title string) error
- func (w *Window) SetTopMost(on bool) error
- func (w *Window) SetTrayIcon(icon string) error
- func (w *Window) SetViewportBounds(rect intgeom.Rect2)
- func (w *Window) ShiftScreen(x, y int)
- func (w *Window) ShowNotification(title, msg string, icon bool) error
- 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() intgeom.Rect2
- func (w *Window) Width() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBackgroundImage ¶
GetBackgroundImage calls GetBackgroundImage on the default window.
func GetCursorPosition ¶
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 SetTrayIcon ¶
SetTrayIcon calls SetTrayIcon on the default window.
func SetViewportBounds ¶
SetViewportBounds calls SetViewportBounds on the default window.
func ShowNotification ¶
ShowNotification calls ShowNotification 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 batch load is true.
type Config ¶
type Config struct { Driver Driver `json:"-"` Assets Assets `json:"assets"` Debug Debug `json:"debug"` Screen Screen `json:"screen"` BatchLoadOptions BatchLoadOptions `json:"batchLoadOptions"` FrameRate int `json:"frameRate"` DrawFrameRate int `json:"drawFrameRate"` IdleDrawFrameRate int `json:"idleDrawFrameRate"` Language string `json:"language"` Title string `json:"title"` EventRefreshRate Duration `json:"refreshRate"` BatchLoad bool `json:"batchLoad"` GestureSupport bool `json:"gestureSupport"` LoadBuiltinCommands bool `json:"loadBuiltinCommands"` TrackInputChanges bool `json:"trackInputChanges"` EnableDebugConsole bool `json:"enableDebugConsole"` TopMost bool `json:"topmost"` Borderless bool `json:"borderless"` Fullscreen bool `json:"fullscreen"` SkipRNGSeed bool `json:"skip_rng_seed"` UnlimitedDrawFrameRate bool `json:"unlimitedDrawFrameRate` }
Config stores initialization settings for oak.
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 Duration ¶
A Duration is a wrapper around time.Duration that allows for easier json formatting.
func (Duration) MarshalJSON ¶
MarshalJSON writes a duration as json.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON extracts a duration from a json byte slice.
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"` // Target sets the expected dimensions of the monitor the game will be opened on, in pixels. // If Fullscreen is false, then a scaling will be applied to correct the game screen size to be // appropriate for the Target size. If no TargetWidth or Height is provided, scaling will not // be adjusted. TargetWidth int `json:"targetHeight"` TargetHeight int `json:"targetWidth"` }
Screen is a json type storing the starting screen width and height
type Window ¶
type Window struct { key.State // 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 TrackMouseClicks bool // 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) 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) CollisionTrees ¶
CollisionTrees helps access the mouse and collision trees from the controller. These trees together detail how a controller can drive mouse and entity interactions.
func (*Window) DoBetweenDraws ¶
func (w *Window) DoBetweenDraws(f func())
DoBetweenDraws will execute the given function in-between draw frames
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) GetCursorPosition ¶
GetCursorPosition returns the cusor position relative to the top left corner of this window.
func (*Window) GetViewportBounds ¶
GetViewportBounds reports what bounds the viewport has been set to, if any.
func (*Window) HideCursor ¶
HideCursor disables showing the cursor when it is over this window.
func (*Window) Init ¶
func (w *Window) Init(firstScene string, configOptions ...ConfigOption) error
Init initializes the oak engine. It spawns off an event loop of several goroutines and loops through scenes after initialization.
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 controller's Config is set to TrackInputChanges
func (*Window) MoveWindow ¶
MoveWindow sets the position of a window to be x,y and it's dimensions to w,h If the window does not support being positioned, it will report as such.
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) SetBorderless ¶
SetBorderless attempts to set the local oak window to have no border. If the window does not support this functionaltiy, it will report as such.
func (*Window) SetColorBackground ¶
SetColorBackground sets this window's background to be a standar image.Image, commonly a uniform color.
func (*Window) SetFullScreen ¶
SetFullScreen attempts to set the local oak window to be full screen. If the window does not support this functionality, it will report as such.
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) SetScreenFilter ¶
SetScreenFilter will filter the screen by the given modification function prior to publishing the screen's rgba to be displayed.
func (*Window) SetTopMost ¶
SetTopMost attempts to set the local oak window to stay on top of other windows. If the window does not support this functionality, it will report as such.
func (*Window) SetTrayIcon ¶
SetTrayIcon sets a application tray icon for this program.
func (*Window) SetViewportBounds ¶
SetViewportBounds sets the minimum and maximum position of the viewport, including screen dimensions
func (*Window) ShiftScreen ¶
ShiftScreen shifts the viewport by x,y
func (*Window) ShowNotification ¶
ShowNotification shows a text notification, optionally using a previously set tray icon.
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.
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.
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. |
range/colorrange
Package colorrange provides distributions that accept and return color.Colors.
|
Package colorrange provides distributions that accept and return color.Colors. |
range/floatrange
Package floatrange provides distributions that accept and return float64s.
|
Package floatrange provides distributions that accept and return float64s. |
range/intrange
Package intrange provides distributions that return ints.
|
Package intrange provides distributions that return ints. |
Package audio provides audio playing utilities.
|
Package audio provides audio playing utilities. |
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. |
font
Package font provides utilities to package together audio manipulations as a 'font'.
|
Package font provides utilities to package together audio manipulations as a 'font'. |
font/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). |
font/dls
Package dls contains data structures for DLS (.dls) file types.
|
Package dls contains data structures for DLS (.dls) file types. |
font/riff
Package riff reads and umarshalls RIFF files.
|
Package riff reads and umarshalls RIFF files. |
klang
Package klang provides audio playing and encoding support
|
Package klang provides audio playing and encoding support |
klang/filter
Package filter provides various audio filters to be applied to audios through the Filter function.
|
Package filter provides various audio filters to be applied to audios through the Filter function. |
klang/filter/supports
Package supports holds interface types for filter supports.
|
Package supports holds interface types for filter supports. |
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. |
sequence
Package sequence provides generators and options for creating audio sequences.
|
Package sequence provides generators and options for creating audio sequences. |
synth
Package synth provides functions and types to support waveform synthesis.
|
Package synth provides functions and types to support waveform synthesis. |
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. |
wininternal
Package wininternal defines common initialization steps for audio on windows.
|
Package wininternal defines common initialization steps for audio on windows. |
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. |
Package dlog provides basic logging functions.
|
Package dlog provides basic logging functions. |
Package entities stores common, useful object and entity combinations.
|
Package entities stores common, useful object and entity combinations. |
Package event provides structures to propagate event occurences to subscribed system entities.
|
Package event provides structures to propagate event occurences 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 shape provides 2D shaping utilities.
|
Package shape provides 2D shaping utilities. |
shiny
|
|
driver
Package driver exposes screen implementation for various platforms Package driver provides the default driver for accessing a screen.
|
Package driver exposes screen implementation for various platforms Package driver provides the default driver for accessing a screen. |
driver/gldriver
Package gldriver provides an OpenGL driver for accessing a screen.
|
Package gldriver provides an OpenGL driver for accessing a screen. |
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/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. |
gesture
Package gesture provides gesture events such as long presses and drags.
|
Package gesture provides gesture events such as long presses and drags. |
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. |