From 2a31d26fca33789ccf8ea28cdb214d20dd29f85d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 18 Jul 2024 12:39:33 +0200 Subject: serve-authorative movement --- server/src/spatial_index.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 server/src/spatial_index.rs (limited to 'server/src/spatial_index.rs') 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 { + entries: HashMap, +} + +impl SpatialIndex { + 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 Default for SpatialIndex { + fn default() -> Self { + Self { + entries: Default::default(), + } + } +} -- cgit v1.2.3-70-g09d2