123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|711|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> timing problem

Wed, 11 Feb 2009, 15:36
dna
In the code below;


There are two timers running. One runs freely and the other measures each second. What I am trying to do is measure something 30 times a second.
It may be a conversion somewhere that I am missing.


-=-=-
DNA
Fri, 13 Feb 2009, 19:05
dna
Here's another method that I used.



Where am I making the error in the loop?


-=-=-
DNA
Fri, 13 Feb 2009, 19:51
dna
Here is the solution that I am using.



Also, when does the millisecs() function start to give errors?

1 millionth of a second?

WHen


thanks


-=-=-
DNA
Mon, 16 Feb 2009, 04:13
Teasy
Well, as MilliSecs returns a value in milliseconds, the maximum precision is milliseconds.
But you can use any interpolation ('cut up') value which can make it seem as if the precision is higher

Below I'll post the stuff I was going to email to you
But then I discovered you posted here

Mon, 16 Feb 2009, 04:20
Teasy
As you referred to my Timer System in email, I'll give some examples with and without my Timer System

Btw, I've updated my Timer System here at SoCoder to the latest version, with some new handy functions
Linky to code snippet
Direct copy/paste:


Some of the examples below take advantage of 2 of these new functions.

It's also handy to put a Decls file in the Blitz\UserLibs folder so various functions from custom includes can be Syntax Highlighted in the BlitzIDE (but also other IDE's like IDEal).



Mon, 16 Feb 2009, 04:25
Teasy
Modified your code (from email) to use a single timer at predefined interval.
Next example shows the precision.

Example 1


Mon, 16 Feb 2009, 04:27
Teasy
Same as before, but using a higher precision (x10).
Note that examples 1 and 2 are very inprecise because they are not directly depending on seconds.
See next example for a better approach.

The reason why this is inprecise is because 1000 / 30 (or 300) doesn't give a whole number.

Example 2


Note that you can check yourself how accurate a routine is by adding a CurrentTime() display (or something like that)

Mon, 16 Feb 2009, 04:28
Teasy
High precision example, using a timer based on seconds.
More CPU intensive though, due to the floating point division (or multiplication, in next example).

See example 3b for same as this, but using Delta timing (only 1 line is changed!)

Example 3a


Mon, 16 Feb 2009, 04:29
Teasy
Same as example 3a (high precision), but using Delta timing.
Only the line with TimerDelta is altered.

Example 3b


Mon, 16 Feb 2009, 04:31
Teasy
Basically the same as example 3, but without any Timers, e.g. everything manually, so you can see what happens 'behind the scenes'.

Using maths to find the number of frames, for maximum precision, though more CPU intensive, due to floating point division.

Example 4


Mon, 16 Feb 2009, 04:34
Teasy
Another example, but simple, using a Blitz Timer.
Also based on the timer itself.

The problem here is that the code will wait long times, which is time that could be spent on something else
This is due to WaitTimer, which simply sits and waits.

But, this is just for illustration
It works very well in many scenarios, simple games, etc.
Note that WaitTimer also has a slight imprecision.



I recommend either example 3a, 3b or 4 for 'perfect usage'
But example 5 for most easy

Mon, 16 Feb 2009, 07:05
JL235
I don't mean this in a way to discourage posting, because it's clear that your giving lots of help to dna (which is good).

But I'd like to recommend that in the future you try to edit and add to your previous post rather then make new ones. Especially if it's only a few minutes old.
Mon, 16 Feb 2009, 21:07
dna
Example 5 is what my original code was based on.

It would run, then I could see that it was not correct, but then I found that if I held the menu bar, to move it or to just hold it, the time stood still.

The ones you recommended seem correct since I will have other things running, in the mean time. (PUN)

My other question was, could 3a,b or 4 keep the right time if programming events internally hog the update cycle?

Your Time Library is great. I was beginning to think that BB2D could not keep an accurate REAL TIME at all.

I hope I can find your complete tutorial so that can help me further.

** Also, you mention something called the DeCls? I have no idea what that is and my version of BB does not have the folder userlibs.

-=-=-
DNA
Wed, 18 Feb 2009, 07:26
Teasy
Yes, that's the beauty of examples 3a, 3b and 4
Enjoy

Well, I have some more tutorials and stuff on my Blitz website: Linky

I think Decls (userlib declarations) are only available in later versions of Blitz3D and BlitzPlus. Maybe also Blitz2D, I don't remember, but Google will know
Wed, 18 Feb 2009, 08:17
Hotshot
Hey Teasy,

Yes Timing is important on any programming language.
How did you get on with X-NON?
Thu, 19 Feb 2009, 10:07
Teasy
Off-topic: Following rules

Hey Hotshot m8
You are a mindreader!
Only a few days before you wrote that I was working on it
It's progressing, but slowly
I guess I could post some first chapters somewhere if you'd like.
Please PM or email me about this
Mon, 23 Feb 2009, 12:25
dna
I modified your non library example and found that it's keeping the correct time per second, but the number of ticks is 33, not 30.




Here's another one.




This one is close but drifts out 10ms.


-=-=-
DNA
Tue, 24 Feb 2009, 08:48
Teasy
Well, I guess that's because 1000 / 30 = 33.3
E.g. Frames, ticks, seconds, FPS (Hz), etc.

Ah, to make the 2nd program more precise, try change this:



Into this:



I think that should work.

Thu, 26 Feb 2009, 20:02
dna

Thst did it TC. But is there a tutorial that explains why it works?

My reason for better understanding how it works would help me use it in other ways that might be similar but not the same.


-=-=-
DNA
Mon, 02 Mar 2009, 04:56
Teasy