Results 1 to 21 of 21

Thread: Timers, Timers, TIMERS!

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Angry

    I really hate the built-in VB timers. I'm doing some games in VB, and the timers really don't work that well. Even if I put in 20, it acts the same as if I had put in 50! (in the INTERVAL). So, does anybody know where I could get a high-resolution timer (one that reads EVERY second?)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    While we're still on the topic of timers, I need to ask:

    If I were to use this code, would it work for every 10 milliseconds?
    (I am using this because of DDraw):

    Code:
    Sub BLAHBLAHBLAH()
    Dim D as Integer
    Dim OldD as Integer
    Dim Started as Boolean
    ...
    ...
    Do
       If Started = True then   
          OldD = D
          D = GetTickCount()
          Do While D < (OldD + 1)
             D = D + 10
             If D > OldD Then
                Exit Loop
             Else
                MoveAllUnits
             End If
          Loop
       Else
          Started = True
          D = GetTickCount()
       End If
    
       BlitScreen
       
    Loop
    That would make up for any movement loss due to bad FPS, right? (I mean call to the MoveAllUnits subroutine). It would fire every 10 milliseconds, wouldn't it?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    New Member
    Join Date
    Jul 2000
    Posts
    15
    The timer would seem to act the same if u just put in 20 or 50 cos thats in miliseconds so you probably wouldnt notice the difference.

    If u want a delay of a second just type in a 1000!
    If practice makes perfect...

    and nobody's perfect...

    why the hell practice?

  4. #4
    Guest
    Timer controls are only accurate to about plus/minus 6ms (assuming no other processing is going on.

    You think VB is a good chioce for writing games?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    sastraxi, I've just emailed you a hi res timer...see what you think of it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Hey parksie, can you send that thing over here to? I want a look at it. Thanks

  7. #7
    Guest
    Use GetTickCount for accuracy up to 1ms. Make a Form with 2 CommandButtons (cmdStart and cmdStop) and put the following code into your Form.

    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Dim ContTime As Boolean
    
    Sub TimerEx(Interval As Long)
    
        Do While ContTime = True
            Start = GetTickCount
            
            Do While GetTickCount < Start + Interval
                DoEvents
            Loop
            
            '<--Place code here-->
            Print "Hello"
        Loop
        
    End Sub
    
    Private Sub cmdStart_Click()
        ContTime = True
        TimerEx (1000)
    End Sub
    
    Private Sub cmdStop_Click()
        ContTime = False
    End Sub

  8. #8

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Thumbs up

    Thanks, Parksie! The timer would be great...if I could use it. Thanks anyway, though! Actually, I might use it in other programs, but not in this one.

    Does anybody know if that Do....Loop code I inserted as a reply works? Because that may be what I'm using for my RTS. Actually, I think I need to make a few changes to the code:

    Code:
    Sub BLAHBLAHBLAH()
    Dim D As Integer
    Dim OldD As Integer
    Dim Started As Boolean
    Dim UseD As Integer
    ...
    ...
    Do
       If Started = True then   
          OldD = D
          D = GetTickCount()
          UseD = OldD
          If D + 10 < UseD + 1 Then
            Do While D < (OldD + 1)
                D = D + 10
                If D > OldD Then
                   Exit Loop
                Else
                   MoveAllUnits
                End If
             Loop
             UseD = OldD
          Else
             UseD = UseD - (D - OldD)
          End If
       Else
          Started = True
          D = GetTickCount()
       End If
    
       BlitScreen
       
    Loop
    End Sub
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Oh, and to answer WOSSNAME's post, Yes. I do think VB is powerful. And if you don't think it's powerful enough to do 3D, think about this.... I got a VB Runtime error in Unreal Tournament, so THAT is a good game made in VB!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Question Unreal made with VB: Unreal

    I believe that there was a VB runtime error and all that, but I'm pretty sure that they would have made it in C++ and maybe added a VB DLL or something.

    (PS: Great example that the thing made in VB had a runtime error )
    Courgettes.

  11. #11
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    What happens if the timer event doesn't have time to finish before the interval is over?
    Is the timer unabled untill it's free, or will it stack up events and do them after the timer is unabled?
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  12. #12
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi Guys,
    Thanks for the timing function Megatron. Works great (in the cmdStart_Click it should read (1000) not (100 0)). However, can you explain what happens here:

    -----------------------------------------
    Start = GetTickCount

    Do While GetTickCount < Start + Interval
    DoEvents
    Loop
    -----------------------------------------

    I'm a beginner and I don't get this code.
    As always.....

    Thanks
    Thanks

    Tomexx.

  13. #13

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    To Pentax: If you were talking to me, about the timer thing:

    I don't think mine will work, because I forgot a DoEvents(duh!)!

    Anyway, I'd like to know more about that Unreal Tournament thing. I'll try and recreate the error.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Tomexx - ? "1000 not 1000" ?

    This is a known problem here, where numbers get split up...you probably noticed it with your post which now makes no sense .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    Guest
    You could also use the SSubTimer from http://www.vbaccelerator.com

  16. #16
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello Sastraxi,

    I do understand you are hating built in timers.
    Try this:

    Copy this code into the declarations section of the project.

    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Use

    To delay the program for 1 second, use this code:

    Call Sleep(1000)

    Good luck,

    Michelle.

  17. #17

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Not on the topic, or anything, but how many posts to become a Lively Member?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, Pentax is a lively member on 102 posts...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  19. #19

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It's not on the topic, but I just got my 79th post (this one) and now am a lively memeber!!!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  20. #20
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754

    Talking To Time or not to Time.....

    http://www.mvps.org/ccrp/controls/ccrpcontrols.htm

    loads of cool replacement controls - check it out, they're free too

  21. #21
    Guest
    Tomexx:
    Code:
    'Start is setting an "Start time" for us
    Start = GetTickCount 
    
    'This loop pauses execution until the given amount of seconds pass by. (Start + Interval is the amount of milliseconds to pause)
    Do While GetTickCount < Start + Interval 
    'DoEvents lets the OS do othr tasks so our App does not freeze
    DoEvents 
    Loop
    Sastraxi, it's 64 posts for a Lively Member. See this page for a list of all the titles.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width