From 231a5ce21fcee9195fcc504ee672e4464d627c47 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 19 Oct 2025 20:21:27 +0200 Subject: Rename client-lib crate to game-core --- server/client-lib/src/spatial_index.rs | 72 ---------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 server/client-lib/src/spatial_index.rs (limited to 'server/client-lib/src/spatial_index.rs') diff --git a/server/client-lib/src/spatial_index.rs b/server/client-lib/src/spatial_index.rs deleted file mode 100644 index 8dd0cc22..00000000 --- a/server/client-lib/src/spatial_index.rs +++ /dev/null @@ -1,72 +0,0 @@ -/* - Hurry Curry! - a game about cooking - Copyright (C) 2025 Hurry Curry! Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, version 3 of the License only. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -*/ -use hurrycurry_protocol::glam::{IVec2, Vec2, ivec2}; -use std::{collections::HashMap, hash::Hash}; - -pub struct SpatialIndex { - entries: HashMap, - bins: HashMap>, -} - -impl SpatialIndex { - pub fn update_entry(&mut self, id: T, position: Vec2) { - self.remove_entry(id); - self.entries.insert(id, position); - let e = self.bins.entry(position.as_ivec2()).or_default(); - if !e.contains(&id) { - e.push(id); - } - } - pub fn remove_entry(&mut self, id: T) { - if let Some(pos) = self.entries.remove(&id) { - self.bins - .entry(pos.as_ivec2()) - .or_default() - .retain(|e| *e != 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, mut cb: impl FnMut(T, Vec2)) { - let p = position.as_ivec2(); - let r = radius.ceil() as i32; - for xo in -r..=r { - for yo in -r..=r { - if let Some(bin) = self.bins.get(&(p + ivec2(xo, yo))) { - for &id in bin { - let p = *self.entries.get(&id).unwrap(); - if p.distance(position) < radius { - cb(id, p) - } - } - } - } - } - } -} -impl Default for SpatialIndex { - fn default() -> Self { - Self { - entries: Default::default(), - bins: Default::default(), - } - } -} -- cgit v1.3