[Gambas-devel] Wait statement changes in recent revision

Kevin Fishburne kevinfishburne at ...590...
Thu Apr 21 06:04:50 CEST 2011


On 04/20/2011 03:51 PM, Kevin Fishburne wrote:
> On 04/18/2011 04:31 AM, Benoît Minisini wrote:
>>> Alright Benoît, what changed in the recent revision? ;)
>>>
>>> I noticed before that supposedly recursive Wait statements were
>>> not-so-recursive, and that I had to call them multiple times to allow
>>> various events to trigger. If I had two events that had queued, for
>>> example, I'd have to call Wait twice per frame for each to execute. Now
>>> calling Wait several times seems to trigger the first event over and
>>> over without triggering the second. I even had a stack overflow early
>>> on, which I hadn't seen since my earliest days of programming. I can
>>> adapt to the new way of things, but I'm not sure exactly what is
>>> happening now. All I could think of was a GOSUB without a RETURN, haha.
>>>
>>> ...
>>
>> Now WAIT should behave as specified in the documentation :
>>
>> 1) With no argument, it will process only (one?) refresh event. Input events
>> (mouse, keyboard, joystick) are queued.
>>
>> 2) With a time argument, it will process all events during the specified time.
>>
>> Normally, joystick events are queud by SDL. Why do you need to ignore them
>> from time to time?
>
> Thanks for the clarification Laurent and Benoît. What's funny is I had
> thought there was a problem with Wait from the beginning, but it had
> been "wrong" for so long I thought it was "right". I've adjusted the
> code so that it works properly now.
>
> I still need to try out the new SDL joystick support, as I'm still using
> the old /dev/input/js0 device (which also queues input). The reason I
> need to flush or ignore some gamepad input is because the controls are
> dual-analog (Playstation-style). The analog sticks create a rapid flood
> of events when they're moved, which by far exceeds the frame rate of the
> game. Since these stick movement events are queued, any movement of an
> analog stick results in those events being spread out over dozens of
> frames, taking several seconds to finish. If you move, the player just
> keeps on moving. If you rotate, the player just keeps on rotating.
>
> I'll figure it out...no worries. :)

*** NOTE ***
I've solved the problem. I'm sending this anyway in the event it may be 
helpful to others. I was experimenting with code the whole time I was 
writing it. :) The answer is that I encapsulated the entirety of the 
gamepad read event code with "Do Until Eof(pad_device)"..."Loop". Before 
I was just enclosing the "Read new gamepad data" section, but I needed 
to enclose the entire procedure that processed the gamepad data. Here's 
the original request for help:

---

I guess I thought I was smarter than I really was. Damn...

The SDL Draw event (Screen_Draw) triggers at 60 fps, but the rate at 
which the program can actually draw a frame is more around 15 fps. The 
gamepad read event (Gamepad_READ) executes once per Screen_Draw event, 
and queues gamepad events that don't get processed. The gamepad code 
looks like this (abbreviated):

' Gamepad device data.
Public pad_device As Process
Public pad_time As Integer
Public pad_data As Short
Public pad_type As Byte
Public pad_number As Byte

' Set up the gamepad.
pad_device = Exec ["cat", "/dev/input/js0"] For Read As "Gamepad"

' General declarations.
Dim s As String     ' Stores gamepad device input.

' Read new gamepad data.
Read #pad_device, s, 4
pad_time = Integer@(s)
Read #pad_device, s, 2
pad_data = Short@(s)
Read #pad_device, s, 1
pad_type = Byte@(s)
Read #pad_device, s, 1
pad_number = Byte@(s)

I've tried multiple ways of getting the Gamepad_READevent to be 
processed repeatedly without the Screen_Drawevent executing each time, 
but have failed. I can't call Wait, because it will keep calling the 
Screen_Drawevent.

The high frame rate of the gamepad events mixed in with the low frame 
rate of the rendering event cause analog stick movements to be spread 
across several seconds of rendering frames, which of course is bad. Any 
ideas of how to get the gamepad event to keep processing until empty, 
while only allowing the rendering event to execute once?

---

If anyone notices anything odd with the use of the Wait statement, let 
the mailing list know since this is a pretty significant change to 
fundamental operations and should be examined closely. Of course, read 
the documentation first and make sure it's in fact misbehaving:

http://gambasdoc.org/help/lang/wait?v3

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...590...
phone: (770) 853-6271





More information about the Devel mailing list