mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Stop singleplayer thread whenever a session is left
Former-commit-id: 16fcf35cbc856bebc12944781c2ac1a4daab5550
This commit is contained in:
parent
76adbec3bb
commit
a768971c6c
@ -45,7 +45,10 @@ impl PlayState for CharSelectionState {
|
||||
// Handle window events
|
||||
for event in global_state.window.fetch_events() {
|
||||
match event {
|
||||
Event::Close => return PlayStateResult::Shutdown,
|
||||
Event::Close => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Shutdown;
|
||||
},
|
||||
// Pass events to ui
|
||||
Event::Ui(event) => {
|
||||
self.char_selection_ui.handle_event(event);
|
||||
@ -60,7 +63,10 @@ impl PlayState for CharSelectionState {
|
||||
// Maintain the UI
|
||||
for event in self.char_selection_ui.maintain(global_state.window.renderer_mut()) {
|
||||
match event {
|
||||
ui::Event::Logout => return PlayStateResult::Pop,
|
||||
ui::Event::Logout => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Pop;
|
||||
},
|
||||
ui::Event::Play => return PlayStateResult::Push(
|
||||
Box::new(SessionState::new(&mut global_state.window, self.client.clone()))
|
||||
),
|
||||
|
@ -125,7 +125,10 @@ impl PlayState for SessionState {
|
||||
continue;
|
||||
}
|
||||
let _handled = match event {
|
||||
Event::Close => return PlayStateResult::Shutdown,
|
||||
Event::Close => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Shutdown;
|
||||
},
|
||||
// Toggle cursor grabbing
|
||||
Event::KeyDown(Key::ToggleCursor) => {
|
||||
global_state
|
||||
@ -166,7 +169,10 @@ impl PlayState for SessionState {
|
||||
self.client.borrow_mut().send_chat(msg);
|
||||
},
|
||||
HudEvent::Logout => return PlayStateResult::Pop,
|
||||
HudEvent::Quit => return PlayStateResult::Shutdown,
|
||||
HudEvent::Quit => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Shutdown;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use std::{
|
||||
thread::JoinHandle
|
||||
};
|
||||
use std::sync::mpsc::{
|
||||
channel, Receiver, Sender
|
||||
channel, Receiver, Sender, TryRecvError,
|
||||
};
|
||||
|
||||
const TPS: u64 = 30;
|
||||
@ -16,6 +16,8 @@ enum Msg {
|
||||
Stop,
|
||||
}
|
||||
|
||||
/// Used to start and stop the background thread running the server
|
||||
/// when in singleplayer mode.
|
||||
pub struct Singleplayer {
|
||||
server_thread: JoinHandle<()>,
|
||||
sender: Sender<Msg>,
|
||||
@ -68,8 +70,8 @@ fn run_server(rec: Receiver<Msg>) {
|
||||
match rec.try_recv() {
|
||||
Ok(msg) => break,
|
||||
Err(err) => match err {
|
||||
Empty => (),
|
||||
Disconnected => break,
|
||||
TryRecvError::Empty => (),
|
||||
TryRecvError::Disconnected => break,
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user