Keep track of inactive regions to prevent object creations.

This commit is contained in:
MobiusDevelopment
2021-04-07 12:28:09 +00:00
parent 85d3e6ae24
commit 82647a9330
46 changed files with 1196 additions and 148 deletions

View File

@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
@ -43,6 +44,7 @@ public class WorldRegion
private final int _regionY;
private boolean _active = Config.GRIDS_ALWAYS_ON;
private ScheduledFuture<?> _neighborsTask = null;
private final AtomicInteger _activeNeighbors = new AtomicInteger();
public WorldRegion(int regionX, int regionY)
{
@ -127,6 +129,21 @@ public class WorldRegion
return _active;
}
public void incrementActiveNeighbors()
{
_activeNeighbors.incrementAndGet();
}
public void decrementActiveNeighbors()
{
_activeNeighbors.decrementAndGet();
}
public boolean areNeighborsActive()
{
return Config.GRIDS_ALWAYS_ON || (_activeNeighbors.get() > 0);
}
public boolean areNeighborsEmpty()
{
for (int i = 0; i < _surroundingRegions.length; i++)
@ -161,6 +178,21 @@ public class WorldRegion
_active = value;
if (value)
{
for (int i = 0; i < _surroundingRegions.length; i++)
{
_surroundingRegions[i].incrementActiveNeighbors();
}
}
else
{
for (int i = 0; i < _surroundingRegions.length; i++)
{
_surroundingRegions[i].decrementActiveNeighbors();
}
}
// Turn the AI on or off to match the region's activation.
switchAI(value);
}

View File

@ -652,20 +652,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
public void broadcastMoveToLocation()
{
final WorldRegion region = getWorldRegion();
if ((region != null) && region.isActive())
if (isPlayable())
{
broadcastPacket(new MoveToLocation(this));
}
else
{
final WorldRegion region = getWorldRegion();
if ((region != null) && region.areNeighborsActive())
{
broadcastPacket(new MoveToLocation(this));
}
}
}
public void broadcastSocialAction(int id)
{
final WorldRegion region = getWorldRegion();
if ((region != null) && region.isActive())
if (isPlayable())
{
broadcastPacket(new SocialAction(getObjectId(), id));
}
else
{
final WorldRegion region = getWorldRegion();
if ((region != null) && region.areNeighborsActive())
{
broadcastPacket(new SocialAction(getObjectId(), id));
}
}
}
/**