Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorder moves for better cache locality #300

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 87 additions & 85 deletions src/main/java/baritone/pathing/movement/Moves.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

Expand All @@ -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);
}
};

Expand Down