Hello Guest

Yet another Display.sync question

  • 3 Replies
Yet another Display.sync question
« on: January 05, 2012, 04:51:35 »

My game loop occasionally has problems.  I have a first person camera and generally speaking I get smooth movement.  But for some reason once in a while for days my forward/strafe movement becomes choppy.  I investigated a little, and what was going on is that the time delta between loops was coming out as 0 and would only be a larger amount every 6 or 7 loop cycles.  Here is the gist of my loop:

Code: [Select]

        lastTime = getTime();
        fpsTime = getTime();

        while (!Display.isCloseRequested() &&
        time = getTime();
        //System.out.println("Current time: " + time + ", lastTime: " + lastTime);

            dt = time - lastTime;
            lastTime = time;

    GLUtil.logError(-10, 0);

        return true;

This seemed like a fairly simple game loop to me. I looked through some of the threads in this forum and there was some fairly complicated stuff going on.  However, then I thought, for some reason, my  mouse look is not choppy at all, even when the movement is choppy.  Surely this must mean there is some other problem?  Anyone have an idea about what might be going on?

Re: Yet another Display.sync question
« Reply #1 on: January 05, 2012, 14:01:56 »
What is the getTime() method using to get the time?
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: Yet another Display.sync question
« Reply #2 on: January 05, 2012, 15:25:07 »
I've experimented.  Initially I was using Sys.getTime() *1000 / Sys.getTimerResolution().

I thought that was the problem, so I switched so System.nanoTime() which didn't fix anything. Same with System.currentTimeinMillis.

I enabled VSync thinking that would do it - but still no.  Which gets me back to the mouselook question. If my timing was screwed up, wouldn't mouselook also move in a jerky manner? It moves very smoothly.

Re: Yet another Display.sync question
« Reply #3 on: January 06, 2012, 02:51:34 »
This was a very stupid programming error on my part. I was using floats for my time storing variables. I don't even know why or how it ever worked appropriately. Now it works fine that I changed them to long. DISREGARD STUPIDITY, PROGRAM GAME.