Sort atoms by plane, then layer

This commit is contained in:
Damian 2018-09-10 20:09:06 +02:00
parent d2770a035c
commit 4f9bab6a43
2 changed files with 18 additions and 1 deletions

View file

@ -112,7 +112,13 @@ impl MapRenderer {
let midpoint = ::std::time::Instant::now();
// z sort - TODO: use depth buffer instead?
atoms.sort_by_key(|a| minimap::layer_of(objtree, a));
atoms.sort_by(|a, b| {
match minimap::plane_of(objtree, a).cmp(&minimap::plane_of(objtree, b)) {
::std::cmp::Ordering::Equal => minimap::layer_of(objtree, a).cmp(&minimap::layer_of(objtree, b)),
other => other
}
});
// render atoms
let mut vertices = Vec::new();

View file

@ -400,6 +400,17 @@ fn fancy_layer_of(objtree: &ObjectTree, atom: &Atom) -> i32 {
}
}
pub fn plane_of(objtree: &ObjectTree, atom: &Atom) -> i32 {
match atom.get_var("plane", objtree) {
&Constant::Int(i) => (i % 1000) * 1000,
&Constant::Float(f) => ((f % 1000.) * 1000.) as i32,
other => {
eprintln!("not a plane: {:?} on {:?}", other, atom.type_.path);
2_000
}
}
}
pub fn layer_of(objtree: &ObjectTree, atom: &Atom) -> i32 {
match atom.get_var("layer", objtree) {
&Constant::Int(i) => (i % 1000) * 1000,