mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-31 01:30:13 +01:00
cargo fmt
This commit is contained in:
parent
3b3e8f4c1d
commit
9d8e2f28c4
|
@ -1,5 +1,5 @@
|
||||||
use std::ops::Index;
|
|
||||||
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
|
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
|
||||||
|
use std::ops::Index;
|
||||||
|
|
||||||
const CHAR_COUNT: usize = u8::MAX as usize + 1;
|
const CHAR_COUNT: usize = u8::MAX as usize + 1;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success};
|
|
||||||
use crate::cp437_font::Cp437Font;
|
use crate::cp437_font::Cp437Font;
|
||||||
|
use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success};
|
||||||
use crate::font_renderer::FontRenderer8x8;
|
use crate::font_renderer::FontRenderer8x8;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
|
|
|
@ -60,7 +60,10 @@ impl FontRenderer8x8 {
|
||||||
|
|
||||||
pub fn from_name(family_name: String) -> Self {
|
pub fn from_name(family_name: String) -> Self {
|
||||||
let font = SystemSource::new()
|
let font = SystemSource::new()
|
||||||
.select_best_match(&[FamilyName::Title(family_name)], &Properties::new())
|
.select_best_match(
|
||||||
|
&[FamilyName::Title(family_name)],
|
||||||
|
&Properties::new(),
|
||||||
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.load()
|
.load()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
14
src/gui.rs
14
src/gui.rs
|
@ -12,7 +12,7 @@ use winit::event_loop::ActiveEventLoop;
|
||||||
use winit::keyboard::KeyCode::KeyC;
|
use winit::keyboard::KeyCode::KeyC;
|
||||||
use winit::window::{Window, WindowId};
|
use winit::window::{Window, WindowId};
|
||||||
|
|
||||||
use crate::cli::{GuiOptions};
|
use crate::cli::GuiOptions;
|
||||||
|
|
||||||
pub struct Gui<'t> {
|
pub struct Gui<'t> {
|
||||||
display: &'t RwLock<Bitmap>,
|
display: &'t RwLock<Bitmap>,
|
||||||
|
@ -76,7 +76,8 @@ impl<'t> Gui<'t> {
|
||||||
fn draw_frame(&self, frame: &mut ChunksExactMut<u8>) {
|
fn draw_frame(&self, frame: &mut ChunksExactMut<u8>) {
|
||||||
let display = self.display.read().unwrap();
|
let display = self.display.read().unwrap();
|
||||||
let luma = self.luma.read().unwrap();
|
let luma = self.luma.read().unwrap();
|
||||||
let brightness_scale = (u8::MAX as f32) / (u8::from(Brightness::MAX) as f32);
|
let brightness_scale =
|
||||||
|
(u8::MAX as f32) / (u8::from(Brightness::MAX) as f32);
|
||||||
|
|
||||||
for tile_y in 0..TILE_HEIGHT {
|
for tile_y in 0..TILE_HEIGHT {
|
||||||
if self.options.spacers && tile_y != 0 {
|
if self.options.spacers && tile_y != 0 {
|
||||||
|
@ -90,11 +91,16 @@ impl<'t> Gui<'t> {
|
||||||
for y in start_y..start_y + TILE_SIZE {
|
for y in start_y..start_y + TILE_SIZE {
|
||||||
for tile_x in 0..TILE_WIDTH {
|
for tile_x in 0..TILE_WIDTH {
|
||||||
let brightness = u8::from(luma.get(tile_x, tile_y));
|
let brightness = u8::from(luma.get(tile_x, tile_y));
|
||||||
let brightness = (brightness_scale * brightness as f32) as u8;
|
let brightness =
|
||||||
|
(brightness_scale * brightness as f32) as u8;
|
||||||
let on_color = self.get_on_color(brightness);
|
let on_color = self.get_on_color(brightness);
|
||||||
let start_x = tile_x * TILE_SIZE;
|
let start_x = tile_x * TILE_SIZE;
|
||||||
for x in start_x..start_x + TILE_SIZE {
|
for x in start_x..start_x + TILE_SIZE {
|
||||||
let color = if display.get(x, y) { on_color } else { OFF_COLOR };
|
let color = if display.get(x, y) {
|
||||||
|
on_color
|
||||||
|
} else {
|
||||||
|
OFF_COLOR
|
||||||
|
};
|
||||||
let pixel = frame.next().unwrap();
|
let pixel = frame.next().unwrap();
|
||||||
pixel.copy_from_slice(&color);
|
pixel.copy_from_slice(&color);
|
||||||
}
|
}
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -1,10 +1,12 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
|
use crate::font_renderer::FontRenderer8x8;
|
||||||
use crate::{
|
use crate::{
|
||||||
execute_command::{CommandExecutor, ExecutionResult},
|
execute_command::{CommandExecutor, ExecutionResult},
|
||||||
gui::{AppEvents, Gui},
|
gui::{AppEvents, Gui},
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use cli::Cli;
|
||||||
use log::{error, info, warn, LevelFilter};
|
use log::{error, info, warn, LevelFilter};
|
||||||
use servicepoint::*;
|
use servicepoint::*;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
@ -12,14 +14,12 @@ use std::net::UdpSocket;
|
||||||
use std::sync::{mpsc, RwLock};
|
use std::sync::{mpsc, RwLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
||||||
use cli::Cli;
|
|
||||||
use crate::font_renderer::FontRenderer8x8;
|
|
||||||
|
|
||||||
mod execute_command;
|
mod cli;
|
||||||
mod cp437_font;
|
mod cp437_font;
|
||||||
|
mod execute_command;
|
||||||
mod font_renderer;
|
mod font_renderer;
|
||||||
mod gui;
|
mod gui;
|
||||||
mod cli;
|
|
||||||
|
|
||||||
const BUF_SIZE: usize = 8985;
|
const BUF_SIZE: usize = 8985;
|
||||||
|
|
||||||
|
@ -49,7 +49,9 @@ fn main() {
|
||||||
event_loop.set_control_flow(ControlFlow::Wait);
|
event_loop.set_control_flow(ControlFlow::Wait);
|
||||||
|
|
||||||
let event_proxy = event_loop.create_proxy();
|
let event_proxy = event_loop.create_proxy();
|
||||||
let font_renderer = cli.font.map(move |font| FontRenderer8x8::from_name(font))
|
let font_renderer = cli
|
||||||
|
.font
|
||||||
|
.map(move |font| FontRenderer8x8::from_name(font))
|
||||||
.unwrap_or_else(move || FontRenderer8x8::default());
|
.unwrap_or_else(move || FontRenderer8x8::default());
|
||||||
let command_executor = CommandExecutor::new(&display, &luma, font_renderer);
|
let command_executor = CommandExecutor::new(&display, &luma, font_renderer);
|
||||||
|
|
||||||
|
@ -59,7 +61,9 @@ fn main() {
|
||||||
while stop_udp_rx.try_recv().is_err() {
|
while stop_udp_rx.try_recv().is_err() {
|
||||||
receive_into_buf(&socket, &mut buf)
|
receive_into_buf(&socket, &mut buf)
|
||||||
.and_then(move |amount| command_from_slice(&buf[..amount]))
|
.and_then(move |amount| command_from_slice(&buf[..amount]))
|
||||||
.map(|cmd| handle_command(&event_proxy, &command_executor, cmd));
|
.map(|cmd| {
|
||||||
|
handle_command(&event_proxy, &command_executor, cmd)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
event_loop
|
event_loop
|
||||||
|
@ -68,7 +72,11 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_command(event_proxy: &EventLoopProxy<AppEvents>, command_executor: &CommandExecutor, command: Command) {
|
fn handle_command(
|
||||||
|
event_proxy: &EventLoopProxy<AppEvents>,
|
||||||
|
command_executor: &CommandExecutor,
|
||||||
|
command: Command,
|
||||||
|
) {
|
||||||
match command_executor.execute(command) {
|
match command_executor.execute(command) {
|
||||||
ExecutionResult::Success => {
|
ExecutionResult::Success => {
|
||||||
event_proxy
|
event_proxy
|
||||||
|
@ -100,10 +108,14 @@ fn init_logging(debug: bool) {
|
||||||
|
|
||||||
fn command_from_slice(slice: &[u8]) -> Option<Command> {
|
fn command_from_slice(slice: &[u8]) -> Option<Command> {
|
||||||
let packet = servicepoint::Packet::try_from(slice)
|
let packet = servicepoint::Packet::try_from(slice)
|
||||||
.inspect_err(|_| warn!("could not load packet with length {}", slice.len()))
|
.inspect_err(|_| {
|
||||||
|
warn!("could not load packet with length {}", slice.len())
|
||||||
|
})
|
||||||
.ok()?;
|
.ok()?;
|
||||||
Command::try_from(packet)
|
Command::try_from(packet)
|
||||||
.inspect_err(move |err| warn!("could not read command for packet: {:?}", err))
|
.inspect_err(move |err| {
|
||||||
|
warn!("could not read command for packet: {:?}", err)
|
||||||
|
})
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue