×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182

    Optimising MIDlets

    Hi have been working on my Game for over 2 months and bought a phone to test it on.
    First phone I got was the Siemens S55 will test on the NOKIA next.

    Siemens are supposed to be slower than nokia if you don’t use either manufactuers specific API’s.

    The game is running too slow to be enjoyable.

    I ‘ve been looking around trying to see if there is ways to speed up the game.
    I tried to get rid of the serviceRepaints(), but then then repaints could not keep up with the game, so that did not work, the ball on the screen looked like it was jumping about, as every time it updated the screen the code that controls the ball must have flew threw a few iterations during each paint so it appeared the ball jumped about the screen.

    Here is my paint method which I think could be the source of the problems.


    protected void paint( Graphics g ){ballSize= 20 + (posZ * -1/9 );
    adjustBall = ballSize/2;
    ScreenX = 45 * posX / posZ + 48 - adjustBall;
    ScreenY = 45 * posY / posZ + 39 - adjustBall;
    int targetScreenPosX = 45 * targetX / 90 + 48;
    int targetScreenPosY = 45 * targetY / 90 + 39;
    g.drawImage(background,48,39,Graphics.HCENTER |Graphics.VCENTER);
    g.drawImage(paddel2,Ax,Ay,Graphics.HCENTER | Graphics.VCENTER);
    g.setColor(0, 0, 255); //blue

    if ( hitCount > 5)
    {
    if ( posZ < 90 )
    {
    g.drawImage(target,targetScreenPosX,targetScreenPosY, Graphics.HCENTER | Graphics.VCENTER);
    g.fillArc(ScreenX, ScreenY, ballSize, ballSize, 0, 360);
    }
    else
    {
    g.fillArc(ScreenX, ScreenY, ballSize, ballSize, 0, 360);
    g.drawImage(target,targetScreenPosX,targetScreenPosY, Graphics.HCENTER | Graphics.VCENTER);
    }
    }
    else
    {
    protected void paint( Graphics g ){ballSize= 20 + (posZ * -1/9 );
    adjustBall = ballSize/2;
    ScreenX = 45 * posX / posZ + 48 - adjustBall;
    ScreenY = 45 * posY / posZ + 39 - adjustBall;
    int targetScreenPosX = 45 * targetX / 90 + 48;
    int targetScreenPosY = 45 * targetY / 90 + 39;
    g.drawImage(background,48,39,Graphics.HCENTER |Graphics.VCENTER);
    g.drawImage(paddel2,Ax,Ay,Graphics.HCENTER | Graphics.VCENTER);
    g.setColor(0, 0, 255); //blue
    if ( hitCount > 5)
    {
    if ( posZ < 90 )
    {
    g.drawImage(target,targetScreenPosX,targetScreenPosY, Graphics.HCENTER | Graphics.VCENTER);
    g.fillArc(ScreenX, ScreenY, ballSize, ballSize, 0, 360);
    }
    else
    {
    g.fillArc(ScreenX, ScreenY, ballSize, ballSize, 0, 360);
    g.drawImage(target,targetScreenPosX,targetScreenPosY, Graphics.HCENTER | Graphics.VCENTER);
    }
    }
    else
    {
    g.fillArc(ScreenX, ScreenY, ballSize, ballSize, 0, 360);
    }
    if (bonusDropped == true)
    {
    int bonusScreenPosX = 45 * bonusX / bonusZ + 48;
    int bonusScreenPosY = 45 * bonusY / bonusZ + 39;
    g.setClip(bonusScreenPosX-2,bonusScreenPosY-2,8,8) ;
    g.drawImage(bonus,bonusScreenPosX*frame,bonusScreenPosY, g.LEFT | g.TOP ) ; //-(6*frame)+3 +3
    g.setClip(0,0,101,80);
    }
    g.drawImage(paddel, paddelX, paddelY, Graphics.HCENTER | Graphics.VCENTER);
    }



    Am I doing something here which is really inefficient and slowing down the whole show??

    Are there any other pointers or suggestions which I could try?

    Thanks
    Brian
    Last edited by Woody_FX; 2003-09-28 at 10:47.

  2. #2
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182
    I have removed all declarations and equation solving from inside the paint() but it seems to have not made things any faster!

    There is a definit bottle neck with the paint() method.

    Will remove fillArc to see if this is very inefficent.

    Thanks Brian

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    39
    Hi,
    Have you tried to use an offscreen Image updated in a different thread, and in a paint method only draw the offscreen Image on the screen.
    I did the same once and it was quite quick on Siemens too.
    Rgds
    Sandor

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182
    Yes that is something i should add!

    You do mean a second image off screen that i can fire across.

    I've read a few times that the siemens double buffer is slow!

    Will try and see if it helps.

    Any other suggestions?

    Brian

  5. #5
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182
    I have implemented double buffering but the speed difference does not seem to have changed.
    Maybe i have misunderstood.

    here is what i have tried.

    private Image bufferImage;
    Graphics buffer;
    public GameCode(Game mGame)
    {
    this.mGame = mGame;
    try
    {
    bufferImage = Image.createImage(getWidth(), getHeight());
    buffer = bufferImage.getGraphics();
    background = Image.createImage("/newback1.png");
    }
    catch (IOException e)
    {
    System.err.println("Failed loading Image!");
    }
    }
    protected void paint( Graphics g )
    {
    Graphics original = g;
    g = buffer;
    g.drawImage(background, 48, 39, g.HCENTER | g.VCENTER);
    g.drawImage(paddel2, Ax, Ay, g.HCENTER | g.VCENTER);
    g.setColor(0, 0, 255); //blue
    if ( hitCount > 5)
    {
    if ( posZ < 90 )
    {
    g.drawImage(target,targetScreenPosX,targetScreenPosY, g.HCENTER | g.VCENTER);
    g.setClip(ScreenX-8,ScreenY-8,16,16) ;
    g.drawImage(ball,ScreenX+8-(15*frameNo),ScreenY-8, g.TOP | g.LEFT); //-(6*frame)+3 +3
    g.setClip(0,0,101,80);
    }
    else
    {
    g.setClip(ScreenX-8,ScreenY-8,16,16) ;
    g.drawImage(ball,ScreenX+8-(15*frameNo),ScreenY-8, g.TOP | g.LEFT); //-(6*frame)+3 +3
    g.setClip(0,0,101,80);
    g.drawImage(target,targetScreenPosX,targetScreenPosY, g.HCENTER | g.VCENTER);
    }
    }
    else
    {
    g.setClip(ScreenX-8,ScreenY-8,16,16) ;
    g.drawImage(ball,ScreenX+8-(15*frameNo),ScreenY-8, g.TOP | g.LEFT); //-(6*frame)+3 +3
    g.setClip(0,0,101,80);
    }
    if (bonusDropped == true)
    {
    int bonusScreenPosX = 45 * bonusX / bonusZ + 48;
    int bonusScreenPosY = 45 * bonusY / bonusZ + 39;
    g.setClip(bonusScreenPosX,bonusScreenPosY,12,12) ;
    g.drawImage(bonus, bonusScreenPosX-frame ,bonusScreenPosY, g.HCENTER | g.VCENTER ) ; //-(6*frame)+3 +3
    g.setClip(0,0,101,80);
    }
    g.drawImage(paddel, paddelX, paddelY, g.HCENTER | g.VCENTER);
    original.drawImage(bufferImage, 0,0, g.TOP | g.LEFT);
    }
    }

    Have i done this wrong seemed a little to simple?Brian
    Last edited by Woody_FX; 2003-10-01 at 01:40.

  6. #6
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    134
    Do you use any sleep()?

    If you want to find out where the bottleneck lies you should profile the code.

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    39

    Offscreen

    Hi,
    I was talking about a different solution.
    Why you not create a thread to run your app. and to update the offscreen image if it is needed, and when you finished or you need to update the screen call the repaint() method.
    In the paint (different thread) you only need to draw the ready made image on the screen. If you will need to wait for the display update, you can call the servicerepaint
    With this you will see quite a big speed improvement :-)
    Rgds
    Sandor

    public void run()
    {

    /**
    * Do nothing if the offscreen not created yet
    */
    while( offscreen == null )
    Thread.yield();
    Graphics g = offscreen.getGraphics();

    g.setClip( 0, 0, getWidth(), getHeight() );
    while( !stopped )
    {

    /**
    * @todo: Draw what you need
    */
    repaint();
    serviceRepaints();
    /**
    * Give chance to the others to run :-)
    */
    Thread.yield();
    }
    }



    /**
    * The Component paint methode
    * Use offscreen graphics
    */
    public void paint( Graphics g )
    {
    g.drawImage( offscreen, 0, 0, Graphics.TOP | Graphics.LEFT );
    }

Posting Permissions

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