'From Cuis 2.3 of 22 March 2010 [latest update: #472] on 27 May 2010 at 9:55:37 am'!

!WorldState methodsFor: 'update cycle' stamp: 'jmv 5/27/2010 09:55'!
doOneCycleFor: aWorld
	"Do one cycle of the interaction loop. This method is called repeatedly when the world is running.
	
	Make for low cpu usage if the ui is inactive, but quick response when ui is in use.
	However, after some inactivity, there will be a MaxCycleLapse delay before the ui gets responsive again."

	| hadAnyEvent thisPause |

	thisPause _ pause.
	"pause is set to very short if we have events already enqueued, so they are processed quickly."
	(Preferences higherPerformance or: [ Sensor eventQueue isEmpty not ]) 
		ifTrue: [ thisPause _ 1 ].
	self interCyclePause: thisPause.

	hadAnyEvent _ self doOneCycleNowFor: aWorld.
	hadAnyEvent
		ifTrue: [  pause _ MinCycleLapse ]
		ifFalse: [
			pause < MaxCycleLapse		"No events processed? Start saving CPU!!"
				ifTrue: [
					pause _ pause * 21//20 ]]! !

