in reply to Re^2: SDLx::App event loop
in thread SDLx::App event loop

With these things being called "callbacks" is this non-blicking by default?

Well

my $app = SDLx::App->new(); .... $app->run;
is an eventloop system. It schedules events as you request them. You can use SDLx without the eventloop, or make your own. See Re: Tk Game Sound demo-with SDL where I use the Tk eventloop with SDL.

Generally in eventloop systems, timers and IO watchers can run simultaneously in a non-blocking manner, but keyboard input may need to be in a separate thread. If you are using Moose, that may be having an unexpected effect.

It's all hard to say, when we are just speculating on unseen code, but timers can run non-blocking, it depends on what the timer is doing. Possibly you could use a key_press_down to start a timer, which every 20 forward-fire cycles, will do one backward fire. Then on the keypress_up, you cancel the timer. I probably could do it in Tk or Gtk2, but I am unfamiliar with all the SDL code. SDL timers seem to address your blocking ( timeslice ) problems.

Generally timers can be used 2 ways, one is a one-shot timer, the other will repeat itself until you tell it to stop. This is where the returning a 1 or 0 , TRUE or FALSE, comes into play.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: SDLx::App event loop
by Ransom (Beadle) on Jun 11, 2012 at 19:57 UTC
    Updated OP with code. I'm starting to think this is a timer issue coupled with my lack of understanding of event loops. Thanks you for all your help so far.
      my ... understanding of event loops

      It isn't SDL, it's Tk; but see Anatomy of an Eventloop. It may give you an idea of what is going on in SDL.

      P.S. I tried to run your code, but couldn't find what "use btype" is, or "ship.pm". Your code is indeed a batch of spaghetti. :-)


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

        It is pretty spaghetti. It's not a complete listing either :( I've got so much of a hierarchy right now and most are just empty placeholder classes. When I have massive amounts of terrible code I really don't like posting it. This was just a testbed for SDL that started to get a little bulky.

        I've started the article and so far it seems to be exactly what I'm looking for. Thank you for pointing me to good resources. I'll be working on rewriting this code a little smaller and posting a follow up on this thread with the wisdom I've gained.

        Ransom