diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index f38b502e..45dbfc77 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -68,7 +68,7 @@ public enum MovementManager { if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) { if (((PlayerCharacter) toMove).isCasting()) - ((PlayerCharacter) toMove).update(); + ((PlayerCharacter) toMove).update(false); } @@ -96,7 +96,7 @@ public enum MovementManager { if (!toMove.isMoving()) toMove.resetLastSetLocUpdate(); else - toMove.update(); + toMove.update(false); // Update movement for the player @@ -351,7 +351,7 @@ public enum MovementManager { ChatManager.chatSystemInfo((PlayerCharacter) ac, "Finished Alt change, setting the end location to " + ac.getEndLoc().getX() + ' ' + ac.getEndLoc().getZ() + " moving=" + ac.isMoving() + " and current location is " + curLoc.getX() + ' ' + curLoc.getZ()); //Send run/walk/sit/stand to tell the client we are flying / landing etc - ac.update(); + ac.update(false); ac.stopMovement(ac.getLoc()); if (ac.isAlive()) MovementManager.sendRWSSMsg(ac); @@ -408,7 +408,7 @@ public enum MovementManager { if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None)) continue; - member.update(); + member.update(false); // All checks passed, let's move the player diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index eea98874..6065a4b1 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -8,7 +8,6 @@ package engine.gameManager; -import com.sun.corba.se.spi.orbutil.fsm.ActionBase; import engine.Enum.*; import engine.InterestManagement.HeightMap; import engine.InterestManagement.WorldGrid; @@ -28,7 +27,6 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.objects.*; import engine.powers.*; -import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.powers.poweractions.AbstractPowerAction; import engine.powers.poweractions.TrackPowerAction; import engine.server.MBServerStatics; @@ -179,7 +177,7 @@ public enum PowersManager { if (pc != null) { sendPowerMsg(pc, 2, msg); if (pc.isCasting()) { - pc.update(); + pc.update(false); } pc.setIsCasting(false); @@ -591,7 +589,7 @@ public enum PowersManager { // make person casting stand up if spell (unless they're casting a chant which does not make them stand up) if (pb.isSpell() && !pb.isChant() && playerCharacter.isSit()) { - playerCharacter.update(); + playerCharacter.update(false); playerCharacter.setSit(false); UpdateStateMsg updateStateMsg = new UpdateStateMsg(playerCharacter); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); @@ -614,7 +612,7 @@ public enum PowersManager { if (time > 100) { - playerCharacter.update(); + playerCharacter.update(false); playerCharacter.setIsCasting(true); } @@ -792,7 +790,7 @@ public enum PowersManager { playerCharacter.removeEffectBySource(EffectSourceType.Root,40,true); } if (playerCharacter.isCasting()) { - playerCharacter.update(); + playerCharacter.update(false); playerCharacter.updateStamRegen(-100); } @@ -2318,7 +2316,7 @@ public enum PowersManager { // set player is not casting for regens if (pc.isCasting()) { - pc.update(); + pc.update(false); } pc.setIsCasting(false); diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 3d00bf0b..1651e5c9 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -151,7 +151,7 @@ public enum SimulationManager { if (player == null) continue; - player.update(); + player.update(false); } _updatePulseTime = System.currentTimeMillis() + 500; diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index af741596..6b5739ec 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -85,7 +85,7 @@ public class ClientMessagePump implements NetMsgHandler { if (pc == null) return; - pc.update(); + pc.update(false); if (msg.getSpeed() == 2) pc.setWalkMode(false); else @@ -114,7 +114,7 @@ public class ClientMessagePump implements NetMsgHandler { if (pc == null) return; - pc.update(); + pc.update(false); pc.setSit(msg.toggleSitStand()); diff --git a/src/engine/net/client/handlers/ChangeAltitudeHandler.java b/src/engine/net/client/handlers/ChangeAltitudeHandler.java index d46742c8..db4a0e78 100644 --- a/src/engine/net/client/handlers/ChangeAltitudeHandler.java +++ b/src/engine/net/client/handlers/ChangeAltitudeHandler.java @@ -70,7 +70,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler { if (pc.getAltitude() == 0 && !msg.up()) return true; - pc.update(); + pc.update(false); pc.stopMovement(pc.getLoc()); msg.setStartAlt(pc.getAltitude()); if (msg.up()) { @@ -135,7 +135,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler { } if (msg.up()) { - pc.update(); + pc.update(false); pc.setDesiredAltitude(targetAlt); pc.setTakeOffTime(System.currentTimeMillis()); } else { @@ -161,7 +161,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler { } else pc.setDesiredAltitude(targetAlt); - pc.update(); + pc.update(false); pc.setTakeOffTime(System.currentTimeMillis()); diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index e81b6513..c8ee2164 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -31,7 +31,6 @@ import engine.net.ByteBufferWriter; import engine.net.DispatchMessage; import engine.net.client.msg.UpdateStateMsg; import engine.powers.EffectsBase; -import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -1841,7 +1840,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } //updates - public void update() { + public void update(Boolean newSystem) { } public void updateRegen() { @@ -1861,16 +1860,16 @@ public abstract class AbstractCharacter extends AbstractWorldObject { try { switch (updateType) { case ALL: - update(); + update(false); break; case REGEN: updateRegen(); break; case LOCATION: - update(); + update(false); break; case MOVEMENTSTATE: - update(); + update(false); break; case FLIGHT: updateFlight(); diff --git a/src/engine/objects/AbstractWorldObject.java b/src/engine/objects/AbstractWorldObject.java index 97d8a5d1..ac06b52a 100644 --- a/src/engine/objects/AbstractWorldObject.java +++ b/src/engine/objects/AbstractWorldObject.java @@ -270,7 +270,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { this.effects.remove(name); if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) if (name.equals("Flight")) { - ((PlayerCharacter) this).update(); + ((PlayerCharacter) this).update(false); PlayerCharacter.GroundPlayer((PlayerCharacter) this); } } @@ -385,7 +385,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { if (source.equals("Flight")) { //ground player if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - ((PlayerCharacter) this).update(); + ((PlayerCharacter) this).update(false); PlayerCharacter.GroundPlayer((PlayerCharacter) this); } } @@ -414,7 +414,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { if (source.equals("Flight")) { //ground player if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - ((PlayerCharacter) this).update(); + ((PlayerCharacter) this).update(false); PlayerCharacter.GroundPlayer((PlayerCharacter) this); } } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index e423ada1..36162ef9 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -26,7 +26,6 @@ import engine.job.JobScheduler; import engine.jobs.DeferredPowerJob; import engine.jobs.FinishSpireEffectJob; import engine.jobs.NoTimeJob; -import engine.jobs.RefreshGroupJob; import engine.math.Bounds; import engine.math.FastMath; import engine.math.Vector3fImmutable; @@ -2102,7 +2101,7 @@ public class PlayerCharacter extends AbstractCharacter { this.lastUpdateTime = System.currentTimeMillis(); this.lastStamUpdateTime = System.currentTimeMillis(); - this.update(); + this.update(false); PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, false); @@ -2923,7 +2922,7 @@ public class PlayerCharacter extends AbstractCharacter { public synchronized void grantXP(int xp) { if(this.promotionClass == null && this.level == 10){ this.setOverFlowEXP(0); - this.update(); + this.update(false); this.incVer(); this.recalculate(); this.calculateMaxHealthManaStamina(); @@ -3084,7 +3083,7 @@ public class PlayerCharacter extends AbstractCharacter { } if (charReloadRequired) { - this.update(); + this.update(false); this.incVer(); this.recalculate(); this.calculateMaxHealthManaStamina(); @@ -3157,7 +3156,7 @@ public class PlayerCharacter extends AbstractCharacter { bonus += this.bonuses.getFloatPercentNullZero(ModType.Speed, SourceType.None); // TODO get equip bonus - this.update(); + this.update(false); this.speedMod = bonus; } @@ -4839,7 +4838,10 @@ public class PlayerCharacter extends AbstractCharacter { } @Override - public void update() { + public void update(Boolean newSystem) { + + if(!newSystem) + return; if (this.updateLock.writeLock().tryLock()) { try { @@ -5547,7 +5549,7 @@ public class PlayerCharacter extends AbstractCharacter { @Override public final void setIsCasting(final boolean isCasting) { if (this.isCasting != isCasting) - this.update(); + this.update(false); this.isCasting = isCasting; } diff --git a/src/engine/powers/effectmodifiers/AttributeEffectModifier.java b/src/engine/powers/effectmodifiers/AttributeEffectModifier.java index 831d8a62..5920a199 100644 --- a/src/engine/powers/effectmodifiers/AttributeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AttributeEffectModifier.java @@ -30,7 +30,7 @@ public class AttributeEffectModifier extends AbstractEffectModifier { @Override public void applyBonus(AbstractCharacter ac, int trains) { - ac.update(); + ac.update(false); Float amount = 0f; PlayerBonuses bonus = ac.getBonuses(); if (this.percentMod != 0f) { //Stat Percent Modifiers diff --git a/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java b/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java index f657a765..8c9649d5 100644 --- a/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java +++ b/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java @@ -29,7 +29,7 @@ public class HealthRecoverRateEffectModifier extends AbstractEffectModifier { @Override public void applyBonus(AbstractCharacter ac, int trains) { - ac.update(); + ac.update(false); Float amount = 0f; PlayerBonuses bonus = ac.getBonuses(); if (this.useRampAdd) diff --git a/src/engine/powers/effectmodifiers/NoModEffectModifier.java b/src/engine/powers/effectmodifiers/NoModEffectModifier.java index a09c5600..7b80ac3e 100644 --- a/src/engine/powers/effectmodifiers/NoModEffectModifier.java +++ b/src/engine/powers/effectmodifiers/NoModEffectModifier.java @@ -39,7 +39,7 @@ public class NoModEffectModifier extends AbstractEffectModifier { PlayerCharacter flyer = (PlayerCharacter) ac; if (flyer.getAltitude() > 0) - flyer.update(); + flyer.update(false); PlayerCharacter.GroundPlayer(flyer); break; diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 80e445df..fe1752e9 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -517,6 +517,9 @@ public class WorldServer { Logger.info("Starting Bane Thread"); BaneThread.startBaneThread(); + Logger.info("Starting Player Update Thread"); + UpdateThread.startUpdateThread(); + return true; } diff --git a/src/engine/workthreads/UpdateThread.java b/src/engine/workthreads/UpdateThread.java new file mode 100644 index 00000000..e4e5100e --- /dev/null +++ b/src/engine/workthreads/UpdateThread.java @@ -0,0 +1,58 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + + +package engine.workthreads; + +import engine.Enum; +import engine.gameManager.SessionManager; +import engine.gameManager.SimulationManager; +import engine.objects.Bane; +import engine.objects.PlayerCharacter; +import org.pmw.tinylog.Logger; + +public class UpdateThread implements Runnable { + + public Long lastRun; + public static int instancedelay = 1000; + public UpdateThread() { + Logger.info(" UpdateThread thread has started!"); + } + + + public void processPlayerUpdate() { + + try { + for(PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()){ + player.update(true); + } + } catch (Exception e) { + Logger.error("UPDATE ERROR"); + } + + + } + + public void run() { + lastRun = System.currentTimeMillis(); + while (true) { + if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition + this.processPlayerUpdate(); + lastRun = System.currentTimeMillis(); // Update lastRun after processing + } + } + } + + + public static void startUpdateThread() { + Thread updateThread; + updateThread = new Thread(new UpdateThread()); + updateThread.setName("updateThread"); + updateThread.start(); + } +}