Skip to content

Commit

Permalink
feat: Asset hot reload as a feature (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
suspistew authored Aug 6, 2021
1 parent e317eda commit b02559f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
5 changes: 4 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions src/rendering/bidimensional/scion2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -402,7 +403,7 @@ impl Scion2D {
) -> Vec<RenderingInfos> {
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(),
Expand Down Expand Up @@ -482,9 +483,14 @@ impl Scion2D {
device: &Device,
queue: &mut Queue,
) {
let mut timers = resource.get_mut::<Timers>().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::<Timers>().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 {
Expand Down

0 comments on commit b02559f

Please # to comment.