Question about running the program at the same speed on any computer

I made a program (in C ++ using gl / glut) for training purposes, where you can mainly run around the screen (in the first person) and have several solids around the scene. I tried to run it on another computer, and the speed was completely different, so I was looking for an item, and now I'm doing something like this:

Standby function:

    start = glutGet (GLUT_ELAPSED_TIME);
    double dt = (start-end)*30/1000;

    <all the movement*dt>

    glutPostRedisplay ();

    end = glutGet (GLUT_ELAPSED_TIME);

Display function:

    <rendering for all objects>

    glutSwapBuffers ();

My question is: is this the right way to do this? Is the scene displayed immediately after the idle function?

I tried placing end = glutGet (GLUT_ELAPSED_TIME) before glutSwapBuffers () and didn’t notice any changes, but when I put it after glutSwapBuffers () it slows down and even sometimes stops.

EDIT: , , , , , , idle() , display() , , , , - , ? ( ?)

, .

.

+3
7

, "Glut", , . , 80-, , , .

.

+4

(, QueryPerformanceCounter Windows) . , delta-time (dt), , . , :

obj.x += 100.0f * dt; // to move 100 units every second

dt 1 1 , x 100 , , . , . , ( ), , ( ). , - , , .

+1

. , , , . , , , , /.

, , x + = v * dt.

gamedev.net . .

+1

, .

+1

, "" , GLUT, GLUT "" . GLUT - glutTimerFunc().

static void timerCallback (int value)
{
    // Calculate the deltas

    glutPostRedisplay(); // Have GLUT call your display function
    glutTimerFunc(elapsedMilliseconds, timerCallback, value);
}

lastMilliseconds 40, 25 . , . , , 40 . .

, glutTimerFunc(elapsedMilliseconds, timerCallback, value); .

+1

.

AI , , 60 . , , , 60, 1000 . , 20 , 3 . , , AI ( ).

0

.

, awnser, , , , ? 99% , , .

: .

, , LOD, . LOD , .

. "". . , 50 , . , , 10 .

. , , , . , . http://gafferongames.com/game-physics/fix-your-timestep/.

0
source

Source: https://habr.com/ru/post/1735268/


All Articles