Index: C:/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java
===================================================================
--- C:/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java (revision 1694)
+++ C:/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java (working copy)
@@ -177,21 +177,32 @@
public void run()
{
try {
- int _oldTicks;
+ int _oldTicks;
for (;;)
{
- long runtime = System.currentTimeMillis() - _gameStartTime;
- _oldTicks=_gameTicks;
- _gameTicks = (int)(runtime / MILLIS_IN_TICK);
- if(_oldTicks!=_gameTicks) moveObjects();
- else yield();
-
- runtime = System.currentTimeMillis() - _gameStartTime;
- int sleepTime = 1 + MILLIS_IN_TICK - ((int)runtime) % MILLIS_IN_TICK;
- sleep( sleepTime );
+ long runtime = System.currentTimeMillis() - _gameStartTime; // from server boot to now
+
+ _oldTicks=_gameTicks; // save old ticks value to avoid moving objects 2x in same tick
+
+ _gameTicks = (int)(runtime / MILLIS_IN_TICK); // new ticks value (ticks now)
+
+ if(_oldTicks != _gameTicks) moveObjects(); // XXX: if this makes objects go slower, remove it
+ // but I think since getGameTicks() is used
+ // it will not make that effect
+
+
+ runtime = (System.currentTimeMillis() - _gameStartTime) - runtime;
+
+ // calculate sleep time... time needed to next tick minus time it takes to call moveObjects()
+ int sleepTime = 1 + MILLIS_IN_TICK - ((int)runtime) % MILLIS_IN_TICK;
+
+ //_log.finest("TICK: "+_gameTicks);
+
+ sleep( sleepTime ); // hope other threads will have much more cpu time available now
+ // SelectorThread most of all
if (_stop)
throw new Exception("stopTimer() was called");
- }
+ }
} catch (Exception e) {
_error = e;
}