Skip to content

Commit

Permalink
Small reduction in idle CPU usage
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Jul 19, 2013
1 parent debc65f commit 57b4bab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/common/nallar/patched/server/PatchMinecraftServer.java
Expand Up @@ -168,6 +168,7 @@ public void run() {
} catch (Throwable t) {
FMLLog.log(Level.SEVERE, t, "Failed to set up Security Manager. This is probably not a huge problem - but it could indicate classloading issues.");
}
currentTick = (int) (System.currentTimeMillis() / 50);
if (this.startServer()) {
FMLLog.fine("calling handleServerStarted()");
FMLCommonHandler.instance().handleServerStarted();
Expand All @@ -177,24 +178,23 @@ public void run() {
for (Configuration configuration : toSaveConfigurationSet) {
configuration.save();
}
// This block is derived from Spigot code,
// LGPL
this.serverIsRunning = true;
if (TickThreading.instance.concurrentNetworkTicks) {
tickNetworkInMainThread = false;
new FakeServerThread(new NetworkTickRunnable(this), "Network Tick", false).start();
}
long lastTick = 0L;
long lastTime = 0L;
double currentMaxTPS = 0;
while (this.serverRunning) {
long curTime = System.nanoTime();
long wait = TARGET_TICK_TIME - (curTime - lastTick);
long wait = (TARGET_TICK_TIME - (curTime - lastTime)) / 1000000;
if (wait > 0 && currentMaxTPS > TARGET_TPS) {
Thread.sleep(wait / 1000000);
Thread.sleep(wait);
continue;
}
lastTick = curTime;
currentTick = ++tickCounter;
lastTime = curTime;
++currentTick;
++tickCounter;
try {
this.tick();
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/nallar/reporting/LeakDetector.java
Expand Up @@ -11,7 +11,7 @@
import nallar.unsafe.UnsafeUtil;

public class LeakDetector {
private final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(0);
private final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
private final long waitTimeSeconds;
private final Map<Long, LeakCheckEntry> scheduledObjects = new ConcurrentHashMap<Long, LeakCheckEntry>();

Expand Down
Expand Up @@ -63,7 +63,7 @@ private static String getTPSString(boolean withColour) {
double tps = MinecraftServer.getTPS();
double targetTPS = MinecraftServer.getTargetTPS();
double difference = Math.abs(targetTPS - tps);
int charsFirst = (int) ((tps / targetTPS) * tpsWidth);
int charsFirst = (int) Math.round((tps / targetTPS) * tpsWidth);
int charsAfter = tpsWidth - charsFirst;
StringBuilder sb = new StringBuilder();
sb
Expand Down

0 comments on commit 57b4bab

Please sign in to comment.