core
This package acts as the central hub of the engine.
Manages global state and configuration. Holds the primary CoreContext.
Features:
- Global context: Global engine state shared across all packages via
getCoreContext. Contains window information, camera and scene data. - Window definition: Contains the core definitions related to the applications windows,
like
GAME_WIDTH,GAME_HEIGHT,windowWidth,windowHeightandWINDOW_TITLE. - Camera definition: Contains the
Camerastruct definition used to trackposition,zoomandboundsof the camera.
Camera
Section titled “Camera”Camera :: struct { position: gmath.Vector2, zoom: f32, bounds: gmath.Rectangle, // world space}A standard 2D Camera definition.
CoreContext
Section titled “CoreContext”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
Section titled “GAME_HEIGHT”GAME_HEIGHT :: 270The internal design resolution height in pixels.
GAME_WIDTH
Section titled “GAME_WIDTH”GAME_WIDTH :: 480The internal design resolution width in pixels.
SCALE_MODE
Section titled “SCALE_MODE”SCALE_MODE :: ScaleMode.FixedHeightThe global configuration determining which scaling logic is active.
ScaleMode
Section titled “ScaleMode”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
Section titled “WINDOW_TITLE”WINDOW_TITLE :: "bonsai"On desktop: Assigns the window name
On web: Assings the tab name
getCameraZoom
Section titled “getCameraZoom”getCameraZoom :: proc () -> f32Calculates the zoom factor required to fit the fixed GAME_HEIGHT into the current window height.
getCoreContext
Section titled “getCoreContext”getCoreContext :: proc () -> ^CoreContextReturns a pointer to the global CoreContext.
This is the primary way systems access shared state (Window size, GameState, Input).
getWorldSpaceCameraMatrix
Section titled “getWorldSpaceCameraMatrix”getWorldSpaceCameraMatrix :: proc () -> gmath.Matrix4Returns the camera’s world transform (model matrix).
getWorldSpaceProjectionMatrix
Section titled “getWorldSpaceProjectionMatrix”getWorldSpaceProjectionMatrix :: proc () -> gmath.Matrix4Generates the orthographic projection matrix for the world.
Centered on (0, 0).
setCoreContext
Section titled “setCoreContext”setCoreContext :: proc (coreContext: CoreContext)Updates the global core context state.