mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 10:30:14 +01:00
update to servicepoint 0.10, improve pixel handling
This commit is contained in:
parent
4ddec8eef2
commit
36d0daba05
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1764,9 +1764,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "servicepoint"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7e803bc88f44d834cf52731e09392f68f9462eebaa68d3b4a406f26b41452b9"
|
||||
checksum = "25fd266845654e7e643cf32a9e69dd20ce2b62cf54557937d4d0d41bf27a050f"
|
||||
dependencies = [
|
||||
"bitvec",
|
||||
"bzip2",
|
||||
|
|
|
@ -16,7 +16,7 @@ pixels = "0.14"
|
|||
pathfinder_geometry = "0.5.1"
|
||||
|
||||
[dependencies.servicepoint]
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
features = ["all_compressions"]
|
||||
|
||||
[dependencies.winit]
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
packages = with pkgs; [
|
||||
rustfmt
|
||||
cargo-expand
|
||||
clippy
|
||||
];
|
||||
# LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (
|
||||
# builtins.concatMap (d: d.runtimeDependencies) inputsFrom
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::{RwLock, RwLockWriteGuard};
|
|||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use servicepoint::{
|
||||
BrightnessGrid, Command, Cp437Grid, Grid, Origin, PixelGrid, Tiles,
|
||||
Bitmap, BrightnessGrid, Command, Cp437Grid, Grid, Origin, Tiles,
|
||||
PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE,
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,7 @@ use crate::font::BitmapFont;
|
|||
pub(crate) fn execute_command(
|
||||
command: Command,
|
||||
font: &BitmapFont,
|
||||
display_ref: &RwLock<PixelGrid>,
|
||||
display_ref: &RwLock<Bitmap>,
|
||||
luma_ref: &RwLock<BrightnessGrid>,
|
||||
) -> bool {
|
||||
debug!("received {command:?}");
|
||||
|
@ -120,7 +120,7 @@ fn print_cp437_data(
|
|||
origin: Origin<Tiles>,
|
||||
grid: &Cp437Grid,
|
||||
font: &BitmapFont,
|
||||
display: &mut RwLockWriteGuard<PixelGrid>,
|
||||
display: &mut RwLockWriteGuard<Bitmap>,
|
||||
) {
|
||||
let Origin { x, y, .. } = origin;
|
||||
for char_y in 0usize..grid.height() {
|
||||
|
@ -152,8 +152,8 @@ fn print_cp437_data(
|
|||
fn print_pixel_grid(
|
||||
offset_x: usize,
|
||||
offset_y: usize,
|
||||
pixels: &PixelGrid,
|
||||
display: &mut RwLockWriteGuard<PixelGrid>,
|
||||
pixels: &Bitmap,
|
||||
display: &mut RwLockWriteGuard<Bitmap>,
|
||||
) -> bool {
|
||||
debug!(
|
||||
"printing {}x{} grid at {offset_x} {offset_y}",
|
||||
|
|
10
src/font.rs
10
src/font.rs
|
@ -4,24 +4,24 @@ use font_kit::font::Font;
|
|||
use font_kit::hinting::HintingOptions;
|
||||
use pathfinder_geometry::transform2d::Transform2F;
|
||||
use pathfinder_geometry::vector::{vec2f, vec2i};
|
||||
use servicepoint::{Grid, PixelGrid, TILE_SIZE};
|
||||
use servicepoint::{Bitmap, Grid, TILE_SIZE};
|
||||
|
||||
const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff");
|
||||
|
||||
const CHAR_COUNT: usize = u8::MAX as usize + 1;
|
||||
|
||||
pub struct BitmapFont {
|
||||
bitmaps: [PixelGrid; CHAR_COUNT],
|
||||
bitmaps: [Bitmap; CHAR_COUNT],
|
||||
}
|
||||
|
||||
impl BitmapFont {
|
||||
pub fn new(bitmaps: [PixelGrid; CHAR_COUNT]) -> Self {
|
||||
pub fn new(bitmaps: [Bitmap; CHAR_COUNT]) -> Self {
|
||||
Self { bitmaps }
|
||||
}
|
||||
|
||||
pub fn load(font: Font, size: usize) -> BitmapFont {
|
||||
let mut bitmaps =
|
||||
core::array::from_fn(|_| PixelGrid::new(TILE_SIZE, TILE_SIZE));
|
||||
core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE));
|
||||
let mut canvas =
|
||||
Canvas::new(vec2i(size as i32, size as i32), Format::A8);
|
||||
let size_f = size as f32;
|
||||
|
@ -61,7 +61,7 @@ impl BitmapFont {
|
|||
Self::new(bitmaps)
|
||||
}
|
||||
|
||||
pub fn get_bitmap(&self, char_code: u8) -> &PixelGrid {
|
||||
pub fn get_bitmap(&self, char_code: u8) -> &Bitmap {
|
||||
&self.bitmaps[char_code as usize]
|
||||
}
|
||||
}
|
||||
|
|
21
src/gui.rs
21
src/gui.rs
|
@ -2,10 +2,9 @@ use std::sync::mpsc::Sender;
|
|||
use std::sync::RwLock;
|
||||
|
||||
use log::{info, warn};
|
||||
use pixels::wgpu::TextureFormat;
|
||||
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
|
||||
use pixels::{Pixels, SurfaceTexture};
|
||||
use servicepoint::{
|
||||
Brightness, BrightnessGrid, Grid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
Bitmap, Brightness, BrightnessGrid, Grid, PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||
TILE_SIZE,
|
||||
};
|
||||
use winit::application::ApplicationHandler;
|
||||
|
@ -18,7 +17,7 @@ use winit::window::{Window, WindowId};
|
|||
use crate::Cli;
|
||||
|
||||
pub struct App<'t> {
|
||||
display: &'t RwLock<PixelGrid>,
|
||||
display: &'t RwLock<Bitmap>,
|
||||
luma: &'t RwLock<BrightnessGrid>,
|
||||
window: Option<Window>,
|
||||
pixels: Option<Pixels>,
|
||||
|
@ -36,7 +35,7 @@ pub enum AppEvents {
|
|||
|
||||
impl<'t> App<'t> {
|
||||
pub fn new(
|
||||
display: &'t RwLock<PixelGrid>,
|
||||
display: &'t RwLock<Bitmap>,
|
||||
luma: &'t RwLock<BrightnessGrid>,
|
||||
stop_udp_tx: Sender<()>,
|
||||
cli: &'t Cli,
|
||||
|
@ -115,11 +114,13 @@ impl ApplicationHandler<AppEvents> for App<'_> {
|
|||
|
||||
let pixels = {
|
||||
let window_size = window.inner_size();
|
||||
let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
|
||||
Pixels::new(
|
||||
size.width as u32,
|
||||
size.height as u32,
|
||||
surface_texture).unwrap()
|
||||
let surface_texture = SurfaceTexture::new(
|
||||
window_size.width,
|
||||
window_size.height,
|
||||
&window,
|
||||
);
|
||||
Pixels::new(size.width as u32, size.height as u32, surface_texture)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
self.pixels = Some(pixels);
|
||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
.set_nonblocking(true)
|
||||
.expect("could not enter non blocking mode");
|
||||
|
||||
let display = RwLock::new(PixelGrid::new(PIXEL_WIDTH, PIXEL_HEIGHT));
|
||||
let display = RwLock::new(Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT));
|
||||
|
||||
let mut luma = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||
luma.fill(Brightness::MAX);
|
||||
|
@ -60,7 +60,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn run(
|
||||
display_ref: &RwLock<PixelGrid>,
|
||||
display_ref: &RwLock<Bitmap>,
|
||||
luma_ref: &RwLock<BrightnessGrid>,
|
||||
socket: UdpSocket,
|
||||
font: BitmapFont,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::font::BitmapFont;
|
||||
use servicepoint::{DataRef, PixelGrid, TILE_SIZE};
|
||||
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
|
||||
|
||||
/// Font from the display firmware `cape-cccb-apd/cp437font_linear.h`
|
||||
pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [
|
||||
|
@ -263,7 +263,7 @@ pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [
|
|||
|
||||
pub fn load_static() -> BitmapFont {
|
||||
let mut bitmaps =
|
||||
core::array::from_fn(|_| PixelGrid::new(TILE_SIZE, TILE_SIZE));
|
||||
core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE));
|
||||
|
||||
for (char_code, bitmap) in bitmaps.iter_mut().enumerate() {
|
||||
let bits = CP437_FONT_LINEAR[char_code];
|
||||
|
|
Loading…
Reference in a new issue