Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: TVInput question (odd halting)  (Read 671 times)
Raine
Customers
Community Member
*****
Posts: 1190


« on: September 28, 2007, 04:45:48 AM »

TVInput.GetKeyPressedArray(keyPressedArray) halts the execution of my application. I can't even pause it in Visual Studio. It just stucks because of that call.

Where should I exactly call this method? Before rendering, after, or even in the middle of the main loop?
Logged

newborn
Customers
Community Member
*****
Posts: 2437


WWW
« Reply #1 on: September 28, 2007, 08:15:01 AM »

I never had any problems with this... Here's my loop:

Input.Update
Camera.Update
Player.Update
...
Engine.Clear
Scene.RenderAll
Engine.RenderToScreen



And here's my code, it should (somewhat) help you with events. You will see that I also handle is the mouse button was all ready down... This was necessary to have single clicks so the game/program/editor/whatever doesn't execute the command 30 times. Note that all of this could be handled so many other ways! But it is mine to offer, yours to receive Smiley


Public Class clsInput
    Private _TVInput As New MTV3D65.TVInputEngine

    ' Mouse
    Private _iMouseX As Integer, _iMouseY As Integer
    Private _iMouseAbsX As Integer, _iMouseAbsY As Integer
    Private _bIsMousePressed(4) As Boolean
    Private _bWasMousePressed(4) As Boolean
    Private _iWasScroll As Integer, _iIsScroll As Integer

    ' Keys
    Private _bKeyIsPressed(255) As Byte
    Private _bKeyWasPressed(255) As Byte

    ' Keyboard configuration
    Private _iQuit As Integer = 1
    Private _iCameraForward As Integer = 17
    Private _iCameraBackward As Integer = 31
    Private _iCameraLeft As Integer = 30
    Private _iCameraRight As Integer = 32
    Private _iCameraUp As Integer = 18
    Private _iCameraDown As Integer = 16

    ' Function keys
    Private Const _iF1 As Integer = 59
    Private Const _iF2 As Integer = 60
    Private Const _iF3 As Integer = 61
    Private Const _iF4 As Integer = 62
    Private Const _iF5 As Integer = 63
    Private Const _iF6 As Integer = 64
    Private Const _iF7 As Integer = 65
    Private Const _iF8 As Integer = 66
    Private Const _iF9 As Integer = 67
    Private Const _iF10 As Integer = 68
    Private Const _iF11 As Integer = 69
    Private Const _iF12 As Integer = 70

    ' Double keys
    Private Const _iShiftLeft As Integer = 42
    Private Const _iShiftRight As Integer = 54
    Private Const _iAltLeft As Integer = 56
    Private Const _iAltRight As Integer = 184
    Private Const _iCtrlLeft As Integer = 29
    Private Const _iCtrlRight As Integer = 157

    Public Sub Update()
        Dim bShift As Boolean
        Dim bAlt As Boolean
        Dim bCtrl As Boolean

        ' Pass Is info to Was info (used for simple key click)
        For i As Integer = 0 To 255 : _bKeyWasPressed(i) = _bKeyIsPressed(i) : Next
        For i As Integer = 0 To 4 : _bWasMousePressed(i) = _bIsMousePressed(i) : Next
        _iWasScroll = _iIsScroll

        ' Update
        With _TVInput
            .GetKeyPressedArray(_bKeyIsPressed)
            .GetAbsMouseState(_iMouseAbsX, _iMouseAbsY)
            .GetMouseState(_iMouseX, _iMouseY, _bIsMousePressed(1), _bIsMousePressed(2), _bIsMousePressed(3), _bIsMousePressed(4), _iIsScroll)
        End With

        ' Msgbox the keypress
        For i As Integer = 0 To 255
            'If WasPressed(i) Then MsgBox("Key: " & i)
        Next

        ' Double keys       
        If IsPressed(_iShiftLeft) Then bShift = True
        If IsPressed(_iShiftRight) Then bShift = True
        If IsPressed(_iAltLeft) Then bAlt = True
        If IsPressed(_iAltRight) Then bAlt = True
        If IsPressed(_iCtrlLeft) Then bCtrl = True
        If IsPressed(_iCtrlRight) Then bCtrl = True

        ' Quit
        If IsPressed(_iQuit) = True Then eStatus = EnumStatus.StatusQuit

        ' Camera movement
        If IsPressed(_iCameraForward) Then cCamera.MoveForward(1, bShift)
        If IsPressed(_iCameraBackward) Then cCamera.MoveForward(-1, bShift)
        If IsPressed(_iCameraLeft) Then cCamera.MoveRight(-1, bShift)
        If IsPressed(_iCameraRight) Then cCamera.MoveRight(1, bShift)
        If IsPressed(_iCameraUp) Then cCamera.MoveUp(1, bShift)
        If IsPressed(_iCameraDown) Then cCamera.MoveUp(-1, bShift)

        ' Mouse Scroll: Camera distance from target
        cCamera.Zoom(GetMouseScroll, bShift)

        ' Mouse B1
        If _bIsMousePressed(1) Then

            ' Check if we were allready pressing button
            If WasMousePressed(1) = False Then

                ' This is a fist mouse click
                ' Event: MouseDown

            Else

                ' Mouse was all ready pressed, user is holding mouse button
                ' Event: MouseStillDown

            End If

        Else

            ' Check if its a mouse release
            If WasMousePressed(1) Then

                ' User released the mouse button
                ' Event : MouseUp

            Else

                ' Mouse button was already up
                ' Event: No event here

            End If

        ' Camera rotate
        If _bIsMousePressed(2) Then cCamera.Rotate(_iMouseY, _iMouseX)

    End Sub
End Class
Logged

Raine
Customers
Community Member
*****
Posts: 1190


« Reply #2 on: September 28, 2007, 10:01:16 AM »

Thanks Vincent, I'm actually using the method similarly. Seeing as the problem is not reproduceable, there must be something else behaving oddily Tongue
Logged

SylvainTV
Administrator
Community Member
*****
Posts: 4479


WWW
« Reply #3 on: September 28, 2007, 10:38:06 AM »

On the engine side, there is really nothing that would freeze :

void CTVInputEngine::GetKeyPressedArray(byte* pKeyArray255Elements)
{
   if(pKeyArray255Elements)
   {
      memcpy(pKeyArray255Elements, gKeyboardState, 255);
   }
}

unless you don't have initialized the input engine maybe.
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
Raine
Customers
Community Member
*****
Posts: 1190


« Reply #4 on: September 28, 2007, 12:06:22 PM »

I was passing a wrong-sized array. When I passed a 256-elements array it worked fine. Something you might want to consider perhaps?

Fixed anyway! Smiley
Logged

EagleEye
Customers
Community Member
*****
Posts: 321


WWW
« Reply #5 on: October 06, 2007, 02:11:31 AM »

http://wiki.truevision3d.com/tv3d6.5/ctvinputengine

Figured I'd point to that particular wiki page in this topic... Smiley
Logged

Vermund - A Matter of Life and Death MMORPG
My TV Projects - EEGUI (A GUI for TV6.5 with .NET 2005+), Material Editor, tutorials, and more!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks