mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-31 01:30:13 +01:00
minimal tweaks
This commit is contained in:
parent
3049a8bd7a
commit
3b3e8f4c1d
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ops::Index;
|
||||||
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
|
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
|
||||||
|
|
||||||
const CHAR_COUNT: usize = u8::MAX as usize + 1;
|
const CHAR_COUNT: usize = u8::MAX as usize + 1;
|
||||||
|
@ -10,10 +11,6 @@ impl Cp437Font {
|
||||||
pub fn new(bitmaps: [Bitmap; CHAR_COUNT]) -> Self {
|
pub fn new(bitmaps: [Bitmap; CHAR_COUNT]) -> Self {
|
||||||
Self { bitmaps }
|
Self { bitmaps }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_bitmap(&self, char_code: u8) -> &Bitmap {
|
|
||||||
&self.bitmaps[char_code as usize]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Cp437Font {
|
impl Default for Cp437Font {
|
||||||
|
@ -32,6 +29,14 @@ impl Default for Cp437Font {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Index<u8> for Cp437Font {
|
||||||
|
type Output = Bitmap;
|
||||||
|
|
||||||
|
fn index(&self, char_code: u8) -> &Self::Output {
|
||||||
|
&self.bitmaps[char_code as usize]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Font from the display firmware `cape-cccb-apd/cp437font_linear.h`
|
/// Font from the display firmware `cape-cccb-apd/cp437font_linear.h`
|
||||||
pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [
|
pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [
|
||||||
0x0000000000000000, // 0x00
|
0x0000000000000000, // 0x00
|
||||||
|
|
|
@ -154,11 +154,10 @@ impl<'t> CommandExecutor<'t> {
|
||||||
let tile_x = char_x + x;
|
let tile_x = char_x + x;
|
||||||
let tile_y = char_y + y;
|
let tile_y = char_y + y;
|
||||||
|
|
||||||
let bitmap = font.get_bitmap(char_code);
|
|
||||||
match self.print_pixel_grid(
|
match self.print_pixel_grid(
|
||||||
tile_x * TILE_SIZE,
|
tile_x * TILE_SIZE,
|
||||||
tile_y * TILE_SIZE,
|
tile_y * TILE_SIZE,
|
||||||
bitmap,
|
&font[char_code],
|
||||||
) {
|
) {
|
||||||
Success => {}
|
Success => {}
|
||||||
Failure => {
|
Failure => {
|
||||||
|
|
|
@ -78,11 +78,8 @@ impl FontRenderer8x8 {
|
||||||
.font
|
.font
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.glyph_for_char(char)
|
.glyph_for_char(char)
|
||||||
.or(self.fallback_char);
|
.or(self.fallback_char)
|
||||||
let glyph_id = match glyph_id {
|
.ok_or_else(|| GlyphNotFound(char))?;
|
||||||
None => return Err(GlyphNotFound(char)),
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
canvas.pixels.fill(0);
|
canvas.pixels.fill(0);
|
||||||
self.font.as_ref().rasterize_glyph(
|
self.font.as_ref().rasterize_glyph(
|
||||||
|
@ -97,8 +94,7 @@ impl FontRenderer8x8 {
|
||||||
|
|
||||||
for y in 0..TILE_SIZE {
|
for y in 0..TILE_SIZE {
|
||||||
for x in 0..TILE_SIZE {
|
for x in 0..TILE_SIZE {
|
||||||
let index = x + y * TILE_SIZE;
|
let canvas_val = canvas.pixels[x + y * TILE_SIZE] != 0;
|
||||||
let canvas_val = canvas.pixels[index] != 0;
|
|
||||||
let bitmap_x = (offset.x + x) as isize;
|
let bitmap_x = (offset.x + x) as isize;
|
||||||
let bitmap_y = (offset.y + y) as isize;
|
let bitmap_y = (offset.y + y) as isize;
|
||||||
if !bitmap.set_optional(bitmap_x, bitmap_y, canvas_val) {
|
if !bitmap.set_optional(bitmap_x, bitmap_y, canvas_val) {
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -57,17 +57,9 @@ fn main() {
|
||||||
scope.spawn(move || {
|
scope.spawn(move || {
|
||||||
let mut buf = [0; BUF_SIZE];
|
let mut buf = [0; BUF_SIZE];
|
||||||
while stop_udp_rx.try_recv().is_err() {
|
while stop_udp_rx.try_recv().is_err() {
|
||||||
let amount = match receive_into_buf(&socket, &mut buf) {
|
receive_into_buf(&socket, &mut buf)
|
||||||
Some(value) => value,
|
.and_then(move |amount| command_from_slice(&buf[..amount]))
|
||||||
None => continue,
|
.map(|cmd| handle_command(&event_proxy, &command_executor, cmd));
|
||||||
};
|
|
||||||
|
|
||||||
let command = match command_from_slice(&buf[..amount]) {
|
|
||||||
Some(value) => value,
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
handle_command(&event_proxy, &command_executor, command);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
event_loop
|
event_loop
|
||||||
|
@ -107,22 +99,12 @@ fn init_logging(debug: bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command_from_slice(slice: &[u8]) -> Option<Command> {
|
fn command_from_slice(slice: &[u8]) -> Option<Command> {
|
||||||
let package = match servicepoint::Packet::try_from(slice) {
|
let packet = servicepoint::Packet::try_from(slice)
|
||||||
Err(_) => {
|
.inspect_err(|_| warn!("could not load packet with length {}", slice.len()))
|
||||||
warn!("could not load packet with length {}", slice.len());
|
.ok()?;
|
||||||
return None;
|
Command::try_from(packet)
|
||||||
}
|
.inspect_err(move |err| warn!("could not read command for packet: {:?}", err))
|
||||||
Ok(package) => package,
|
.ok()
|
||||||
};
|
|
||||||
|
|
||||||
let command = match Command::try_from(package) {
|
|
||||||
Err(err) => {
|
|
||||||
warn!("could not read command for packet: {:?}", err);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Ok(val) => val,
|
|
||||||
};
|
|
||||||
Some(command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_into_buf(
|
fn receive_into_buf(
|
||||||
|
|
Loading…
Reference in a new issue