aboutsummaryrefslogtreecommitdiff
path: root/src/map.rs
blob: 212ce75100ad56ee2efef6ea1e59d676339e886b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Implements a map graph and world logic

use crate::{
    config::{LinkCfg, MapCfg, NodeCfg},
    data::{Link, Node, NodeId},
    server::{ServerErr, ServerResult},
    wire::Response,
};
use async_std::sync::Arc;
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.
pub struct Map {
    /// 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() -> Self {
        Self {
            nodes: BTreeMap::new(),
            links: BTreeMap::new(),
            coord: Quadtree::new(2),
        }
    }

    pub fn update<F>(&mut self, cb: F) -> ServerResult<Response>
    where
        F: Fn(&mut Map) -> ServerResult<Response>,
    {
        unimplemented!()
    }
}