resizing fixed
This commit is contained in:
122
src/main.rs
122
src/main.rs
@@ -1,5 +1,6 @@
|
||||
extern crate tobj;
|
||||
extern crate winit;
|
||||
extern crate ncollide3d;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -19,6 +20,7 @@ use winit::{
|
||||
};
|
||||
|
||||
use crate::render::Renderer;
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
|
||||
mod framework;
|
||||
mod geometry;
|
||||
@@ -124,66 +126,28 @@ pub struct Mesh {
|
||||
bind_group: Arc<BindGroup>,
|
||||
}
|
||||
|
||||
//log::info!("");
|
||||
|
||||
fn main() {
|
||||
|
||||
|
||||
|
||||
// #[cfg(not(target_arch = "wasm32"))]
|
||||
// {
|
||||
// let chrome_tracing_dir = std::env::var("WGPU_CHROME_TRACE");
|
||||
// wgpu_subscriber::initialize_default_subscriber(
|
||||
// chrome_tracing_dir.as_ref().map(std::path::Path::new).ok(),
|
||||
// );
|
||||
// };
|
||||
// #[cfg(target_arch = "wasm32")]
|
||||
// console_log::init().expect("could not initialize logger");
|
||||
|
||||
use legion::*;
|
||||
let mut world = World::default();
|
||||
|
||||
/*
|
||||
Querying entities by their handle
|
||||
|
||||
// entries return `None` if the entity does not exist
|
||||
if let Some(mut entry) = world.entry(entity) {
|
||||
// access information about the entity's archetype
|
||||
//println!("{:?} has {:?}", entity, entry.archetype().layout().component_types());
|
||||
|
||||
// add an extra component
|
||||
//entry.add_component(12f32);
|
||||
|
||||
// access the entity's components, returns `None` if the entity does not have the component
|
||||
//assert_eq!(entry.get_component::<f32>().unwrap(), &12f32);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let (mut pool, spawner) = {
|
||||
let local_pool = futures::executor::LocalPool::new();
|
||||
let spawner = local_pool.spawner();
|
||||
(local_pool, spawner)
|
||||
};
|
||||
|
||||
// Schedule for the render systen
|
||||
let mut render_schedule = Schedule::builder()
|
||||
.add_system(render::render_test_system())
|
||||
.build();
|
||||
|
||||
// run our schedule (you should do this each update)
|
||||
//schedule.execute(&mut world, &mut resources);
|
||||
|
||||
// Querying entities by component is just defining the component type!
|
||||
let mut query = Read::<Position>::query();
|
||||
|
||||
// you can then iterate through the components found in the world
|
||||
for position in query.iter(&world) {
|
||||
//println!("{:?}", position);
|
||||
}
|
||||
// TODO schedule for the update system and others
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let mut builder = winit::window::WindowBuilder::new();
|
||||
builder = builder.with_title("title");
|
||||
builder = builder.with_title("MVGE");
|
||||
|
||||
// I don't know what they are doing here
|
||||
#[cfg(windows_OFF)] // TODO
|
||||
@@ -192,66 +156,48 @@ fn main() {
|
||||
builder = builder.with_no_redirection_bitmap(true);
|
||||
}
|
||||
|
||||
// I think right here is where I can start pulling everything into the renderer
|
||||
|
||||
let window = builder.build(&event_loop).unwrap();
|
||||
|
||||
// Not sure why this is guarded, maybe we don't handle the event loop timing?
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let mut last_update_inst = Instant::now();
|
||||
|
||||
log::info!("Entering render loop...");
|
||||
|
||||
// Load up the renderer (and the resources)
|
||||
let mut renderer = render::Renderer::init(window);
|
||||
|
||||
entity_loading(&mut world, &mut renderer);
|
||||
let mut renderer = {
|
||||
let mut renderer = render::Renderer::init(&window);
|
||||
entity_loading(&mut world, &mut renderer);
|
||||
renderer
|
||||
};
|
||||
|
||||
let mut resources = Resources::default();
|
||||
resources.insert(renderer);
|
||||
|
||||
// This is just an winit event loop
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
//let _ = (&instance, &adapter); // force ownership by the closure (wtf??)
|
||||
|
||||
// Override the control flow behaviour based on our system
|
||||
*control_flow = if cfg!(feature = "metal-auto-capture") {
|
||||
ControlFlow::Exit
|
||||
} else {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
// Artificially slows the loop rate to 10 millis
|
||||
// This is called after redraw events cleared
|
||||
ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(10))
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
ControlFlow::Poll
|
||||
}
|
||||
};
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
|
||||
// Artificially slows the loop rate to 10 millis
|
||||
// This is called after redraw events cleared
|
||||
*control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(10));
|
||||
|
||||
match event {
|
||||
event::Event::MainEventsCleared => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
// ask for a redraw every 20 millis
|
||||
if last_update_inst.elapsed() > Duration::from_millis(20) {
|
||||
//window.request_redraw();
|
||||
resources
|
||||
.get_mut::<Renderer>()
|
||||
.unwrap()
|
||||
.window
|
||||
.request_redraw();
|
||||
last_update_inst = Instant::now();
|
||||
}
|
||||
|
||||
pool.run_until_stalled();
|
||||
// ask for a redraw every 20 millis
|
||||
if last_update_inst.elapsed() > Duration::from_millis(20) {
|
||||
window.request_redraw();
|
||||
last_update_inst = Instant::now();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
window.request_redraw();
|
||||
pool.run_until_stalled();
|
||||
}
|
||||
event::Event::DeviceEvent {
|
||||
event: MouseMotion{ delta },
|
||||
..
|
||||
} => {
|
||||
|
||||
resources
|
||||
.get_mut::<Renderer>()
|
||||
.unwrap()
|
||||
.cam_look_delta((delta.0, delta.1));
|
||||
|
||||
//swap_chain = device.create_swap_chain(&surface, &sc_desc);
|
||||
},
|
||||
// Resizing will queue a request_redraw
|
||||
event::Event::WindowEvent {
|
||||
event: WindowEvent::Resized(size),
|
||||
@@ -267,7 +213,7 @@ fn main() {
|
||||
.resize(width, height);
|
||||
|
||||
//swap_chain = device.create_swap_chain(&surface, &sc_desc);
|
||||
}
|
||||
},
|
||||
event::Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
@@ -286,8 +232,8 @@ fn main() {
|
||||
}
|
||||
},
|
||||
event::Event::RedrawRequested(_) => {
|
||||
// Call the render system
|
||||
render_schedule.execute(&mut world, &mut resources);
|
||||
//resources.get_mut::<Renderer>().unwrap().render();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user