fix list updating exception

This commit is contained in:
austin 2022-04-24 14:09:44 -04:00
parent c0c0e81327
commit e303ac4a03

View File

@ -128,15 +128,19 @@ public class NavMeshUtils {
// ); // );
toRemove.clear(); toRemove.clear();
//TODO: iterate this backwards and check for x adjacency, if no adjacency end loop early //TODO: iterate this backwards and check for x adjacency, if no adjacency end loop early
List<SecondPhaseBox> neighborUpdateList = new LinkedList<SecondPhaseBox>();
for(SecondPhaseBox interim : secondPhaseBoxes){ for(SecondPhaseBox interim : secondPhaseBoxes){
if(firstPhaseBox.yStart == interim.boundMinY && firstPhaseBox.yEnd == interim.boundMaxY && firstPhaseBox.x == interim.boundMaxX){ if(firstPhaseBox.yStart == interim.boundMinY && firstPhaseBox.yEnd == interim.boundMaxY && firstPhaseBox.x == interim.boundMaxX){
for(SecondPhaseBox neighbor : interim.getNeighbors()){ for(SecondPhaseBox neighbor : interim.getNeighbors()){
neighbor.removeNeighbor(interim); neighborUpdateList.add(neighbor);
interim.removeNeighbor(neighbor);
neighbor.addNeighbor(newBox);
newBox.addNeighbor(neighbor);
// System.out.println("ADD NEIGHBOR: " + neighbor.boundMaxX + " " + neighbor.boundMaxY + " " + neighbor.boundMinX + " " + neighbor.boundMinY); // System.out.println("ADD NEIGHBOR: " + neighbor.boundMaxX + " " + neighbor.boundMaxY + " " + neighbor.boundMinX + " " + neighbor.boundMinY);
} }
for(SecondPhaseBox update : neighborUpdateList){
update.removeNeighbor(interim);
interim.removeNeighbor(update);
update.addNeighbor(newBox);
newBox.addNeighbor(update);
}
toRemove.add(interim); toRemove.add(interim);
newBox.setBoundMinX(interim.getBoundMinX()); newBox.setBoundMinX(interim.getBoundMinX());
//TODO: calculate new min/max height //TODO: calculate new min/max height