|
|
|
@ -23,7 +23,7 @@ use winit::dpi::LogicalSize;
|
|
|
|
|
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent};
|
|
|
|
|
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
|
|
|
|
use winit::platform::unix::WindowBuilderExtUnix;
|
|
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
|
use winit::window::{WindowBuilder, Window};
|
|
|
|
|
|
|
|
|
|
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable};
|
|
|
|
|
use crate::canvas::canvas_state::CanvasState;
|
|
|
|
@ -50,16 +50,15 @@ pub mod canvas;
|
|
|
|
|
extern crate specs;
|
|
|
|
|
|
|
|
|
|
use specs::prelude::*;
|
|
|
|
|
use vulkano::swapchain::Surface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Draws(VertexTypeContainer);
|
|
|
|
|
struct Draws(Sprite);
|
|
|
|
|
|
|
|
|
|
impl Component for Draws {
|
|
|
|
|
type Storage = VecStorage<Self>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Renderer(u32);
|
|
|
|
|
|
|
|
|
|
struct Vel(f32);
|
|
|
|
|
|
|
|
|
|
impl Component for Vel {
|
|
|
|
@ -72,17 +71,33 @@ impl Component for Pos {
|
|
|
|
|
type Storage = VecStorage<Self>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct RenderSystem;
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
struct PersistentState {
|
|
|
|
|
surface: Option<Arc<Surface<Window>>>,
|
|
|
|
|
window_size: (u32, u32),
|
|
|
|
|
canvas_frame: CanvasFrame,
|
|
|
|
|
compu_frame: CompuFrame,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct RenderSystem;
|
|
|
|
|
impl<'a> System<'a> for RenderSystem {
|
|
|
|
|
|
|
|
|
|
type SystemData = (
|
|
|
|
|
WriteStorage<'a, Pos>,
|
|
|
|
|
WriteStorage<'a, Vel>,
|
|
|
|
|
WriteStorage<'a, Draws>,
|
|
|
|
|
Write<'a, PersistentState>,
|
|
|
|
|
Write<'a, VkProcessor>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fn run(&mut self, (mut pos, vel, data): Self::SystemData) {
|
|
|
|
|
fn run(&mut self, (mut pos, vel, draw, mut state, mut vk_processor): Self::SystemData) {
|
|
|
|
|
|
|
|
|
|
state.canvas_frame = CanvasFrame::new(state.window_size);
|
|
|
|
|
state.compu_frame = CompuFrame::new(state.window_size);
|
|
|
|
|
|
|
|
|
|
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
|
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
|
|
|
|
|
|
// The `.join()` combines multiple components,
|
|
|
|
|
// so we only access those entities which have
|
|
|
|
@ -92,9 +107,19 @@ impl<'a> System<'a> for RenderSystem {
|
|
|
|
|
// and Velocity together; it's also possible to do this
|
|
|
|
|
// in parallel using rayon's `ParallelIterator`s.
|
|
|
|
|
// See `ParJoin` for more.
|
|
|
|
|
for (pos, vel) in (&mut pos, &vel).join() {
|
|
|
|
|
pos.0 += vel.0;
|
|
|
|
|
|
|
|
|
|
for draw_data in (&draw).join() {
|
|
|
|
|
let size = state.window_size.clone();
|
|
|
|
|
state.canvas_frame.add(draw_data.0.get(size))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vk_processor.run(&state.surface.clone().unwrap(),
|
|
|
|
|
&state.canvas_frame,
|
|
|
|
|
&state.compu_frame);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -159,7 +184,7 @@ pub fn main() {
|
|
|
|
|
|
|
|
|
|
let mut timer = Timer::new();
|
|
|
|
|
let mut frame_future: Box<dyn GpuFuture> =
|
|
|
|
|
Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
|
|
|
|
Box::new(sync::now(processor.device.clone().unwrap())) as Box<dyn GpuFuture>;
|
|
|
|
|
|
|
|
|
|
let step_size: f32 = 0.005;
|
|
|
|
|
let mut elapsed_time: f32 = timer.elap_time();
|
|
|
|
@ -214,9 +239,13 @@ pub fn main() {
|
|
|
|
|
world.register::<Pos>();
|
|
|
|
|
world.register::<Vel>();
|
|
|
|
|
world.register::<Draws>();
|
|
|
|
|
world.insert::<Renderer>(Renderer(10));
|
|
|
|
|
world.insert::<VkProcessor>(processor);
|
|
|
|
|
|
|
|
|
|
world.insert::<PersistentState>(PersistentState {
|
|
|
|
|
surface: Some(surface.clone()),
|
|
|
|
|
window_size: (0, 0),
|
|
|
|
|
canvas_frame: CanvasFrame::new((0,0)),
|
|
|
|
|
compu_frame: CompuFrame::new((0,0)),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// An entity may or may not contain some component.
|
|
|
|
|
world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build();
|
|
|
|
@ -232,9 +261,6 @@ pub fn main() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut funky_sprite = Sprite::new(
|
|
|
|
|
(200.0, 200.0),
|
|
|
|
|
(100.0, 150.0), 10, funky_handle.clone());
|
|
|
|
@ -242,15 +268,18 @@ pub fn main() {
|
|
|
|
|
|
|
|
|
|
let slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
|
|
|
|
|
|
|
|
|
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
//let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
|
|
|
|
|
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drop(q2);
|
|
|
|
|
drop(q1);
|
|
|
|
|
|
|
|
|
|
let l = hprof::enter("Loop");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event_loop_proxy = events_loop.create_proxy();
|
|
|
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
@ -285,11 +314,6 @@ pub fn main() {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let mut window_size: (u32, u32) = (0, 0);
|
|
|
|
|
|
|
|
|
|
let mut canvas_frame = CanvasFrame::new(window_size);
|
|
|
|
|
let mut compu_frame = CompuFrame::new(window_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What would the component for a sprite be...
|
|
|
|
@ -320,11 +344,8 @@ pub fn main() {
|
|
|
|
|
match event {
|
|
|
|
|
Event::NewEvents(cause) => {
|
|
|
|
|
if cause == StartCause::Init {
|
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
|
canvas_frame.draw(&compu_sprite1);
|
|
|
|
|
canvas_frame.draw(&slider);
|
|
|
|
|
|
|
|
|
|
window_size = surface.window().inner_size().into();
|
|
|
|
|
world.write_resource::<PersistentState>()
|
|
|
|
|
.window_size = surface.window().inner_size().into();
|
|
|
|
|
}
|
|
|
|
|
elapsed_time = timer.elap_time();
|
|
|
|
|
delta_time = elapsed_time - current_time;
|
|
|
|
@ -338,7 +359,8 @@ pub fn main() {
|
|
|
|
|
*control_flow = ControlFlow::Exit
|
|
|
|
|
}
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
|
|
|
|
|
world.write_resource::<VkProcessor>().swapchain_recreate_needed = true;
|
|
|
|
|
world.write_resource::<VkProcessor>()
|
|
|
|
|
.swapchain_recreate_needed = true;
|
|
|
|
|
let size = (new_size.width, new_size.height);
|
|
|
|
|
}
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
@ -373,25 +395,6 @@ pub fn main() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Event::MainEventsCleared => {
|
|
|
|
|
funky_sprite.update(delta_time);
|
|
|
|
|
|
|
|
|
|
canvas_frame = CanvasFrame::new(window_size);
|
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
|
//canvas_frame.draw(&container);
|
|
|
|
|
// canvas_frame.draw(&compu_sprite1);
|
|
|
|
|
canvas_frame.draw(&slider);
|
|
|
|
|
|
|
|
|
|
compu_frame = CompuFrame::new(window_size);
|
|
|
|
|
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
|
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("Run");
|
|
|
|
|
world.write_resource::<VkProcessor>()
|
|
|
|
|
.run(&surface.clone(),
|
|
|
|
|
&canvas_frame,
|
|
|
|
|
&compu_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
// accumulator_time -= step_size;
|
|
|
|
|