mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Go back to char selection on death
Former-commit-id: a8b5ee42f432ff2da8385225b17be654420f17d1
This commit is contained in:
parent
b26f00ddfb
commit
449b717777
@ -35,6 +35,7 @@ pub enum Event {
|
||||
|
||||
pub struct Client {
|
||||
client_state: Option<ClientState>,
|
||||
pending_state_request: bool,
|
||||
thread_pool: ThreadPool,
|
||||
|
||||
last_ping: f64,
|
||||
@ -79,6 +80,7 @@ impl Client {
|
||||
|
||||
Ok(Self {
|
||||
client_state,
|
||||
pending_state_request: false,
|
||||
thread_pool: threadpool::Builder::new()
|
||||
.thread_name("veloren-worker".into())
|
||||
.build(),
|
||||
@ -105,6 +107,7 @@ impl Client {
|
||||
pub fn request_character(&mut self, name: String, body: comp::Body) {
|
||||
self.postbox
|
||||
.send_message(ClientMsg::Character { name, body });
|
||||
self.pending_state_request = true;
|
||||
}
|
||||
|
||||
pub fn set_view_distance(&mut self, view_distance: u32) {
|
||||
@ -139,6 +142,17 @@ impl Client {
|
||||
self.entity
|
||||
}
|
||||
|
||||
/// Get the client state
|
||||
#[allow(dead_code)]
|
||||
pub fn get_client_state(&self) -> Option<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 {
|
||||
@ -372,12 +386,14 @@ impl Client {
|
||||
}
|
||||
ServerMsg::StateAnswer(Ok(state)) => {
|
||||
self.client_state = Some(state);
|
||||
self.pending_state_request = false;
|
||||
}
|
||||
ServerMsg::StateAnswer(Err((error, state))) => {
|
||||
self.client_state = Some(state);
|
||||
self.pending_state_request = false;
|
||||
}
|
||||
ServerMsg::ForceState(state) => {
|
||||
self.client_state = Some(state);
|
||||
self.client_state = Some(dbg!(state));
|
||||
}
|
||||
ServerMsg::Disconnect => {
|
||||
self.client_state = None;
|
||||
|
@ -586,6 +586,8 @@ impl Server {
|
||||
|
||||
for entity in todo_remove {
|
||||
self.state.ecs_mut().delete_entity_synced(entity);
|
||||
self.clients
|
||||
.notify(entity, ServerMsg::ForceState(ClientState::Registered));
|
||||
}
|
||||
|
||||
// Remove all force flags.
|
||||
|
@ -78,7 +78,7 @@ impl PlayState for CharSelectionState {
|
||||
self.char_selection_ui.character_name.clone(),
|
||||
comp::Body::Humanoid(self.char_selection_ui.character_body),
|
||||
);
|
||||
return PlayStateResult::Switch(Box::new(SessionState::new(
|
||||
return PlayStateResult::Push(Box::new(SessionState::new(
|
||||
&mut global_state.window,
|
||||
self.client.clone(),
|
||||
global_state.settings.clone(),
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
||||
};
|
||||
use client::{self, Client, Input, InputEvent};
|
||||
use common::clock::Clock;
|
||||
use common::{clock::Clock, msg::ClientState};
|
||||
use glutin::MouseButton;
|
||||
use std::{cell::RefCell, mem, rc::Rc, time::Duration};
|
||||
use vek::*;
|
||||
@ -128,7 +128,9 @@ impl PlayState for SessionState {
|
||||
*/
|
||||
|
||||
// Game loop
|
||||
loop {
|
||||
while self.client.borrow().is_request_pending()
|
||||
|| self.client.borrow().get_client_state() == Some(ClientState::Character)
|
||||
{
|
||||
// Handle window events.
|
||||
for event in global_state.window.fetch_events() {
|
||||
// Pass all events to the ui first.
|
||||
@ -237,6 +239,8 @@ impl PlayState for SessionState {
|
||||
// Clean things up after the tick.
|
||||
self.cleanup();
|
||||
}
|
||||
|
||||
PlayStateResult::Pop
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
|
Loading…
Reference in New Issue
Block a user