erratic screen updates (was Slow screen lock/unlock)

Michael J. Lew michaell at unimelb.edu.au
Thu Mar 17 19:23:01 EST 2005


OK, thanks to all who helped me. The suggestions of Malte Brill, Jim 
Hurley and Richard Gaskin were particularly useful.

I've now done some more fiddling around, and it seems that Jim is 
right: my problem is the same as that he was battling previously. 
Malte's suggestion to use messages and a flag rather than an if in a 
repeat did indeed speed up my display. Richard's suggestion of a wait 
with messages also sped up the original script.

My conclusions are:
1. There are few, and erratic screen updates in a repeat loop.
This script results in the display of only two numbers on my system:
on mouseUp
    put 0
    repeat 100
      add 1 to msg
    end repeat
end mouseUp

2. A redraw can indeed be forced with a wait. If I add "wait 0" or 
"unlock screen" within the loop then all of the expected numbers 
flash past rapidly. I didn't see any difference between wait with 
messages and a simple wait.

3. Lock screen does unexpected things. If the loop in the script is 
"add 1 to msg; unlock screen" then it works well, but if it is "lock 
screen; add 1 to msg; unlock screen" then only about every 7th number 
appears.

4. Completion of a handler only forces a redraw if there is a wait 
command. Thus the following handler gives only a couple of numbers:
on mouseUp
    put 0
    addOne
end mouseUp

on addOne
    add 1 to msg
    if msg<100 then send addOne to me
end addOne
If a wait is added by making the line into "if msg<100 then send 
addOne to me in 0 millisecond" then all numbers are displayed.


Here is an improved version of my point animating test script (you'll 
need a button for the script, two graphics and one field):

local timelist

on mouseUp
     set the flag of me to not the flag of me
     if the flag of me then put empty into timeList
     set the l of me to the left of grc 1
     set the w of me to the width of grc 1
     set the t of me to the top of grc 1
     set the h of me to the height of grc 1
     if the flag of me then animatePoints
     if not the flag of me then put reportTimes() into fld 1
     set the clipboardData["text"] to fld 1
   end mouseUp

on animatePoints
   --make randomly placed points
   put empty into myPoints
   repeat 100
     put the l of me + random(the w of me) into x
     put the t of me + random(the h of me) into y
     put x,y & return after mypoints
   end repeat
   --display them
   set the points of grc 2 to myPoints
   if the flag of me then send animatePoints to me in 20 millisecond
   put the milliseconds & return after timeList
end animatePoints

function reportTimes
   put 0 into prevTime
   put line 1 of timeList into st
   repeat for each line ttime in timeList
     put ttime-st & tab & ttime-prevTime & return after durationList
     put ttime into prevTime
   end repeat
   delete line 1 of durationList
   return durationList
end reportTimes

If you run it you may find, as I do, that it is plenty fast enough in 
bursts, but the rate is erratic, with some cycles as much as 6 times 
slower than the average. Overall it works in a disappointing way.

This has been interesting, but at the end I still have to say that I 
haven't found a way to get smooth animation rates. The calculations 
are fast enough and the screen updates are fast enough most of the 
time, but every second or so there are a few slow cycles and that 
makes any animation jerky and horrible.

-- 
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: michaell at unimelb.edu.au
**


More information about the use-livecode mailing list