update lightyear + fix aiming crash (#67)

This commit is contained in:
PROMETHIA-27
2025-09-28 12:55:46 -04:00
committed by GitHub
parent fb4c6f501c
commit a07dfb3840
4 changed files with 437 additions and 496 deletions

875
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -64,7 +64,7 @@ bevy_trenchbroom = { version = "0.8.1", default-features = false, features = [
happy_feet = { git = "https://github.com/atornity/happy_feet.git", rev = "1b24ed95f166e63af35e7b6f9f0053d6d28e1f1a", features = [ happy_feet = { git = "https://github.com/atornity/happy_feet.git", rev = "1b24ed95f166e63af35e7b6f9f0053d6d28e1f1a", features = [
"serde", "serde",
] } ] }
lightyear = { version = "0.22.4", default-features = false, features = [ lightyear = { version = "0.24", git = "https://github.com/cBournhonesque/lightyear", rev = "69675e5f7b305ae02c3c2c3cd320bbc3e442ee4d", default-features = false, features = [
"input_native", "input_native",
"interpolation", "interpolation",
"netcode", "netcode",
@@ -73,8 +73,8 @@ lightyear = { version = "0.22.4", default-features = false, features = [
"std", "std",
"udp", "udp",
] } ] }
lightyear_avian3d = { git = "https://github.com/cBournhonesque/lightyear.git", rev = "03cbf419a2c0595261b64420bc0332fc3fe1cc3f" } lightyear_avian3d = { git = "https://github.com/cBournhonesque/lightyear", rev = "69675e5f7b305ae02c3c2c3cd320bbc3e442ee4d" }
lightyear_serde = "0.22.4" lightyear_serde = { git = "https://github.com/cBournhonesque/lightyear", rev = "69675e5f7b305ae02c3c2c3cd320bbc3e442ee4d" }
nil = "0.14.0" nil = "0.14.0"
rand = "=0.8.5" rand = "=0.8.5"
ron = "0.8" ron = "0.8"

View File

@@ -7,8 +7,13 @@ use bevy::{
}; };
use bevy_trenchbroom::geometry::Brushes; use bevy_trenchbroom::geometry::Brushes;
use lightyear::{ use lightyear::{
link::{LinkConditioner, prelude::*},
netcode::Key, netcode::Key,
prelude::{client::NetcodeConfig, input::native::InputMarker, *}, prelude::{
client::{Input, InputDelayConfig, NetcodeConfig},
input::native::InputMarker,
*,
},
}; };
use nil::prelude::Mutex; use nil::prelude::Mutex;
use shared::{ use shared::{
@@ -25,6 +30,7 @@ use std::{
net::{IpAddr, Ipv4Addr, SocketAddr}, net::{IpAddr, Ipv4Addr, SocketAddr},
process::Stdio, process::Stdio,
sync::{LazyLock, mpsc}, sync::{LazyLock, mpsc},
time::Duration,
}; };
/// Cache of server processes to be cleared at process exit /// Cache of server processes to be cleared at process exit
@@ -78,11 +84,21 @@ fn attempt_connection(mut commands: Commands) -> Result {
private_key: Key::default(), private_key: Key::default(),
protocol_id: 0, protocol_id: 0,
}; };
let sync_config = SyncConfig {
jitter_multiple: 5,
jitter_margin: Duration::from_millis(15),
..default()
};
let conditioner = LinkConditioner::new(LinkConditionerConfig {
incoming_latency: Duration::from_millis(10),
incoming_jitter: Duration::from_millis(0),
incoming_loss: 0.0,
});
commands commands
.spawn(( .spawn((
Name::from("Client"), Name::from("Client"),
Client::default(), Client::default(),
Link::new(None), Link::new(Some(conditioner)),
LocalAddr(client_addr), LocalAddr(client_addr),
PeerAddr(server_addr), PeerAddr(server_addr),
ReplicationReceiver::default(), ReplicationReceiver::default(),
@@ -94,6 +110,10 @@ fn attempt_connection(mut commands: Commands) -> Result {
}, },
)?, )?,
UdpIo::default(), UdpIo::default(),
InputTimeline(Timeline::from(Input::new(
sync_config,
InputDelayConfig::balanced(),
))),
)) ))
.trigger(Connect); .trigger(Connect);

View File

@@ -1,11 +1,17 @@
use crate::config::ServerConfig; use crate::config::ServerConfig;
use bevy::prelude::*; use bevy::prelude::*;
use lightyear::prelude::{ use lightyear::{
server::{NetcodeConfig, NetcodeServer, ServerUdpIo, Started}, link::LinkConditioner,
*, prelude::{
server::{NetcodeConfig, NetcodeServer, ServerUdpIo, Started},
*,
},
}; };
use shared::{GameState, global_observer, heads_database::HeadsDatabase, tb_entities::SpawnPoint}; use shared::{GameState, global_observer, heads_database::HeadsDatabase, tb_entities::SpawnPoint};
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
time::Duration,
};
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {
app.add_systems(Startup, (start_server, setup_timeout_timer)); app.add_systems(Startup, (start_server, setup_timeout_timer));
@@ -34,9 +40,15 @@ fn handle_new_client(
info!("Client connected on IP: {}", id.ip()); info!("Client connected on IP: {}", id.ip());
let conditioner = LinkConditioner::new(LinkConditionerConfig {
incoming_latency: Duration::from_millis(10),
incoming_jitter: Duration::from_millis(0),
incoming_loss: 0.0,
});
commands commands
.entity(trigger.target()) .entity(trigger.target())
.insert(ReplicationSender::default()); .insert((ReplicationSender::default(), Link::new(Some(conditioner))));
crate::player::spawn(commands, trigger.target(), query, asset_server, heads_db); crate::player::spawn(commands, trigger.target(), query, asset_server, heads_db);
@@ -56,11 +68,17 @@ fn close_on_disconnect(
fn start_server(mut commands: Commands) -> Result { fn start_server(mut commands: Commands) -> Result {
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 25565); let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 25565);
let conditioner = LinkConditioner::new(LinkConditionerConfig {
incoming_latency: Duration::from_millis(10),
incoming_jitter: Duration::from_millis(0),
incoming_loss: 0.0,
});
let mut commands = commands.spawn(( let mut commands = commands.spawn((
Name::from("Server"), Name::from("Server"),
LocalAddr(server_addr), LocalAddr(server_addr),
ServerUdpIo::default(), ServerUdpIo::default(),
NetcodeServer::new(NetcodeConfig::default()), NetcodeServer::new(NetcodeConfig::default()),
Link::new(Some(conditioner)),
)); ));
commands.trigger(server::Start); commands.trigger(server::Start);