undo rename for easier rebase
This commit is contained in:
parent
4bcab8ad67
commit
339eee14f6
4 changed files with 22 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
|
|||
|
||||
use crate::{
|
||||
get_pixel,
|
||||
grid::{self, FlutGrid},
|
||||
grid::{self, Flut},
|
||||
increment_counter,
|
||||
protocols::{BinaryParser, IOProtocol, Parser, Responder, TextParser},
|
||||
set_pixel_rgba, Canvas, Color, Command, Coordinate, Protocol, Response,
|
||||
|
|
@ -45,7 +45,7 @@ where
|
|||
{
|
||||
reader: BufReader<R>,
|
||||
writer: BufWriter<W>,
|
||||
grids: Arc<[FlutGrid<u32>]>,
|
||||
grids: Arc<[Flut<u32>]>,
|
||||
parser: ParserTypes,
|
||||
counter: u64,
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(reader: R, writer: W, grids: Arc<[grid::FlutGrid<u32>]>) -> Self {
|
||||
pub fn new(reader: R, writer: W, grids: Arc<[grid::Flut<u32>]>) -> Self {
|
||||
FlutClient {
|
||||
reader: BufReader::new(reader),
|
||||
writer: BufWriter::new(writer),
|
||||
|
|
|
|||
30
src/grid.rs
30
src/grid.rs
|
|
@ -12,20 +12,20 @@ pub trait Grid<I, V> {
|
|||
fn set(&self, x: I, y: I, value: V);
|
||||
}
|
||||
|
||||
pub struct FlutGrid<T> {
|
||||
pub struct Flut<T> {
|
||||
size_x: usize,
|
||||
size_y: usize,
|
||||
cells: SyncUnsafeCell<Vec<T>>,
|
||||
jpgbuf: RwLock<Vec<u8>>
|
||||
}
|
||||
|
||||
impl<T: Clone> FlutGrid<T> {
|
||||
pub fn init(size_x: usize, size_y: usize, value: T) -> FlutGrid<T> {
|
||||
impl<T: Clone> Flut<T> {
|
||||
pub fn init(size_x: usize, size_y: usize, value: T) -> Flut<T> {
|
||||
let mut vec = Vec::with_capacity(size_x * size_y);
|
||||
for _ in 0..(size_x * size_y) {
|
||||
vec.push(value.clone());
|
||||
}
|
||||
FlutGrid {
|
||||
Flut {
|
||||
size_x,
|
||||
size_y,
|
||||
cells: vec.into(),
|
||||
|
|
@ -38,7 +38,7 @@ impl<T: Clone> FlutGrid<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> FlutGrid<T> {
|
||||
impl<T> Flut<T> {
|
||||
fn index(&self, x: Coordinate, y: Coordinate) -> Option<usize> {
|
||||
let x = x as usize;
|
||||
let y = y as usize;
|
||||
|
|
@ -52,7 +52,7 @@ impl<T> FlutGrid<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Grid<Coordinate, T> for FlutGrid<T> {
|
||||
impl<T> Grid<Coordinate, T> for Flut<T> {
|
||||
fn get(&self, x: Coordinate, y: Coordinate) -> Option<&T> {
|
||||
self.index(x, y)
|
||||
.map(|idx| unsafe { &(*self.cells.get())[idx] })
|
||||
|
|
@ -71,7 +71,7 @@ impl<T> Grid<Coordinate, T> for FlutGrid<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl GenericImageView for FlutGrid<u32> {
|
||||
impl GenericImageView for Flut<u32> {
|
||||
type Pixel = Rgb<u8>;
|
||||
|
||||
fn dimensions(&self) -> (u32, u32) {
|
||||
|
|
@ -87,7 +87,7 @@ impl GenericImageView for FlutGrid<u32> {
|
|||
|
||||
}
|
||||
|
||||
impl FlutGrid<u32> {
|
||||
impl Flut<u32> {
|
||||
pub async fn update_jpg_buffer(&self) {
|
||||
let mut jpgbuf = self.jpgbuf.write().await;
|
||||
jpgbuf.clear();
|
||||
|
|
@ -103,19 +103,19 @@ impl FlutGrid<u32> {
|
|||
#[cfg(test)]
|
||||
#[allow(clippy::needless_return)]
|
||||
mod tests {
|
||||
use super::FlutGrid;
|
||||
use super::Flut;
|
||||
use super::Grid;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_grid_init_values() {
|
||||
let grid = FlutGrid::init(3, 3, 0);
|
||||
let grid = Flut::init(3, 3, 0);
|
||||
|
||||
assert_eq!(grid.cells.into_inner(), vec![0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_grid_init_size() {
|
||||
let grid = FlutGrid::init(800, 600, 0);
|
||||
let grid = Flut::init(800, 600, 0);
|
||||
|
||||
assert_eq!(grid.size_x, 800);
|
||||
assert_eq!(grid.size_y, 600);
|
||||
|
|
@ -123,7 +123,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_grid_set() {
|
||||
let grid = FlutGrid::init(3, 3, 0);
|
||||
let grid = Flut::init(3, 3, 0);
|
||||
grid.set(1, 1, 255);
|
||||
grid.set(2, 1, 256);
|
||||
assert_eq!(grid.cells.into_inner(), vec![0, 0, 0, 0, 255, 256, 0, 0, 0]);
|
||||
|
|
@ -131,7 +131,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_grid_set_out_of_range() {
|
||||
let grid = FlutGrid::init(3, 3, 0);
|
||||
let grid = Flut::init(3, 3, 0);
|
||||
grid.set(1, 1, 255);
|
||||
grid.set(3, 1, 256);
|
||||
assert_eq!(grid.cells.into_inner(), vec![0, 0, 0, 0, 255, 0, 0, 0, 0]);
|
||||
|
|
@ -139,14 +139,14 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_grid_get() {
|
||||
let grid = FlutGrid::init(3, 3, 0);
|
||||
let grid = Flut::init(3, 3, 0);
|
||||
grid.set(1, 2, 222);
|
||||
assert_eq!(grid.get(1, 2), Some(&222));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_grid_get_out_of_range() {
|
||||
let grid = FlutGrid::init(3, 3, 0);
|
||||
let grid = Flut::init(3, 3, 0);
|
||||
grid.set(3, 1, 256);
|
||||
assert_eq!(grid.get(3, 1), None);
|
||||
assert_eq!(grid.get(1, 2), Some(&0));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub type Coordinate = u16;
|
|||
pub static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
fn set_pixel_rgba(
|
||||
grids: &[grid::FlutGrid<u32>],
|
||||
grids: &[grid::Flut<u32>],
|
||||
canvas: Canvas,
|
||||
x: Coordinate,
|
||||
y: Coordinate,
|
||||
|
|
@ -34,7 +34,7 @@ fn set_pixel_rgba(
|
|||
}
|
||||
|
||||
fn get_pixel(
|
||||
grids: &[grid::FlutGrid<u32>],
|
||||
grids: &[grid::Flut<u32>],
|
||||
canvas: Canvas,
|
||||
x: Coordinate,
|
||||
y: Coordinate,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use debug_print::{debug_eprintln, debug_println};
|
|||
use flurry::{
|
||||
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL},
|
||||
flutclient::FlutClient,
|
||||
grid::{self, FlutGrid},
|
||||
grid::{self, Flut},
|
||||
COUNTER,
|
||||
};
|
||||
use image::{codecs::jpeg::JpegEncoder, GenericImageView, SubImage};
|
||||
|
|
@ -84,7 +84,7 @@ async fn handle_flut(flut_listener: TcpListener, grids: Arc<[grid::Flut<u32>]>)
|
|||
#[tokio::main]
|
||||
#[allow(clippy::needless_return)]
|
||||
async fn main() {
|
||||
let grids: Arc<[FlutGrid<u32>; GRID_LENGTH]> = [grid::FlutGrid::init(800, 600, 0xff_00_ff_ff)].into();
|
||||
let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
|
||||
println!("created grids");
|
||||
|
||||
let Ok(flut_listener) = TcpListener::bind(HOST).await else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue