From 8e4b4f198d732d2418905a424822fc1ad521dd97 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 25 Dec 2018 20:06:15 -0800 Subject: [PATCH] reorder moves for better cache locality --- .../java/baritone/pathing/movement/Moves.java | 172 +++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Moves.java b/src/main/java/baritone/pathing/movement/Moves.java index c626327e1..245b9768a 100644 --- a/src/main/java/baritone/pathing/movement/Moves.java +++ b/src/main/java/baritone/pathing/movement/Moves.java @@ -52,99 +52,107 @@ public double cost(CalculationContext context, int x, int y, int z) { } }, - TRAVERSE_NORTH(0, 0, -1) { + ASCEND_NORTH(0, +1, -1) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementTraverse(context.getBaritone(), src, src.north()); + return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z - 1)); } @Override public double cost(CalculationContext context, int x, int y, int z) { - return MovementTraverse.cost(context, x, y, z, x, z - 1); + return MovementAscend.cost(context, x, y, z, x, z - 1); } }, - TRAVERSE_SOUTH(0, 0, +1) { + TRAVERSE_NORTH(0, 0, -1) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementTraverse(context.getBaritone(), src, src.south()); + return new MovementTraverse(context.getBaritone(), src, src.north()); } @Override public double cost(CalculationContext context, int x, int y, int z) { - return MovementTraverse.cost(context, x, y, z, x, z + 1); + return MovementTraverse.cost(context, x, y, z, x, z - 1); } }, - TRAVERSE_EAST(+1, 0, 0) { + PARKOUR_NORTH(0, 0, -4, true, false) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementTraverse(context.getBaritone(), src, src.east()); + return MovementParkour.cost(context, src, EnumFacing.NORTH); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementTraverse.cost(context, x, y, z, x + 1, z); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementParkour.cost(context, x, y, z, EnumFacing.NORTH, result); } }, - TRAVERSE_WEST(-1, 0, 0) { + DESCEND_NORTH(0, -1, -1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementTraverse(context.getBaritone(), src, src.west()); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + if (res.y == src.y - 1) { + return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } else { + return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementTraverse.cost(context, x, y, z, x - 1, z); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDescend.cost(context, x, y, z, x, z - 1, result); } }, - ASCEND_NORTH(0, +1, -1) { + DIAGONAL_NORTHEAST(+1, 0, -1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z - 1)); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST, res.y - src.y); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementAscend.cost(context, x, y, z, x, z - 1); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDiagonal.cost(context, x, y, z, x + 1, z - 1, result); } }, - ASCEND_SOUTH(0, +1, +1) { + ASCEND_EAST(+1, +1, 0) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z + 1)); + return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x + 1, src.y + 1, src.z)); } @Override public double cost(CalculationContext context, int x, int y, int z) { - return MovementAscend.cost(context, x, y, z, x, z + 1); + return MovementAscend.cost(context, x, y, z, x + 1, z); } }, - ASCEND_EAST(+1, +1, 0) { + TRAVERSE_EAST(+1, 0, 0) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x + 1, src.y + 1, src.z)); + return new MovementTraverse(context.getBaritone(), src, src.east()); } @Override public double cost(CalculationContext context, int x, int y, int z) { - return MovementAscend.cost(context, x, y, z, x + 1, z); + return MovementTraverse.cost(context, x, y, z, x + 1, z); } }, - ASCEND_WEST(-1, +1, 0) { + PARKOUR_EAST(+4, 0, 0, true, false) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x - 1, src.y + 1, src.z)); + return MovementParkour.cost(context, src, EnumFacing.EAST); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementAscend.cost(context, x, y, z, x - 1, z); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementParkour.cost(context, x, y, z, EnumFacing.EAST, result); } }, @@ -166,161 +174,155 @@ public void apply(CalculationContext context, int x, int y, int z, MutableMoveRe } }, - DESCEND_WEST(-1, -1, 0, false, true) { + DIAGONAL_SOUTHEAST(+1, 0, +1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { MutableMoveResult res = new MutableMoveResult(); apply(context, src.x, src.y, src.z, res); - if (res.y == src.y - 1) { - return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } else { - return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST, res.y - src.y); } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDescend.cost(context, x, y, z, x - 1, z, result); + MovementDiagonal.cost(context, x, y, z, x + 1, z + 1, result); } }, - DESCEND_NORTH(0, -1, -1, false, true) { + ASCEND_SOUTH(0, +1, +1) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - MutableMoveResult res = new MutableMoveResult(); - apply(context, src.x, src.y, src.z, res); - if (res.y == src.y - 1) { - return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } else { - return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } + return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z + 1)); } @Override - public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDescend.cost(context, x, y, z, x, z - 1, result); + public double cost(CalculationContext context, int x, int y, int z) { + return MovementAscend.cost(context, x, y, z, x, z + 1); } }, - DESCEND_SOUTH(0, -1, +1, false, true) { + + TRAVERSE_SOUTH(0, 0, +1) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - MutableMoveResult res = new MutableMoveResult(); - apply(context, src.x, src.y, src.z, res); - if (res.y == src.y - 1) { - return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } else { - return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); - } + return new MovementTraverse(context.getBaritone(), src, src.south()); } @Override - public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDescend.cost(context, x, y, z, x, z + 1, result); + public double cost(CalculationContext context, int x, int y, int z) { + return MovementTraverse.cost(context, x, y, z, x, z + 1); } }, - DIAGONAL_NORTHEAST(+1, 0, -1, false, true) { + + PARKOUR_SOUTH(0, 0, +4, true, false) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - MutableMoveResult res = new MutableMoveResult(); - apply(context, src.x, src.y, src.z, res); - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST, res.y - src.y); + return MovementParkour.cost(context, src, EnumFacing.SOUTH); } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDiagonal.cost(context, x, y, z, x + 1, z - 1, result); + MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH, result); } }, - DIAGONAL_NORTHWEST(-1, 0, -1, false, true) { + DESCEND_SOUTH(0, -1, +1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { MutableMoveResult res = new MutableMoveResult(); apply(context, src.x, src.y, src.z, res); - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST, res.y - src.y); + if (res.y == src.y - 1) { + return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } else { + return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDiagonal.cost(context, x, y, z, x - 1, z - 1, result); + MovementDescend.cost(context, x, y, z, x, z + 1, result); } }, - DIAGONAL_SOUTHEAST(+1, 0, +1, false, true) { + DIAGONAL_SOUTHWEST(-1, 0, +1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { MutableMoveResult res = new MutableMoveResult(); apply(context, src.x, src.y, src.z, res); - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST, res.y - src.y); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST, res.y - src.y); } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDiagonal.cost(context, x, y, z, x + 1, z + 1, result); + MovementDiagonal.cost(context, x, y, z, x - 1, z + 1, result); } }, - DIAGONAL_SOUTHWEST(-1, 0, +1, false, true) { + ASCEND_WEST(-1, +1, 0) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - MutableMoveResult res = new MutableMoveResult(); - apply(context, src.x, src.y, src.z, res); - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST, res.y - src.y); + return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x - 1, src.y + 1, src.z)); } @Override - public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementDiagonal.cost(context, x, y, z, x - 1, z + 1, result); + public double cost(CalculationContext context, int x, int y, int z) { + return MovementAscend.cost(context, x, y, z, x - 1, z); } }, - PARKOUR_NORTH(0, 0, -4, true, false) { + TRAVERSE_WEST(-1, 0, 0) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return MovementParkour.cost(context, src, EnumFacing.NORTH); + return new MovementTraverse(context.getBaritone(), src, src.west()); } @Override - public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementParkour.cost(context, x, y, z, EnumFacing.NORTH, result); + public double cost(CalculationContext context, int x, int y, int z) { + return MovementTraverse.cost(context, x, y, z, x - 1, z); } }, - PARKOUR_SOUTH(0, 0, +4, true, false) { + PARKOUR_WEST(-4, 0, 0, true, false) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return MovementParkour.cost(context, src, EnumFacing.SOUTH); + return MovementParkour.cost(context, src, EnumFacing.WEST); } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH, result); + MovementParkour.cost(context, x, y, z, EnumFacing.WEST, result); } }, - PARKOUR_EAST(+4, 0, 0, true, false) { + DESCEND_WEST(-1, -1, 0, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return MovementParkour.cost(context, src, EnumFacing.EAST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + if (res.y == src.y - 1) { + return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } else { + return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z)); + } } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementParkour.cost(context, x, y, z, EnumFacing.EAST, result); + MovementDescend.cost(context, x, y, z, x - 1, z, result); } }, - PARKOUR_WEST(-4, 0, 0, true, false) { + DIAGONAL_NORTHWEST(-1, 0, -1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return MovementParkour.cost(context, src, EnumFacing.WEST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST, res.y - src.y); } @Override public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { - MovementParkour.cost(context, x, y, z, EnumFacing.WEST, result); + MovementDiagonal.cost(context, x, y, z, x - 1, z - 1, result); } };