use crate::ecs::snapshot::hooks::SnapshotCapability;
use crate::ecs::world::World;
use crate::plugins::physics::resources::PhysicsWorld;
pub fn register_snapshot_capability(world: &mut World) {
crate::ecs::snapshot::hooks::register_snapshot_capability(
world,
SnapshotCapability {
key: "physics",
member_world: |world| {
world
.ecs
.resource::<PhysicsWorld>()
.and_then(|physics| physics.component_world)
},
registry: crate::plugins::physics::schema::register_physics_components,
restore: restore_physics,
},
);
}
fn restore_physics(world: &mut World, member_world: Option<usize>) {
if world.ecs.resource::<PhysicsWorld>().is_none() {
return;
}
let physics = world.plugin_resource_mut::<PhysicsWorld>();
let gravity = physics.gravity;
let fixed_timestep = physics.fixed_timestep;
let max_substeps = physics.max_substeps;
let enabled = physics.enabled;
let debug_draw = physics.debug_draw;
*physics = PhysicsWorld::default();
physics.gravity = gravity;
physics.fixed_timestep = fixed_timestep;
physics.max_substeps = max_substeps;
physics.enabled = enabled;
physics.debug_draw = debug_draw;
physics.component_world = member_world;
}