render optim
This commit is contained in:
parent
d3891a8f11
commit
71c36a7b0b
@ -28,7 +28,6 @@ import baritone.bot.pathing.calc.IPathFinder;
|
||||
import baritone.bot.pathing.goals.Goal;
|
||||
import baritone.bot.pathing.goals.GoalBlock;
|
||||
import baritone.bot.pathing.goals.GoalXZ;
|
||||
import baritone.bot.pathing.movement.Movement;
|
||||
import baritone.bot.pathing.path.IPath;
|
||||
import baritone.bot.pathing.path.PathExecutor;
|
||||
import baritone.bot.utils.BlockStateInterface;
|
||||
@ -47,6 +46,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -175,23 +176,18 @@ public class PathingBehavior extends Behavior {
|
||||
//System.out.println("Render passing");
|
||||
//System.out.println(event.getPartialTicks());
|
||||
float partialTicks = event.getPartialTicks();
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime();
|
||||
|
||||
// Render the current path, if there is one
|
||||
if (current != null && current.getPath() != null) {
|
||||
int renderBegin = Math.max(current.getPosition() - 3, 0);
|
||||
drawPath(current.getPath(), renderBegin, player(), partialTicks, Color.RED);
|
||||
}
|
||||
long split = System.currentTimeMillis();
|
||||
getPath().ifPresent(path -> {
|
||||
for (Movement m : path.movements()) {
|
||||
for (BlockPos pos : m.toPlace())
|
||||
drawSelectionBox(player(), pos, partialTicks, Color.GREEN);
|
||||
for (BlockPos pos : m.toBreak()) {
|
||||
drawSelectionBox(player(), pos, partialTicks, Color.RED);
|
||||
}
|
||||
}
|
||||
});
|
||||
long split = System.nanoTime();
|
||||
if (current != null) {
|
||||
drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED);
|
||||
drawManySelectionBoxes(player(), current.toPlace(), partialTicks, Color.GREEN);
|
||||
}
|
||||
|
||||
// If there is a path calculation currently running, render the path calculation process
|
||||
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(currentlyRunning -> {
|
||||
@ -199,11 +195,12 @@ public class PathingBehavior extends Behavior {
|
||||
drawPath(p, 0, player(), partialTicks, Color.BLUE);
|
||||
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
|
||||
drawPath(mr, 0, player(), partialTicks, Color.CYAN);
|
||||
drawSelectionBox(player(), mr.getDest(), partialTicks, Color.CYAN);
|
||||
drawManySelectionBoxes(player(), Arrays.asList(mr.getDest()), partialTicks, Color.CYAN);
|
||||
});
|
||||
});
|
||||
});
|
||||
long end = System.currentTimeMillis();
|
||||
long end = System.nanoTime();
|
||||
//System.out.println((end - split) + " " + (split - start));
|
||||
// if (end - start > 0)
|
||||
// System.out.println("Frame took " + (split - start) + " " + (end - split));
|
||||
}
|
||||
@ -263,7 +260,7 @@ public class PathingBehavior extends Behavior {
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawSelectionBox(EntityPlayer player, BlockPos blockpos, float partialTicks, Color color) {
|
||||
public static void drawManySelectionBoxes(EntityPlayer player, Collection<BlockPos> positions, float partialTicks, Color color) {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
|
||||
@ -272,41 +269,47 @@ public class PathingBehavior extends Behavior {
|
||||
GlStateManager.depthMask(false);
|
||||
float f = 0.002F;
|
||||
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
|
||||
IBlockState state = BlockStateInterface.get(blockpos);
|
||||
Block block = state.getBlock();
|
||||
if (block.equals(Blocks.AIR)) {
|
||||
block = Blocks.DIRT;
|
||||
}
|
||||
//block.setBlockBoundsBasedOnState(Minecraft.getMinecraft().world, blockpos);
|
||||
|
||||
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
|
||||
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
|
||||
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
|
||||
AxisAlignedBB toDraw = block.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin(3, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.begin(3, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.begin(1, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
for (BlockPos pos : positions) {
|
||||
IBlockState state = BlockStateInterface.get(pos);
|
||||
Block block = state.getBlock();
|
||||
AxisAlignedBB toDraw;
|
||||
if (block.equals(Blocks.AIR)) {
|
||||
toDraw = Blocks.DIRT.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, pos);
|
||||
} else {
|
||||
toDraw = state.getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
|
||||
}
|
||||
toDraw = toDraw.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2);
|
||||
buffer.begin(3, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.begin(3, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.begin(1, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
||||
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
|
@ -29,6 +29,10 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static baritone.bot.pathing.movement.MovementState.MovementStatus.*;
|
||||
|
||||
/**
|
||||
@ -45,6 +49,9 @@ public class PathExecutor extends Behavior {
|
||||
private int ticksAway;
|
||||
private int ticksOnCurrent;
|
||||
private boolean failed;
|
||||
private boolean recalcBP = true;
|
||||
private HashSet<BlockPos> toBreak = new HashSet<>();
|
||||
private HashSet<BlockPos> toPlace = new HashSet<>();
|
||||
|
||||
public PathExecutor(IPath path) {
|
||||
this.path = path;
|
||||
@ -136,12 +143,39 @@ public class PathExecutor extends Behavior {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
long start = System.currentTimeMillis();
|
||||
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 m = path.movements().get(i);
|
||||
HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak());
|
||||
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace());
|
||||
m.toBreakCached = null;
|
||||
m.toPlaceCached = null;
|
||||
m.toBreak();
|
||||
m.toPlace();
|
||||
if (!prevBreak.equals(new HashSet<>(m.toBreak()))) {
|
||||
recalcBP = true;
|
||||
}
|
||||
if (!prevPlace.equals(new HashSet<>(m.toPlace()))) {
|
||||
recalcBP = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recalcBP) {
|
||||
HashSet<BlockPos> newBreak = new HashSet<>();
|
||||
HashSet<BlockPos> newPlace = new HashSet<>();
|
||||
for (int i = 0; i < path.movements().size(); i++) {
|
||||
newBreak.addAll(path.movements().get(i).toBreak());
|
||||
newPlace.addAll(path.movements().get(i).toPlace());
|
||||
}
|
||||
toBreak = newBreak;
|
||||
toPlace = newPlace;
|
||||
recalcBP = false;
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
if (end - start > 0) {
|
||||
displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
|
||||
}
|
||||
Movement movement = path.movements().get(pathPosition);
|
||||
if (movement.recalculateCost() >= ActionCosts.COST_INF) {
|
||||
displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||
@ -192,4 +226,12 @@ public class PathExecutor extends Behavior {
|
||||
public boolean finished() {
|
||||
return pathPosition >= path.length();
|
||||
}
|
||||
|
||||
public Set<BlockPos> toBreak() {
|
||||
return Collections.unmodifiableSet(toBreak);
|
||||
}
|
||||
|
||||
public Set<BlockPos> toPlace() {
|
||||
return Collections.unmodifiableSet(toPlace);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user