Skip to content

Commit

Permalink
Meanwhile ... passable and ray-racing... and fixes.
Browse files Browse the repository at this point in the history
* Increase precision of debug logging.
* Fix iteration conditions for the axes.
* Fix margins for collidesFence (method + THICK_FENCE workaround
parameter).
  • Loading branch information
asofold committed Jun 10, 2016
1 parent 181502c commit 5d0d5d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Expand Up @@ -36,7 +36,14 @@
public class Passable extends Check {

/** TESTING RATHER. */
private static boolean preferAxisWise = false;

// TODO: Make this configurable once a working set of settings has been found.
// TODO: Once made configurable... intense testing... and test cases.
private static boolean rt_legacy = true;
// TODO: rt_xzFactor = 1.0; // Problems: Doors, fences.
private static double rt_xzFactor = 0.98;
// TODO: Test bumping head into things.
private static double rt_heightFactor = 1.0;

/**
* Convenience for player moving, to keep a better overview.
Expand All @@ -46,10 +53,11 @@ public class Passable extends Check {
* @return
*/
public static boolean isPassable(Location from, Location to) {
return preferAxisWise ? BlockProperties.isPassableAxisWise(from, to) : BlockProperties.isPassable(from, to);
return rt_legacy ? BlockProperties.isPassable(from, to) : BlockProperties.isPassableAxisWise(from, to);
}

private final ICollidePassable rayTracing = preferAxisWise ? new PassableAxisTracing() : new PassableRayTracing();
// TODO: Store both and select on check (with config then).
private final ICollidePassable rayTracing = rt_legacy ? new PassableRayTracing() : new PassableAxisTracing();

public Passable() {
super(CheckType.MOVING_PASSABLE);
Expand Down Expand Up @@ -78,7 +86,7 @@ public Location check(final Player player, final PlayerLocation from, final Play
boolean toPassable = to.isPassable();
// General condition check for using ray-tracing.
if (toPassable && cc.passableRayTracingCheck && (!cc.passableRayTracingBlockChangeOnly || manhattan > 0)) {
rayTracing.setMargins(from.getEyeHeight(), from.getWidth() / 2.0); // max from/to + resolution ?
rayTracing.setMargins(from.getEyeHeight() * rt_heightFactor, from.getWidth() / 2.0 * rt_xzFactor); // max from/to + resolution ?
rayTracing.set(from, to);
rayTracing.loop();
if (rayTracing.collides() || rayTracing.getStepsDone() >= rayTracing.getMaxSteps()) {
Expand Down Expand Up @@ -271,7 +279,7 @@ private void debugExtraCollisionDetails(Player player, ICollidePassable rayTraci
debug(player, "Raytracing collision (" + tag + "): " + rayTracing.getCollidingAxis());
}
else if (rayTracing.getStepsDone() >= rayTracing.getMaxSteps()) {
debug(player, "Raytracing collision (" + tag + "): max steps exceeded.");
debug(player, "Raytracing max steps exceeded (" + tag + "): "+ rayTracing.getCollidingAxis());
}
}

Expand Down
Expand Up @@ -1886,7 +1886,7 @@ else if ((flags & F_PASSABLE_X4) != 0 && (access.getData(bx, by, bz) & 0x4) != 0
return true;
}
else if ((flags & F_THICK_FENCE) != 0) {
if (!collidesFence(fx, fz, dX, dZ, dT, 0.425)) {
if (!collidesFence(fx, fz, dX, dZ, dT, 0.125)) {
return true;
}
}
Expand Down Expand Up @@ -1939,11 +1939,11 @@ && getGroundMinHeight(access, bx, by, bz, id, access.getBounds(bx, by, bz), flag
public static boolean collidesFence(final double fx, final double fz, final double dX, final double dZ, final double dT, final double d) {
final double dFx = 0.5 - fx;
final double dFz = 0.5 - fz;
if (Math.abs(dFx) > 0.05 && Math.abs(dFz) > d) {
if (Math.abs(dFx) > d && Math.abs(dFz) > d) {
// Check moving between quadrants.
final double dFx2 = 0.5 - (fx + dX * dT);
final double dFz2 = 0.5 - (fz + dZ * dT);
if (Math.abs(dFx2) > 0.05 && Math.abs(dFz2) > d) {
if (Math.abs(dFx2) > d && Math.abs(dFz2) > d) {
if (dFx * dFx2 > 0.0 && dFz * dFz2 > 0.0) {
return false;
}
Expand Down
Expand Up @@ -123,6 +123,7 @@ public void loop() {
double z = this.z0;
for (int i = 0; i < 3; i++) {
final Axis axis = axisOrder[i];
collidesAxis = axis; // Ensure here, to get it on max steps.
if (axis == Axis.Y_AXIS) {
runAxisY(x, y, z);
y = this.y1;
Expand All @@ -142,7 +143,6 @@ else if (axis != Axis.NONE) {
}
// NONE = skip
if (collides) {
collidesAxis = axis;
break;
}
}
Expand All @@ -161,24 +161,26 @@ private void runAxisY(final double xIn, final double yIn, final double zIn) {
final double zMin = zIn - marginZneg;
final double zMax = zIn + marginZpos;
final double yStart, yEnd;
final int iEndY;
if (yIn < this.y1) {
increment = 1;
yStart = yIn - marginYneg;
yEnd = this.y1 + marginYpos;
iEndY = Location.locToBlock(yEnd) + 1;
}
else {
increment = -1;
yStart = yIn + marginYpos;
yEnd = this.y1 - marginYneg;
iEndY = Location.locToBlock(yEnd) - 1;
}
final int iMinX = Location.locToBlock(xMin);
final int iMaxX = Location.locToBlock(xMax);
final int iMinZ = Location.locToBlock(zMin);
final int iMaxZ = Location.locToBlock(zMax);
final int iStartY = Location.locToBlock(yStart);
final int iEndY = Location.locToBlock(yEnd);
axisStep = 0;
for (int y = iStartY; y <= iEndY; y += increment) {
for (int y = iStartY; y != iEndY; y += increment) {
++step;
++axisStep;
if (step > maxSteps) {
Expand Down Expand Up @@ -210,24 +212,26 @@ private void runAxisX(final double xIn, final double yIn, final double zIn) {
final double zMin = zIn - marginZneg;
final double zMax = zIn + marginZpos;
final double xStart, xEnd;
final int iEndX;
if (xIn < this.x1) {
increment = 1;
xStart = xIn - marginXneg;
xEnd = this.x1 + marginXpos;
iEndX = Location.locToBlock(xEnd) + 1;
}
else {
increment = -1;
xStart = xIn + marginXpos;
xEnd = this.x1 - marginXneg;
iEndX = Location.locToBlock(xEnd) - 1;
}
final int iMinY = Location.locToBlock(yMin);
final int iMaxY = Location.locToBlock(yMax);
final int iMinZ = Location.locToBlock(zMin);
final int iMaxZ = Location.locToBlock(zMax);
final int iStartX = Location.locToBlock(xStart);
final int iEndX = Location.locToBlock(xEnd);
axisStep = 0;
for (int x = iStartX; x <= iEndX; x += increment) {
for (int x = iStartX; x != iEndX; x += increment) {
++step;
++axisStep;
if (step > maxSteps) {
Expand Down Expand Up @@ -259,24 +263,26 @@ private void runAxisZ(final double xIn, final double yIn, final double zIn) {
final double xMin = xIn - marginXneg;
final double xMax = xIn + marginXpos;
final double zStart, zEnd;
final int iEndZ;
if (zIn < this.z1) {
increment = 1;
zStart = zIn - marginZneg;
zEnd = this.z1 + marginZpos;
iEndZ = Location.locToBlock(zEnd + 1);
}
else {
increment = -1;
zStart = zIn + marginZpos;
zEnd = this.z1 - marginZneg;
iEndZ = Location.locToBlock(zEnd - 1);
}
final int iMinY = Location.locToBlock(yMin);
final int iMaxY = Location.locToBlock(yMax);
final int iMinX = Location.locToBlock(xMin);
final int iMaxX = Location.locToBlock(xMax);
final int iStartZ = Location.locToBlock(zStart);
final int iEndZ = Location.locToBlock(zEnd);
axisStep = 0;
for (int z = iStartZ; z <= iEndZ; z += increment) {
for (int z = iStartZ; z != iEndZ; z += increment) {
++step;
++axisStep;
if (step > maxSteps) {
Expand Down
Expand Up @@ -10,6 +10,7 @@ public class PassableAxisTracing extends AxisTracing implements ICollidePassable

private boolean ignoreFirst = false;

// TODO: Might need another option for margins (option to skip margin for the axis-start point, or alter ignoreFirst behavior).
// TODO: Consider an iteration margin as well (0.5 below for fences).

public BlockCache getBlockCache() {
Expand Down

0 comments on commit 5d0d5d4

Please sign in to comment.