diff --git a/kubi/src/control_flow.rs b/kubi/src/control_flow.rs index 10997de..03ec5e2 100644 --- a/kubi/src/control_flow.rs +++ b/kubi/src/control_flow.rs @@ -3,20 +3,19 @@ use winit::{keyboard::KeyCode, event_loop::ControlFlow}; use crate::input::RawKbmInputState; #[derive(Unique)] -pub struct SetControlFlow(pub Option); +pub struct RequestExit(pub bool); pub fn exit_on_esc( raw_inputs: UniqueView, - mut control_flow: UniqueViewMut + mut exit: UniqueViewMut ) { if raw_inputs.keyboard_state.contains(KeyCode::Escape as u32) { - //TODO MIGRATION: fix exit on esc - //control_flow.0 = Some(ControlFlow::Exit); + exit.0 = true; } } pub fn insert_control_flow_unique( storages: AllStoragesView ) { - storages.add_unique(SetControlFlow(None)) + storages.add_unique(RequestExit(false)) } diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index a916489..4432ef5 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -72,7 +72,7 @@ use rendering::{ use block_placement::update_block_placement; use delta_time::{DeltaTime, init_delta_time}; use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now}; -use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow}; +use control_flow::{exit_on_esc, insert_control_flow_unique, RequestExit}; use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state, is_connecting}; use networking::{update_networking, update_networking_late, is_multiplayer, disconnect_on_exit, is_singleplayer}; use init::initialize_from_args; @@ -215,8 +215,8 @@ pub fn kubi_main() { //Run the event loop let mut last_update = Instant::now(); - event_loop.run(move |event, target| { - target.set_control_flow(ControlFlow::Poll); + event_loop.run(move |event, window_target| { + window_target.set_control_flow(ControlFlow::Poll); process_glutin_events(&mut world, &event); #[allow(clippy::collapsible_match, clippy::single_match)] @@ -224,7 +224,7 @@ pub fn kubi_main() { Event::WindowEvent { event, .. } => match event { WindowEvent::CloseRequested => { log::info!("exit requested"); - target.exit(); + window_target.exit(); }, _ => (), }, @@ -258,9 +258,8 @@ pub fn kubi_main() { world.run_workload(after_frame_end).unwrap(); //Process control flow changes - if let Some(flow) = world.borrow::>().unwrap().0 { - //TODO MIGRATION - //*control_flow = flow; + if world.borrow::>().unwrap().0 == true { + window_target.exit(); } }, _ => (), diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index eac99f7..9e1fe28 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -12,7 +12,7 @@ use kubi_shared::networking::{ }; use crate::{ events::EventComponent, - control_flow::SetControlFlow, + control_flow::RequestExit, world::tasks::ChunkTaskManager, state::is_ingame_or_loading, fixed_timestamp::FixedTimestamp @@ -155,20 +155,20 @@ pub fn update_networking_late() -> Workload { } pub fn disconnect_on_exit( - control_flow: UniqueView, + exit: UniqueView, mut client: UniqueViewMut, ) { - //TODO MIGRATION - // if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 { - // if client.0.is_active() { - // client.0.flush(); - // client.0.disconnect(); - // while client.0.is_active() { client.0.step().for_each(|_|()); } - // log::info!("Client disconnected"); - // } else { - // log::info!("Client inactive") - // } - // } + //TODO check if this works + if exit.0 { + if client.0.is_active() { + client.0.flush(); + client.0.disconnect(); + while client.0.is_active() { client.0.step().for_each(|_|()); } + log::info!("Client disconnected"); + } else { + log::info!("Client inactive") + } + } } // conditions diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index b429dc0..733b0e4 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -36,7 +36,7 @@ impl Renderer { pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); - let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop); + let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(event_loop); // let wb = WindowBuilder::new() // .with_title("kubi")