 |

10-26-2001, 01:35 AM
|
|
|
Is there a way to use direct x to act like a timer
|
In my games i have a sleep command as my timer for the game speed
but it is a little slow, and i heard that there is a directx command that also will do the same thing but runs smoother
|
|

10-26-2001, 01:53 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
Syncing to screen, also called vsync or wvbl (wait for vertical blanc)
First you need a reference to ddraw.tlb
The commands I use:
<pre>
' first some public declares
Public DD As DirectDraw ' our directdraw reference
' init DirectDraw
DirectDrawCreate ByVal 0&, DD, Nothing
DD.SetCooperativeLevel Me.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
DD.SetDisplayMode lXres, lYres, lColorDepth
' in the game loop use this
Do
'
' Game code
' Game code
'
DD.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0&
Loop Until bGameFinished
</pre>
|
|

10-26-2001, 01:58 AM
|
|
|
Re: Is there a way to use direct x to act like a timer
|
I dont understand how this works...what is the code actually doing to make it like a timer?
|
|

10-26-2001, 02:36 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
Suppose your screen is refreshed 70 times per second.
If you do all needed screen updates within 1/70th of a second and suspend all screen updates until the next screen refresh occurs, you will get smooth animation without needing a timer to refresh/repaint your screen.
|
|

10-26-2001, 07:01 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Is there a way to use direct x to act like a timer
|
Arnout, I think maybe you are missing the point here. V. Syncing doesnt have anything to do with timers, its just used to make things all fit together. I believe what andrewo wants is an alternative to the sleep API, to pause program executiong for a set period of time.
What you might be after is a way of making the game run at the same speed on any PC, without setting a FPS cap. However, I suspect you are just looking for an all-purpose timer. This code might help:
<pre>Public Sub DXTimer(lMilliseconds As Long)
Dim cTim As Long
cTim = DX.TickCount
Do Until DX.TickCount - cTim >= lMilliseconds
DoEvents
'You could make it do other stuff here, like update the screen
'Or game phyics
Loop
End Sub</pre>
Of course, this will actually pause program execution for the specified time, just like sleep. Music will continue to run, as will sound, but you will have to engineer it specially if you want it to refresh the screen during this wait period. If that is what you are after, then I can help you there as well.
[img]images/icons/smile.gif[/img]
|
|

10-26-2001, 07:28 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
Must be me, but I've never used sleep or whatever timers in games/demo's.
What do you need a timer for??
|
|

10-26-2001, 07:31 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Is there a way to use direct x to act like a timer
Well, basically so that when the game is run on faster PCs it doesnt just zoom along, and the speed is uniform across a variety of platforms.
You can find more info on this here (Lucky's VB)
|
|

10-26-2001, 07:35 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
But if you use a WVBL, your execution will be halted until the screen starts to redraw. So whatever speed you have, it will never be to fast...
|
|

10-26-2001, 07:38 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
Just read Lucky's page... It's merely a trick to keep slower computers in speed...
Indeed when you don't have the speed to build the screen every WVBL the game can become unplayable ...
|
|

10-30-2001, 11:13 PM
|
|
|
Re: Is there a way to use direct x to act like a timer
|
Hey so arnoutv are u sayin your code waits for the next frame to go by or something?
i've seen this timer that works by going frame by frame and adding an amount of milliseconds for each frame
does anyone know how to do this?
|
|

10-30-2001, 11:18 PM
|
|
|
Re: Is there a way to use direct x to act like a timer
|
hey i cant find the ddraw.tlb file on my computer , is there another similar file that i can use?
|
|

10-31-2001, 01:13 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,884
|
|
Re: Is there a way to use direct x to act like a timer
|
You're right, I wait for the screen to be repainted to do all actions.
|
|

10-31-2001, 08:47 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Is there a way to use direct x to act like a timer
|
You dont need a ddraw TLB, you just need to Reference DirectX 7 for Visual Basic Type Library in your project. The actual file it all comes from is called DX7VB.DLL and comes with DirectX 7, so if you have DX 7 installed on your computer, then it is very likely you will have this file also.
|
|

11-01-2001, 02:20 AM
|
|
|
Where do I enter the code?
|
Ok for the code below I dont understand where you set the amount of milliseconds
and also where you actually enter this code...
I tried adding this in the code like this
section of vb but it says argument not optional..........................
Public Sub DXTimer(lMilliseconds As Long)
Dim cTim As Long
cTim = DX.TickCount
Do Until DX.TickCount - cTim >= lMilliseconds
DoEvents
Print "Hi"
Loop
End Sub
Private Sub Command1_Click()
DXTimer
End Sub
-----------------------------------------------------------------------------------------
Also with this code, I also dont know where to enter it
and where do you add the amount of milliseconds between frames?
I
Public DD As DirectDraw ' our directdraw reference
DirectDrawCreate ByVal 0&, DD, Nothing
DD.SetCooperativeLevel Me.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
DD.SetDisplayMode lXres, lYres, lColorDepth
Do
DD.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0&
Loop Until bGameFinished
|
|

11-01-2001, 03:29 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Where do I enter the code?
|
Your problem is that you called the timer sub without passing the correct parameters. To call the sub you would use Call DXTimer(enter number here) to get it to work.
As for the second problem, check out my DirectDraw/Direct3D/DirectMusic sample code (not tutorial) in the Code Library
|
|

11-02-2001, 05:32 AM
|
|
|
Re: Where do I enter the code?
|
still doesnt work.....................
Public Sub DXTimer(lMilliseconds As Long)
Dim cTim As Long
cTim = DX.TickCount
Do Until DX.TickCount - cTim >= lMilliseconds
DoEvents
'You could make it do other stuff here, like update the screen
'Or game phyics
Print "G"
Loop
End Sub
Private Sub Command1_Click()
Call DXTimer(500)
Print "hi"
End Sub
-------------------------------------
it now says "Run-time error '424' "
"Object required"
on the line
cTim = DX.TickCount
|
|

11-02-2001, 08:07 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Where do I enter the code?
Thats because you havent declared DX as a DirectX object. It sounds to me like you are very new to DirectX. I would suggest checking out my tutorial(s) in Tutors Corner, the DirectMusic tutorial is the starter one that deals with setting up DirectX and its objects.
|
|

11-04-2001, 12:55 AM
|
|
|
Re: Where do I enter the code?
|
Sorry I still got absolutely no idea even after looking at the tutorials..
Can you just right me a full example of using the timer within a program squirm
|
|

11-04-2001, 02:14 AM
|
 |
Hell's Angel
Retired Moderator * Guru *
|
|
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
|
|
Re: Where do I enter the code?
|
Just place this with your variable declarations:
Dim DX As New DirectX7
|
__________________
A wise one man once said "what you talking about dog breath"
|

11-04-2001, 03:43 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: Where do I enter the code?
|
andrewo, it seems to me that you are using DirectX for the sole purpose of acting like a timer. When you first asked the question I assumed that you were already using DirectX for the graphics/sound/music, and so adding this piece of code would be simple.
However, it is clear to me now that you are not already using DirectX. In this case I would suggest using the timer API calls instead. They have a better resolution that the timer control, down to 1ms which I am sure is adequate for your purposes (DirectX cannot do any better). Referencing and declaring DirectX for the sole purpose of a timer in my opinion is a waste of system resources.
Not that I want to put you off DirectX, I just think you might be doing something which is not necessary.
[img]images/icons/smile.gif[/img]
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|