Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions native/watchos/gen_stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const fns = pkg.perry.nativeLibrary.functions;

const OVERRIDES = new Set([
// Platform + input
'bloom_get_platform', 'bloom_get_crown_rotation',
'bloom_get_platform', 'bloom_get_crown_rotation', 'bloom_get_language',
'bloom_set_direct_2d_mode',
'bloom_get_screen_width', 'bloom_get_screen_height',
'bloom_get_touch_x', 'bloom_get_touch_y', 'bloom_get_touch_count',
'bloom_get_delta_time', 'bloom_get_time', 'bloom_get_fps',
Expand All @@ -25,7 +26,8 @@ const OVERRIDES = new Set([
'bloom_is_gamepad_available', 'bloom_get_gamepad_axis',
'bloom_is_gamepad_button_pressed', 'bloom_is_gamepad_button_down', 'bloom_is_gamepad_button_released',
'bloom_get_gamepad_axis_count',
// 2D shapes
// 2D camera + shapes
'bloom_begin_mode_2d', 'bloom_end_mode_2d',
'bloom_draw_rect', 'bloom_draw_rect_lines',
'bloom_draw_circle', 'bloom_draw_circle_lines',
'bloom_draw_line', 'bloom_draw_triangle', 'bloom_draw_poly',
Expand Down Expand Up @@ -69,13 +71,17 @@ const OVERRIDES = new Set([
const rustType = (p) => {
if (p === 'f64') return 'f64';
if (p === 'i64') return 'i64';
// Perry passes/returns heap strings as a pointer carried in an integer
// register; the stub ignores it, so i64 is the correct ABI-compatible type.
if (p === 'string') return 'i64';
if (p === 'void') return '()';
throw new Error(`Unknown param type: ${p}`);
};

const defaultForReturn = (r) => {
if (r === 'f64') return '0.0';
if (r === 'i64') return '0';
if (r === 'string') return '0';
if (r === 'void') return '()';
throw new Error(`Unknown return type: ${r}`);
};
Expand Down
23 changes: 22 additions & 1 deletion native/watchos/src/BloomWatchApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ let K_TEXTURE: Int32 = 7
let K_TEXTURE_REC: Int32 = 8
let K_TEXTURE_PRO: Int32 = 9
let K_TEXT: Int32 = 10
let K_BEGIN_2D: Int32 = 11
let K_END_2D: Int32 = 12

// 3D primitives
let K_CUBE: Int32 = 20
Expand Down Expand Up @@ -307,11 +309,30 @@ struct BloomRootView: View {
// Pull this frame's commands. 2D draws render here; 3D
// commands are filtered by BloomSceneView.
let n = Int(bloom_watchos_copy_draw_list(drawBuf.baseAddress!, 4096))
// `active` is the context world-space draws use: between a
// BEGIN_2D / END_2D pair it carries the camera's affine
// transform (world → screen); otherwise it's the plain
// screen-space context.
var active = ctx
for i in 0..<n {
let ptr = drawBuf.baseAddress!.advanced(by: i)
let k = ptr.pointee.kind
if k >= 20 && k <= 29 { continue } // 3D — handled by SceneView
drawOne(ctx: ctx, cmdPtr: ptr)
if k == K_BEGIN_2D {
let zoom = ptr.pointee.size
var t = CGAffineTransform(translationX: ptr.pointee.x, y: ptr.pointee.y)
t = t.scaledBy(x: zoom, y: zoom)
t = t.translatedBy(x: -ptr.pointee.w, y: -ptr.pointee.h)
var w = ctx
w.transform = t
active = w
continue
}
if k == K_END_2D {
active = ctx
continue
}
drawOne(ctx: active, cmdPtr: ptr)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions native/watchos/src/draw_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub mod kind {
pub const TEXTURE_PRO: i32 = 9; // full: source, dest, origin, rotation
pub const TEXT: i32 = 10;

// 2D camera mode markers. BEGIN carries the camera in reused fields:
// x,y = screen offset; w,h = world target; size = zoom. The Swift Canvas
// applies the matching affine transform to every command until END.
pub const BEGIN_2D: i32 = 11;
pub const END_2D: i32 = 12;

// 3D immediate-mode primitives (pos = x,y,z; w,h = scale; src_x,y,z = secondary).
pub const CUBE: i32 = 20; // pos (x,y,z), size (w,h,size=depth)
pub const CUBE_WIRES: i32 = 21;
Expand Down
Loading
Loading