From a30a439de8ba07cb93285de64d4ef31c2ae2dee5 Mon Sep 17 00:00:00 2001 From: William Venner Date: Fri, 3 Jun 2022 20:14:17 +0100 Subject: [PATCH] Remove unused stuff and dependencies --- Cargo.lock | 72 +------------------------------- Cargo.toml | 7 +--- heightmap-ripper/Cargo.toml | 2 +- util/Cargo.toml | 2 +- vision-common/src/dylib.rs | 4 +- vision-common/src/lib.rs | 4 +- vision-common/src/markers/mod.rs | 59 ++++++++++++++------------ vision-cpu/src/lib.rs | 28 +++++++------ vision-gpu/src/lib.rs | 53 ++++++++++++----------- web/Cargo.toml | 3 +- 10 files changed, 87 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38cd798..2c39442 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -511,26 +511,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" -[[package]] -name = "const_format" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0936ffe6d0c8d6a51b3b0a73b2acbe925d786f346cf45bfddc8341d79fb7dc8a" -dependencies = [ - "const_format_proc_macros", -] - -[[package]] -name = "const_format_proc_macros" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef196d5d972878a48da7decb7686eded338b4858fbabeed513d63a7c98b2b82d" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - [[package]] name = "conv" version = "0.3.3" @@ -1196,16 +1176,6 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] -[[package]] -name = "gif" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b" -dependencies = [ - "color_quant", - "weezl", -] - [[package]] name = "gimli" version = "0.26.1" @@ -1522,14 +1492,11 @@ dependencies = [ "bytemuck", "byteorder", "color_quant", - "gif", "jpeg-decoder", "num-iter", "num-rational", "num-traits", "png", - "scoped_threadpool", - "tiff", ] [[package]] @@ -1625,9 +1592,6 @@ name = "jpeg-decoder" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" -dependencies = [ - "rayon", -] [[package]] name = "keyvalues-parser" @@ -2409,15 +2373,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -[[package]] -name = "prefer-dynamic" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75e44b517d01fe504831a8568573f74b41744be36719d50adedc644a6671a4fe" -dependencies = [ - "build_cfg", -] - [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -2716,12 +2671,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" -[[package]] -name = "scoped_threadpool" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" - [[package]] name = "scopeguard" version = "1.1.0" @@ -2930,7 +2879,6 @@ dependencies = [ name = "smh-web" version = "0.1.0" dependencies = [ - "const_format", "futures-util", "lazy_static", "local-ip-address", @@ -2971,7 +2919,7 @@ dependencies = [ [[package]] name = "squad-mortar-helper" -version = "0.2.0" +version = "0.2.1" dependencies = [ "backtrace", "build-time", @@ -2987,7 +2935,6 @@ dependencies = [ "lazy_static", "magic_static", "msgbox", - "prefer-dynamic", "scrap", "serde", "serde_json", @@ -3118,17 +3065,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tiff" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" -dependencies = [ - "jpeg-decoder", - "miniz_oxide 0.4.4", - "weezl", -] - [[package]] name = "time" version = "0.1.43" @@ -3430,12 +3366,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "weezl" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e" - [[package]] name = "which" version = "3.1.1" diff --git a/Cargo.toml b/Cargo.toml index 252de96..0a35814 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "squad-mortar-helper" -version = "0.2.0" +version = "0.2.1" edition = "2021" authors = ["William Venner "] publish = false @@ -77,7 +77,4 @@ winapi = { version = "0.3.9", features = ["winuser"] } winres = "0" [build-dependencies] -build_cfg = "1" - -[dev-dependencies] -prefer-dynamic = { version = "0", features = ["link-test"] } \ No newline at end of file +build_cfg = "1" \ No newline at end of file diff --git a/heightmap-ripper/Cargo.toml b/heightmap-ripper/Cargo.toml index 65bcc79..2424892 100644 --- a/heightmap-ripper/Cargo.toml +++ b/heightmap-ripper/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] thiserror = "1" -image = "0.23" +image = { version = "0.23", default-features = false, features = ["png", "jpeg", "ico"] } log = "0" steamlocate = "1" byteorder = "1" diff --git a/util/Cargo.toml b/util/Cargo.toml index 33e5780..4edea91 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] log = "0" rayon = "1.5.3" -image = "0.23" +image = { version = "0.23", default-features = false, features = ["png", "jpeg", "ico"] } imageproc = { version = "0.22", features = ["rayon"] } open = "2" paste = "1" diff --git a/vision-common/src/dylib.rs b/vision-common/src/dylib.rs index 1a40e5d..a832251 100644 --- a/vision-common/src/dylib.rs +++ b/vision-common/src/dylib.rs @@ -123,7 +123,7 @@ vision_dylib_wrapper! { &mut self => { fn load_frame(&mut self, image: VisionFrame) -> Result<(), E>; - fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), E>; + // fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), E>; }; &self => { @@ -136,7 +136,7 @@ vision_dylib_wrapper! { fn find_scales_preprocess(&self, scales_start_y: u32) -> Result<*const SusRefCell, E>; fn isolate_map_markers(&self) -> Result<(), E>; - fn filter_map_marker_icons(&self) -> Result<(), E>; + // fn filter_map_marker_icons(&self) -> Result<(), E>; fn mask_marker_lines(&self) -> Result<(), E>; fn find_marker_lines(&self, max_gap: u32) -> Result, 32>, E>; fn find_longest_line(&self, image: &LSDImage, pt: Point, max_gap: f32) -> Result<(Line, f32), E>; diff --git a/vision-common/src/lib.rs b/vision-common/src/lib.rs index 4931b76..d6ea0a4 100644 --- a/vision-common/src/lib.rs +++ b/vision-common/src/lib.rs @@ -50,7 +50,7 @@ pub trait Vision: Sized + Send + Sync { fn get_cpu_frame(&self) -> Arc; fn load_frame(&mut self, image: VisionFrame) -> Result<(), Self::Error>; - fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), Self::Error>; + // fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), Self::Error>; fn crop_to_map(&self, grayscale: bool) -> Result, Self::Error>; @@ -59,7 +59,7 @@ pub trait Vision: Sized + Send + Sync { fn find_scales_preprocess(&self, scales_start_y: u32) -> Result<*const SusRefCell, Self::Error>; fn isolate_map_markers(&self) -> Result<(), Self::Error>; - fn filter_map_marker_icons(&self) -> Result<(), Self::Error>; + // fn filter_map_marker_icons(&self) -> Result<(), Self::Error>; fn mask_marker_lines(&self) -> Result<(), Self::Error>; fn find_longest_line(&self, image: &Self::LSDImage, pt: Point, max_gap: f32) -> Result<(Line, f32), Self::Error>; fn find_marker_lines(&self, max_gap: u32) -> Result, 32>, Self::Error>; diff --git a/vision-common/src/markers/mod.rs b/vision-common/src/markers/mod.rs index c2cdea8..f5adba0 100644 --- a/vision-common/src/markers/mod.rs +++ b/vision-common/src/markers/mod.rs @@ -8,33 +8,6 @@ const CHARLIE_MARKER_COLOR_HSV_TUP: (u16, u8, u8) = ( CHARLIE_MARKER_COLOR_HSV[2] as _, ); -macro_rules! markers { - ($($path:literal),*) => { - const RAW_MARKERS: &[&[u8]] = &[$(include_bytes!($path)),*]; - pub const AMOUNT: usize = RAW_MARKERS.len(); - }; -} -markers! { - "resources/map_commandmarker_squad_attack.TGA", - "resources/map_commandmarker_squad_build.TGA", - "resources/map_commandmarker_squad_defend.TGA", - "resources/map_commandmarker_squad_move.TGA", - "resources/map_commandmarker_squad_observe.TGA" -} - -#[derive(Clone, Copy, Debug)] -pub struct MapMarkerPixel { - pub x: u32, - pub y: u32, - pub pixel: image::Rgba, -} - -#[derive(Clone, Copy, Debug)] -pub struct MarkedMapMarkerPixel { - pub visible: bool, - pub pixel: image::Rgba, -} - /// Saturation is a special case. /// /// The markers can be brightened by the lightness arc that the player icon emits on the map. @@ -80,6 +53,10 @@ pub fn is_any_map_marker_color(pixel: P) -> bool { }) } +/* +DISABLED +Not needed for now. + fn isolate_map_markers(image: &mut image::RgbaImage) { image .pixels_mut() @@ -87,6 +64,33 @@ fn isolate_map_markers(image: &mut image::RgbaImage) { .for_each(|pixel| *pixel = image::Rgba([0, 0, 0, 0])) } +macro_rules! markers { + ($($path:literal),*) => { + const RAW_MARKERS: &[&[u8]] = &[$(include_bytes!($path)),*]; + pub const AMOUNT: usize = RAW_MARKERS.len(); + }; +} +markers! { + "resources/map_commandmarker_squad_attack.TGA", + "resources/map_commandmarker_squad_build.TGA", + "resources/map_commandmarker_squad_defend.TGA", + "resources/map_commandmarker_squad_move.TGA", + "resources/map_commandmarker_squad_observe.TGA" +} + +#[derive(Clone, Copy, Debug)] +pub struct MapMarkerPixel { + pub x: u32, + pub y: u32, + pub pixel: image::Rgba, +} + +#[derive(Clone, Copy, Debug)] +pub struct MarkedMapMarkerPixel { + pub visible: bool, + pub pixel: image::Rgba, +} + fn process_marker(marker: &'static [u8], size: u32, corners: Option<&[MapMarkerPixel]>) -> Box<[P::Pixel]> { let marker = image::load_from_memory_with_format(marker, image::ImageFormat::Tga) .expect("Failed to load embedded map marker TGA! This should never happen..."); @@ -145,3 +149,4 @@ impl MapMarkerFilter for UnfilteredMarkers { marker.pixels().copied().collect() } } +*/ \ No newline at end of file diff --git a/vision-cpu/src/lib.rs b/vision-cpu/src/lib.rs index 800270b..15def7e 100644 --- a/vision-cpu/src/lib.rs +++ b/vision-cpu/src/lib.rs @@ -21,9 +21,9 @@ pub struct CPUFallback { lsd_image: SusRefCell, - marked_marker_pixels: (SusRefCell>, AtomicUsize), - markers: [Box<[markers::MapMarkerPixel]>; markers::AMOUNT], - map_marker_size: u32, + // marked_marker_pixels: (SusRefCell>, AtomicUsize), + // markers: [Box<[markers::MapMarkerPixel]>; markers::AMOUNT], + // map_marker_size: u32, } macro_rules! memory { @@ -82,7 +82,7 @@ impl Vision for CPUFallback { self.cropped_map = image::RgbImage::new(w, h).into(); self.cropped_brq = image::RgbImage::new(brq_w, brq_h).into(); self.ocr_out = image::GrayImage::new(brq_w, brq_h).into(); - self.marked_marker_pixels = (SusRefCell::new(vec![Default::default(); w as usize * h as usize]), AtomicUsize::new(0)); + // self.marked_marker_pixels = (SusRefCell::new(vec![Default::default(); w as usize * h as usize]), AtomicUsize::new(0)); self.scales_preprocessed = image::GrayImage::new(brq_w, brq_h).into(); self.lsd_image = image::GrayImage::new(w, h).into(); } @@ -97,13 +97,15 @@ impl Vision for CPUFallback { self.frame.clone() } + /* fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), Self::Error> { if self.map_marker_size != map_marker_size { - self.markers = markers::load_markers::(map_marker_size); + // self.markers = markers::load_markers::(map_marker_size); self.map_marker_size = map_marker_size; } Ok(()) } + */ fn crop_to_map(&self, grayscale: bool) -> Result, Self::Error> { let frame = &self.frame; @@ -251,32 +253,33 @@ impl Vision for CPUFallback { fn isolate_map_markers(&self) -> Result<(), Self::Error> { let mut cropped_map = memory!(&mut self.cropped_map); - let marked_marker_pixels = memory!(&self.marked_marker_pixels); - let (mut marked_marker_pixels, len) = (marked_marker_pixels.0.borrow_mut(), &marked_marker_pixels.1); + // let marked_marker_pixels = memory!(&self.marked_marker_pixels); + // let (mut marked_marker_pixels, len) = (marked_marker_pixels.0.borrow_mut(), &marked_marker_pixels.1); - len.store(0, std::sync::atomic::Ordering::Release); + // len.store(0, std::sync::atomic::Ordering::Release); // Isolate green pixels let par_cropped_map = UnsafeSendPtr::new_mut(&mut *cropped_map); - let par_marked_marker_pixels = UnsafeSendPtr::new_mut(&mut *marked_marker_pixels); + // let par_marked_marker_pixels = UnsafeSendPtr::new_mut(&mut *marked_marker_pixels); par_iter_pixels!(cropped_map).for_each(move |(x, y, pixel)| { let cropped_map = unsafe { par_cropped_map.clone().as_mut() }; - let marked_marker_pixels = unsafe { par_marked_marker_pixels.clone().as_mut() }; + // let marked_marker_pixels = unsafe { par_marked_marker_pixels.clone().as_mut() }; if !markers::is_any_map_marker_color(pixel) { cropped_map.put_pixel_fast(x, y, image::Rgb([0, 0, 0])); - } else if x >= self.map_marker_size + }/* else if x >= self.map_marker_size && y >= self.map_marker_size && x < cropped_map.width() - self.map_marker_size - 1 && y < cropped_map.height() - self.map_marker_size - 1 { marked_marker_pixels[len.fetch_add(1, std::sync::atomic::Ordering::SeqCst)] = (x, y); - } + }*/ }); Ok(()) } + /* fn filter_map_marker_icons(&self) -> Result<(), Self::Error> { let map_marker_size = self.map_marker_size; let markers = &self.markers; @@ -349,6 +352,7 @@ impl Vision for CPUFallback { Ok(()) } + */ fn mask_marker_lines(&self) -> Result<(), Self::Error> { let cropped_map = memory!(&self.cropped_map); diff --git a/vision-gpu/src/lib.rs b/vision-gpu/src/lib.rs index 36aa4d9..23080e4 100644 --- a/vision-gpu/src/lib.rs +++ b/vision-gpu/src/lib.rs @@ -6,7 +6,7 @@ extern crate bytemuck; mod cuda; mod gpuimage; -mod gpumarkers; +// mod gpumarkers; smh_vision_common::export_dylib_wrapper!(smh_vision_gpu => cuda::CUDAInstance); @@ -21,14 +21,14 @@ use cust::{ launch, memory::{ AsyncCopyDestination, CopyDestination, DeviceBox, DeviceBuffer, DeviceCopy, DevicePointer, DeviceSlice, LockedBuffer, UnifiedBuffer, - UnifiedPointer, DeviceSliceIndex, + UnifiedPointer }, prelude::*, }; use cuda::*; use gpuimage::*; -use gpumarkers::*; +// use gpumarkers::*; struct GPUMemory { frame: GPUImage, image::Bgra>, @@ -43,9 +43,9 @@ struct GPUMemory { scales_preprocessed: GPUImage, image::Luma>, scales_preprocessed_host: SusRefCell, - map_marker_template_matches_sad: SusRefCell>, - marked_map_marker_pixels: DeviceBuffer, - marked_map_marker_pixels_count: DeviceBox, + // map_marker_template_matches_sad: SusRefCell>, + // marked_map_marker_pixels: DeviceBuffer, + // marked_map_marker_pixels_count: DeviceBox, lsd_image: SusRefCell, image::Luma>>, lsd_image_dilate: DeviceBuffer, @@ -59,7 +59,7 @@ struct GPUMemory { impl GPUMemory { fn new(dimensions: (u32, u32)) -> Result { unsafe { - let map_icon_size: u32 = 22; // TODO scale to monitor + // let map_icon_size: u32 = 22; let [_, _, w, h] = MAP_BOUNDS.into_absolute([dimensions.0, dimensions.1]); @@ -90,9 +90,9 @@ impl GPUMemory { scales_preprocessed: GPUImage::uninitialized(brq_w, brq_h, 1)?, scales_preprocessed_host: SusRefCell::new(image::GrayImage::new(brq_w, brq_h)), - map_marker_template_matches_sad: SusRefCell::new(vec![GPUTemplateMatch::zeroed(); (w - map_icon_size) as usize * (h - map_icon_size) as usize]), - marked_map_marker_pixels: DeviceBuffer::uninitialized(w as usize * h as usize)?, - marked_map_marker_pixels_count: DeviceBox::uninitialized()?, + // map_marker_template_matches_sad: SusRefCell::new(vec![GPUTemplateMatch::zeroed(); (w - map_icon_size) as usize * (h - map_icon_size) as usize]), + // marked_map_marker_pixels: DeviceBuffer::uninitialized(w as usize * h as usize)?, + // marked_map_marker_pixels_count: DeviceBox::uninitialized()?, lsd_image: PinnedGPUImage::uninitialized(w, h, 1)?.into(), lsd_image_dilate: DeviceBuffer::uninitialized(w as usize * h as usize)?, @@ -110,8 +110,8 @@ struct GPUVisionState { dimensions: (u32, u32), memory: Option, - map_marker_size: u32, - map_markers: Option + // map_marker_size: u32, + // map_markers: Option } impl GPUVisionState { #[inline] @@ -124,6 +124,7 @@ impl GPUVisionState { Ok(unsafe { self.memory.as_mut().unwrap_unchecked() }) } + /* #[inline] fn update_map_markers(&mut self, map_marker_size: u32) -> Result<(), AnyError> { if self.map_markers.is_none() || self.map_marker_size != map_marker_size { @@ -133,6 +134,7 @@ impl GPUVisionState { } Ok(()) } + */ } macro_rules! memory { @@ -179,9 +181,8 @@ impl Vision for CUDAInstance { // reset state memory.red_pixels.async_copy_from(&0, stream)?; - memory.marked_map_marker_pixels_count.async_copy_from(&0, stream)?; - - memory.map_marker_template_matches_sad.borrow_mut().fill(GPUTemplateMatch::zeroed()); + // memory.marked_map_marker_pixels_count.async_copy_from(&0, stream)?; + // memory.map_marker_template_matches_sad.borrow_mut().fill(GPUTemplateMatch::zeroed()); stream.synchronize()?; } @@ -196,10 +197,12 @@ impl Vision for CUDAInstance { self.state.cpu_frame.clone() } + /* #[inline] fn load_map_markers(&mut self, map_marker_size: u32) -> Result<(), Self::Error> { self.state.update_map_markers(map_marker_size) } + */ fn crop_to_map(&self, grayscale: bool) -> Result, Self::Error> { // TODO whats the point of cropping on GPU? shouldn't we just use the CPU? @@ -345,19 +348,19 @@ impl Vision for CUDAInstance { fn isolate_map_markers(&self) -> Result<(), Self::Error> { let stream = memory!(&self.markers_stream); let cropped_map = memory!(&self.cropped_map); - let marked_map_marker_pixels = memory!(&self.marked_map_marker_pixels); - let marked_map_marker_pixels_count = memory!(&self.marked_map_marker_pixels_count); - let map_marker_size = self.state.map_marker_size; + // let marked_map_marker_pixels = memory!(&self.marked_map_marker_pixels); + // let marked_map_marker_pixels_count = memory!(&self.marked_map_marker_pixels_count); + // let map_marker_size = self.state.map_marker_size; unsafe { let (grid, block) = gpu_2d_kernel![<<<[cropped_map.width, cropped_map.height], (8, 8)>>>]; launch!( self.isolate_map_markers<<>>( cropped_map.as_device_ptr(), - cropped_map.width, cropped_map.height, - marked_map_marker_pixels.as_device_ptr(), - marked_map_marker_pixels_count.as_device_ptr(), - map_marker_size + cropped_map.width, cropped_map.height + // marked_map_marker_pixels.as_device_ptr(), + // marked_map_marker_pixels_count.as_device_ptr(), + // map_marker_size ) )?; } @@ -367,6 +370,7 @@ impl Vision for CUDAInstance { Ok(()) } + /* fn filter_map_marker_icons(&self) -> Result<(), Self::Error> { let marked_map_marker_pixels_count = memory!(&self.marked_map_marker_pixels_count).as_host_value()?; if marked_map_marker_pixels_count == 0 { @@ -423,6 +427,7 @@ impl Vision for CUDAInstance { Ok(()) } + */ fn mask_marker_lines(&self) -> Result<(), Self::Error> { #[link(name = "gpu_dilate", kind = "static")] @@ -570,7 +575,7 @@ fn test_gpu_computer_vision() { let image = image::ImageBuffer::from_raw(image.width(), image.height(), image.into_raw().into_boxed_slice()).unwrap(); cuda.load_frame(image).unwrap(); - cuda.load_map_markers(22).unwrap(); + // cuda.load_map_markers(22).unwrap(); let ui_map = cuda.crop_to_map(true).unwrap().expect("crop_to_map failed"); @@ -585,7 +590,7 @@ fn test_gpu_computer_vision() { cuda.thread_ctx().unwrap(); cuda.isolate_map_markers().expect("isolate_map_markers failed"); - cuda.filter_map_marker_icons().expect("filter_map_marker_icons failed"); + // cuda.filter_map_marker_icons().expect("filter_map_marker_icons failed"); cuda.mask_marker_lines().expect("mask_marker_lines failed"); cuda.find_marker_lines(22).expect("find_marker_lines failed") }, diff --git a/web/Cargo.toml b/web/Cargo.toml index 7c19dba..bb7c2ee 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -13,5 +13,4 @@ tokio = { version = "1", features = ["rt", "sync", "macros", "parking_lot", "tim tokio-tungstenite = "0" futures-util = "0" local-ip-address = "0" -lazy_static = "1" -const_format = "0" \ No newline at end of file +lazy_static = "1" \ No newline at end of file