[oden] Assets becomes async load in terms of IO/GFX

This commit is contained in:
John Doty 2023-06-30 06:29:21 -07:00
parent d2dfa7c401
commit f3f9988314
3 changed files with 16 additions and 8 deletions

View file

@ -1,5 +1,7 @@
import * as core from "asset-core";
import * as io from "./io.ts";
import * as gfx from "./graphics.ts";
export function load_texture(path: string): number {
return core.load_texture(path);
export async function load_texture(path: string): Promise<number> {
const buffer = await io.load(path);
return gfx.create_texture(buffer, path);
}

View file

@ -1,18 +1,22 @@
import { cls, print, spr, use_texture } from "./graphics.ts";
import { load_texture } from "./assets.ts";
let the_texture = 0;
let the_texture: number | undefined = undefined;
export function init() {
print("Hello world!");
// TODO: Async IO
the_texture = load_texture("./src/happy-tree.png");
// Start this load, but then...
load_texture("./src/happy-tree.png").then((n) => (the_texture = n));
}
export function update() {}
export function draw() {
cls(0.1, 0.2, 0.3);
use_texture(the_texture);
spr((320 - 256) / 2, 0, 256, 240, 0, 0);
if (the_texture != undefined) {
// ...it gets resolved here?
use_texture(the_texture);
spr((320 - 256) / 2, 0, 256, 240, 0, 0);
}
}

View file

@ -1 +1,3 @@
// These are the functions exposed by the native assets module.
//
export function load_texture(path: string): number;