i forgot to save
This commit is contained in:
parent
0364361fbe
commit
9b4fa69e36
|
@ -151,45 +151,43 @@ func (q *Quadtree) Insert(collidable Collidable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update reassigns shapes to quadrants if needed
|
// Update reassigns shapes to correct quadrants if needed
|
||||||
func (q *Quadtree) Update() {
|
func (q *Quadtree) Update() {
|
||||||
new := []Collidable{}
|
toReinsert := []Collidable{}
|
||||||
if len(q.Shapes) > q.Cap && !q.splitted {
|
q.update(&toReinsert)
|
||||||
q.split()
|
for _, s := range toReinsert {
|
||||||
|
q.Insert(s)
|
||||||
}
|
}
|
||||||
if q.splitted {
|
}
|
||||||
q.tl.Update()
|
|
||||||
q.tr.Update()
|
func (q *Quadtree) update(moved *[]Collidable) {
|
||||||
q.bl.Update()
|
i := 0
|
||||||
q.br.Update()
|
for _, s := range q.Shapes {
|
||||||
for _, c := range q.Shapes {
|
if s.IsDead() {
|
||||||
if c.IsDead() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rect := c.GetRect()
|
if !q.fits(s.GetRect()) {
|
||||||
sub := q.getSub(rect)
|
*moved = append(*moved, s)
|
||||||
if sub != nil {
|
|
||||||
sub.Insert(c)
|
|
||||||
} else if q.fits(rect) || q.pr == nil {
|
|
||||||
new = append(new, c)
|
|
||||||
} else {
|
|
||||||
q.pr.Shapes = append(q.pr.Shapes, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, c := range q.Shapes {
|
|
||||||
if c.IsDead() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if q.fits(c.GetRect()) || q.pr == nil {
|
|
||||||
new = append(new, c)
|
|
||||||
} else {
|
|
||||||
q.pr.Shapes = append(q.pr.Shapes, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
q.Shapes = new
|
q.Shapes[i] = s
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := i; j < len(q.Shapes); j++ {
|
||||||
|
q.Shapes[j] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
q.Shapes = q.Shapes[:i]
|
||||||
|
|
||||||
|
if !q.splitted {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
q.tl.update(moved)
|
||||||
|
q.tr.update(moved)
|
||||||
|
q.bl.update(moved)
|
||||||
|
q.br.update(moved)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetColliding returns all coliding collidables, if rect belongs to object that is already
|
// GetColliding returns all coliding collidables, if rect belongs to object that is already
|
||||||
|
|
Loading…
Reference in New Issue