Selaa lähdekoodia

Adds summons to charKnownList and enables player & summon iteration to speed up
forget task (quick test: no diff in normal area, 10x faster in siege where many guards)

Sami 17 vuotta sitten
vanhempi
sitoutus
79464f3053

+ 0 - 40
L2_GameServer_Hell/java/net/sf/l2j/gameserver/model/actor/instance/L2NpcInstance.java

@@ -206,46 +206,6 @@ public class L2NpcInstance extends L2Character
         return (Config.MAX_NPC_ANIMATION > 0);
     }
 
-    public class destroyTemporalNPC implements Runnable
-    {
-        private L2Spawn _oldSpawn;
-
-        public destroyTemporalNPC(L2Spawn spawn)
-        {
-            _oldSpawn = spawn;
-        }
-
-        public void run()
-        {
-            try
-            {
-                _oldSpawn.getLastSpawn().deleteMe();
-                _oldSpawn.stopRespawn();
-                SpawnTable.getInstance().deleteSpawn(_oldSpawn, false);
-            }
-            catch (Throwable t) {
-                t.printStackTrace();
-            }
-        }
-    }
-
-    public class destroyTemporalSummon implements Runnable
-    {
-        L2Summon _summon;
-        L2PcInstance _player;
-
-        public destroyTemporalSummon(L2Summon summon, L2PcInstance player)
-        {
-            _summon = summon;
-            _player = player;
-        }
-
-        public void run()
-        {
-            _summon.unSummon(_player);
-        }
-    }
-
     /**
      * Constructor of L2NpcInstance (use L2Character constructor).<BR><BR>
      *

+ 75 - 0
L2_GameServer_Hell/java/net/sf/l2j/gameserver/model/actor/knownlist/CharKnownList.java

@@ -21,9 +21,11 @@ import javolution.util.FastList;
 import javolution.util.FastMap;
 import net.sf.l2j.gameserver.model.L2Character;
 import net.sf.l2j.gameserver.model.L2Object;
+import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.model.L2Summon;
 import net.sf.l2j.gameserver.util.Util;
 
 public class CharKnownList extends ObjectKnownList
@@ -31,6 +33,7 @@ public class CharKnownList extends ObjectKnownList
     // =========================================================
     // Data Field
     private Map<Integer, L2PcInstance> _knownPlayers;
+    private Map<Integer, L2Summon> _knownSummons;
     private Map<Integer, Integer> _knownRelations;
 
     // =========================================================
@@ -52,6 +55,9 @@ public class CharKnownList extends ObjectKnownList
         	getKnownPlayers().put(object.getObjectId(), (L2PcInstance)object);
         	getKnownRelations().put(object.getObjectId(), -1);
         }
+        else if (object instanceof L2Summon)
+        	getKnownSummons().put(object.getObjectId(), (L2Summon)object);
+        	
         return true;
     }
 
@@ -68,6 +74,7 @@ public class CharKnownList extends ObjectKnownList
         super.removeAllKnownObjects();
         getKnownPlayers().clear();
         getKnownRelations().clear();
+        getKnownSummons().clear();
 
         // Set _target of the L2Character to null
         // Cancel Attack or Cast
@@ -85,11 +92,73 @@ public class CharKnownList extends ObjectKnownList
         	getKnownPlayers().remove(object.getObjectId());
         	getKnownRelations().remove(object.getObjectId());
         }
+        else if (object instanceof L2Summon)
+        {
+        	getKnownSummons().remove(object.getObjectId());
+        }
         // If object is targeted by the L2Character, cancel Attack or Cast
         if (object == getActiveChar().getTarget()) getActiveChar().setTarget(null);
 
         return true;
     }
+    
+    @Override
+    public void forgetObjects(boolean fullCheck)
+    {
+    	if (!fullCheck)
+    	{
+        	for (L2PcInstance player: getKnownPlayers().values())
+        	{
+        		// Remove all objects invisible or too far
+        		if (
+        				!player.isVisible() ||
+        				!Util.checkIfInShortRadius(getDistanceToForgetObject(player), getActiveObject(), player, true)
+        		)
+        				removeKnownObject(player);
+        	}
+        	for (L2Summon summon: getKnownSummons().values())
+        	{
+        		// Remove all objects invisible or too far
+        		if (
+        				!summon.isVisible() ||
+        				!Util.checkIfInShortRadius(getDistanceToForgetObject(summon), getActiveObject(), summon, true)
+        		)
+        				removeKnownObject(summon);
+        	}
+        	return;
+    	}
+    	// Go through knownObjects
+    	for (L2Object object: getKnownObjects().values())
+    	{
+    		// Remove all objects invisible or too far
+    		if (
+    				!object.isVisible() ||
+    				!Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)
+    		)
+    			if (object instanceof L2BoatInstance && getActiveObject() instanceof L2PcInstance)
+    			{
+    				if(((L2BoatInstance)(object)).getVehicleDeparture() == null )
+    				{
+    					//
+    				}
+    				else if(((L2PcInstance)getActiveObject()).isInBoat())
+    				{
+    					if(((L2PcInstance)getActiveObject()).getBoat() != object)
+    					{
+    						removeKnownObject(object);
+    					}
+    				}
+    				else
+    				{
+    					removeKnownObject(object);
+    				}
+    			}
+    			else
+    			{
+    				removeKnownObject(object);
+    			}
+    	}
+    }
 
     // =========================================================
     // Method - Private
@@ -154,6 +223,12 @@ public class CharKnownList extends ObjectKnownList
         return _knownRelations;
     }
 
+    public final Map<Integer, L2Summon> getKnownSummons()
+    {
+        if (_knownSummons == null) _knownSummons = new FastMap<Integer, L2Summon>().setShared(true);
+        return _knownSummons;
+    }
+    
     public final Collection<L2PcInstance> getKnownPlayersInRadius(long radius)
     {
         FastList<L2PcInstance> result = new FastList<L2PcInstance>();

+ 1 - 1
L2_GameServer_Hell/java/net/sf/l2j/gameserver/model/actor/knownlist/FriendlyMobKnownList.java

@@ -61,7 +61,7 @@ public class FriendlyMobKnownList extends AttackableKnownList
             if (getActiveChar().getTarget() == temp) getActiveChar().setTarget(null);
         }
 
-        if (getActiveChar().isVisible() && getKnownPlayers().isEmpty())
+        if (getActiveChar().isVisible() && getKnownPlayers().isEmpty() && getKnownSummons().isEmpty())
         {
             getActiveChar().clearAggroList();
             //removeAllKnownObjects();

+ 1 - 1
L2_GameServer_Hell/java/net/sf/l2j/gameserver/model/actor/knownlist/MonsterKnownList.java

@@ -68,7 +68,7 @@ public class MonsterKnownList extends AttackableKnownList
             //  setTarget(null);
         }
 
-        if (getActiveChar().isVisible() && getKnownPlayers().isEmpty())
+        if (getActiveChar().isVisible() && getKnownPlayers().isEmpty() && getKnownSummons().isEmpty())
         {
             // Clear the _aggroList of the L2MonsterInstance
             getActiveChar().clearAggroList();

+ 3 - 8
L2_GameServer_Hell/java/net/sf/l2j/gameserver/model/actor/knownlist/ObjectKnownList.java

@@ -104,7 +104,7 @@ public class ObjectKnownList
     }
     
     // Remove invisible and too far L2Object from _knowObject and if necessary from _knownPlayers of the L2Character
-    public final void forgetObjects(boolean fullCheck)
+    public void forgetObjects(boolean fullCheck)
     {
     	// Go through knownObjects
     	for (L2Object object: getKnownObjects().values())
@@ -112,8 +112,7 @@ public class ObjectKnownList
     		if (!fullCheck && !(object instanceof L2PlayableInstance))
     			continue;
 
-    		// Remove all invisible object
-    		// Remove all too far object
+    		// Remove all objects invisible or too far
     		if (
     				!object.isVisible() ||
     				!Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)
@@ -126,11 +125,7 @@ public class ObjectKnownList
     				}
     				else if(((L2PcInstance)getActiveObject()).isInBoat())
     				{
-    					if(((L2PcInstance)getActiveObject()).getBoat() == object)
-    					{
-    						//
-    					}
-    					else
+    					if(((L2PcInstance)getActiveObject()).getBoat() != object)
     					{
     						removeKnownObject(object);
     					}