Browse Source

optimized bane thread

lakebane
FatBoy-DOTC 14 hours ago
parent
commit
e86749febd
  1. 23
      src/engine/workthreads/BaneThread.java

23
src/engine/workthreads/BaneThread.java

@ -27,8 +27,8 @@ import java.util.ArrayList;
public class BaneThread implements Runnable { public class BaneThread implements Runnable {
public Long lastRun; private volatile Long lastRun;
public static int instancedelay = 10000; public static final Long instancedelay = 1000L;
public BaneThread() { public BaneThread() {
Logger.info(" BaneThread thread has started!"); Logger.info(" BaneThread thread has started!");
} }
@ -37,14 +37,16 @@ public class BaneThread implements Runnable {
public void processBanesWindow() { public void processBanesWindow() {
try { try {
for(int baneId : Bane.banes.keySet()){ synchronized (Bane.banes) {
Bane bane = Bane.banes.get(baneId); for (int baneId : Bane.banes.keySet()) {
if(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)){ Bane bane = Bane.banes.get(baneId);
bane.applyZergBuffs(); if (bane != null && bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) {
bane.applyZergBuffs();
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
Logger.error("BANE ERROR"); Logger.error("BANE ERROR",e);
} }
@ -56,6 +58,13 @@ public class BaneThread implements Runnable {
if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition
this.processBanesWindow(); this.processBanesWindow();
lastRun = System.currentTimeMillis(); // Update lastRun after processing lastRun = System.currentTimeMillis(); // Update lastRun after processing
}else {
try {
Thread.sleep(100); // Pause for 10ms to reduce CPU usage
} catch (InterruptedException e) {
Logger.error("Thread interrupted", e);
Thread.currentThread().interrupt();
}
} }
} }
} }

Loading…
Cancel
Save