Skip to content

Commit

Permalink
Attempt to fix issues with too low valid-count for velocity.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Mar 13, 2013
1 parent 25e4cb3 commit a5ed780
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Expand Up @@ -451,13 +451,19 @@ public void removeInvalidVelocity(final int tick) {
final Velocity vel = it.next();
// 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){
// System.out.prsintln("Invalidate active: " + vel);
it.remove();
}
}
// Queued.
it = hVelQueued.iterator();
while (it.hasNext()){
final Velocity vel = it.next();
if (vel.actCount <= 0 || vel.tick < tick) it.remove();
if (vel.actCount <= 0 || vel.tick < tick){
// System.out.println("Invalidate queued: " + vel);
it.remove();
}
}
}

Expand All @@ -466,10 +472,12 @@ public void removeInvalidVelocity(final int tick) {
*/
public void velocityTick(){
// Decrease counts for active.
// TODO: Consider removing already invalidated here.
for (final Velocity vel : hVelActive){
vel.valCount --;
vel.sum += vel.value;
vel.value *= 0.9; // TODO: Actual friction.
vel.value *= 0.93; // TODO: Actual friction.
// (Altered entries should be kept, since they get used right away.)
}
// Decrease counts for queued.
final Iterator<Velocity> it = hVelQueued.iterator();
Expand Down
Expand Up @@ -1006,7 +1006,7 @@ public void onPlayerVelocity(final PlayerVelocityEvent event) {
newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ());
if (newVal > 0D) {
used = true;
final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, 1 + (int) Math.round(newVal * 10.0));
final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, Math.max(20, 1 + (int) Math.round(newVal * 10.0)));
data.addHorizontalVelocity(vel);
// data.horizontalFreedom += newVal;
// data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 30;
Expand Down
Expand Up @@ -158,6 +158,7 @@ else if (yDistance < -0.5){
// Judge if horizontal speed is above limit.
// double hDistanceAboveLimit = hDistance - hAllowedDistance - data.horizontalFreedom;
double hDistanceAboveLimit = hDistance - hAllowedDistance;
double hFreedom = 0; // Horizontal velocity used (!).
if (hDistanceAboveLimit > 0){
// Check extra buffer (!).
final double extraUsed;
Expand All @@ -174,7 +175,6 @@ else if (yDistance < -0.5){
extraUsed = 0.0;
}
// Check velocity.
double hFreedom; // Horizontal freedom if used (!).
if (hDistanceAboveLimit > 0){
hFreedom = data.getHorizontalFreedom();
if (hFreedom < hDistanceAboveLimit){
Expand All @@ -186,6 +186,7 @@ else if (yDistance < -0.5){
}
}
else{
// System.out.println("*** Invalidate velocity on not used (extra)");
data.hVelActive.clear(); // TODO: test/check !
hFreedom = 0;
}
Expand All @@ -207,6 +208,7 @@ else if (yDistance < -0.5){
}
}
else{
// System.out.println("*** Invalidate velocity on not used (normal)");
data.hVelActive.clear(); // TODO: test/check !
data.sfHBufExtra = 0;
}
Expand Down Expand Up @@ -290,7 +292,7 @@ else if (yDistance < -0.5){
if (silentSetBack != null){
if (cc.debug) {
tags.add("silentsbcobweb");
outputDebug(player, to, data, cc, hDistance, hAllowedDistance, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo);
outputDebug(player, to, data, cc, hDistance, hAllowedDistance, hFreedom, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo);
}
return silentSetBack;
}
Expand Down Expand Up @@ -438,7 +440,7 @@ else if (!data.sfDirty){

if (cc.debug) {
// Put in a method for shorter code.
outputDebug(player, to, data, cc, hDistance, hAllowedDistance, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo);
outputDebug(player, to, data, cc, hDistance, hAllowedDistance, hFreedom, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo);
}

data.sfJumpPhase++;
Expand Down Expand Up @@ -533,6 +535,7 @@ else if (resetFrom){
// Check removal of active horizontal velocity.
if (hDistance <= hAllowedDistance){ // TODO: Check conditions etc.
// Invalidate used horizontal velocity.
// System.out.println("*** INVALIDATE ON SPEED");
data.hVelActive.clear();
// if (data.horizontalVelocityUsed > cc.velocityGraceTicks){
// data.horizontalFreedom = 0;
Expand Down Expand Up @@ -560,14 +563,15 @@ else if (resetFrom){
* @param resetTo
*/
private void outputDebug(final Player player, final PlayerLocation to, final MovingData data, final MovingConfig cc,
final double hDistance, final double hAllowedDistance, final double yDistance, final double vAllowedDistance,
final double hDistance, final double hAllowedDistance, final double hFreedom, final double yDistance, final double vAllowedDistance,
final boolean fromOnGround, final boolean resetFrom, final boolean toOnGround, final boolean resetTo) {
// TODO: Show player name once (!)
final StringBuilder builder = new StringBuilder(500);
final String hBuf = (data.sfHorizontalBuffer < 1.0 ? ((" hbuf=" + StringUtil.fdec3.format(data.sfHorizontalBuffer))) : "");
final String hBufExtra = (data.sfHBufExtra > 0 ? (" hbufextra=" + data.sfHBufExtra) : "");
final String hVelUsed = hFreedom > 0 ? " hVelUsed=" + StringUtil.fdec3.format(hFreedom) : "";
builder.append(player.getName() + " SurvivalFly\nground: " + (data.noFallAssumeGround ? "(assumeonground) " : "") + (fromOnGround ? "onground -> " : (resetFrom ? "resetcond -> " : "--- -> ")) + (toOnGround ? "onground" : (resetTo ? "resetcond" : "---")) + ", jumpphase: " + data.sfJumpPhase);
builder.append("\n" + " hDist: " + StringUtil.fdec3.format(hDistance) + " / " + StringUtil.fdec3.format(hAllowedDistance) + hBuf + hBufExtra + " , vDist: " + StringUtil.fdec3.format(yDistance) + " (" + StringUtil.fdec3.format(to.getY() - data.getSetBackY()) + " / " + StringUtil.fdec3.format(vAllowedDistance) + "), sby=" + (data.hasSetBack() ? data.getSetBackY() : "?"));
builder.append("\n" + " hDist: " + StringUtil.fdec3.format(hDistance) + " / " + StringUtil.fdec3.format(hAllowedDistance) + hBuf + hBufExtra + hVelUsed + " , vDist: " + StringUtil.fdec3.format(yDistance) + " (" + StringUtil.fdec3.format(to.getY() - data.getSetBackY()) + " / " + StringUtil.fdec3.format(vAllowedDistance) + "), sby=" + (data.hasSetBack() ? data.getSetBackY() : "?"));
if (data.verticalVelocityCounter > 0 || data.verticalFreedom >= 0.001){
builder.append("\n" + " vertical freedom: " + StringUtil.fdec3.format(data.verticalFreedom) + " (vel=" + StringUtil.fdec3.format(data.verticalVelocity) + "/counter=" + data.verticalVelocityCounter +"/used="+data.verticalVelocityUsed);
}
Expand All @@ -594,7 +598,8 @@ private void outputDebug(final Player player, final PlayerLocation to, final Mov

private void addVeloctiy(final StringBuilder builder, final List<Velocity> entries) {
for (final Velocity vel: entries){
builder.append(" value=" + vel.value + " counter=" + vel.actCount);
builder.append(" ");
builder.append(vel);
}
}

Expand Down
Expand Up @@ -69,4 +69,8 @@ public Velocity(int tick, double value, int actCount, int valCount){
this.valCount = valCount;
}

public String toString(){
return "Velocity(tick=" + tick + " sum=" + sum + " value=" + value + " valid=" + valCount + " activate=" + actCount + ")";
}

}

0 comments on commit a5ed780

Please sign in to comment.