setup graphics directly
This commit is contained in:
@@ -20,14 +20,12 @@ impl From<ToSurfaceTarget> for wgpu::SurfaceTarget<'static>{
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Setup{
|
||||
device:wgpu::Device,
|
||||
queue:wgpu::Queue,
|
||||
pub struct Graphics{
|
||||
graphics:graphics::Graphics,
|
||||
surface:wgpu::Surface<'static>,
|
||||
config:wgpu::SurfaceConfiguration,
|
||||
}
|
||||
#[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 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 (device,queue)=setup::step4::request_device(&adapter).await;
|
||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,size);
|
||||
|
||||
Setup{device,queue,surface,config}
|
||||
Graphics{
|
||||
graphics:graphics::Graphics::new(device,queue,config),
|
||||
surface:surface,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub struct Graphics{
|
||||
graphics:graphics::Graphics,
|
||||
surface:wgpu::Surface<'static>,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
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]
|
||||
pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){
|
||||
// TODO: check f64 range
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import init, {
|
||||
setup,
|
||||
setup_graphics,
|
||||
CompleteBot,
|
||||
Graphics,
|
||||
CompleteMap,
|
||||
PlaybackHead,
|
||||
} 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 context = await setup(canvas);
|
||||
const graphics = new Graphics(context);
|
||||
const graphics = await setup_graphics(canvas);
|
||||
const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
|
||||
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
||||
const playback = new PlaybackHead(0);
|
||||
|
||||
Reference in New Issue
Block a user