Difference between revisions of "SDK 6.3/Rust"
(C++ (WASM) and Rust API reference for SDK 6.3 (WowBot)) |
(Link full API reference subpages (WowBot)) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | {{notice|'''Official WOWCube SDK documentation.''' SDK 6.3, Rust API. | + | {{notice|'''Official WOWCube SDK documentation.''' SDK 6.3, Rust API — '''EXPERIMENTAL.''' Rust support is an experimental, supported track: APIs may change between releases. The C++ (WebAssembly) API remains the primary development track.}} |
{{SDK 6.3 nav}} | {{SDK 6.3 nav}} | ||
| Line 5: | Line 5: | ||
''← [[SDK 6.3]] · Rust'' | ''← [[SDK 6.3]] · Rust'' | ||
| − | Rust cubeapps | + | Rust cubeapps compile to WebAssembly (<code>wasm32-unknown-unknown</code>, <code>no_std</code>) and use the same engine ABI as the [[SDK 6.3/C++/Native API|C++ native API]] — with '''1:1 feature parity''' with C++ SDK 6.3 (all graphics, topology, communication, motion, sound, leaderboard, 140+ named colors, math). One WASM module runs on all eight cube modules; each instance drives the module's three 240×240 screens. |
| − | == | + | == The CubiOS Rust SDK == |
| − | + | The SDK is a two-crate Cargo workspace — '''[https://github.com/wowcube/CubiOS_Rust_SDK CubiOS_Rust_SDK]''' on GitHub: | |
| − | |||
| − | |||
| − | |||
| − | + | * '''<code>cubios-sys</code> — raw layer.''' FFI bindings to the CubiOS engine ABI plus thin safe wrappers and the application event loop. Modules: <code>application</code> (the <code>Application</code> trait, timers, event loop), <code>comm</code> (packets, BLE, time, saves, RNG, logging), <code>gfx</code> (immediate-mode drawing), <code>topology</code>, <code>sound</code>, <code>motion</code>, <code>leaderboard</code>, <code>event</code>, <code>network_message</code> / <code>save_message</code> (bit-packed serializers), <code>screen</code>, <code>math</code> (Vec2, Color, Transform, Rect2), <code>types</code>, <code>constants</code>. | |
| − | + | * '''<code>cubios</code> — safe / high-level layer.''' A Rust port of the C++ <code>Cubios::</code> classes: retained per-screen rendering (<code>begin → add → end</code>), <code>Scene</code> registry, <code>Sprite</code> / <code>AnimatedSprite</code> / <code>SpriteAtlas</code> / <code>Background</code> / <code>Text</code> / <code>QRCode</code> / <code>OffscreenRenderTarget</code>, <code>Sound</code> / <code>SoundCollection</code>, <code>Scramble</code>, <code>Splashscreen</code>, and 142 named colors (<code>Colors::*</code>). Builders are chainable; storage is <code>heapless</code> (no allocator). | |
| − | + | Public API surface: '''533 functions across 27 modules'''. Everything is <code>no_std</code>; the bundled minimal example builds to a ~3 KB <code>.wasm</code>. | |
| − | |||
== Application trait == | == Application trait == | ||
| − | A cubeapp implements | + | A cubeapp implements <code>Application</code> (from <code>cubios_sys::ffi::application</code>) and exports two entry points the runtime calls: <code>on_init(cid)</code> (module index 0–7) and <code>run</code>. |
| − | + | {| class="wikitable" | |
| − | + | ! Callback !! When | |
| + | |- | ||
| + | | <code>on_init()</code> || once, after construction | ||
| + | |- | ||
| + | | <code>on_tick(cur_time, delta_time)</code> || every frame (ms) | ||
| + | |- | ||
| + | | <code>on_render(&mut [Screen; 3])</code> || module is about to draw | ||
| + | |- | ||
| + | | <code>on_phys_tick(&[Screen; 3])</code> || fixed-cadence physics tick | ||
| + | |- | ||
| + | | <code>on_twist(&TopologyTwistInfo)</code> || cube twisted | ||
| + | |- | ||
| + | | <code>on_tap(count)</code> / <code>on_pat(count)</code> || tap on a screen / opposite side | ||
| + | |- | ||
| + | | <code>on_message(msg_type, data)</code> || packet from another module | ||
| + | |- | ||
| + | | <code>on_external_message(data)</code> || BLE data from the companion app | ||
| + | |- | ||
| + | | <code>on_timer(timer_id)</code> || programmable timer fired | ||
| + | |- | ||
| + | | <code>on_close()</code> || app is closing | ||
| + | |} | ||
| − | + | Timer helpers (<code>set_timer / start_timer / stop_timer / kill_timer</code>) come with the trait via <code>ApplicationContext</code>. | |
| − | |||
| − | |||
| − | |||
| − | fn | + | == Quick start == |
| + | |||
| + | #![no_std] | ||
| + | use cubios::high_level::gfx::{Background, Text}; | ||
| + | use cubios::high_level::scene::SceneObjectEnum; | ||
| + | use cubios::high_level::screen::Screen; | ||
| + | use cubios::sys::ffi::application::{application_init, application_run, | ||
| + | AppErr, Application, ApplicationContext}; | ||
| + | use cubios::sys::ffi::screen::Screen as SysScreen; | ||
| + | use cubios::sys::ffi::types::{TopologyOrientation, TopologyTwistInfo}; | ||
| + | |||
| + | struct HelloCube { ctx: ApplicationContext } | ||
| + | |||
| + | impl Application for HelloCube { | ||
| + | fn app_context_mut(&mut self) -> &mut ApplicationContext { &mut self.ctx } | ||
| + | fn on_init(&mut self) -> Result<(), AppErr> { Ok(()) } | ||
| + | fn on_tick(&mut self, _t: u32, _dt: u32) -> Result<(), AppErr> { Ok(()) } | ||
| + | |||
| + | fn on_render(&mut self, screens: &mut [SysScreen; 3]) -> Result<(), AppErr> { | ||
| + | for s in screens.iter() { | ||
| + | let mut screen: Screen = Screen::new(s.id()); | ||
| + | screen.begin(TopologyOrientation::Menu, false); | ||
| + | screen.add(SceneObjectEnum::Background(Background::from_rgb(0, 0, 0))); | ||
| + | screen.add(SceneObjectEnum::Text(Text::at("HELLO", 120.0, 100.0).with_font_size(24))); | ||
| + | screen.add(SceneObjectEnum::Text(Text::at("WOWCUBE", 120.0, 140.0).with_font_size(24))); | ||
| + | screen.end(); | ||
| + | } | ||
| + | Ok(()) | ||
| + | } | ||
| + | // ... remaining callbacks return Ok(()) | ||
} | } | ||
| − | + | ||
| − | + | static mut APPLICATION: Option<HelloCube> = None; | |
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | static mut APPLICATION: Option< | ||
| − | |||
#[no_mangle] | #[no_mangle] | ||
pub extern "C" fn on_init(cid: u32) { | pub extern "C" fn on_init(cid: u32) { | ||
| − | let mut | + | let mut app = HelloCube { ctx: ApplicationContext::new() }; |
| − | + | application_init(&mut app, cid); | |
| − | unsafe { APPLICATION = Some( | + | unsafe { *core::ptr::addr_of_mut!(APPLICATION) = Some(app) } |
} | } | ||
| − | + | ||
#[no_mangle] | #[no_mangle] | ||
pub extern "C" fn run() { | pub extern "C" fn run() { | ||
| − | let | + | let app = unsafe { (*core::ptr::addr_of_mut!(APPLICATION)).as_mut().unwrap() }; |
| − | + | application_run(app); | |
} | } | ||
| − | <code> | + | Build: <code>cargo build --release --target wasm32-unknown-unknown</code> (the workspace config adds <code>--allow-undefined</code> so engine functions become WASM imports). Package and install like a C++ cubeapp via the [https://marketplace.visualstudio.com/items?itemName=cubios-inc.WOWCubeSDK WOWCube SDK extension for VS Code]. |
| − | |||
| − | + | == Full API reference == | |
| + | Complete, generated from the repository sources: | ||
| + | * [[SDK 6.3/Rust/cubios-sys]] — raw layer: every FFI binding and safe wrapper (14 modules) | ||
| + | * [[SDK 6.3/Rust/cubios]] — high-level layer: every type and method (scene, screens, sprites, text, sound, splash, 142 colors) | ||
| − | + | == Conventions == | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Identical to the C++ SDK: colors <code>0xAARRGGBB</code> (142 named <code>Colors::*</code>); rotation in degrees; scale in percent (100 = 1:1); inter-module packets bit-packed via <code>NetworkMessage</code> (≤ <code>MESSAGE_SIZE_MAX</code> bytes); persistent state via <code>SaveMessage</code> (≤ <code>GAME_SAVE_SIZE</code> bytes); <code>NET_BROADCAST</code> = 0xFF; the module index is <code>CUBE_N</code>. | |
| − | + | == Availability == | |
| − | + | * '''Experimental status:''' Rust support is supported but experimental — API may change; the C++ track is primary. | |
| + | * The '''Development Kit''' currently ships a thin bindings crate (<code>wowcube_sdk</code> v0.1.0) with buildable examples (''Basics 1–3''). | ||
| + | * The full two-crate '''CubiOS Rust SDK''' is public: [https://github.com/wowcube/CubiOS_Rust_SDK github.com/wowcube/CubiOS_Rust_SDK] (source-available, © Cubios Inc.) — clone and build with stable Rust + <code>wasm32-unknown-unknown</code>. | ||
| − | + | For per-function semantics see the [[SDK 6.3/C++/Native API|C++ native reference]] — names map 1:1 (<code>gfx::draw_text</code> → <code>GFX_drawText</code>). | |
[[Category:SDK 6.3]] | [[Category:SDK 6.3]] | ||
[[Category:Rust API]] | [[Category:Rust API]] | ||
Latest revision as of 10:45, 26 July 2026
SDK 6.3 · PAWN API: Core ·
Graphics ·
Topology ·
Sound ·
Motion Sensor ·
Leaderboard ·
Splash Screen ·
Physics ·
Network ·
Save ·
Scramble ·
Logging
C++: Native API · Application · GFX Engine · Rust: Rust API (experimental) · Changelog
← SDK 6.3 · Rust
Rust cubeapps compile to WebAssembly (wasm32-unknown-unknown, no_std) and use the same engine ABI as the C++ native API — with 1:1 feature parity with C++ SDK 6.3 (all graphics, topology, communication, motion, sound, leaderboard, 140+ named colors, math). One WASM module runs on all eight cube modules; each instance drives the module's three 240×240 screens.
Contents
The CubiOS Rust SDK
The SDK is a two-crate Cargo workspace — CubiOS_Rust_SDK on GitHub:
cubios-sys— raw layer. FFI bindings to the CubiOS engine ABI plus thin safe wrappers and the application event loop. Modules:application(theApplicationtrait, timers, event loop),comm(packets, BLE, time, saves, RNG, logging),gfx(immediate-mode drawing),topology,sound,motion,leaderboard,event,network_message/save_message(bit-packed serializers),screen,math(Vec2, Color, Transform, Rect2),types,constants.cubios— safe / high-level layer. A Rust port of the C++Cubios::classes: retained per-screen rendering (begin → add → end),Sceneregistry,Sprite/AnimatedSprite/SpriteAtlas/Background/Text/QRCode/OffscreenRenderTarget,Sound/SoundCollection,Scramble,Splashscreen, and 142 named colors (Colors::*). Builders are chainable; storage isheapless(no allocator).
Public API surface: 533 functions across 27 modules. Everything is no_std; the bundled minimal example builds to a ~3 KB .wasm.
Application trait
A cubeapp implements Application (from cubios_sys::ffi::application) and exports two entry points the runtime calls: on_init(cid) (module index 0–7) and run.
| Callback | When |
|---|---|
on_init() |
once, after construction |
on_tick(cur_time, delta_time) |
every frame (ms) |
on_render(&mut [Screen; 3]) |
module is about to draw |
on_phys_tick(&[Screen; 3]) |
fixed-cadence physics tick |
on_twist(&TopologyTwistInfo) |
cube twisted |
on_tap(count) / on_pat(count) |
tap on a screen / opposite side |
on_message(msg_type, data) |
packet from another module |
on_external_message(data) |
BLE data from the companion app |
on_timer(timer_id) |
programmable timer fired |
on_close() |
app is closing |
Timer helpers (set_timer / start_timer / stop_timer / kill_timer) come with the trait via ApplicationContext.
Quick start
#![no_std]
use cubios::high_level::gfx::{Background, Text};
use cubios::high_level::scene::SceneObjectEnum;
use cubios::high_level::screen::Screen;
use cubios::sys::ffi::application::{application_init, application_run,
AppErr, Application, ApplicationContext};
use cubios::sys::ffi::screen::Screen as SysScreen;
use cubios::sys::ffi::types::{TopologyOrientation, TopologyTwistInfo};
struct HelloCube { ctx: ApplicationContext }
impl Application for HelloCube {
fn app_context_mut(&mut self) -> &mut ApplicationContext { &mut self.ctx }
fn on_init(&mut self) -> Result<(), AppErr> { Ok(()) }
fn on_tick(&mut self, _t: u32, _dt: u32) -> Result<(), AppErr> { Ok(()) }
fn on_render(&mut self, screens: &mut [SysScreen; 3]) -> Result<(), AppErr> {
for s in screens.iter() {
let mut screen: Screen = Screen::new(s.id());
screen.begin(TopologyOrientation::Menu, false);
screen.add(SceneObjectEnum::Background(Background::from_rgb(0, 0, 0)));
screen.add(SceneObjectEnum::Text(Text::at("HELLO", 120.0, 100.0).with_font_size(24)));
screen.add(SceneObjectEnum::Text(Text::at("WOWCUBE", 120.0, 140.0).with_font_size(24)));
screen.end();
}
Ok(())
}
// ... remaining callbacks return Ok(())
}
static mut APPLICATION: Option<HelloCube> = None;
#[no_mangle]
pub extern "C" fn on_init(cid: u32) {
let mut app = HelloCube { ctx: ApplicationContext::new() };
application_init(&mut app, cid);
unsafe { *core::ptr::addr_of_mut!(APPLICATION) = Some(app) }
}
#[no_mangle]
pub extern "C" fn run() {
let app = unsafe { (*core::ptr::addr_of_mut!(APPLICATION)).as_mut().unwrap() };
application_run(app);
}
Build: cargo build --release --target wasm32-unknown-unknown (the workspace config adds --allow-undefined so engine functions become WASM imports). Package and install like a C++ cubeapp via the WOWCube SDK extension for VS Code.
Full API reference
Complete, generated from the repository sources:
- SDK 6.3/Rust/cubios-sys — raw layer: every FFI binding and safe wrapper (14 modules)
- SDK 6.3/Rust/cubios — high-level layer: every type and method (scene, screens, sprites, text, sound, splash, 142 colors)
Conventions
Identical to the C++ SDK: colors 0xAARRGGBB (142 named Colors::*); rotation in degrees; scale in percent (100 = 1:1); inter-module packets bit-packed via NetworkMessage (≤ MESSAGE_SIZE_MAX bytes); persistent state via SaveMessage (≤ GAME_SAVE_SIZE bytes); NET_BROADCAST = 0xFF; the module index is CUBE_N.
Availability
- Experimental status: Rust support is supported but experimental — API may change; the C++ track is primary.
- The Development Kit currently ships a thin bindings crate (
wowcube_sdkv0.1.0) with buildable examples (Basics 1–3). - The full two-crate CubiOS Rust SDK is public: github.com/wowcube/CubiOS_Rust_SDK (source-available, © Cubios Inc.) — clone and build with stable Rust +
wasm32-unknown-unknown.
For per-function semantics see the C++ native reference — names map 1:1 (gfx::draw_text → GFX_drawText).