Added a serverside uptime tick counter
This commit is contained in:
parent
c49fdfa5ff
commit
32851b8fb0
@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.progressia.server;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@ -183,6 +183,18 @@ public class Server {
|
||||
return this.serverThread.getTicker().getTPS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of ticks performed since the server has started. This
|
||||
* value resets on shutdowns. The counter is incremented at the end of a
|
||||
* tick.
|
||||
*
|
||||
* @return the number of times the world has finished a tick since the
|
||||
* server has started.
|
||||
*/
|
||||
public long getUptimeTicks() {
|
||||
return this.serverThread.getTicker().getUptimeTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link WorldAccessor} object for this server. Use the
|
||||
* provided accessor to
|
||||
|
@ -82,6 +82,7 @@ public class TickerCoordinator {
|
||||
private boolean isTickStartSet = false;
|
||||
private long tickStart = -1;
|
||||
private double tickLength = 1.0 / 20; // Do something about it
|
||||
private long ticks = 0;
|
||||
|
||||
private final Logger logger = LogManager.getLogger("Ticker Coordinator");
|
||||
|
||||
@ -151,6 +152,10 @@ public class TickerCoordinator {
|
||||
public double getTPS() {
|
||||
return 1 / tickLength;
|
||||
}
|
||||
|
||||
public long getUptimeTicks() {
|
||||
return ticks;
|
||||
}
|
||||
|
||||
private void onTickStart() {
|
||||
long now = System.currentTimeMillis();
|
||||
@ -163,6 +168,10 @@ public class TickerCoordinator {
|
||||
|
||||
tickStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void onTickEnd() {
|
||||
ticks++;
|
||||
}
|
||||
|
||||
/*
|
||||
* runOneTick & Friends
|
||||
@ -182,6 +191,8 @@ public class TickerCoordinator {
|
||||
logger.debug("Pass complete");
|
||||
passes++;
|
||||
}
|
||||
|
||||
onTickEnd();
|
||||
|
||||
logger.debug("Tick complete; run {} passes", passes);
|
||||
|
||||
@ -191,7 +202,7 @@ public class TickerCoordinator {
|
||||
// ...or almost silently
|
||||
logger.debug("Tick interrupted. WTF?");
|
||||
} catch (Exception e) {
|
||||
crash(e, "Coordinator");
|
||||
throw CrashReports.report(e, "Coordinator");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user