kagura

2D-first game engine for MoonBit inspired by Ebiten

game-engine
wgpu
webgl
moonbit
moon add mizchi/kagura@0.4.0
Download zip
Author
Version
0.4.0
License
Apache-2.0
Last updated
2 months ago
Downloads
53
README

#kagura

A 2D-first (with future 3D) game engine for MoonBit, inspired by Ebiten.

#Features

  • Contract-first architecture -- API contracts are defined before implementations, keeping the codebase modular and replaceable
  • Ebiten-inspired design -- Fixed timestep updates, draw command batching, offscreen compositing, and backend abstraction
  • Cross-platform -- Desktop via wgpu-native, browser via WebGPU
  • Pure MoonBit -- No CGo, no FFI beyond the graphics backend boundary

#Architecture

moon.work |-- mizchi/kagura Thin public facade over core/engine contracts |-- mizchi/kagura_core Core contracts, math, camera, mesh, input utilities |-- mizchi/kagura_engine Rendering/runtime infrastructure | |-- platform/, gfx/ Platform, graphics, native/web backends | |-- runtime/, asset/ Runtime loop, assets, audio, text, UI | `-- gltf/, renderer*/ glTF loading and 2D/3D renderer facades |-- mizchi/kagura_physics Reusable physics, collision, and pathfinding |-- mizchi/kagura_game Gameplay-oriented packages | |-- scene/ Declarative 2D Scene API | `-- ai/, ecs/, tilemap2d/ Game systems and helpers `-- mizchi/kagura_js_runtime JS-only WebGPU runtime helpers

#Platform Support

TargetBackendStatus
Web (all OS)WebGPUSupported
Native macOSwgpu-native + Metal + GLFWSupported
Native Linuxwgpu-native + Vulkan + GLFWSupported (CI: check + test + build)
Native Windowswgpu-native + D3D12/Vulkan + GLFWPartial (CI: check + build workaround; runtime validation pending)
WASM GuestShared-memory binary protocolSupported (MoonBit / Rust / Zig)

JS builds (browser) work on any OS. Native builds support macOS and Linux. Windows native build uses a repo-side workaround for the upstream -lm issue, but runtime validation is still limited.

#Quick Start

#Prerequisites

#Run in Browser

pnpm install just dev flappy_bird

Builds and serves at http://localhost:8080. Browser demos currently require WebGPU (Chrome 113+, Edge 113+).

#Native

bash scripts/setup-wgpu-native.sh # Run with just (recommended -- sets CPATH/LIBRARY_PATH automatically) just run-native action_rpg # Non-visual smoke test (window can appear black) (cd examples/smoke/runtime_smoke_native && moon run src --target native) # Visual sanity check just run-native native_triangle

runtime_smoke_native is intended for internal verification. A black window is expected; success is runtime_smoke_native: ok (real).

#Examples

ExampleDescription
runtime_smokeMinimal JS smoke test
runtime_smoke_nativeMinimal native smoke test (non-visual)
native_triangleNative backend triangle demo
flappy_bird2D game loop with input handling
survivorMulti-entity game with weapons/UI
action_rpgAction RPG prototype
arena3d3D arena prototype (experimental)

Each example is an independent MoonBit module. Run with:

(cd examples/<name> && moon run src --target <js|native>)

#Documentation

#For Users

#For Contributors

#Verification

just fmt just check target=js just test target=js just check target=native just test target=native just check-release pnpm e2e:smoke

#Dependencies

#License

Apache-2.0

#
EngineTermination

#
FixedStepConfig

Fixed-step simulation contract. Ebiten refs:
  • internal/clock/clock.go
  • internal/ui/context.go (updateFrameImpl / update count handling)

#
FixedStepState

Scheduler state carried between frames. Ebiten refs:
  • internal/ui/context.go (tick progression and frame accumulator semantics)

#
RenderPassDesc

What GraphicsDriver.begin does before any draw calls of a pass.

clear_enabled=false keeps the previous framebuffer contents (useful for additive overlays). present=true swaps buffers at end; set false for offscreen render-to-texture passes.

#
RunOptions

#
StepResult

Planned updates for one rendered frame. Ebiten refs:
  • run.go (Update / Draw separation)
  • internal/ui/context.go (skip / interpolation flow)

#
default_fixed_step_config

fn default_fixed_step_config() ->
FixedStepConfig

#
initial_fixed_step_state

fn initial_fixed_step_state() ->
FixedStepState

#
new_fixed_step_config

fn new_fixed_step_config(tps : Int, max_updates_per_frame : Int) ->
FixedStepConfig

#
step_result_alpha

fn step_result_alpha(result :
StepResult
) -> Double

#
step_result_next_state

#
step_result_updates

fn step_result_updates(result :
StepResult
) -> Int

Source Files