From b02559fe6309b3fc36f3d688e44f65571474244c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thulliez?= <43185161+grzi@users.noreply.github.com> Date: Fri, 6 Aug 2021 22:20:54 +0200 Subject: [PATCH] feat: Asset hot reload as a feature (#159) --- Cargo.toml | 1 + src/application.rs | 5 ++++- src/rendering/bidimensional/scion2d.rs | 14 ++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 599d114..b313a82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0" [features] parallel = ["legion/parallel"] +hot-reload = [] [dependencies] legion = { version = "0.4", default-features = false, features = ["codegen"] } diff --git a/src/application.rs b/src/application.rs index 6e8acb3..d503f94 100644 --- a/src/application.rs +++ b/src/application.rs @@ -112,7 +112,10 @@ impl Scion { .expect("Error while creating topic for inputs event"); let mut timers = Timers::default(); - timers.add_timer("hot_reload", TimerType::Cyclic, 2.); + + if cfg!(feature = "hot-reload") { + timers.add_timer("hot-reload-timer", TimerType::Cyclic, 5.); + } self.resources.insert(Time::default()); self.resources.insert(events); diff --git a/src/rendering/bidimensional/scion2d.rs b/src/rendering/bidimensional/scion2d.rs index 01c7faf..de4ca48 100644 --- a/src/rendering/bidimensional/scion2d.rs +++ b/src/rendering/bidimensional/scion2d.rs @@ -22,6 +22,7 @@ use crate::{ ScionRenderer, }, }; +use std::cfg; use std::time::SystemTime; use crate::utils::file::{read_file_modification_time, FileReaderError}; use crate::core::resources::time::Timers; @@ -402,7 +403,7 @@ impl Scion2D { ) -> Vec { let mut render_infos = Vec::new(); for (entity, component, transform) in - <(Entity, &mut T, &Transform)>::query().iter_mut(world) + <(Entity, &mut T, &Transform)>::query().iter_mut(world) { render_infos.push(RenderingInfos { layer: transform.translation().layer(), @@ -482,9 +483,14 @@ impl Scion2D { device: &Device, queue: &mut Queue, ) { - let mut timers = resource.get_mut::().expect("Missing mandatory resource : Timers"); - let hot_reload_timer = timers.get_timer("hot_reload").expect("Missing mandatory timer : hot_reload"); - let hot_timer_cycle = hot_reload_timer.cycle() > 0; + let hot_timer_cycle = if cfg!(feature = "hot-reload") { + let mut timers = resource.get_mut::().expect("Missing mandatory resource : Timers"); + let hot_reload_timer = timers.get_timer("hot-reload-timer").expect("Missing mandatory timer : hot_reload"); + hot_reload_timer.cycle() > 0 + } else { + false + }; + <(Entity, &Material)>::query().for_each(world, |(_entity, material)| { match material {