forked from lavina/lavina
rename socket => connection for consistency
This commit is contained in:
parent
57ea2dd2d7
commit
4e5ccd604c
|
@ -79,7 +79,7 @@ impl PlayerHandle {
|
||||||
let (sender, receiver) = channel(32);
|
let (sender, receiver) = channel(32);
|
||||||
let (promise, deferred) = oneshot();
|
let (promise, deferred) = oneshot();
|
||||||
self.tx
|
self.tx
|
||||||
.send(PlayerCommand::AddSocket { sender, promise })
|
.send(PlayerCommand::AddConnection { sender, promise })
|
||||||
.await;
|
.await;
|
||||||
let connection_id = deferred.await.unwrap();
|
let connection_id = deferred.await.unwrap();
|
||||||
PlayerConnection {
|
PlayerConnection {
|
||||||
|
@ -126,7 +126,7 @@ impl PlayerHandle {
|
||||||
|
|
||||||
pub enum PlayerCommand {
|
pub enum PlayerCommand {
|
||||||
/** Commands from connections */
|
/** Commands from connections */
|
||||||
AddSocket {
|
AddConnection {
|
||||||
sender: Sender<Updates>,
|
sender: Sender<Updates>,
|
||||||
promise: OneshotSender<ConnectionId>,
|
promise: OneshotSender<ConnectionId>,
|
||||||
},
|
},
|
||||||
|
@ -186,7 +186,7 @@ impl PlayerRegistry {
|
||||||
|
|
||||||
pub async fn get_or_create_player(&mut self, id: PlayerId) -> PlayerHandle {
|
pub async fn get_or_create_player(&mut self, id: PlayerId) -> PlayerHandle {
|
||||||
let player = Player {
|
let player = Player {
|
||||||
sockets: AnonTable::new(),
|
connections: AnonTable::new(),
|
||||||
};
|
};
|
||||||
let mut inner = self.0.write().unwrap();
|
let mut inner = self.0.write().unwrap();
|
||||||
if let Some((handle, _)) = inner.players.get(&id) {
|
if let Some((handle, _)) = inner.players.get(&id) {
|
||||||
|
@ -214,7 +214,7 @@ struct PlayerRegistryInner {
|
||||||
|
|
||||||
/// Player actor inner state representation.
|
/// Player actor inner state representation.
|
||||||
struct Player {
|
struct Player {
|
||||||
sockets: AnonTable<Sender<Updates>>,
|
connections: AnonTable<Sender<Updates>>,
|
||||||
}
|
}
|
||||||
impl Player {
|
impl Player {
|
||||||
fn launch(
|
fn launch(
|
||||||
|
@ -229,8 +229,8 @@ impl Player {
|
||||||
let fiber = tokio::task::spawn(async move {
|
let fiber = tokio::task::spawn(async move {
|
||||||
while let Some(cmd) = rx.recv().await {
|
while let Some(cmd) = rx.recv().await {
|
||||||
match cmd {
|
match cmd {
|
||||||
PlayerCommand::AddSocket { sender, promise } => {
|
PlayerCommand::AddConnection { sender, promise } => {
|
||||||
let connection_id = self.sockets.insert(sender);
|
let connection_id = self.connections.insert(sender);
|
||||||
promise.send(ConnectionId(connection_id));
|
promise.send(ConnectionId(connection_id));
|
||||||
}
|
}
|
||||||
PlayerCommand::JoinRoom {
|
PlayerCommand::JoinRoom {
|
||||||
|
@ -275,10 +275,10 @@ impl Player {
|
||||||
PlayerCommand::Update(update) => {
|
PlayerCommand::Update(update) => {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Player received an update, broadcasting to {} connections",
|
"Player received an update, broadcasting to {} connections",
|
||||||
self.sockets.len()
|
self.connections.len()
|
||||||
);
|
);
|
||||||
for socket in &self.sockets {
|
for connection in &self.connections {
|
||||||
socket.send(update.clone()).await;
|
connection.send(update.clone()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue