[BLEEDING] Alter 'ignoreFirst' mechanics with collision checking.

Change to 'ignoreInitiallyColliding' and only ignore the first block, if
it really is colliding right now. The flag is not resetting with
set(...) anymore.
This commit is contained in:
asofold 2016-06-11 12:38:22 +02:00
parent 57cb4580f9
commit b2d7c29814
7 changed files with 55 additions and 53 deletions

View File

@ -233,10 +233,12 @@ public class Passable extends Check {
*/
private boolean collidesIgnoreFirst(PlayerLocation from, PlayerLocation to) {
// TODO: Set (and reset?) margins?
// TODO: rayTracing.setIgnoreInitiallyColliding(true);
rayTracing.set(from, to);
rayTracing.setIgnoreFirst();
rayTracing.setIgnoreInitiallyColliding(true);
rayTracing.setCutOppositeDirectionMargin(true);
rayTracing.loop();
rayTracing.setIgnoreInitiallyColliding(false);
rayTracing.setCutOppositeDirectionMargin(false);
return rayTracing.collides() || rayTracing.getStepsDone() >= rayTracing.getMaxSteps();
}

View File

@ -55,10 +55,6 @@ public abstract class AxisTracing implements ICollide, ISetMargins {
private int maxSteps = 0;
// TODO: maxBlocks (...).
// TODO: ignoreFirst -> Should be ignore a specific block or blocks within the initial bounds or ...?
// TODO: Margin only for iteration, not for the bounds (for use-cases like fences).
public AxisTracing() {
@ -135,6 +131,7 @@ public abstract class AxisTracing implements ICollide, ISetMargins {
double x = this.x0;
double y = this.y0;
double z = this.z0;
// TODO: if (ignoreInitiallyColliding) -> fetch blocks, test in runAxis.
for (int i = 0; i < 3; i++) {
final Axis axis = axisOrder[i];
collidesAxis = axis; // Ensure here, to get it on max steps.

View File

@ -8,16 +8,29 @@ package fr.neatmonster.nocheatplus.utilities.collision;
*/
public interface ICollide {
// TODO: number of visited blocks?
/**
* Set the maximum steps to be done during loop(). Setting to 0 should
* disable the upper limit. (Integer.MAX_VALUE will be on the safe side as
* well.)
* Set the maximum steps to be done during loop() along the primary line.
* Setting to 0 should disable the upper limit. (Integer.MAX_VALUE will be
* on the safe side as well.) The primary line is meant to somehow reflect
* run time complexity, not necessarily each visited block.
*
* @param maxSteps
*/
// TODO: Not sure :p.
public void setMaxSteps(int maxSteps);
public int getMaxSteps();
/**
* Call before loop, in order to skip checking blocks that are found to be
* colliding at the start of loop. May or may not have any effect.
*
* @param ignoreInitiallyColliding
*/
public void setIgnoreInitiallyColliding(boolean ignoreInitiallyColliding);
public boolean getIgnoreInitiallyColliding();
/**
* Call before loop to set the coordinates of a move.
*
@ -45,7 +58,9 @@ public interface ICollide {
public int getStepsDone();
/**
* Test if the testing found a collision during loop().
* Test if the testing found a collision during loop(). This should reset
* automatically with calling set.
*
* @return
*/
public boolean collides();
@ -53,6 +68,7 @@ public interface ICollide {
/**
* Optional information about which (sub-) type of checking lead to
* collision. Should only be considered valid, if collides() returns true.
* Implementation-specific.
*
* @return
*/

View File

@ -11,14 +11,13 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
*/
public interface ICollidePassable extends ICollide, ISetMargins {
// TODO: IRayTracing
public void setBlockCache(BlockCache blockCache);
public BlockCache getBlockCache();
/**
* Set from PlayerLocation instances. May use the BlockCache from the
* from-location internally.
* Convenience: Call set and setBlockCache with the data from the
* PlayerLocation instances. Should use from.getBlockCache() as BlockCache
* instance.
*
* @param from
* @param to
@ -26,25 +25,13 @@ public interface ICollidePassable extends ICollide, ISetMargins {
public void set(final PlayerLocation from, final PlayerLocation to);
/**
* Ignore the first block. Must be called after set, because set should
* override internal state with false.
*/
// TODO: Switch to ignoreBlock(int, int, int) rather?
// TODO: Remove resetting on set?
// TODO: Consider to imply setCutOppositeDirectionMargin(true) with this (needs not reset with set)?
public void setIgnoreFirst();
/**
* Test if the first block is set to be ignored (resets to false with set).
*
* @return
*/
public boolean getIgnoreFirst();
/**
* Indicate if extra workarounds may be necessary, such as running y-axis
* collision before xz-axes collision in case the default run yields a
* collision.
*
* @return Return false in order to prevent workarounds with split by axis
* checking.
* checking. Typically should return true with ray-tracing and false
* with axis-tracing.
*/
public boolean mightNeedSplitAxisHandling();

View File

@ -8,7 +8,7 @@ public class PassableAxisTracing extends AxisTracing implements ICollidePassable
private BlockCache blockCache;
private boolean ignoreFirst = false;
private boolean ignoreInitiallyColliding = 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).
@ -26,7 +26,8 @@ public class PassableAxisTracing extends AxisTracing implements ICollidePassable
final double minX, final double minY, final double minZ,
final double maxX, final double maxY, final double maxZ,
final Axis axis, final int increment) {
if (ignoreFirst && step == 1) {
// TODO: Ignore blocks by coordinates (handle before calling step).
if (ignoreInitiallyColliding && step == 1) {
return true;
}
if (BlockProperties.isPassableBox(blockCache, blockX, blockY, blockZ, minX, minY, minZ, maxX, maxY, maxZ)) {
@ -41,7 +42,6 @@ public class PassableAxisTracing extends AxisTracing implements ICollidePassable
@Override
public void set(double x0, double y0, double z0, double x1, double y1, double z1) {
super.set(x0, y0, z0, x1, y1, z1);
ignoreFirst = false;
}
@Override
@ -51,14 +51,13 @@ public class PassableAxisTracing extends AxisTracing implements ICollidePassable
}
@Override
public void setIgnoreFirst() {
// TODO: ignoreBlock rather.
ignoreFirst = true;
public void setIgnoreInitiallyColliding(boolean ignoreInitiallyColliding) {
this.ignoreInitiallyColliding = ignoreInitiallyColliding;
}
@Override
public boolean getIgnoreFirst() {
return ignoreFirst;
public boolean getIgnoreInitiallyColliding() {
return ignoreInitiallyColliding;
}
@Override

View File

@ -22,8 +22,6 @@ public class PassableRayTracing extends RayTracing implements ICollidePassable {
protected BlockCache blockCache = null;
protected boolean ignorefirst = false;
@Override
public BlockCache getBlockCache() {
return blockCache;
@ -47,17 +45,6 @@ public class PassableRayTracing extends RayTracing implements ICollidePassable {
public void set(double x0, double y0, double z0, double x1, double y1, double z1) {
super.set(x0, y0, z0, x1, y1, z1);
collides = false;
ignorefirst = false;
}
@Override
public void setIgnoreFirst(){
this.ignorefirst = true;
}
@Override
public boolean getIgnoreFirst(){
return ignorefirst;
}
@Override
@ -67,10 +54,11 @@ public class PassableRayTracing extends RayTracing implements ICollidePassable {
@Override
protected boolean step(final int blockX, final int blockY, final int blockZ, final double oX, final double oY, final double oZ, final double dT, final boolean isPrimary) {
// Just delegate.
if (isPrimary && step == 1 && ignorefirst){
// Check if initially colliding blocks are meant to be skipped.
if (isPrimary && step == 1 && ignoreInitiallyColliding && !BlockProperties.isPassable(blockCache, oX + blockX, oY + blockY, oZ + blockZ, blockCache.getTypeId(blockX, blockY, blockZ))){
return true;
}
// Actual collision check for this block vs. the move.
if (BlockProperties.isPassableRay(blockCache, blockX, blockY, blockZ, oX, oY, oZ, dX, dY, dZ, dT)){
return true;
}

View File

@ -64,6 +64,9 @@ public abstract class RayTracing implements ICollide {
/** Maximum steps that will be done. */
private int maxSteps = Integer.MAX_VALUE;
/** Just the flag, a sub-class must make use during handling step. */
protected boolean ignoreInitiallyColliding = false;
protected boolean collides = false;
public RayTracing(double x0, double y0, double z0, double x1, double y1, double z1) {
@ -74,6 +77,16 @@ public abstract class RayTracing implements ICollide {
set(0, 0, 0, 0, 0, 0);
}
@Override
public void setIgnoreInitiallyColliding(boolean ignoreInitiallyColliding) {
this.ignoreInitiallyColliding = ignoreInitiallyColliding;
}
@Override
public boolean getIgnoreInitiallyColliding() {
return ignoreInitiallyColliding;
}
@Override
public void set(double x0, double y0, double z0, double x1, double y1, double z1) {
this.x0 = x0;