CGameProgrammer:
Shouldn''t any _good_ compiler convert any simple division call (say 1/100) to it''s multiplication counterpart. As far as I know they generally do because multiplation is usually faster then division.
My logic anyways
Cray
timeGetTime scale?
Speaking of timegettime, I have had something weird happen to me.
Everything is working great, and the average FPS gets spit out into a debug text file at the end.
Oops, I lock up my computer, and reboot (I am using WinME).
I run the program again, but it LOOKs like I am getting about 2 FPS now. I check my text out, and it says I am still getting 120 FPS.
I then proceed to check my calculations for about an hour, then take an hour break after getting no where. I come back later, and
everything looks fine again.
As a test, I reboot my computer, and again, it looks slow, but it is actually still updated fast. My objects are updated
according to time.
I am computing how much time has passed each frame, and my objects use that as their bases of movement. So why would
rebooting my computer effect anything?
Since timegettime gives miliseconds, and I am using only the difference, smaller return values from the function (computer just being turned on) should not make a difference.
I am evidently missing something here. Anyone have any suggestions?
Everything is working great, and the average FPS gets spit out into a debug text file at the end.
Oops, I lock up my computer, and reboot (I am using WinME).
I run the program again, but it LOOKs like I am getting about 2 FPS now. I check my text out, and it says I am still getting 120 FPS.
I then proceed to check my calculations for about an hour, then take an hour break after getting no where. I come back later, and
everything looks fine again.
As a test, I reboot my computer, and again, it looks slow, but it is actually still updated fast. My objects are updated
according to time.
I am computing how much time has passed each frame, and my objects use that as their bases of movement. So why would
rebooting my computer effect anything?
Since timegettime gives miliseconds, and I am using only the difference, smaller return values from the function (computer just being turned on) should not make a difference.
I am evidently missing something here. Anyone have any suggestions?
If the elapsed time is being used to calculate things like rotation angles, you should be aware that some CPUs have maximum input ranges for functions like sin() and cos() - if you are doing something like:
a = time * 0.001f;
c = cos( a );
or even
a += elapsed * 0.001f;
c = cos( a );
Then after a while, the inputs to those functions will be too high.
Also, as mentioned above - don''t put the value from timeGetTime() directly into a float or even cast it (explicityly or implicitly) because the bigger the number gets, the more fractional precision you can lose. Always do the elapsed part as unsigned integer, if you need to cast into a float, cast the result variable into a float.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
a = time * 0.001f;
c = cos( a );
or even
a += elapsed * 0.001f;
c = cos( a );
Then after a while, the inputs to those functions will be too high.
Also, as mentioned above - don''t put the value from timeGetTime() directly into a float or even cast it (explicityly or implicitly) because the bigger the number gets, the more fractional precision you can lose. Always do the elapsed part as unsigned integer, if you need to cast into a float, cast the result variable into a float.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
resolution...
if you, say, use GetTickCount(), and query ever 1 millisecond,
youll get values like:
xxx00
xxx00
xxx00
xxx00
xxx00
xxx00
xxx00
xxx18
xxx18
xxx18
xxx18
xxx18
xxx18
and on. means the smallest difference between returned values.
you would expect this to be 1, but on NT/2000 this is not even true for timeGetTime().
thats timer-resolution.
if you, say, use GetTickCount(), and query ever 1 millisecond,
youll get values like:
xxx00
xxx00
xxx00
xxx00
xxx00
xxx00
xxx00
xxx18
xxx18
xxx18
xxx18
xxx18
xxx18
and on. means the smallest difference between returned values.
you would expect this to be 1, but on NT/2000 this is not even true for timeGetTime().
thats timer-resolution.
quote:Shouldn''t any _good_ compiler convert any simple division call (say 1/100) to it''s multiplication counterpart. As far as I know they generally do because multiplation is usually faster then division
No. For integers this is impossible, of course, and integer division is what I was talking about. For floats, I think there will be slight precision errors, so it would be left to the programmer to decide whether to multiply or divide. However, operations with constants are resolved at compile-time, so you can multiply by (1/1000)/Font> and it should convert that to 0.001. Useful for more complex numbers.
~CGameProgrammer( );
so...
any good compiler will substitute "/ const" by "* const" if you tell him.
there are optimization switches to do so.
and: if you have something like "/4.0f" it can be optimized anyway, because 1.0f/4.0f is an "exact" number.
if you have "/10.0f" things are different ofcourse.
on the rotation-angle stuff:
yes, you should always have a "wrap around" for angles to make them (0 to 2*pi) or (-pi to pi), whatever you prefer.
or, even better use DWORDS, they have "automatic wraparound" and you can easily convert them to float/double just before calling any trigonometric functions with
bye,
-- foobar
any good compiler will substitute "/ const" by "* const" if you tell him.
there are optimization switches to do so.
and: if you have something like "/4.0f" it can be optimized anyway, because 1.0f/4.0f is an "exact" number.
if you have "/10.0f" things are different ofcourse.
on the rotation-angle stuff:
yes, you should always have a "wrap around" for angles to make them (0 to 2*pi) or (-pi to pi), whatever you prefer.
or, even better use DWORDS, they have "automatic wraparound" and you can easily convert them to float/double just before calling any trigonometric functions with
// somewhere in your globals.h:static const float fDWORD_Range = float(1L<<31)*2.0f; // for dumb compilers ;)static const float fDWORD_Range = float(1i64<<32); // for smart ones like MSVC++ 6.0 and up// in your code:DWORD dw_phi = 1234567; // or any valuefloat phi = float(dw_phi)*(2.0f*PI/fDWORD_Range); //this is just on fmul == really cheap
bye,
-- foobar
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement