I’m actually making this in C# with OpenTK. Here is my [icode]GameLoop()[/icode] method.
private void GameLoop()
{
// Initialize GL
InitGL();
// Gameloop variables
long now = GetCurrentTime();
long gameTime = GetCurrentTime();
int frames = 0;
int updates = 0;
int frameSkip = 1;
long frameTime = 1000 / Global.STEPS_FOR_SECOND;
int skippedFrames = 0;
long lastUpdateCount = GetCurrentTime();
long lastFramesCount = GetCurrentTime();
// The Game Loop
while (Exists)
{
CheckEnginePrefs();
now = GetCurrentTime();
// Update loop
while (now + frameTime > gameTime && skippedFrames < frameSkip)
{
Update(frameTime);
updates++;
gameTime += frameTime;
// Check for UPS
if (now - lastUpdateCount >= 1000)
{
Global.ACTUAL_STEPS_FOR_SECOND = updates;
updates = 0;
lastUpdateCount = now;
}
}
// render
GL.Clear(ClearBufferMask.ColorBufferBit);
Render();
frames++;
// Check for FPS
if (now - lastFramesCount >= 1000)
{
Global.FRAMES_PER_SECOND = frames;
frames = 0;
lastFramesCount = now;
}
SwapBuffers();
// Do the System Events
ProcessEvents();
}
}
This plays up nicely but I can see some stuttering i.e., non smooth movement of the character even though the game achieves 175 fps and 30 ups constantly. Now I’m thinking of implementing interpolation. I’ve read the GameLoops article but can’t understand it. How can I implement this in my loop?
Thanks.