Addition of the Chronos class.
This commit is contained in:
@@ -22,11 +22,12 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SunRise;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SunSet;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
|
||||
public class GameTimeController extends Thread
|
||||
{
|
||||
private static GameTimeController _instance;
|
||||
private long _gameStartTime = System.currentTimeMillis() - 3600000L;
|
||||
private long _gameStartTime = Chronos.currentTimeMillis() - 3600000L;
|
||||
|
||||
public static GameTimeController getInstance()
|
||||
{
|
||||
@@ -45,7 +46,7 @@ public class GameTimeController extends Thread
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
final long time = (System.currentTimeMillis() - _gameStartTime) / 10000L;
|
||||
final long time = (Chronos.currentTimeMillis() - _gameStartTime) / 10000L;
|
||||
return (int) time;
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ public class GameTimeController extends Thread
|
||||
{
|
||||
broadcastToPlayers(new SunRise());
|
||||
Thread.sleep(21600000L);
|
||||
_gameStartTime = System.currentTimeMillis();
|
||||
_gameStartTime = Chronos.currentTimeMillis();
|
||||
broadcastToPlayers(new SunSet());
|
||||
Thread.sleep(3600000L);
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.TeleportToLocation;
|
||||
import org.l2jmobius.gameserver.templates.Weapon;
|
||||
import org.l2jmobius.gameserver.threadpool.ThreadPool;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
import org.l2jmobius.util.Rnd;
|
||||
|
||||
public abstract class Creature extends WorldObject
|
||||
@@ -193,7 +194,7 @@ public abstract class Creature extends WorldObject
|
||||
{
|
||||
return super.getX();
|
||||
}
|
||||
final long elapsed = System.currentTimeMillis() - _moveStartTime;
|
||||
final long elapsed = Chronos.currentTimeMillis() - _moveStartTime;
|
||||
final int diff = (int) (elapsed * _xAddition);
|
||||
final int remain = Math.abs(getXdestination() - super.getX()) - Math.abs(diff);
|
||||
if (remain > 0)
|
||||
@@ -210,7 +211,7 @@ public abstract class Creature extends WorldObject
|
||||
{
|
||||
return super.getY();
|
||||
}
|
||||
final long elapsed = System.currentTimeMillis() - _moveStartTime;
|
||||
final long elapsed = Chronos.currentTimeMillis() - _moveStartTime;
|
||||
final int diff = (int) (elapsed * _yAddition);
|
||||
final int remain = Math.abs(getYdestination() - super.getY()) - Math.abs(diff);
|
||||
if (remain > 0)
|
||||
@@ -929,7 +930,7 @@ public abstract class Creature extends WorldObject
|
||||
setXdestination(destinationX);
|
||||
setYdestination(destinationY);
|
||||
setZdestination(z);
|
||||
_moveStartTime = System.currentTimeMillis();
|
||||
_moveStartTime = Chronos.currentTimeMillis();
|
||||
if (_timeToTarget < 0L)
|
||||
{
|
||||
_timeToTarget = 0L;
|
||||
|
@@ -81,6 +81,7 @@ import org.l2jmobius.gameserver.templates.CharTemplate;
|
||||
import org.l2jmobius.gameserver.templates.Item;
|
||||
import org.l2jmobius.gameserver.templates.Weapon;
|
||||
import org.l2jmobius.gameserver.threadpool.ThreadPool;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
import org.l2jmobius.util.Rnd;
|
||||
|
||||
public class PlayerInstance extends Creature
|
||||
@@ -435,7 +436,7 @@ public class PlayerInstance extends Creature
|
||||
{
|
||||
_pvpTask = ThreadPool.scheduleAtFixedRate(new pvpTask(), 1000, 1000);
|
||||
}
|
||||
_lastPvpTime = System.currentTimeMillis() + 30000;
|
||||
_lastPvpTime = Chronos.currentTimeMillis() + 30000;
|
||||
}
|
||||
if (_pvpFlag == value)
|
||||
{
|
||||
@@ -452,7 +453,7 @@ public class PlayerInstance extends Creature
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
final long currentTime = Chronos.currentTimeMillis();
|
||||
if (currentTime > _lastPvpTime)
|
||||
{
|
||||
stopPvPFlag();
|
||||
@@ -1660,7 +1661,7 @@ public class PlayerInstance extends Creature
|
||||
|
||||
public long getUptime()
|
||||
{
|
||||
return System.currentTimeMillis() - _uptime;
|
||||
return Chronos.currentTimeMillis() - _uptime;
|
||||
}
|
||||
|
||||
public void onMagicUseTimer(Creature target, Skill skill)
|
||||
|
@@ -43,6 +43,7 @@ import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.templates.Item;
|
||||
import org.l2jmobius.loginserver.LoginController;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
|
||||
public class ClientThread extends Thread
|
||||
{
|
||||
@@ -81,17 +82,17 @@ public class ClientThread extends Thread
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long starttime = System.currentTimeMillis();
|
||||
long starttime = Chronos.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((_activeChar != null) && (_autoSaveTime < (System.currentTimeMillis() - starttime)))
|
||||
if ((_activeChar != null) && (_autoSaveTime < (Chronos.currentTimeMillis() - starttime)))
|
||||
{
|
||||
saveCharToDisk(_activeChar);
|
||||
starttime = System.currentTimeMillis();
|
||||
starttime = Chronos.currentTimeMillis();
|
||||
}
|
||||
final byte[] decrypt = _connection.getPacket();
|
||||
_handler.handlePacket(decrypt);
|
||||
@@ -595,7 +596,7 @@ public class ClientThread extends Thread
|
||||
oldChar.setTitle(st.nextToken().trim());
|
||||
oldChar.setAllyId(Integer.parseInt(st.nextToken()));
|
||||
World.getInstance().storeObject(oldChar);
|
||||
oldChar.setUptime(System.currentTimeMillis());
|
||||
oldChar.setUptime(Chronos.currentTimeMillis());
|
||||
lnr.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -34,6 +34,7 @@ import javax.swing.border.LineBorder;
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.GameServer;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
import org.l2jmobius.util.Locator;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ public class SystemPanel extends JPanel
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(SystemPanel.class.getName());
|
||||
|
||||
protected static final long START_TIME = System.currentTimeMillis();
|
||||
protected static final long START_TIME = Chronos.currentTimeMillis();
|
||||
|
||||
public SystemPanel()
|
||||
{
|
||||
@@ -130,7 +131,7 @@ public class SystemPanel extends JPanel
|
||||
}
|
||||
lblConnected.setText("Connected: " + playerCount);
|
||||
lblMaxConnected.setText("Max connected: " + World.MAX_CONNECTED_COUNT);
|
||||
lblElapsedTime.setText("Elapsed: " + getDurationBreakdown(System.currentTimeMillis() - START_TIME));
|
||||
lblElapsedTime.setText("Elapsed: " + getDurationBreakdown(Chronos.currentTimeMillis() - START_TIME));
|
||||
}
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.l2jmobius.gameserver.network.Connection;
|
||||
import org.l2jmobius.util.Chronos;
|
||||
|
||||
public class LoginController
|
||||
{
|
||||
@@ -50,7 +51,7 @@ public class LoginController
|
||||
public int assignSessionKeyToLogin(String account, int accessLevel, Socket cSocket)
|
||||
{
|
||||
int key = -1;
|
||||
key = (int) System.currentTimeMillis() & 0xFFFFFF;
|
||||
key = (int) Chronos.currentTimeMillis() & 0xFFFFFF;
|
||||
_logins.put(account, key);
|
||||
_accountsInLoginServer.put(account, cSocket);
|
||||
_accessLevels.put(account, accessLevel);
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Pantelis Andrianakis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package org.l2jmobius.util;
|
||||
|
||||
/**
|
||||
* Chronos updates an internal long value with System.currentTimeMillis() approximately every 1 millisecond.<br>
|
||||
* To get the current time in milliseconds use Chronos.currentTimeMillis()
|
||||
* @author Pantelis Andrianakis
|
||||
* @version February 3rd 2021
|
||||
*/
|
||||
public class Chronos extends Thread
|
||||
{
|
||||
private long _currentTimeMillis = System.currentTimeMillis();
|
||||
|
||||
public Chronos()
|
||||
{
|
||||
super.setName("Chronos");
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setDaemon(true);
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_currentTimeMillis = System.currentTimeMillis();
|
||||
|
||||
// Sleep for approximately 1 millisecond.
|
||||
try
|
||||
{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond,the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.<br>
|
||||
* <br>
|
||||
* See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).
|
||||
* @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
|
||||
*/
|
||||
public static long currentTimeMillis()
|
||||
{
|
||||
return getInstance()._currentTimeMillis;
|
||||
}
|
||||
|
||||
public static Chronos getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final Chronos INSTANCE = new Chronos();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user