From cb982d007cdbeca30b59b4edc1a2d65a14a02f69 Mon Sep 17 00:00:00 2001 From: Theis Pieter Hollebeek Date: Mon, 8 Apr 2024 11:14:29 +0200 Subject: [PATCH] it compiles ! --- src/engine.rs | 42 +++++++++++++++++++++--------------------- src/main.rs | 12 +++--------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index fc43880..24bab18 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -59,7 +59,7 @@ where { id_counter: &'context mut u64, canvas: &'context mut Canvas, - texture_creator: &'context TextureCreator, + texture_creator: *const TextureCreator, entities: &'context mut Vec, components: &'context mut Vec<(u64, Box)>, systems: &'context mut Vec>, @@ -72,7 +72,7 @@ impl<'context, 'game> Context<'context, 'game> { P: AsRef, { let path = path.as_ref().to_path_buf(); - let texture: Texture<'game> = self.texture_creator.load_texture(&path)?; + let texture: Texture<'game> = unsafe { (*self.texture_creator).load_texture(&path)? }; self.textures.insert(path.clone(), texture); Ok(Sprite { path }) } @@ -157,25 +157,25 @@ impl<'game> Game<'game> { }) } - pub fn run ()>(&mut self, _f: F) { - // 'running: loop { - // for event in self.event_pump.poll_iter() { - // match event { - // Event::Quit { .. } - // | Event::KeyDown { - // keycode: Some(Keycode::Escape), - // .. - // } => break 'running, - // _ => {} - // } - // } - // self.canvas.set_draw_color(Color::RGB(60, 180, 180)); - // self.canvas.clear(); - // f(&mut self.context()); - // self.canvas.present(); - // } - // self.canvas.present(); - // std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)) + pub fn run(&mut self, f: F) { + 'running: loop { + for event in self.event_pump.poll_iter() { + match event { + Event::Quit { .. } + | Event::KeyDown { + keycode: Some(Keycode::Escape), + .. + } => break 'running, + _ => {} + } + } + self.canvas.set_draw_color(Color::RGB(60, 180, 180)); + self.canvas.clear(); + f(&mut self.context()); + self.canvas.present(); + std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)) + } + self.canvas.present(); } pub fn context<'context>(&'context mut self) -> Context<'context, 'game> diff --git a/src/main.rs b/src/main.rs index bbb4151..73c98cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -#![allow(unused_imports)] use component_macro::Component; use engine::{Component, Sprite, System}; @@ -19,17 +18,12 @@ impl System for PlayerRenderer { fn on_update(&self, _ctx: &mut engine::Context) {} } -fn add_player<'borrow, 'game>(game: &'borrow mut engine::Game<'game>) { +fn main() { + let mut game = engine::Game::new().unwrap(); + let mut context = game.context(); context.add_system(Box::new(PlayerRenderer)); context.spawn(vec![Box::new(Player { sprite: None })]); -} - -fn main() { - let mut game = engine::Game::new().unwrap(); - { - add_player(&mut game); - } game.run(|context| { let sprite = context.load_sprite("textures/player.png").unwrap();