diff options
Diffstat (limited to 'src/map.rs')
-rw-r--r-- | src/map.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/map.rs b/src/map.rs index f977bec93e1d..212ce75100ad 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1,31 +1,42 @@ //! Implements a map graph and world logic use crate::{ - data::{Link, Node}, - server::{ServerResult, ServerErr}, - wire::Response + config::{LinkCfg, MapCfg, NodeCfg}, + data::{Link, Node, NodeId}, + server::{ServerErr, ServerResult}, + wire::Response, }; use async_std::sync::Arc; -use serde::{Deserialize, Serialize}; +use quadtree_rs::Quadtree; use std::collections::BTreeMap; +pub struct MapNode { + pos: (f64, f64), + inner: Node, +} + /// A map that people fight on /// /// A map is defined by it's graph relationships, but also where on /// the map nodes are placed, how much spacing there is, etc. All /// this information is encoded in the same structs because it's /// static, and just more convenient. -#[derive(Default, Serialize, Deserialize)] pub struct Map { - /// Node IDs mapped to node objects - nodes: BTreeMap<u16, Arc<Node>>, + /// Node IDs mapped to coordinates + nodes: BTreeMap<NodeId, (i64, i64)>, /// Link IDs mapped to link objects links: BTreeMap<u16, Arc<Link>>, + /// A coordinate map for the network + coord: Quadtree<i64, Arc<MapNode>>, } impl Map { - pub fn new() -> Arc<Self> { - Arc::new(Self::default()) + pub fn new() -> Self { + Self { + nodes: BTreeMap::new(), + links: BTreeMap::new(), + coord: Quadtree::new(2), + } } pub fn update<F>(&mut self, cb: F) -> ServerResult<Response> |