Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 30
Registered: ‎08-06-2012
My Device: PlayBook
My Carrier: Cosmote
Accepted Solution

BB10 simulator: Question regarding clock function

I'm not sure but I have the notion that under the simulator for BB10 the clock() function returns a value in host's resolution timer and not the correct one


And since 


#define CLOCKS_PER_SEC  1000000


when converting the clock to seconds it will have wrong results at least under windows. Because under Windows it's


#define CLOCKS_PER_SEC  1000


I want to keep constant 60 FPS and I have a code like:


const int FRAMES_PER_SECOND = 60;
const int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;


int GetTickCount(void)
       return MathUtils::dti( (double)clock() / CLOCKS_PER_SEC );


and game's loop is:


int t_prev = GetTickCount();

mbGameRunning = true;
while ( mbGameRunning )
     int t = GetTickCount();

     if ( (t - t_prev) > SKIP_TICKS )





     t_prev = t;


Am I missing something?

Trusted Contributor
Posts: 232
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: BB10 simulator: Question regarding clock function

The clock() function only increments while your program is being handled by the OS. When the OS switches to another task, your program's 'clock' stops running.


You have to use:


clock_gettime(), which is the system clock that always runs.

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 simulator: Question regarding clock function

also, please don't code your loop this way if you can avoid it.

it will spend most of its time running-ready most likely, unless your event-handling function happens to block for a suitable amount of time.  this will chew through battery unnecessarily, as it's more or less the same as writing a while(1) {} loop.

a better solution would be to use a periodic timer set to expire at a rate of 60Hz and block periodically waiting for that event.

the bps event handler allows you to specify a timeout, so that's the perfect place to block waiting for input, etc. but also be guaranteed to wake up at least once every 1/60th of a second.




New Developer
Posts: 30
Registered: ‎08-06-2012
My Device: PlayBook
My Carrier: Cosmote

Re: BB10 simulator: Question regarding clock function

As I'm creating a game I want to be able to control the FPS and not rely on the system when it will call me. From my experience from other platforms this kind of loop is the best way and you could also take into account the time difference between rendering frames to make motion smoother.


I've decided to use the clock_gettime