|go ahead... be a heretic|
Deep recursion in Tk repeatby polypompholyx (Chaplain)
|on Sep 01, 2003 at 10:54 UTC||Need Help??|
polypompholyx has asked for the
wisdom of the Perl Monks concerning the following question:
I have mostly finished writing a Tk composite widget that simulates a biological movement called taxis, so that the technicians at the school I work at don't have to collect two thousand woodlice (sowbugs) for a biology practical next month. The module sets up a Canvas full of Photos of woodlice that mill about according to certain rules, and eventually end up mostly on the right hand (dark) side of the canvas.
The simulation script uses a hand-rolled event-loop to call the taxis method, which moves the woodlice through one cycle. However, this...
didn't work quite right, because the loop (hence the simulation) ran much faster if taxis only had to move one woodlouse, and much slower if it tried to animate fifty at a time. As an alternative, I have tried...
which does what I want, but if the refresh rate (50 ms) is reduced to e.g. 20 ms with a large population of woodlice, the script hangs and complains of deep recursion, presumably because it takes longer than 20 ms to run the taxis code.
This is probably OK, as 50 ms isn't too jerky, but I am a little worried about the elderly computers at the school hanging with values of population and refresh rate that work fine on my speedier machine. I can easily hard-code a slower refresh rate if this happens, but I wondered if there was a nicer way of guesstimating a suitable refresh rate. I guess it would be a combination of benchmarking the code, getting the processor speed somehow, and working out something empirically. Does this sound reasonable, does anyone have any idea how to get information on the 'speed' of the computer, is there a better way to code the refresh callback, or am I just worrying unnecessarily?
Any advice gratefully received!