Browse Source

mob respawning handled in its own thread

master
FatBoy-DOTC 1 year ago
parent
commit
7f1e537975
  1. 7
      src/engine/ai/MobileFSMManager.java
  2. 3
      src/engine/objects/Zone.java
  3. 9
      src/engine/server/world/WorldServer.java
  4. 74
      src/engine/workthreads/MobRespawnThread.java

7
src/engine/ai/MobileFSMManager.java

@ -94,13 +94,6 @@ public class MobileFSMManager { @@ -94,13 +94,6 @@ public class MobileFSMManager {
for (Zone zone : ZoneManager.getAllZones()) {
if(zone.respawnQue.size() > 0 && zone.lastRespawn + 100 < System.currentTimeMillis()){
if(zone.respawnQue.get(0) != null) {
zone.respawnQue.get(0).respawn();
zone.respawnQue.remove(0);
zone.lastRespawn = System.currentTimeMillis();
}
}
for (Mob mob : zone.zoneMobSet) {
try {

3
src/engine/objects/Zone.java

@ -58,7 +58,8 @@ public class Zone extends AbstractGameObject { @@ -58,7 +58,8 @@ public class Zone extends AbstractGameObject {
private String hash;
private float worldAltitude = 0;
private float seaLevel = 0;
public static ArrayList<Mob> respawnQue = new ArrayList<>();
//public static ArrayList<Mob> respawnQue = new ArrayList<>();
public static final Set<Mob> respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>());
public static long lastRespawn = 0;
/**
* ResultSet Constructor

9
src/engine/server/world/WorldServer.java

@ -18,6 +18,7 @@ import engine.InterestManagement.HeightMap; @@ -18,6 +18,7 @@ import engine.InterestManagement.HeightMap;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSMManager;
import engine.workthreads.MobRespawnThread;
import engine.db.archive.DataWarehouse;
import engine.exception.MsgSendException;
import engine.gameManager.*;
@ -57,6 +58,7 @@ import java.net.InetAddress; @@ -57,6 +58,7 @@ import java.net.InetAddress;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -479,7 +481,10 @@ public class WorldServer { @@ -479,7 +481,10 @@ public class WorldServer {
Logger.info("Initializing Client Connection Manager");
initClientConnectionManager();
//intiate mob respawn thread
Logger.info("Starting network Dispatcher");
MobRespawnThread.startRespawnThread();
// Run maintenance
MaintenanceManager.dailyMaintenance();
@ -494,7 +499,7 @@ public class WorldServer { @@ -494,7 +499,7 @@ public class WorldServer {
// Calculate bootstrap time and rest boot time to current time.
java.time.Duration bootDuration = java.time.Duration.between(LocalDateTime.now(), bootTime);
Duration bootDuration = Duration.between(LocalDateTime.now(), bootTime);
long bootSeconds = Math.abs(bootDuration.getSeconds());
String boottime = String.format("%d hours %02d minutes %02d seconds", bootSeconds / 3600, (bootSeconds % 3600) / 60, (bootSeconds % 60));
Logger.info("Bootstrap time was " + boottime);

74
src/engine/workthreads/MobRespawnThread.java

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.workthreads;
import engine.Enum.DispatchChannel;
import engine.gameManager.ZoneManager;
import engine.net.Dispatch;
import engine.objects.Mob;
import engine.objects.Zone;
import org.pmw.tinylog.Logger;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* Thread blocks until MagicBane dispatch messages are
* enqueued then processes them in FIFO order. The collection
* is thread safe.
* <p>
* Any large messages not time sensitive such as load object
* sent to more than a single individual should be spawned
* individually on a DispatchMessageThread.
*/
public class MobRespawnThread implements Runnable {
// Instance variables
// Thread constructor
public MobRespawnThread() {
Logger.info(" MobRespawnThread thread has started!");
}
@Override
public void run() {
for (Zone zone : ZoneManager.getAllZones()) {
if (zone.respawnQue.isEmpty() == false && zone.lastRespawn + 100 < System.currentTimeMillis()) {
if (zone.respawnQue.iterator().next() != null) {
Mob respawner = zone.respawnQue.iterator().next();
respawner.respawn();
zone.respawnQue.remove(respawner);
zone.lastRespawn = System.currentTimeMillis();
}
}
}
}
public static void startRespawnThread() {
Thread respawnThread;
respawnThread = new Thread(new PurgeOprhans());
respawnThread.setName("respawnThread");
respawnThread.start();
}
}
Loading…
Cancel
Save