From 31d56ded3fca7a23ff49146f816d8aacef79fd00 Mon Sep 17 00:00:00 2001 From: zomseffen Date: Mon, 26 Aug 2024 20:53:52 +0200 Subject: [PATCH] dumb iterator implemented ith faster hashmap --- Cargo.lock | 7 +++++++ Cargo.toml | 3 ++- src/scene.rs | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf0c4d4..6b5601e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -954,6 +954,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustix" version = "0.38.32" @@ -1218,6 +1224,7 @@ dependencies = [ "png", "pretty_env_logger", "rand", + "rustc-hash", "serde", "thiserror", "tobj", diff --git a/Cargo.toml b/Cargo.toml index f61cfbf..fbdf097 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ tobj = { version = "3", features = ["log"] } vulkanalia = { version = "=0.23.0", features = ["libloading", "provisional", "window"] } winit = "0.29" serde = { version = "1.0", features = ["derive"] } -rand = "0.8" \ No newline at end of file +rand = "0.8" +rustc-hash = "*" \ No newline at end of file diff --git a/src/scene.rs b/src/scene.rs index abc1874..d77c898 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -4,6 +4,7 @@ use anyhow::Result; use cgmath::{vec2, vec3}; use std::collections::HashMap; +use rustc_hash::FxHashMap; use crate::app_data::AppData; use crate::buffer; @@ -13,7 +14,7 @@ use crate::primitives::cube::Cube; extern crate rand; use rand::Rng; -const CHUNK_SIZE: usize = 100; +const CHUNK_SIZE: usize = 500; #[derive(Clone, Debug, Default)] pub struct Scene { @@ -80,12 +81,12 @@ impl Scene { #[derive(Clone, Debug)] struct Chunk { //todo change to hashmap? - blocks: HashMap, Cube>, + blocks: HashMap, Cube, rustc_hash::FxBuildHasher>, } impl Chunk { pub fn create() -> Result { - let mut map = HashMap::new(); + let mut map: HashMap, Cube, rustc_hash::FxBuildHasher> = FxHashMap::default(); Ok(Self { blocks: map })