renders
This commit is contained in:
@@ -72,6 +72,8 @@ impl Sprite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Drawable for Sprite {
|
impl Drawable for Sprite {
|
||||||
fn get(&self, window_size: (u32, u32)) -> Vec<VertexTypeContainer> {
|
fn get(&self, window_size: (u32, u32)) -> Vec<VertexTypeContainer> {
|
||||||
vec![
|
vec![
|
||||||
|
|||||||
41
src/main.rs
41
src/main.rs
@@ -81,8 +81,8 @@ struct PersistentState {
|
|||||||
|
|
||||||
|
|
||||||
struct RenderSystem;
|
struct RenderSystem;
|
||||||
impl<'a> System<'a> for RenderSystem {
|
|
||||||
|
|
||||||
|
impl<'a> System<'a> for RenderSystem {
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
WriteStorage<'a, Vel>,
|
||||||
@@ -92,7 +92,6 @@ impl<'a> System<'a> for RenderSystem {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, (mut pos, vel, draw, mut state, mut vk_processor): 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.canvas_frame = CanvasFrame::new(state.window_size);
|
||||||
state.compu_frame = CompuFrame::new(state.window_size);
|
state.compu_frame = CompuFrame::new(state.window_size);
|
||||||
|
|
||||||
@@ -111,22 +110,17 @@ impl<'a> System<'a> for RenderSystem {
|
|||||||
for draw_data in (&draw).join() {
|
for draw_data in (&draw).join() {
|
||||||
let size = state.window_size.clone();
|
let size = state.window_size.clone();
|
||||||
state.canvas_frame.add(draw_data.0.get(size))
|
state.canvas_frame.add(draw_data.0.get(size))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vk_processor.run(&state.surface.clone().unwrap(),
|
vk_processor.run(&state.surface.clone().unwrap(),
|
||||||
&state.canvas_frame,
|
&state.canvas_frame,
|
||||||
&state.compu_frame);
|
&state.compu_frame);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SysA;
|
struct SysA;
|
||||||
|
|
||||||
impl<'a> System<'a> for SysA {
|
impl<'a> System<'a> for SysA {
|
||||||
|
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
ReadStorage<'a, Vel>
|
ReadStorage<'a, Vel>
|
||||||
@@ -149,7 +143,6 @@ impl<'a> System<'a> for SysA {
|
|||||||
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
||||||
hprof::start_frame();
|
hprof::start_frame();
|
||||||
|
|
||||||
let q1 = hprof::enter("setup");
|
let q1 = hprof::enter("setup");
|
||||||
@@ -221,8 +214,6 @@ pub fn main() {
|
|||||||
// processor.get_font_handle(String::from("sansation.ttf")).unwrap();
|
// processor.get_font_handle(String::from("sansation.ttf")).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// So I would have to go full in on the ECS in order to do rendering...
|
// So I would have to go full in on the ECS in order to do rendering...
|
||||||
|
|
||||||
// That would probably look like a canvasFrame and compuFrame component which would
|
// That would probably look like a canvasFrame and compuFrame component which would
|
||||||
@@ -243,43 +234,36 @@ pub fn main() {
|
|||||||
world.insert::<PersistentState>(PersistentState {
|
world.insert::<PersistentState>(PersistentState {
|
||||||
surface: Some(surface.clone()),
|
surface: Some(surface.clone()),
|
||||||
window_size: (0, 0),
|
window_size: (0, 0),
|
||||||
canvas_frame: CanvasFrame::new((0,0)),
|
canvas_frame: CanvasFrame::new((0, 0)),
|
||||||
compu_frame: CompuFrame::new((0,0)),
|
compu_frame: CompuFrame::new((0, 0)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// An entity may or may not contain some component.
|
// An entity may or may not contain some component.
|
||||||
world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build();
|
world.create_entity()
|
||||||
|
.with(Vel(2.0))
|
||||||
|
.with(Pos(0.0))
|
||||||
|
.with(Draws(
|
||||||
|
Sprite::new(
|
||||||
|
(200.0, 200.0),
|
||||||
|
(100.0, 150.0), 10, funky_handle.clone())))
|
||||||
|
.build();
|
||||||
|
|
||||||
let mut dispatcher = DispatcherBuilder::new()
|
let mut dispatcher = DispatcherBuilder::new()
|
||||||
.with(SysA, "sys_a", &[])
|
.with(SysA, "sys_a", &[])
|
||||||
.with(RenderSystem, "render_s", &[]).build();
|
.with(RenderSystem, "render_s", &[]).build();
|
||||||
|
|
||||||
// This dispatches all the systems in parallel (but blocking).
|
|
||||||
dispatcher.dispatch(&mut world);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut funky_sprite = Sprite::new(
|
|
||||||
(200.0, 200.0),
|
|
||||||
(100.0, 150.0), 10, funky_handle.clone());
|
|
||||||
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||||
|
|
||||||
let slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
let slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
drop(q2);
|
drop(q2);
|
||||||
drop(q1);
|
drop(q1);
|
||||||
|
|
||||||
let l = hprof::enter("Loop");
|
let l = hprof::enter("Loop");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let event_loop_proxy = events_loop.create_proxy();
|
let event_loop_proxy = events_loop.create_proxy();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
@@ -315,7 +299,6 @@ pub fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// What would the component for a sprite be...
|
// What would the component for a sprite be...
|
||||||
// Drawable with the vertex format in one rendering system
|
// Drawable with the vertex format in one rendering system
|
||||||
// position + velocity could then be two more in one system
|
// position + velocity could then be two more in one system
|
||||||
@@ -354,6 +337,8 @@ pub fn main() {
|
|||||||
delta_time = 0.02;
|
delta_time = 0.02;
|
||||||
}
|
}
|
||||||
accumulator_time += delta_time;
|
accumulator_time += delta_time;
|
||||||
|
// This dispatches all the systems in parallel (but blocking).
|
||||||
|
dispatcher.dispatch(&mut world);
|
||||||
}
|
}
|
||||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||||
*control_flow = ControlFlow::Exit
|
*control_flow = ControlFlow::Exit
|
||||||
|
|||||||
Reference in New Issue
Block a user