fix resize

This commit is contained in:
2026-02-18 07:20:40 -08:00
parent 7882a92059
commit 89386f12a0
4 changed files with 19 additions and 11 deletions

View File

@@ -48,13 +48,10 @@ impl Graphics{
self.graphics.generate_models(&self.device,&self.queue,&map);
},
Instruction::Resize(size)=>{
println!("Resizing to {:?}",size);
let t0=std::time::Instant::now();
self.config.width=size.x.max(1);
self.config.height=size.y.max(1);
surface.configure(&self.device,&self.config);
self.graphics.resize(&self.device,&self.config,glam::Vec2::ONE);
println!("Resize took {:?}",t0.elapsed());
}
Instruction::Render{pos,angles}=>{
//this has to go deeper somehow

View File

@@ -38,6 +38,10 @@ impl Graphics{
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]
pub fn resize(&mut self,width:u32,height:u32){
self.graphics.send(&self.surface,strafesnet_roblox_bot_player::graphics::Instruction::Resize([width,height].into()));
}
}
#[wasm_bindgen]

View File

@@ -13,16 +13,15 @@
}
html,
body {
margin: 0; /* remove default margin */
height: 100%; /* make body fill the browser window */
display: flex;
place-content: center center;
margin: 0px;
width: 100%;
height: 100%;
overflow: hidden;
}
canvas {
width: 600px;
height: 600px;
max-width: 100%;
display: block;
margin: 0;
width: 100%;
height: 100%;
}
</style>
<script defer src="player.js" type="module"></script>

View File

@@ -34,3 +34,11 @@ function animate(now) {
}
requestAnimationFrame(animate);
function resize() {
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
graphics.resize(canvas.width, canvas.height);
}
window.addEventListener("resize", resize);
resize();