Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
touch/mouse events buffering during lengthy handler processing — Gideros Forum

touch/mouse events buffering during lengthy handler processing

HakanGuleryuzHakanGuleryuz Member
edited March 2013 in Bugs and issues


I have a mouse/touch handler that performs several image/sound load/unload operations. This is like a "Next" button which moves from one scene to the other.
On some scenes this can take 3-4 seconds.
I noticed mouse/touch events are buffered during this time, and delivered to their respective handlers the moment the long lua operation finishes.
I want to control this event buffering, and remove old events from the previous screen, because visually the user clicks on the previously shown objects on screen but the events take place after they are thrown and new ones are shown on the screen.

I tried various other techniques with Timer object, but could not reach a satisfactory result.

I could load all objects for all scenes at the very start of the app, but that might bring out memory issues, since there are many scenes.

I could write a scene loader that releases the lua thread by using a Timer and uses a list of resource objects to load at every timer event and maybe also display a "loading next scene please wait" indicator, and during this time the mouse/touch events would be delivered but not used. But this would be a big task at the moment.

In short:
What are my options to control the buffered touch / mouse events after a lengthy lua event handler code finishes its job ?

Does mouse / touch events have an origination time comparable / compatible with os.timer() ?
This could be used to detect stale / old touch/mouse down events?

Thanks for developing such a highly productive environment.
I hope the opengl(es?) support arrives soon.

Comments

  • keszeghkeszegh Member
    edited March 2013
    just an idea,
    if you add to the scene a dummy empty sprite just before starting the process of switching to new scene (onExitBegin if you use scenemanager) and also you add eventhandlers to this sprite for all touch events, which do nothing except calling stopPropagation, and then when the switching ended (onExitend) you could remove this sprite and so every touch events incoming during the scene-change would be absorbed by this sprite.
  • Thanks for the idea. I was not aware of scenemanager helper project, and it seems I had coded something similar for my needs. I can use the scenemanager with next project...

    I modded my own version of page manager with a topologically similar change to your suggestion, but instead of adding empty sprite.. I coded a disable/enable all buttons option after which I ran fast a few rounds of empty/unprocessesed rounds of Event.TIMER events and after which I reenabled the all buttons at Event.TIMER_COMPLETE event. It seems the together with unhandled Event.TIMER events the disabled buttons ate up all the "old" touch events.

    It would be simpler if there was something native to Gideros API such as a class level call to EventDispatcher.purgeEvents()
    which removes all buffered events
    and so I could call it at the end of lengthy lua operations.

  • I think that removing all touch event handlers of a scene that is about to disappear is always a good idea, say necessary. if you only add touch event handlers to the new scene after it appeared completely/after the computations, i think that the trickering with the timer events might not be necessary, i never used them in any case. you can try to turn off the timer stuff and see if that changes anything.
    also, although the above should be enough, if it is not, maybe the dummy sprite method is better than the timer method, as it aims directly to eat up the touch events, while your solution is not doing that, just waiting enough so that they disappear, but you never know how much you need to wait.
    in any case i'm glad if you could make it to work as you wanted in some way or another.
  • i had an idea about adding an enterframe listener after loading and only inside the on enterframe function should you invoke to start transition, that way there is no transition until everything is loaded, so there is no overload of anyhting. that would perhaps solve your issue as well. of course you have to remove all touch events before loading next frame and enabling touch events for the next frame only after finishing the transition.

    you can consider to change to scenemanager, it is never too late, at some point i also had to rewrite some of my code to be able to use scenemanager, but it may be worth to do once.
    see my last comment here about how to change scenemanager according to my idea:
    http://www.giderosmobile.com/forum/discussion/comment/21841#Comment_21841
  • Thanks, your comments will be useful when I use scenemanager in my next project.

    At the moment, without using scenemanager, the long scene loading code disables all buttons, and prepares a timer to re-enabled them. The timer iterations is just 2, and interval is 10ms. The last iteration sends Event.TIMER_COMPLETE at which the buttons are re-enabled. The code change is minimal and all stale events generated in the long code execution get thrown away.
Sign In or Register to comment.