veloren_common/
lod.rs

1use crate::{terrain::TerrainChunkSize, vol::RectVolSize};
2use serde::{Deserialize, Serialize};
3use strum::EnumIter;
4use vek::*;
5
6// In chunks
7pub const ZONE_SIZE: u32 = 32;
8
9bitflags::bitflags! {
10    #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
11    pub struct InstFlags: u8 {
12        const SNOW_COVERED  = 0b00000001;
13        const GLOW          = 0b00000010;
14        /// Rotate half pi radians (90 degrees)
15        const ROTATE_HALF_PI = 0b00000100;
16        /// Rotate pi radians (180 degrees)
17        const ROTATE_PI      = 0b00001000;
18    }
19}
20
21#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug, Serialize, Deserialize, EnumIter)]
22#[repr(u16)]
23pub enum ObjectKind {
24    GenericTree,
25    Pine,
26    Dead,
27    House,
28    GiantTree,
29    Mangrove,
30    Acacia,
31    Birch,
32    Redwood,
33    Baobab,
34    Frostpine,
35    Haniwa,
36    Desert,
37    Palm,
38    Arena,
39    SavannahHut,
40    SavannahAirshipDock,
41    TerracottaPalace,
42    TerracottaHouse,
43    TerracottaYard,
44    AirshipDock,
45    CoastalHouse,
46    CoastalWorkshop,
47}
48
49#[derive(Clone, Debug, Serialize, Deserialize)]
50pub struct Object {
51    pub kind: ObjectKind,
52    pub pos: Vec3<i16>,
53    pub flags: InstFlags,
54    pub color: Rgb<u8>,
55}
56
57#[derive(Clone, Debug, Serialize, Deserialize)]
58pub struct Zone {
59    pub objects: Vec<Object>,
60}
61
62pub fn to_wpos(wpos: i32) -> i32 { wpos * (TerrainChunkSize::RECT_SIZE.x * ZONE_SIZE) as i32 }
63
64pub fn from_wpos(zone_pos: i32) -> i32 {
65    zone_pos.div_euclid((TerrainChunkSize::RECT_SIZE.x * ZONE_SIZE) as i32)
66}