polypompholyx has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
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...
while (1) { $taxis->taxis(); # move every woodlouse through one cycle DoOneEvent( $running ? DONT_WAIT : ALL_EVENTS ); }
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...
$mw->repeat( 50, [ sub { $taxis->taxis() if $running } ] ); DoOneEvent( $running ? DONT_WAIT : ALL_EVENTS ) while 1;
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!
polypompholyx
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deep recursion in Tk repeat
by bbfu (Curate) on Sep 01, 2003 at 20:00 UTC | |
by polypompholyx (Chaplain) on Sep 02, 2003 at 09:28 UTC | |
|
Re: Deep recursion in Tk repeat
by benn (Vicar) on Sep 01, 2003 at 16:19 UTC | |
|
Re: Deep recursion in Tk repeat
by bobn (Chaplain) on Sep 01, 2003 at 21:51 UTC | |
|
Re: Deep recursion in Tk repeat
by aquarium (Curate) on Sep 01, 2003 at 12:54 UTC |