setup graphics directly

This commit is contained in:
2026-02-18 10:50:22 -08:00
parent 3117a56d51
commit 4a8c9e05a1
2 changed files with 9 additions and 25 deletions

View File

@@ -20,14 +20,12 @@ impl From<ToSurfaceTarget> for wgpu::SurfaceTarget<'static>{
} }
#[wasm_bindgen] #[wasm_bindgen]
pub struct Setup{ pub struct Graphics{
device:wgpu::Device, graphics:graphics::Graphics,
queue:wgpu::Queue,
surface:wgpu::Surface<'static>, surface:wgpu::Surface<'static>,
config:wgpu::SurfaceConfiguration,
} }
#[wasm_bindgen] #[wasm_bindgen]
pub async fn setup(canvas:web_sys::HtmlCanvasElement)->Setup{ pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Graphics{
let size=(canvas.width(),canvas.height()); let size=(canvas.width(),canvas.height());
let instance=setup::step1::create_instance(); let instance=setup::step1::create_instance();
@@ -35,25 +33,13 @@ pub async fn setup(canvas:web_sys::HtmlCanvasElement)->Setup{
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!"); let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
let (device,queue)=setup::step4::request_device(&adapter).await; let (device,queue)=setup::step4::request_device(&adapter).await;
let config=setup::step5::configure_surface(&adapter,&device,&surface,size); let config=setup::step5::configure_surface(&adapter,&device,&surface,size);
Graphics{
Setup{device,queue,surface,config} graphics:graphics::Graphics::new(device,queue,config),
} surface:surface,
#[wasm_bindgen] }
pub struct Graphics{
graphics:graphics::Graphics,
surface:wgpu::Surface<'static>,
} }
#[wasm_bindgen] #[wasm_bindgen]
impl Graphics{ impl Graphics{
#[wasm_bindgen(constructor)]
pub fn new(
setup:Setup,
)->Self{
Self{
graphics:graphics::Graphics::new(setup.device,setup.queue,setup.config),
surface:setup.surface,
}
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){ pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){
// TODO: check f64 range // TODO: check f64 range

View File

@@ -1,7 +1,6 @@
import init, { import init, {
setup, setup_graphics,
CompleteBot, CompleteBot,
Graphics,
CompleteMap, CompleteMap,
PlaybackHead, PlaybackHead,
} from "./pkg/strafesnet_roblox_bot_player_wasm_module.js"; } from "./pkg/strafesnet_roblox_bot_player_wasm_module.js";
@@ -13,8 +12,7 @@ const m = await fetch("bhop_marble_5692093612.snfm");
const canvas = document.querySelector("canvas"); const canvas = document.querySelector("canvas");
const context = await setup(canvas); const graphics = await setup_graphics(canvas);
const graphics = new Graphics(context);
const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer())); const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer())); const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
const playback = new PlaybackHead(0); const playback = new PlaybackHead(0);