Results 1 to 1 of 1
  1. #1
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Weird UPS/FPS Issue

    This is weird, so good luck helping me figure this out...

    So, I have a thread and the run() method is set up to update and render close to 50 times per second... But my problem was that is was running at about 32 times per second, so I went to debug and put in a System.out.println(<something>) to try to figure something out. Oddly, it then went to about 50 times per second. So, I took that line out. It was back down to 32. Put it back in, back up to 50. I did this a bunch of times, and it was always consistent. I thought maybe because I was calling System.currentTimeMillis() to be print in my debug string that it was updating or something, idk. So instead of printing it, I just called that, and it went to 32. So, I just changed the debug line to print "test" and the fps remained at 50. Removing it brought it to 32.

    So, including a print statement makes the FPS work correctly and average about 50, while excluding it makes it work incorrectly and average about 32...

    This isn't making any sense to me... >_> but here's the code...

    Java Code:
    		public void run()
    		{
    			long beforeTime, timeDiff, sleepTime;
    			
    			beforeTime = System.currentTimeMillis();
    			
    			running = true;
    			while(running)
    			{
    				update();
    				render();
    				paintScreen();
    				
    				timeDiff = System.currentTimeMillis() - beforeTime;
    				sleepTime = period - timeDiff; //note: period = 20
    
    				try
    				{
    					if(sleepTime > 0)
    						Thread.sleep(sleepTime);
    				}
    				catch(InterruptedException ex)
    				{}
    				FPS = 1000/(System.currentTimeMillis() - beforeTime);
    				System.out.println("test"); //This line makes all the difference?
    				beforeTime = System.currentTimeMillis();
    			}
    			System.exit(0);
    		}
    Last edited by AndrewM16921; 04-06-2011 at 12:19 AM.

Similar Threads

  1. Weird problem with 36 and 39?
    By jh7468 in forum New To Java
    Replies: 3
    Last Post: 02-06-2011, 09:01 PM
  2. Weird output
    By gandalf5166 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 10:17 PM
  3. weird problem
    By GPB in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 01:04 PM
  4. Seriously weird output
    By gandalf5166 in forum Java Applets
    Replies: 4
    Last Post: 02-27-2010, 05:16 AM
  5. Weird Error?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 03:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •