it compiles !

This commit is contained in:
Theis Pieter Hollebeek 2024-04-08 11:14:29 +02:00
parent bc3c2fef76
commit cb982d007c
2 changed files with 24 additions and 30 deletions

View File

@ -59,7 +59,7 @@ where
{
id_counter: &'context mut u64,
canvas: &'context mut Canvas<Window>,
texture_creator: &'context TextureCreator<WindowContext>,
texture_creator: *const TextureCreator<WindowContext>,
entities: &'context mut Vec<Entity>,
components: &'context mut Vec<(u64, Box<dyn Component>)>,
systems: &'context mut Vec<Box<dyn System>>,
@ -72,7 +72,7 @@ impl<'context, 'game> Context<'context, 'game> {
P: AsRef<std::path::Path>,
{
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<F: Fn(&mut Context) -> ()>(&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<F: Fn(&mut Context)>(&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>

View File

@ -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();