none
Phantom pauses in LDPhysics RRS feed

  • Question

  • Hey guys. 

    I have been having a bug in my program that has been very hard to track down. I think that it is coming from the DoTimeStep function in the LDPhysics engine (It was happening before and after the extension was sped up). It is very hard to trace, however, because it seems to be happening in the background, Or not corresponding to a specific function. It is a 100-250 ms delay that happens sporadically as I play the game (about once every 5 seconds). Here is the code segment I am using to display it:

    LDPhysics.DoTimestep() starttime = Clock.ElapsedMilliseconds Shapes.SetText(FPSText,"FPS: " + 1000/TimeElapsed) '<-- The delay happens here

    If Clock.ElapsedMilliseconds - starttime > 100 Then TextWindow.WriteLine(Clock.ElapsedMilliseconds - starttime) EndIf


    It seems at first glance that it is the SetText function that is creating the delay, but the delay happens weather or not the function is there or not. It just won't display it unless I have it there.

    If I move the DoTimestep() function to a different location, then it won't display it here either. This is why I think the function is causing it.

    Another thing I have noticed is this: If I play the game in the background (Another window in focus) then the problem with go away.

    I know this is very confusing, but it is all the information I could get. If any of you come up with anything I could try, I'd love to give it a shot.

    Thanks!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, December 8, 2016 3:00 AM
    Answerer

Answers

  • Figured it out!! It was the animation images! 

    What is did was increased the number of projectiles in the game for one tank to 200 instead of 20. This made the game almost unplayable because of the lag. I then replaced all the projectiles in the game with rectangles, and did the same with the explosions. Its completely smooth now!

    I did realize that with 200 projectiles in the game, at 2X1 animations, and 200 explosions, at 4x2, that makes a total of 2,000 sprite images! (Wow) 

    So now I just need to decrease the number of sprites as much as possible.

    I'm also wondering, is there a way the animation images could be a little faster?

    Thanks!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Proposed as answer by litdevModerator Sunday, December 11, 2016 6:04 PM
    • Marked as answer by Zock77Editor Sunday, December 11, 2016 10:30 PM
    Sunday, December 11, 2016 12:55 AM
    Answerer
  • I'm also wondering, is there a way the animation images could be a little faster?

    I have updated the test beta version of extension to speed the animated gifs as much as I can using the ideas I used for images and some other bits.

    Ultimately there wiil always be limits - if you have loads of stuff going on, then you may have to cut some of it, for tthe animated gifs, it is their overall number and LDShapes.AnimationInterval, but try with updated version first.


    • Proposed as answer by YLedEditor Sunday, December 11, 2016 5:45 PM
    • Edited by litdevModerator Sunday, December 11, 2016 10:22 PM
    • Marked as answer by Zock77Editor Sunday, December 11, 2016 10:30 PM
    Sunday, December 11, 2016 5:17 PM
    Moderator

All replies

  • Hi Zock !

    ''as I play the game (about once every 5 seconds)"'

    i suggest to post your full game, and i will try it on my computer , to see all the parameters.

    i think it's the 1000/TimeElapsed

    that give a long long long number...


    • Edited by YLedEditor Thursday, December 8, 2016 2:18 PM
    Thursday, December 8, 2016 2:10 PM
    Answerer
  • Hard to be certain without a simple example that shows the problem which I guess you don't have.

    My guess would be the following:

    Various methods and calculations are occurring on different threads - especially with the mods I am making for performance.  One consequence may be that the main UI thread is not able to keep pace, it has to do the acual drawing etc.  At some point it gets overwhelmed and the OS steps in and lets it do its thing, pausing other stuff and there appears a lag.

    So as a test I recommend giving the game loop a slightly longer delay, i.e. reduce the fps update to that the UI thread does't get too overloaded.  The latest beta update of extension has LDStopWatch which has very accurate system timers that may help, but some functions (Shapes.Move as well as LDPhyscs.DoTimestep) start other threads to do some of the work so just because a function has returned doesn't necessarily mean everything it was asked to do is finished.

    Basically you want to run at a maximum fps that still leaves the UI thread time to do the graphics.  Of course if you can reproduce in a small test program all the better.

    PS

    A givaway that the UI threadis struggling is that interaction (e.g. mouse over corner X or dragging the GraphicsWindow) is slow to respond

    Another possibility is lots of stuff done in Event threads.

    Thursday, December 8, 2016 6:41 PM
    Moderator
  • Hmm. So I Halved the FPS (Now about a 30ms delay) but it had no effect. 

    I am wondering what your thoughts are on the fact that the lag disappears completely when you have another window in the foreground. I Just have the Textwindow from the same program in the foreground, and the lag is completely gone. (I can still see the game in the background).


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, December 9, 2016 3:59 AM
    Answerer
  • Assuming its not the UI thread catching up, I couldn't reproduce it.

    But it seems OK when its not in focus.

    My next guess would be to do with window events, which don't happen when it doesn't have focus.  So I would try removing as many interaction events as you can, i.e. MouseMove etc to see if this has an effect.

    Friday, December 9, 2016 10:05 AM
    Moderator
  • @litdev

    could it be the LDController like a USB  gamepad or joystick,   attached device ?

    Friday, December 9, 2016 3:03 PM
    Answerer
  • So I am not using any mousedown or keydown events in this program. Just Mouse.IsLeftButtonDown and LdUtilities.KeyDown

    It did strike me though that I only notice the lag when I'm playing multiplayer. Hmm


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, December 10, 2016 1:20 AM
    Answerer
  • It did strike me though that I only notice the lag when I'm playing multiplayer. Hmm

    Could be or a controller or anything, depends on what you are doing - the best is to try to isolate, simplify etc.

    Saturday, December 10, 2016 11:06 PM
    Moderator
  • I'll try my best. Its just really hard when the delay isn't happening on any specific function...

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Sunday, December 11, 2016 12:36 AM
    Answerer
  • Figured it out!! It was the animation images! 

    What is did was increased the number of projectiles in the game for one tank to 200 instead of 20. This made the game almost unplayable because of the lag. I then replaced all the projectiles in the game with rectangles, and did the same with the explosions. Its completely smooth now!

    I did realize that with 200 projectiles in the game, at 2X1 animations, and 200 explosions, at 4x2, that makes a total of 2,000 sprite images! (Wow) 

    So now I just need to decrease the number of sprites as much as possible.

    I'm also wondering, is there a way the animation images could be a little faster?

    Thanks!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Proposed as answer by litdevModerator Sunday, December 11, 2016 6:04 PM
    • Marked as answer by Zock77Editor Sunday, December 11, 2016 10:30 PM
    Sunday, December 11, 2016 12:55 AM
    Answerer
  • I'm also wondering, is there a way the animation images could be a little faster?

    I have updated the test beta version of extension to speed the animated gifs as much as I can using the ideas I used for images and some other bits.

    Ultimately there wiil always be limits - if you have loads of stuff going on, then you may have to cut some of it, for tthe animated gifs, it is their overall number and LDShapes.AnimationInterval, but try with updated version first.


    • Proposed as answer by YLedEditor Sunday, December 11, 2016 5:45 PM
    • Edited by litdevModerator Sunday, December 11, 2016 10:22 PM
    • Marked as answer by Zock77Editor Sunday, December 11, 2016 10:30 PM
    Sunday, December 11, 2016 5:17 PM
    Moderator