From 12753a9b5c8613f5f1edb2af5e06b3d40a3beef1 Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Tue, 5 Nov 2019 10:55:07 +0100 Subject: [PATCH] Attempt to rewrite away the skip array --- .../anuke/mindustry/input/InputHandler.java | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index bfb5527a81..92902dc310 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -820,44 +820,68 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ points = Placement.normalizeLine(startX, startY, endX, endY); } - Array skip = new Array<>(); -// Array fake = new Array<>(); - if(block instanceof PowerNode){ - final int[] i = {0}; - points.each(req -> { - if(i[0]++ == 0 || i[0] == points.size){ - // beginning & end should always be placed - }else{ - // check with how many powernodes the *next* tile will overlap - int overlaps = 0; - for(int j = 0; j < i[0]; j++){ - // skip powernodes we have already crossed off as air - if(skip.contains(points.get(j))) continue; - -// // do not suggest building where you cant? -// if(!validPlace(points.get(i[0]-1).x, points.get(i[0]-1).y, block, rotation)){ -// skip.add(points.get(i[0]-1)); -// fake.add(points.get(i[0]-1)); -// return; +// Array skip = new Array<>(); +// if(block instanceof PowerNode){ +// final int[] i = {0}; +// points.each(req -> { +// if(i[0]++ == 0 || i[0] == points.size){ +// // beginning & end should always be placed +// }else{ +// // check with how many powernodes the *next* tile will overlap +// int overlaps = 0; +// for(int j = 0; j < i[0]; j++){ +// // skip powernodes we have already crossed off as air +// if(skip.contains(points.get(j))) continue; +// +// Tile next = world.ltile(points.get(i[0]).x, points.get(i[0]).y); +// Tile loop = world.ltile(points.get(j).x, points.get(j).y); +// +// if (((PowerNode) block).overlaps(next, loop)){ +// overlaps++; // } +// } +// +// // 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); - Tile loop = world.ltile(points.get(j).x, points.get(j).y); + if(block instanceof PowerNode){ +// while(true){ +// Tile cursor = world.ltile(points.first().x, points.first().y); +// } - if (((PowerNode) block).overlaps(next, loop)){ - overlaps++; + final int[] i = {0}; + 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 > 1){ - skip.add(points.get(i[0]-1)); + if(overlaps[0] > 1){ + points.remove(1); + } else { + break; } } }); } -// skip.removeAll(fake); - points.removeAll(skip); float angle = Angles.angle(startX, startY, endX, endY); int baseRotation = rotation;