Update units_spacial_set.rs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use bevy::prelude::Entity;
|
||||
use quadtree_rs::Quadtree;
|
||||
use bevy::prelude::*;
|
||||
use quadtree_rs::{point::Point, Quadtree};
|
||||
use shared::tags::Faction;
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
@@ -13,11 +13,29 @@ pub struct UnitEntity {
|
||||
}
|
||||
|
||||
pub struct UnitSpacialSet {
|
||||
tree: Quadtree<i32, UnitEntity>,
|
||||
tree: Quadtree<usize, UnitEntity>,
|
||||
}
|
||||
|
||||
impl UnitSpacialSet {
|
||||
pub fn new() {
|
||||
pub fn new(map_size: f32) -> Self {
|
||||
let n = f32::log2(map_size) / f32::log2(2.0);
|
||||
return Self {
|
||||
tree: Quadtree::new(n.ceil() as usize),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn add_unit(&mut self, unit: UnitEntity, pos: Vec3) -> Option<u64> {
|
||||
let p = pos.xz().as_uvec2();
|
||||
return self.tree.insert_pt(
|
||||
Point {
|
||||
x: p.x as usize,
|
||||
y: p.y as usize,
|
||||
},
|
||||
unit,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn move_unit(&mut self, handle: u64) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user