Removed enhanced For from World and WorldRegion.

This commit is contained in:
MobiusDevelopment
2020-08-30 19:26:33 +00:00
parent b88d13a836
commit d86b65da9b
67 changed files with 2640 additions and 1929 deletions

View File

@@ -94,7 +94,7 @@ sp_cleanup.always_use_parentheses_in_expressions=true
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=true
sp_cleanup.convert_to_enhanced_for_loop=true
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
@@ -106,18 +106,23 @@ sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=false
sp_cleanup.number_suffix=false
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.push_down_negation=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_modifiers=false
sp_cleanup.remove_redundant_semicolons=false
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=true
sp_cleanup.remove_unnecessary_array_creation=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
@@ -126,11 +131,14 @@ sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.simplify_lambda_expression_and_method_ref=false
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_autoboxing=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_directly_map_method=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=true
sp_cleanup.use_this_for_non_static_field_access=false
@@ -138,3 +146,4 @@ sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_type_arguments=false
sp_cleanup.use_unboxing=false

View File

@@ -406,10 +406,13 @@ public class World
oldRegion.removeVisibleObject(object);
// Go through all surrounding WorldRegion Creatures
for (WorldRegion worldRegion : oldRegion.getSurroundingRegions())
final WorldRegion[] surroundingRegions = oldRegion.getSurroundingRegions();
for (int i = 0; i < surroundingRegions.length; i++)
{
for (WorldObject wo : worldRegion.getVisibleObjects().values())
final List<WorldObject> visibleObjects = surroundingRegions[i].getVisibleObjects();
for (int j = 0; j < visibleObjects.size(); j++)
{
final WorldObject wo = visibleObjects.get(j);
if (wo == object)
{
continue;
@@ -466,15 +469,19 @@ public class World
return;
}
for (WorldRegion worldRegion : oldRegion.getSurroundingRegions())
final WorldRegion[] oldSurroundingRegions = oldRegion.getSurroundingRegions();
for (int i = 0; i < oldSurroundingRegions.length; i++)
{
final WorldRegion worldRegion = oldSurroundingRegions[i];
if (newRegion.isSurroundingRegion(worldRegion))
{
continue;
}
for (WorldObject wo : worldRegion.getVisibleObjects().values())
final List<WorldObject> visibleObjects = worldRegion.getVisibleObjects();
for (int j = 0; j < visibleObjects.size(); j++)
{
final WorldObject wo = visibleObjects.get(j);
if (wo == object)
{
continue;
@@ -522,15 +529,19 @@ public class World
}
}
for (WorldRegion worldRegion : newRegion.getSurroundingRegions())
final WorldRegion[] newSurroundingRegions = newRegion.getSurroundingRegions();
for (int i = 0; i < newSurroundingRegions.length; i++)
{
final WorldRegion worldRegion = newSurroundingRegions[i];
if (oldRegion.isSurroundingRegion(worldRegion))
{
continue;
}
for (WorldObject wo : worldRegion.getVisibleObjects().values())
final List<WorldObject> visibleObjects = worldRegion.getVisibleObjects();
for (int j = 0; j < visibleObjects.size(); j++)
{
final WorldObject wo = visibleObjects.get(j);
if ((wo == object) || (wo.getInstanceWorld() != object.getInstanceWorld()))
{
continue;
@@ -610,27 +621,30 @@ public class World
return;
}
final WorldRegion centerWorldRegion = getRegion(object);
if (centerWorldRegion == null)
final WorldRegion worldRegion = getRegion(object);
if (worldRegion == null)
{
return;
}
for (WorldRegion region : centerWorldRegion.getSurroundingRegions())
final WorldRegion[] surroundingRegions = worldRegion.getSurroundingRegions();
for (int i = 0; i < surroundingRegions.length; i++)
{
for (WorldObject visibleObject : region.getVisibleObjects().values())
final List<WorldObject> visibleObjects = surroundingRegions[i].getVisibleObjects();
for (int j = 0; j < visibleObjects.size(); j++)
{
if ((visibleObject == null) || (visibleObject == object) || !clazz.isInstance(visibleObject))
final WorldObject wo = visibleObjects.get(j);
if ((wo == null) || (wo == object) || !clazz.isInstance(wo))
{
continue;
}
if (visibleObject.getInstanceWorld() != object.getInstanceWorld())
if (wo.getInstanceWorld() != object.getInstanceWorld())
{
continue;
}
c.accept(clazz.cast(visibleObject));
c.accept(clazz.cast(wo));
}
}
}
@@ -662,29 +676,32 @@ public class World
return;
}
final WorldRegion centerWorldRegion = getRegion(object);
if (centerWorldRegion == null)
final WorldRegion worldRegion = getRegion(object);
if (worldRegion == null)
{
return;
}
for (WorldRegion region : centerWorldRegion.getSurroundingRegions())
final WorldRegion[] surroundingRegions = worldRegion.getSurroundingRegions();
for (int i = 0; i < surroundingRegions.length; i++)
{
for (WorldObject visibleObject : region.getVisibleObjects().values())
final List<WorldObject> visibleObjects = surroundingRegions[i].getVisibleObjects();
for (int j = 0; j < visibleObjects.size(); j++)
{
if ((visibleObject == null) || (visibleObject == object) || !clazz.isInstance(visibleObject))
final WorldObject wo = visibleObjects.get(j);
if ((wo == null) || (wo == object) || !clazz.isInstance(wo))
{
continue;
}
if (visibleObject.getInstanceWorld() != object.getInstanceWorld())
if (wo.getInstanceWorld() != object.getInstanceWorld())
{
continue;
}
if (visibleObject.calculateDistance3D(object) <= range)
if (wo.calculateDistance3D(object) <= range)
{
c.accept(clazz.cast(visibleObject));
c.accept(clazz.cast(wo));
}
}
}

View File

@@ -16,8 +16,8 @@
*/
package org.l2jmobius.gameserver.model;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import org.l2jmobius.Config;
@@ -28,9 +28,9 @@ import org.l2jmobius.gameserver.taskmanager.RandomAnimationTaskManager;
public class WorldRegion
{
/** Map containing visible objects in this world region. */
private final Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
/** Map containing nearby regions forming this world region's effective area. */
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new ArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
private final int _regionY;
@@ -52,8 +52,9 @@ public class WorldRegion
if (!isOn)
{
for (WorldObject wo : _visibleObjects.values())
for (int i = 0; i < _visibleObjects.size(); i++)
{
final WorldObject wo = _visibleObjects.get(i);
if (wo.isAttackable())
{
final Attackable mob = (Attackable) wo;
@@ -87,15 +88,16 @@ public class WorldRegion
}
else
{
for (WorldObject wo : _visibleObjects.values())
for (int i = 0; i < _visibleObjects.size(); i++)
{
final WorldObject wo = _visibleObjects.get(i);
if (wo.isAttackable())
{
// Start HP/MP/CP regeneration task.
((Attackable) wo).getStatus().startHpMpRegeneration();
RandomAnimationTaskManager.getInstance().add((Npc) wo);
}
else if (wo instanceof Npc)
else if (wo.isNpc())
{
RandomAnimationTaskManager.getInstance().add((Npc) wo);
}
@@ -110,11 +112,19 @@ public class WorldRegion
public boolean areNeighborsEmpty()
{
for (WorldRegion worldRegion : _surroundingRegions)
for (int i = 0; i < _surroundingRegions.length; i++)
{
if (worldRegion.isActive() && worldRegion.getVisibleObjects().values().stream().anyMatch(WorldObject::isPlayable))
final WorldRegion worldRegion = _surroundingRegions[i];
if (worldRegion.isActive())
{
return false;
final List<WorldObject> regionObjects = worldRegion.getVisibleObjects();
for (int j = 0; j < regionObjects.size(); j++)
{
if (regionObjects.get(j).isPlayable())
{
return false;
}
}
}
}
return true;
@@ -157,9 +167,9 @@ public class WorldRegion
// Then, set a timer to activate the neighbors.
_neighborsTask = ThreadPool.schedule(() ->
{
for (WorldRegion worldRegion : _surroundingRegions)
for (int i = 0; i < _surroundingRegions.length; i++)
{
worldRegion.setActive(true);
_surroundingRegions[i].setActive(true);
}
}, 1000 * Config.GRID_NEIGHBOR_TURNON_TIME);
}
@@ -183,8 +193,9 @@ public class WorldRegion
// Suggest means: first check if a neighbor has PlayerInstances in it. If not, deactivate.
_neighborsTask = ThreadPool.schedule(() ->
{
for (WorldRegion worldRegion : _surroundingRegions)
for (int i = 0; i < _surroundingRegions.length; i++)
{
final WorldRegion worldRegion = _surroundingRegions[i];
if (worldRegion.areNeighborsEmpty())
{
worldRegion.setActive(false);
@@ -206,7 +217,13 @@ public class WorldRegion
return;
}
_visibleObjects.put(object.getObjectId(), object);
synchronized (_visibleObjects)
{
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
}
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)
@@ -230,7 +247,11 @@ public class WorldRegion
{
return;
}
_visibleObjects.remove(object.getObjectId());
synchronized (_visibleObjects)
{
_visibleObjects.remove(object);
}
if (object.isPlayable() && areNeighborsEmpty() && !Config.GRIDS_ALWAYS_ON)
{
@@ -238,7 +259,7 @@ public class WorldRegion
}
}
public Map<Integer, WorldObject> getVisibleObjects()
public List<WorldObject> getVisibleObjects()
{
return _visibleObjects;
}