flat assembler
Message board for the users of flat assembler.

Index > Windows > why invoke gettickcount in opengl demo?

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 08:07
hello.
as i play with opengl demo from the fasmw.zip package, i saw a part of code that don't change anything if ignored.
Code:
.wmpaint:
;invoke  GetTickCount
;        sub eax,[clock]
;        cmp eax,10
;        jb .animation_ok
;        add [clock],eax
;.animation_ok:
    


then, i ask, what is the use of this part?
apparentllyy, opengl don't need it to set a reliable speed.
then, i don't see why it is there.

thanks.

and one bug in this demo (under win98) is when exiting with escape, it will not free the task bar, an artefact will be there like with some flash full screen returns, eg: dailymotion.

thanks.
Post 17 Mar 2010, 08:07
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 17 Mar 2010, 10:03
The system send WM_PAINT message continuously until
rect is validated by Begin-End-Paint or ValidateRect etc...
So there is always a new WM_PAINT message in the queue.
This has very low priority but get picked up quite often.
So it use GetTickCount to see how much time passed since last draw.
This is a bit different than the old OpenGL demo which used
InvalidateRect in the main loop to force a repaint.
It seems TG is playing around with the code still Smile
The fastest and cleanest way to render is in my demo.
As for the bug, i have 98 on hdd here and will try it there...
And 98 has low res timer so you may not see any difference.
I think my XP has 10ms where your 98 has around 50ms.
Post 17 Mar 2010, 10:03
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 17 Mar 2010, 12:38
it sholdnt use this function, it will overfow to 0 after 50 days.
Post 17 Mar 2010, 12:38
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 13:40
a115433 wrote:
it sholdnt use this function, it will overfow to 0 after 50 days.

hem... that is not a problem.
the problem i meet with this function is that with or without, i don't see any diffrence, and as i use the demo as a base for my squeleton, i need to clean it up.

then, if it is only to count the ticks, i will maybe implement it as a f.timer function.
the overflow is not a problem because:
gettickcount is used only to have the delta between two frames, and then, know the fps value in real time.

i still have this in the basic fool design with a newint8 interrupt and service.
then, i can know the time in 1 millisecond granularity.
under windows, it is not the same resolution.
Post 17 Mar 2010, 13:40
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 17 Mar 2010, 14:25
Quote:

gettickcount is used only to have the delta between two frames, and then, know the fps value in real time.

and what if this delta will be > 50 days?
whis function should return ERROR if time overflowed.

for example 0 - and get last error set to != 0 to distinguish between 0 time.
or as well it could be -1, or any other value + GetLastError().
Post 17 Mar 2010, 14:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Mar 2010, 15:07
Quote:
and what if this delta will be > 50 days?

The program stopped that long time? If the counter doesn't pass through or gets equal to your last GetTickCount call, then the difference will always give you the correct answer. For instance take a look to this:
Code:
mov ecx, $ffff'ff80 ; Simulating last GetTickCount call
mov edx, $0000'007F ; Simulating a GetTickCount call (overflow occurred once)

mov eax, edx
sub eax, ecx ; EDX  = $FF which is correct, it only passed 255 milliseconds    
Post 17 Mar 2010, 15:07
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 15:20
erf.
if i remember, you are the poster of the thread about jcc over 2Gigs.

lol.

remember a PC is a machine, that needs a code to work.
a code made by a coder.
then, if the coder make a program that reach theses problems without correction, it is time to correct.

when you code, yo test your code to see if it works well.

50 days is very long time for a CPU.
and the question was not tick overflow.
Post 17 Mar 2010, 15:20
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Mar 2010, 15:29
edfed, I've checked and there IS a difference, it goes faster without that code (well theoretically, I don't notice it).

Change to "cmp eax,10" to "cmp eax,1000", and it will be much clear what it is supposed to do.
Post 17 Mar 2010, 15:29
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 17 Mar 2010, 15:48
Quote:
then the difference will always give you the correct answer.

yes, with period of those 50 days. so you couldnt be able to tell if 1 second passed, or 1 bilion years. it will be the same.
The best way is jsut not use those kind of functions. cpu has real time closk, but its purpose is just generating interrupts, wich affect 'real clock' that update timer. And its purpose is just to give objects some information about creation time, etc, also shouldnt be really used, just information. Program design should be infinite, no matter what it would work, no matter how long, you get correct and consist results. Idea is to make something better than inferior human mind and body wich cant even handle 100+ years of living.

Quote:
50 days is very long time for a CPU.

and what is a long time?
50 days is long?
30 days is also long?

cmon, 2 hours is also very long.
Wlat about 1 minute, its also long time!
Why bother with entire synchronisation issue in multitasking!
time in wich thread execute 1 instruction, for example inc [m32] is really low!
its uncomparable to time in witch another thread will ever reach this instruction? And i belive in some cases ratio is over '50 days'. Why bother, to hell with semaphores, lock prefix, wait functions, just use sleep()! it will work just fine!
yeah!
Post 17 Mar 2010, 15:48
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 16:04
LocoDelAssembly wrote:
Change to "cmp eax,10" to "cmp eax,1000", and it will be much clear what it is supposed to do.


i don't see any difference.
and i can explain why.

the test does nothing else than inc [clock] each 10 ticks.
no affect on any part of the rest of the code.


then, i doubt it is really needed, for the moment.
Post 17 Mar 2010, 16:04
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Mar 2010, 16:08
If the demo will really take more than 50 days between draws then it is not worth to see already.

Also, in the code the only purpose it has is to "don't go fast", as the glRotate call is not taking the time elapsed into consideration so if the program is stopped by ten minutes, it will only progress ten milliseconds of animation at most once it is resumed.

There is of course situations in which GetTickCount is not good, for instance when you need extra precision or you want to time a very long computation that could take several months to complete, but a "don't ever use because it overflows after 49.71 days" is excessive paranoia to me.
Post 17 Mar 2010, 16:08
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Mar 2010, 16:09
edfed, you must have a different version (or you made some extra changes), I applied the change and the square rotates very slowly.

To clarify, this is what I have:
Code:
  .wmpaint:
        invoke  GetTickCount
        sub     eax,[clock]
        cmp     eax,10 ; <<< I've changed to cmp eax, 1000 here
        jb      .animation_ok
        add     [clock],eax
        invoke  glRotatef,[theta],0.0,0.0,1.0
      .animation_ok:    
Post 17 Mar 2010, 16:09
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 16:57
ok, i forgot that little modification.

yep, but now, i use theta as a variable. then, i can have very slow movments with only the change of theta, that i named speed because it is more a speed at the end.

thanks, now i know what it is exactlly.
and then, i can really delete this part of code.
cool!!

what i wonder now, is how can i rotate only one element without rotating all the scene.
Post 17 Mar 2010, 16:57
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 17 Mar 2010, 18:29
Quote:
but a "don't ever use because it overflows after 49.71 days" is excessive paranoia to me.

for me its a design flaw wich is unacceptable.
fixing this is really simple, just let it return BOOL, and store ticks in variable, wich should also be 64 bit.
return false = overflow/other error, return true = variable holds valid, non overflowed value.
Why didnt they though about it when they made this function?



And you think this 50 days is really 50 days?
What if i change frequency of power supply, so realtime clock will go faster?
What if i do something with clock itself?
What if i manage to get on top secret military server, hang the application between GetTickCount() exactly -1 microseconds, so both calls return same value? And the next code will behave diffrently after it? For example divide by 0 (maybe in module responsible for logging statistics)?

It create problems, and of source security flaws wich are 100% avoidable with NO effort and extra costs.
Post 17 Mar 2010, 18:29
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 20:50
maybe you need to learn with practice now.
theory is not enough.
go code and stop troll.
Laughing
Post 17 Mar 2010, 20:50
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 17 Mar 2010, 21:12
troll? im right, trolling would be if i call author a noob and everyone else without explanation other than 'because u are'.
Post 17 Mar 2010, 21:12
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Mar 2010, 21:33
troll because instead of focus on theorical flaw, you should test them, and see how it can be corrected.

turning around a pot don't give any solution, it just gives a Troll.
Post 17 Mar 2010, 21:33
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 18 Mar 2010, 08:24
a115433 has a point, though - you can get some funky timing errors if you depend on GetTickCount and the machine has been running for those ~50 days. We're not talking delays of 50 days, but code running on a machine that has been up for that long time (or use hibernation instead of poweroff...)
Post 18 Mar 2010, 08:24
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 18 Mar 2010, 09:10
edfed wrote:
what i wonder now, is how can i rotate only one element without rotating all the scene.

You store transformation/rotation info for each node in the scene.
Then use gl matrix procedures to animate each node separately.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 18 Mar 2010, 09:10
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 18 Mar 2010, 14:48
f0dder,

He has a point iff those GetTickCount() calls are more than 2³²-1 ticks apart (oh yeah, millisecond resolution for several days long period). There is GetTickCount64() (Vista/2008+) as well. Wink
Post 18 Mar 2010, 14:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.