Elixir42 0 Junior Poster in Training

Hi

I am getting some strange results from my framerate calculation. It seems to have a mind of its own. It wants to stay at about 60 fps even if I set it to 80fps. It does run though if I set it to 50fps.

I am getting smooth movement at 60fps but at 50fps the waiting part kicks in and starts to jitter the movement. I have given the entire while loop.

it works I've tested it but I dont know why it stays at 60 fps and not go crazy.

Please help.

    MSG    msg;
    DWORD  ticks      = GetTickCount() / 1000;
    DWORD  ticksMS    = GetTickCount();
    ticks             = 0;      
    int    iFrame     = 0;  // the current frame
    int    iFrameRate = 60; // limits the framerate
    g_uFrameRate      = 0;  // global framerate
    long   iWaited    = 0;  // length of time waited
    int    iNumSecs   = 0;  // number of seconds gone by in game loop
    char   c[80];               // used as debug text
    string s;
    DWORD  fDelta     = 0.0f;
    FILE*  pFile;
    char   buffer[100];
    int    iFrameCycles = 0;

    fopen_s (&pFile, "myfile.txt" , "w");
    if (pFile == NULL) perror ("Error opening file");

    while (g_App.GetD3DStatus())
    {
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if (msg.message == WM_QUIT)
        break;

        if (KEY_DOWN(VK_ESCAPE)) PostMessage(hWnd, WM_DESTROY, 0, 0);
        if (KEY_DOWN(VK_MBUTTON)) PostMessage(hWnd, WM_DESTROY, 0, 0);


        // only run if more than 1 second has passed
        if (ticks < (GetTickCount() / 1000))
        {
            // save the framerate to tell CApplication, sprites and meshes
            g_uFrameRate = iFrame;

            // values
            iWaited   = 0;                      // reset the amount of time waited
            ticks     = GetTickCount() / 1000;  // rest ticks to the current time
            ticksMS   = GetTickCount(); 
            iFrame    = 0;                      // reset the number of frames to zero
            iNumSecs += 1;                      // increment the number of secs gone by
            iFrameCycles = 0;                   // the number of revolutions per second
        }

        // pause if we have rendered more than the framerate in 1 sec
        if (iFrame >= iFrameRate)
        {
            // calc amount of ms left over
            fDelta = 1000 - (GetTickCount() - ticksMS);
        }
        else
        {
            // check for user input
            g_App.DetectInput();

            // render
            g_App.Render();
            //Sleep(20);

            // incrememnt the frame number
            iFrame++;
        } // endelse

        iFrameCycles++;

    } // end while (g_App.GetD3DStatus())

    fclose (pFile);

Here is how I am moving... This is smooth at 60fps but jittery at 50fps.

void CShape::Orbit(float fX, float fY, float fZ)
{
    // calc xyz velocity's cirular points
    m_fXV = (float)(sin(fX) * 12.0f) * 20.0f;
    m_fYV = 0;
    m_fZV = (float)(cos(fZ) * 25.0f) * 20.0f;

    // set the spacial coords equal to triad velocities
    // make sure that there is no divide by zero and 
    // divide the velocity by the current framerate to give
    // the per second unit of movement.
    if (m_fXV != 0) 
        m_fX = m_fXV * fT;
    if (m_fYV != 0) 
        m_fY = m_fYV * fT;
    if (m_fZV != 0) 
        m_fZ = m_fZV * fT;

    // apply this to a matrix
    D3DXMatrixTranslation(&m_matTranslate, m_fX, m_fY, m_fZ);
}// Orbit