2022-05-11 18:06:41 +00:00
|
|
|
#[cfg(not(feature = "worldgen"))]
|
|
|
|
use crate::test_world::{IndexRef, World};
|
2022-05-08 23:53:19 +00:00
|
|
|
use common::lod;
|
|
|
|
use hashbrown::HashMap;
|
|
|
|
use vek::*;
|
2022-05-11 18:06:41 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
|
|
|
use world::{IndexRef, World};
|
2022-05-08 23:53:19 +00:00
|
|
|
|
|
|
|
static EMPTY_ZONE: lod::Zone = lod::Zone {
|
|
|
|
objects: Vec::new(),
|
|
|
|
};
|
|
|
|
|
2022-05-11 18:06:41 +00:00
|
|
|
#[derive(Default)]
|
2022-05-08 23:53:19 +00:00
|
|
|
pub struct Lod {
|
|
|
|
pub zones: HashMap<Vec2<i32>, lod::Zone>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lod {
|
2022-05-11 18:06:41 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
|
|
|
pub fn from_world(world: &World, index: IndexRef) -> Self {
|
2022-05-08 23:53:19 +00:00
|
|
|
let mut zones = HashMap::new();
|
|
|
|
|
|
|
|
let zone_sz = (world.sim().get_size() + lod::ZONE_SIZE - 1) / lod::ZONE_SIZE;
|
|
|
|
|
|
|
|
for i in 0..zone_sz.x {
|
|
|
|
for j in 0..zone_sz.y {
|
|
|
|
let zone_pos = Vec2::new(i, j).map(|e| e as i32);
|
|
|
|
zones.insert(zone_pos, world.get_lod_zone(zone_pos, index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Self { zones }
|
|
|
|
}
|
|
|
|
|
2022-05-11 18:06:41 +00:00
|
|
|
#[cfg(not(feature = "worldgen"))]
|
|
|
|
pub fn from_world(world: &World, index: IndexRef) -> Self { Self::default() }
|
|
|
|
|
2022-05-08 23:53:19 +00:00
|
|
|
pub fn zone(&self, zone_pos: Vec2<i32>) -> &lod::Zone {
|
|
|
|
self.zones.get(&zone_pos).unwrap_or(&EMPTY_ZONE)
|
|
|
|
}
|
|
|
|
}
|