Problem with the chrono library

The Partridge Family were neither partridges nor a family. Discuss.
Ariphael
Posts: 7
Joined: February 11th, 2017, 11:20 am

Problem with the chrono library

Post by Ariphael » February 11th, 2017, 11:35 am

I have a problem, when I use the chrono library to measure the time between two time points, the time duration, in seconds, is around 2.85100009e-06 which is 0.000003
This number is too low, so to move my box around the screen, I have to set the velocity to 1,000,000 which should be too big.
I have cleaned my solution, as chili instructed, using this: http://wiki.planetchili.net/index.php?t ... ili_Forums
Attachments
Chili Framework 2016.rar
Solution file
(87.44 KiB) Downloaded 115 times
Last edited by Ariphael on February 12th, 2017, 5:21 am, edited 1 time in total.

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Problem with the chrono library

Post by MrGodin » February 11th, 2017, 3:54 pm

The repository is empty.. ?
Curiosity killed the cat, satisfaction brought him back

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

Re: Problem with the chrono library

Post by chili » February 11th, 2017, 4:39 pm

Ariphael, looks like you had a problem creating / uploading the git repo. Either try again, or clean/zip the solution folder and upload it here.
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Problem with the chrono library

Post by albinopapa » February 11th, 2017, 6:10 pm

This type of thing has happened to me a few times because I'm not paying attention. Make sure you are resetting the clock at the beginning of the frame where the clock is stopped first then started. This way, the elapsed time measures the entire frame including all the updates and drawing.

If you are not accounting for the time it takes to draw all the pixels, then it won't be accurate since the update portion will probably take less time than drawing the hundreds of thousands of pixels, not to mention the half million pixel copies from the system memory to the gpu memory ( this usually only takes about 1 millisecond on my slow machine, but because of vsync it takes up whatever is left of 16).

If that's not the issue, then yeah, you'll need to try again to share your code with the class.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Ariphael
Posts: 7
Joined: February 11th, 2017, 11:20 am

Re: Problem with the chrono library

Post by Ariphael » February 12th, 2017, 5:21 am

chili wrote:Ariphael, looks like you had a problem creating / uploading the git repo. Either try again, or clean/zip the solution folder and upload it here.
MrGodin wrote:The repository is empty.. ?
ok i have attached the solution in a zip file, download that.

Ariphael
Posts: 7
Joined: February 11th, 2017, 11:20 am

Re: Problem with the chrono library

Post by Ariphael » February 12th, 2017, 5:27 am

oops, i put the timer.mark() in the wrong function, but that does not fix anything.

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

Re: Problem with the chrono library

Post by chili » February 12th, 2017, 5:31 am

Looks like you cleaned it properly ;)
I will take a look at this in a bit and get back to you bro.
Chili

Ariphael
Posts: 7
Joined: February 11th, 2017, 11:20 am

Re: Problem with the chrono library

Post by Ariphael » February 12th, 2017, 5:33 am

chili wrote:Looks like you cleaned it properly ;)
I will take a look at this in a bit and get back to you bro.
i accidently put timer.mark() in DrawBox function, i was supposed to put it in composeframe, but the time interval is still so small.
So I put it in ComposeFrame, and now the time interval is ~2e-5 which is one digit bigger, so then I could lower the velocity to 100,000 instead of 1,000,000.
I do not understand what is happening.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Problem with the chrono library

Post by albinopapa » February 12th, 2017, 6:24 am

Ok, like I said, you need to have the measured time cover the entire frame. Currently, you are only measuring the controls and drawing the box, you still aren't taking into account the gfx.BeginFrame and gfx.EndFrame()

You need to do something like this

Elapsed = timer.Mark();
timer.Point();

So that, at the beginning of the new frame, you update your elapsed time and restart the clock.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Ariphael
Posts: 7
Joined: February 11th, 2017, 11:20 am

Re: Problem with the chrono library

Post by Ariphael » February 12th, 2017, 8:01 am

albinopapa wrote:Ok, like I said, you need to have the measured time cover the entire frame. Currently, you are only measuring the controls and drawing the box, you still aren't taking into account the gfx.BeginFrame and gfx.EndFrame()

You need to do something like this

Elapsed = timer.Mark();
timer.Point();

So that, at the beginning of the new frame, you update your elapsed time and restart the clock.
Ok, so I put that in the Game::Go() function and now it works, thanks; I had to consider gfx.BeginFrame() and gfx.EndFrame(), the entire frame.

Post Reply