andrewo 10-26-2001, 01:35 AM 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
Flyguy 10-26-2001, 01:53 AM 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>
andrewo 10-26-2001, 01:58 AM I dont understand how this works...what is the code actually doing to make it like a timer?
Flyguy 10-26-2001, 02:36 AM 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.
Squirm 10-26-2001, 07:01 AM 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.
images/icons/smile.gif
Flyguy 10-26-2001, 07:28 AM Must be me, but I've never used sleep or whatever timers in games/demo's.
What do you need a timer for??
Squirm 10-26-2001, 07:31 AM 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) (http://www.rookscape.com/vbgaming/tutAQ.php)
Flyguy 10-26-2001, 07:35 AM 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...
Flyguy 10-26-2001, 07:38 AM 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 ...
andrewo 10-30-2001, 11:13 PM 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?
andrewo 10-30-2001, 11:18 PM hey i cant find the ddraw.tlb file on my computer , is there another similar file that i can use?
Flyguy 10-31-2001, 01:13 AM You're right, I wait for the screen to be repainted to do all actions.
Squirm 10-31-2001, 08:47 AM 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.
andrewo 11-01-2001, 02:20 AM 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
Squirm 11-01-2001, 03:29 PM 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
andrewo 11-02-2001, 05:32 AM 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
Squirm 11-02-2001, 08:07 AM 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 (http://www.visualbasicforum.com/bbs/postlist.php?Cat=&Board=tu), the DirectMusic tutorial is the starter one that deals with setting up DirectX and its objects.
andrewo 11-04-2001, 12:55 AM 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
Banjo 11-04-2001, 02:14 AM Just place this with your variable declarations:
Dim DX As New DirectX7
Squirm 11-04-2001, 03:43 AM 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.
images/icons/smile.gif
|