Update units_spacial_set.rs

This commit is contained in:
2024-09-25 19:51:41 -04:00
parent 5ad54ca844
commit 47c0732f23

View File

@@ -1,5 +1,5 @@
use bevy::prelude::Entity; use bevy::prelude::*;
use quadtree_rs::Quadtree; use quadtree_rs::{point::Point, Quadtree};
use shared::tags::Faction; use shared::tags::Faction;
use world_generation::hex_utils::HexCoord; use world_generation::hex_utils::HexCoord;
@@ -13,11 +13,29 @@ pub struct UnitEntity {
} }
pub struct UnitSpacialSet { pub struct UnitSpacialSet {
tree: Quadtree<i32, UnitEntity>, tree: Quadtree<usize, UnitEntity>,
} }
impl UnitSpacialSet { 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!();
} }
} }