it compiles !
This commit is contained in:
parent
bc3c2fef76
commit
cb982d007c
@ -59,7 +59,7 @@ where
|
|||||||
{
|
{
|
||||||
id_counter: &'context mut u64,
|
id_counter: &'context mut u64,
|
||||||
canvas: &'context mut Canvas<Window>,
|
canvas: &'context mut Canvas<Window>,
|
||||||
texture_creator: &'context TextureCreator<WindowContext>,
|
texture_creator: *const TextureCreator<WindowContext>,
|
||||||
entities: &'context mut Vec<Entity>,
|
entities: &'context mut Vec<Entity>,
|
||||||
components: &'context mut Vec<(u64, Box<dyn Component>)>,
|
components: &'context mut Vec<(u64, Box<dyn Component>)>,
|
||||||
systems: &'context mut Vec<Box<dyn System>>,
|
systems: &'context mut Vec<Box<dyn System>>,
|
||||||
@ -72,7 +72,7 @@ impl<'context, 'game> Context<'context, 'game> {
|
|||||||
P: AsRef<std::path::Path>,
|
P: AsRef<std::path::Path>,
|
||||||
{
|
{
|
||||||
let path = path.as_ref().to_path_buf();
|
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);
|
self.textures.insert(path.clone(), texture);
|
||||||
Ok(Sprite { path })
|
Ok(Sprite { path })
|
||||||
}
|
}
|
||||||
@ -157,25 +157,25 @@ impl<'game> Game<'game> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run<F: Fn(&mut Context) -> ()>(&mut self, _f: F) {
|
pub fn run<F: Fn(&mut Context)>(&mut self, f: F) {
|
||||||
// 'running: loop {
|
'running: loop {
|
||||||
// for event in self.event_pump.poll_iter() {
|
for event in self.event_pump.poll_iter() {
|
||||||
// match event {
|
match event {
|
||||||
// Event::Quit { .. }
|
Event::Quit { .. }
|
||||||
// | Event::KeyDown {
|
| Event::KeyDown {
|
||||||
// keycode: Some(Keycode::Escape),
|
keycode: Some(Keycode::Escape),
|
||||||
// ..
|
..
|
||||||
// } => break 'running,
|
} => break 'running,
|
||||||
// _ => {}
|
_ => {}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// self.canvas.set_draw_color(Color::RGB(60, 180, 180));
|
self.canvas.set_draw_color(Color::RGB(60, 180, 180));
|
||||||
// self.canvas.clear();
|
self.canvas.clear();
|
||||||
// f(&mut self.context());
|
f(&mut self.context());
|
||||||
// self.canvas.present();
|
self.canvas.present();
|
||||||
// }
|
std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60))
|
||||||
// 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>
|
pub fn context<'context>(&'context mut self) -> Context<'context, 'game>
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -1,5 +1,4 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_imports)]
|
|
||||||
|
|
||||||
use component_macro::Component;
|
use component_macro::Component;
|
||||||
use engine::{Component, Sprite, System};
|
use engine::{Component, Sprite, System};
|
||||||
@ -19,17 +18,12 @@ impl System for PlayerRenderer {
|
|||||||
fn on_update(&self, _ctx: &mut engine::Context) {}
|
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();
|
let mut context = game.context();
|
||||||
context.add_system(Box::new(PlayerRenderer));
|
context.add_system(Box::new(PlayerRenderer));
|
||||||
context.spawn(vec![Box::new(Player { sprite: None })]);
|
context.spawn(vec![Box::new(Player { sprite: None })]);
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut game = engine::Game::new().unwrap();
|
|
||||||
{
|
|
||||||
add_player(&mut game);
|
|
||||||
}
|
|
||||||
|
|
||||||
game.run(|context| {
|
game.run(|context| {
|
||||||
let sprite = context.load_sprite("textures/player.png").unwrap();
|
let sprite = context.load_sprite("textures/player.png").unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user