Why is my chrono duration not display the right value?
up vote
0
down vote
favorite
I am trying to create a FPS calculator for my game engine using the chrono
library, but somehow after I convert the total run time of my engine, it becomes like pic related.
Notice the -922337...
while it should be 1
and increment every line.
Followings are how I declare the variables relevant to FPS calculation.
std::chrono::duration<double> printFPStime, runTime, deltaTime;
std::chrono::high_resolution_clock::time_point frameStart, frameEnd;
int frames = 0;
float fps = 0.0f;
Followings are my source code for the FPS calculation.
void Game::CalculateFPS(){
runTime += deltaTime;
printFPStime += deltaTime;
frames++;
if (printFPStime >= std::chrono::seconds(1)){
std::cout << std::chrono::duration_cast
<std::chrono::seconds>(runTime).count()
<< " sec, " << frames <<
" fps" << std::endl;
printFPStime -= std::chrono::seconds(1);
frames = 0;
}
}
Where did I do wrong?
c++ frame-rate chrono
add a comment |
up vote
0
down vote
favorite
I am trying to create a FPS calculator for my game engine using the chrono
library, but somehow after I convert the total run time of my engine, it becomes like pic related.
Notice the -922337...
while it should be 1
and increment every line.
Followings are how I declare the variables relevant to FPS calculation.
std::chrono::duration<double> printFPStime, runTime, deltaTime;
std::chrono::high_resolution_clock::time_point frameStart, frameEnd;
int frames = 0;
float fps = 0.0f;
Followings are my source code for the FPS calculation.
void Game::CalculateFPS(){
runTime += deltaTime;
printFPStime += deltaTime;
frames++;
if (printFPStime >= std::chrono::seconds(1)){
std::cout << std::chrono::duration_cast
<std::chrono::seconds>(runTime).count()
<< " sec, " << frames <<
" fps" << std::endl;
printFPStime -= std::chrono::seconds(1);
frames = 0;
}
}
Where did I do wrong?
c++ frame-rate chrono
Try zero-initializing your durations, e.g.printFPStime{}
. If you don't initialize them, they have an indeterminate value.
– Howard Hinnant
Nov 10 at 16:27
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
1
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to create a FPS calculator for my game engine using the chrono
library, but somehow after I convert the total run time of my engine, it becomes like pic related.
Notice the -922337...
while it should be 1
and increment every line.
Followings are how I declare the variables relevant to FPS calculation.
std::chrono::duration<double> printFPStime, runTime, deltaTime;
std::chrono::high_resolution_clock::time_point frameStart, frameEnd;
int frames = 0;
float fps = 0.0f;
Followings are my source code for the FPS calculation.
void Game::CalculateFPS(){
runTime += deltaTime;
printFPStime += deltaTime;
frames++;
if (printFPStime >= std::chrono::seconds(1)){
std::cout << std::chrono::duration_cast
<std::chrono::seconds>(runTime).count()
<< " sec, " << frames <<
" fps" << std::endl;
printFPStime -= std::chrono::seconds(1);
frames = 0;
}
}
Where did I do wrong?
c++ frame-rate chrono
I am trying to create a FPS calculator for my game engine using the chrono
library, but somehow after I convert the total run time of my engine, it becomes like pic related.
Notice the -922337...
while it should be 1
and increment every line.
Followings are how I declare the variables relevant to FPS calculation.
std::chrono::duration<double> printFPStime, runTime, deltaTime;
std::chrono::high_resolution_clock::time_point frameStart, frameEnd;
int frames = 0;
float fps = 0.0f;
Followings are my source code for the FPS calculation.
void Game::CalculateFPS(){
runTime += deltaTime;
printFPStime += deltaTime;
frames++;
if (printFPStime >= std::chrono::seconds(1)){
std::cout << std::chrono::duration_cast
<std::chrono::seconds>(runTime).count()
<< " sec, " << frames <<
" fps" << std::endl;
printFPStime -= std::chrono::seconds(1);
frames = 0;
}
}
Where did I do wrong?
c++ frame-rate chrono
c++ frame-rate chrono
asked Nov 10 at 15:58
dude
17315
17315
Try zero-initializing your durations, e.g.printFPStime{}
. If you don't initialize them, they have an indeterminate value.
– Howard Hinnant
Nov 10 at 16:27
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
1
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55
add a comment |
Try zero-initializing your durations, e.g.printFPStime{}
. If you don't initialize them, they have an indeterminate value.
– Howard Hinnant
Nov 10 at 16:27
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
1
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55
Try zero-initializing your durations, e.g.
printFPStime{}
. If you don't initialize them, they have an indeterminate value.– Howard Hinnant
Nov 10 at 16:27
Try zero-initializing your durations, e.g.
printFPStime{}
. If you don't initialize them, they have an indeterminate value.– Howard Hinnant
Nov 10 at 16:27
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
1
1
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240714%2fwhy-is-my-chrono-duration-not-display-the-right-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try zero-initializing your durations, e.g.
printFPStime{}
. If you don't initialize them, they have an indeterminate value.– Howard Hinnant
Nov 10 at 16:27
OH MY GOD is this the real Howard Hinnant?!?!?!?!?! wtf?!?!?!
– dude
Nov 10 at 16:34
1
Hang on, I'll ask my wife....
– Howard Hinnant
Nov 10 at 16:55