mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Change client_state_pending to ClientState::Pending
Former-commit-id: 4b6a304a138ccfbffc3b6e28d36feaa2693d01a7
This commit is contained in:
parent
1dbca8b994
commit
3697c47e33
@ -30,8 +30,7 @@ pub enum Event {
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
client_state: Option<ClientState>,
|
||||
pending_state_request: bool,
|
||||
client_state: ClientState,
|
||||
thread_pool: ThreadPool,
|
||||
|
||||
last_ping: f64,
|
||||
@ -52,7 +51,7 @@ impl Client {
|
||||
/// Create a new `Client`.
|
||||
#[allow(dead_code)]
|
||||
pub fn new<A: Into<SocketAddr>>(addr: A, view_distance: Option<u32>) -> Result<Self, Error> {
|
||||
let mut client_state = Some(ClientState::Connected);
|
||||
let mut client_state = ClientState::Connected;
|
||||
let mut postbox = PostBox::to(addr)?;
|
||||
|
||||
// Wait for initial sync
|
||||
@ -76,7 +75,6 @@ impl Client {
|
||||
|
||||
Ok(Self {
|
||||
client_state,
|
||||
pending_state_request: false,
|
||||
thread_pool: threadpool::Builder::new()
|
||||
.thread_name("veloren-worker".into())
|
||||
.build(),
|
||||
@ -98,13 +96,13 @@ impl Client {
|
||||
|
||||
pub fn register(&mut self, player: comp::Player) {
|
||||
self.postbox.send_message(ClientMsg::Register { player });
|
||||
self.pending_state_request = true;
|
||||
self.client_state = ClientState::Pending;
|
||||
}
|
||||
|
||||
pub fn request_character(&mut self, name: String, body: comp::Body) {
|
||||
self.postbox
|
||||
.send_message(ClientMsg::Character { name, body });
|
||||
self.pending_state_request = true;
|
||||
self.client_state = ClientState::Pending;
|
||||
}
|
||||
|
||||
pub fn set_view_distance(&mut self, view_distance: u32) {
|
||||
@ -148,15 +146,10 @@ impl Client {
|
||||
|
||||
/// Get the client state
|
||||
#[allow(dead_code)]
|
||||
pub fn get_client_state(&self) -> Option<ClientState> {
|
||||
pub fn get_client_state(&self) -> ClientState {
|
||||
self.client_state
|
||||
}
|
||||
|
||||
/// Get the pending state request bool
|
||||
pub fn is_request_pending(&self) -> bool {
|
||||
self.pending_state_request
|
||||
}
|
||||
|
||||
/// Get the current tick number.
|
||||
#[allow(dead_code)]
|
||||
pub fn get_tick(&self) -> u64 {
|
||||
@ -360,18 +353,15 @@ impl Client {
|
||||
self.pending_chunks.remove(&key);
|
||||
}
|
||||
ServerMsg::StateAnswer(Ok(state)) => {
|
||||
self.client_state = Some(state);
|
||||
self.pending_state_request = false;
|
||||
self.client_state = state;
|
||||
}
|
||||
ServerMsg::StateAnswer(Err((error, state))) => {
|
||||
self.client_state = Some(state);
|
||||
self.pending_state_request = false;
|
||||
self.client_state = state;
|
||||
}
|
||||
ServerMsg::ForceState(state) => {
|
||||
self.client_state = Some(state);
|
||||
self.client_state = state;
|
||||
}
|
||||
ServerMsg::Disconnect => {
|
||||
self.client_state = None;
|
||||
frontend_events.push(Event::Disconnect);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ pub use self::server::{RequestStateError, ServerMsg};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ClientState {
|
||||
Pending,
|
||||
Connected,
|
||||
Registered,
|
||||
Spectator,
|
||||
|
@ -384,6 +384,7 @@ impl Server {
|
||||
ClientState::Spectator
|
||||
| ClientState::Character
|
||||
| ClientState::Dead => client.allow_state(ClientState::Registered),
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
ClientState::Spectator => match requested_state {
|
||||
// Become Registered first.
|
||||
@ -396,12 +397,14 @@ impl Server {
|
||||
ClientState::Registered
|
||||
| ClientState::Character
|
||||
| ClientState::Dead => client.allow_state(ClientState::Spectator),
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
// Use ClientMsg::Character instead.
|
||||
ClientState::Character => {
|
||||
client.error_state(RequestStateError::WrongMessage)
|
||||
}
|
||||
ClientState::Dead => client.error_state(RequestStateError::Impossible),
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
ClientMsg::Register { player } => match client.client_state {
|
||||
ClientState::Connected => {
|
||||
@ -433,6 +436,7 @@ impl Server {
|
||||
ClientState::Character => {
|
||||
client.error_state(RequestStateError::Already)
|
||||
}
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
ClientMsg::Chat(msg) => match client.client_state {
|
||||
ClientState::Connected => {
|
||||
@ -442,6 +446,7 @@ impl Server {
|
||||
| ClientState::Spectator
|
||||
| ClientState::Dead
|
||||
| ClientState::Character => new_chat_msgs.push((entity, msg)),
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
ClientMsg::PlayerInputs(mut inputs) => match client.client_state {
|
||||
ClientState::Character | ClientState::Dead => {
|
||||
@ -490,6 +495,7 @@ impl Server {
|
||||
None => requested_chunks.push(key),
|
||||
}
|
||||
}
|
||||
ClientState::Pending => {}
|
||||
},
|
||||
// Always possible.
|
||||
ClientMsg::Ping => client.postbox.send_message(ServerMsg::Pong),
|
||||
|
@ -47,9 +47,8 @@ impl PlayState for CharSelectionState {
|
||||
let mut clock = Clock::new();
|
||||
self.client.borrow_mut().reset_terrain();
|
||||
|
||||
while self.client.borrow().is_request_pending()
|
||||
|| self.client.borrow().get_client_state() == Some(ClientState::Registered)
|
||||
{
|
||||
let mut current_client_state = self.client.borrow().get_client_state();
|
||||
while let ClientState::Pending | ClientState::Registered = current_client_state {
|
||||
// Handle window events.
|
||||
for event in global_state.window.fetch_events() {
|
||||
match event {
|
||||
@ -124,6 +123,8 @@ impl PlayState for CharSelectionState {
|
||||
|
||||
// Wait for the next tick.
|
||||
clock.tick(Duration::from_millis(1000 / FPS));
|
||||
|
||||
current_client_state = self.client.borrow().get_client_state();
|
||||
}
|
||||
|
||||
PlayStateResult::Pop
|
||||
|
@ -129,11 +129,9 @@ impl PlayState for SessionState {
|
||||
*/
|
||||
|
||||
// Game loop
|
||||
while self.client.borrow().is_request_pending()
|
||||
|| self.client.borrow().get_client_state() == Some(ClientState::Character)
|
||||
|| self.client.borrow().get_client_state() == Some(ClientState::Dead)
|
||||
{
|
||||
let alive = self.client.borrow().get_client_state() == Some(ClientState::Character);
|
||||
let mut current_client_state = self.client.borrow().get_client_state();
|
||||
while let ClientState::Pending | ClientState::Character | ClientState::Dead = current_client_state {
|
||||
let alive = self.client.borrow().get_client_state() == ClientState::Character;
|
||||
|
||||
// Handle window events.
|
||||
for event in global_state.window.fetch_events() {
|
||||
@ -248,6 +246,8 @@ impl PlayState for SessionState {
|
||||
|
||||
// Clean things up after the tick.
|
||||
self.cleanup();
|
||||
|
||||
current_client_state = self.client.borrow().get_client_state();
|
||||
}
|
||||
|
||||
PlayStateResult::Pop
|
||||
|
Loading…
Reference in New Issue
Block a user