diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-18 12:39:33 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-18 12:39:33 +0200 |
commit | 2a31d26fca33789ccf8ea28cdb214d20dd29f85d (patch) | |
tree | 426faa4d55905ecacdb9a1a4beca6d5a1ab97953 /server/src/spatial_index.rs | |
parent | c4ae8c2df44cac2a8b3e4c8db43c2870b7d2bf69 (diff) | |
download | hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.bz2 hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.zst |
serve-authorative movement
Diffstat (limited to 'server/src/spatial_index.rs')
-rw-r--r-- | server/src/spatial_index.rs | 31 |
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(), + } + } +} |