-
Notifications
You must be signed in to change notification settings - Fork 16
/
protocol.rs
98 lines (92 loc) · 2.1 KB
/
protocol.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use bevy::prelude::{Entity, Vec2, Vec3};
use bevy_quinnet::shared::{
channels::{ChannelId, ChannelType, ChannelsConfiguration},
ClientId,
};
use serde::{Deserialize, Serialize};
use crate::BrickId;
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) enum PaddleInput {
#[default]
None,
Left,
Right,
}
// Messages from clients
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) enum ClientMessage {
PaddleInput { input: PaddleInput },
}
// Messages from the server
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) enum ServerMessage {
InitClient {
client_id: ClientId,
},
SpawnPaddle {
owner_client_id: ClientId,
entity: Entity,
position: Vec3,
},
SpawnBall {
owner_client_id: ClientId,
entity: Entity,
position: Vec3,
direction: Vec2,
},
SpawnBricks {
offset: Vec2,
rows: usize,
columns: usize,
},
StartGame,
BrickDestroyed {
by_client_id: ClientId,
brick_id: BrickId,
},
BallCollided {
owner_client_id: ClientId,
entity: Entity,
position: Vec3,
velocity: Vec2,
},
PaddleMoved {
entity: Entity,
position: Vec3,
},
}
#[repr(u8)]
pub enum ClientChannel {
PaddleCommands,
}
impl Into<ChannelId> for ClientChannel {
fn into(self) -> ChannelId {
self as ChannelId
}
}
impl ClientChannel {
pub fn channels_configuration() -> ChannelsConfiguration {
ChannelsConfiguration::from_types(vec![ChannelType::OrderedReliable]).unwrap()
}
}
#[repr(u8)]
pub enum ServerChannel {
GameSetup,
GameEvents,
PaddleUpdates,
}
impl Into<ChannelId> for ServerChannel {
fn into(self) -> ChannelId {
self as ChannelId
}
}
impl ServerChannel {
pub fn channels_configuration() -> ChannelsConfiguration {
ChannelsConfiguration::from_types(vec![
ChannelType::OrderedReliable,
ChannelType::UnorderedReliable,
ChannelType::Unreliable,
])
.unwrap()
}
}