1#![allow(clippy::missing_safety_doc)]
8
9#[cfg(target_arch = "wasm32")]
10mod imports {
11 #[link(wasm_import_module = "gasm")]
12 unsafe extern "C" {
13 pub fn log(msg: *const u8, msg_len: u32);
15 pub fn time_ms() -> f64;
17 pub fn set_frame_rate(hz: f64);
19 pub fn video_present(rgba: *const u8, width: u32, height: u32, stride: u32);
21 pub fn audio_config(sample_rate: u32, channels: u32);
23 pub fn audio_push(samples: *const f32, frames: u32);
25 pub fn input_pad(player: u32) -> u32;
27 pub fn asset_size(name: *const u8, name_len: u32) -> i32;
29 pub fn asset_read(name: *const u8, name_len: u32, dst: *mut u8, cap: u32) -> i32;
31 pub fn asset_read_at(name: *const u8, name_len: u32, offset: u32, dst: *mut u8, len: u32) -> i32;
33 pub fn param(name: *const u8, name_len: u32, dst: *mut u8, cap: u32) -> i32;
35 }
36
37 #[link(wasm_import_module = "gasm:gfx")]
38 unsafe extern "C" {
39 #[link_name = "width"]
41 pub fn gfx_width() -> u32;
42 #[link_name = "height"]
44 pub fn gfx_height() -> u32;
45 #[link_name = "create_shader"]
47 pub fn gfx_create_shader(wgsl: *const u8, wgsl_len: u32) -> u32;
48 #[link_name = "create_buffer"]
50 pub fn gfx_create_buffer(size: u32, usage: u32) -> u32;
51 #[link_name = "create_pipeline"]
53 pub fn gfx_create_pipeline(json: *const u8, json_len: u32) -> u32;
54 #[link_name = "create_bind_group"]
56 pub fn gfx_create_bind_group(json: *const u8, json_len: u32) -> u32;
57 #[link_name = "write_buffer"]
59 pub fn gfx_write_buffer(buffer: u32, offset: u32, data: *const u8, len: u32);
60 #[link_name = "begin_frame"]
62 pub fn gfx_begin_frame(r: f32, g: f32, b: f32, a: f32) -> u32;
63 #[link_name = "set_pipeline"]
64 pub fn gfx_set_pipeline(pipeline: u32);
65 #[link_name = "set_bind_group"]
66 pub fn gfx_set_bind_group(index: u32, bind_group: u32);
67 #[link_name = "set_vertex_buffer"]
68 pub fn gfx_set_vertex_buffer(slot: u32, buffer: u32, offset: u32);
69 #[link_name = "set_index_buffer"]
71 pub fn gfx_set_index_buffer(buffer: u32, format: u32, offset: u32);
72 #[link_name = "draw"]
73 pub fn gfx_draw(vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32);
74 #[link_name = "draw_indexed"]
75 pub fn gfx_draw_indexed(index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32);
76 #[link_name = "end_frame"]
78 pub fn gfx_end_frame();
79 }
80
81 #[link(wasm_import_module = "gasm:net")]
82 unsafe extern "C" {
83 #[link_name = "open"]
85 pub fn net_open(url: *const u8, url_len: u32) -> i32;
86 #[link_name = "state"]
88 pub fn net_state(conn: i32) -> u32;
89 #[link_name = "send"]
91 pub fn net_send(conn: i32, data: *const u8, len: u32) -> i32;
92 #[link_name = "recv"]
94 pub fn net_recv(conn: i32, dst: *mut u8, cap: u32) -> i32;
95 #[link_name = "close"]
96 pub fn net_close(conn: i32);
97 }
98
99 #[link(wasm_import_module = "gasm:storage")]
100 unsafe extern "C" {
101 #[link_name = "get"]
103 pub fn storage_get(key: *const u8, key_len: u32, dst: *mut u8, cap: u32) -> i32;
104 #[link_name = "set"]
106 pub fn storage_set(key: *const u8, key_len: u32, data: *const u8, len: u32) -> i32;
107 #[link_name = "delete"]
109 pub fn storage_delete(key: *const u8, key_len: u32) -> i32;
110 }
111
112 #[link(wasm_import_module = "wasi_snapshot_preview1")]
113 unsafe extern "C" {
114 pub fn proc_exit(code: i32) -> !;
116 }
117}
118
119#[cfg(target_arch = "wasm32")]
120pub use imports::*;
121
122#[cfg(not(target_arch = "wasm32"))]
123pub use crate::native::abi::*;