Testbed: add a constructor that calls a custom closure with bevy’s App

This commit is contained in:
Sébastien Crozet
2022-01-24 14:35:34 +01:00
committed by Sébastien Crozet
parent 0ef55c7df7
commit 22f21c14b8
3 changed files with 9 additions and 4 deletions

View File

@@ -18,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
let bytes = std::fs::read("state.bin").unwrap();
let mut state: State = bincode::deserialize(&bytes).unwrap();
let state: State = bincode::deserialize(&bytes).unwrap();
testbed.set_world(
state.bodies,

BIN
examples3d-f64/rapier.data Normal file

Binary file not shown.

View File

@@ -227,7 +227,11 @@ impl TestbedApp {
self.builders = SceneBuilders(builders)
}
pub fn run(mut self) {
pub fn run(self) {
self.run_with_init(|_| {})
}
pub fn run_with_init(mut self, mut init: impl FnMut(&mut App)) {
let mut args = env::args();
let mut benchmark_mode = false;
@@ -392,8 +396,9 @@ impl TestbedApp {
.insert_non_send_resource(self.plugins)
.add_stage_before(CoreStage::Update, "physics", SystemStage::single_threaded())
.add_system_to_stage("physics", update_testbed.system())
.add_system(egui_focus.system())
.run();
.add_system(egui_focus.system());
init(&mut app);
app.run();
}
}
}