×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    3

    Running application at constant speed on different phones

    I'm developing application(game) using MIDP2.0 and I'm not able to have it running at constant/desired speed. Here's how I'm doing it: (run function is inherited from Runnable object and it is running in separate thread)
    Code:
    static int MS_PER_FRAME = 40;
    public void run() { 
        while(true) {         
          long startTime = System.currentTimeMillis();
            
          tick();
          draw(g);    
          
          // Sleeps      
          long waitTime = MS_PER_FRAME - (startTime - System.currentTimeMillis());
          if (waitTime > 0) {
            try {
              synchronized(this) {
                wait(waitTime);
              }
            } catch (InterruptedException e) {}
          } else 
            thread.yield();       
            
        }
      }
    Using this code, all mobiles with enough memory and strong cpu should give me same frame rate 25 FPS (1000 / MS_PER_FRAME). But they don't. On Nokia 6300 I get only 15 FPS, on another phone I have 20FPS... The thing is that when I comment part which sleeps, FPS on both devices jumps to 100 FPS. Is this behaviour normal or is my sleeping mechanism wrong?

    Any help would be appreciated, Thanks.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Running application at constant speed on different phones

    Hi,

    Check their clock speeds. Does it make sense?

    Br,
    Juarez Alvares Barbosa Junior - Brazil

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    3

    Re: Running application at constant speed on different phones

    Thank you very much for reply, but I'll need a little explanation... I thought that wait will wait for certain amounts of miliseconds. How is this affected by the clock speed? Anyway, I don't know how to get clock speed of my devices.. Is there a function in Java API? That would make solving easier.

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Running application at constant speed on different phones

    The problem here is that the thread does not start executing immediately after the sleep is over (they are placed in a pool and the scheduler picks them from there for execution). So the results are unpredictable and different from one implementation to another...

    There are not any methods to find the phone's clock speed. You could check for the phone model and find a good wait period for each of the phones experimentally, however even that does not guarantee a constant execution speed (some backgound applications could hog processing time and hence the execution of your MIDlet would slow down)

    Hartti

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    10

    Re: Running application at constant speed on different phones

    Hi,
    I think the
    Code:
    long waitTime = MS_PER_FRAME - (startTime - System.currentTimeMillis());
    line is the problem, it should be
    Code:
    long waitTime = MS_PER_FRAME - (System.currentTimeMillis() - startTime);
    because current time - start time is the elapsed time in the cycle

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    3

    Re: Running application at constant speed on different phones

    Ouw... Thanks pz126 I'm blind... At least I learned something about threads a clocks ... Thanks

Similar Threads

  1. Problem in running application in S60 emulator
    By abhisarswami in forum Mobile Java General
    Replies: 0
    Last Post: 2006-10-26, 07:46
  2. Application not running in standalone
    By aSaSSin0000 in forum Symbian
    Replies: 2
    Last Post: 2006-09-01, 22:43
  3. knowing-if an application is running in background
    By sunny_singh in forum Symbian
    Replies: 3
    Last Post: 2005-11-21, 12:01
  4. Replies: 4
    Last Post: 2005-09-01, 13:47
  5. Problem In running The Application in the device
    By mihirrath in forum Symbian
    Replies: 2
    Last Post: 2003-06-13, 08:00

Posting Permissions

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