renders
This commit is contained in:
@@ -72,6 +72,8 @@ impl Sprite {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Drawable for Sprite {
|
||||
fn get(&self, window_size: (u32, u32)) -> Vec<VertexTypeContainer> {
|
||||
vec![
|
||||
|
||||
41
src/main.rs
41
src/main.rs
@@ -81,8 +81,8 @@ struct PersistentState {
|
||||
|
||||
|
||||
struct RenderSystem;
|
||||
impl<'a> System<'a> for RenderSystem {
|
||||
|
||||
impl<'a> System<'a> for RenderSystem {
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Pos>,
|
||||
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) {
|
||||
|
||||
state.canvas_frame = CanvasFrame::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() {
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct SysA;
|
||||
|
||||
impl<'a> System<'a> for SysA {
|
||||
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Pos>,
|
||||
ReadStorage<'a, Vel>
|
||||
@@ -149,7 +143,6 @@ impl<'a> System<'a> for SysA {
|
||||
|
||||
|
||||
pub fn main() {
|
||||
|
||||
hprof::start_frame();
|
||||
|
||||
let q1 = hprof::enter("setup");
|
||||
@@ -221,8 +214,6 @@ pub fn main() {
|
||||
// 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...
|
||||
|
||||
// That would probably look like a canvasFrame and compuFrame component which would
|
||||
@@ -243,43 +234,36 @@ pub fn main() {
|
||||
world.insert::<PersistentState>(PersistentState {
|
||||
surface: Some(surface.clone()),
|
||||
window_size: (0, 0),
|
||||
canvas_frame: CanvasFrame::new((0,0)),
|
||||
compu_frame: CompuFrame::new((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();
|
||||
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()
|
||||
.with(SysA, "sys_a", &[])
|
||||
.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 slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
||||
|
||||
|
||||
|
||||
|
||||
drop(q2);
|
||||
drop(q1);
|
||||
|
||||
let l = hprof::enter("Loop");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let event_loop_proxy = events_loop.create_proxy();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
@@ -315,7 +299,6 @@ pub fn main() {
|
||||
});
|
||||
|
||||
|
||||
|
||||
// What would the component for a sprite be...
|
||||
// Drawable with the vertex format in one rendering system
|
||||
// position + velocity could then be two more in one system
|
||||
@@ -354,6 +337,8 @@ pub fn main() {
|
||||
delta_time = 0.02;
|
||||
}
|
||||
accumulator_time += delta_time;
|
||||
// This dispatches all the systems in parallel (but blocking).
|
||||
dispatcher.dispatch(&mut world);
|
||||
}
|
||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||
*control_flow = ControlFlow::Exit
|
||||
|
||||
Reference in New Issue
Block a user