Integrate current look into flying queue checking. Include invalidation.

This commit is contained in:
asofold 2017-05-03 15:42:12 +02:00
parent 54f9d42ca1
commit e5f6370705
5 changed files with 68 additions and 32 deletions

View File

@ -77,11 +77,11 @@ public class Reach extends Check {
final ViolationData vd = new ViolationData(this, player, data.reachVL, distance, cc.reachActions);
vd.setParameter(ParameterName.REACH_DISTANCE, String.valueOf(Math.round(data.reachDistance)));
cancel = executeActions(vd).willCancel();
} else
} else {
// Player passed the check, reward them.
data.reachVL *= 0.9D;
data.addPassedCheck(this.type);
data.addPassedCheck(this.type);
}
return cancel;
}

View File

@ -132,26 +132,14 @@ public class Visible extends Check {
}
else {
// Ray-tracing.
Vector direction = loc.getDirection();
// Initialize.
final BlockCache blockCache = this.wrapBlockCache.getBlockCache();
blockCache.setAccess(loc.getWorld());
rayTracing.setBlockCache(blockCache);
collides = checkRayTracing(eyeX, eyeY, eyeZ, direction.getX(), direction.getY(), direction.getZ(), blockX, blockY, blockZ, face, tags, data.debug);
if (collides) {
// Debug output.
if (data.debug) {
debug(player, "pitch=" + loc.getPitch() + ",yaw=" + loc.getYaw() + " tags=" + StringUtil.join(tags, "+"));
}
// Re-check with flying packets.
if (checker.checkFlyingQueue(eyeX, eyeY, eyeZ, useLoc.getYaw(), useLoc.getPitch(),
blockX, blockY, blockZ, flyingHandle, face, tags, data.debug, player)) {
// Check passed.
collides = false;
}
checker.cleanup();
useLoc.setWorld(null);
}
collides = !checker.checkFlyingQueue(eyeX, eyeY, eyeZ, loc.getYaw(), loc.getPitch(),
blockX, blockY, blockZ, flyingHandle, face, tags, data.debug, player);
checker.cleanup();
useLoc.setWorld(null);
// Cleanup.
rayTracing.cleanup();
blockCache.cleanup();

View File

@ -122,15 +122,13 @@ public abstract class AbstractBlockDirectionCheck<D extends ICheckData, C extend
final int blockY = block.getY();
final int blockZ = block.getZ();
// The distance is squared initially.
double distance = checkBoulder(x, y, z, loc.getYaw(), loc.getPitch(), blockX, blockY, blockZ);
if (distance != Double.MAX_VALUE) {
if (checker.checkFlyingQueue(x, y, z, loc.getYaw(), loc.getPitch(),
blockX, blockY, blockZ, flyingHandle)) {
distance = Double.MAX_VALUE;
}
else {
distance = Math.min(distance, checker.getMinDistance());
}
double distance;
if (checker.checkFlyingQueue(x, y, z, loc.getYaw(), loc.getPitch(),
blockX, blockY, blockZ, flyingHandle)) {
distance = Double.MAX_VALUE;
}
else {
distance = checker.getMinDistance();
}
// TODO: Consider a protected field with a tolerance value.

View File

@ -20,6 +20,11 @@ public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
private final Player player;
private DataPacketFlying[] queue;
/**
* Convenience flag for keeping track amongst multiple checks, which all get
* passed this FlyingQueueHandle.
*/
private boolean currentLocationValid = true;
public FlyingQueueHandle(Player player) {
this.player = player;
@ -86,4 +91,24 @@ public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
return queue == null ? -1 : queue.length;
}
/**
* Test the currentLocationValid flag (convenience to keep track of a custom
* flag).
*
* @return
*/
public boolean isCurrentLocationValid() {
return currentLocationValid;
}
/**
* Set the currentLocationValid flag (convenience to keep track of a custom
* flag).
*
* @param currentLocationValid
*/
public void setCurrentLocationValid(boolean currentLocationValid) {
this.currentLocationValid = currentLocationValid;
}
}

View File

@ -13,12 +13,28 @@ public abstract class FlyingQueueLookBlockChecker {
* Override to prevent setting elements that can't be used or for which
* check returned false to null.
*/
protected boolean setUnusableToNull = true;
protected boolean invalidateFailed = true;
/**
* Run the check with the given oldPitch and oldYaw, unless invalidated.
* invalidateFailed applies.
*/
protected boolean checkOldLook = true;
protected abstract boolean check(final double x, final double y, final double z,
final float yaw, final float pitch,
final int blockX, final int blockY, final int blockZ);
public FlyingQueueLookBlockChecker setInvalidateFailed(boolean invalidatedFailed) {
this.invalidateFailed = invalidatedFailed;
return this;
}
public FlyingQueueLookBlockChecker setCheckOldLook(boolean checkOldLook) {
this.checkOldLook = checkOldLook;
return this;
}
/**
* Run check with the given start position (e.g. eye coordinates), but use
* yaw and pitch from the flying queue. Non matching entries are nulled,
@ -41,6 +57,15 @@ public abstract class FlyingQueueLookBlockChecker {
public boolean checkFlyingQueue(final double x, final double y, final double z,
final float oldYaw, final float oldPitch,
final int blockX, final int blockY, final int blockZ, final FlyingQueueHandle flyingHandle) {
if (checkOldLook && flyingHandle.isCurrentLocationValid()) {
if (check(x, y, z, oldYaw, oldPitch, blockX, blockY, blockZ)) {
return true;
}
else {
// Invalidate.
flyingHandle.setCurrentLocationValid(false);
}
}
final DataPacketFlying[] queue = flyingHandle.getHandle();
if (queue.length == 0) {
return false;
@ -51,7 +76,7 @@ public abstract class FlyingQueueLookBlockChecker {
continue;
}
if (!packetData.hasLook) {
if (setUnusableToNull) {
if (invalidateFailed) {
queue[i] = null;
}
continue;
@ -61,7 +86,7 @@ public abstract class FlyingQueueLookBlockChecker {
// Simple heuristic: reduce impact of checking by skipping redundant entries.
// TODO: Other heuristic / what's typical?
if (yaw == oldYaw && pitch == oldPitch) {
if (setUnusableToNull) {
if (invalidateFailed) {
queue[i] = null;
}
continue;
@ -72,7 +97,7 @@ public abstract class FlyingQueueLookBlockChecker {
return true;
}
else {
if (setUnusableToNull) {
if (invalidateFailed) {
queue[i] = null;
}
}