diff --git a/build/plugins/wasmTypes.ts b/build/plugins/wasmTypes.ts index 73dd6d3..a3097e4 100644 --- a/build/plugins/wasmTypes.ts +++ b/build/plugins/wasmTypes.ts @@ -166,12 +166,12 @@ export function renderDts(wasmBytes: Uint8Array, meta?: Map) return [ '// Auto-generated by wasmPlugin. Do not edit.', - 'declare const _: {', + 'declare const _: Readonly<{', ...fns.map(([name, sig]) => ` ${name}: ${tsSignature(sig, meta?.get(name))};`), ' memory: WebAssembly.Memory;', ' table: WebAssembly.Table;', - ' readonly data: DataView;', - '};', + ' data: DataView;', + '}>;', 'export default _;', '', ].join('\n'); diff --git a/build/wasm.d.ts b/build/wasm.d.ts index 2cef2c1..47f8604 100644 --- a/build/wasm.d.ts +++ b/build/wasm.d.ts @@ -2,31 +2,31 @@ // After a build, a sibling `${file}.d.ts` with concrete export names takes precedence. declare module '*.cpp' { - const _: { + const _: Readonly<{ memory: WebAssembly.Memory; table: WebAssembly.Table; - readonly data: DataView; + data: DataView; [fn: string]: unknown; - }; + }>; export default _; } declare module '*.c' { - const _: { + const _: Readonly<{ memory: WebAssembly.Memory; table: WebAssembly.Table; - readonly data: DataView; + data: DataView; [fn: string]: unknown; - }; + }>; export default _; } declare module '*.wasm' { - const _: { + const _: Readonly<{ memory: WebAssembly.Memory; table?: WebAssembly.Table; data: DataView; [fn: string]: unknown; - }; + }>; export default _; } \ No newline at end of file diff --git a/src/common/physics/engine.c b/src/common/physics/engine.c index 0961d70..84c2bdf 100644 --- a/src/common/physics/engine.c +++ b/src/common/physics/engine.c @@ -6,17 +6,17 @@ #include #include -#define TYPE_EMPTY 0 -#define TYPE_CIRCLE 1 -#define TYPE_PLANE 2 - -#define rb_get(idx) (rigid_bodies + (idx)) +typedef enum : uint8_t { + TYPE_EMPTY = 0, + TYPE_CIRCLE = 1, + TYPE_PLANE = 2, +} body_type; ////////// Types -typedef struct rigid_body_t { +typedef struct { // Public - uint8_t type; + body_type type; uint8_t reserved[3]; vec2 pos; vec2 vel; @@ -51,6 +51,10 @@ static rigid_body_collision_callback_t rigid_body_collision_callback = NULL; ////////// Functions +inline static rigid_body* rb_get(rigid_body_index idx) { + return (rigid_bodies + (idx)); +} + JS_EXPORT rigid_body* rigid_body_get(rigid_body_index idx) { return rb_get(idx); }