Attempt to rewrite away the skip array

This commit is contained in:
Patrick 'Quezler' Mounier
2019-11-05 10:55:07 +01:00
parent 0f39596685
commit 12753a9b5c

View File

@@ -820,44 +820,68 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
points = Placement.normalizeLine(startX, startY, endX, endY); points = Placement.normalizeLine(startX, startY, endX, endY);
} }
Array<Point2> skip = new Array<>(); // Array<Point2> skip = new Array<>();
// Array<Point2> fake = new Array<>(); // if(block instanceof PowerNode){
if(block instanceof PowerNode){ // final int[] i = {0};
final int[] i = {0}; // points.each(req -> {
points.each(req -> { // if(i[0]++ == 0 || i[0] == points.size){
if(i[0]++ == 0 || i[0] == points.size){ // // beginning & end should always be placed
// beginning & end should always be placed // }else{
}else{ // // check with how many powernodes the *next* tile will overlap
// check with how many powernodes the *next* tile will overlap // int overlaps = 0;
int overlaps = 0; // for(int j = 0; j < i[0]; j++){
for(int j = 0; j < i[0]; j++){ // // skip powernodes we have already crossed off as air
// skip powernodes we have already crossed off as air // if(skip.contains(points.get(j))) continue;
if(skip.contains(points.get(j))) continue; //
// Tile next = world.ltile(points.get(i[0]).x, points.get(i[0]).y);
// // do not suggest building where you cant? // Tile loop = world.ltile(points.get(j).x, points.get(j).y);
// if(!validPlace(points.get(i[0]-1).x, points.get(i[0]-1).y, block, rotation)){ //
// skip.add(points.get(i[0]-1)); // if (((PowerNode) block).overlaps(next, loop)){
// fake.add(points.get(i[0]-1)); // overlaps++;
// return;
// } // }
// }
//
// // if its more than one it can bridge the gap
// if(overlaps > 1){
// skip.add(points.get(i[0]-1));
// }
// }
// });
// }
// points.removeAll(skip);
Tile next = world.ltile(points.get(i[0]).x, points.get(i[0]).y); if(block instanceof PowerNode){
Tile loop = world.ltile(points.get(j).x, points.get(j).y); // while(true){
// Tile cursor = world.ltile(points.first().x, points.first().y);
// }
if (((PowerNode) block).overlaps(next, loop)){ final int[] i = {0};
overlaps++; points.each(point2 -> {
if(i[0]++ == 0 || i[0] == points.size) return;
Tile from = world.ltile(points.first().x, points.first().y);
while (true){
final int[] overlaps = {0};
points.each(tmp -> {
Tile to = world.ltile(points.get(1).x, points.get(1).y);
if (to == from) return;
if(((PowerNode) block).overlaps(from, to)){
overlaps[0]++;
} }
} });
// if its more than one it can bridge the gap if(overlaps[0] > 1){
if(overlaps > 1){ points.remove(1);
skip.add(points.get(i[0]-1)); } else {
break;
} }
} }
}); });
} }
// skip.removeAll(fake);
points.removeAll(skip);
float angle = Angles.angle(startX, startY, endX, endY); float angle = Angles.angle(startX, startY, endX, endY);
int baseRotation = rotation; int baseRotation = rotation;