I am not even considering the interpolation thing right now and just trying to get the basics of it timed properly, because I think there is something wrong even before.
4 hours ago, Kylotan said:
Marcus, you're still insisting that Vsync is messing up the interpolation value, and I think I told you right back on page 1, twice, that it's not.
I just made a test for Vsync, image below, let's see who can explain it.
So this image is the resoult I get with SDL_RENDERER_PRESENTVSYNC active(image below).
The data is stored into vectors and is collected inside the Update loop, therefore since I have a Fixed Update once every 40ms, this means we collect 25 samples in a second, and that shown is 1 second worth of data. So, the bar on top are the "scheduled next update" which predictably increase at step of 40ms, nothing to see there, but the matching data on the bottom is the current time when we enter the update loop. As you can see, we are always entering late when Vsync is On.

Now compare with the image below, where the SDL_RENDERER_PRESENTVSYNC flag is off. As you can see in the image below, we enter the update loop as soon as possible, which makes us right on time (except the 25th update where we are 1ms late).

Anyway, why is Vsync messing up when I enter the update function?! =_=
I also leave the testing code below in spoiler, so you can see where I was storing the values.
void App::GameLoop()
{
/*DEBUG*///////////////
std::vector<std::string> UpdateCall;
std::vector<std::string> NextUpdateVals;
Timer->Restart();
while (Game->IsRunning())
{
time_point<steady_clock>& CurrentTime = Timer->Tick();
/*DEBUG*///////////////
SDL_SetRenderDrawColor(Renderer, 55, 55, 55, SDL_ALPHA_OPAQUE);
SDL_RenderClear(Renderer);
//UPDATE
while (CurrentTime >= Timer->NextUpdateTime)
{
/*DEBUG*///////////////
int CurrentMs = duration_cast<milliseconds>(CurrentTime - Timer->TimeBegin).count();
int NextUpdateMs = duration_cast<milliseconds>(Timer->NextUpdateTime - Timer->TimeBegin).count();
UpdateCall.push_back(std::to_string(CurrentMs));
NextUpdateVals.push_back(std::to_string(NextUpdateMs));
Game->Update();
Timer->NextUpdateTime += Timer->GameUpdateTPS;
}
//DRAW
Game->Draw(0.f/*Timer->DrawTick()*/);
//Testing the loop from here.
/*DEBUG*///////////////
Timer->DrawTick();
//1 seconds worth of Updates. Step marks at 40ms spacing
int spacing = 100, border = 50;
float fixedUpdate = 40;
for (int i = 0; i < NextUpdateVals.size(); i++)
{
auto& val = NextUpdateVals[i];
DrawDebugText(Renderer, val, Point{ border + spacing*i,180 }, Color{ 150,110,40,255 });
DrawDebugLine(Renderer, Point{ border + spacing*i,200 }, Point{ border + spacing*i,230 }, Color{ 150,110,40,255 });
}
//Draw and compare the recorded value of when we entered UpdateLoop
for (int i = 0; i < UpdateCall.size(); i++)
{
auto& val = UpdateCall[i];
int scaledToGraph = (std::stof(val) / fixedUpdate) * spacing;
DrawDebugText(Renderer, val, Point{ border + scaledToGraph,400 }, Color{ 215,130,40,255 });
DrawDebugLine(Renderer, Point{ border + scaledToGraph,390 }, Point{ border + scaledToGraph,234 }, Color{ 215,130,40,255 });
}
SDL_RenderPresent(Renderer);
/*DEBUG*/////////////////////////////////////////
}
}