diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..93e7c64 --- /dev/null +++ b/deno.lock @@ -0,0 +1,6 @@ +{ + "version": "2", + "remote": { + "https://deno.land/x/byte_type@0.1.7/ffi.ts": "5bc603fd9d0b695bcd1bdaeb45e6e34b0925d5cd8da41ceaec290570a55287e0" + } +} diff --git a/examples/sprite/main.ts b/examples/sprite/main.ts index e748115..fa7c675 100644 --- a/examples/sprite/main.ts +++ b/examples/sprite/main.ts @@ -1,5 +1,5 @@ import { EventType, Rect, Surface, WindowBuilder } from "../../mod.ts"; -import { drawMap, Sprite } from "./util.ts"; +import { drawMap, sleepSync, Sprite } from "./util.ts"; const canvasSize = { width: 400, height: 400 }; const window = new WindowBuilder( @@ -115,7 +115,7 @@ function frame() { } canv.present(); - Deno.sleepSync(10); + sleepSync(10); } for (const event of window.events()) { diff --git a/examples/sprite/util.ts b/examples/sprite/util.ts index 7a9bbf6..33cc44d 100644 --- a/examples/sprite/util.ts +++ b/examples/sprite/util.ts @@ -1,5 +1,11 @@ import { Canvas, Rect, Texture } from "../../mod.ts"; +export function sleepSync(timeout: number) { + const sab = new SharedArrayBuffer(1024); + const int32 = new Int32Array(sab); + Atomics.wait(int32, 0, 0, timeout); +} + export interface Area { x: number; y: number; diff --git a/mod.ts b/mod.ts index d63430d..5e2bf09 100644 --- a/mod.ts +++ b/mod.ts @@ -61,7 +61,7 @@ const sdl2 = Deno.dlopen(getLibraryPath("SDL2"), { }, "SDL_CreateWindow": { "parameters": [ - "pointer", + "buffer", "i32", "i32", "i32", @@ -248,7 +248,7 @@ const sdl2Image = Deno.dlopen(getLibraryPath("SDL2_image"), { "result": "u32", }, "IMG_Load": { - "parameters": ["pointer"], + "parameters": ["buffer"], "result": "pointer", }, }); @@ -259,11 +259,11 @@ const sdl2Font = Deno.dlopen(getLibraryPath("SDL2_ttf"), { "result": "u32", }, "TTF_OpenFont": { - "parameters": ["pointer", "i32"], + "parameters": ["buffer", "i32"], "result": "pointer", }, "TTF_RenderText_Solid": { - "parameters": ["pointer", "pointer", "pointer"], + "parameters": ["pointer", "buffer", "pointer"], "result": "pointer", }, "TTF_RenderText_Shaded": { @@ -407,8 +407,8 @@ function asCString(str: string): Uint8Array { function throwSDLError(): never { const error = sdl2.symbols.SDL_GetError(); - const view = new Deno.UnsafePointerView(error); - throw new Error(`SDL Error: ${view.getCString()}`); + const view = Deno.UnsafePointerView.getCString(error); + throw new Error(`SDL Error: ${view}`); } export class Canvas { @@ -523,8 +523,8 @@ export class Canvas { const ret = sdl2.symbols.SDL_RenderCopy( this.target, texture[_raw], - source ? source[_raw] : null, - dest ? dest[_raw] : null, + source ? Deno.UnsafePointer.of(source[_raw]) : null, + dest ? Deno.UnsafePointer.of(dest[_raw]) : null, ); if (ret < 0) { throwSDLError();