Skip to content

Commit

Permalink
- added serde-like indexing of elements for no reason yet
Browse files Browse the repository at this point in the history
- changed minimum dimensions for texture to 4096 to support more devices
- updated msrv to 1.80.0
  • Loading branch information
RealRTTV committed May 24, 2024
1 parent b73c665 commit afe9e8a
Show file tree
Hide file tree
Showing 13 changed files with 455 additions and 117 deletions.
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nbtworkbench"
version = "1.3.0"
version = "1.3.1"
edition = "2021"
description = "A modern NBT Editor written in Rust designed for performance and efficiency."
license-file = "LICENSE"
Expand Down Expand Up @@ -50,22 +50,23 @@ winres = "0.1.12"

[dependencies]
zune-inflate = { version = "0.2.54", features = ["gzip", "zlib"] }
flate2 = "1.0.27"
winit = "0.29.10"
wgpu = { version = "=0.19.1", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] }
flate2 = "1.0.28"
winit = "0.29.15"
wgpu = { version = "=0.19.4", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] }
fxhash = "0.2.1"
hashbrown = { version = "0.14.0", features = ["raw", "inline-more", "nightly"], default-features = false }
getrandom = { version = "0.2.12", features = ["js"] }
notify = "6.0.1"
uuid = { version = "1.4.1", features = ["v4"] }
hashbrown = { version = "0.14.3", features = ["raw", "inline-more", "nightly"], default-features = false }
getrandom = { version = "0.2.14", features = ["js"] }
notify = "6.1.1"
uuid = { version = "1.8.0", features = ["v4"] }
compact_str = "0.7.1"
wgsl-inline = { version = "0.2.0", features = ["minify"] }
static_assertions = "1.1.0"
anyhow = "1.0.79"
lz4_flex = { version = "0.11.2", default-features = false, features = ["std", "nightly"] }
regex = "1.10.3"
anyhow = "1.0.82"
lz4_flex = { version = "0.11.3", default-features = false, features = ["std", "nightly"] }
regex = "1.10.4"
glob = "0.3.1"
zune-png = { version = "0.4.10", features = [] }
polonius-the-crab = "0.4.1"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.9", features = [] }
Expand All @@ -78,4 +79,4 @@ native-dialog = "0.7.0"
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.91"
wasm-bindgen-futures = "0.4.41"
web-sys = { version = "=0.3.67", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url"] }
web-sys = { version = "=0.3.69", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url"] }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ however, it would not come to be without the lovely projects below inspiring it.

# Compiling
### For Windows
* You must have [Rust](https://rustup.rs) 1.78.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* You must have [Rust](https://rustup.rs) 1.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* Uncomment the windows-only section of your `Cargo.toml` file and make sure the other sections are commented out.
* Run the following command to make a release build in `./target/x86_64-pc-windows-msvc/release`:\
`cargo +nightly build --release --target x86_64-pc-windows-msvc -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort -- -Ctarget-feature=+avx`
### For Wasm
* You must have [Rust](https://rustup.rs) 1.78.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* You must have [Rust](https://rustup.rs) 1.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* You must have [wasm-pack](https://crates.io/crates/wasm-pack) installed using cargo
* Uncomment the wasm-only section of your `Cargo.toml` file and make sure the other sections are commented out.
* Run the following command to compile for web assembly in `./web`:\
Expand Down
2 changes: 2 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub const RENAME_TAIL_UV: Vec2u = Vec2u::new(32, 112);
pub const MOVE_TAIL_UV: Vec2u = Vec2u::new(48, 112);
pub const REPLACE_TAIL_UV: Vec2u = Vec2u::new(64, 112);
pub const REORDER_TAIL_UV: Vec2u = Vec2u::new(80, 112);
pub const BULK_UV: Vec2u = Vec2u::new(240, 240);
pub const BULK_TAIL_UV: Vec2u = Vec2u::new(240, 240);
pub const UNDO_UV: Vec2u = Vec2u::new(32, 144);
pub const REDO_UV: Vec2u = Vec2u::new(48, 144);
pub const LINE_NUMBER_SEPARATOR_UV: Vec2u = Vec2u::new(60, 64);
Expand Down
4 changes: 2 additions & 2 deletions src/element_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use compact_str::CompactString;
use notify::{EventKind, PollWatcher, RecursiveMode, Watcher};
use uuid::Uuid;

use crate::{panic_unchecked, set_clipboard, FileUpdateSubscription, StrExt};
use crate::{panic_unchecked, set_clipboard, FileUpdateSubscription};
#[cfg(not(target_arch = "wasm32"))]
use crate::{FileUpdateSubscriptionType, assets::{OPEN_ARRAY_IN_HEX_UV, OPEN_IN_TXT}, since_epoch};
use crate::{FileUpdateSubscriptionType, assets::{OPEN_ARRAY_IN_HEX_UV, OPEN_IN_TXT}, since_epoch, StrExt};
use crate::assets::{ACTION_WHEEL_Z, COPY_FORMATTED_UV, COPY_RAW_UV, SORT_COMPOUND_BY_NAME, SORT_COMPOUND_BY_TYPE};
use crate::elements::chunk::NbtChunk;
use crate::elements::compound::NbtCompound;
Expand Down
36 changes: 13 additions & 23 deletions src/elements/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ impl NbtRegion {

#[must_use]
pub fn from_be_bytes(bytes: &[u8], sort: SortAlgorithm) -> Option<Self> {
fn parse(raw: u32, bytes: &[u8], sort: SortAlgorithm) -> Option<(FileFormat, NbtElement)> {
if raw < 512 { return Some((FileFormat::Zlib, unsafe { core::mem::zeroed() })) }
fn parse(raw: u32, bytes: &[u8], sort: SortAlgorithm) -> Option<(FileFormat, Option<NbtCompound>)> {
if raw < 512 { return Some((FileFormat::Zlib, None)) }

let len = (raw as usize & 0xFF) * 4096;
let offset = ((raw >> 8) - 2) as usize * 4096;
Expand Down Expand Up @@ -128,11 +128,11 @@ impl NbtRegion {
4 => (FileFormat::Lz4, NbtElement::from_be_file(&lz4_flex::decompress(data, data.len()).ok()?, sort)?),
_ => return None,
};
if element.id() != NbtCompound::ID { return None }
Some((compression, element))
} else {
None
if let Some(element) = element.into_compound() {
return Some((compression, Some(element)));
}
}
None
}

if bytes.len() < 8192 { return None }
Expand All @@ -155,23 +155,19 @@ impl NbtRegion {
threads.push((timestamp, s.spawn(move || parse(offset, bytes, sort))));
}


for (pos, (timestamp, thread)) in threads.into_iter().enumerate() {
let mut pos = 0;
for (timestamp, thread) in threads {
let (format, element) = thread.join().ok()??;
if element.id() == NbtCompound::ID {
if let Some(element) = element {
unsafe {
region.insert_unchecked(
pos,
region.len(),
NbtElement::Chunk(NbtChunk::from_compound(
core::mem::transmute(element),
((pos >> 5) as u8 & 31, pos as u8 & 31),
format,
timestamp,
)),
NbtElement::Chunk(NbtChunk::from_compound(element, ((pos >> 5) as u8 & 31, pos as u8 & 31), format, timestamp, )),
);
}
}
pos += 1;
}

Some(region)
Expand All @@ -198,20 +194,14 @@ impl NbtRegion {

for (pos, (timestamp, thread)) in threads.into_iter().enumerate() {
let (format, element) = thread?;
if element.id() == NbtCompound::ID {
if let Some(element) = element {
unsafe {
region.insert_unchecked(
pos,
region.len(),
NbtElement::Chunk(NbtChunk::from_compound(
core::mem::transmute_copy(&element),
((pos >> 5) as u8 & 31, pos as u8 & 31),
format,
timestamp,
)),
NbtElement::Chunk(NbtChunk::from_compound(element, ((pos >> 5) as u8 & 31, pos as u8 & 31), format, timestamp, )),
);
}
core::mem::forget(element);
}
}

Expand Down
Loading

0 comments on commit afe9e8a

Please sign in to comment.