Prevent starting tasks if addKnownObject returns false.

This commit is contained in:
MobiusDevelopment 2020-02-09 11:48:19 +00:00
parent 60b928e969
commit 3f632faecd
2 changed files with 130 additions and 131 deletions

View File

@ -16,6 +16,8 @@
*/ */
package org.l2jmobius.gameserver.model.actor.knownlist; package org.l2jmobius.gameserver.model.actor.knownlist;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.ai.CreatureAI; import org.l2jmobius.gameserver.ai.CreatureAI;
import org.l2jmobius.gameserver.model.WorldObject; import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature; import org.l2jmobius.gameserver.model.actor.Creature;
@ -48,6 +50,8 @@ import org.l2jmobius.gameserver.network.serverpackets.VehicleInfo;
public class PlayerKnownList extends PlayableKnownList public class PlayerKnownList extends PlayableKnownList
{ {
private int _packetSendDelay = 0;
public PlayerKnownList(PlayerInstance player) public PlayerKnownList(PlayerInstance player)
{ {
super(player); super(player);
@ -103,6 +107,18 @@ public class PlayerKnownList extends PlayableKnownList
return false; return false;
} }
// Delay is broken down to 100ms intervals.
// With the random time added it gives at least 50ms between tasks.
if (_packetSendDelay > 3000)
{
_packetSendDelay = 0;
}
_packetSendDelay += 100;
// Send packets asynchronously. (Obviously heavier on CPU, but significantly reduces network spikes.)
// On retail there is a similar, if not greater, delay as well.
ThreadPool.schedule(() ->
{
if (object.getPoly().isMorphed() && object.getPoly().getPolyType().equals("item")) if (object.getPoly().isMorphed() && object.getPoly().getPolyType().equals("item"))
{ {
activeChar.sendPacket(new SpawnItemPoly(object)); activeChar.sendPacket(new SpawnItemPoly(object));
@ -188,7 +204,6 @@ public class PlayerKnownList extends PlayableKnownList
} }
activeChar.sendPacket(new GetOnVehicle(otherPlayer, otherPlayer.getBoat(), otherPlayer.getBoatPosition().getX(), otherPlayer.getBoatPosition().getY(), otherPlayer.getBoatPosition().getZ())); activeChar.sendPacket(new GetOnVehicle(otherPlayer, otherPlayer.getBoat(), otherPlayer.getBoatPosition().getX(), otherPlayer.getBoatPosition().getY(), otherPlayer.getBoatPosition().getZ()));
} }
else else
{ {
@ -227,6 +242,7 @@ public class PlayerKnownList extends PlayableKnownList
} }
} }
} }
}, _packetSendDelay + Rnd.get(50)); // Add additional 0-49ms in case of overlapping tasks on heavy load.
return true; return true;
} }

View File

@ -19,8 +19,6 @@ package org.l2jmobius.gameserver.model.actor.knownlist;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject; import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature; import org.l2jmobius.gameserver.model.actor.Creature;
@ -124,26 +122,12 @@ public class WorldObjectKnownList
if (_activeObject.isPlayable()) if (_activeObject.isPlayable())
{ {
int delay = 0;
// Go through all visible WorldObject near the Creature // Go through all visible WorldObject near the Creature
for (WorldObject object : World.getInstance().getVisibleObjects(_activeObject)) for (WorldObject object : World.getInstance().getVisibleObjects(_activeObject))
{
// Delay is broken down to 100ms intervals.
// With the random time added it gives at least 50ms between tasks.
if (delay >= 5000)
{
delay = 0;
}
delay += 100;
// Send packets asynchronously. (Obviously heavier on CPU, but significantly reduces network spikes.)
// On retail there is a similar, if not greater, delay as well.
ThreadPool.schedule(() ->
{ {
if (object == null) if (object == null)
{ {
return; continue;
} }
// Try to add object to active object's known objects // Try to add object to active object's known objects
@ -156,7 +140,6 @@ public class WorldObjectKnownList
{ {
object.getKnownList().addKnownObject(_activeObject); object.getKnownList().addKnownObject(_activeObject);
} }
}, delay + Rnd.get(50)); // Add additional 0-49ms in case of overlapping tasks on heavy load.
} }
} }
else else