LWJGL Forum

Programming => OpenGL => Topic started by: sufimaster on January 05, 2012, 04:51:35

Title: Yet another Display.sync question
Post by: sufimaster on January 05, 2012, 04:51:35
Hi,

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() &&
                !Keyboard.isKeyDown(Keyboard.KEY_Q))
        {
        framesPassed++;
       
        time = getTime();
        //System.out.println("Current time: " + time + ", lastTime: " + lastTime);

            dt = time - lastTime;
            lastTime = time;

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glMatrixMode(GL_MODELVIEW);
    GLUtil.logError(-10, 0);

            glLoadIdentity();                       
            updateScene(dt);           
            renderScene(dt);
            updateFPS(dt);
                       
            Display.update();
            Display.sync(60);
        }
        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?
Title: Re: Yet another Display.sync question
Post by: Fool Running on January 05, 2012, 14:01:56
What is the getTime() method using to get the time?
Title: Re: Yet another Display.sync question
Post by: sufimaster 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.
Title: Re: Yet another Display.sync question
Post by: sufimaster 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.