mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 18:40:14 +01:00
extract handle_package function, make window resizable as content gets scaled
This commit is contained in:
parent
64e85bcd4f
commit
1584a2685e
47
src/main.rs
47
src/main.rs
|
@ -102,7 +102,7 @@ fn main() {
|
||||||
let mut buf = [0; 8985];
|
let mut buf = [0; 8985];
|
||||||
|
|
||||||
while rx.try_recv().is_err() {
|
while rx.try_recv().is_err() {
|
||||||
let (amount, source) = match socket.recv_from(&mut buf) {
|
let (amount, _) = match socket.recv_from(&mut buf) {
|
||||||
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
||||||
thread::sleep(Duration::from_millis(1));
|
thread::sleep(Duration::from_millis(1));
|
||||||
continue;
|
continue;
|
||||||
|
@ -110,20 +110,35 @@ fn main() {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
other => other.unwrap(),
|
other => other.unwrap(),
|
||||||
};
|
};
|
||||||
let received = &mut buf[..amount];
|
|
||||||
|
|
||||||
|
handle_package(&mut buf[..amount]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let event_loop = EventLoop::new().expect("could not create event loop");
|
||||||
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
|
|
||||||
|
let mut app = App::default();
|
||||||
|
event_loop
|
||||||
|
.run_app(&mut app)
|
||||||
|
.expect("could not run event loop");
|
||||||
|
|
||||||
|
tx.send(()).expect("could not cancel thread");
|
||||||
|
thread.join().expect("could not join threads");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_package(received: &mut [u8]) {
|
||||||
let header = read_hdr_window(&received[..10]);
|
let header = read_hdr_window(&received[..10]);
|
||||||
if let Err(err) = header {
|
if let Err(err) = header {
|
||||||
warn!("could not read header: {}", err);
|
warn!("could not read header: {}", err);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let header = header.unwrap();
|
let header = header.unwrap();
|
||||||
let payload = &received[10..];
|
let payload = &received[10..];
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"received from {:?}: {:?} (and {} bytes of payload)",
|
"received from {:?} (and {} bytes of payload)",
|
||||||
source,
|
|
||||||
header,
|
header,
|
||||||
payload.len()
|
payload.len()
|
||||||
);
|
);
|
||||||
|
@ -143,25 +158,9 @@ fn main() {
|
||||||
print_cp437_data(&header, payload);
|
print_cp437_data(&header, payload);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!(
|
error!("command {:?} not implemented yet", header.command);
|
||||||
"command {:?} sent by {:?} not implemented yet",
|
|
||||||
header.command, source
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let event_loop = EventLoop::new().expect("could not create event loop");
|
|
||||||
event_loop.set_control_flow(ControlFlow::Poll);
|
|
||||||
|
|
||||||
let mut app = App::default();
|
|
||||||
event_loop
|
|
||||||
.run_app(&mut app)
|
|
||||||
.expect("could not run event loop");
|
|
||||||
|
|
||||||
tx.send(()).expect("could not cancel thread");
|
|
||||||
thread.join().expect("could not join threads");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -175,9 +174,7 @@ impl ApplicationHandler for App {
|
||||||
let size = Size::from(LogicalSize::new(PIXEL_WIDTH as f64, PIXEL_HEIGHT as f64));
|
let size = Size::from(LogicalSize::new(PIXEL_WIDTH as f64, PIXEL_HEIGHT as f64));
|
||||||
let attributes = Window::default_attributes()
|
let attributes = Window::default_attributes()
|
||||||
.with_title("pixel-receiver-rs")
|
.with_title("pixel-receiver-rs")
|
||||||
.with_inner_size(size)
|
.with_inner_size(size);
|
||||||
.with_resizable(false)
|
|
||||||
.with_visible(true);
|
|
||||||
|
|
||||||
let window = event_loop.create_window(attributes).unwrap();
|
let window = event_loop.create_window(attributes).unwrap();
|
||||||
self.window = Some(window);
|
self.window = Some(window);
|
||||||
|
|
Loading…
Reference in a new issue