lots of hacking and gutting, but it compiles
This commit is contained in:
127
src/main.rs
127
src/main.rs
@@ -4,13 +4,21 @@ extern crate winit;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use futures::task::LocalSpawn;
|
||||
use wgpu_subscriber;
|
||||
use winit::{
|
||||
event::{self, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
};
|
||||
|
||||
use crate::render::Renderer;
|
||||
use bytemuck::__core::ops::Range;
|
||||
use cgmath::Point3;
|
||||
use std::rc::Rc;
|
||||
use wgpu::Buffer;
|
||||
use winit::platform::unix::x11::ffi::Time;
|
||||
use legion::*;
|
||||
|
||||
mod framework;
|
||||
mod geometry;
|
||||
@@ -48,8 +56,6 @@ ECS
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#[allow(unused)]
|
||||
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
|
||||
@@ -84,7 +90,40 @@ pub enum ShaderStage {
|
||||
queue: wgpu::Queue,
|
||||
*/
|
||||
|
||||
async fn main() {
|
||||
// a component is any type that is 'static, sized, send and sync
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct Position {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct Velocity {
|
||||
dx: f32,
|
||||
dy: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq, Hash, Copy, Debug)]
|
||||
pub struct RangeCopy<Idx> {
|
||||
pub start: Idx,
|
||||
pub end: Idx,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct DirectionalLight {
|
||||
color: wgpu::Color,
|
||||
fov: f32,
|
||||
depth: RangeCopy<f32>
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Mesh {
|
||||
index_buffer: Rc<Buffer>,
|
||||
vertex_buffer: Rc<Buffer>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
|
||||
// #[cfg(not(target_arch = "wasm32"))]
|
||||
// {
|
||||
@@ -96,6 +135,66 @@ async fn main() {
|
||||
// #[cfg(target_arch = "wasm32")]
|
||||
// console_log::init().expect("could not initialize logger");
|
||||
|
||||
use legion::*;
|
||||
let mut world = World::default();
|
||||
|
||||
// This could be used for relationships between entities...???
|
||||
let entity: Entity = world.push((
|
||||
cgmath::Point3 {
|
||||
x: -5.0,
|
||||
y: 7.0,
|
||||
z: 10.0,
|
||||
},
|
||||
DirectionalLight {
|
||||
color: wgpu::Color {
|
||||
r: 1.0,
|
||||
g: 0.5,
|
||||
b: 0.5,
|
||||
a: 1.0,
|
||||
},
|
||||
fov: 45.0,
|
||||
depth: RangeCopy { start: 1.0, end: 20.0 },
|
||||
}
|
||||
));
|
||||
|
||||
let entities: &[Entity] = world.extend(vec![
|
||||
(Position { x: 0.0, y: 0.0 }, Velocity { dx: 0.0, dy: 0.0 }),
|
||||
(Position { x: 1.0, y: 1.0 }, Velocity { dx: 0.0, dy: 0.0 }),
|
||||
(Position { x: 2.0, y: 2.0 }, Velocity { dx: 0.0, dy: 0.0 }),
|
||||
]);
|
||||
|
||||
/*
|
||||
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);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// construct a schedule (you should do this on init)
|
||||
let mut schedule = Schedule::builder()
|
||||
// .add_system(Renderer::render_test)
|
||||
.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);
|
||||
}
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let mut builder = winit::window::WindowBuilder::new();
|
||||
@@ -119,15 +218,14 @@ async fn main() {
|
||||
let surface = instance.create_surface(&window);
|
||||
(size, surface)
|
||||
};
|
||||
let adapter = async {
|
||||
let adapter =
|
||||
instance
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::HighPerformance,
|
||||
compatible_surface: Some(&surface),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
};
|
||||
});
|
||||
|
||||
let adapter = futures::executor::block_on(adapter).unwrap();
|
||||
|
||||
let optional_features = Renderer::optional_features();
|
||||
let required_features = Renderer::required_features();
|
||||
@@ -144,7 +242,7 @@ async fn main() {
|
||||
let trace_dir = std::env::var("WGPU_TRACE");
|
||||
|
||||
// And then get the device we want
|
||||
let (device, queue) = adapter
|
||||
let device = adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
features: (optional_features & adapter_features) | required_features,
|
||||
@@ -152,10 +250,11 @@ async fn main() {
|
||||
shader_validation: true,
|
||||
},
|
||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||
)
|
||||
.unwrap();
|
||||
);
|
||||
|
||||
let (device, queue) = futures::executor::block_on(device).unwrap();
|
||||
|
||||
let device = Rc::new(device);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let (mut pool, spawner) = {
|
||||
let local_pool = futures::executor::LocalPool::new();
|
||||
@@ -219,9 +318,9 @@ async fn main() {
|
||||
log::info!("Entering render loop...");
|
||||
|
||||
// Load up the renderer (and the resources)
|
||||
let mut renderer = render::Renderer::init(&device, &sc_desc);
|
||||
let mut renderer = render::Renderer::init(device.clone(), &sc_desc);
|
||||
|
||||
let (plane_vertex_buffer, plane_index_buffer) = Renderer::load_mesh_to_buffer(device, "plane.obj");
|
||||
let (plane_vertex_buffer, plane_index_buffer) = Renderer::load_mesh_to_buffer(device.clone(), "plane.obj");
|
||||
|
||||
// Init, this wants the references to the buffers...
|
||||
let mut runtime = runtime::Runtime::init(&sc_desc, &device, &queue);
|
||||
@@ -291,7 +390,7 @@ async fn main() {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {
|
||||
renderer.update(event);
|
||||
//renderer.update(event);
|
||||
}
|
||||
},
|
||||
event::Event::RedrawRequested(_) => {
|
||||
|
||||
Reference in New Issue
Block a user