Skip to content

core

This package acts as the central hub of the engine. Manages global state and configuration. Holds the primary CoreContext.

Features:


Camera :: struct {
position: gmath.Vector2,
zoom: f32,
bounds: gmath.Rectangle, // world space
}

A standard 2D Camera definition.


CoreContext :: struct {
// updated on every window resize event
windowWidth: i32, // equal to sokol_app.width()
windowHeight: i32, // equal to sokol_app.height()
// .update() and .draw() are called from here
currentScene: ^type.Scene,
nextScene: ^type.Scene,
camera: Camera,
// userData can be used to plug in own game-specific state
userData: rawptr,
}

The core context holding global engine state shared across systems. Acts as the bridge between the platform layer (Sokol), core logic, and renderer.


GAME_HEIGHT :: 270

The internal design resolution height in pixels.


GAME_WIDTH :: 480

The internal design resolution width in pixels.


SCALE_MODE :: ScaleMode.FixedHeight

The global configuration determining which scaling logic is active.


ScaleMode :: enum {
// Locks vertical height.
// Game height is constant, width is matched to fit.
FixedHeight,
// Locks horizontal width.
// Game width is constant, height is matched to fit.
FixedWidth,
}

Defines how the game content scales to fit the window aspect ratio.


WINDOW_TITLE :: "bonsai"

On desktop: Assigns the window name

On web: Assings the tab name


getCameraZoom :: proc () -> f32

Calculates the zoom factor required to fit the fixed GAME_HEIGHT into the current window height.


getCoreContext :: proc () -> ^CoreContext

Returns a pointer to the global CoreContext. This is the primary way systems access shared state (Window size, GameState, Input).


getWorldSpaceCameraMatrix :: proc () -> gmath.Matrix4

Returns the camera’s world transform (model matrix).


getWorldSpaceProjectionMatrix :: proc () -> gmath.Matrix4

Generates the orthographic projection matrix for the world. Centered on (0, 0).


setCoreContext :: proc (coreContext: CoreContext)

Updates the global core context state.