I have a weird problem with the value returned by my class called Timer
(that uses std::chrono
).
If I keep the std::cout
commented, I have the feeling that delta
returned by timer.restart()
gets a very low value (it takes 3 or 4 times longer to reach 10.f). I tried to display it, but as I said above, uncommenting the std::cout
solves the problem.
My timer does its job well in others parts of the application, so I don't think the problem is in there.
void Party::gameOver(float delta)
{
_delta += delta;
// std::cout << _delta << std::endl; // if I uncomment this the problem is solved
if (_delta > 10.0000f) {
// ...
_state = GameStatusType::Waiting;
_delta = 0;
}
}
This method is called here:
void Party::loop(void)
{
Timer timer;
while (!isFinished())
{
float delta = timer.restart(); // return in second
switch (_state)
{
// ...
case GameStatusType::GameOver:
gameOver(delta);
break;
}
}
}
The method "loop" is called in a thread like below:
void Party::run(void)
{
_party = std::thread(&Party::loop, shared_from_this());
}
I don't know if this can help, but I execute this code on Visual Studio 2015 on Windows 10. If you need further information, just ask.