From a732b2f2f119f3d5cebe683e22d67a0edba6f6a5 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 8 Feb 2020 11:38:44 +0000 Subject: [PATCH] Began work on post-generation town rendering, fixed overflow bug on large maps --- world/src/generator/mod.rs | 20 ++++++++++++++++++-- world/src/generator/settlement/mod.rs | 21 +++++++-------------- world/src/lib.rs | 5 +++++ world/src/sim/mod.rs | 6 +++++- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/world/src/generator/mod.rs b/world/src/generator/mod.rs index 2b92859af5..6c0cfb95c2 100644 --- a/world/src/generator/mod.rs +++ b/world/src/generator/mod.rs @@ -7,8 +7,15 @@ pub use self::{ town::{TownGen, TownState}, }; -use crate::{column::ColumnSample, util::Sampler}; -use common::terrain::Block; +use crate::{ + block::ZCache, + column::ColumnSample, + util::{Grid, Sampler}, +}; +use common::{ + terrain::Block, + vol::{BaseVol, WriteVol}, +}; use std::sync::Arc; use vek::*; @@ -23,6 +30,15 @@ impl Site { Site::Settlement(settlement) => settlement.get_surface(wpos), } } + + pub fn apply_to( + &self, + wpos2d: Vec2, + zcaches: &Grid>, + vol: &mut (impl BaseVol + WriteVol), + ) { + // TODO + } } impl From for Site { diff --git a/world/src/generator/settlement/mod.rs b/world/src/generator/settlement/mod.rs index 74d9929967..f504f9093f 100644 --- a/world/src/generator/settlement/mod.rs +++ b/world/src/generator/settlement/mod.rs @@ -632,30 +632,23 @@ impl PartialEq for Id { } pub struct Store { - items: HashMap, - id_counter: usize, + items: Vec, } impl Default for Store { - fn default() -> Self { - Self { - items: HashMap::new(), - id_counter: 0, - } - } + fn default() -> Self { Self { items: Vec::new() } } } impl Store { - pub fn get(&self, id: Id) -> &T { self.items.get(&id.0).unwrap() } + pub fn get(&self, id: Id) -> &T { self.items.get(id.0).unwrap() } - pub fn get_mut(&mut self, id: Id) -> &mut T { self.items.get_mut(&id.0).unwrap() } + pub fn get_mut(&mut self, id: Id) -> &mut T { self.items.get_mut(id.0).unwrap() } - pub fn iter(&self) -> impl Iterator { self.items.values() } + pub fn iter(&self) -> impl Iterator { self.items.iter() } pub fn insert(&mut self, item: T) -> Id { - self.id_counter += 1; - let id = Id(self.id_counter, PhantomData); - self.items.insert(id.0, item); + let id = Id(self.items.len(), PhantomData); + self.items.push(item); id } } diff --git a/world/src/lib.rs b/world/src/lib.rs index 365c49adaa..d69a3bce6f 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -136,6 +136,11 @@ impl World { } } + sim_chunk + .sites + .iter() + .for_each(|site| site.apply_to(chunk_wpos2d, &zcache_grid, &mut chunk)); + let gen_entity_pos = || { let lpos2d = TerrainChunkSize::RECT_SIZE .map(|sz| rand::thread_rng().gen::().rem_euclid(sz)); diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index e21efd45a1..f0de053a28 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1478,7 +1478,11 @@ impl WorldSim { if let Some((pos, site)) = sites .iter() - .filter(|(pos, _)| pos.distance_squared(wpos) < 1200i32.pow(2)) + .filter(|(pos, _)| { + pos.map(|e| e as i64) + .distance_squared(wpos.map(|e| e as i64)) + < 1200i64.pow(2) + }) .min_by_key(|(pos, _)| wpos.distance_squared(*pos)) { chunk.sites.push(site.clone());