Browse Source

player update handled in new thread

lakebane2
FatBoy-DOTC 2 weeks ago
parent
commit
1098265145
  1. 8
      src/engine/gameManager/MovementManager.java
  2. 12
      src/engine/gameManager/PowersManager.java
  3. 2
      src/engine/gameManager/SimulationManager.java
  4. 4
      src/engine/net/client/ClientMessagePump.java
  5. 6
      src/engine/net/client/handlers/ChangeAltitudeHandler.java
  6. 9
      src/engine/objects/AbstractCharacter.java
  7. 6
      src/engine/objects/AbstractWorldObject.java
  8. 16
      src/engine/objects/PlayerCharacter.java
  9. 2
      src/engine/powers/effectmodifiers/AttributeEffectModifier.java
  10. 2
      src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java
  11. 2
      src/engine/powers/effectmodifiers/NoModEffectModifier.java
  12. 3
      src/engine/server/world/WorldServer.java
  13. 58
      src/engine/workthreads/UpdateThread.java

8
src/engine/gameManager/MovementManager.java

@ -68,7 +68,7 @@ public enum MovementManager {
if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) { if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) {
if (((PlayerCharacter) toMove).isCasting()) if (((PlayerCharacter) toMove).isCasting())
((PlayerCharacter) toMove).update(); ((PlayerCharacter) toMove).update(false);
} }
@ -96,7 +96,7 @@ public enum MovementManager {
if (!toMove.isMoving()) if (!toMove.isMoving())
toMove.resetLastSetLocUpdate(); toMove.resetLastSetLocUpdate();
else else
toMove.update(); toMove.update(false);
// Update movement for the player // 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()); 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 //Send run/walk/sit/stand to tell the client we are flying / landing etc
ac.update(); ac.update(false);
ac.stopMovement(ac.getLoc()); ac.stopMovement(ac.getLoc());
if (ac.isAlive()) if (ac.isAlive())
MovementManager.sendRWSSMsg(ac); MovementManager.sendRWSSMsg(ac);
@ -408,7 +408,7 @@ public enum MovementManager {
if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None)) if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None))
continue; continue;
member.update(); member.update(false);
// All checks passed, let's move the player // All checks passed, let's move the player

12
src/engine/gameManager/PowersManager.java

@ -8,7 +8,6 @@
package engine.gameManager; package engine.gameManager;
import com.sun.corba.se.spi.orbutil.fsm.ActionBase;
import engine.Enum.*; import engine.Enum.*;
import engine.InterestManagement.HeightMap; import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
@ -28,7 +27,6 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.*; import engine.net.client.msg.*;
import engine.objects.*; import engine.objects.*;
import engine.powers.*; import engine.powers.*;
import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.powers.poweractions.AbstractPowerAction; import engine.powers.poweractions.AbstractPowerAction;
import engine.powers.poweractions.TrackPowerAction; import engine.powers.poweractions.TrackPowerAction;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
@ -179,7 +177,7 @@ public enum PowersManager {
if (pc != null) { if (pc != null) {
sendPowerMsg(pc, 2, msg); sendPowerMsg(pc, 2, msg);
if (pc.isCasting()) { if (pc.isCasting()) {
pc.update(); pc.update(false);
} }
pc.setIsCasting(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) // 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()) { if (pb.isSpell() && !pb.isChant() && playerCharacter.isSit()) {
playerCharacter.update(); playerCharacter.update(false);
playerCharacter.setSit(false); playerCharacter.setSit(false);
UpdateStateMsg updateStateMsg = new UpdateStateMsg(playerCharacter); UpdateStateMsg updateStateMsg = new UpdateStateMsg(playerCharacter);
DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
@ -614,7 +612,7 @@ public enum PowersManager {
if (time > 100) { if (time > 100) {
playerCharacter.update(); playerCharacter.update(false);
playerCharacter.setIsCasting(true); playerCharacter.setIsCasting(true);
} }
@ -792,7 +790,7 @@ public enum PowersManager {
playerCharacter.removeEffectBySource(EffectSourceType.Root,40,true); playerCharacter.removeEffectBySource(EffectSourceType.Root,40,true);
} }
if (playerCharacter.isCasting()) { if (playerCharacter.isCasting()) {
playerCharacter.update(); playerCharacter.update(false);
playerCharacter.updateStamRegen(-100); playerCharacter.updateStamRegen(-100);
} }
@ -2318,7 +2316,7 @@ public enum PowersManager {
// set player is not casting for regens // set player is not casting for regens
if (pc.isCasting()) { if (pc.isCasting()) {
pc.update(); pc.update(false);
} }
pc.setIsCasting(false); pc.setIsCasting(false);

2
src/engine/gameManager/SimulationManager.java

@ -151,7 +151,7 @@ public enum SimulationManager {
if (player == null) if (player == null)
continue; continue;
player.update(); player.update(false);
} }
_updatePulseTime = System.currentTimeMillis() + 500; _updatePulseTime = System.currentTimeMillis() + 500;

4
src/engine/net/client/ClientMessagePump.java

@ -85,7 +85,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (pc == null) if (pc == null)
return; return;
pc.update(); pc.update(false);
if (msg.getSpeed() == 2) if (msg.getSpeed() == 2)
pc.setWalkMode(false); pc.setWalkMode(false);
else else
@ -114,7 +114,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (pc == null) if (pc == null)
return; return;
pc.update(); pc.update(false);
pc.setSit(msg.toggleSitStand()); pc.setSit(msg.toggleSitStand());

6
src/engine/net/client/handlers/ChangeAltitudeHandler.java

@ -70,7 +70,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
if (pc.getAltitude() == 0 && !msg.up()) if (pc.getAltitude() == 0 && !msg.up())
return true; return true;
pc.update(); pc.update(false);
pc.stopMovement(pc.getLoc()); pc.stopMovement(pc.getLoc());
msg.setStartAlt(pc.getAltitude()); msg.setStartAlt(pc.getAltitude());
if (msg.up()) { if (msg.up()) {
@ -135,7 +135,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
} }
if (msg.up()) { if (msg.up()) {
pc.update(); pc.update(false);
pc.setDesiredAltitude(targetAlt); pc.setDesiredAltitude(targetAlt);
pc.setTakeOffTime(System.currentTimeMillis()); pc.setTakeOffTime(System.currentTimeMillis());
} else { } else {
@ -161,7 +161,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
} else } else
pc.setDesiredAltitude(targetAlt); pc.setDesiredAltitude(targetAlt);
pc.update(); pc.update(false);
pc.setTakeOffTime(System.currentTimeMillis()); pc.setTakeOffTime(System.currentTimeMillis());

9
src/engine/objects/AbstractCharacter.java

@ -31,7 +31,6 @@ import engine.net.ByteBufferWriter;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.UpdateStateMsg; import engine.net.client.msg.UpdateStateMsg;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -1841,7 +1840,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
//updates //updates
public void update() { public void update(Boolean newSystem) {
} }
public void updateRegen() { public void updateRegen() {
@ -1861,16 +1860,16 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
try { try {
switch (updateType) { switch (updateType) {
case ALL: case ALL:
update(); update(false);
break; break;
case REGEN: case REGEN:
updateRegen(); updateRegen();
break; break;
case LOCATION: case LOCATION:
update(); update(false);
break; break;
case MOVEMENTSTATE: case MOVEMENTSTATE:
update(); update(false);
break; break;
case FLIGHT: case FLIGHT:
updateFlight(); updateFlight();

6
src/engine/objects/AbstractWorldObject.java

@ -270,7 +270,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
this.effects.remove(name); this.effects.remove(name);
if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) if (this.getObjectType().equals(GameObjectType.PlayerCharacter))
if (name.equals("Flight")) { if (name.equals("Flight")) {
((PlayerCharacter) this).update(); ((PlayerCharacter) this).update(false);
PlayerCharacter.GroundPlayer((PlayerCharacter) this); PlayerCharacter.GroundPlayer((PlayerCharacter) this);
} }
} }
@ -385,7 +385,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
if (source.equals("Flight")) { if (source.equals("Flight")) {
//ground player //ground player
if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) {
((PlayerCharacter) this).update(); ((PlayerCharacter) this).update(false);
PlayerCharacter.GroundPlayer((PlayerCharacter) this); PlayerCharacter.GroundPlayer((PlayerCharacter) this);
} }
} }
@ -414,7 +414,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
if (source.equals("Flight")) { if (source.equals("Flight")) {
//ground player //ground player
if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) {
((PlayerCharacter) this).update(); ((PlayerCharacter) this).update(false);
PlayerCharacter.GroundPlayer((PlayerCharacter) this); PlayerCharacter.GroundPlayer((PlayerCharacter) this);
} }
} }

16
src/engine/objects/PlayerCharacter.java

@ -26,7 +26,6 @@ import engine.job.JobScheduler;
import engine.jobs.DeferredPowerJob; import engine.jobs.DeferredPowerJob;
import engine.jobs.FinishSpireEffectJob; import engine.jobs.FinishSpireEffectJob;
import engine.jobs.NoTimeJob; import engine.jobs.NoTimeJob;
import engine.jobs.RefreshGroupJob;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.FastMath; import engine.math.FastMath;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
@ -2102,7 +2101,7 @@ public class PlayerCharacter extends AbstractCharacter {
this.lastUpdateTime = System.currentTimeMillis(); this.lastUpdateTime = System.currentTimeMillis();
this.lastStamUpdateTime = System.currentTimeMillis(); this.lastStamUpdateTime = System.currentTimeMillis();
this.update(); this.update(false);
PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, 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) { public synchronized void grantXP(int xp) {
if(this.promotionClass == null && this.level == 10){ if(this.promotionClass == null && this.level == 10){
this.setOverFlowEXP(0); this.setOverFlowEXP(0);
this.update(); this.update(false);
this.incVer(); this.incVer();
this.recalculate(); this.recalculate();
this.calculateMaxHealthManaStamina(); this.calculateMaxHealthManaStamina();
@ -3084,7 +3083,7 @@ public class PlayerCharacter extends AbstractCharacter {
} }
if (charReloadRequired) { if (charReloadRequired) {
this.update(); this.update(false);
this.incVer(); this.incVer();
this.recalculate(); this.recalculate();
this.calculateMaxHealthManaStamina(); this.calculateMaxHealthManaStamina();
@ -3157,7 +3156,7 @@ public class PlayerCharacter extends AbstractCharacter {
bonus += this.bonuses.getFloatPercentNullZero(ModType.Speed, SourceType.None); bonus += this.bonuses.getFloatPercentNullZero(ModType.Speed, SourceType.None);
// TODO get equip bonus // TODO get equip bonus
this.update(); this.update(false);
this.speedMod = bonus; this.speedMod = bonus;
} }
@ -4839,7 +4838,10 @@ public class PlayerCharacter extends AbstractCharacter {
} }
@Override @Override
public void update() { public void update(Boolean newSystem) {
if(!newSystem)
return;
if (this.updateLock.writeLock().tryLock()) { if (this.updateLock.writeLock().tryLock()) {
try { try {
@ -5547,7 +5549,7 @@ public class PlayerCharacter extends AbstractCharacter {
@Override @Override
public final void setIsCasting(final boolean isCasting) { public final void setIsCasting(final boolean isCasting) {
if (this.isCasting != isCasting) if (this.isCasting != isCasting)
this.update(); this.update(false);
this.isCasting = isCasting; this.isCasting = isCasting;
} }

2
src/engine/powers/effectmodifiers/AttributeEffectModifier.java

@ -30,7 +30,7 @@ public class AttributeEffectModifier extends AbstractEffectModifier {
@Override @Override
public void applyBonus(AbstractCharacter ac, int trains) { public void applyBonus(AbstractCharacter ac, int trains) {
ac.update(); ac.update(false);
Float amount = 0f; Float amount = 0f;
PlayerBonuses bonus = ac.getBonuses(); PlayerBonuses bonus = ac.getBonuses();
if (this.percentMod != 0f) { //Stat Percent Modifiers if (this.percentMod != 0f) { //Stat Percent Modifiers

2
src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java

@ -29,7 +29,7 @@ public class HealthRecoverRateEffectModifier extends AbstractEffectModifier {
@Override @Override
public void applyBonus(AbstractCharacter ac, int trains) { public void applyBonus(AbstractCharacter ac, int trains) {
ac.update(); ac.update(false);
Float amount = 0f; Float amount = 0f;
PlayerBonuses bonus = ac.getBonuses(); PlayerBonuses bonus = ac.getBonuses();
if (this.useRampAdd) if (this.useRampAdd)

2
src/engine/powers/effectmodifiers/NoModEffectModifier.java

@ -39,7 +39,7 @@ public class NoModEffectModifier extends AbstractEffectModifier {
PlayerCharacter flyer = (PlayerCharacter) ac; PlayerCharacter flyer = (PlayerCharacter) ac;
if (flyer.getAltitude() > 0) if (flyer.getAltitude() > 0)
flyer.update(); flyer.update(false);
PlayerCharacter.GroundPlayer(flyer); PlayerCharacter.GroundPlayer(flyer);
break; break;

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

@ -517,6 +517,9 @@ public class WorldServer {
Logger.info("Starting Bane Thread"); Logger.info("Starting Bane Thread");
BaneThread.startBaneThread(); BaneThread.startBaneThread();
Logger.info("Starting Player Update Thread");
UpdateThread.startUpdateThread();
return true; return true;
} }

58
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();
}
}
Loading…
Cancel
Save