Skip to content

Commit

Permalink
Merge pull request #37 from FromOrdinaryToWonder/master
Browse files Browse the repository at this point in the history
feat: added inline impl for ObjectStorage functions for cheaper trait usage
  • Loading branch information
ElhamAryanpur authored Aug 22, 2023
2 parents 142a683 + b0d48bb commit 51e1681
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
16 changes: 4 additions & 12 deletions examples/dev/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ use blue_engine::{
};

fn main() {
let mut engine = Engine::new_config(WindowDescriptor {
width: 1600,
height: 1200,
title: "diffuse light test",
decorations: true,
resizable: true,
power_preference: PowerPreference::HighPerformance,
})
.expect("win");
let mut engine = Engine::new().expect("win");

// ===============================

Expand All @@ -29,7 +21,7 @@ fn main() {
&mut engine.objects,
)
.unwrap();
engine.objects.get_mut("cube").unwrap().scale(0.6, 0.6, 0.6);
// engine.objects.get_mut("cube").unwrap().scale(0.6, 0.6, 0.6);
engine
.objects
.get_mut("cube")
Expand Down Expand Up @@ -93,7 +85,7 @@ fn main() {

engine
.update_loop(move |renderer, _window, objects, input, camera, plugins| {
let o =
/*let o =
renderer.build_object("haha", Vec::new(), Vec::new(), ObjectSettings::default());
let camx = start.elapsed().unwrap().as_secs_f32().sin() * radius;
Expand Down Expand Up @@ -151,7 +143,7 @@ fn main() {
sprite.position.1,
sprite.position.2 + speed,
);
}
} */
})
.expect("Error during update loop");
}
26 changes: 20 additions & 6 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,31 @@ impl ObjectStorage {
}

pub fn add_object(&mut self, key: impl StringBuffer, object: Object) -> anyhow::Result<()> {
self.insert(key.as_string(), object);

Ok(())
fn add_object_inner(
object_storage: &mut ObjectStorage,
key: String,
object: Object,
) -> anyhow::Result<()> {
object_storage.insert(key, object);

Ok(())
}
add_object_inner(self, key.as_string(), object)
}

/// Allows for safe update of objects
pub fn update_object<T: Fn(&mut Object)>(&mut self, key: impl StringBuffer, callback: T) {
let object = self.get_mut(&key.as_string());
if object.is_some() {
callback(object.unwrap());
fn update_object_inner<T: Fn(&mut Object)>(
object_storage: &mut ObjectStorage,
key: String,
callback: T,
) {
let object = object_storage.get_mut(&key);
if object.is_some() {
callback(object.unwrap());
}
}
update_object_inner(self, key.as_string(), callback);
}
}

Expand Down

0 comments on commit 51e1681

Please sign in to comment.