Began work on post-generation town rendering, fixed overflow bug on large maps

This commit is contained in:
Joshua Barretto 2020-02-08 11:38:44 +00:00
parent 0021bd6452
commit 085a115e2b
4 changed files with 35 additions and 17 deletions

View File

@ -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<i32>,
zcaches: &Grid<Option<ZCache>>,
vol: &mut (impl BaseVol<Vox = Block> + WriteVol),
) {
// TODO
}
}
impl From<Settlement> for Site {

View File

@ -632,30 +632,23 @@ impl<T> PartialEq for Id<T> {
}
pub struct Store<T> {
items: HashMap<usize, T>,
id_counter: usize,
items: Vec<T>,
}
impl<T> Default for Store<T> {
fn default() -> Self {
Self {
items: HashMap::new(),
id_counter: 0,
}
}
fn default() -> Self { Self { items: Vec::new() } }
}
impl<T> Store<T> {
pub fn get(&self, id: Id<T>) -> &T { self.items.get(&id.0).unwrap() }
pub fn get(&self, id: Id<T>) -> &T { self.items.get(id.0).unwrap() }
pub fn get_mut(&mut self, id: Id<T>) -> &mut T { self.items.get_mut(&id.0).unwrap() }
pub fn get_mut(&mut self, id: Id<T>) -> &mut T { self.items.get_mut(id.0).unwrap() }
pub fn iter(&self) -> impl Iterator<Item = &T> { self.items.values() }
pub fn iter(&self) -> impl Iterator<Item = &T> { self.items.iter() }
pub fn insert(&mut self, item: T) -> Id<T> {
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
}
}

View File

@ -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::<u32>().rem_euclid(sz));

View File

@ -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());