1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![doc(html_logo_url = "https://raw.githubusercontent.com/lowenware/dotrix/master/logo.png")]
#![warn(missing_docs)]
use std::any::Any;
use dotrix_core::{ Application, Id, System };
use dotrix_core::assets::Mesh;
mod generator;
mod services;
mod systems;
mod layers;
pub use generator::{ Falloff, Generator, Noise };
pub use services::Terrain;
pub use systems::{ startup, render, spawn };
pub use layers::{ Layers, Layer };
pub struct Tile {
pub x: i32,
pub z: i32,
pub lod: usize,
pub mesh: Id<Mesh>,
pub loaded: bool,
}
pub trait Heightmap: Any + Sync + Send {
fn value(&self, x: usize, z: usize) -> f32;
fn size(&self) -> usize;
}
impl dyn Heightmap {
#[inline]
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
if self.is::<T>() {
unsafe { Some(&*(self as *const dyn Heightmap as *const T)) }
} else {
None
}
}
#[inline]
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
unsafe { Some(&mut *(self as *mut dyn Heightmap as *mut T)) }
} else {
None
}
}
#[inline]
fn is<T: Any>(&self) -> bool {
std::any::TypeId::of::<T>() == self.type_id()
}
}
pub fn extension(app: &mut Application) {
app.add_system(System::from(startup));
app.add_system(System::from(spawn));
app.add_system(System::from(render));
app.add_service(Terrain::default());
}