From 45967e4fd8654f3c749f4797cbc2e4efdb243aa6 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 17 Mar 2021 22:05:41 +0000 Subject: [PATCH] Use UnboundArrayList for GameTimeController. --- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 64 +++++++++---------- .../gameserver/GameTimeController.java | 64 +++++++++---------- .../gameserver/GameTimeController.java | 39 ++++++++--- .../gameserver/GameTimeController.java | 39 ++++++++--- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- .../gameserver/GameTimeController.java | 39 +++++++++-- 23 files changed, 728 insertions(+), 219 deletions(-) diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameTimeController.java index f3806517b8..b8e6dc80de 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameTimeController.java @@ -28,6 +28,7 @@ import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.ai.CtrlEvent; import org.l2jmobius.gameserver.instancemanager.DayNightSpawnManager; import org.l2jmobius.gameserver.model.actor.Creature; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * @version $Revision: 1.1.4.8 $ $Date: 2005/04/06 16:13:24 $ @@ -45,7 +46,7 @@ public class GameTimeController protected static long _gameStartTime; protected static boolean _isNight = false; - private static List _movingObjects = new ArrayList<>(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); protected static TimerThread _timer; private final ScheduledFuture _timerWatcher; @@ -94,17 +95,14 @@ public class GameTimeController * All Creature in movement are identified in movingObjects of GameTimeController. * @param creature The Creature to add to movingObjects of GameTimeController */ - public synchronized void registerMovingObject(Creature creature) + public void registerMovingObject(Creature creature) { if (creature == null) { return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -119,39 +117,34 @@ public class GameTimeController *
  • If movement is finished, the Creature is removed from movingObjects
  • *
  • Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED
  • */ - protected synchronized void moveObjects() + protected void moveObjects() { - // Get all Creature from the ArrayList movingObjects and put them into a table - final Creature[] chars = _movingObjects.toArray(new Creature[_movingObjects.size()]); - - // Create an ArrayList to contain all Creature that are arrived to destination - List ended = null; - - // Go throw the table containing Creature in movement - for (Creature creature : chars) + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) { - // Update the position of the Creature and return True if the movement is finished - final boolean end = creature.updatePosition(_gameTicks); - - // If movement is finished, the Creature is removed from movingObjects and added to the ArrayList ended - if (end) + final Creature creature = _movingObjects.get(i); + if (creature == null) { - _movingObjects.remove(creature); - if (ended == null) + continue; + } + + if (creature.updatePosition(_gameTicks)) + { + if (finished == null) { - ended = new ArrayList<>(); + finished = new ArrayList<>(); } - - ended.add(creature); + finished.add(creature); } } - // Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject - // then notify AI with EVT_ARRIVED - // TODO: maybe a general TP is needed for that kinda stuff (all knownlist updates should be done in a TP anyway). - if (ended != null) + if (finished != null) { - ThreadPool.execute(new MovingObjectArrived(ended)); + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + ThreadPool.execute(new MovingObjectArrived(finished)); } } @@ -235,24 +228,25 @@ public class GameTimeController */ class MovingObjectArrived implements Runnable { - private final List _ended; + private final List _finished; - MovingObjectArrived(List ended) + MovingObjectArrived(List finished) { - _ended = ended; + _finished = finished; } @Override public void run() { - for (Creature creature : _ended) + for (int i = 0; i < _finished.size(); i++) { try { + final Creature creature = _finished.get(i); creature.getKnownList().updateKnownObjects(); creature.getAI().notifyEvent(CtrlEvent.EVT_ARRIVED); } - catch (NullPointerException e) + catch (Exception e) { } } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java index f3806517b8..b8e6dc80de 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java @@ -28,6 +28,7 @@ import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.ai.CtrlEvent; import org.l2jmobius.gameserver.instancemanager.DayNightSpawnManager; import org.l2jmobius.gameserver.model.actor.Creature; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * @version $Revision: 1.1.4.8 $ $Date: 2005/04/06 16:13:24 $ @@ -45,7 +46,7 @@ public class GameTimeController protected static long _gameStartTime; protected static boolean _isNight = false; - private static List _movingObjects = new ArrayList<>(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); protected static TimerThread _timer; private final ScheduledFuture _timerWatcher; @@ -94,17 +95,14 @@ public class GameTimeController * All Creature in movement are identified in movingObjects of GameTimeController. * @param creature The Creature to add to movingObjects of GameTimeController */ - public synchronized void registerMovingObject(Creature creature) + public void registerMovingObject(Creature creature) { if (creature == null) { return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -119,39 +117,34 @@ public class GameTimeController *
  • If movement is finished, the Creature is removed from movingObjects
  • *
  • Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED
  • */ - protected synchronized void moveObjects() + protected void moveObjects() { - // Get all Creature from the ArrayList movingObjects and put them into a table - final Creature[] chars = _movingObjects.toArray(new Creature[_movingObjects.size()]); - - // Create an ArrayList to contain all Creature that are arrived to destination - List ended = null; - - // Go throw the table containing Creature in movement - for (Creature creature : chars) + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) { - // Update the position of the Creature and return True if the movement is finished - final boolean end = creature.updatePosition(_gameTicks); - - // If movement is finished, the Creature is removed from movingObjects and added to the ArrayList ended - if (end) + final Creature creature = _movingObjects.get(i); + if (creature == null) { - _movingObjects.remove(creature); - if (ended == null) + continue; + } + + if (creature.updatePosition(_gameTicks)) + { + if (finished == null) { - ended = new ArrayList<>(); + finished = new ArrayList<>(); } - - ended.add(creature); + finished.add(creature); } } - // Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject - // then notify AI with EVT_ARRIVED - // TODO: maybe a general TP is needed for that kinda stuff (all knownlist updates should be done in a TP anyway). - if (ended != null) + if (finished != null) { - ThreadPool.execute(new MovingObjectArrived(ended)); + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + ThreadPool.execute(new MovingObjectArrived(finished)); } } @@ -235,24 +228,25 @@ public class GameTimeController */ class MovingObjectArrived implements Runnable { - private final List _ended; + private final List _finished; - MovingObjectArrived(List ended) + MovingObjectArrived(List finished) { - _ended = ended; + _finished = finished; } @Override public void run() { - for (Creature creature : _ended) + for (int i = 0; i < _finished.size(); i++) { try { + final Creature creature = _finished.get(i); creature.getKnownList().updateKnownObjects(); creature.getAI().notifyEvent(CtrlEvent.EVT_ARRIVED); } - catch (NullPointerException e) + catch (Exception e) { } } diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/GameTimeController.java index 3044cd9c3d..efe2b4bed7 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,9 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,6 +26,7 @@ import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.instancemanager.DayNightSpawnManager; import org.l2jmobius.gameserver.model.actor.Creature; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -44,7 +45,7 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); private final long _referenceTime; private GameTimeController() @@ -108,10 +109,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -130,7 +128,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/GameTimeController.java index 3044cd9c3d..efe2b4bed7 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,9 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,6 +26,7 @@ import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.instancemanager.DayNightSpawnManager; import org.l2jmobius.gameserver.model.actor.Creature; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -44,7 +45,7 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); private final long _referenceTime; private GameTimeController() @@ -108,10 +109,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -130,7 +128,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer() diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/GameTimeController.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/GameTimeController.java index 48391b466d..e3adea02d5 100644 --- a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/GameTimeController.java +++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/GameTimeController.java @@ -16,7 +16,9 @@ */ package org.l2jmobius.gameserver; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -28,6 +30,7 @@ import org.l2jmobius.gameserver.model.events.EventDispatcher; import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange; import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; +import org.l2jmobius.gameserver.util.UnboundArrayList; /** * Game Time controller class. @@ -47,8 +50,8 @@ public class GameTimeController extends Thread private static GameTimeController _instance; - private final Set _movingObjects = ConcurrentHashMap.newKeySet(); - private final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); + private static final UnboundArrayList _movingObjects = new UnboundArrayList<>(); + private static final Set _shadowSenseCharacters = ConcurrentHashMap.newKeySet(); private final long _referenceTime; private GameTimeController() @@ -112,10 +115,7 @@ public class GameTimeController extends Thread return; } - if (!_movingObjects.contains(creature)) - { - _movingObjects.add(creature); - } + _movingObjects.addIfAbsent(creature); } /** @@ -134,7 +134,32 @@ public class GameTimeController extends Thread */ private void moveObjects() { - _movingObjects.removeIf(Creature::updatePosition); + List finished = null; + for (int i = 0; i < _movingObjects.size(); i++) + { + final Creature creature = _movingObjects.get(i); + if (creature == null) + { + continue; + } + + if (creature.updatePosition()) + { + if (finished == null) + { + finished = new ArrayList<>(); + } + finished.add(creature); + } + } + + if (finished != null) + { + for (int i = 0; i < finished.size(); i++) + { + _movingObjects.remove(finished.get(i)); + } + } } public void stopTimer()