Skip to content

Commit

Permalink
updated libs
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRTTV committed Dec 17, 2024
1 parent 3570685 commit 29662c1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 76 deletions.
21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,20 @@ winres = "0.1.12"
zune-inflate = { version = "0.2.54", features = ["gzip", "zlib"] }
flate2 = "1.0.31"
winit = "0.30.5"
wgpu = { version = "22.1.0", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] }
wgpu = { version = "23.0.1", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] }
fxhash = "0.2.1"
hashbrown = { version = "0.14.5", features = ["raw", "inline-more", "nightly"], default-features = false }
getrandom = { version = "0.2.15", features = ["js"] }
notify = "6.1.1"
hashbrown = { version = "0.15.2", features = ["inline-more", "nightly"], default-features = false }
notify = "7.0.0"
uuid = { version = "1.10.0", features = ["v4"] }
compact_str = "0.8.0"
wgsl-inline = { version = "0.2.1", features = ["minify"] }
static_assertions = "1.1.0"
anyhow = "1.0.86"
anyhow = "1.0.94"
lz4_flex = { version = "0.11.3", default-features = false, features = ["std", "nightly"] }
regex = "1.10.6"
regex = "1.11.1"
glob = "0.3.1"
zune-png = { version = "0.4.10", features = [] }
polonius-the-crab = "0.4.1"
polonius-the-crab = "0.4.2"
enum-map = "3.0.0-beta.2"
parking_lot = "0.12.3"

Expand All @@ -75,11 +74,11 @@ winapi = { version = "0.3.9", features = ["wincon"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
cli-clipboard = "0.4.0"
pollster = "0.3.0"
pollster = "0.4.0"
native-dialog = "0.7.0"
dirs = "5.0.1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.91"
wasm-bindgen-futures = "0.4.41"
web-sys = { version = "=0.3.69", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url", "Storage"] }
wasm-bindgen = "0.2.99"
wasm-bindgen-futures = "0.4.49"
web-sys = { version = "0.3.72", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url", "Storage"] }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,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.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* You must have [Rust](https://rustup.rs) 1.85.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`
### For Wasm
* You must have [Rust](https://rustup.rs) 1.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc)
* You must have [Rust](https://rustup.rs) 1.85.0+ \[Nightly\]
* 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
93 changes: 44 additions & 49 deletions src/elements/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::ops::Deref;
use std::thread::Scope;

use compact_str::{CompactString, format_compact, ToCompactString};
use hashbrown::raw::RawTable;
use hashbrown::hash_table::Entry::*;
use hashbrown::hash_table::HashTable;

use crate::{config, hash, width_ascii, DropFn, NbtElementAndKey, RenderContext, StrExt, VertexBufferBuilder};
use crate::assets::{BASE_Z, COMPOUND_ROOT_UV, COMPOUND_UV, CONNECTION_UV, HEADER_SIZE, JUST_OVERLAPPING_BASE_TEXT_Z, LINE_NUMBER_CONNECTOR_Z, LINE_NUMBER_SEPARATOR_UV, ZOffset};
Expand Down Expand Up @@ -752,7 +753,7 @@ impl NbtCompound {
// Based on indexmap, but they didn't let me clone with unchecked mem stuff
#[allow(clippy::module_name_repetitions)]
pub struct CompoundMap {
pub indices: RawTable<usize>,
pub indices: HashTable<usize>,
pub entries: Vec<Entry>,
}

Expand Down Expand Up @@ -787,13 +788,8 @@ impl Clone for CompoundMap {
}

unsafe {
let mut table = RawTable::try_with_capacity(self.indices.len()).unwrap_unchecked();
for (idx, bucket) in self.indices.iter().enumerate() {
let hash = hash!(self.entries.get_unchecked(idx).key);
let _ = table.insert_in_slot(hash, core::mem::transmute(idx), *bucket.as_ref());
}
Self {
indices: table,
indices: HashTable::clone(&self.indices),
entries: clone_entries(&self.entries),
}
}
Expand All @@ -810,7 +806,7 @@ pub struct Entry {
impl Default for CompoundMap {
fn default() -> Self {
Self {
indices: RawTable::new(),
indices: HashTable::new(),
entries: Vec::new(),
}
}
Expand All @@ -826,7 +822,7 @@ impl CompoundMap {
#[must_use]
pub fn idx_of(&self, key: &str) -> Option<usize> {
self.indices
.get(hash!(key), |&idx| unsafe { self.entries.get_unchecked(idx).key.as_str() == key })
.find(hash!(key), |&idx| unsafe { self.entries.get_unchecked(idx).key.as_str() == key })
.copied()
}

Expand All @@ -844,9 +840,9 @@ impl CompoundMap {
pub fn insert_full(&mut self, key: CompactString, element: NbtElement) -> (usize, Option<NbtElement>) {
unsafe {
let hash = hash!(key);
match self.indices.find_or_find_insert_slot(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key), ) {
Ok(bucket) => {
let idx = *bucket.as_ref();
match self.indices.entry(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) {
Occupied(entry) => {
let idx = *entry.get();
(
idx,
Some(core::mem::replace(
Expand All @@ -855,7 +851,7 @@ impl CompoundMap {
)),
)
}
Err(slot) => {
Vacant(slot) => {
let len = self.entries.len();
self.entries.try_reserve(1).unwrap_unchecked();
self.entries.as_mut_ptr().add(len).write(Entry {
Expand All @@ -864,7 +860,7 @@ impl CompoundMap {
additional: 0,
});
self.entries.set_len(len + 1);
self.indices.insert_in_slot(hash, slot, len);
slot.insert(len);
(len, None)
}
}
Expand All @@ -874,9 +870,9 @@ impl CompoundMap {
pub fn insert_at(&mut self, key: CompactString, element: NbtElement, idx: usize) -> Option<(CompactString, NbtElement)> {
unsafe {
let hash = hash!(key);
let (prev, end, bucket) = match self.indices.find_or_find_insert_slot(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) {
Ok(bucket) => {
let before = core::mem::replace(bucket.as_mut(), idx);
let (prev, end, ptr) = match self.indices.entry(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) {
Occupied(mut entry) => {
let before = core::mem::replace(entry.get_mut(), idx);
let Entry {
key: k, value: v, ..
} = self.entries.remove(before);
Expand All @@ -888,9 +884,9 @@ impl CompoundMap {
additional: 0,
},
);
(Some((k, v)), before, bucket)
(Some((k, v)), before, entry.get_mut() as *mut usize)
}
Err(slot) => {
Vacant(slot) => {
let len = self.entries.len();
self.entries.try_reserve_exact(1).unwrap_unchecked();
let ptr = self.entries.as_mut_ptr().add(idx);
Expand All @@ -901,32 +897,32 @@ impl CompoundMap {
additional: 0,
});
self.entries.set_len(len + 1);
let bucket = self.indices.insert_in_slot(hash, slot, idx);
(None, len, bucket)
let mut entry = slot.insert(len);
(None, len, entry.get_mut() as *mut usize)
}
};

match idx.cmp(&end) {
Ordering::Less => {
for index in self.indices.iter() {
let value = *index.as_ref();
for index in self.indices.iter_mut() {
let value = *index;
if value >= idx && value <= end {
*index.as_mut() += 1;
*index += 1;
}
}
}
Ordering::Equal => {}
Ordering::Greater => {
for index in self.indices.iter() {
let value = *index.as_ref();
for index in self.indices.iter_mut() {
let value = *index;
if value <= idx && value >= end {
*index.as_mut() -= 1;
*index -= 1;
}
}
}
}

*bucket.as_mut() = idx;
*ptr = idx;

prev
}
Expand All @@ -940,18 +936,28 @@ impl CompoundMap {
pub unsafe fn update_key_idx_unchecked(&mut self, idx: usize, key: CompactString) -> CompactString {
let new_hash = hash!(key);
let old_key = core::mem::replace(&mut self.entries.get_unchecked_mut(idx).key, key);
self.indices.remove_entry(hash!(old_key), |&target_idx| target_idx == idx).unwrap_unchecked();
self.indices.insert(new_hash, idx, |&idx| hash!(self.entries.get_unchecked(idx).key));
if let Ok(entry) = self.indices.find_entry(hash!(old_key), |&target_idx| target_idx == idx) {
entry.remove();
} else {
// should **never** happen
core::hint::unreachable_unchecked();
}
self.indices.insert_unique(new_hash, idx, |&idx| hash!(self.entries.get_unchecked(idx).key));
old_key
}

pub fn shift_remove_idx(&mut self, idx: usize) -> Option<(CompactString, NbtElement)> {
if idx > self.entries.len() { return None }
unsafe {
self.indices.remove_entry(hash!(self.entries.get_unchecked(idx).key), |&found_idx| found_idx == idx);
for bucket in self.indices.iter() {
if *bucket.as_ref() > idx {
*bucket.as_mut() -= 1;
if let Ok(entry) = self.indices.find_entry(hash!(self.entries.get_unchecked(idx).key), |&found_idx| found_idx == idx) {
entry.remove();
} else {
// should **never** happen
core::hint::unreachable_unchecked();
}
for entry in self.indices.iter_mut() {
if *entry > idx {
*entry -= 1;
}
}
}
Expand All @@ -960,25 +966,14 @@ impl CompoundMap {
Some((key, value))
}

pub fn swap_remove_idx(&mut self, idx: usize) -> Option<(CompactString, NbtElement)> {
if idx > self.entries.len() { return None }
let Entry { key, value, .. } = self.entries.swap_remove(idx);
let hash = hash!(key);
unsafe {
let tail = self.indices.remove_entry(hash, |&idx| idx + 1 == self.entries.len()).unwrap_unchecked();
*self.indices.get_mut(hash, |&idx| self.entries.get_unchecked(idx).key == key).unwrap_unchecked() = tail;
}
Some((key, value))
}

pub fn swap(&mut self, a: usize, b: usize) {
if a >= self.entries.len() || b >= self.entries.len() { return; }
unsafe {
let a_hash = hash!(self.entries.get_unchecked(a).key);
let b_hash = hash!(self.entries.get_unchecked(b).key);
self.entries.swap(a, b);
let a = self.indices.get_mut(a_hash, |&idx| idx == a).unwrap_unchecked() as *mut usize;
let b = self.indices.get_mut(b_hash, |&idx| idx == b).unwrap_unchecked() as *mut usize;
let a = self.indices.find_mut(a_hash, |&idx| idx == a).unwrap_unchecked() as *mut usize;
let b = self.indices.find_mut(b_hash, |&idx| idx == b).unwrap_unchecked() as *mut usize;
core::ptr::swap(a, b);
}
}
Expand Down Expand Up @@ -1018,7 +1013,7 @@ impl CompoundMap {
// SAFETY: these indices are valid since the length did not change and since the values written were indexes
unsafe {
let entry = self.entries.get_unchecked_mut(new_idx);
*self.indices.find(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists").as_mut() = new_idx;
*self.indices.find_mut(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists") = new_idx;

let true_line_number = *true_line_numbers.get_unchecked(idx);
let line_number = *line_numbers.get_unchecked(idx);
Expand Down
8 changes: 4 additions & 4 deletions src/elements/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::slice::{Iter, IterMut};
use std::thread::Scope;

use compact_str::{CompactString, format_compact, ToCompactString};
use hashbrown::raw::RawTable;
use hashbrown::HashTable;
use polonius_the_crab::{polonius, polonius_return};

use crate::{array, assets::JUST_OVERLAPPING_BASE_TEXT_Z, DropFn, primitive, RenderContext, since_epoch, StrExt, TextColor, VertexBufferBuilder, NbtElementAndKey, width_ascii};
Expand Down Expand Up @@ -1592,7 +1592,7 @@ impl Drop for NbtElement {
NbtCompound::ID => {
let map = &mut *self.compound.entries;
let CompoundMap { indices, entries } = map;
(indices as *mut RawTable<usize>).drop_in_place();
(indices as *mut HashTable<usize>).drop_in_place();
for Entry { value, key, .. } in &mut *entries {
(value as *mut Self).drop_in_place();
if key.is_heap_allocated() {
Expand All @@ -1616,7 +1616,7 @@ impl Drop for NbtElement {
NbtChunk::ID => {
let map = &mut *self.chunk.entries;
let CompoundMap { indices, entries } = map;
(indices as *mut RawTable<usize>).drop_in_place();
(indices as *mut HashTable<usize>).drop_in_place();
for Entry { value, key, .. } in &mut *entries {
(value as *mut Self).drop_in_place();
if key.is_heap_allocated() {
Expand Down Expand Up @@ -1644,7 +1644,7 @@ impl Drop for NbtElement {
let ptr = &mut **chunk.as_chunk_unchecked_mut();
let map = &mut *ptr.entries;
let CompoundMap { indices, entries } = map;
(indices as *mut RawTable<usize>).drop_in_place();
(indices as *mut HashTable<usize>).drop_in_place();
for Entry { value, key, .. } in &mut *entries {
(value as *mut Self).drop_in_place();
if key.is_heap_allocated() {
Expand Down
8 changes: 3 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
#![feature(
array_chunks,
box_patterns,
const_collections_with_hasher,
core_intrinsics,
iter_array_chunks,
iter_next_chunk,
lazy_cell,
let_chains,
optimize_attribute,
panic_update_hook,
stmt_expr_attributes,
float_next_up_down,
variant_count,
sync_unsafe_cell,
duration_millis_float
duration_millis_float,
let_chains
)]
#![windows_subsystem = "windows"]

Expand Down Expand Up @@ -656,7 +654,7 @@ impl SortAlgorithm {
// SAFETY: these indices are valid since the length did not change and since the values written were indexes
unsafe {
let entry = map.entries.get_unchecked_mut(new_idx);
*map.indices.find(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists").as_mut() = new_idx;
*map.indices.find_mut(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists") = new_idx;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'window> State<'window> {
layout: Some(&render_pipeline_layout),
vertex: VertexState {
module: &shader,
entry_point: "vertex",
entry_point: Some("vertex"),
compilation_options: Default::default(),
buffers: &[VertexBufferLayout {
array_stride: 20,
Expand All @@ -309,7 +309,7 @@ impl<'window> State<'window> {
},
fragment: Some(FragmentState {
module: &shader,
entry_point: "fragment",
entry_point: Some("fragment"),
compilation_options: Default::default(),
targets: &[Some(ColorTargetState {
format: config.format,
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<'window> State<'window> {
layout: Some(&text_render_pipeline_layout),
vertex: VertexState {
module: &text_shader,
entry_point: "vertex",
entry_point: Some("vertex"),
compilation_options: Default::default(),
buffers: &[VertexBufferLayout {
array_stride: 16,
Expand All @@ -415,7 +415,7 @@ impl<'window> State<'window> {
},
fragment: Some(FragmentState {
module: &text_shader,
entry_point: "fragment",
entry_point: Some("fragment"),
compilation_options: Default::default(),
targets: &[Some(ColorTargetState {
format: config.format,
Expand Down
2 changes: 1 addition & 1 deletion src/workbench_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl WorkbenchAction {
let mut current_true_line_number = true_line_number + 1;
for (idx, &new_idx) in reordering_indices.iter().enumerate() {
let entry = core::mem::replace(previous_entries.get_unchecked_mut(new_idx), MaybeUninit::uninit()).assume_init();
*indices.find(hash!(entry.key), |&x| x == new_idx).expect("index obviously exists").as_mut() = idx;
*indices.find_mut(hash!(entry.key), |&x| x == new_idx).expect("index obviously exists") = idx;
let line_number = *line_numbers.get_unchecked(new_idx);
let true_line_number = *true_line_numbers.get_unchecked(new_idx);
let height = entry.value.height();
Expand Down

0 comments on commit 29662c1

Please sign in to comment.