Skip to content

Commit

Permalink
Update units_spacial_set.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Amatsugu committed Sep 25, 2024
1 parent 5ad54ca commit 47c0732
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions game/units/src/units_spacial_set.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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!();
}
}

0 comments on commit 47c0732

Please sign in to comment.