Hello all.
I was looking at changing my game loop. But I have some questions,
(Q1)Like why do they have the accumulator in a while loop
(Q2)does that loop do the update or do you wait until the loop ends.
(Q3) What is t with long waits this just counts up and up each time you do a pass.
(Q4)lloks like it only works when frame time is small
(Q5)My test code maybe wrong.
(Q6)How do you proccess 8000 objects in a small amount of time. That will not make the time delay blow up.
(Q7)Its just me I have it all wrong Hoping.
This does not look wright if I add a 1 second delay at the end of the loop the while accumulator will spin for like depending on the wait can spin
upto 615 steps in the loop and more, this seams wrong why waste that loop.
I noticed in the article they put a if(frameTime > 0.25) frameTime = 0.25; whats the point of calling thy timer. In my current setup I just hard coded a 0.20 as my frame delta and vsync thats why I want to change to this, But I'm missing something.
this is the article
May be I have it wrong here is my test app.
.
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include<Windows.h>
#include <string>
#include <iostream>
#include <sstream>
#include<GameTimer.h>
int main(int argc, char* argv[])
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
std::cout << "Press Q to quit" << std::endl;
__int64 ctr1 = 0, freq = 0;
__int64 currentTime = 0;//hires_time_in_seconds();
int acc = 0, i = 0;
//get the time
if(QueryPerformanceCounter((LARGE_INTEGER *)¤tTime)== FALSE)
{
std::cout << "Timer error" << std::endl;
}
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
double t = 0.0;
const double dt = 0.01;
double accumulator = 0.0;
size_t listsize = 0;
std::string line; //stores the most recent line of input
while(std::getline(std::cin, line)) //read entire lines at a time
{
//deal with the contents of `line`
if(line.compare("q") == 0 || line.compare("Q") == 0)
break;
if(QueryPerformanceCounter((LARGE_INTEGER *)&ctr1)== FALSE)
{
std::cout << "Timer error" << std::endl;
}
__int64 newTime = ctr1;//hires_time_in_seconds();
double frameTime = ((newTime - currentTime) *1.0 / freq);//convert to seconds
//if(frameTime > 0.25 )
// frameTime = 0.25;
std::cout << "CurrentTime: = " << currentTime << std::endl;
std::cout << "NewTime: = " << newTime << std::endl;
std::cout << "Current Frame Time: = " << frameTime << std::endl;
currentTime = newTime;
accumulator += frameTime;
int count = 0;
while( accumulator >= dt )
{
count++;
//Sleep(200);
std::cout << "accumulator::" << accumulator << " Steps :" << count << std::endl;
std::cout << "Current Frame Time: = " << frameTime << std::endl;
//integrate( state, t, dt );
accumulator -= dt;
t += dt;
std::cout << "Time t = " << t << std::endl;
}
Sleep(1000);
}//end while running
return 0;
}
.
Just found this post Now if I set a DT of 1/120 and a sleep(1000) there is over 23000 steps lol say good by to your game loop hehehe. 1/30 seams to work a lot better
but what happens if your render takes a second say good bye again.
Can't you just set a timer to fire every 0.03 seconds and update.
I think I may have to move this into my real app and see what happens.