PowerBooks and iBooks have an option called "Allow Process Cycling" in
the
Energy Saver control panel. This feature will reduce the processor
speed
after its
been idle for a while in order to save battery life.
The downside to this can be that an application that is doing something
processor-intensive (like a sprite-based game for example) could appear
to
be jumpy unless the mouse is moving rather than the smooth execution
you get
when the processor is not trying to save battery life.
Using DECLARE method in REALbasic, you can tell Mac OS that something
important is going on so that it won't reduce processor speed. Here's an
example of the declare:
dim x as integer
#if TargetMacOS then
// make sure the power manager supports this function
if system.gestalt("powr",x) AND (BitwiseAnd(x,2) <> 0) then
#if TargetCarbon then
Declare Function IdleUpdate Lib "CarbonLib" ()
#else
Declare Function IdleUpdate Lib "InterfaceLib" ()
#endif
IdleUpdate
end
#endif
For example, in a Sprite-based game you might want to make calls to
IdleUpdate in the NextFrame event. With the way that process cycling
works
you shouldn't have to call this for each frame. The sample code below
could
be used in the NextFrame event to call IdleUpdate every 5 seconds. You
will
need to add a property called LastIdleUpdate (integer) to the window
that
contains the spritesurface.
// how many seconds between updates
const kUpdateTime = 5
// are we due to call idleUpdate again
if (ticks - lastIdleUpdate) > (kUpdateTime * 60) then
lastIdleUpdate = ticks
IdleUpdate// uses the declare statements
end
Keep in mind of course that this could be useful for any
processor-intensive
code not just sprite-based applications.
This tip was suggested by Mike Bailey with help from Thomas Tempelmann.
--
Geoff Perlman
President & CEO
REAL Software, Inc.
http://www.realsoftware.com
mailto:geoff at realsoftware dot com
Phone: 512-328-REAL (7325) x711
Fax: 512-328-7372
- - - - - - - - - -
Got a useful tip to share? Send it to us at:
REALbasic-tips at lists dot realsoftware dot com dot
To unsubscribe from the Tips list, send an email to
<mailto:realbasic-tips-off at lists dot realsoftware dot com>
|