optimized mob ai thread
This commit is contained in:
@@ -28,18 +28,26 @@ public class MobAIThread implements Runnable{
|
|||||||
AI_BASE_AGGRO_RANGE = (int)(60 * Float.parseFloat(ConfigManager.MB_AI_AGGRO_RANGE.getValue()));
|
AI_BASE_AGGRO_RANGE = (int)(60 * Float.parseFloat(ConfigManager.MB_AI_AGGRO_RANGE.getValue()));
|
||||||
while (true) {
|
while (true) {
|
||||||
for (Zone zone : ZoneManager.getAllZones()) {
|
for (Zone zone : ZoneManager.getAllZones()) {
|
||||||
|
if (zone != null && zone.zoneMobSet != null) {
|
||||||
for (Mob mob : zone.zoneMobSet) {
|
synchronized (zone.zoneMobSet) {
|
||||||
|
for (Mob mob : zone.zoneMobSet) {
|
||||||
try {
|
try {
|
||||||
if (mob != null)
|
if (mob != null) {
|
||||||
MobAI.DetermineAction(mob);
|
MobAI.DetermineAction(mob);
|
||||||
} catch (Exception e) {
|
}
|
||||||
Logger.error("Mob: " + mob.getName() + " UUID: " + mob.getObjectUUID() + " ERROR: " + e);
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error processing Mob [Name: {}, UUID: {}]", mob.getName(), mob.getObjectUUID(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Logger.error("AI Thread interrupted", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void startAIThread() {
|
public static void startAIThread() {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class BaneThread implements Runnable {
|
|||||||
lastRun = System.currentTimeMillis(); // Update lastRun after processing
|
lastRun = System.currentTimeMillis(); // Update lastRun after processing
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100); // Pause for 10ms to reduce CPU usage
|
Thread.sleep(100); // Pause for 100ms to reduce CPU usage
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Logger.error("Thread interrupted", e);
|
Logger.error("Thread interrupted", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|||||||
Reference in New Issue
Block a user