fluidity & FPS

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

fluidity & FPS

Postby MickArea » Fri Feb 27, 2009 11:41 am

Hi,

I discovered that in my application i lost FPS due to :

02-27 11:31:05.403: DEBUG/dalvikvm(90): GC freed 1110 objects / 57568 bytes in 216ms
02-27 11:31:34.193: DEBUG/dalvikvm(1423): GC freed 11086 objects / 388256 bytes in 116ms
02-27 11:32:24.702: DEBUG/dalvikvm(1423): GC freed 16590 objects / 556688 bytes in 117ms
02-27 11:33:09.542: DEBUG/dalvikvm(1423): GC freed 16144 objects / 536248 bytes in 114ms
02-27 11:33:46.322: DEBUG/GpsLocationProvider(49): NetworkThread out of wake loop
02-27 11:33:46.322: DEBUG/GpsLocationProvider(49): Requesting time from NTP server pool.ntp.org
02-27 11:33:54.562: DEBUG/dalvikvm(1423): GC freed 15763 objects / 524240 bytes in 121ms
02-27 11:33:56.632: DEBUG/SntpClient(49): request time failed: java.net.SocketTimeoutException: The operation timed out
02-27 11:33:56.632: DEBUG/GpsLocationProvider(49): requestTime failed
02-27 11:33:56.632: DEBUG/GpsLocationProvider(49): NetworkThread wait for 300000ms


i don't know why i have so much of GC freed ..
In first i thought that it is due to so much reallocation memory, but after improving the code. I have still the problem !

i make this code but it is worst :

Code: Select all
///// drawing //////////////////
// the code to regulate the fps :
      countFrame++;
      period=System.currentTimeMillis()-start;
      start=System.currentTimeMillis();
      if( (50-period)>0 )delay=(50-period+delay)/2;
      else delay=5;
      
      if(System.currentTimeMillis()-startFrame >= 1000 ) {
         FPS=countFrame;
         
         countFrame=0;
         startFrame=System.currentTimeMillis();
         
      }

//////////////////////////
   class RefreshRunner implements Runnable {

      // @Override
      public void run() {
         while (!Thread.currentThread().isInterrupted()) {
            demoView.postInvalidate();
            try {
               Thread.sleep(demoView.delay); // a 10th of a second
               
            } catch (InterruptedException e) {
               Thread.currentThread().interrupt();
            }
         }
      }
   }


I need help, it is an application which need a lot of calculation and drawing.
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Top

Postby MrSnowflake » Mon Mar 02, 2009 9:25 am

When using a surface, and locking that surface, you get a steady fps, so, your own fps regulation is only necessairy when you want less than 50 fps.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby ClockworkAlchemist » Thu Mar 05, 2009 7:12 pm

Also, keep in mind that calling sleep() doesn't mean that your thread will sleep() for EXACTLY that amount of time, it means it will sleep for AT LEAST that amount of time. Often it is more.

What are you trying to do? I've written a few small timer / FPS related things while trying to learn how drawing works on android, I might be able to post something that is pertinent to your issue.
ClockworkAlchemist
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sun Feb 08, 2009 3:41 am
Location: Orange County, CA

Postby MickArea » Thu Mar 05, 2009 7:33 pm

Hi,

thanks, I need a way to regulate the fps, because some time android do something in the background and i lost a lot of FPS, like a freeze ...

example :
dalvikvm(90): GC freed 1110 objects / 57568 bytes in 216ms
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Postby MrSnowflake » Thu Mar 05, 2009 7:40 pm

Sleeping your thread will only make it worse if anything!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby MickArea » Thu Mar 05, 2009 7:45 pm

i know,

but the goal of this code is to regulate the fps, like this :

time between two frames is too smal, add a delay to get what i want.
time between two frames is too big , reduce the delay to get what i want :p


if i want a 26 fps, it could be possible !
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Top

Postby MrSnowflake » Thu Mar 05, 2009 8:14 pm

MickArea wrote:if i want a 26 fps, it could be possible !
Then you should take 25fps, as that is coïncides with the 50Hz of the G1's screen.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby ClockworkAlchemist » Fri Mar 06, 2009 1:23 am

Also, you want to make sure that your application can properly handle variable length updates. I just sketched this out in notepad. It's probably not 100% correct, but you can see what is going on. Note your first update will probably be zero, and this would need some work to handle cases where less than a millisecond had passed. On a related note, does anybody know if the G1 properly supports a higher resolution timer?


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.    class RefreshRunner implements Runnable
  5.  
  6.    {
  7.  
  8.      private long last_time_ms = 0;
  9.  
  10.      private long elapsed_time_ms = 0;
  11.  
  12.      private float elapsed_time = 0.0f;
  13.  
  14.      private boolean thread_done = false;
  15.  
  16.  
  17.  
  18.      private void update_timer()
  19.  
  20.      {
  21.  
  22.         long current_time_ms = System.currentTimeMillis();
  23.  
  24.         elapsed_time_ms = current_time_ms - last_time_ms;
  25.  
  26.         elapsed_time = ((float)(elapsed_time_ms))/1000.0f;
  27.  
  28.         last_time_ms = current_time_ms;
  29.  
  30.      }
  31.  
  32.  
  33.  
  34.      private void run_simulation(float32 elapsed)
  35.  
  36.      {
  37.  
  38.         // do stuff here
  39.  
  40.      }
  41.  
  42.  
  43.  
  44.       // @Override
  45.  
  46.       public void run()
  47.  
  48.       {
  49.  
  50.         last_time_ms = System.currentTimeMillis();
  51.  
  52.          
  53.  
  54.          while (!thread_done)
  55.  
  56.          {
  57.  
  58.             update_timer();
  59.  
  60.             run_simulation(elapsed);
  61.  
  62.          }
  63.  
  64.       }
  65.  
  66.    }
  67.  
  68.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
ClockworkAlchemist
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sun Feb 08, 2009 3:41 am
Location: Orange County, CA

Postby MrSnowflake » Fri Mar 06, 2009 11:04 am

Yup, that's the most important feature any game should have. Because the G1 has an update frequency of 50Hz but any future device may have a higher (60Hz) or lower frequency, so your game would play faster/slower on such devices.

This won't fix your drop in fps at some points, but at least your gameplay won't feel choppy.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby MickArea » Sat Mar 07, 2009 1:09 pm

ok, i understand.

but in my game i've to move pixel by pixel, i can't make something like that ( lunar example ) :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mHeading += mRotating * (PHYS_SLEW_SEC * elapsed);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


or maybe calling twice or more my engine function :s
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Postby MickArea » Mon Mar 09, 2009 10:47 am

a good news for me, using surfaceview solve the problem with the " GC freed x objects/ y bytes in z ms "
:D
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Postby MrSnowflake » Mon Mar 09, 2009 12:14 pm

Than what were you doing originally?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby MickArea » Mon Mar 09, 2009 12:53 pm

originally i used your template :p
the problem for me is due to ondraw() a bad way to draw something :p

now i'm using surfaceview and SurfaceHolder :p
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Postby MrSnowflake » Mon Mar 09, 2009 1:11 pm

So my template doesn't use a surfaceView? strang hehe :). Needs some updating apparently :D.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby MickArea » Fri Mar 13, 2009 9:33 pm

i don't understand ... :D sorry ... my english is poor .... xD

( well, because it's you, i will make a update )
MickArea
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Feb 23, 2009 4:42 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests