Beginner Tutorial 17 Framertimer

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
hannes321123
Posts: 2
Joined: August 11th, 2019, 8:37 pm

Beginner Tutorial 17 Framertimer

Post by hannes321123 » August 28th, 2019, 2:44 pm

Hi everyone,

I have a problem to understand an error I made in tutorial 17. In Frametimer.cpp in the mark-function there is a line "last = steady_clock::now();" I know that "last" is a member variable declared by us but I accidentally wrote an "auto" in front off it, that caused a huge acceleration. Investigating it further by writting "steady_clock::time_point" instead of "auto" the acceleration remaind... What is happening there?

Thanks already
hannes

User avatar
Yumtard
Posts: 568
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Beginner Tutorial 17 Framertimer

Post by Yumtard » August 28th, 2019, 8:36 pm

What's happening is that you're creating another variable called last which is local to the mark function

At the beginning of the function you also create a variable old and set its value to the member variable last.
The value of the member variable never changes though since, as we established you're making a new local variable when you're going:
auto last = steady_clock::now();

This leads to an acceleration because when you're calculating the frame time you're doing
last - old
last in this case refers to the local variable which stores the current time
old in this case has the same value as the member variable last, which never changes
causing the delta time to grow larger

User avatar
chili
Site Admin
Posts: 3841
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Beginner Tutorial 17 Framertimer

Post by chili » August 30th, 2019, 3:17 am

Scope is an essential concept to master for sure :D
Chili

hannes321123
Posts: 2
Joined: August 11th, 2019, 8:37 pm

Re: Beginner Tutorial 17 Framertimer

Post by hannes321123 » September 1st, 2019, 4:02 pm

Thanks a lot, the explanation was very helpful. Sorry for answering late. I have been working mostly with Matlab there you have to declare less stuff and things are more seperated. Thanks to all the people working on the tutorials and in the forum, it is great !!!

Post Reply