1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-07-03 09:38:04 +02:00
Dieser Commit ist enthalten in:
Chaoscaot 2023-12-26 21:28:46 +01:00
Ursprung d20940f89b
Commit 511ce04f0b
8 geänderte Dateien mit 176 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -16,4 +16,5 @@ opt-level = "z"
codegen-units = 1 codegen-units = 1
[profile.release] [profile.release]
lto = true lto = true
opt-level = 3

Datei anzeigen

@ -1,10 +1,10 @@
default: default:
@echo "Building (Release)..."; @echo "Building (Release)...";
cargo rustc --release --color=always -p schemsearch-cli -- -C target-feature=+avx2 cargo rustc --release --color=always -p schemsearch-cli -- -C target-cpu=native
sql: sql:
@echo "Building (Release)..."; @echo "Building (Release)...";
cargo rustc --release --color=always -p schemsearch-cli --features sql -- -C target-feature=+avx2 cargo rustc --release --color=always -p schemsearch-cli --features sql -- -C target-cpu=native
debug: debug:
@echo "Building (Debug)..."; @echo "Building (Debug)...";

Datei anzeigen

@ -11,3 +11,6 @@ serde = { version = "1.0.160", features = ["derive"] }
schemsearch-files = { path = "../schemsearch-files" } schemsearch-files = { path = "../schemsearch-files" }
named-binary-tag = "0.6" named-binary-tag = "0.6"
libmath = "0.2.1" libmath = "0.2.1"
[build-dependencies]
cc = { version = "1.0.83", features = [] }

7
schemsearch-lib/build.rs Normale Datei
Datei anzeigen

@ -0,0 +1,7 @@
use cc;
fn main() {
cc::Build::new()
.file("src/compare.c")
.compile("compare");
}

Datei anzeigen

@ -0,0 +1,69 @@
#include <stdint.h>
int32_t isMatching(
const int32_t *schem_data,
const int32_t *pattern_data,
size_t pattern_data_length,
int32_t x,
int32_t y,
int32_t z,
int32_t schem_width,
int32_t schem_length,
int32_t pattern_width,
int32_t pattern_height,
int32_t pattern_length,
int32_t *w_ptr
) {
for (int j = 0; j < pattern_height; ++j) {
for (int k = 0; k < pattern_length; ++k) {
int pattern_index_pre = k * pattern_width + j * pattern_width * pattern_length;
int schem_index_pre = x + (k + z) * schem_width + (j + y) * schem_width * schem_length;
for (int i = 0; i < pattern_width; ++i) {
int pattern_index = i + pattern_index_pre;
int schem_index = i + schem_index_pre;
w_ptr[pattern_index] = schem_data[schem_index];
}
}
}
int32_t matching = 0;
for (int i = 0; i < pattern_data_length; ++i) {
matching += w_ptr[i] == pattern_data[i];
}
return matching;
}
void is_matching_all(
const int32_t *schem_data,
const int32_t *pattern_data,
size_t schem_width,
size_t schem_height,
size_t schem_length,
size_t pattern_width,
size_t pattern_height,
size_t pattern_length,
int32_t *result
) {
for (size_t pz = 0; pz < pattern_length; ++pz) {
size_t maxZ = schem_length - pattern_length + pz + 1;
for (size_t py = 0; py < pattern_height; ++py) {
size_t maxY = schem_height - pattern_height + py + 1;
for (size_t px = 0; px < pattern_width; ++px) {
int32_t pv = pattern_data[px + py * pattern_width + pz * pattern_width * pattern_height];
size_t maxX = schem_width - pattern_width + px + 1;
for (size_t z = pz; z < maxZ; ++z) {
size_t sourceOffsetZ = z * schem_width * schem_height;
size_t resultOffsetZ = (z - pz) * schem_width * schem_height - py * schem_width;
for (size_t y = py; y < maxY; ++y) {
size_t sourceOffsetY = sourceOffsetZ + y * schem_width;
size_t resultOffsetY = resultOffsetZ + y * schem_width - px;
for (size_t x = px; x < maxX; ++x) {
result[resultOffsetY + x] += schem_data[sourceOffsetY + x] == pv;
}
}
}
}
}
}
}

Datei anzeigen

@ -33,6 +33,36 @@ pub struct SearchBehavior {
pub threshold: f32, pub threshold: f32,
} }
extern "C" {
pub fn isMatching(
schem_data: *const i32,
pattern_data: *const i32,
pattern_data_length: usize,
x: usize,
y: usize,
z: usize,
schem_width: usize,
schem_length: usize,
pattern_width: usize,
pattern_height: usize,
pattern_length: usize,
w_ptr: *mut i32,
) -> i32;
pub fn is_matching_all(
schem_data: *const i32,
pattern_data: *const i32,
schem_width: usize,
schem_height: usize,
schem_length: usize,
pattern_width: usize,
pattern_height: usize,
pattern_length: usize,
result: *mut i32
);
}
pub fn search( pub fn search(
schem: SpongeSchematic, schem: SpongeSchematic,
pattern_schem: &SpongeSchematic, pattern_schem: &SpongeSchematic,
@ -62,7 +92,8 @@ pub fn search(
let air_id = if search_behavior.ignore_air || search_behavior.air_as_any { pattern_schem.palette.get("minecraft:air").unwrap_or(&-1) } else { &-1}; let air_id = if search_behavior.ignore_air || search_behavior.air_as_any { pattern_schem.palette.get("minecraft:air").unwrap_or(&-1) } else { &-1};
let pattern_blocks = pattern_schem.block_data.len() as f32; let pattern_blocks_usize = pattern_schem.block_data.len();
let pattern_blocks = pattern_blocks_usize as f32;
let i_pattern_blocks = pattern_blocks as i32; let i_pattern_blocks = pattern_blocks as i32;
let pattern_width = pattern_schem.width as usize; let pattern_width = pattern_schem.width as usize;
@ -75,44 +106,75 @@ pub fn search(
let skip_amount = ceil((pattern_blocks * (1.0 - search_behavior.threshold)) as f64, 0) as i32; let skip_amount = ceil((pattern_blocks * (1.0 - search_behavior.threshold)) as f64, 0) as i32;
for y in 0..=schem_height - pattern_height { /*for y in 0..=schem_height - pattern_height {
for z in 0..=schem_length - pattern_length { for z in 0..=schem_length - pattern_length {
for x in 0..=schem_width - pattern_width { for x in 0..=schem_width - pattern_width {
let mut not_matching = 0; let matching_count;
'outer: unsafe {
for j in 0..pattern_height { matching_count = isMatching(
for k in 0..pattern_length { schem_data,
'inner: pattern_data,
for i in 0..pattern_width { pattern_blocks_usize,
let index = (x + i) + schem_width * ((z + k) + (y + j) * schem_length); x,
let pattern_index = i + pattern_width * (k + j * pattern_length); y,
let data = unsafe { *schem_data.add(index) }; z,
let pattern_data = unsafe { *pattern_data.add(pattern_index) }; schem_width,
if (search_behavior.ignore_air && data != *air_id) || (search_behavior.air_as_any && pattern_data != *air_id) { schem_length,
continue 'inner; pattern_width,
} pattern_height,
if data != pattern_data { pattern_length,
not_matching += 1; w_ptr,
if not_matching >= skip_amount { );
break 'outer; };
}
}
}
}
}
if not_matching < skip_amount { if matching_count >= i_pattern_blocks - skip_amount {
matches.push(Match { let percent = matching_count as f32 / pattern_blocks;
x: x as u16, if percent >= search_behavior.threshold {
y: y as u16, matches.push(Match {
z: z as u16, x: x as u16,
percent: (i_pattern_blocks - not_matching) as f32 / pattern_blocks, y: y as u16,
}); z: z as u16,
percent,
});
}
} }
} }
} }
}*/
let mut result = Vec::<i32>::with_capacity(schem_width * schem_height * schem_length);
result.resize(schem_width * schem_height * schem_length, 0);
unsafe {
is_matching_all(
schem_data,
pattern_data,
schem_width,
schem_height,
schem_length,
pattern_width,
pattern_height,
pattern_length,
result.as_mut_ptr()
);
} }
dbg!(result.clone());
result.into_iter().enumerate().filter(|(_, matching_count)| *matching_count >= i_pattern_blocks - skip_amount).for_each(|(i, matching_count)| {
let percent = matching_count as f32 / pattern_blocks;
let x = i % schem_width;
let y = (i / schem_width) % schem_height;
let z = i / (schem_width * schem_height);
matches.push(Match {
x: x as u16,
y: y as u16,
z: z as u16,
percent,
});
});
return matches; return matches;
} }

BIN
tests/Pattern.nbt Normale Datei

Binäre Datei nicht angezeigt.

BIN
tests/Random.nbt Normale Datei

Binäre Datei nicht angezeigt.