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


In reply to Deep recursion in Tk repeat by polypompholyx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.