Disable ticking completely when disconnected from a server
This commit is contained in:
parent
a644f3ac8f
commit
bb82798ab8
|
@ -107,7 +107,7 @@ impl super::Screen for SettingsMenu {
|
|||
if self.show_disconnect_button {
|
||||
let (mut btn_exit_game, mut txt_exit_game) = new_centered_button("Disconnect", renderer, ui_container, 100.0, ui::VAttach::Bottom);
|
||||
super::button_action(ui_container, btn_exit_game.clone(), Some(txt_exit_game.clone()), move | game, _ | {
|
||||
game.server.disconnect();
|
||||
game.server.disconnect(None);
|
||||
game.screen_sys.replace_screen(Box::new(super::ServerList::new(None)));
|
||||
});
|
||||
elements.add(btn_exit_game);
|
||||
|
@ -261,7 +261,7 @@ impl super::Screen for AudioSettingsMenu {
|
|||
});
|
||||
elements.add(btn_done);
|
||||
elements.add(txt_done);
|
||||
|
||||
|
||||
self.elements = Some(UIElement {
|
||||
elements: elements
|
||||
});
|
||||
|
|
|
@ -45,6 +45,7 @@ pub struct Server {
|
|||
conn: Option<protocol::Conn>,
|
||||
read_queue: Option<mpsc::Receiver<Result<packet::Packet, protocol::Error>>>,
|
||||
pub disconnect_reason: Option<format::Component>,
|
||||
just_disconnected: bool,
|
||||
|
||||
pub world: world::World,
|
||||
pub entities: ecs::Manager,
|
||||
|
@ -274,6 +275,7 @@ impl Server {
|
|||
conn: conn,
|
||||
read_queue: read_queue,
|
||||
disconnect_reason: None,
|
||||
just_disconnected: false,
|
||||
|
||||
world: world::World::new(),
|
||||
world_age: 0,
|
||||
|
@ -308,12 +310,13 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(&mut self) {
|
||||
pub fn disconnect(&mut self, reason: Option<format::Component>) {
|
||||
self.conn = None;
|
||||
self.disconnect_reason = None;
|
||||
self.disconnect_reason = reason;
|
||||
if let Some(player) = self.player.take() {
|
||||
self.entities.remove_entity(player);
|
||||
}
|
||||
self.just_disconnected = true;
|
||||
}
|
||||
|
||||
pub fn is_connected(&self) -> bool {
|
||||
|
@ -404,13 +407,16 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
self.entity_tick_timer += delta;
|
||||
while self.entity_tick_timer >= 3.0 && self.is_connected() {
|
||||
self.entities.tick(&mut self.world, renderer);
|
||||
self.entity_tick_timer -= 3.0;
|
||||
}
|
||||
if self.is_connected() || self.just_disconnected { // Allow an extra tick when disconnected to clean up
|
||||
self.just_disconnected = false;
|
||||
self.entity_tick_timer += delta;
|
||||
while self.entity_tick_timer >= 3.0 {
|
||||
self.entities.tick(&mut self.world, renderer);
|
||||
self.entity_tick_timer -= 3.0;
|
||||
}
|
||||
|
||||
self.entities.render_tick(&mut self.world, renderer);
|
||||
self.entities.render_tick(&mut self.world, renderer);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, renderer: &mut render::Renderer) {
|
||||
|
@ -543,11 +549,7 @@ impl Server {
|
|||
}
|
||||
|
||||
fn on_disconnect(&mut self, disconnect: packet::play::clientbound::Disconnect) {
|
||||
self.conn = None;
|
||||
self.disconnect_reason = Some(disconnect.reason);
|
||||
if let Some(player) = self.player.take() {
|
||||
self.entities.remove_entity(player);
|
||||
}
|
||||
self.disconnect(Some(disconnect.reason));
|
||||
}
|
||||
|
||||
fn on_time_update(&mut self, time_update: packet::play::clientbound::TimeUpdate) {
|
||||
|
|
Loading…
Reference in New Issue