Add maximum activation ticks for velocity (queued).

This commit is contained in:
asofold 2013-03-13 02:55:24 +01:00
parent 310b62384f
commit bb38ff5a1b
6 changed files with 39 additions and 9 deletions

View File

@ -120,6 +120,7 @@ public class MovingConfig extends ACheckConfig {
/** This is not strictly ticks, but packets, for now.*/ /** This is not strictly ticks, but packets, for now.*/
public final int velocityGraceTicks; public final int velocityGraceTicks;
public final int velocityActivationCounter; public final int velocityActivationCounter;
public final int velocityActivationTicks;
public final double noFallyOnGround; public final double noFallyOnGround;
public final double yOnGround; public final double yOnGround;
public final double yStep; public final double yStep;
@ -185,6 +186,7 @@ public class MovingConfig extends ACheckConfig {
velocityGraceTicks = config.getInt(ConfPaths.MOVING_VELOCITY_GRACETICKS); velocityGraceTicks = config.getInt(ConfPaths.MOVING_VELOCITY_GRACETICKS);
velocityActivationCounter = config.getInt(ConfPaths.MOVING_VELOCITY_ACTIVATIONCOUNTER); velocityActivationCounter = config.getInt(ConfPaths.MOVING_VELOCITY_ACTIVATIONCOUNTER);
velocityActivationTicks = config.getInt(ConfPaths.MOVING_VELOCITY_ACTIVATIONTICKS);
yOnGround = config.getDouble(ConfPaths.MOVING_YONGROUND, 0.001, 2.0, 0.0626); // sqrt(1/256), see: NetServerHandler. yOnGround = config.getDouble(ConfPaths.MOVING_YONGROUND, 0.001, 2.0, 0.0626); // sqrt(1/256), see: NetServerHandler.
noFallyOnGround = config.getDouble(ConfPaths.MOVING_NOFALL_YONGROUND, 0.001, 2.0, yOnGround); noFallyOnGround = config.getDouble(ConfPaths.MOVING_NOFALL_YONGROUND, 0.001, 2.0, yOnGround);
// ystep is set to 0.45 by default, for stairs / steps. // ystep is set to 0.45 by default, for stairs / steps.

View File

@ -50,8 +50,8 @@ public class MovingData extends ACheckData {
} }
}; };
/** The map containing the data per players. */
private static Map<String, MovingData> playersMap = new HashMap<String, MovingData>(); private static Map<String, MovingData> playersMap = new HashMap<String, MovingData>();
/** The map containing the data per players. */
/** /**
* Gets the data of a specified player. * Gets the data of a specified player.
@ -440,8 +440,9 @@ public class MovingData extends ACheckData {
/** /**
* Remove all velocity entries that are invalid. Checks both active and queued. * Remove all velocity entries that are invalid. Checks both active and queued.
* <br>(This does not catch invalidation by speed / direction changing.) * <br>(This does not catch invalidation by speed / direction changing.)
* @param tick All velocity added before this tick gets removed.
*/ */
public void removeInvalidVelocity() { public void removeInvalidVelocity(final int tick) {
// TODO: Also merge entries here, or just on adding? // TODO: Also merge entries here, or just on adding?
Iterator<Velocity> it; Iterator<Velocity> it;
// Active. // Active.
@ -449,13 +450,14 @@ public class MovingData extends ACheckData {
while (it.hasNext()){ while (it.hasNext()){
final Velocity vel = it.next(); final Velocity vel = it.next();
// TODO: 0.001 can be stretched somewhere else, most likely... // TODO: 0.001 can be stretched somewhere else, most likely...
// TODO: Somehow use tick here too (actCount, valCount)?
if (vel.valCount <= 0 || vel.value <= 0.001) it.remove(); if (vel.valCount <= 0 || vel.value <= 0.001) it.remove();
} }
// Queued. // Queued.
it = hVelQueued.iterator(); it = hVelQueued.iterator();
while (it.hasNext()){ while (it.hasNext()){
final Velocity vel = it.next(); final Velocity vel = it.next();
if (vel.actCount <= 0) it.remove(); if (vel.actCount <= 0 || vel.tick < tick) it.remove();
} }
} }
@ -463,13 +465,13 @@ public class MovingData extends ACheckData {
* Called for moving events, increase age of velocity. * Called for moving events, increase age of velocity.
*/ */
public void velocityTick(){ public void velocityTick(){
// Increase counts for active. // Decrease counts for active.
for (final Velocity vel : hVelActive){ for (final Velocity vel : hVelActive){
vel.actCount --; vel.actCount --;
vel.sum += vel.value; vel.sum += vel.value;
vel.value *= 0.9; // TODO: Actual friction. vel.value *= 0.9; // TODO: Actual friction.
} }
// Increase counts for queued. // Decrease counts for queued.
final Iterator<Velocity> it = hVelQueued.iterator(); final Iterator<Velocity> it = hVelQueued.iterator();
while (it.hasNext()){ while (it.hasNext()){
it.next().actCount --; it.next().actCount --;
@ -509,6 +511,7 @@ public class MovingData extends ACheckData {
break; break;
} }
} }
// TODO: Add to sum.
return used; return used;
} }

View File

@ -64,6 +64,7 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.CheckUtils; import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation; import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.TickTask;
import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
/* /*
@ -517,7 +518,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do // Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do
// general data modifications one for each event. // general data modifications one for each event.
// TODO: Rework to queued velocity entries: activation + invalidation // TODO: Rework to queued velocity entries: activation + invalidation
data.removeInvalidVelocity(); data.removeInvalidVelocity(TickTask.getTick() - cc.velocityActivationTicks);
data.velocityTick(); data.velocityTick();
// // Horizontal velocity. // // Horizontal velocity.
// if (data.horizontalVelocityCounter > 0D){ // if (data.horizontalVelocityCounter > 0D){
@ -979,10 +980,12 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
data.removeAllVelocity(); data.removeAllVelocity();
return; return;
} }
data.removeInvalidVelocity();
final MovingConfig cc = MovingConfig.getConfig(player); final MovingConfig cc = MovingConfig.getConfig(player);
final int tick = TickTask.getTick();
data.removeInvalidVelocity(tick - cc.velocityActivationTicks);
final Vector velocity = event.getVelocity(); final Vector velocity = event.getVelocity();
if (cc.debug) System.out.println(event.getPlayer().getName() + " new velocity: " + velocity); if (cc.debug) System.out.println(event.getPlayer().getName() + " new velocity: " + velocity);
@ -1003,7 +1006,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ()); newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ());
if (newVal > 0D) { if (newVal > 0D) {
used = true; used = true;
final Velocity vel = new Velocity(newVal, cc.velocityActivationCounter, 1 + (int) Math.round(newVal * 10.0)); final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, 1 + (int) Math.round(newVal * 10.0));
data.addHorizontalVelocity(vel); data.addHorizontalVelocity(vel);
// data.horizontalFreedom += newVal; // data.horizontalFreedom += newVal;
// data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 30; // data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 30;

View File

@ -1,5 +1,8 @@
package fr.neatmonster.nocheatplus.checks.moving; package fr.neatmonster.nocheatplus.checks.moving;
import fr.neatmonster.nocheatplus.utilities.TickTask;
/** /**
* One entry of velocity for a player. Might be used per axis or for horizontal/vertical. * One entry of velocity for a player. Might be used per axis or for horizontal/vertical.
* @author mc_dev * @author mc_dev
@ -7,6 +10,9 @@ package fr.neatmonster.nocheatplus.checks.moving;
*/ */
public class Velocity { public class Velocity {
/** Tick at which velocity got added. */
public final int tick;
/** The amount of velocity, decreasing with use. */ /** The amount of velocity, decreasing with use. */
public double value; public double value;
/** "Some sum" for general purpose. /** "Some sum" for general purpose.
@ -43,10 +49,24 @@ public class Velocity {
public Velocity(double value, int actCount, int valCount){ public Velocity(double value, int actCount, int valCount){
this.tick = TickTask.getTick();
this.value = value; this.value = value;
this.actCount = actCount; this.actCount = actCount;
this.valCount = valCount; this.valCount = valCount;
} }
public Velocity(int tick, double value, int actCount, int valCount){
this.tick = tick;
this.value = value;
this.actCount = actCount;
this.valCount = valCount;
}
} }

View File

@ -552,6 +552,7 @@ public abstract class ConfPaths {
private static final String MOVING_VELOCITY = MOVING + "velocity."; private static final String MOVING_VELOCITY = MOVING + "velocity.";
public static final String MOVING_VELOCITY_GRACETICKS = MOVING_VELOCITY + "graceticks"; public static final String MOVING_VELOCITY_GRACETICKS = MOVING_VELOCITY + "graceticks";
public static final String MOVING_VELOCITY_ACTIVATIONCOUNTER = MOVING_VELOCITY + "activationcounter"; public static final String MOVING_VELOCITY_ACTIVATIONCOUNTER = MOVING_VELOCITY + "activationcounter";
public static final String MOVING_VELOCITY_ACTIVATIONTICKS = MOVING_VELOCITY + "activationticks";
public static final String MOVING_NOFALL_YONGROUND = MOVING_NOFALL + "yonground"; public static final String MOVING_NOFALL_YONGROUND = MOVING_NOFALL + "yonground";
public static final String MOVING_YONGROUND = MOVING + "yonground"; public static final String MOVING_YONGROUND = MOVING + "yonground";

View File

@ -432,6 +432,7 @@ public class DefaultConfig extends ConfigFile {
// Special. // Special.
set(ConfPaths.MOVING_VELOCITY_GRACETICKS, 20); set(ConfPaths.MOVING_VELOCITY_GRACETICKS, 20);
set(ConfPaths.MOVING_VELOCITY_ACTIVATIONCOUNTER, 80); set(ConfPaths.MOVING_VELOCITY_ACTIVATIONCOUNTER, 80);
set(ConfPaths.MOVING_VELOCITY_ACTIVATIONTICKS, 140);
/* /*
* dP"8 d8 ,e, * dP"8 d8 ,e,