update to servicepoint 0.4.2

This commit is contained in:
Vinzenz Schroeter 2024-05-26 10:50:29 +02:00
parent c01264afd7
commit 5fff78506a
3 changed files with 17 additions and 22 deletions

View file

@ -5,7 +5,7 @@ use font_kit::font::Font;
use font_kit::hinting::HintingOptions; use font_kit::hinting::HintingOptions;
use pathfinder_geometry::transform2d::Transform2F; use pathfinder_geometry::transform2d::Transform2F;
use pathfinder_geometry::vector::{vec2f, vec2i}; use pathfinder_geometry::vector::{vec2f, vec2i};
use servicepoint2::{PixelGrid, TILE_SIZE}; use servicepoint2::{Grid, PixelGrid, TILE_SIZE};
const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff"); const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff");
@ -16,7 +16,7 @@ pub struct BitmapFont {
impl BitmapFont { impl BitmapFont {
pub fn load(font: Font) -> BitmapFont { pub fn load(font: Font) -> BitmapFont {
let mut bitmaps = core::array::from_fn(|_| { let mut bitmaps = core::array::from_fn(|_| {
PixelGrid::new(TILE_SIZE as usize, TILE_SIZE as usize) PixelGrid::new(TILE_SIZE, TILE_SIZE)
}); });
for char_code in u8::MIN..u8::MAX { for char_code in u8::MIN..u8::MAX {
@ -43,9 +43,9 @@ impl BitmapFont {
assert_eq!(canvas.pixels.len(), 64); assert_eq!(canvas.pixels.len(), 64);
assert_eq!(canvas.stride, 8); assert_eq!(canvas.stride, 8);
for y in 0..TILE_SIZE as usize { for y in 0..TILE_SIZE {
for x in 0..TILE_SIZE as usize { for x in 0..TILE_SIZE {
let index = x + y * TILE_SIZE as usize; let index = x + y * TILE_SIZE;
let canvas_val = canvas.pixels[index] != 0; let canvas_val = canvas.pixels[index] != 0;
bitmaps[char_code as usize].set(x, y, canvas_val); bitmaps[char_code as usize].set(x, y, canvas_val);
} }

View file

@ -4,9 +4,7 @@ use std::sync::RwLock;
use log::{info, warn}; use log::{info, warn};
use pixels::wgpu::TextureFormat; use pixels::wgpu::TextureFormat;
use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use servicepoint2::{ use servicepoint2::{ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE, Grid};
ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
};
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::WindowEvent; use winit::event::WindowEvent;
@ -25,7 +23,7 @@ pub struct App<'t> {
cli: &'t Cli, cli: &'t Cli,
} }
const SPACER_HEIGHT: u16 = 4; const SPACER_HEIGHT: usize = 4;
#[derive(Debug)] #[derive(Debug)]
pub enum AppEvents { pub enum AppEvents {
@ -56,18 +54,18 @@ impl<'t> App<'t> {
let mut frame = pixels.frame_mut().chunks_exact_mut(4); let mut frame = pixels.frame_mut().chunks_exact_mut(4);
let display = self.display.read().unwrap(); let display = self.display.read().unwrap();
let luma = self.luma.read().unwrap(); let luma = self.luma.read().unwrap();
for y in 0..PIXEL_HEIGHT as usize { for y in 0..PIXEL_HEIGHT {
if self.cli.spacers && y != 0 && y % TILE_SIZE as usize == 0 { if self.cli.spacers && y != 0 && y % TILE_SIZE == 0 {
// cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing // cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing
for _ in 0..PIXEL_WIDTH as usize * SPACER_HEIGHT as usize { for _ in 0..PIXEL_WIDTH * SPACER_HEIGHT {
frame.next().unwrap(); frame.next().unwrap();
} }
} }
for x in 0..PIXEL_WIDTH as usize { for x in 0..PIXEL_WIDTH {
let is_set = display.get(x, y); let is_set = display.get(x, y);
let brightness = let brightness =
luma.get(x / TILE_SIZE as usize, y / TILE_SIZE as usize); luma.get(x / TILE_SIZE, y / TILE_SIZE);
let color = if is_set { let color = if is_set {
[ [
@ -98,7 +96,7 @@ impl ApplicationHandler<AppEvents> for App<'_> {
PIXEL_HEIGHT PIXEL_HEIGHT
}; };
let size = LogicalSize::new(PIXEL_WIDTH, height); let size = LogicalSize::new(PIXEL_WIDTH as u16, height as u16);
let attributes = Window::default_attributes() let attributes = Window::default_attributes()
.with_title("servicepoint-simulator") .with_title("servicepoint-simulator")
.with_inner_size(size) .with_inner_size(size)

View file

@ -7,10 +7,7 @@ use std::time::Duration;
use clap::Parser; use clap::Parser;
use log::{info, warn, LevelFilter}; use log::{info, warn, LevelFilter};
use servicepoint2::{ use servicepoint2::{ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT, TILE_WIDTH, Grid};
ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT,
TILE_WIDTH,
};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
use crate::execute_command::execute_command; use crate::execute_command::execute_command;
@ -53,11 +50,11 @@ fn main() {
.expect("could not enter non blocking mode"); .expect("could not enter non blocking mode");
let display = RwLock::new(PixelGrid::new( let display = RwLock::new(PixelGrid::new(
PIXEL_WIDTH as usize, PIXEL_WIDTH,
PIXEL_HEIGHT as usize, PIXEL_HEIGHT,
)); ));
let mut luma = ByteGrid::new(TILE_WIDTH as usize, TILE_HEIGHT as usize); let mut luma = ByteGrid::new(TILE_WIDTH, TILE_HEIGHT);
luma.fill(u8::MAX); luma.fill(u8::MAX);
let luma = RwLock::new(luma); let luma = RwLock::new(luma);