diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-04-08 11:48:54 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-04-08 12:10:44 +0200 |
commit | 7643fb90dcf148605e3309c2007cd8a4c27914fa (patch) | |
tree | 5caf8100b3d99418dad1e284398392aa83fa29bb | |
parent | 80109d0da833842695948fe404489ea33f9dcfdb (diff) |
chore: update lightyear to 0.13.0
-rw-r--r-- | Cargo.lock | 13 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/client.rs | 103 | ||||
-rw-r--r-- | src/client/network.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/server.rs | 12 |
6 files changed, 84 insertions, 53 deletions
@@ -1433,9 +1433,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", @@ -2780,9 +2780,9 @@ dependencies = [ [[package]] name = "lightyear" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410945fe163a11eee759ffbe8beff893d259e276ce1823ff63ec5b18b8e249ba" +checksum = "595f5af63a6c42288c35915d7b84fc37dae6aa1d1edd7266ec9e773110f86924" dependencies = [ "anyhow", "async-compat", @@ -2805,6 +2805,7 @@ dependencies = [ "instant", "lightyear_macros", "nonzero_ext", + "parking_lot", "paste", "rand", "ringbuffer", @@ -2819,9 +2820,9 @@ dependencies = [ [[package]] name = "lightyear_macros" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc977b2d3f117608514cc692340599953f7666235c878f02f44e58f51bd9ad0" +checksum = "0b3a812fb12460d8a0bc2f1bbd1af686b3b4fde8650cfe2b3b86b31d8de8eede" dependencies = [ "anyhow", "darling", @@ -7,7 +7,7 @@ edition = "2021" bevy = { version = "0.13.2" } clap = { version = "4.5.2", features = ["derive"] } crossbeam-channel = { version = "0.5.12" } -lightyear = { version = "0.12.0" } +lightyear = { version = "0.13.0" } rand = { version = "0.8.5" } serde = { version = "1.0.197" } diff --git a/src/client.rs b/src/client.rs index e2f52cb..007edc6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,8 +19,12 @@ use bevy::input::keyboard::*; use bevy::input::mouse::MouseButton; use bevy::prelude::*; use bevy::sprite::{MaterialMesh2dBundle, Mesh2dHandle}; +use lightyear::client::connection::ConnectionManager; use lightyear::client::events::*; +use lightyear::client::input::InputManager; use lightyear::client::input::InputSystemSet; +use lightyear::prelude::client::ClientConnection; +use lightyear::prelude::client::NetClient; use lightyear::prelude::*; use std::net::SocketAddr; @@ -28,7 +32,7 @@ mod network; pub fn main( server_addr: Option<SocketAddr>, - client_id: u64, + client_id: ClientId, transport: TransportConfig, champion: Champion, faction: Faction, @@ -46,7 +50,7 @@ pub fn main( } #[derive(Resource)] -struct ClientId(pub u64); +struct MyClientId(ClientId); #[derive(Resource)] struct MyChampion(pub Champion); @@ -65,7 +69,7 @@ struct CameraControls { struct ClientPlugin { pub server_addr: Option<SocketAddr>, - pub client_id: u64, + pub client_id: ClientId, pub transport: TransportConfig, pub champion: Champion, pub faction: Faction, @@ -73,14 +77,18 @@ struct ClientPlugin { impl Plugin for ClientPlugin { fn build(&self, app: &mut App) { - app.insert_resource(ClientId(self.client_id)) + app.insert_resource(MyClientId(self.client_id)) .insert_resource(MyChampion(self.champion)) .insert_resource(MyFaction(self.faction)) .insert_resource(Attack(None)) .insert_resource(CameraControls::default()) .add_plugins(NetworkPlugin { server_addr: self.server_addr.clone(), - client_id: self.client_id, + client_id: match self.client_id { + ClientId::Netcode(client_id) => client_id, + ClientId::Steam(client_id) => client_id, + ClientId::Local(client_id) => client_id, + }, transport: self.transport.clone(), }) .add_systems(Startup, setup) @@ -137,10 +145,11 @@ pub struct Hotbar(AbilitySlot); pub struct HotbarCooldown(AbilitySlot); fn setup( - mut client: ClientMut, + mut client: ResMut<ClientConnection>, mut commands: Commands, champion: Res<MyChampion>, faction: Res<MyFaction>, + mut connection_manager: ResMut<ConnectionManager<MyProtocol>>, ) { commands.spawn(Camera2dBundle::default()); commands @@ -214,10 +223,10 @@ fn setup( } }); client.connect().unwrap(); - client + connection_manager .send_message::<Channel1, SelectChampion>(SelectChampion(champion.0)) .unwrap(); - client + connection_manager .send_message::<Channel1, SelectFaction>(SelectFaction(faction.0)) .unwrap(); } @@ -311,12 +320,13 @@ fn buffer_input( players: Query<(&PlayerId, &PlayerPosition, &Shape)>, mut attack: ResMut<Attack>, cameras: Query<(&Camera, &GlobalTransform)>, - client_id: Res<ClientId>, + client_id: Res<MyClientId>, keyboard_input: Res<ButtonInput<KeyCode>>, mouse_input: Res<ButtonInput<MouseButton>>, - mut client: ClientMut, + mut input_manager: ResMut<InputManager<Inputs>>, windows: Query<&Window>, champion: Res<MyChampion>, + tick_manager: Res<TickManager>, ) { if mouse_input.just_pressed(MouseButton::Left) { match attack.0 { @@ -330,10 +340,10 @@ fn buffer_input( return; }; let direction = world_position - position.0; - client.add_input(Inputs::Imperative(Imperative::AttackDirection( - ability_slot, - direction, - ))); + input_manager.add_input( + Inputs::Imperative(Imperative::AttackDirection(ability_slot, direction)), + tick_manager.tick(), + ); attack.0 = None; } Ability::Targeted(_) => { @@ -346,10 +356,10 @@ fn buffer_input( ) else { return; }; - client.add_input(Inputs::Imperative(Imperative::AttackTarget( - ability_slot, - target_player, - ))); + input_manager.add_input( + Inputs::Imperative(Imperative::AttackTarget(ability_slot, target_player)), + tick_manager.tick(), + ); attack.0 = None; } }, @@ -361,13 +371,16 @@ fn buffer_input( &players, &windows, ) { - client.add_input(Inputs::Imperative(Imperative::AttackTarget( - AbilitySlot::A, - target_player, - ))); + input_manager.add_input( + Inputs::Imperative(Imperative::AttackTarget(AbilitySlot::A, target_player)), + tick_manager.tick(), + ); } else { if let Some(world_position) = cursor_world_position(&windows, &cameras) { - client.add_input(Inputs::Imperative(Imperative::WalkTo(world_position))); + input_manager.add_input( + Inputs::Imperative(Imperative::WalkTo(world_position)), + tick_manager.tick(), + ); } } } @@ -376,15 +389,18 @@ fn buffer_input( match attack.0 { None => { if let Some(world_position) = cursor_world_position(&windows, &cameras) { - client.add_input(Inputs::Imperative(Imperative::WalkTo(world_position))); + input_manager.add_input( + Inputs::Imperative(Imperative::WalkTo(world_position)), + tick_manager.tick(), + ); } } Some(_) => {} } } else if keyboard_input.just_pressed(KeyCode::KeyS) { - client.add_input(Inputs::Imperative(Imperative::Idle)); + input_manager.add_input(Inputs::Imperative(Imperative::Idle), tick_manager.tick()); } else { - client.add_input(Inputs::None); + input_manager.add_input(Inputs::None, tick_manager.tick()); } } @@ -393,7 +409,8 @@ fn choose_attack( keyboard_input: Res<ButtonInput<KeyCode>>, mouse_input: Res<ButtonInput<MouseButton>>, mut attack: ResMut<Attack>, - mut client: ClientMut, + mut input_manager: ResMut<InputManager<Inputs>>, + tick_manager: Res<TickManager>, ) { if keyboard_input.just_pressed(KeyCode::KeyA) { attack.0 = Some(AbilitySlot::A); @@ -419,7 +436,10 @@ fn choose_attack( match attack.0 { Some(ability_slot) => match champion.0.ability(ability_slot) { Ability::Activated(_) => { - client.add_input(Inputs::Activation(Activation::Activate(ability_slot))); + input_manager.add_input( + Inputs::Activation(Activation::Activate(ability_slot)), + tick_manager.tick(), + ); attack.0 = None; } _ => {} @@ -430,7 +450,7 @@ fn choose_attack( fn gizmos_hover_indicator( cameras: Query<(&Camera, &GlobalTransform)>, - client_id: Res<ClientId>, + client_id: Res<MyClientId>, hoverables: Query<(&PlayerId, &PlayerPosition, &Shape)>, mut gizmos: Gizmos, windows: Query<&Window>, @@ -471,7 +491,7 @@ const HOVER_RANGE_ATTACK: f32 = 100.; fn hovered_other_player_within( range: f32, cameras: &Query<(&Camera, &GlobalTransform)>, - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, hoverables: &Query<(&PlayerId, &PlayerPosition, &Shape)>, windows: &Query<&Window>, ) -> Option<(PlayerId, PlayerPosition, Shape)> { @@ -498,7 +518,7 @@ fn hovered_other_player_within( fn gizmos_attack_indicator( attack: Res<Attack>, cameras: Query<(&Camera, &GlobalTransform)>, - client_id: Res<ClientId>, + client_id: Res<MyClientId>, effective_statses: Query<(&PlayerId, &EffectiveStats)>, mut gizmos: Gizmos, player_champions: Query<(&PlayerId, &Champion)>, @@ -592,7 +612,7 @@ fn gizmos_attack_indicator( } fn player_entity( - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, players: &Query<(&PlayerId, Entity)>, ) -> Option<Entity> { for (id, entity) in players.iter() { @@ -604,7 +624,7 @@ fn player_entity( } fn player_position( - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, players: &Query<(&PlayerId, &PlayerPosition, &Shape)>, ) -> Option<PlayerPosition> { for (id, position, _) in players.iter() { @@ -628,7 +648,7 @@ fn other_player_position( } fn player_effective_stats( - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, players: &Query<(&PlayerId, &EffectiveStats)>, ) -> Option<EffectiveStats> { for (id, effective_stats) in players.iter() { @@ -640,7 +660,7 @@ fn player_effective_stats( } fn player_champion( - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, players: &Query<(&PlayerId, &Champion)>, ) -> Option<Champion> { for (id, champion) in players.iter() { @@ -651,7 +671,10 @@ fn player_champion( None } -fn player_shape(client_id: &Res<ClientId>, players: &Query<(&PlayerId, &Shape)>) -> Option<Shape> { +fn player_shape( + client_id: &Res<MyClientId>, + players: &Query<(&PlayerId, &Shape)>, +) -> Option<Shape> { for (id, shape) in players.iter() { if id.0 == client_id.0 { return Some(*shape); @@ -741,7 +764,7 @@ fn render_tower_target( } fn hotbar_cooldown( - client_id: Res<ClientId>, + client_id: Res<MyClientId>, cooldowns: Query<(&PlayerId, &Cooldown)>, mut hotbar_cooldowns: Query<(&HotbarCooldown, &mut Text, &mut Style)>, ) { @@ -763,7 +786,7 @@ fn hotbar_cooldown( } fn player_cooldown( - client_id: &Res<ClientId>, + client_id: &Res<MyClientId>, players: &Query<(&PlayerId, &Cooldown)>, ) -> Option<Cooldown> { for (id, cooldown) in players.iter() { @@ -775,7 +798,7 @@ fn player_cooldown( } fn hotbar_hotbar_display( - client_id: Res<ClientId>, + client_id: Res<MyClientId>, cooldowns: Query<(&PlayerId, &Cooldown)>, mut hotbars: Query<(&Hotbar, &mut Style)>, ) { @@ -907,7 +930,7 @@ fn move_camera( mut cameras: Query<&mut Transform, With<Camera>>, time: Res<Time>, camera_controls: Res<CameraControls>, - client_id: Res<ClientId>, + client_id: Res<MyClientId>, players: Query<(&PlayerId, &PlayerPosition, &Shape)>, ) { let dt = time.delta().as_secs_f32(); diff --git a/src/client/network.rs b/src/client/network.rs index df55cc9..2ce3a41 100644 --- a/src/client/network.rs +++ b/src/client/network.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; use lightyear::client::config::*; use lightyear::client::plugin::ClientPlugin; use lightyear::client::plugin::PluginConfig; -use lightyear::client::resource::Authentication; +use lightyear::prelude::client::Authentication; use lightyear::prelude::client::NetConfig; use lightyear::prelude::*; use lightyear::transport::LOCAL_SOCKET; diff --git a/src/main.rs b/src/main.rs index 4ee5e14..210909b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use crate::shared::champion::*; use crate::shared::faction::*; use clap::Parser; +use lightyear::connection::id::ClientId; use lightyear::transport::io::TransportConfig; use rand::Rng; use shared::SERVER_PORT; @@ -42,7 +43,7 @@ fn main() { let client_addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), SERVER_PORT + client_id); client::main( Some(server_addr), - client_id as u64, + ClientId::Netcode(client_id as u64), TransportConfig::UdpSocket(client_addr), cli.champion, cli.faction, @@ -60,7 +61,7 @@ fn main() { client::main( None, - client_id as u64, + ClientId::Netcode(client_id as u64), TransportConfig::LocalChannel { recv: from_server_recv, send: to_server_send, diff --git a/src/server.rs b/src/server.rs index 003b5e5..a509f28 100644 --- a/src/server.rs +++ b/src/server.rs @@ -61,7 +61,13 @@ impl Plugin for ServerPlugin { }) .add_systems(Startup, setup) .add_systems(Update, (connects, disconnects)) - .add_systems(Update, (receive_message_select_champion, receive_message_select_faction)) + .add_systems( + Update, + ( + receive_message_select_champion, + receive_message_select_faction, + ), + ) .add_systems(FixedUpdate, timers_tick) .add_systems(FixedUpdate, effective_stats.after(buffs_despawn)) .add_systems(FixedUpdate, health_regen.after(timers_tick)) @@ -984,12 +990,12 @@ fn nexus_spawn_minions( } } -fn generate_client_ids<const N: usize>(entity_map: &ResMut<EntityMap>) -> [u64; N] { +fn generate_client_ids<const N: usize>(entity_map: &ResMut<EntityMap>) -> [ClientId; N] { let mut rng = rand::thread_rng(); let mut k = 0; let mut client_ids = vec![]; while k < N { - let client_id = rng.gen(); + let client_id = ClientId::Local(rng.gen()); if entity_map.0.contains_key(&client_id) { continue; } |