This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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!