This commit is contained in:
2026-02-17 09:12:01 -08:00
parent e054886a27
commit 2f8c1ed6f4

View File

@@ -3,40 +3,33 @@ use wasm_bindgen::JsValue;
use strafesnet_roblox_bot_player::{bot,graphics,head};
use strafesnet_common::session::Time as SessionTime;
use crate::setup::SetupContext;
mod setup;
#[wasm_bindgen]
pub struct Graphics{
context:SetupContext<'static>,
graphics:graphics::Graphics,
surface:wgpu::Surface<'static>,
}
#[wasm_bindgen]
impl Graphics{
#[wasm_bindgen(constructor)]
pub fn new(
canvas:web_sys::HtmlCanvasElement,
)->Self{
let context=crate::setup::setup_and_start(canvas);
Self{context}
}
}
#[wasm_bindgen]
pub struct MapGraphics{
graphics:graphics::Graphics,
}
#[wasm_bindgen]
impl MapGraphics{
#[wasm_bindgen(constructor)]
pub fn new(
data:&[u8],
graphics:Graphics,
)->Result<Self,JsValue>{
let context=crate::setup::setup_and_start(canvas);
Ok(Self{
graphics:graphics::Graphics::new(data,graphics.context.device,graphics.context.queue,graphics.context.config).map_err(|e|JsValue::from_str(&e.to_string()))?,
graphics:graphics::Graphics::new(data,context.device,context.queue,context.config).map_err(|e|JsValue::from_str(&e.to_string()))?,
surface:context.surface,
})
}
#[wasm_bindgen]
pub fn render(&mut self,bot:&Bot,head:&PlaybackHead,time:f64){
// TODO: check f64 range
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
let (pos,angles)=head.head.get_position_angles(&bot.bot,time);
self.graphics.send(&self.surface,strafesnet_roblox_bot_player::graphics::Instruction::Render{pos,angles});
}
}
#[wasm_bindgen]
@@ -67,4 +60,10 @@ impl PlaybackHead{
head:head::PlaybackHead::new(time),
})
}
#[wasm_bindgen]
pub fn advance_time(&mut self,bot:&Bot,time:f64){
// TODO: check f64 range
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
self.head.advance_time(&bot.bot,time);
}
}