Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/com/l2jserver/gameserver/GameTimeController.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- java/com/l2jserver/gameserver/GameTimeController.java (revision 6306)
- +++ java/com/l2jserver/gameserver/GameTimeController.java (revision )
- @@ -1,36 +1,36 @@
- /*
- * Copyright (C) 2004-2013 L2J Server
- - *
- + *
- * This file is part of L2J Server.
- - *
- + *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- - *
- + *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- - *
- + *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver;
- -import java.util.Calendar;
- -import java.util.logging.Level;
- -import java.util.logging.Logger;
- -
- -import javolution.util.FastMap;
- -
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.ai.CtrlEvent;
- import com.l2jserver.gameserver.ai.L2CharacterAI;
- import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.util.StackTrace;
- +import javolution.util.FastMap;
- +import java.util.Calendar;
- +import java.util.Iterator;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- /**
- * Game Time controller class.
- * @author Unknown, Forsaiken
- @@ -38,7 +38,7 @@
- public final class GameTimeController extends Thread
- {
- private static final Logger _log = Logger.getLogger(GameTimeController.class.getName());
- -
- +
- public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
- public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
- public static final int IG_DAYS_PER_DAY = 6;
- @@ -47,53 +47,53 @@
- public static final int MINUTES_PER_IG_DAY = SECONDS_PER_IG_DAY / 60;
- public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
- public static final int TICKS_SUN_STATE_CHANGE = TICKS_PER_IG_DAY / 4;
- -
- +
- private static GameTimeController _instance;
- -
- +
- - private final FastMap<Integer, L2Character> _movingObjects = new FastMap<Integer, L2Character>().shared();
- + private final FastMap<L2Character, Integer> _movingObjects = new FastMap<L2Character, Integer>().shared();
- private final long _referenceTime;
- -
- +
- private GameTimeController()
- {
- super("GameTimeController");
- super.setDaemon(true);
- super.setPriority(MAX_PRIORITY);
- -
- +
- final Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- _referenceTime = c.getTimeInMillis();
- -
- +
- super.start();
- }
- -
- +
- public static final void init()
- {
- _instance = new GameTimeController();
- }
- -
- +
- public final int getGameTime()
- {
- return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
- }
- -
- +
- public final int getGameHour()
- {
- return getGameTime() / 60;
- }
- -
- +
- public final int getGameMinute()
- {
- return getGameTime() % 60;
- }
- -
- +
- public final boolean isNight()
- {
- return getGameHour() < 6;
- }
- -
- +
- /**
- * The true GameTime tick. Directly taken from current time. This represents the tick of the time.
- * @return
- @@ -102,7 +102,7 @@
- {
- return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
- }
- -
- +
- /**
- * Add a L2Character to movingObjects of GameTimeController.
- * @param cha The L2Character to add to movingObjects of GameTimeController
- @@ -113,10 +113,11 @@
- {
- return;
- }
- -
- +
- - _movingObjects.putIfAbsent(cha.getObjectId(), cha);
- + _movingObjects.put(cha, 0); // NOTE: Deedlit - probably no noticeable performance improvement here...
- +// _movingObjects.putIfAbsent(cha, 0);
- }
- -
- +
- /**
- * Move all L2Characters contained in movingObjects of GameTimeController.<BR>
- * <B><U> Concept</U> :</B><BR>
- @@ -130,20 +131,32 @@
- */
- private final void moveObjects()
- {
- - L2Character character;
- - for (FastMap.Entry<Integer, L2Character> e = _movingObjects.head(), tail = _movingObjects.tail(); (e = e.getNext()) != tail;)
- + final Iterator<L2Character> i = _movingObjects.keySet().iterator();
- + L2Character cha;
- + while (i.hasNext())
- {
- - character = e.getValue();
- -
- - if (character.updatePosition(getGameTicks()))
- + cha = i.next();
- + if (cha == null)
- {
- - // Destination reached. Remove from map and execute arrive event.
- - _movingObjects.remove(e.getKey());
- - fireCharacterArrived(character);
- + i.remove();
- + continue;
- + }
- + // If movement is finished, the L2Character is removed from movingObjects
- + if (cha.updatePosition(getGameTicks()))
- + {
- + /**
- + * NOTE: Deedlit - 2nd big performance improvement hint:
- + * 1) Determine in {@link com.l2jserver.gameserver.model.actor.L2Character#moveToLocation(int, int, int, int)} if character is already moving (if so, do not call registerMovingObject())
- + * 2) Remove registerMovingObject from {@link com.l2jserver.gameserver.model.actor.L2Character#moveToNextRoutePoint()}
- + * 3) Place ai.notifyEvent(CtrlEvent.EVT_ARRIVED) in {@link com.l2jserver.gameserver.model.actor.L2Character#updatePosition(int)} and remove from {@link com.l2jserver.gameserver.GameTimeController#fireCharacterArrived(com.l2jserver.gameserver.model.actor.L2Character)}
- + * 4) Determine if moving object should be removed from map, by checking {@link com.l2jserver.gameserver.model.actor.L2Character#isMoving()} (_move is always null when last move was completed or char stopped)
- + */
- + i.remove();
- + fireCharacterArrived(cha);
- }
- }
- }
- -
- +
- private final void fireCharacterArrived(final L2Character character)
- {
- final L2CharacterAI ai = character.getAI();
- @@ -151,7 +164,7 @@
- {
- return;
- }
- -
- +
- ThreadPoolManager.getInstance().executeAi(new Runnable()
- {
- @Override
- @@ -163,7 +176,7 @@
- {
- character.getKnownList().findObjects();
- }
- -
- +
- ai.notifyEvent(CtrlEvent.EVT_ARRIVED);
- }
- catch (final Throwable e)
- @@ -173,21 +186,21 @@
- }
- });
- }
- -
- +
- public final void stopTimer()
- {
- super.interrupt();
- _log.log(Level.INFO, "Stopping " + getClass().getSimpleName());
- }
- -
- +
- @Override
- public final void run()
- {
- _log.log(Level.CONFIG, getClass().getSimpleName() + ": Started.");
- -
- +
- long nextTickTime, sleepTime;
- boolean isNight = isNight();
- -
- +
- if (isNight)
- {
- ThreadPoolManager.getInstance().executeAi(new Runnable()
- @@ -199,11 +212,11 @@
- }
- });
- }
- -
- +
- while (true)
- {
- nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
- -
- +
- try
- {
- moveObjects();
- @@ -212,7 +225,7 @@
- {
- StackTrace.displayStackTraceInformation(e);
- }
- -
- +
- sleepTime = nextTickTime - System.currentTimeMillis();
- if (sleepTime > 0)
- {
- @@ -222,14 +235,14 @@
- }
- catch (final InterruptedException e)
- {
- -
- +
- }
- }
- -
- +
- if (isNight() != isNight)
- {
- isNight = !isNight;
- -
- +
- ThreadPoolManager.getInstance().executeAi(new Runnable()
- {
- @Override
- @@ -241,7 +254,7 @@
- }
- }
- }
- -
- +
- public static final GameTimeController getInstance()
- {
- return _instance;
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement