Browse Source

dirtyflag chosen as solution.

master
MagicBot 1 year ago
parent
commit
6923251a88
  1. 53
      src/engine/InterestManagement/InterestManager.java
  2. 5
      src/engine/objects/PlayerCharacter.java

53
src/engine/InterestManagement/InterestManager.java

@ -30,12 +30,13 @@ import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import static engine.math.FastMath.sqr;
public enum InterestManager implements Runnable { public enum InterestManager implements Runnable {
INTERESTMANAGER; INTERESTMANAGER;
private static long lastTime; private static long lastTime;
private static boolean keepGoing = true;
InterestManager() { InterestManager() {
Logger.info(" Interest Management thread is running."); Logger.info(" Interest Management thread is running.");
@ -155,10 +156,6 @@ public enum InterestManager implements Runnable {
} }
} }
public void shutdown() {
this.keepGoing = false;
}
@Override @Override
public void run() { public void run() {
beginLoadJob(); beginLoadJob();
@ -168,7 +165,7 @@ public enum InterestManager implements Runnable {
InterestManager.lastTime = System.currentTimeMillis(); InterestManager.lastTime = System.currentTimeMillis();
while (InterestManager.keepGoing) { while (true) {
try { try {
updateAllPlayers(); updateAllPlayers();
} catch (Exception e) { } catch (Exception e) {
@ -232,11 +229,26 @@ public enum InterestManager implements Runnable {
private void updateStaticList(PlayerCharacter player, ClientConnection origin) { private void updateStaticList(PlayerCharacter player, ClientConnection origin) {
// Only update if we've moved far enough to warrant it
float distanceSquared = player.getLoc().distanceSquared2D(player.getLastStaticLoc());
if (distanceSquared > sqr(25)) {
player.setLastStaticLoc(player.getLoc());
player.dirtyLoad = true;
}
if (player.dirtyLoad == false)
return;
// Get Statics in range // Get Statics in range
HashSet<AbstractWorldObject> toLoad = WorldGrid.getObjectsInRangePartial(player.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE, HashSet<AbstractWorldObject> toLoad = WorldGrid.getObjectsInRangePartial(player.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE,
MBServerStatics.MASK_STATIC); MBServerStatics.MASK_STATIC);
// get list of obects loaded that need removed // get list of obects loaded that need removed
HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects(); HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects();
HashSet<AbstractWorldObject> toRemove = null; HashSet<AbstractWorldObject> toRemove = null;
@ -246,11 +258,16 @@ public enum InterestManager implements Runnable {
toRemove.removeAll(toLoad); toRemove.removeAll(toLoad);
// unload static objects now out of range // unload static objects now out of range
if (toRemove.size() > 0) { if (toRemove.size() > 0) {
UnloadObjectsMsg uom = new UnloadObjectsMsg(); UnloadObjectsMsg uom = new UnloadObjectsMsg();
for (AbstractWorldObject obj : toRemove) { for (AbstractWorldObject obj : toRemove) {
if (obj.getObjectType().equals(GameObjectType.Building)) if (obj.getObjectType().equals(GameObjectType.Building))
InterestManager.HandleSpecialUnload((Building) obj, origin); InterestManager.HandleSpecialUnload((Building) obj, origin);
if (obj != null && !obj.equals(player)) if (obj != null && !obj.equals(player))
uom.addObject(obj); uom.addObject(obj);
} }
@ -262,6 +279,7 @@ public enum InterestManager implements Runnable {
loadedStaticObjects.removeAll(toRemove); loadedStaticObjects.removeAll(toRemove);
// remove any object to load that are already loaded // remove any object to load that are already loaded
toLoad.removeAll(loadedStaticObjects); toLoad.removeAll(loadedStaticObjects);
LoadStructureMsg lsm = new LoadStructureMsg(); LoadStructureMsg lsm = new LoadStructureMsg();
@ -269,6 +287,7 @@ public enum InterestManager implements Runnable {
ArrayList<LoadCharacterMsg> lcmList = new ArrayList<>(); ArrayList<LoadCharacterMsg> lcmList = new ArrayList<>();
for (AbstractWorldObject awo : toLoad) { for (AbstractWorldObject awo : toLoad) {
if (awo.getObjectType().equals(GameObjectType.Building)) if (awo.getObjectType().equals(GameObjectType.Building))
lsm.addObject((Building) awo); lsm.addObject((Building) awo);
else if (awo.getObjectType().equals(GameObjectType.Corpse)) { else if (awo.getObjectType().equals(GameObjectType.Corpse)) {
@ -278,7 +297,6 @@ public enum InterestManager implements Runnable {
Dispatch dispatch = Dispatch.borrow(player, lcm); Dispatch dispatch = Dispatch.borrow(player, lcm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
} else if (awo.getObjectType().equals(GameObjectType.NPC)) { } else if (awo.getObjectType().equals(GameObjectType.NPC)) {
NPC npc = (NPC) awo; NPC npc = (NPC) awo;
lcm = new LoadCharacterMsg(npc, PlayerCharacter.hideNonAscii()); lcm = new LoadCharacterMsg(npc, PlayerCharacter.hideNonAscii());
@ -299,6 +317,7 @@ public enum InterestManager implements Runnable {
} }
loadedStaticObjects.addAll(toLoad); loadedStaticObjects.addAll(toLoad);
player.dirtyLoad = false;
} }
private void updateMobileList(PlayerCharacter player, ClientConnection origin) { private void updateMobileList(PlayerCharacter player, ClientConnection origin) {
@ -407,17 +426,20 @@ public enum InterestManager implements Runnable {
ArrayList<AbstractWorldObject> addToList = new ArrayList<>(); ArrayList<AbstractWorldObject> addToList = new ArrayList<>();
for (AbstractWorldObject awo : toLoadToPlayer) { for (AbstractWorldObject awo : toLoadToPlayer) {
// dont load yourself
try { try {
if (awo.equals(player)) if (awo.equals(player)) // dont load yourself
continue; continue;
if ((awo.getObjectTypeMask() & MBServerStatics.MASK_PLAYER) != 0) { if ((awo.getObjectTypeMask() & MBServerStatics.MASK_PLAYER) != 0) {
// object to load is a player // object to load is a player
PlayerCharacter awopc = (PlayerCharacter) awo; PlayerCharacter awopc = (PlayerCharacter) awo;
// dont load if invis // dont load if invis
if (player.getSeeInvis() < awopc.getHidden()) if (player.getSeeInvis() < awopc.getHidden())
continue; continue;
@ -444,15 +466,14 @@ public enum InterestManager implements Runnable {
continue; continue;
//removed, interest manager should still load mob corpses //removed, interest manager should still load mob corpses
if (awonpc.despawned == true) if (awonpc.despawned == true)
continue; continue;
awonpc.playerAgroMap.put(player.getObjectUUID(), false); awonpc.playerAgroMap.put(player.getObjectUUID(), false);
//MobAI.setAwake(awonpc, false);
((Mob) awonpc).setCombatTarget(null); ((Mob) awonpc).setCombatTarget(null);
// IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000));
// awonpc.enableIntelligence();
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
} else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_NPC) != 0) { } else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_NPC) != 0) {
NPC awonpc = (NPC) awo; NPC awonpc = (NPC) awo;
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
@ -465,10 +486,8 @@ public enum InterestManager implements Runnable {
awonpc.playerAgroMap.put(player.getObjectUUID(), false); awonpc.playerAgroMap.put(player.getObjectUUID(), false);
if ((awonpc.agentType.equals(Enum.AIAgentType.MOBILE))) if ((awonpc.agentType.equals(Enum.AIAgentType.MOBILE)))
//MobAI.setAwake(awonpc, false);
((Mob) awonpc).setCombatTarget(null); ((Mob) awonpc).setCombatTarget(null);
// IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000));
// awonpc.enableIntelligence();
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
} }
@ -504,6 +523,7 @@ public enum InterestManager implements Runnable {
return; return;
//Update static list //Update static list
try { try {
updateStaticList(player, origin); updateStaticList(player, origin);
} catch (Exception e) { } catch (Exception e) {
@ -511,6 +531,7 @@ public enum InterestManager implements Runnable {
} }
//Update mobile list //Update mobile list
try { try {
updateMobileList(player, origin); updateMobileList(player, origin);
} catch (Exception e) { } catch (Exception e) {
@ -529,6 +550,7 @@ public enum InterestManager implements Runnable {
return; return;
//Update static list //Update static list
try { try {
updateStaticList(player, origin); updateStaticList(player, origin);
} catch (Exception e) { } catch (Exception e) {
@ -536,6 +558,7 @@ public enum InterestManager implements Runnable {
} }
//Update mobile list //Update mobile list
try { try {
updateMobileList(player, origin); updateMobileList(player, origin);
} catch (Exception e) { } catch (Exception e) {

5
src/engine/objects/PlayerCharacter.java

@ -181,6 +181,8 @@ public class PlayerCharacter extends AbstractCharacter {
private boolean lastSwimming = false; private boolean lastSwimming = false;
private boolean isTeleporting = false; private boolean isTeleporting = false;
public boolean dirtyLoad = false;
/** /**
* No Id Constructor * No Id Constructor
*/ */
@ -5501,8 +5503,10 @@ public class PlayerCharacter extends AbstractCharacter {
@Override @Override
public final void teleport(final Vector3fImmutable targetLoc) { public final void teleport(final Vector3fImmutable targetLoc) {
Regions targetRegion = Regions.GetRegionForTeleport(targetLoc); Regions targetRegion = Regions.GetRegionForTeleport(targetLoc);
locationLock.writeLock().lock(); locationLock.writeLock().lock();
try { try {
MovementManager.translocate(this, targetLoc, targetRegion); MovementManager.translocate(this, targetLoc, targetRegion);
} catch (Exception e) { } catch (Exception e) {
@ -5519,7 +5523,6 @@ public class PlayerCharacter extends AbstractCharacter {
public float getBargain() { public float getBargain() {
float bargain = 0; float bargain = 0;
CharacterSkill bargainSkill = this.getSkills().get(engine.Enum.CharacterSkills.Bargaining.name()); CharacterSkill bargainSkill = this.getSkills().get(engine.Enum.CharacterSkills.Bargaining.name());
if (bargainSkill != null) if (bargainSkill != null)

Loading…
Cancel
Save