All pastes #68371 Raw Edit

Someone

public text v1 · immutable
#68371 ·published 2006-06-21 14:12 UTC
rendered paste body
Index: /root/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java
===================================================================
--- /root/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java	(revision 2136)
+++ /root/workspace/L2_GameServer_c4/java/net/sf/l2j/gameserver/GameTimeController.java	(working copy)
@@ -179,10 +179,16 @@
 				{

 					int _oldTicks=_gameTicks; // save old ticks value to avoid moving objects 2x in same tick	

 					long runtime = System.currentTimeMillis() - _gameStartTime; // from server boot to now

+					int _newTicks;

+                    for (;;) {

+					    _newTicks = (int) (runtime / MILLIS_IN_TICK);

+                        if (_oldTicks != _newTicks) {

+                            _gameTicks = _newTicks;

+                            break;

+                        }

+                    }

 

-					_gameTicks = (int) (runtime / MILLIS_IN_TICK); // new ticks value (ticks now) 

-

-					if (_oldTicks != _gameTicks) moveObjects(); // XXX: if this makes objects go slower, remove it

+					moveObjects(); // XXX: if this makes objects go slower, remove it

 					// but I think it can't make that effect. is it better to call moveObjects() twice in same

 					// tick to make-up for missed tick ?   or is it better to ignore missed tick ?

 					// (will happen very rarely but it will happen ... on garbage collection definitely)

@@ -190,11 +196,11 @@
 					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;

+					int sleepTime = (int) ((1 + MILLIS_IN_TICK - ((int) runtime) % MILLIS_IN_TICK) * 0.95);

 

 					//_log.finest("TICK: "+_gameTicks);

 

-					sleep(sleepTime); // hope other threads will have much more cpu time available now

+					if (sleepTime > 0) sleep(sleepTime); // hope other threads will have much more cpu time available now

 					// SelectorThread most of all

 				}

 			}