Skip to content

Commit

Permalink
More grace to velocity handling, configurable.
Browse files Browse the repository at this point in the history
Before full revert or recode: a moderate (smaller than
before) minimal grace amount for the counters is used now.
  • Loading branch information
asofold committed Feb 6, 2013
1 parent 261fca0 commit df005b4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
Expand Up @@ -110,6 +110,8 @@ public static MovingConfig getConfig(final Player player) {
public final double sfHoverViolation;

// Special tolerance values:
/** This is not strictly ticks, but packets, for now.*/
public final int velocityGraceTicks;
public final double noFallyOnGround;
public final double yOnGround;
public final double yStep;
Expand Down Expand Up @@ -168,6 +170,7 @@ public MovingConfig(final ConfigFile data) {
sfHoverFallDamage = data.getBoolean(ConfPaths.MOVING_SURVIVALFLY_HOVER_FALLDAMAGE);
sfHoverViolation = data.getDouble(ConfPaths.MOVING_SURVIVALFLY_HOVER_SFVIOLATION);

velocityGraceTicks = data.getInt(ConfPaths.MOVING_VELOCITY_GRACETICKS);
yOnGround = data.getDouble(ConfPaths.MOVING_YONGROUND, 0.001, 2.0, 0.0626); // sqrt(1/256), see: NetServerHandler.
noFallyOnGround = data.getDouble(ConfPaths.MOVING_NOFALL_YONGROUND, 0.001, 2.0, 0.3);
// ystep is set to 0.45 by default, for stairs / steps.
Expand Down
Expand Up @@ -87,11 +87,13 @@ public static void clear(){

// Velocity handling.
// TODO: consider resetting these with clearFlyData and onSetBack.
public int verticalVelocityCounter;
public double verticalFreedom;
public double verticalVelocity;
public int verticalVelocityCounter;
public double horizontalVelocityCounter;
public int verticalVelocityUsed = 0;
public int horizontalVelocityCounter;
public double horizontalFreedom;
public int horizontalVelocityUsed = 0;

// Coordinates.
/** Last from coordinates. */
Expand Down
Expand Up @@ -525,20 +525,28 @@ public void onPlayerMove(final PlayerMoveEvent event) {
// 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.
if (data.horizontalVelocityCounter > 0D){
data.horizontalVelocityUsed ++;
data.horizontalVelocityCounter--;
data.horizontalFreedom = Math.max(0.0, data.horizontalFreedom - 0.09);
}
else if (data.horizontalFreedom > 0.001D)
data.horizontalFreedom *= 0.90D;
else if (data.horizontalFreedom > 0.001D){
data.horizontalVelocityUsed ++;
data.horizontalFreedom *= 0.90D;
}

if (data.verticalVelocity <= 0.09D)
data.verticalVelocityCounter--;
if (data.verticalVelocity <= 0.09D){
data.verticalVelocityUsed ++;
data.verticalVelocityCounter--;
}
else if (data.verticalVelocityCounter > 0D) {
data.verticalVelocityUsed ++;
data.verticalFreedom += data.verticalVelocity;
data.verticalVelocity = Math.max(0.0, data.verticalVelocity -0.09);
} else if (data.verticalFreedom > 0.001D)
} else if (data.verticalFreedom > 0.001D){
// Counter has run out, now reduce the vertical freedom over time.
data.verticalVelocityUsed ++;
data.verticalFreedom *= 0.93D;
}

Location newTo = null;

Expand Down Expand Up @@ -884,15 +892,20 @@ public void onPlayerVelocity(final PlayerVelocityEvent event) {

double newVal = velocity.getY();
if (newVal >= 0D) {
if (data.verticalFreedom <= 0.001 && data.verticalVelocityCounter >= 0){
data.verticalVelocity = 0;
}
data.verticalVelocity += newVal;
data.verticalFreedom += data.verticalVelocity;
data.verticalVelocityCounter = Math.min(100, Math.max(data.verticalVelocityCounter, 0) + 1 + (int) Math.round(newVal * 10.0)); // 50;
data.verticalVelocityCounter = Math.min(100, Math.max(data.verticalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 50;
data.verticalVelocityUsed = 0;
}

newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ());
if (newVal > 0D) {
data.horizontalFreedom += newVal;
data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, 0) + 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;
data.horizontalVelocityUsed = 0;
}

// Set dirty flag here.
Expand Down Expand Up @@ -1106,9 +1119,11 @@ private final void onPlayerVehicleLeave(final Player player){
// Experiment: add some velocity (fake).
data.horizontalVelocityCounter = 1;
data.horizontalFreedom = 0.75;
data.horizontalVelocityUsed = 0;
data.verticalVelocityCounter = 1;
data.verticalFreedom = 1.2;
data.verticalVelocity = 0.1;
data.verticalVelocityUsed = 0;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand Down
Expand Up @@ -400,7 +400,7 @@ else if (resetFrom || data.noFallAssumeGround){
// Apply reset conditions.
data.toWasReset = resetTo || data.noFallAssumeGround;
data.fromWasReset = resetFrom || data.noFallAssumeGround;
if (yDistance <= 0 && data.sfLastYDist > 0){
if (data.verticalVelocityUsed > cc.velocityGraceTicks && yDistance <= 0 && data.sfLastYDist > 0){
// data.verticalFreedom = 0;
data.verticalVelocityCounter = 0;
data.verticalVelocity = 0;
Expand All @@ -411,14 +411,16 @@ else if (resetFrom || data.noFallAssumeGround){
data.sfJumpPhase = 0;
data.clearAccounting();
// TODO: Experimental: reset velocity.
if (toOnGround && yDistance < 0 || Math.abs(yDistance) < 0.09){
if (data.verticalVelocityUsed > cc.velocityGraceTicks && toOnGround && yDistance < 0){
data.verticalVelocityCounter = 0;
data.verticalFreedom = 0;
data.verticalVelocity = 0;
data.verticalVelocityUsed = 0;
}
if (hDistance < sprintingSpeed){
if (data.horizontalVelocityUsed > cc.velocityGraceTicks && hDistance < sprintingSpeed){
data.horizontalFreedom = 0;
data.horizontalVelocityCounter = 0;
data.horizontalVelocityUsed = 0;
}
}
else if (resetFrom){
Expand Down
Expand Up @@ -508,6 +508,9 @@ public abstract class ConfPaths {
public static final String MOVING_SURVIVALFLY_HOVER_SFVIOLATION = MOVING_SURVIVALFLY_HOVER + "sfviolation";

// Special (to be sorted in or factored out).
private static final String MOVING_VELOCITY = MOVING + "velocity.";
public static final String MOVING_VELOCITY_GRACETICKS = MOVING_VELOCITY + "graceticks";

public static final String MOVING_NOFALL_YONGROUND = MOVING_NOFALL + "yonground";
public static final String MOVING_YONGROUND = MOVING + "yonground";
public static final String MOVING_SURVIVALFLY_YSTEP = MOVING_SURVIVALFLY + "ystep";
Expand All @@ -534,5 +537,5 @@ public abstract class ConfPaths {
public static final String SUB_IGNOREPASSABLE = RootConfPaths.SUB_IGNOREPASSABLE;
public static final String SUB_ALLOWINSTANTBREAK = RootConfPaths.SUB_ALLOWINSTANTBREAK;
public static final String SUB_LAG = "lag";

}
Expand Up @@ -400,6 +400,9 @@ public DefaultConfig() {
set(ConfPaths.MOVING_SURVIVALFLY_HOVER_FALLDAMAGE, true);
set(ConfPaths.MOVING_SURVIVALFLY_HOVER_SFVIOLATION, 500);

// Special.
set(ConfPaths.MOVING_VELOCITY_GRACETICKS, 20);

/*
* dP"8 d8 ,e,
* C8b Y d88 888,8, " 888 8e e88 888 dP"Y
Expand Down

0 comments on commit df005b4

Please sign in to comment.