[.net] Problem, possibly directinput, possibly incompetence

Started by
2 comments, last by RomSteady 18 years, 7 months ago

        Do While tRunning
            lastTick = currentTick
            currentTick = Environment.TickCount
            KeyIn.Poll(MessageCache, currentTick - lastTick)
            Do While Not MessageCache.Count = 0
                CallByName(Me, CType(MessageCache(0), gMessage).Command, CallType.Method, CType(MessageCache(0), gMessage).params)
                MessageCache.RemoveAt(0)
            Loop
            Dim tpoint As Double() = Players(0).getPoint
            txtCor.Text = Str(tpoint(0)) & Str(tpoint(1))
            Application.DoEvents()
        Loop
Is my main loop. The issue is with KeyIn.Poll(MessageCache, currentTick - lastTick) it runs perfectly until I press a key, and when I press the key it runs exactly the same with the exception that lasttick=currenttick for some reason. I don't know if it is relevant but the code for poll is

Public Function Poll(ByRef recv As ArrayList, ByVal ticks As Integer) As Boolean
        'Return true if device is still aquired, return false if it isn't
        If Active = True Then
            Try
                If Not KeyAc Then
                    kb.Acquire()
                    KeyAc = True
                End If

                Dim State As KeyboardState = kb.GetCurrentKeyboardState

                'Movement
                Dim movx As Single, movy As Single
                Dim gm As frmGame.gMessage
                Dim s As Boolean
                ReDim gm.params(4)
                gm.Command = "mov"
                gm.params(0) = "p"
                gm.params(1) = "0"
                gm.params(2) = "0"
                gm.params(3) = "0"
                gm.params(4) = Str(ticks)
                If State.Item(Key.UpArrow) Then
                    gm.params(3) = "1"
                    s = True
                End If
                If State.Item(Key.DownArrow) Then
                    gm.params(3) = Str(Int(gm.params(3)) - 1)
                    s = True
                End If
                If State.Item(Key.RightArrow) Then
                    gm.params(2) = "1"
                    s = True
                End If
                If State.Item(Key.LeftArrow) Then
                    gm.params(2) = Str(Int(gm.params(2)) - 1)
                    s = True
                End If
                If s = True Then
                    recv.Add(gm)
                End If

                Return True
            Catch e As Exception
                KeyAc = False
                Return False
            End Try
        End If
    End Function

If this info isn't enough, tell me and I can post the source code somewhere. HELP! (Going insane)
Advertisement
TickCount only updates 18.2 times a second.
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.
Thanks, is there an event when it updates or should I just check if it has, or should I be using something else completely to keep track of time passing?
Sorry for my brief answers...check into using QueryPerformanceCounter and QueryPerformanceFrequency. There are some tutorials on how to use them in managed code floating around the net.
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.

This topic is closed to new replies.

Advertisement