My code is not compiling, not sure why o_O
Let me explain the whole current situation.
I have this static constexpr member variable inside App class in App.h which rapresent how many times in a second we enter the Update function for the entire game:
class App
{
//GameUpdateTickPerSecond suggested ratio 1/25 seconds = 40ms per udpate
static constexpr uint8_t GameUpdatesPerSec = 25;
//...other stuff
};
then I have this using-declaration on top of Timer.h
//use this tipe to declare the ticks per second of the update call
template <size_t N>
using UpdateTickDuration = duration<uint32_t, std::ratio<1, N>>;
it is templated, so that the call inside my App::GameLoop function looks like:
static constexpr UpdateTickDuration<GameUpdatesPerSec> GameUpdateTPS{ 1 };
which should resoult in UpdateTickDuration<25> which in it's expanded form it's simply:
std::chrono::duration<uint32_t, std::ratio<1, 25>>
so if I cast an UpdateTickDuration type (with a value of 1) to milliseconds, then I would get 40ms.
Now, my entire game loop looks like this:
void App::GameLoop()
{
static constexpr UpdateTickDuration<GameUpdatesPerSec> GameUpdateTPS{ 1 };
while (Game->IsRunning())
{
//UPDATE
while (Timer->CurrentTime() > Timer->NextUpdateTime)
{
Game->Update();
Timer->NextUpdateTime += GameUpdateTPS;
}
//DRAW
float Interpolation = Timer->ComputeInterpolation(GameUpdateTPS);
Game->Draw(Interpolation);
}
}
So as you see, I am computing the Interpolation from within the GameTimer class, so my problem could also be there. That function looks like this:
Declaration in GameTimer.h:
template<size_t N>
float ComputeInterpolation(const UpdateTickDuration<N>& gameUpdateTPS);
Definition in GameTimer.h:
template<size_t N>
float GameTimer::ComputeInterpolation(const UpdateTickDuration<N>& gameUpdateTPS)
{
auto TimeOffset_ns = CurrentTime() + gameUpdateTPS - NextUpdateTime;
auto GameUpdateTPS_ns = duration_cast<nanoseconds>(gameUpdateTPS);
return (float(TimeOffset_ns.count()) / float(GameUpdateTPS_ns.count()));
}
The error I am getting is this:
Errore LNK2019 riferimento al simbolo esterno "public: float __thiscall GameTimer::ComputeInterpolation<25>(class std::chrono::duration<unsigned int,struct std::ratio<1,25> > const &)" (??$ComputeInterpolation@$0BJ@@GameTimer@@QAEMABV?$duration@IU?$ratio@$00$0BJ@@std@@@chrono@std@@@Z) non risolto nella funzione "public: void __thiscall App::GameLoop(void)" (?GameLoop@App@@QAEXXZ) Breakout Z:\Asus\Documenti\Visual Studio 2017\Breakout\Breakout\App.obj 1