Re: Optimizing Screensaver
Re: Optimizing Screensaver
- Subject: Re: Optimizing Screensaver
- From: Stéphane Sudre <email@hidden>
- Date: Fri, 16 Jan 2004 23:56:41 +0100
On vendredi, janvier 16, 2004, at 10:11 PM, Jurjan Dijkstra wrote:
Hi list,
I'm making a screensaver (like everybody has done at one time or
another I guess).
My problem is that on 'slower' machines it's taking up to 40%
processor-utilization.
( found by ssh'ing into the machine and using top).
I would like to lower that percentage.
After all, all I'm doing is displaying some text (max about 7 small
lines)
(using: [[NSString stringWithFormat:@"%@",[teksten
objectAtIndex:i]] drawAtPoint:NSMakePoint(x_pos, y_pos[i])
withAttributes:attribuutjes];)
and some small picts
(using: [ster[1] compositeToPoint:NSMakePoint((([self
bounds].size.width - (grootte.height * 5)) / 2) + (i *
grootte.height), y_pos[[teksten count]]) fromRect:NSMakeRect( 0, 0,
grootte.height, grootte.height ) operation:NSCompositeSourceOver];)
and appleevents (querying iTunes (what else....))
I have NO idea where to start, and furthermore: how DOES one analyse a
screensaver while running??
After all, a screensaver (by definitiion) only runs when the user
isn't doing anything.
Does anybody have an idea on how to accomplish this??
2 possible suggestions without using the dev tools:
[[NSString stringWithFormat:@"%@",[teksten objectAtIndex:i]]
drawAtPoint:NSMakePoint(x_pos, y_pos[i]) withAttributes:attribuutjes];
[[teksten objectAtIndex:i] drawAtPoint:NSMakePoint(x_pos, y_pos[i])
withAttributes:attribuutjes];
// If teksten only contains NSString instances
[ster[1] compositeToPoint:NSMakePoint((([self bounds].size.width -
(grootte.height * 5)) / 2) + (i * grootte.height), y_pos[[teksten
count]]) fromRect:NSMakeRect( 0, 0, grootte.height, grootte.height )
operation:NSCompositeSourceOver];
[ster[1] compositeToPoint:NSMakePoint(((NSWidth([self bounds]) -
(grootte.height * 5)) * 0.5) + (i * grootte.height), y_pos[[teksten
count]]) fromRect:NSMakeRect( 0, 0, grootte.height, grootte.height )
operation:NSCompositeSourceOver];
You should also consider caching: NSMakeRect( 0, 0, grootte.height,
grootte.height )
This is a method constant I guess: ((NSWidth([self bounds]) -
(grootte.height * 5)) * 0.5)
so keep it as a constant at the beginning of the loop
float tHorizontalStart;
NSRect tDrawingFrame;
NSPoint tPoint;
tHorizontalStart= (NSWidth([self bounds] - grootte.height * 5) * 0.5;
tDrawingFrame= NSMakeRect( 0, 0, grootte.height, grootte.height );
tPoint.x= tHorizontalStart;
tPoint.y= y_pos[[teksten count]];
for(...)
{
[ster[1] compositeToPoint: tPoint
fromRect:tDrawingFrame
operation:NSCompositeSourceOver];
tPoint += grootte.height; // One addition instead of a lot of
operations
}
And before trying to optimize something that is internally slow
(currently) (drawing pictures and text with Quartz), think OpenGL.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.