render improvements

This commit is contained in:
Leijurv 2018-08-06 16:09:28 -07:00
parent 4caf6a8265
commit 2cbf8fff9b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 24 additions and 1 deletions

View File

@ -134,9 +134,11 @@ public class PathingBehavior extends Behavior {
//System.out.println("Render passing");
//System.out.println(event.getPartialTicks());
float partialTicks = event.getPartialTicks();
long start = System.currentTimeMillis();
// Render the current path, if there is one
getPath().ifPresent(path -> drawPath(path, player(), partialTicks, Color.RED));
long split = System.currentTimeMillis();
getPath().ifPresent(path -> {
for (BlockPos pos : path.getBlocksToBreak()) {
drawSelectionBox(player(), pos, partialTicks, Color.RED);
@ -156,6 +158,9 @@ public class PathingBehavior extends Behavior {
});
});
});
long end = System.currentTimeMillis();
if (end - start > 0)
System.out.println("Frame took " + (split - start) + " " + (end - split));
}
public void drawPath(IPath path, EntityPlayerSP player, float partialTicks, Color color) {

View File

@ -187,23 +187,34 @@ public abstract class Movement implements Helper, MovementHelper {
return state;
}
public ArrayList<BlockPos> toBreakCached = null;
public ArrayList<BlockPos> toPlaceCached = null;
public ArrayList<BlockPos> toBreak() {
if (toBreakCached != null) {
return toBreakCached;
}
ArrayList<BlockPos> result = new ArrayList<>();
for (BlockPos positionsToBreak1 : positionsToBreak) {
if (!MovementHelper.canWalkThrough(positionsToBreak1, BlockStateInterface.get(positionsToBreak1))) {
result.add(positionsToBreak1);
}
}
toBreakCached = result;
return result;
}
public ArrayList<BlockPos> toPlace() {
if (toPlaceCached != null) {
return toPlaceCached;
}
ArrayList<BlockPos> result = new ArrayList<>();
for (BlockPos positionsToPlace1 : positionsToPlace) {
if (!MovementHelper.canWalkOn(positionsToPlace1)) {
result.add(positionsToPlace1);
}
}
toPlaceCached = result;
return result;
}
}

View File

@ -35,7 +35,7 @@ public class PathExecutor extends Behavior {
@Override
public void onTick(TickEvent event) {
if(event.getType() == TickEvent.Type.OUT) {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
if (pathPosition >= path.length()) {
@ -48,6 +48,7 @@ public class PathExecutor extends Behavior {
BlockPos whereAmI = playerFeet();
if (pathPosition == path.length() - 1) {
System.out.println("On last path position -- done!");
pathPosition++;
return;
}
if (!whereShouldIBe.equals(whereAmI)) {
@ -116,6 +117,12 @@ public class PathExecutor extends Behavior {
}
}
}*/
for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
if (i >= 0 && i < path.movements().size()) {
path.movements().get(i).toBreakCached = null;
path.movements().get(i).toPlaceCached = null;
}
}
Movement movement = path.movements().get(pathPosition);
if (movement.recalculateCost() >= ActionCosts.COST_INF) {
System.out.println("Something has changed in the world and this movement has become impossible. Cancelling.");