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)?;
|
let mut postbox = PostBox::to(addr)?;
|
||||||
|
|
||||||
// Wait for initial sync
|
// 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 }) => {
|
Some(ServerMsg::InitialSync { ecs_state, entity_uid }) => {
|
||||||
let mut state = State::from_state_package(ecs_state);
|
let mut state = State::from_state_package(ecs_state);
|
||||||
let player_entity = state.ecs().entity_from_uid(entity_uid).ok_or(Error::ServerWentMad)?;
|
let entity = state.ecs().entity_from_uid(entity_uid).ok_or(Error::ServerWentMad)?;
|
||||||
(state, player_entity)
|
(state, entity)
|
||||||
},
|
},
|
||||||
_ => return Err(Error::ServerWentMad),
|
_ => return Err(Error::ServerWentMad),
|
||||||
};
|
};
|
||||||
@ -79,7 +79,7 @@ impl Client {
|
|||||||
|
|
||||||
tick: 0,
|
tick: 0,
|
||||||
state,
|
state,
|
||||||
entity: player_entity,
|
entity,
|
||||||
view_distance,
|
view_distance,
|
||||||
|
|
||||||
pending_chunks: HashSet::new(),
|
pending_chunks: HashSet::new(),
|
||||||
|
@ -12,7 +12,7 @@ pub enum RequestStateError {
|
|||||||
Impossible,
|
Impossible,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum ServerMsg {
|
pub enum ServerMsg {
|
||||||
InitialSync {
|
InitialSync {
|
||||||
ecs_state: sphynx::StatePackage<EcsPacket>,
|
ecs_state: sphynx::StatePackage<EcsPacket>,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use serde_derive::{Serialize, Deserialize};
|
use serde_derive::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum BiomeKind {
|
pub enum BiomeKind {
|
||||||
Void,
|
Void,
|
||||||
Grassland,
|
Grassland,
|
||||||
|
@ -19,7 +19,7 @@ use crate::{
|
|||||||
|
|
||||||
// TerrainChunkSize
|
// TerrainChunkSize
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct TerrainChunkSize;
|
pub struct TerrainChunkSize;
|
||||||
|
|
||||||
impl VolSize for TerrainChunkSize {
|
impl VolSize for TerrainChunkSize {
|
||||||
@ -28,7 +28,7 @@ impl VolSize for TerrainChunkSize {
|
|||||||
|
|
||||||
// TerrainChunkMeta
|
// TerrainChunkMeta
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct TerrainChunkMeta {
|
pub struct TerrainChunkMeta {
|
||||||
biome: BiomeKind,
|
biome: BiomeKind,
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ pub enum ChunkErr {
|
|||||||
// V = Voxel
|
// V = Voxel
|
||||||
// S = Size (replace when const generics are a thing)
|
// S = Size (replace when const generics are a thing)
|
||||||
// M = Metadata
|
// M = Metadata
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Chunk<V: Vox, S: VolSize, M> {
|
pub struct Chunk<V: Vox, S: VolSize, M> {
|
||||||
vox: Vec<V>,
|
vox: Vec<V>,
|
||||||
meta: M,
|
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() {
|
for client in self.clients.values_mut() {
|
||||||
if client.client_state != ClientState::Connected {
|
if client.client_state != ClientState::Connected {
|
||||||
client.notify(msg.clone());
|
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() {
|
for (entity, client) in self.clients.iter_mut() {
|
||||||
if client.client_state != ClientState::Connected && *entity != except_entity {
|
if client.client_state != ClientState::Connected && *entity != except_entity {
|
||||||
client.notify(msg.clone());
|
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..]);
|
let argv = String::from(&msg[1..]);
|
||||||
self.process_chat_cmd(entity, argv);
|
self.process_chat_cmd(entity, argv);
|
||||||
} else {
|
} else {
|
||||||
self.clients.notify_connected(ServerMsg::Chat(
|
self.clients.notify_registered(ServerMsg::Chat(
|
||||||
match self
|
match self
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
@ -410,7 +410,7 @@ impl Server {
|
|||||||
/// Sync client states with the most up to date information
|
/// Sync client states with the most up to date information
|
||||||
fn sync_clients(&mut self) {
|
fn sync_clients(&mut self) {
|
||||||
// Sync 'logical' state using Sphynx
|
// 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
|
// Sync 'physical' state
|
||||||
for (entity, &uid, &pos, &vel, &dir, force_update) in (
|
for (entity, &uid, &pos, &vel, &dir, force_update) in (
|
||||||
@ -429,8 +429,8 @@ impl Server {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match force_update {
|
match force_update {
|
||||||
Some(_) => self.clients.notify_connected(msg),
|
Some(_) => self.clients.notify_ingame(msg),
|
||||||
None => self.clients.notify_connected_except(entity, msg),
|
None => self.clients.notify_ingame_except(entity, msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ impl Server {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.clients.notify_connected_except(entity, ServerMsg::EntityAnimation {
|
self.clients.notify_ingame_except(entity, ServerMsg::EntityAnimation {
|
||||||
entity: uid.into(),
|
entity: uid.into(),
|
||||||
animation_history,
|
animation_history,
|
||||||
});
|
});
|
||||||
@ -499,6 +499,6 @@ impl Server {
|
|||||||
|
|
||||||
impl Drop for Server {
|
impl Drop for Server {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.clients.notify_connected(ServerMsg::Shutdown);
|
self.clients.notify_registered(ServerMsg::Shutdown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user