Threads Needed, Waits Wanted
-
I've added an extra parameter to my SketchTalk m command. It's the number of seconds over which the move should be done. This floats a component instance referred to by
b
up 20 units in 5 seconds:m b, [0,0,20], 5
Problem is, this may or may not execute a single frame of the first move:
m b, [0,0,20] m b, [20,0,0]
This is the
movie
function:def movie( args ) # animated move inst = args[0] vec = args[1] nsecs = args[2] nframes = nsecs * $sketch_talk_fps # $sketch_talk_fps is a float frame_vec = [ vec[0]/nframes, vec[1]/nframes, vec[2]/nframes ] mover = Mover.new( frame_vec, nframes, inst ) anim = Sketchup.active_model.active_view.animation = mover puts 'main? ' + (Thread.current == Thread.main).to_s() until anim.done puts 'done? ' + anim.done().to_s() Thread.current.sleep( 100 ) end end # of movie()
Yes, it reports,
Thread.current == Thread.main
No, it reports,
anim.done
is false.It reports this exactly once. I am trying, via the loop at the end of
movie()
to wait for the animation to finish before going on to the next one. But it seems that the wait loop doesn't do any waiting.The
@done
is set to false in theMover
constructor, reset to true in theMover
'sstop()
method. TheView
callsstop()
correctly.The Ruby code has priority. An infinite loop (no call to sleep) loops infinitely and no animation takes place. Calls to
Thread.yield()
don't work, either. -
From previous threads on ... threads (no pun intended) it appears that threading in SU ruby is a no-go. Unleashes all kinds of demons of other dimensions.
-
Is there any reason something like this wouldn't work?
now = Time.now UI.start_timer(0,true){ if(Time.now - now > 0.5) puts "Test" now = Time.now end }
-
@cjthompson said:
Is there any reason something like this wouldn't work?
Yes.. there's no exit condition to exit from the timer loop (stop_timer).
And.. since your not using any start delay (the first param is 0,) it's not necessary to use UI.start_timer, just use a normal Ruby loop of some kind, ie: do .. while, etc.But CJ your on the right track using Time.now as a test condition.
-
@dan rathbun said:
@cjthompson said:
And.. since your not using any start delay (the first param is 0,) it's not necessary to use UI.start_timer, just use a normal Ruby loop of some kind, ie: do .. while, etc.
A normal loop will lock up any other processing. I wonder if a Timer loop allows for other things to process..?
-
How does this topic "jive" with: Re: Timer < 1.0 seconds ?
http://forums.sketchucation.com/viewtopic.php?f=180&t=26454&start=15#p242163Psst, I haven't had time to test that code yet.. Has anyone else?
-
I had this brilliant idea (that was a total flop). Since the delay works between frames in an animation, why not just grab that one?
Was working well until I moved the
puts Time.now() - start
out of the animation code and into the mainline:for i in 1..10 do waiter(500); puts Time.now() - start end
That said something like
0.03, 0.06, ...
So I moved a call to acontinue()
method into the animation in response tostop()
. BugSplat.I think I know how to at least solve the starter problem. The animated "move" commmand stacks move specs that are then run in an animation. Kludgy? Yup. PITA? Yup. But it should actually work.
Advertisement