onix

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Onix

English | 简体中文

Onix is a game and application engine written in Go. It includes a typed ECS, 2D and 3D rendering and physics, HTML/CSS UI, audio, resource packaging, and a project editor.

The Go module is github.com/onix-engine/onix; the root package is onix.

Prerequisites

  • Go 1.26 or newer, with Git to clone the repository.
  • A C/C++ toolchain for native builds, with CGO enabled and the development libraries required by the host platform. Linux windowing uses X11, Xext, Xrender, Xi, Wayland, wayland-cursor, and xkbcommon; native macOS development requires Xcode Command Line Tools.
  • Target-specific tools for packaging or cross-compilation. See desktop builds and Android builds for toolchain and packaging requirements.

Quick start

Run these commands from the engine checkout. Keep game and application projects outside this repository:

go run ./editor/cmd/onix new ../my-game
go run ./editor/cmd/onix check ../my-game
go run ./editor/cmd/onix ../my-game

The last command opens the editor for the new project. Use Play to build and run it, or Build Project to package it. Running go run ./editor/cmd/onix without arguments opens the editor's New/Open workflow.

When the destination has no enclosing Go module, project creation generates a go.mod with a local replace pointing to this engine checkout. To set the application module path and initial viewport explicitly:

go run ./editor/cmd/onix new -module example.com/my-game -width 1280 -height 720 ../my-game
Project layout
my-game/
  go.mod
  go.sum
  main.go
  onix_generated.go
  resources/
    project.json
    scenes/
      main.json

main.go belongs to the application. onix_generated.go contains generated registration and engine setup through OnixRegistry, OnixInstallSystems, OnixModuleOptions, and OnixOpenWindow; regenerate it instead of editing it. Project creation starts with an empty scene. Keep project JSON and assets in resources/, and add module definitions and behavior using the module authoring guide.

Command reference

All commands below run from the engine checkout. Options precede the project directory.

Task Command
Create a project go run ./editor/cmd/onix new ../my-game
Validate a project go run ./editor/cmd/onix check ../my-game
Regenerate registration go run ./editor/cmd/onix generate ../my-game
Open a project in the editor go run ./editor/cmd/onix ../my-game
Build a desktop release for the host platform go run ./editor/cmd/onix build -mode release ../my-game
Build a Web release go run ./editor/cmd/onix build -platform web -mode release ../my-game

generate preserves the application's main.go. Builds collect and preprocess resources, then produce platform-specific artifacts under the project's dist/. Release builds use the onix_release tag and binary resource packages; use the build command or editor to prepare them. Build targets are windows, macos, linux, web, android, ios, and wechat, subject to their host and toolchain requirements.

Source map

Path Responsibility
Root package onix Application lifecycle, scheduling, and engine integration
ecs/ Typed components, queries, systems, and structural commands
module/ Module lifecycles, typed messages, slots, and scene management
project/ Project validation, compilation, and resource preprocessing
editor/ Project editor, code generation, build pipeline, and CLI
scene/, camera/, physics/ Scene components, cameras, and 2D/3D physics
render/, graphics/ Rendering backends, graphics data, and image codecs
ui/, text/, font/ HTML/Markdown UI, text layout, and fonts
resource/, fs/ Resource packages and file access
window/, input/, audio/ Platform windows, input, and audio
tests/, testdata/ Integration checks and test fixtures

Platform bridge names use the Onix prefix; build tags and environment variables use onix_ and ONIX_ respectively.

Documentation

Start at the documentation index for usage, design and performance guides, each with a Simplified Chinese version. Focused API and platform references are listed in the usage guide.

Engine development

Read AGENTS.md before changing the engine. Prefer concise generic implementations, minimize allocations on warm paths, and combine traversals when possible. HTML rendering changes must follow W3C standards and align with Chromium.

Run tests for the packages affected by a change. For example, for ECS work:

go test ./ecs
go test ./ecs -run TestName -count=1

Replace TestName with the relevant test name or pattern. Do not run go test ./...; the repository-wide suite can freeze the machine. Visual acceptance is manual; do not launch the editor for automated screenshot testing.

License

Onix is licensed under the MIT License. You may use, modify, compile, and distribute the engine, including in commercial games and software, subject to the license's notice requirements. Third-party code and assets retain their own licenses; see third-party notices.

Documentation

Index

Constants

View Source
const (
	DefaultTargetFPS        = 30
	DefaultTargetTPS        = 64
	DefaultMaxFrameDelta    = 250 * time.Millisecond
	DefaultMaxRendersPerRun = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Animations2D

type Animations2D struct{}

Animations2D installs the animator update systems for node-bound clips.

type App

type App struct {
	World *ecs.World

	*window.Context
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) AddInputHandler

func (app *App) AddInputHandler(phase input.Phase, handler func(*input.Dispatch))

AddInputHandler registers a synchronous handler for one input phase. Handlers run in registration order and may call Dispatch.Consume.

func (*App) AddSystem

func (app *App) AddSystem(stage Stage, config ecs.SystemConfig) error

func (*App) AddSystems

func (app *App) AddSystems(stage Stage, configs ...ecs.SystemConfig) error

func (*App) Destroy

func (app *App) Destroy()

Destroy releases browser surfaces before destroying the native window.

func (*App) Frame

func (app *App) Frame() error

func (*App) InstallSystems

func (app *App) InstallSystems[T SystemSet]() error

InstallSystems installs one capability and its explicit dependencies. Calls are idempotent, and unused capability implementations can be removed by the Go linker.

func (*App) LoadModules

func (app *App) LoadModules[P module.ContentProfile](plan *project.ProjectPlan, registry module.Registry, options module.Options) (*module.Scene, error)

LoadModules mounts the entry of the new module format. It does not open a native window, so loading and logic tests work independently of rendering.

func (*App) LoadScene

func (app *App) LoadScene(bundle *project.Bundle) (*project.SceneInstance, error)

func (*App) Modules

func (app *App) Modules() *module.Runtime

func (*App) OpenFile

func (app *App) OpenFile(options window.FileDialogOptions) (string, error)

OpenFile opens a native dialog for one file owned by the engine window.

func (*App) OpenFileDialog

func (app *App) OpenFileDialog(options window.FileDialogOptions) ([]string, error)

OpenFileDialog opens a modal native file dialog owned by the engine window. An empty result means that the user cancelled the dialog.

func (*App) OpenFiles

func (app *App) OpenFiles(options window.FileDialogOptions) ([]string, error)

OpenFiles opens a native multi-file dialog owned by the engine window.

func (*App) OpenFolder

func (app *App) OpenFolder(options window.FileDialogOptions) (string, error)

OpenFolder opens a native dialog for one folder owned by the engine window.

func (*App) OpenModuleWindow

func (app *App) OpenModuleWindow(spec project.ProjectSpec, source fs.FS, decoder window.IconDecoder) error

OpenModuleWindow applies project window metadata. LoadModules stays usable without a native window for simulation, build validation and server hosts.

func (*App) RequestRender

func (app *App) RequestRender()

func (*App) Run

func (app *App) Run() error

func (*App) Schedule

func (app *App) Schedule(stage Stage) *ecs.Schedule

func (*App) SetIdleEnabled

func (app *App) SetIdleEnabled(enabled bool)

SetIdleEnabled allows an on-demand app to suspend its schedules between events. Custom time-driven systems must schedule WakeAt or disable idle.

func (*App) SetInitialWindowSize

func (app *App) SetInitialWindowSize(width, height int)

SetInitialWindowSize overrides the project window size before the native window is created. Project window options are still applied by LoadScene.

func (*App) SetRenderMode

func (app *App) SetRenderMode(mode RenderMode)

func (*App) SetScriptRegistry

func (app *App) SetScriptRegistry(registry project.ScriptRegistry) error

SetScriptRegistry installs generated scene script bindings. The registry is applied to the next scene loaded by the app and to the current scene, if one has already been loaded.

func (*App) SetTargetFPS

func (app *App) SetTargetFPS(fps int)

func (*App) SetTargetTPS

func (app *App) SetTargetTPS(tps int)

func (*App) SetWebViewBackend

func (app *App) SetWebViewBackend(backend scene.WebViewBackend)

SetWebViewBackend installs the platform browser backend used by ECS WebView components. It is useful on Linux and mobile, where the host can provide a WebKitGTK or native Android/iOS implementation.

func (*App) SetWindowAlwaysOnTop

func (app *App) SetWindowAlwaysOnTop(enabled bool)

func (*App) SetWindowDragRegion

func (app *App) SetWindowDragRegion(region func(x, y float64) bool)

func (*App) SetWindowIcon

func (app *App) SetWindowIcon(data []byte) error

func (*App) SetWindowInputRegion

func (app *App) SetWindowInputRegion(rects []window.InputRegionRect)

SetWindowInputRegion limits pointer input to logical viewport rectangles. A nil slice restores the full window; an empty non-nil slice passes all pointer input through.

func (*App) SetWindowOptions

func (app *App) SetWindowOptions(options window.Options)

func (*App) SetWindowSize

func (app *App) SetWindowSize(width, height int)

func (*App) SetWindowTaskbarVisible

func (app *App) SetWindowTaskbarVisible(visible bool)

func (*App) SetWindowTitle

func (app *App) SetWindowTitle(title string)

func (*App) Step

func (app *App) Step() (bool, error)

func (*App) ToggleFullscreen

func (app *App) ToggleFullscreen()

ToggleFullscreen switches the native window between fullscreen and its previous windowed bounds.

func (*App) WakeAt

func (app *App) WakeAt(deadline time.Time)

WakeAt schedules one update at the earliest requested deadline. It can be called from another goroutine; ECS writes must stay on the app's loop thread.

type Input2D

type Input2D struct{}

type MarkdownRuntime

type MarkdownRuntime interface {
	InstallMarkdown(*App) error
}

MarkdownRuntime is the optional implementation behind UIMarkdown. Keeping the implementation in a feature package lets projects that do not enable Markdown leave its parser dependencies out of the final binary.

type Particles2D

type Particles2D struct{}

type Physics2D

type Physics2D struct{}

type Physics3D

type Physics3D struct{}

type Render2D

type Render2D struct{}

type Render3D

type Render3D struct{}

type RenderMode

type RenderMode uint8
const (
	RenderAlways RenderMode = iota
	RenderOnDemand
)

type Spine2D

type Spine2D struct{}

type SpriteTrails2D

type SpriteTrails2D struct{}

type Stage

type Stage string
const (
	StageStartup               Stage = "startup"
	StageInputPreprocess       Stage = "input_preprocess"
	StageInputGlobal           Stage = "input_global"
	StageInputGUI              Stage = "input_gui"
	StageInputShortcut         Stage = "input_shortcut"
	StageInputUnhandled        Stage = "input_unhandled"
	StagePreUpdate             Stage = "pre_update"
	StageBeforeFixedUpdateLoop Stage = "before_fixed_update_loop"
	StageFixedFirst            Stage = "fixed_first"
	StageModuleEvents          Stage = "module_events"
	StageFixedPreUpdate        Stage = "fixed_pre_update"
	StageFixedUpdate           Stage = "fixed_update"
	StageFixedPostUpdate       Stage = "fixed_post_update"
	StageFixedLast             Stage = "fixed_last"
	StageAfterFixedUpdateLoop  Stage = "after_fixed_update_loop"
	StageUpdate                Stage = "update"
	StagePostUpdate            Stage = "post_update"
	StageRender                Stage = "render"
)

type SystemSet

type SystemSet interface {
	// contains filtered or unexported methods
}

SystemSet is a statically selected engine capability. The unexported method keeps installation logic inside Onix while allowing a generic public API.

type Tilemaps2D

type Tilemaps2D struct{}

type Transforms

type Transforms struct{}

type UIControls

type UIControls struct{}

type UIHTML

type UIHTML struct{}

UIHTML installs the HTML component renderer on top of the UI runtime.

type UIMarkdown

type UIMarkdown[F MarkdownRuntime] struct{}

type UITextInput

type UITextInput struct{}

type UIWidgets

type UIWidgets struct{}

type WebView

type WebView struct{}

WebView installs the optional browser surface runtime. The platform backend is created after the window context exists, so projects can install systems before loading their first scene.

Directories

Path Synopsis
codec
Package codec provides the full built-in audio decoder collection.
Package codec provides the full built-in audio decoder collection.
Package ecs provides typed component storage, queries, structural commands, schedules, resources and messages.
Package ecs provides typed component storage, queries, structural commands, schedules, resources and messages.
cmd/builder command
Command builder preprocesses a project resource package before compiling it.
Command builder preprocesses a project resource package before compiling it.
cmd/onix command
examples
2048 command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
animations command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
flappybird command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
flappybird/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
pelican command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
spine command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
spine/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
webview command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
webview/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
Package fs provides Onix's persistent virtual filesystem.
Package fs provides Onix's persistent virtual filesystem.
codec/hdr
Package hdr decodes Radiance RGBE panoramas without reducing their dynamic range.
Package hdr decodes Radiance RGBE panoramas without reducing their dynamic range.
codec/ontex
Package ontex reads and writes the ONIXTEX1 container: a block-compressed texture together with the mip chain the build already generated.
Package ontex reads and writes the ONIXTEX1 container: a block-compressed texture together with the mip chain the build already generated.
codec/ultrahdr
Package ultrahdr reconstructs linear HDR from JPEG base images and gain maps.
Package ultrahdr reconstructs linear HDR from JPEG base images and gain maps.
html
css
dom
images
png
Package png implements a PNG image decoder and encoder.
Package png implements a PNG image decoder and encoder.
svg
Package svg decodes and rasterizes SVG documents without external dependencies.
Package svg decodes and rasterizes SVG documents without external dependencies.
webp
Package webp implements a decoder for WEBP images.
Package webp implements a decoder for WEBP images.
webp/config
Package config reads WebP headers without registering a pixel decoder.
Package config reads WebP headers without registering a pixel decoder.
webp/internal/riff
Package riff implements the Resource Interchange File Format, used by media formats such as AVI, WAVE and WEBP.
Package riff implements the Resource Interchange File Format, used by media formats such as AVI, WAVE and WEBP.
webp/internal/vp8
Package vp8 implements a decoder for the VP8 lossy image format.
Package vp8 implements a decoder for the VP8 lossy image format.
webp/internal/vp8l
Package vp8l implements a decoder for the VP8L lossless image format.
Package vp8l implements a decoder for the VP8L lossless image format.
internal
brotli
Package brotli implements the Brotli reader and writer needed by external formats: WOFF2 decoding and the WeChat WASM artifact.
Package brotli implements the Brotli reader and writer needed by external formats: WOFF2 decoding and the WeChat WASM artifact.
ecsgen command
Command ecsgen generates typed query, spawn and patch adapters around shared plans.
Command ecsgen generates typed query, spawn and patch adapters around shared plans.
entitycache
Package entitycache stores large system records densely behind a small entity index.
Package entitycache stores large system records densely behind a small entity index.
reuse
Package reuse provides operations on reusable scratch storage.
Package reuse provides operations on reusable scratch storage.
smallsort
Package smallsort provides compact in-place sorting for small collections.
Package smallsort provides compact in-place sorting for small collections.
sourcejson
Package sourcejson isolates build-time JSON parsing from release runtimes.
Package sourcejson isolates build-time JSON parsing from release runtimes.
texcompress
Package texcompress implements pure-Go block compression for build-time texture preprocessing.
Package texcompress implements pure-Go block compression for build-time texture preprocessing.
texcontainer
Package texcontainer describes the byte layout of the block-compressed texture container a build packs in place of a source image.
Package texcontainer describes the byte layout of the block-compressed texture container a build packs in place of a source image.
typedbin
Package typedbin encodes values using their Go type as the schema.
Package typedbin encodes values using their Go type as the schema.
Package module runs independent minimum systems composed by project scene plans.
Package module runs independent minimum systems composed by project scene plans.
assets
Package assets contains opt-in project resource implementations.
Package assets contains opt-in project resource implementations.
audio
Package projectaudio provides an opt-in audio resource feature for project bundles.
Package projectaudio provides an opt-in audio resource feature for project bundles.
internal/dxbcgen command
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
internal/hlslgen command
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.
Package scene provides scene components and runtime systems built on ecs, including transforms, common cameras, 2D rendering, animation, and input.
Package scene provides scene components and runtime systems built on ecs, including transforms, common cameras, 2D rendering, animation, and input.
render3d
Package render3d owns meshes, camera settings, lights, deformation, shadows, post-processing, and the 3D extract/prepare/sort/draw pipeline.
Package render3d owns meshes, camera settings, lights, deformation, shadows, post-processing, and the 3D extract/prepare/sort/draw pipeline.
Package spine loads Spine 3.7 JSON and atlas exports and evaluates them into indexed 2D geometry for Onix's render pipeline.
Package spine loads Spine 3.7 JSON and atlas exports and evaluates them into indexed 2D geometry for Onix's render pipeline.
Package syntax incrementally tokenizes TextMate grammars and colors their scopes with VS Code themes.
Package syntax incrementally tokenizes TextMate grammars and colors their scopes with VS Code themes.
tests
htmlcompat command
Command htmlcompat renders the browser compatibility fixture through Onix.
Command htmlcompat renders the browser compatibility fixture through Onix.
piecetree
Package piecetree stores UTF-8 text in an AVL tree of references into an immutable original buffer and an append-only edit buffer.
Package piecetree stores UTF-8 text in an AVL tree of references into an immutable original buffer and an append-only edit buffer.
tools
ui
Package ui provides layouts, constraints, reusable controls and composition.
Package ui provides layouts, constraints, reusable controls and composition.
html
Package html provides retained HTML surfaces and typed components on the scene runtime.
Package html provides retained HTML surfaces and typed components on the scene runtime.
codec/png
Package png provides the opt-in PNG window icon decoder.
Package png provides the opt-in PNG window icon decoder.
codec/svg
Package svg provides SVG window icon decoding at a statically selected size.
Package svg provides SVG window icon decoding at a statically selected size.

Jump to

Keyboard shortcuts

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