Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (613)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A weird fps tale  (Read 2353 times)
0 Members and 1 Guest are viewing this topic.
« Posted 2003-09-06 13:29:48 »

Ok here's the thing. I was testing my game at 50 frames per second. As you know the delay for 50 fps is 20 ms. I tried it out and all I could get was 32 fps.

I thought it was my game, so I stripped it out of "suspicious" methods and classes, but nothing. I ended up making a little program to test this fps situation.

The result was to say the least crazy. 20ms delay produces in reality a 31 or 32 ms delay. 19ms or 21ms (or anything else) delays are almost okay. Check out the code:

public class EmptyGame
   public static void main( String[] args )
     EmptyGame test = new EmptyGame();

  // A delay of 20L should give us 50 fps (1000 / 20)
  private static final long DELAY = 20L; // try either 19L or 21L to see the difference

  public EmptyGame()
    long startTime;
    int frames = 0;
    long fpsTime = System.currentTimeMillis();

    while( true )
      startTime = System.currentTimeMillis();      
      if (startTime - fpsTime > 999)
            System.out.println("FPS: " + frames);
        frames = 0;
        fpsTime = startTime;
          Thread.sleep( DELAY );
      } catch(Exception e) {}

      // Un-comment the following line to see the actual delay
      //System.out.print(System.currentTimeMillis()- startTime+"  ");

Please try it out and see for yourself. Is there something that I'm not aware of? Another Java bug perhaps?

Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #1 - Posted 2003-09-06 13:50:17 »

Welcome to the wild and wooly world of system timing. You have two options here:

1. Loop around a "sleep(5)" method until the time expires.
2. Download GAGETimer and turn off the CPU monitor. (It's just a psychological thing anyway...)

Java Game Console Project
Last Journal Entry: 12/17/04
« Reply #2 - Posted 2003-09-06 14:04:48 »

Thanks. I wish I knew what you meant by
Loop around a "sleep(5)" method until the time expires.

Is it about the 5ms threshold (or something) of the java timer?

Update: No need to reply. Got it now, thanks.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #3 - Posted 2003-09-06 14:18:25 »

Thanks. I wish I knew what you meant by
Is it about the 5ms threshold (or something) of the java timer?

The resolution of System.currentTimeMillis() under win9X is 50-55msec... however the accuracy of sleep is actually 5msecs.

弾幕 ☆ @mahonnaiseblog
Offline fooberry

Junior Newbie

Still working on something clever.

« Reply #4 - Posted 2003-10-07 23:18:47 »

2. Download GAGETimer and turn off the CPU monitor.
I've come upon the same realization recently.
Could you please explain the bit about turning off the CPU monitor?  How much would it really help and what's the worst that could happen by doing so?  Thanks.

Offline kevglass

« JGO Spiffy Duke »

Medals: 272
Projects: 25
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #5 - Posted 2003-10-08 05:12:17 »

I think JBanes was getting at that if you have the CPU Monitor (the system tool that comes as part of windows) turned on you'll notice that with the GAGETimer in your loop you'll see 100% CPU usage most of the time.

However, this is misleading in that the 100% doesn't mean that nothing else can run, since should anything else attempt to run your game (based on the gage timer) will yield its processor time. Lots of people see the 100% usage and fear the worse but its simply a non issue.


Offline MGodehardt

Junior Devvie

why does the chicken cross the road?

« Reply #6 - Posted 2003-10-08 09:05:17 »

Correct go buy UO and start it and look at your performance monitor and look its 100% and this game is from EA, one of the leading software companies, they know what they do trust me

People telling me 100% is bad are no serious programmers for me.

WOW nice got an extra DUKE
Offline gregorypierce

Senior Devvie

I come upon thee like the blue screen of death....

« Reply #7 - Posted 2003-10-09 13:58:43 »

Well when a game is running it would ideally be using as much of the native platform as it could to achieve effect. No point running at 30% CPU and having hitches and pauses Smiley

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (12 views)
2015-09-03 00:41:28

Andrew_3ds (24 views)
2015-09-01 19:08:10

afikri (16 views)
2015-08-31 09:30:22

afikri (24 views)
2015-08-31 09:30:07

afikri (12 views)
2015-08-31 09:27:24

afikri (16 views)
2015-08-31 09:26:40

Roquen (23 views)
2015-08-29 11:30:54

GamerC4 (34 views)
2015-08-22 20:38:50

GamerC4 (31 views)
2015-08-22 20:37:18

GamerC4 (37 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!