use std::{time::Duration, sync::Arc};
use log::{error};
use rapier2d::prelude::{PhysicsPipeline};
use tokio::{time::sleep, sync::RwLock};
use crate::{manager::{ClientHandlerMessage, ClientManager, PhysicsData}, SCALE};
pub async fn timer_main(mgr: ClientManager, physics_data: Arc<RwLock<PhysicsData>>) {
let mut pipeline = PhysicsPipeline::new();
loop {
sleep(Duration::from_millis(5)).await;
physics_data.write().await.tick(&mut pipeline);
for (_addr, client_thread) in mgr.handlers.read().await.iter() {
match client_thread.tx.send(ClientHandlerMessage::Tick).await {
Ok(_) => (),
Err(e) => {
error!("unable to update a client thread: {}", e);
}
}
}
}
}