update to servicepoint 0.4.2

This commit is contained in:
Vinzenz Schroeter 2024-05-26 10:50:29 +02:00
parent 8690e052bd
commit c01264afd7
5 changed files with 26 additions and 25 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
/.idea /.idea
.direnv

8
Cargo.lock generated
View file

@ -477,9 +477,9 @@ dependencies = [
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.4.0" version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@ -1622,9 +1622,9 @@ dependencies = [
[[package]] [[package]]
name = "servicepoint2" name = "servicepoint2"
version = "0.4.1" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54d49d501f34100406d70730d887775ed5961b6343ccb10d5ef0e105d7b295ae" checksum = "94d9aecc4d31a71578481de6c6d64383d374126c38469c9689067579c1d910fd"
dependencies = [ dependencies = [
"bzip2", "bzip2",
"flate2", "flate2",

View file

@ -7,7 +7,7 @@ license = "GPL-3.0-or-later"
[dependencies] [dependencies]
# packet parsing # packet parsing
servicepoint2 = "0.4.1" servicepoint2 = { version = "0.4.2", features = ["all_compressions"] }
# gui # gui
winit = { version = "0.30", features = ["rwh_05"] } # for creating a window winit = { version = "0.30", features = ["rwh_05"] } # for creating a window

View file

@ -1,4 +1,11 @@
{pkgs ? import <nixpkgs> {}}: {pkgs ? import <nixpkgs> {}}:
pkgs.mkShell { pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [ rustup pkg-config xe lzma ]; nativeBuildInputs = with pkgs.buildPackages; [
rustup
pkg-config
xe
lzma
libxkbcommon
wayland
];
} }

View file

@ -2,7 +2,8 @@ use std::sync::{RwLock, RwLockWriteGuard};
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use servicepoint2::{ use servicepoint2::{
ByteGrid, Command, Origin, PixelGrid, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE, ByteGrid, Command, Grid, Origin, PIXEL_COUNT, PIXEL_WIDTH, PixelGrid,
TILE_SIZE,
}; };
use crate::font::BitmapFont; use crate::font::BitmapFont;
@ -25,7 +26,7 @@ pub(crate) fn execute_command(
} }
Command::BitmapLinearWin(Origin(x, y), pixels, _) => { Command::BitmapLinearWin(Origin(x, y), pixels, _) => {
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
print_pixel_grid(x as usize, y as usize, &pixels, &mut display); print_pixel_grid(x, y, &pixels, &mut display);
} }
Command::Cp437Data(origin, grid) => { Command::Cp437Data(origin, grid) => {
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
@ -37,7 +38,7 @@ pub(crate) fn execute_command(
} }
// TODO: how to deduplicate this code in a rusty way? // TODO: how to deduplicate this code in a rusty way?
Command::BitmapLinear(offset, vec, _) => { Command::BitmapLinear(offset, vec, _) => {
if !check_bitmap_valid(offset, vec.len()) { if !check_bitmap_valid(offset as u16, vec.len()) {
return true; return true;
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
@ -48,7 +49,7 @@ pub(crate) fn execute_command(
} }
} }
Command::BitmapLinearAnd(offset, vec, _) => { Command::BitmapLinearAnd(offset, vec, _) => {
if !check_bitmap_valid(offset, vec.len()) { if !check_bitmap_valid(offset as u16, vec.len()) {
return true; return true;
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
@ -60,7 +61,7 @@ pub(crate) fn execute_command(
} }
} }
Command::BitmapLinearOr(offset, vec, _) => { Command::BitmapLinearOr(offset, vec, _) => {
if !check_bitmap_valid(offset, vec.len()) { if !check_bitmap_valid(offset as u16, vec.len()) {
return true; return true;
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
@ -72,7 +73,7 @@ pub(crate) fn execute_command(
} }
} }
Command::BitmapLinearXor(offset, vec, _) => { Command::BitmapLinearXor(offset, vec, _) => {
if !check_bitmap_valid(offset, vec.len()) { if !check_bitmap_valid(offset as u16, vec.len()) {
return true; return true;
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
@ -85,8 +86,6 @@ pub(crate) fn execute_command(
} }
Command::CharBrightness(origin, grid) => { Command::CharBrightness(origin, grid) => {
let Origin(offset_x, offset_y) = origin; let Origin(offset_x, offset_y) = origin;
let offset_x = offset_x as usize;
let offset_y = offset_y as usize;
let mut luma = luma_ref.write().unwrap(); let mut luma = luma_ref.write().unwrap();
for inner_y in 0..grid.height() { for inner_y in 0..grid.height() {
@ -130,9 +129,6 @@ fn print_cp437_data(
display: &mut RwLockWriteGuard<PixelGrid>, display: &mut RwLockWriteGuard<PixelGrid>,
) { ) {
let Origin(x, y) = origin; let Origin(x, y) = origin;
let x = x as usize;
let y = y as usize;
for char_y in 0usize..grid.height() { for char_y in 0usize..grid.height() {
for char_x in 0usize..grid.width() { for char_x in 0usize..grid.width() {
let char_code = grid.get(char_x, char_y); let char_code = grid.get(char_x, char_y);
@ -142,8 +138,8 @@ fn print_cp437_data(
let bitmap = font.get_bitmap(char_code); let bitmap = font.get_bitmap(char_code);
if !print_pixel_grid( if !print_pixel_grid(
tile_x * TILE_SIZE as usize, tile_x * TILE_SIZE,
tile_y * TILE_SIZE as usize, tile_y * TILE_SIZE,
bitmap, bitmap,
display, display,
) { ) {
@ -185,8 +181,5 @@ fn print_pixel_grid(
fn get_coordinates_for_index(offset: usize, index: usize) -> (usize, usize) { fn get_coordinates_for_index(offset: usize, index: usize) -> (usize, usize) {
let pixel_index = offset + index; let pixel_index = offset + index;
( (pixel_index % PIXEL_WIDTH, pixel_index / PIXEL_WIDTH)
pixel_index % PIXEL_WIDTH as usize,
pixel_index / PIXEL_WIDTH as usize,
)
} }