Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 2000 times)
0 Members and 1 Guest are viewing this topic.
whereisthemoney
Guest
« Posted 2003-09-06 15: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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
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();      
      frames++;
      if (startTime - fpsTime > 999)
      {
            System.out.println("FPS: " + frames);
        frames = 0;
        fpsTime = startTime;
      }
        try
        {
          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?

Thanks.
Offline jbanes

JGO Coder


Projects: 1


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


« Reply #1 - Posted 2003-09-06 15: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
whereisthemoney
Guest
« Reply #2 - Posted 2003-09-06 16:04:48 »

Thanks. I wish I knew what you meant by
Quote
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: 1


pixels! :x


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

Quote
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-08 01:18:47 »

Quote
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.

Regards,
Fooberry
Offline kevglass

JGO Kernel


Medals: 121
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-10-08 07: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.

Kev

Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #6 - Posted 2003-10-08 11: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 Member




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


« Reply #7 - Posted 2003-10-09 15: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

http://www.gregorypierce.com

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (15 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!