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
86
87
88
89
90
use std::collections::HashMap;
pub use navmesh::*;
#[derive(Debug, Default)]
pub struct NavMeshesRes(pub(crate) HashMap<NavMeshID, NavMesh>);
impl NavMeshesRes {
#[inline]
pub fn register(&mut self, mesh: NavMesh) -> NavMeshID {
let id = mesh.id();
self.0.insert(id, mesh);
id
}
#[inline]
pub fn unregister(&mut self, id: NavMeshID) -> Option<NavMesh> {
self.0.remove(&id)
}
#[inline]
pub fn unregister_all(&mut self) {
self.0.clear()
}
#[inline]
pub fn meshes_iter(&self) -> impl Iterator<Item = &NavMesh> {
self.0.values()
}
#[inline]
pub fn find_mesh(&self, id: NavMeshID) -> Option<&NavMesh> {
self.0.get(&id)
}
#[inline]
pub fn find_mesh_mut(&mut self, id: NavMeshID) -> Option<&mut NavMesh> {
self.0.get_mut(&id)
}
pub fn closest_point(&self, point: NavVec3, query: NavQuery) -> Option<(NavMeshID, NavVec3)> {
self.0
.iter()
.filter_map(|(id, mesh)| {
mesh.closest_point(point, query)
.map(|p| (p, (p - point).sqr_magnitude(), *id))
})
.min_by(|a, b| a.1.partial_cmp(&b.1).unwrap())
.map(|(p, _, id)| (id, p))
}
}