fix dynamic grid broadphase being broken

This commit is contained in:
RandomityGuy 2024-11-05 20:25:58 +05:30
parent 0a56019a53
commit 3de0519d47
2 changed files with 35 additions and 25 deletions

View file

@ -34,6 +34,7 @@ class CollisionWorld {
public function build() { public function build() {
this.grid.build(); this.grid.build();
this.dynamicGrid.setBounds(this.grid.bounds);
this.dynamicGrid.build(); this.dynamicGrid.build();
} }

View file

@ -32,6 +32,7 @@ class GridBroadphase {
var searchKey:Int = 0; var searchKey:Int = 0;
var _built = false; var _built = false;
var hasBounds:Bool = false;
public function new() { public function new() {
// this.bounds = bounds.clone(); // this.bounds = bounds.clone();
@ -139,11 +140,18 @@ class GridBroadphase {
} }
} }
public function setBounds(bounds:Bounds) {
this.bounds = bounds.clone();
this.cellSize = new Vector(bounds.xSize / CELL_DIV.x, bounds.ySize / CELL_DIV.y);
this.hasBounds = true;
}
public function build() { public function build() {
if (_built) if (_built)
return; return;
_built = true; _built = true;
// Find the bounds // Find the bounds
if (!hasBounds) {
var xMin = 1e8; var xMin = 1e8;
var xMax = -1e8; var xMax = -1e8;
var yMin = 1e8; var yMin = 1e8;
@ -170,6 +178,7 @@ class GridBroadphase {
zMax += 100; zMax += 100;
this.bounds = Bounds.fromValues(xMin, yMin, zMin, xMax - xMin, yMax - yMin, zMax - zMin); this.bounds = Bounds.fromValues(xMin, yMin, zMin, xMax - xMin, yMax - yMin, zMax - zMin);
this.cellSize = new Vector(this.bounds.xSize / CELL_DIV.x, this.bounds.ySize / CELL_DIV.y); this.cellSize = new Vector(this.bounds.xSize / CELL_DIV.x, this.bounds.ySize / CELL_DIV.y);
}
// Insert the objects // Insert the objects
for (i in 0...CELL_SIZE) { for (i in 0...CELL_SIZE) {