mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 18:40:14 +01:00
implement BitmapLinear* commands
This commit is contained in:
parent
d07440f3d0
commit
5f4d2fba25
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2151,7 +2151,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint2"
|
name = "servicepoint2"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/kaesaecracker/servicepoint.git#571cf735105c39a11455b83392ce3b863bd590c1"
|
source = "git+https://github.com/kaesaecracker/servicepoint.git#8ceaef72faaa5d36000089c415a5b28f7e244513"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num",
|
"num",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
|
|
76
src/main.rs
76
src/main.rs
|
@ -9,11 +9,11 @@ use clap::Parser;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use servicepoint2::{
|
use servicepoint2::{
|
||||||
Command, Origin, Packet, PixelGrid, Size, Window, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
|
Command, Origin, Packet, PixelGrid, Size, Window, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
|
||||||
|
TILE_WIDTH,
|
||||||
};
|
};
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::sync::{mpsc, RwLock, RwLockWriteGuard};
|
use std::sync::{mpsc, RwLock, RwLockWriteGuard};
|
||||||
use std::thread;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ fn main() {
|
||||||
while stop_udp_rx.try_recv().is_err() {
|
while stop_udp_rx.try_recv().is_err() {
|
||||||
let (amount, _) = match socket.recv_from(&mut buf) {
|
let (amount, _) = match socket.recv_from(&mut buf) {
|
||||||
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
||||||
thread::sleep(Duration::from_millis(1));
|
std::thread::sleep(Duration::from_millis(1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
|
@ -87,13 +87,9 @@ fn main() {
|
||||||
|
|
||||||
udp_thread.join().expect("could not join udp thread");
|
udp_thread.join().expect("could not join udp thread");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_package(
|
fn handle_package(received: Packet, font: &BitmapFont, display: &mut RwLockWriteGuard<PixelGrid>) {
|
||||||
received: Packet,
|
|
||||||
font: &BitmapFont,
|
|
||||||
display: &mut RwLockWriteGuard<PixelGrid>,
|
|
||||||
) {
|
|
||||||
// TODO handle error case
|
|
||||||
let command = match Command::try_from(received) {
|
let command = match Command::try_from(received) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("could not read command for packet: {:?}", err);
|
warn!("could not read command for packet: {:?}", err);
|
||||||
|
@ -117,21 +113,52 @@ fn main() {
|
||||||
Command::Cp437Data(window, payload) => {
|
Command::Cp437Data(window, payload) => {
|
||||||
print_cp437_data(window, &payload, font, display);
|
print_cp437_data(window, &payload, font, display);
|
||||||
}
|
}
|
||||||
|
#[allow(deprecated)]
|
||||||
Command::BitmapLegacy => {
|
Command::BitmapLegacy => {
|
||||||
warn!("ignoring deprecated command {:?}", command);
|
warn!("ignoring deprecated command {:?}", command);
|
||||||
}
|
}
|
||||||
Command::BitmapLinear(offset, vec) => {}
|
Command::BitmapLinear(offset, vec) => {
|
||||||
Command::BitmapLinearAnd(_, _) => {}
|
for bitmap_index in 0..vec.len() {
|
||||||
Command::BitmapLinearOr(_, _) => {}
|
let pixel_index = offset as usize + bitmap_index;
|
||||||
Command::BitmapLinearXor(_, _) => {}
|
let y = pixel_index / TILE_WIDTH as usize;
|
||||||
|
let x = pixel_index % TILE_SIZE as usize;
|
||||||
Command::FadeOut => {}
|
display.set(x, y, vec.get(bitmap_index));
|
||||||
Command::CharBrightness(_, _) => {}
|
|
||||||
Command::Brightness(_) => {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Command::BitmapLinearAnd(offset, vec) => {
|
||||||
|
for bitmap_index in 0..vec.len() {
|
||||||
|
let pixel_index = offset as usize + bitmap_index;
|
||||||
|
let y = pixel_index / TILE_WIDTH as usize;
|
||||||
|
let x = pixel_index % TILE_SIZE as usize;
|
||||||
|
let old_value = display.get(x, y);
|
||||||
|
display.set(x, y, old_value && vec.get(bitmap_index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Command::BitmapLinearOr(offset, vec) => {
|
||||||
|
for bitmap_index in 0..vec.len() {
|
||||||
|
let pixel_index = offset as usize + bitmap_index;
|
||||||
|
let y = pixel_index / TILE_WIDTH as usize;
|
||||||
|
let x = pixel_index % TILE_SIZE as usize;
|
||||||
|
let old_value = display.get(x, y);
|
||||||
|
display.set(x, y, old_value || vec.get(bitmap_index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Command::BitmapLinearXor(offset, vec) => {
|
||||||
|
for bitmap_index in 0..vec.len() {
|
||||||
|
let pixel_index = offset as usize + bitmap_index;
|
||||||
|
let y = pixel_index / TILE_WIDTH as usize;
|
||||||
|
let x = pixel_index % TILE_SIZE as usize;
|
||||||
|
let old_value = display.get(x, y);
|
||||||
|
display.set(x, y, old_value ^ vec.get(bitmap_index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
error!("command not implemented: {command:?}")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn check_payload_size(buf: &[u8], expected: usize) -> bool {
|
fn check_payload_size(buf: &[u8], expected: usize) -> bool {
|
||||||
let actual = buf.len();
|
let actual = buf.len();
|
||||||
if actual == expected {
|
if actual == expected {
|
||||||
return true;
|
return true;
|
||||||
|
@ -142,14 +169,14 @@ fn main() {
|
||||||
expected, actual
|
expected, actual
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_cp437_data(
|
fn print_cp437_data(
|
||||||
window: Window,
|
window: Window,
|
||||||
payload: &[u8],
|
payload: &[u8],
|
||||||
font: &BitmapFont,
|
font: &BitmapFont,
|
||||||
display: &mut RwLockWriteGuard<PixelGrid>,
|
display: &mut RwLockWriteGuard<PixelGrid>,
|
||||||
) {
|
) {
|
||||||
let Window(Origin(x, y), Size(w, h)) = window;
|
let Window(Origin(x, y), Size(w, h)) = window;
|
||||||
if !check_payload_size(payload, (w * h) as usize) {
|
if !check_payload_size(payload, (w * h) as usize) {
|
||||||
return;
|
return;
|
||||||
|
@ -171,14 +198,14 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_pixel_grid(
|
fn print_pixel_grid(
|
||||||
offset_x: usize,
|
offset_x: usize,
|
||||||
offset_y: usize,
|
offset_y: usize,
|
||||||
pixels: &PixelGrid,
|
pixels: &PixelGrid,
|
||||||
display: &mut RwLockWriteGuard<PixelGrid>,
|
display: &mut RwLockWriteGuard<PixelGrid>,
|
||||||
) {
|
) {
|
||||||
debug!(
|
debug!(
|
||||||
"printing {}x{} grid at {offset_x} {offset_y}",
|
"printing {}x{} grid at {offset_x} {offset_y}",
|
||||||
pixels.width, pixels.height
|
pixels.width, pixels.height
|
||||||
|
@ -189,5 +216,4 @@ fn main() {
|
||||||
display.set(offset_x + inner_x, offset_y + inner_y, is_set);
|
display.set(offset_x + inner_x, offset_y + inner_y, is_set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue