pite_script/
physics_bridge.rs1use pite_physics::PhysicsWorld;
3use std::sync::{Arc, Mutex, RwLock};
4
5static CURRENT_PHYSICS: RwLock<Option<Arc<Mutex<PhysicsWorld>>>> = RwLock::new(None);
6
7pub fn set_current_physics(physics: Option<Arc<Mutex<PhysicsWorld>>>) {
8 *CURRENT_PHYSICS.write().unwrap() = physics;
9}
10
11pub fn current_physics() -> Option<Arc<Mutex<PhysicsWorld>>> {
12 CURRENT_PHYSICS.read().unwrap().clone()
13}
14
15pub fn with_physics<R>(f: impl FnOnce(&mut PhysicsWorld) -> R) -> Option<R> {
16 let arc = current_physics()?;
17 let mut lock = arc.lock().ok()?;
18 Some(f(&mut lock))
19}