Skip to content

Commit

Permalink
(mc1.20.4+) Fixed /tick warp status shows wrong tps / mspt
Browse files Browse the repository at this point in the history
sprintStartTime is not sprint start time
  • Loading branch information
Fallen-Breath committed Jul 25, 2024
1 parent d72eeaf commit a4784b5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ public long getRemainingTicks()
}

@Override
public long getStartTime()
public long getElapsedTime()
{
return TickSpeed.time_warp_start_time;
}

@Override
public long getCurrentTime()
{
return System.nanoTime();
return System.nanoTime() - TickSpeed.time_warp_start_time;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MemorizedTickWarpInfo implements TickWarpInfo
private final TickWarpInfo delegate;
private long totalTicks;
private long timeRemaining;
private long startTime;
private long elapsedTime;
private boolean recordedSomething = false;
private long lastRecordingTime;
private ServerCommandSource lastTimeAdvancer;
Expand All @@ -58,11 +58,11 @@ public void setTimeAdvancer(@Nullable ServerCommandSource timeAdvancer)
*/
public void recordResultIfsuitable()
{
if (this.delegate.getStartTime() != 0)
if (this.delegate.getTotalTicks() != 0)
{
this.totalTicks = this.delegate.getTotalTicks();
this.timeRemaining = this.delegate.getRemainingTicks();
this.startTime = this.delegate.getStartTime();
this.elapsedTime = this.delegate.getElapsedTime();
this.lastTimeAdvancer = this.delegate.getTimeAdvancer();
this.recordedSomething = true;
this.lastRecordingTime = System.nanoTime();
Expand All @@ -88,9 +88,9 @@ public long getRemainingTicks()
}

@Override
public long getStartTime()
public long getElapsedTime()
{
return this.startTime;
return this.elapsedTime;
}

@Override
Expand All @@ -100,12 +100,6 @@ public ServerCommandSource getTimeAdvancer()
return this.lastTimeAdvancer;
}

@Override
public long getCurrentTime()
{
return this.lastRecordingTime;
}

public boolean hasData()
{
return this.recordedSomething;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public interface TickWarpInfoReader

long getRemainingTicks();

long getStartTime();

long getCurrentTime();
long getElapsedTime();

// ----------------------- utilities methods -----------------------

Expand All @@ -43,7 +41,7 @@ default long getCompletedTicks()

default double getAverageMSPT()
{
double milliSeconds = Math.max(this.getCurrentTime() - this.getStartTime(), 1) / 1e6;
double milliSeconds = Math.max(this.getElapsedTime(), 1) / 1e6;
return milliSeconds / this.getCompletedTicks();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public long getRemainingTicks()
}

@Override
public long getStartTime()
public long getElapsedTime()
{
return trm().map(ServerTickRateManagerAccessor::getTickWarpStartTime).orElse(0L);
}

@Override
public long getCurrentTime()
{
return System.nanoTime();
return trm().map(m -> {
//#if MC >= 12003
//$$ return m.getTickWarpElapsedTime();
//#else
return System.nanoTime() - m.getTickWarpStartTime();
//#endif
}).orElse(0L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public interface ServerTickRateManagerAccessor
@Accessor(value = "sprintTicks")
long getRemainingWarpTicks();

@Accessor(value = "sprintStartTime")
long getTickWarpStartTime();
@Accessor(value = "sprintTime")
long getTickWarpElapsedTime();

@Accessor(value = "scheduledSprintTicks")
long getScheduledCurrentWarpTicks();
Expand Down

0 comments on commit a4784b5

Please sign in to comment.