'From Cuis 1.0 of 16 July 2009 [latest update: #228] on 23 July 2009 at 11:46:44 pm'!

!WorldState methodsFor: 'update cycle' stamp: 'jmv 7/23/2009 23:45'!
interCyclePause: milliSecs
	"delay enough that the previous cycle plus the amount of delay will equal milliSecs.  If the cycle is already expensive, then no delay occurs.  However, if the system is idly waiting for interaction from the user, the method will delay for a proportionally long time and cause the overall CPU usage of Squeak to be low."

	| currentTime wait |
	waitDelay ifNil: [ waitDelay _ Delay forMilliseconds: 50 ].
	Preferences serverMode
		ifFalse: [
			(lastCycleTime notNil and: [CanSurrenderToOS ~~ false]) ifTrue: [ 
				currentTime _ Time millisecondClockValue.
				wait _ lastCycleTime + milliSecs - currentTime.
		 		(wait > 0 and: [ wait <= milliSecs ] )
				ifTrue: [
					waitDelay setDelay: wait; wait ] ] ]
		ifTrue: [ waitDelay setDelay: 50; wait ].

	lastCycleTime _  Time millisecondClockValue.
	CanSurrenderToOS _ true.! !

