Tracking animation in multiple windows using NSTimer vs NSThread?
Tracking animation in multiple windows using NSTimer vs NSThread?
- Subject: Tracking animation in multiple windows using NSTimer vs NSThread?
- From: "l.m.orchard" <email@hidden>
- Date: Sat, 11 Aug 2001 23:56:13 -0400
Okay, so I have this app I'm playing with to experiment with managing
multiple windows outside the NSDocument context. One of the things I
wanted to do with it is run an associated with each NSWindowController
that makes a circle bounce around in a custom NSView in the Window. This
view sends messages back to the controller to update it on the circle's
location, which in turn sends messages back to a master app controller
that maintains an NSTableView listing the locations of all circles in all
spawned windows.
So, basically, I have a bunch of windows on-screen with bouncing balls,
and one main window with a table view displaying a constantly updated list
of the positions of the bouncing balls in the child windows. Make sense?
Problem is that I use 100% CPU, and I think it's because I'm trying to
make the run loop do too much. I'm using an NSTimer in every
BouncingBallView which calls a performAnimation: message every 0.5 sec to
update the position of the ball and flag the View as needing re-display.
And every time the circle's position is updated, it messages it's
controller, which in turn messages the master controller, which in turn
updates its table view.
So I'm wondering which part of this process is so heavyweight.
Is it the timers? I thought about maybe having a single shared
BouncingBallViewAnimator object which maintains a global list of all Views,
uses a single timer, and iterates through every view to send it a
performAnimation: message (maybe via an NSConnection to ensure it happens
on the main thread?)
Or... is it the main tracking window, which recieves an updateData: method
from every WindowController every time a BouncingBallView animates?
Where I'm going with this is a multi-threaded download manager. I'll
replace the bouncing balls with NSTasks running wget, and I want every
thread to update a main window listing the progress of every download
thread, as well as progress bars in child windows (instead of the balls).
--
Leslie Michael Orchard <email@hidden>
ICQ: 492905 (home) 11082089 (work)
"...see you space cowboy..."