1#![no_std]
2#![allow(unused)]
9
10pub mod components;
11pub mod game;
12
13pub use pico_ecs as ecs;
14pub use pico_ecs::camera;
15pub use pico_rendering as graphics;
16
17use pico_engine_hardware::{Hardware, Display, Timer, Input};
18
19pub use ecs::component_storage::ComponentStorage;
21pub use ecs::{component, entity::Entity, world::World, MAX_ENTITIES};
22pub use game::Game;
23
24pub struct Engine<H: Hardware> {
26 hardware: H,
27}
28
29impl<H: Hardware> Engine<H> {
30 pub fn new(hardware: H) -> Self {
32 Engine { hardware }
33 }
34
35 pub fn run<G: Game>(&mut self, game: &mut G) -> ! {
37 game.init(self.hardware.display().get_screen_width() as u16, self.hardware.display().get_screen_height() as u16);
39
40 const FRAME_TIME_MS: u32 = 33; let mut delta_time = FRAME_TIME_MS;
44 let mut fps = 60u32;
45
46 loop {
47 let frame_start = self.hardware.timer().get_counter();
49
50 self.hardware.input().update();
52 let should_continue = game.update(self.hardware.input().current_state(), delta_time);
53 if !should_continue {
54 panic!("Game exited");
57 }
58
59 game.render(self.hardware.display(), delta_time);
61
62 let current_time = self.hardware.timer().get_counter();
64 let elapsed = (current_time - frame_start) / 1000; if elapsed < FRAME_TIME_MS as u64 {
66 self.hardware
67 .timer()
68 .delay_ms((FRAME_TIME_MS as u64 - elapsed) as u32);
69 }
70 let end_time = self.hardware.timer().get_counter();
71 delta_time = ((end_time - frame_start) / 1000) as u32;
72
73
74 }
77 }
78}