Skip to content

Commit

Permalink
Remove unused stuff and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamVenner committed Jun 3, 2022
1 parent d7cd018 commit a30a439
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 147 deletions.
72 changes: 1 addition & 71 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "squad-mortar-helper"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["William Venner <[email protected]>"]
publish = false
Expand Down Expand Up @@ -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"] }
build_cfg = "1"
2 changes: 1 addition & 1 deletion heightmap-ripper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions vision-common/src/dylib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -136,7 +136,7 @@ vision_dylib_wrapper! {
fn find_scales_preprocess(&self, scales_start_y: u32) -> Result<*const SusRefCell<image::GrayImage>, 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<SmallVec<Line<f32>, 32>, E>;
fn find_longest_line(&self, image: &LSDImage, pt: Point<f32>, max_gap: f32) -> Result<(Line<f32>, f32), E>;
Expand Down
4 changes: 2 additions & 2 deletions vision-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait Vision: Sized + Send + Sync {
fn get_cpu_frame(&self) -> Arc<VisionFrame>;

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<Option<(image::RgbaImage, [u32; 4])>, Self::Error>;

Expand All @@ -59,7 +59,7 @@ pub trait Vision: Sized + Send + Sync {
fn find_scales_preprocess(&self, scales_start_y: u32) -> Result<*const SusRefCell<image::GrayImage>, 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<f32>, max_gap: f32) -> Result<(Line<f32>, f32), Self::Error>;
fn find_marker_lines(&self, max_gap: u32) -> Result<SmallVec<Line<f32>, 32>, Self::Error>;
Expand Down
59 changes: 32 additions & 27 deletions vision-common/src/markers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
}

#[derive(Clone, Copy, Debug)]
pub struct MarkedMapMarkerPixel {
pub visible: bool,
pub pixel: image::Rgba<u8>,
}

/// Saturation is a special case.
///
/// The markers can be brightened by the lightness arc that the player icon emits on the map.
Expand Down Expand Up @@ -80,13 +53,44 @@ pub fn is_any_map_marker_color<P: HSV>(pixel: P) -> bool {
})
}

/*
DISABLED
Not needed for now.
fn isolate_map_markers(image: &mut image::RgbaImage) {
image
.pixels_mut()
.filter(|pixel| !is_any_map_marker_color(**pixel))
.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<u8>,
}
#[derive(Clone, Copy, Debug)]
pub struct MarkedMapMarkerPixel {
pub visible: bool,
pub pixel: image::Rgba<u8>,
}
fn process_marker<P: MapMarkerFilter>(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...");
Expand Down Expand Up @@ -145,3 +149,4 @@ impl MapMarkerFilter for UnfilteredMarkers {
marker.pixels().copied().collect()
}
}
*/
28 changes: 16 additions & 12 deletions vision-cpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub struct CPUFallback {

lsd_image: SusRefCell<image::GrayImage>,

marked_marker_pixels: (SusRefCell<Vec<(u32, u32)>>, AtomicUsize),
markers: [Box<[markers::MapMarkerPixel]>; markers::AMOUNT],
map_marker_size: u32,
// marked_marker_pixels: (SusRefCell<Vec<(u32, u32)>>, AtomicUsize),
// markers: [Box<[markers::MapMarkerPixel]>; markers::AMOUNT],
// map_marker_size: u32,
}

macro_rules! memory {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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::<markers::FilteredMarkers>(map_marker_size);
// self.markers = markers::load_markers::<markers::FilteredMarkers>(map_marker_size);
self.map_marker_size = map_marker_size;
}
Ok(())
}
*/

fn crop_to_map(&self, grayscale: bool) -> Result<Option<(image::RgbaImage, [u32; 4])>, Self::Error> {
let frame = &self.frame;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -349,6 +352,7 @@ impl Vision for CPUFallback {
Ok(())
}
*/

fn mask_marker_lines(&self) -> Result<(), Self::Error> {
let cropped_map = memory!(&self.cropped_map);
Expand Down
Loading

0 comments on commit a30a439

Please sign in to comment.