dumb iterator implemented ith faster hashmap

This commit is contained in:
zomseffen 2024-08-26 20:53:52 +02:00
parent 7879e57275
commit 31d56ded3f
3 changed files with 13 additions and 4 deletions

7
Cargo.lock generated
View file

@ -954,6 +954,12 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.32" version = "0.38.32"
@ -1218,6 +1224,7 @@ dependencies = [
"png", "png",
"pretty_env_logger", "pretty_env_logger",
"rand", "rand",
"rustc-hash",
"serde", "serde",
"thiserror", "thiserror",
"tobj", "tobj",

View file

@ -16,4 +16,5 @@ tobj = { version = "3", features = ["log"] }
vulkanalia = { version = "=0.23.0", features = ["libloading", "provisional", "window"] } vulkanalia = { version = "=0.23.0", features = ["libloading", "provisional", "window"] }
winit = "0.29" winit = "0.29"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
rand = "0.8" rand = "0.8"
rustc-hash = "*"

View file

@ -4,6 +4,7 @@ use anyhow::Result;
use cgmath::{vec2, vec3}; use cgmath::{vec2, vec3};
use std::collections::HashMap; use std::collections::HashMap;
use rustc_hash::FxHashMap;
use crate::app_data::AppData; use crate::app_data::AppData;
use crate::buffer; use crate::buffer;
@ -13,7 +14,7 @@ use crate::primitives::cube::Cube;
extern crate rand; extern crate rand;
use rand::Rng; use rand::Rng;
const CHUNK_SIZE: usize = 100; const CHUNK_SIZE: usize = 500;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct Scene { pub struct Scene {
@ -80,12 +81,12 @@ impl Scene {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct Chunk { struct Chunk {
//todo change to hashmap? //todo change to hashmap?
blocks: HashMap<cgmath::Vector3<u32>, Cube>, blocks: HashMap<cgmath::Vector3<u32>, Cube, rustc_hash::FxBuildHasher>,
} }
impl Chunk { impl Chunk {
pub fn create() -> Result<Self> { pub fn create() -> Result<Self> {
let mut map = HashMap::new(); let mut map: HashMap<cgmath::Vector3<u32>, Cube, rustc_hash::FxBuildHasher> = FxHashMap::default();
Ok(Self { Ok(Self {
blocks: map blocks: map
}) })