summaryrefslogtreecommitdiff
path: root/server/src/spatial_index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/spatial_index.rs')
-rw-r--r--server/src/spatial_index.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/server/src/spatial_index.rs b/server/src/spatial_index.rs
new file mode 100644
index 00000000..4395f0f5
--- /dev/null
+++ b/server/src/spatial_index.rs
@@ -0,0 +1,31 @@
+use hurrycurry_protocol::glam::Vec2;
+use std::{collections::HashMap, hash::Hash};
+
+// TODO stub implementation. please implement
+pub struct SpatialIndex<T> {
+ entries: HashMap<T, Vec2>,
+}
+
+impl<T: Eq + Hash + Copy> SpatialIndex<T> {
+ pub fn update_entry(&mut self, id: T, position: Vec2) {
+ self.entries.insert(id, position);
+ }
+ pub fn remove_entry(&mut self, id: T) {
+ self.entries.remove(&id);
+ }
+ pub fn all(&self, mut cb: impl FnMut(T, Vec2)) {
+ for (&e, &pos) in &self.entries {
+ cb(e, pos)
+ }
+ }
+ pub fn query(&self, _position: Vec2, _radius: f32, cb: impl FnMut(T, Vec2)) {
+ self.all(cb)
+ }
+}
+impl<T> Default for SpatialIndex<T> {
+ fn default() -> Self {
+ Self {
+ entries: Default::default(),
+ }
+ }
+}