Re: Looking for a wait until x or timeout design pattern..

2012-01-29 Thread Ken Corey

Here's the basic idea of the code I needed.

the touchMove event arrives in no particular order, and in no particular 
time.


If you absolutely have to have a timeout, you can't just test for a 
timestamp on the next run of touchMove, because there might not be 
another touchMove.


I'm not quite clear on what the wait 50 milliseconds with messages 
command does.  Is that a more succinct way of putting it?


-Ken


---8---
-- Semaphore handling for touch movements
--
-- This code is meant to be used to group random events that
-- happen in a timeframe, group them together, and take action
-- on those events as a whole.
--
-- User input is pseudo-random, and we therefore cannot count on
-- events coming in a particular order, or even coming at all.
--
-- I use code similar to this to group several distinct user inputs and
-- deal with several at a time.  If no more events come within the
-- delay period, we fire the handler.
--
-- This isn't perfect, as there doesn't seem to be a way to cancel a
-- pending send...so we guard against the send happening in
-- performAction.
--
-- What this means is that the delay (50 milliseconds below) must
-- be chosen carefully so that there's only one group of data waiting
-- to be processed.
--
-- If the touchMove event happens but is delayed, and another
-- touchMove event with immediate execution happens within the
-- timeout period, the second touchMove event clears the sSemaphore,
-- so then the delayed performAction from the first touchMove event
-- is ignored.
--

local sDetails,sSemaphore

on touchMove pID,pX,pY
   -- check to see if we've dealt with pID before
   if pID is in the keys of sSemaphore then
  -- have seen it before so take action immediately
  put (pXcommapY) into sSemaphore[pID]
  send performAction pID,pX,pY
   else
  -- haven't seen it, only do it after a delay
  put (pXcommapY) into sSemaphore[pID]
  send performAction pID,pX,pY to me in 50 milliseconds
   end if
end touchMove

on performAction
   -- check to see if it's already been handled.
   if the number of lines in the keys of sSemaphore  0 then
  -- nope, let's get busy

  -- code to deal with the data

  delete variable sSemaphore
   end if
end performAction


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looking for a wait until x or timeout design pattern..

2012-01-29 Thread stephen barncard
you should check out Dar Scott's primers on Message Mechanics.

Visually and technically informative.

http://pages.swcp.com/dsc/revstacks.html

On 29 January 2012 11:38, Ken Corey k...@kencorey.com wrote:

 Here's the basic idea of the code I needed.

 the touchMove event arrives in no particular order, and in no particular
 time.

 If you absolutely have to have a timeout, you can't just test for a
 timestamp on the next run of touchMove, because there might not be another
 touchMove.

 I'm not quite clear on what the wait 50 milliseconds with messages
 command does.  Is that a more succinct way of putting it?

 -Ken


 ---8-**--
 -- Semaphore handling for touch movements
 --
 -- This code is meant to be used to group random events that
 -- happen in a timeframe, group them together, and take action
 -- on those events as a whole.
 --
 -- User input is pseudo-random, and we therefore cannot count on
 -- events coming in a particular order, or even coming at all.
 --
 -- I use code similar to this to group several distinct user inputs and
 -- deal with several at a time.  If no more events come within the
 -- delay period, we fire the handler.
 --
 -- This isn't perfect, as there doesn't seem to be a way to cancel a
 -- pending send...so we guard against the send happening in
 -- performAction.
 --
 -- What this means is that the delay (50 milliseconds below) must
 -- be chosen carefully so that there's only one group of data waiting
 -- to be processed.
 --
 -- If the touchMove event happens but is delayed, and another
 -- touchMove event with immediate execution happens within the
 -- timeout period, the second touchMove event clears the sSemaphore,
 -- so then the delayed performAction from the first touchMove event
 -- is ignored.
 --

 local sDetails,sSemaphore

 on touchMove pID,pX,pY
   -- check to see if we've dealt with pID before
   if pID is in the keys of sSemaphore then
  -- have seen it before so take action immediately
  put (pXcommapY) into sSemaphore[pID]
  send performAction pID,pX,pY
   else
  -- haven't seen it, only do it after a delay
  put (pXcommapY) into sSemaphore[pID]
  send performAction pID,pX,pY to me in 50 milliseconds
   end if
 end touchMove

 on performAction
   -- check to see if it's already been handled.
   if the number of lines in the keys of sSemaphore  0 then
  -- nope, let's get busy

  -- code to deal with the data

  delete variable sSemaphore
   end if
 end performAction



 __**_
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/**mailman/listinfo/use-livecodehttp://lists.runrev.com/mailman/listinfo/use-livecode




-- 



Stephen Barncard
San Francisco Ca. USA

more about sqb  http://www.google.com/profiles/sbarncar
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looking for a wait until x or timeout design pattern..

2012-01-29 Thread Ken Corey

Now *that* is exactly what I needed. Should be required reading.

Why didn't runrev hire this guy to write more of their manuals in this 
style?


Thanks muchly!

-Ken

On 29/01/2012 19:51, stephen barncard wrote:

you should check out Dar Scott's primers on Message Mechanics.

Visually and technically informative.

http://pages.swcp.com/dsc/revstacks.html



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Looking for a wait until x or timeout design pattern..

2012-01-28 Thread Ken Corey
I've been working on a pinch library for a week or so, and I have 
complained about the jerkiness. I am thinking that the problem is that 
it's /too/ repsonsive.


The instant one touch moves, it's causing the pinchMove event to be 
generated.  This is fine if nothing else truly has moved, but if the two 
move events are sent back to back, they should both be handled before 
sending a pinchMove message...not two different pinchMove events.


The pinchMove event should only be sent once the status of all the 
touches have been updated...but of course, we have no guarantee that 
there's a touchMove coming for each point, nor the order in which they 
will come...


So, in pseudo code, what I'd like to do is:

on touchMove i,x,y
  store x,y into positionArray[i]  -- update the postition for a touch

  wait until (got touch events from all touches) or \
(30 milliseconds have passed)

  pinchMove blah,blah,blah
end touchMove

But the wait command seems to either wait 100 milliseconds or wait until 
cond, but not both.


Then I thought to provide a timeout with a 'send timeout in xx 
milliseconds', but cancel it if we got events on all touches first. 
Couldn't see how to cancel a pending send.


I guess I could break my timeout period down and do a series of shorter 
waits (sort of slow polling), with a fall-through at the end of the timeout.


Also, all other events still need to be handled in the normal 
way...can't lock the application for those 30 seconds.


Thoughts?

-Ken

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looking for a wait until x or timeout design pattern..

2012-01-28 Thread Scott Rossi
You might try:

  wait 30 millisecs with messages

Regards,

Scott Rossi
Creative Director
Tactile Media, UX Design



Recently, Ken Corey wrote:

 I've been working on a pinch library for a week or so, and I have
 complained about the jerkiness. I am thinking that the problem is that
 it's /too/ repsonsive.
 
 The instant one touch moves, it's causing the pinchMove event to be
 generated.  This is fine if nothing else truly has moved, but if the two
 move events are sent back to back, they should both be handled before
 sending a pinchMove message...not two different pinchMove events.
 
 The pinchMove event should only be sent once the status of all the
 touches have been updated...but of course, we have no guarantee that
 there's a touchMove coming for each point, nor the order in which they
 will come...
 
 So, in pseudo code, what I'd like to do is:
 
 on touchMove i,x,y
store x,y into positionArray[i]  -- update the postition for a touch
 
wait until (got touch events from all touches) or \
 (30 milliseconds have passed)
 
pinchMove blah,blah,blah
 end touchMove
 
 But the wait command seems to either wait 100 milliseconds or wait until
 cond, but not both.
 
 Then I thought to provide a timeout with a 'send timeout in xx
 milliseconds', but cancel it if we got events on all touches first.
 Couldn't see how to cancel a pending send.
 
 I guess I could break my timeout period down and do a series of shorter
 waits (sort of slow polling), with a fall-through at the end of the timeout.
 
 Also, all other events still need to be handled in the normal
 way...can't lock the application for those 30 seconds.
 
 Thoughts?
 
 -Ken
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode