aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 03:28:49 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 03:28:49 +0100
commitab675360c0005718a3c9b8b5e7962af897269c04 (patch)
treebfae0eafd5c5fa29c12d544f3075adfd5b96cbc5 /src
parente40eab9143fd881add48aba1e4ea1e1283c72cff (diff)
chore: play with network settings
Diffstat (limited to 'src')
-rw-r--r--src/client.rs1
-rw-r--r--src/protocol.rs5
-rw-r--r--src/server.rs17
-rw-r--r--src/shared.rs37
-rw-r--r--src/shared/ability.rs1
-rw-r--r--src/shared/health_event.rs1
-rw-r--r--src/shared/imperative.rs3
-rw-r--r--src/shared/player.rs45
-rw-r--r--src/shared/projectile.rs13
9 files changed, 75 insertions, 48 deletions
diff --git a/src/client.rs b/src/client.rs
index 8220047..e3c4594 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -6,6 +6,7 @@ use crate::shared::cooldown::*;
use crate::shared::health::*;
use crate::shared::health_event::*;
use crate::shared::imperative::*;
+use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::*;
use bevy::input::keyboard::*;
diff --git a/src/protocol.rs b/src/protocol.rs
index c1c18e4..1b7eaa0 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -3,8 +3,8 @@ use crate::shared::cooldown::*;
use crate::shared::health::*;
use crate::shared::health_event::*;
use crate::shared::imperative::*;
+use crate::shared::player::*;
use crate::shared::projectile::*;
-use crate::shared::*;
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::Deserialize;
@@ -31,7 +31,6 @@ pub enum Messages {
#[component_protocol(protocol = "MyProtocol")]
pub enum Components {
- #[sync(once)]
PlayerId(PlayerId),
PlayerPosition(PlayerPosition),
PlayerColor(PlayerColor),
@@ -54,7 +53,7 @@ protocolize! {
pub fn protocol() -> MyProtocol {
let mut protocol = MyProtocol::default();
protocol.add_channel::<Channel1>(ChannelSettings {
- mode: ChannelMode::OrderedReliable(ReliableSettings::default()),
+ mode: ChannelMode::UnorderedUnreliable,
..Default::default()
});
protocol
diff --git a/src/server.rs b/src/server.rs
index 6a22755..165c5f0 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -5,6 +5,7 @@ use crate::shared::cooldown::*;
use crate::shared::health::*;
use crate::shared::health_event::*;
use crate::shared::imperative::*;
+use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::*;
use bevy::prelude::*;
@@ -274,10 +275,11 @@ fn imperative_attack_attack(
};
if cooldown.a_cooldown.is_zero() {
cooldown.a_cooldown = Duration::from_secs_f32(1.5);
- commands.spawn(ProjectileBundle {
- projectile: ability.to_projectile(*id, position.0, target_player),
- replicate: Replicate::default(),
- });
+ commands.spawn(ProjectileBundle::new(ability.to_projectile(
+ *id,
+ position.0,
+ target_player,
+ )));
}
}
}
@@ -296,10 +298,9 @@ fn imperative_attack_attack(
};
if cooldown.a_cooldown.is_zero() {
cooldown.a_cooldown = Duration::from_secs_f32(1.5);
- commands.spawn(ProjectileBundle {
- projectile: ability.to_projectile(*id, position.0, direction),
- replicate: Replicate::default(),
- });
+ commands.spawn(ProjectileBundle::new(
+ ability.to_projectile(*id, position.0, direction),
+ ));
}
}
_ => {}
diff --git a/src/shared.rs b/src/shared.rs
index f5a813e..a06ff3e 100644
--- a/src/shared.rs
+++ b/src/shared.rs
@@ -15,6 +15,7 @@ pub mod cooldown;
pub mod health;
pub mod health_event;
pub mod imperative;
+pub mod player;
pub mod projectile;
pub const KEY: [u8; 32] = [
@@ -23,39 +24,3 @@ pub const KEY: [u8; 32] = [
pub const PLAYER_RADIUS: f32 = 10.;
pub const PROTOCOL_ID: u64 = 0;
pub const SERVER_PORT: u16 = 16384;
-
-#[derive(Bundle)]
-pub struct PlayerBundle {
- id: PlayerId,
- position: PlayerPosition,
- color: PlayerColor,
- replicate: Replicate,
- imperative: Imperative,
- cooldown: Cooldown,
- health: Health,
- champion: Champion,
-}
-
-#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
-pub struct PlayerId(pub ClientId);
-
-#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
-pub struct PlayerPosition(pub Vec2);
-
-#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
-pub struct PlayerColor(pub Color);
-
-impl PlayerBundle {
- pub fn new(id: ClientId, position: Vec2, color: Color) -> Self {
- PlayerBundle {
- id: PlayerId(id),
- position: PlayerPosition(position),
- color: PlayerColor(color),
- replicate: Replicate::default(),
- imperative: Imperative::Idle,
- cooldown: Cooldown::default(),
- health: Health::default(),
- champion: Champion::default(),
- }
- }
-}
diff --git a/src/shared/ability.rs b/src/shared/ability.rs
index 8ef0c29..9639afe 100644
--- a/src/shared/ability.rs
+++ b/src/shared/ability.rs
@@ -1,3 +1,4 @@
+use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::*;
diff --git a/src/shared/health_event.rs b/src/shared/health_event.rs
index 9932599..10af4ed 100644
--- a/src/shared/health_event.rs
+++ b/src/shared/health_event.rs
@@ -1,3 +1,4 @@
+use crate::shared::player::*;
use crate::shared::*;
#[derive(Message, Serialize, Deserialize, PartialEq, Clone, Debug)]
diff --git a/src/shared/imperative.rs b/src/shared/imperative.rs
index bd604f8..afdf244 100644
--- a/src/shared/imperative.rs
+++ b/src/shared/imperative.rs
@@ -1,9 +1,10 @@
use crate::shared::ability::*;
+use crate::shared::player::*;
use crate::shared::*;
use serde::Deserialize;
use serde::Serialize;
-#[derive(Component, Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
+#[derive(Component, Message, Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum Imperative {
Idle,
WalkTo(Vec2),
diff --git a/src/shared/player.rs b/src/shared/player.rs
new file mode 100644
index 0000000..a886499
--- /dev/null
+++ b/src/shared/player.rs
@@ -0,0 +1,45 @@
+use crate::shared::*;
+
+#[derive(Bundle)]
+pub struct PlayerBundle {
+ id: PlayerId,
+ position: PlayerPosition,
+ color: PlayerColor,
+ imperative: Imperative,
+ cooldown: Cooldown,
+ health: Health,
+ champion: Champion,
+ replicate: Replicate,
+}
+
+impl PlayerBundle {
+ pub fn new(id: ClientId, position: Vec2, color: Color) -> Self {
+ let mut replicate = Replicate {
+ replication_group: ReplicationGroup::default().set_priority(10.),
+ ..Default::default()
+ };
+ replicate.enable_replicate_once::<PlayerId>();
+ replicate.enable_replicate_once::<PlayerColor>();
+ replicate.target::<Cooldown>(NetworkTarget::Single(id));
+ replicate.target::<Champion>(NetworkTarget::Single(id));
+ PlayerBundle {
+ id: PlayerId(id),
+ position: PlayerPosition(position),
+ color: PlayerColor(color),
+ imperative: Imperative::Idle,
+ cooldown: Cooldown::default(),
+ health: Health::default(),
+ champion: Champion::default(),
+ replicate,
+ }
+ }
+}
+
+#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
+pub struct PlayerId(pub ClientId);
+
+#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
+pub struct PlayerPosition(pub Vec2);
+
+#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
+pub struct PlayerColor(pub Color);
diff --git a/src/shared/projectile.rs b/src/shared/projectile.rs
index f944e8a..772f5d9 100644
--- a/src/shared/projectile.rs
+++ b/src/shared/projectile.rs
@@ -1,3 +1,4 @@
+use crate::shared::player::*;
use crate::shared::*;
#[derive(Bundle)]
@@ -6,6 +7,18 @@ pub struct ProjectileBundle {
pub replicate: Replicate,
}
+impl ProjectileBundle {
+ pub fn new(projectile: Projectile) -> Self {
+ ProjectileBundle {
+ projectile,
+ replicate: Replicate {
+ replication_group: ReplicationGroup::default().set_priority(1.),
+ ..Default::default()
+ },
+ }
+ }
+}
+
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Projectile {