mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed names, debug and notify
Former-commit-id: f58dedf7c4eb9b284982588fc6b19bbe3edb0391
This commit is contained in:
parent
37367491da
commit
06693136b6
@ -59,11 +59,11 @@ impl Client {
|
||||
let mut postbox = PostBox::to(addr)?;
|
||||
|
||||
// Wait for initial sync
|
||||
let (state, player_entity) = match postbox.next_message() {
|
||||
let (state, entity) = match postbox.next_message() {
|
||||
Some(ServerMsg::InitialSync { ecs_state, entity_uid }) => {
|
||||
let mut state = State::from_state_package(ecs_state);
|
||||
let player_entity = state.ecs().entity_from_uid(entity_uid).ok_or(Error::ServerWentMad)?;
|
||||
(state, player_entity)
|
||||
let entity = state.ecs().entity_from_uid(entity_uid).ok_or(Error::ServerWentMad)?;
|
||||
(state, entity)
|
||||
},
|
||||
_ => return Err(Error::ServerWentMad),
|
||||
};
|
||||
@ -79,7 +79,7 @@ impl Client {
|
||||
|
||||
tick: 0,
|
||||
state,
|
||||
entity: player_entity,
|
||||
entity,
|
||||
view_distance,
|
||||
|
||||
pending_chunks: HashSet::new(),
|
||||
|
@ -12,7 +12,7 @@ pub enum RequestStateError {
|
||||
Impossible,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ServerMsg {
|
||||
InitialSync {
|
||||
ecs_state: sphynx::StatePackage<EcsPacket>,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum BiomeKind {
|
||||
Void,
|
||||
Grassland,
|
||||
|
@ -19,7 +19,7 @@ use crate::{
|
||||
|
||||
// TerrainChunkSize
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TerrainChunkSize;
|
||||
|
||||
impl VolSize for TerrainChunkSize {
|
||||
@ -28,7 +28,7 @@ impl VolSize for TerrainChunkSize {
|
||||
|
||||
// TerrainChunkMeta
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TerrainChunkMeta {
|
||||
biome: BiomeKind,
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ pub enum ChunkErr {
|
||||
// V = Voxel
|
||||
// S = Size (replace when const generics are a thing)
|
||||
// M = Metadata
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Chunk<V: Vox, S: VolSize, M> {
|
||||
vox: Vec<V>,
|
||||
meta: M,
|
||||
|
@ -58,7 +58,7 @@ impl Clients {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify_connected(&mut self, msg: ServerMsg) {
|
||||
pub fn notify_registered(&mut self, msg: ServerMsg) {
|
||||
for client in self.clients.values_mut() {
|
||||
if client.client_state != ClientState::Connected {
|
||||
client.notify(msg.clone());
|
||||
@ -66,11 +66,28 @@ impl Clients {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify_connected_except(&mut self, except_entity: EcsEntity, msg: ServerMsg) {
|
||||
pub fn notify_ingame(&mut self, msg: ServerMsg) {
|
||||
for client in self.clients.values_mut() {
|
||||
if client.client_state == ClientState::Spectator || client.client_state == ClientState::Character {
|
||||
client.notify(msg.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify_registered_except(&mut self, except_entity: EcsEntity, msg: ServerMsg) {
|
||||
for (entity, client) in self.clients.iter_mut() {
|
||||
if client.client_state != ClientState::Connected && *entity != except_entity {
|
||||
client.notify(msg.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify_ingame_except(&mut self, except_entity: EcsEntity, msg: ServerMsg) {
|
||||
for (entity, client) in self.clients.iter_mut() {
|
||||
if (client.client_state == ClientState::Spectator || client.client_state == ClientState::Character)
|
||||
&& *entity != except_entity {
|
||||
client.notify(msg.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ impl Server {
|
||||
let argv = String::from(&msg[1..]);
|
||||
self.process_chat_cmd(entity, argv);
|
||||
} else {
|
||||
self.clients.notify_connected(ServerMsg::Chat(
|
||||
self.clients.notify_registered(ServerMsg::Chat(
|
||||
match self
|
||||
.state
|
||||
.ecs()
|
||||
@ -410,7 +410,7 @@ impl Server {
|
||||
/// Sync client states with the most up to date information
|
||||
fn sync_clients(&mut self) {
|
||||
// Sync 'logical' state using Sphynx
|
||||
self.clients.notify_connected(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package()));
|
||||
self.clients.notify_registered(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package()));
|
||||
|
||||
// Sync 'physical' state
|
||||
for (entity, &uid, &pos, &vel, &dir, force_update) in (
|
||||
@ -429,8 +429,8 @@ impl Server {
|
||||
};
|
||||
|
||||
match force_update {
|
||||
Some(_) => self.clients.notify_connected(msg),
|
||||
None => self.clients.notify_connected_except(entity, msg),
|
||||
Some(_) => self.clients.notify_ingame(msg),
|
||||
None => self.clients.notify_ingame_except(entity, msg),
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ impl Server {
|
||||
continue;
|
||||
}
|
||||
|
||||
self.clients.notify_connected_except(entity, ServerMsg::EntityAnimation {
|
||||
self.clients.notify_ingame_except(entity, ServerMsg::EntityAnimation {
|
||||
entity: uid.into(),
|
||||
animation_history,
|
||||
});
|
||||
@ -499,6 +499,6 @@ impl Server {
|
||||
|
||||
impl Drop for Server {
|
||||
fn drop(&mut self) {
|
||||
self.clients.notify_connected(ServerMsg::Shutdown);
|
||||
self.clients.notify_registered(ServerMsg::Shutdown);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user