Factor in connection latency when respawning player, bump LiteRustLib (with fix #143)

This commit is contained in:
NG (Graham) committed 2026-08-09 15:27:49 -04:00
1 parent 7147df2a9c
commit 961190a467
6 files changed
+29 -12

No files matched your search

+4 -4
View File
@@ -22,10 +22,10 @@ num-quaternion.workspace = true
rand.workspace = true
git-version.workspace = true
#literustlib_server = { version = "0.4", path = "../../LiteRustLib/server" }
#literustlib = { version = "0.4", path = "../../LiteRustLib" }
literustlib_server = { version = "0.4" }
literustlib = { version = "0.4" }
literustlib_server = { version = "0.5", path = "../../LiteRustLib/server" }
literustlib = { version = "0.5", path = "../../LiteRustLib" }
#literustlib_server = { version = "0.4" }
#literustlib = { version = "0.4" }
rlnl = { version = "0.1", path = "../../rlnl" }
oj_serdes.workspace = true
@@ -1298,6 +1298,12 @@ impl BattleArenaLogic {
};
if let Some(player_desc) = generic.user_descriptor(player_id) {
let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect();
let my_connection_latency = generic.users.read().await
.iter()
.filter(|(user_player_id, _)| **user_player_id == player_id)
.next()
.unwrap()
.1.connection.connection.latency();
tokio::task::spawn(super::respawn_player_after(
respawn_timestamp,
connections,
@@ -1305,6 +1311,7 @@ impl BattleArenaLogic {
Some(self.map_center.clone()),
player_id,
player_desc.machine.is_alive.clone(),
my_connection_latency,
));
} else {
log::error!("Player {} cannot respawn because they are not in the game!?", player_id);
+2 -2
View File
@@ -16,8 +16,8 @@ pub use team_death_match::TeamDeathMatchLogic;
pub(super) mod trackers;
async fn respawn_player_after(after: chrono::DateTime<chrono::Utc>, players: Vec<crate::matches::generic::UserSender>, spawn: oj_rc_core::persist::config::Point, looking_at: Option<oj_rc_core::persist::config::Point>, player_id: u8, alive_flag: std::sync::Arc<std::sync::atomic::AtomicBool>) {
let sleep_dur = after.signed_duration_since(chrono::Utc::now()).to_std().expect("Respawn duration too long to sleep");
async fn respawn_player_after(after: chrono::DateTime<chrono::Utc>, players: Vec<crate::matches::generic::UserSender>, spawn: oj_rc_core::persist::config::Point, looking_at: Option<oj_rc_core::persist::config::Point>, player_id: u8, alive_flag: std::sync::Arc<std::sync::atomic::AtomicBool>, player_latency: std::time::Duration) {
let sleep_dur = after.signed_duration_since(chrono::Utc::now()).to_std().expect("Respawn duration too long to sleep") - player_latency;
tokio::time::sleep(sleep_dur).await;
let spawn_payload = rlnl::events::sync::SpawnPoint {
pos: rlnl::types::PosQuatPair {
+7
View File
@@ -368,6 +368,12 @@ impl PitLogic {
).await;
let spawn_point = Self::choose_spawn_point(&generic.map_config, player_id).1;
let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect();
let my_connection_latency = generic.users.read().await
.iter()
.filter(|(user_player_id, _)| **user_player_id == player_id)
.next()
.unwrap()
.1.connection.connection.latency();
tokio::task::spawn(super::respawn_player_after(
respawn_timestamp,
connections,
@@ -375,6 +381,7 @@ impl PitLogic {
Some(self.map_center.clone()),
player_id,
player_desc.machine.is_alive.clone(),
my_connection_latency,
));
}
}
@@ -307,6 +307,12 @@ impl TeamDeathMatchLogic {
};
if let Some(player_desc) = generic.user_descriptor(player_id) {
let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect();
let my_connection_latency = generic.users.read().await
.iter()
.filter(|(user_player_id, _)| **user_player_id == player_id)
.next()
.unwrap()
.1.connection.connection.latency();
tokio::task::spawn(super::respawn_player_after(
respawn_timestamp,
connections,
@@ -314,6 +320,7 @@ impl TeamDeathMatchLogic {
Some(self.map_center.clone()),
player_id,
player_desc.machine.is_alive.clone(),
my_connection_latency,
));
} else {
log::error!("Player {} cannot respawn because they are not in the game!?", player_id);