[Gambas-user] gb3: how to check if event is pending execution before it triggers
nando
nando_f at ...951...
Sat Mar 17 09:56:40 CET 2012
How about this...
Let's say you want the Frame to render not less than 0.5 seconds after reading
UDP stuff...but only if there is no UDP stuff to read.
So, make a Timer that is solely for Frame render/updating.
When UDP_Read triggers, store your data to render/update, but don't render it yet.
Also, do TIMER.Enable = FALSE and TIMER.Enable = TRUE immediately
Thus, the timer will be reset for another 0.5 seconds.
If nothing is read, the frame updates in the timer.
(Inside the timer, do TIMER.Enable=FALSE so it doesn't re-trigger)
As data arrives UDP, it will reset the timer, but not update as long
as data arrives under 0.5 second pieces.
Change the 0.5 to what works nicely in real life.
This should work nicely.
-Fernando
---------- Original Message -----------
From: Benoît Minisini <gambas at ...1...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Sat, 17 Mar 2012 09:37:43 +0100
Subject: Re: [Gambas-user] gb3: how to check if event is pending execution before it triggers
> Le 17/03/2012 08:46, Kevin Fishburne a écrit :
> > On 03/17/2012 03:05 AM, Bruce Bruen wrote:
> >> On Sat, 2012-03-17 at 02:04 -0400, Kevin Fishburne wrote:
> >>> Is there a way to check if an event is going to trigger in advance?
> >> Not in the known universe. It would be nice though, Lotto numbers,
> >> stock price changes etc etc :-)
> >>
> >>> My startup procedure (GUI.Main) allows two event procedures to trigger,
> >>> Render.Screen_Draw (SDL) and Network.UDP_Read (UDP socket). When
> >>> Screen_Draw triggers I need to know if there are pending UDP packets so
> >>> I can avoid rendering the frame until those pending network events are
> >>> processed. The logic would look something like this:
> >>>
> >>> Public Sub Screen_Draw()
> >>> If [there is data in the socket] Then Return
> >>> [render a complete frame]
> >>> End
> >>>
> >>> Basically I need to give processing incoming UDP packets priority over
> >>> rendering frames since processing the packets is quick but rendering a
> >>> frame is slow. I only want it to render a frame when there are no
> >>> incoming UDP packets needing attention. I've been thinking about logical
> >>> ways to do this, but if there is some inherent GAMBAS way that would be
> >>> more elegant.
> >>>
> >> Could you use some global counter to achieve this?
> >> For every UDP packet received, inc the counter and dec it on UDP_Read
> >> (or zero it?)
> >> Then Screen_Draw need only check that the counter is zero.
> >>
> >> I don't really know whether this will work for you but from your
> >> description it does sound like a classic semaphore problem. ???
> >
> > You're a funny guy. :) I need to control the order and priority of
> > rendering a frame and reading a UDP packet, and it appears that using
> > events takes this control completely out of my hands. I can easily have
> > the rendering event not actually do any rendering, but is there a way to
> > have a UDP read event similarly delay reading the UDP data for a later
> > time? Basically, when Network.UDP_Read triggers, can I just exit and let
> > it trigger again later when I'm ready to actually process it?
> >
>
> What happens if you use Lof() on the UDP socket to see if there is
> something to read?
>
> --
> Benoît Minisini
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------
More information about the User
mailing list