• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Getting games to run at a consistent frame (cycle) rate?  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently, to have my game run at a consistent frame (or should I say cycle) rate, I:
1) Determine the Cycles Per Second I need, for this example 40
2) After each cycle is complete, I have the game Sleep for the remainder of time allocated to that cycle.

Problem is, this process seems to create a big performance hit on my game. Even if I jack up the Cycles Per Second, the game still runs slow. However, if I removed this code, the game flys way too fast (in the hundreds of Cycles Per Second). Is there a better way to accomplish this?
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As far as increasing the FPS is concerned...I saw a game, which really did not respond well with very high FPS, as developer had used the FPS in an equation of his game, which was giving this negative effect...
if you could post the portion of the code that deals with your thread's sleeping for the remaining time, the problem may get sorted out...

Ramy...
[ January 12, 2006: Message edited by: Ramender Mall ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the exact same problem as Hank.. Here is the slow code:

long timeSinceStart = (cycleStartTime - System.currentTimeMillis());
if (timeSinceStart < MS_PER_FRAME){
try {
Thread.sleep(MS_PER_FRAME - timeSinceStart);
} catch(java.lang.InterruptedException e){}
}
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered the use of TimerTask and Timer from the MIDP API?
I believe that Timer.scheduleAtFixedRate() can produce the intended behaviour: the TimerTask procedure will run with a fixed time rate.
See the MIDP documentation for more details.


[ January 15, 2006: Message edited by: Eduardo Marques ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!