Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Converting the timer tutorial code

Author
Message
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 24th Jul 2005 21:59
Hello

I`m tryng to convert the code from BatVink`s timer tutorial. For the most part it`s just a case of converting the syntax but in one part he creates an array of timer structures and then adds this array to a queue. That`s where I get stuck. You see I don`t know what a queue is, what it`s used for or if it has an equivelant in c. Does anyone know what a queue is and how to have one in c?


Gimme teh votez!!!!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Jul 2005 03:54
A queue is really a linked list, whereby an item is put on the front of the list and deleted from the item of said list.

Got the source code (and DLL) for a doubly-linked list if you want to use that.

AtomZ - its got an A. Its got a Z. Now its just needs U
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 25th Jul 2005 04:14
mmm. A linked list? Ah I was just reading about that. They look complex. If you wouldn`t mind giving me the source code to that double link list I would apriciate it.
Thanks for your help


Gimme teh votez!!!!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jul 2005 08:01
Seeing as you are using a C++ compiler, why not just use the STL? That has a linked list container, as well as lots of other container types. There really is no good reason to reinvent a system that is already provided for you.



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Erick G
Retired Moderator
19
Years of Service
User Offline
Joined: 2nd Oct 2004
Location: Texas, USA
Posted: 25th Jul 2005 15:12
And STL is quick, like IanM said, dont waste time creating your own, STL is optomised and there for the using. Vectors, deques, maps etc...
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Jul 2005 16:33
I was wondering how long it would take to mention STL

AtomZ - its got an A. Its got a Z. Now its just needs U
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 25th Jul 2005 17:23
Well I don`t know anything about C++ but if you say that STL is easier than doing what I was going to do then now is as good as time as any to learn. ok. Thank you. I`lll report my progess as soon as I have any.


Gimme teh votez!!!!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jul 2005 18:43 Edited at: 25th Jul 2005 18:47
As an aside...I'm not a C++ programmer, and I don't use SDK. But I believe there are more accurate ways of getting the system time outside of DB Pro. My tutorial just uses Timer(), which appears to have an accuracy of 1 millisecond. However, my own experience seems to suggest it's nearer 4 milliseconds.

So you can use the same techniques as the tutorial, but probably with better accuracy.

Quote: "he creates an array of timer structures and then adds this array to a queue"


A queue is simply a way of adding Array elements. A queue doesn't actually exist, it's a way of describing how the array access works - First In, First Out. So if you ADD TO QUEUE(), it puts the new element at the end. If you REMOVE FROM QUEUE(), it takes the first item, element 0.
If you don't have these options available in C++, you simply need to keep track of the number of elements yourself, so you know where to add the next one.

Hope this helps

BatVink
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Jul 2005 19:02
The timer used by Timer(), is, I believe the low frequency one (ie calls GetTickCount())

I have found that once you start using the SDK, code gets executed so fast that code that gets the difference between two calls return a difference of 0 - hence the need to use a higher frequency clock.

AtomZ - its got an A. Its got a Z. Now its just needs U
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
Erick G
Retired Moderator
19
Years of Service
User Offline
Joined: 2nd Oct 2004
Location: Texas, USA
Posted: 25th Jul 2005 19:09 Edited at: 25th Jul 2005 19:11
to use higher precision timing, you can use , QueryPerfomanceCounter and QueryPerformanceFrequency, if you would like an example I can quickly knock one up.

GetTickCount aint that reliable compared to the above.

EDIT** did a quick search, here is an example

http://www.angelcode.com/dev/timefps/timefps.asp
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Jul 2005 19:45
Or see my demo programs to see how to use them.

AtomZ - its got an A. Its got a Z. Now its just needs U
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
Erick G
Retired Moderator
19
Years of Service
User Offline
Joined: 2nd Oct 2004
Location: Texas, USA
Posted: 25th Jul 2005 19:50
or that
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 25th Jul 2005 21:30 Edited at: 25th Jul 2005 21:34
Quote: "Hope this helps"

Yes. It has. Thank you. With all this new info it looks like I`m gong to have to do some planning on paper first. Sigh...
Quote: "I have found that once you start using the SDK, code gets executed so fast that code that gets the difference between two calls return a difference of 0 - hence the need to use a higher frequency clock.
"

mmm. I`ll use the other timer then. The good thing is. Pcs that only have GetTickCount() couldn`t possible run the game fast enough for the diference to be 0. A win win situation.

Quote: "you can use , QueryPerfomanceCounter and QueryPerformanceFrequency"

Thank you. Right today`s goal. Make 1337 timer functions


Gimme teh votez!!!!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jul 2005 22:06
The decision of which timer to use is a simple matter:

If you want a fast but not-so-accurate timer, use GetTickCount().
If you want a slower but really accurate timer, use the performance counter.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 26th Jul 2005 01:45 Edited at: 26th Jul 2005 01:52
Right scap that STL and structure stuff. Way too hard for me. I`ll just get the time compare it to the time the game started and compare that with anything I want to move or animate. These ticks, structs, templates, lists and all the other termanolagy is making my head hurt. Though I see no harm in using that accurate timer. If I only use it once per loop the speed diference between the two shouldn`t make any diference.
Thanks for the help guys.

Edit: One quick question. If I declare a global variable at the top of a cpp file. Will it only be avalible to the functions in that file? Is that even possible? I was just wondering on how to make my code easier to maintain. I think I need to look into scope more. They never seem to talk about it much in the tutorials I read though.


Gimme teh votez!!!!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 26th Jul 2005 22:44
Quote: "If I declare a global variable at the top of a cpp file. Will it only be avalible to the functions in that file? Is that even possible?"

Yes and Yes. Use extern to be able to use it in other source files.

AtomZ - its got an A. Its got a Z. Now its just needs U
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 27th Jul 2005 02:43
Quote: "Yes and Yes. Use extern to be able to use it in other source files."

Thank you. That`s great. Now I can seperate the code into seperate files and nothave to worry about so many global variables.


Gimme teh votez!!!!

Login to post a reply

Server time is: 2024-04-19 09:34:07
Your offset time is: 2024-04-19 09:34:07