hxcpp -- Main loop only runs when tapping the screen

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

hxcpp -- Main loop only runs when tapping the screen

singmajesty
Hi,

I'm using the SDL stage, and all in all, everything is working wonderfully.

However, I've noticed something strange about the main loop. Left to its  
own, it doesn't trigger any enterFrame actions in the application unless  
you tap the screen, in which case, it renders one frame. I'm guessing that  
something about GetNextWake() isn't working correctly?

As you can see in the code below, I wrapped the sleep timer inside an  
#ifndef, so it isn't executing it anymore. With the code missing,  
animation runs as normal, but it seems "hungry" ... events like tapping  
suffer from a good deal of lag, even though everything renders. I'm  
guessing that this means it's rendering the screen as often as possible,  
rather than employing a frame limiter?

Please let me know if you have ideas to help!

Thanks!



void MainLoop()
{

        SDL_Event event;

       
        bool everyOther = false;

    while(!sgDead)
    {
           if (everyOther) {
       while (!sgDead && SDL_PollEvent(&event) )
       {
          ProcessEvent(event);
          event.type = -1;
          if (sgDead) break;
       }

       if (sgDead)
          break;

       Event poll(etPoll);
       sgSDLFrame->ProcessEvent(poll);
       
          #ifndef WEBOS
       // Sleep if required...
       double next = sgSDLFrame->GetStage()->GetNextWake() - GetTimeStamp();
       if (next > 0.001)
       {
          int snooze = next*1000.0;
          sgTimerActive = true;
          sgTimerID = SDL_AddTimer(snooze, OnTimer, 0);

          event.type = -1;
          SDL_WaitEvent(&event);

          if (sgTimerActive && sgTimerID)
          {
             SDL_RemoveTimer(sgTimerID);
             sgTimerActive = false;
             sgTimerID = 0;
          }
          ProcessEvent(event);
       }
          #endif
       
           }
       
           everyOther = !everyOther;
       
    }

    Event kill(etDestroyHandler);
    sgSDLFrame->ProcessEvent(kill);
    SDL_Quit();
}





--
Joshua Granick
Owner / Lead Developer
[ eclecticdesignstudio ]
P: (916) 889-7306

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: hxcpp -- Main loop only runs when tapping the screen

slenkar
what device are you using it on ? a PC?

GetNextWake() might be waiting for the next time the computer is awoken from sleep? (just a guess)

you could use haxe.Timer instead?
Reply | Threaded
Open this post in threaded view
|

Re: hxcpp -- Main loop only runs when tapping the screen

singmajesty
Oh, I'm using it on a Palm phone.

hxcpp includes support for Mac, Windows, Linux, iPhone and Android, so  
I've been adding Palm support.

It's been a bit unique, because unlike Mac, Windows or Linux, it's a  
mobile device (of course), but unlike the iPhone or Android, it supports  
C/C++ and dynamic libraries. I've been in the process of mixing features  
 from the desktop platforms with the mobile platforms, since it doesn't  
require a Java wrapper like Android, and it does support normal dynamic  
libraries unlike the iPhone.

This is some C code that drives the whole framework. It doesn't use  
timestamps or check the user's frame rate setting, like it should, but for  
now I've been able to improve things by changing this line:


double next = sgSDLFrame->GetStage()->GetNextWake() - GetTimeStamp();



... to this:



double next = 1 / 31;


I think the original code was comparing the target frame rate against the  
current time. In my code it will try and run 31 times a second, but if it  
is running too slow, it won't skip any frames, like it should, to keep the  
max at 31 frames per second



On Tue, 03 Aug 2010 19:01:18 -0700, slenkar <[hidden email]> wrote:

>
> what device are you using it on ? a PC?
>
> GetNextWake() might be waiting for the next time the computer is awoken  
> from
> sleep? (just a guess)
>
> you could use haxe.Timer instead?


--
Joshua Granick
Owner / Lead Developer
[ eclecticdesignstudio ]
P: (916) 889-7306

--
haXe - an open source web programming language
http://haxe.org