mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-05 05:54:02 +01:00
Add CPU matching option and improve default behavior handling
This commit is contained in:
@ -168,6 +168,13 @@ fn main() {
|
||||
.default_value("50")
|
||||
.value_parser(|s: &str| s.parse::<usize>().map_err(|e| e.to_string())),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("cpu")
|
||||
.help("Force CPU Matching, skip OpenCL checks")
|
||||
.short('c')
|
||||
.long("force-cpu")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.about("Searches for a pattern in a schematic")
|
||||
.bin_name("schemsearch");
|
||||
|
||||
@ -214,6 +221,7 @@ fn main() {
|
||||
ignore_entities: matches.get_flag("ignore-entities"),
|
||||
threshold: *matches.get_one::<f32>("threshold").expect("Couldn't get threshold"),
|
||||
invalid_nbt: matches.get_flag("invalid-nbt"),
|
||||
use_cpu: matches.get_flag("use-cpu"),
|
||||
};
|
||||
|
||||
let pattern = match matches.get_one::<String>("pattern") {
|
||||
|
||||
@ -9,6 +9,22 @@ pub struct SearchBehavior {
|
||||
pub ignore_entities: bool,
|
||||
pub threshold: f32,
|
||||
pub invalid_nbt: bool,
|
||||
pub use_cpu: bool,
|
||||
}
|
||||
|
||||
impl Default for SearchBehavior {
|
||||
fn default() -> Self {
|
||||
SearchBehavior {
|
||||
ignore_block_data: false,
|
||||
ignore_block_entities: false,
|
||||
ignore_air: false,
|
||||
air_as_any: false,
|
||||
ignore_entities: false,
|
||||
threshold: 0.9,
|
||||
invalid_nbt: false,
|
||||
use_cpu: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)]
|
||||
|
||||
@ -7,10 +7,9 @@ license = "AGPL-3.0-or-later"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
schemsearch-files = { path = "../schemsearch-files" }
|
||||
schemsearch-common = { path = "../schemsearch-common" }
|
||||
schemsearch-ocl-matcher = { path = "../schemsearch-ocl-matcher" }
|
||||
named-binary-tag = "0.6"
|
||||
libmath = "0.2.1"
|
||||
lazy_static = "1.4.0"
|
||||
lazy_static = "1.4.0"
|
||||
@ -84,15 +84,7 @@ mod tests {
|
||||
let schematic = SpongeSchematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
|
||||
let endstone = SpongeSchematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
|
||||
|
||||
let _ = search(schematic, &endstone, SearchBehavior {
|
||||
ignore_block_data: true,
|
||||
ignore_block_entities: true,
|
||||
ignore_entities: true,
|
||||
ignore_air: false,
|
||||
air_as_any: false,
|
||||
threshold: 0.9,
|
||||
invalid_nbt: false
|
||||
});
|
||||
let _ = search(schematic, &endstone, SearchBehavior::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -100,15 +92,7 @@ mod tests {
|
||||
let schematic = SpongeSchematic::load(&PathBuf::from("../tests/Random.schem")).unwrap();
|
||||
let pattern = SpongeSchematic::load(&PathBuf::from("../tests/Pattern.schem")).unwrap();
|
||||
|
||||
let matches = search(schematic, &pattern, SearchBehavior {
|
||||
ignore_block_data: true,
|
||||
ignore_block_entities: true,
|
||||
ignore_entities: true,
|
||||
ignore_air: false,
|
||||
air_as_any: false,
|
||||
threshold: 0.9,
|
||||
invalid_nbt: false
|
||||
});
|
||||
let matches = search(schematic, &pattern, SearchBehavior::default());
|
||||
|
||||
assert_eq!(matches.len(), 1);
|
||||
assert_eq!(matches[0].x, 1);
|
||||
@ -122,15 +106,7 @@ mod tests {
|
||||
let schematic = SpongeSchematic::load(&PathBuf::from("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap();
|
||||
let pattern = SpongeSchematic::load(&PathBuf::from("../tests/gray_castle_complex.schem")).unwrap();
|
||||
|
||||
let matches = search(schematic, &pattern, SearchBehavior {
|
||||
ignore_block_data: false,
|
||||
ignore_block_entities: false,
|
||||
ignore_entities: false,
|
||||
ignore_air: false,
|
||||
air_as_any: false,
|
||||
threshold: 0.9,
|
||||
invalid_nbt: false
|
||||
});
|
||||
let matches = search(schematic, &pattern, SearchBehavior::default());
|
||||
|
||||
assert_eq!(matches.len(), 1);
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ pub fn search(
|
||||
let schem_width = schem.width as usize;
|
||||
let schem_height = schem.height as usize;
|
||||
let schem_length = schem.length as usize;
|
||||
|
||||
if ocl_available() {
|
||||
|
||||
if !search_behavior.use_cpu && ocl_available() {
|
||||
return ocl_search(schem_data.as_slice(), [schem_width, schem_height, schem_length], pattern_schem.block_data.as_slice(), [pattern_width, pattern_height, pattern_length], *air_id, search_behavior).unwrap()
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use std::sync::OnceLock;
|
||||
use ocl::{Buffer, MemFlags, ProQue, Platform};
|
||||
use ocl::{Buffer, MemFlags, ProQue, core};
|
||||
use ocl::SpatialDims::Three;
|
||||
use schemsearch_common::{Match, SearchBehavior};
|
||||
use math::round::ceil;
|
||||
@ -9,7 +9,7 @@ const KERNEL: &str = include_str!("kernel.cl");
|
||||
static PRO_QUEU_CELL: OnceLock<ProQue> = OnceLock::new();
|
||||
|
||||
pub fn ocl_available() -> bool {
|
||||
!Platform::list().is_empty()
|
||||
core::default_platform().is_ok()
|
||||
}
|
||||
|
||||
pub fn ocl_search(
|
||||
|
||||
Reference in New Issue
Block a user