×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    121

    3410 losing key events

    Hi,

    Our game works wonderfully on series 30, series 40 and series 60... except for S30 mono (3410).

    The problem is that key events are being lost - i.e. the game is unresponsive.

    Now this must be related to the render loop I am using - but I have tried several approaches and nothing seems to fix the input events being lost.

    For example, I have tried:

    1) using repaint(), serviceRepaints() and then Thread.sleep( FPSmillis-previousRenderDelta), then callSerially( this)

    2) using repaint(), Thread.sleep(), then callSerially( this)

    3) using repaint(), Thread.sleep(10 or more), then callSerially( this)

    None of these improve key performance.

    Does anybody have any clues for me? I know that -very- rarely we are missing key events on S40/S60 too - as this results in a "key stick" effect in my game - this is so rare you basically never see it - but it points to a problem in our game loop.

    This really is the biggest weakness in MIDP


    I just don't get why key events aren't getting through - we are sleeping, and we are returning control to MIDP because we use callSerially.


    Thanks in advance for any words of wisdom.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    37
    Hi Marc,

    I wouldn't hold your breath for any official response...

    We have a similar problem, which I am currently trying to fix at the moment.

    For me, the problem seems to be not only are key events being lost but the repainting stops aswell.

    I have tried all the approaches you suggest, plus I also tried using Thread.yield (which made no difference) and putting the call to callSerially in a different thread, i.e.

    run() {
    repaint();
    new Timer.schedule(
    new TimerTask(
    public void run() {
    Display.getDisplay(midletInstance).callSerially
    (thisClassInstance);
    }
    ), 100 /* ms */);
    }

    which seemed to work, but caused an OutOfMemoryException after a few seconds.

    Maybe you could try this approach and see what difference it makes?

    The next things I am going to try are to use code similar to above,
    but with my own timer class that can be rescheduled to avoid all the object creation. If that doesn't work I may have to ditch callSerially altogether for the 3410, and just repaint based on timer events, which as I'm sure you know, is not ideal.

    Post back if you have any success.

    Aled

  3. #3
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    121

    Solved...

    At last I solved this problem with a mechanism I thought of over the weekend.

    Basically you need to do this:

    Start a thread (oh yes) and in the Runnable you call display.callSerially() to call your render loop code.

    Then you need to synchronize on a lock object and wait for it to notify.

    Then you do a sleep to throttle your frame rate.

    ...and loop around in the thread just doing this.

    In your render loop you do all your processing, call canvas.repaint(), and then sync on the lock object and notify on it so the looping thread carries on.

    Ta-da, key even problems solved for all Nokia phone platforms.

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    121

    Wasn't quite right

    The above solution does not allow for FPS throttling that works while allowing key events through on a 3410 phone.

    I solved this using a variant of the previous approach. Use a TimerTask set to repeat at the min millis per frame you think is acceptable, and have that do callSerially, wait on a lock object, check a boolean flag to see if your previous paint has completed properly...

    Then just go away again and wait for the next timer. Sorry our implementation is complicated by lots of other stuff so can't paste it - but if you understand synchronisation well you will get there

    Our game is now reliably throttled at 15fps on S40s, 3510i and 3410. It only runs @ 9fps on the 3410 though

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    37
    Woohoo! animation on the 3410 works!

    I tried your original solution (not using timers), and it is much better than what I was doing before.

    Keys do seem slightly unresponsive compared to Nokia 3650/Sharp GX10 but at least it doesn't hang :-)

    Aled.

Posting Permissions

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