diff --git a/Cargo.toml b/Cargo.toml index da3ebd4..3288d9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,7 @@ edition = "2018" legion = "0.4.0" winit = "0.24.0" +spin_sleep = "1.0.0" + serde = "1.0.124" toml = "0.5.8" \ No newline at end of file diff --git a/examples/hello-world/main.rs b/examples/hello-world/main.rs index e4eef33..8f9fb9c 100644 --- a/examples/hello-world/main.rs +++ b/examples/hello-world/main.rs @@ -1,9 +1,10 @@ use scion::application::Scion; -use scion::legion::system; +use scion::legion::{system}; +use scion::utils::time::Time; #[system] -fn hello(){ - println!("Hello from system") +fn hello(#[resource] time: &Time){ + println!("Hello from system {:?}", time.delta_duration()); } fn main() { diff --git a/src/application.rs b/src/application.rs index e8e1da9..9116103 100644 --- a/src/application.rs +++ b/src/application.rs @@ -6,6 +6,8 @@ use crate::config::scion_config::{ScionConfig, ScionConfigReader}; use winit::window::{Window, WindowBuilder}; use winit::event_loop::{EventLoop, ControlFlow}; use winit::event::{Event, WindowEvent}; +use crate::utils::time::Time; +use crate::utils::frame_limiter::{FRAME_LOCKED, FrameLimiter, FrameLimiterStrategy}; /// `Scion` is the entry point of any application made with Scion engine. pub struct Scion{ @@ -27,7 +29,10 @@ impl Scion { } fn setup(&mut self) { - // TODO : Add needed resources + self.resources.insert(Time::default()); + self.resources.insert(FrameLimiter::new( + self.config.frame_limiter.clone().unwrap_or(Default::default()) + )); } fn run (mut self) { @@ -50,9 +55,20 @@ impl Scion { } _ => (), } - self.schedule.execute(&mut self.world, &mut self.resources); + self.next_frame(); }); } + + fn next_frame(&mut self) { + let locked_ecs = unsafe { FRAME_LOCKED }; + if !locked_ecs { + self.resources.get_mut::