Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 6:58:23 PM (13 years ago)
Author:
rgrieder
Message:

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/ois/linux/LinuxInputManager.cpp

    r5781 r8284  
    4040        hideMouse = true;
    4141        mGrabs = true;
    42         useXRepeat = false;
    4342        keyboardUsed = mouseUsed = false;
    4443
     
    7473
    7574        //--------- Keyboard Settings ------------//
    76         i = paramList.find("XAutoRepeatOn");
    77         if( i != paramList.end() )
    78                 if( i->second == "true" )
    79                         useXRepeat = true;
    80 
    8175        i = paramList.find("x11_keyboard_grab");
    8276        if( i != paramList.end() )
     
    172166        {
    173167                if( keyboardUsed == false )
    174                         obj = new LinuxKeyboard(this, bufferMode, grabKeyboard, useXRepeat);
     168                        obj = new LinuxKeyboard(this, bufferMode, grabKeyboard);
    175169                break;
    176170        }
  • code/branches/kicklib2/src/external/ois/linux/LinuxInputManager.h

    r5781 r8284  
    101101                bool mGrabs;
    102102                bool hideMouse;
    103 
    104                 //! By default, keyboard disables XRepeatRate
    105                 bool useXRepeat;
    106103        };
    107104}
  • code/branches/kicklib2/src/external/ois/linux/LinuxJoyStickEvents.cpp

    r5781 r8284  
    9696        //We are in non blocking mode - we just read once, and try to fill up buffer
    9797        input_event js[JOY_BUFFERSIZE];
    98         int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
    99         if( ret <= 0 )
    100                 return;
    101 
    102         //Determine how many whole events re read up
    103         ret /= sizeof(struct input_event);
    104         for(int i = 0; i < ret; ++i)
     98        while(true)
    10599        {
    106                 switch(js[i].type)
     100                int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
     101        if( ret < 0 )
     102                        break;
     103
     104                //Determine how many whole events re read up
     105                ret /= sizeof(struct input_event);
     106                for(int i = 0; i < ret; ++i)
    107107                {
    108                 case EV_KEY:  //Button
    109                 {
    110                         int button = mButtonMap[js[i].code];
    111 
    112                         #ifdef OIS_LINUX_JOY_DEBUG
    113                           cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl;
    114                         #endif
    115 
    116                         //Check to see whether push or released event...
    117                         if(js[i].value)
    118                         {
    119                                 mState.mButtons[button] = true;
    120                                 if( mBuffered && mListener )
    121                                         if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return;
    122                         }
    123                         else
    124                         {
    125                                 mState.mButtons[button] = false;
    126                                 if( mBuffered && mListener )
    127                                         if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return;
    128                         }
    129                         break;
    130                 }
    131 
    132                 case EV_ABS:  //Absolute Axis
    133                 {
    134                         //A Stick (BrakeDefine is the highest possible Axis)
    135                         if( js[i].code <= ABS_BRAKE )
    136                         {
    137                                 int axis = mAxisMap[js[i].code];
    138                                 assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" );
    139 
    140                                 axisMoved[axis] = true;
    141 
    142                                 //check for rescaling:
    143                                 if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS )
    144                                 {       //Scale is perfect
    145                                         mState.mAxes[axis].abs = js[i].value;
     108                        switch(js[i].type)
     109                        {
     110                        case EV_KEY:  //Button
     111                        {
     112                                int button = mButtonMap[js[i].code];
     113
     114                                #ifdef OIS_LINUX_JOY_DEBUG
     115                                  cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl;
     116                                #endif
     117
     118                                //Check to see whether push or released event...
     119                                if(js[i].value)
     120                                {
     121                                        mState.mButtons[button] = true;
     122                                        if( mBuffered && mListener )
     123                                                if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return;
    146124                                }
    147125                                else
    148                                 {       //Rescale
    149                                         float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max);
    150                                         mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion));
     126                                {
     127                                        mState.mButtons[button] = false;
     128                                        if( mBuffered && mListener )
     129                                                if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return;
    151130                                }
    152                         }
    153                         else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed
    154                         {
    155                                 //Normalise the POV to between 0-7
    156                                 //Even is X Axis, Odd is Y Axis
    157                                 unsigned char LinuxPovNumber = js[i].code - 16;
    158                                 short OIS_POVIndex = POV_MASK[LinuxPovNumber];
    159 
    160                                 //Handle X Axis first (Even) (left right)
    161                                 if((LinuxPovNumber & 0x0001) == 0)
     131                                break;
     132                        }
     133
     134                        case EV_ABS:  //Absolute Axis
     135                        {
     136                                //A Stick (BrakeDefine is the highest possible Axis)
     137                                if( js[i].code <= ABS_BRAKE )
    162138                                {
    163                                         //Why do this? Because, we use a bit field, and when this axis is east,
    164                                         //it can't possibly be west too. So clear out the two X axes, then refil
    165                                         //it in with the new direction bit.
    166                                         //Clear the East/West Bit Flags first
    167                                         mState.mPOV[OIS_POVIndex].direction &= 0x11110011;
    168                                         if( js[i].value == -1 ) //Left
    169                                                 mState.mPOV[OIS_POVIndex].direction |= Pov::West;
    170                                         else if( js[i].value == 1 ) //Right
    171                                                 mState.mPOV[OIS_POVIndex].direction |= Pov::East;
     139                                        int axis = mAxisMap[js[i].code];
     140                                        assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" );
     141
     142                                        axisMoved[axis] = true;
     143
     144                                        //check for rescaling:
     145                                        if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS )
     146                                        {       //Scale is perfect
     147                                                mState.mAxes[axis].abs = js[i].value;
     148                                        }
     149                                        else
     150                                        {       //Rescale
     151                                                float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max);
     152                                                mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion));
     153                                        }
    172154                                }
    173                                 //Handle Y Axis (Odd) (up down)
    174                                 else
     155                                else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed
    175156                                {
    176                                         //Clear the North/South Bit Flags first
    177                                         mState.mPOV[OIS_POVIndex].direction &= 0x11111100;
    178                                         if( js[i].value == -1 ) //Up
    179                                                 mState.mPOV[OIS_POVIndex].direction |= Pov::North;
    180                                         else if( js[i].value == 1 ) //Down
    181                                                 mState.mPOV[OIS_POVIndex].direction |= Pov::South;
     157                                        //Normalise the POV to between 0-7
     158                                        //Even is X Axis, Odd is Y Axis
     159                                        unsigned char LinuxPovNumber = js[i].code - 16;
     160                                        short OIS_POVIndex = POV_MASK[LinuxPovNumber];
     161
     162                                        //Handle X Axis first (Even) (left right)
     163                                        if((LinuxPovNumber & 0x0001) == 0)
     164                                        {
     165                                                //Why do this? Because, we use a bit field, and when this axis is east,
     166                                                //it can't possibly be west too. So clear out the two X axes, then refil
     167                                                //it in with the new direction bit.
     168                                                //Clear the East/West Bit Flags first
     169                                                mState.mPOV[OIS_POVIndex].direction &= 0x11110011;
     170                                                if( js[i].value == -1 ) //Left
     171                                                        mState.mPOV[OIS_POVIndex].direction |= Pov::West;
     172                                                else if( js[i].value == 1 ) //Right
     173                                                        mState.mPOV[OIS_POVIndex].direction |= Pov::East;
     174                                        }
     175                                        //Handle Y Axis (Odd) (up down)
     176                                        else
     177                                        {
     178                                                //Clear the North/South Bit Flags first
     179                                                mState.mPOV[OIS_POVIndex].direction &= 0x11111100;
     180                                                if( js[i].value == -1 ) //Up
     181                                                        mState.mPOV[OIS_POVIndex].direction |= Pov::North;
     182                                                else if( js[i].value == 1 ) //Down
     183                                                        mState.mPOV[OIS_POVIndex].direction |= Pov::South;
     184                                        }
     185
     186                                        if( mBuffered && mListener )
     187                                                if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false )
     188                                                        return;
    182189                                }
    183 
    184                                 if( mBuffered && mListener )
    185                                         if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false )
    186                                                 return;
    187                         }
    188                         break;
    189                 }
    190 
    191                
    192                 case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?)
    193 #ifdef OIS_LINUX_JOY_DEBUG
    194                     cout << "\nWarning: Relatives axes not supported yet" << endl;
    195 #endif
    196                         break;
    197                 default: break;
     190                                break;
     191                        }
     192
     193                       
     194                        case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?)
     195        #ifdef OIS_LINUX_JOY_DEBUG
     196                                cout << "\nWarning: Relatives axes not supported yet" << endl;
     197        #endif
     198                                break;
     199                        default: break;
     200                        }
    198201                }
    199202        }
  • code/branches/kicklib2/src/external/ois/linux/LinuxKeyboard.cpp

    r5781 r8284  
    3333#include <iostream>
    3434//-------------------------------------------------------------------//
    35 LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat)
     35LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab)
    3636        : Keyboard(creator->inputSystemName(), buffered, 0, creator)
    3737{
     
    4343        grabKeyboard = grab;
    4444        keyFocusLost = false;
    45 
    46         xAutoRepeat = useXRepeat;
    47         oldXAutoRepeat = false;
    4845
    4946        //X Key Map to KeyCode
     
    213210
    214211        keyFocusLost = false;
    215 
    216         if( xAutoRepeat == false )
    217         {
    218                 //We do not want to blindly turn on autorepeat later when quiting if
    219                 //it was not on to begin with.. So, let us check and see first
    220                 XKeyboardState old;
    221                 XGetKeyboardControl( display, &old );
    222                 oldXAutoRepeat = false;
    223 
    224                 if( old.global_auto_repeat == AutoRepeatModeOn )
    225                         oldXAutoRepeat = true;
    226 
    227                 XAutoRepeatOff( display );
    228         }
    229212}
    230213
     
    234217        if( display )
    235218        {
    236                 if( oldXAutoRepeat )
    237                         XAutoRepeatOn(display);
    238 
    239219                if( grabKeyboard )
    240220                        XUngrabKeyboard(display, CurrentTime);
     
    303283
    304284        while( XPending(display) > 0 )
    305         {               XNextEvent(display, &event);            if( KeyPress == event.type )
     285        {
     286                XNextEvent(display, &event);
     287
     288                if(KeyPress == event.type)
    306289                {
    307290                        unsigned int character = 0;
    308291
    309                         if( mTextMode != Off )
     292                        if(mTextMode != Off)
    310293                        {
    311294                                unsigned char buffer[6] = {0,0,0,0,0,0};
     
    332315                        if( event.xkey.state & Mod1Mask && key == XK_Tab )
    333316                                linMan->_setGrabState(false);
    334                 }               else if( KeyRelease == event.type )
     317                }
     318                else if(KeyRelease == event.type)
    335319                {
    336                         //Mask out the modifier states X sets.. or we will get improper values
    337                         event.xkey.state &= ~ShiftMask;
    338                         event.xkey.state &= ~LockMask;
    339 
    340                         //Else, it is a valid key release
    341                         XLookupString(&event.xkey,NULL,0,&key,NULL);
    342                         _injectKeyUp(key);              }
     320                        if(!_isKeyRepeat(event))
     321                        {
     322                                //Mask out the modifier states X sets.. or we will get improper values
     323                                event.xkey.state &= ~ShiftMask;
     324                                event.xkey.state &= ~LockMask;
     325
     326                                XLookupString(&event.xkey,NULL,0,&key,NULL);
     327                                _injectKeyUp(key);
     328                        }
     329                }
    343330        }
    344331
  • code/branches/kicklib2/src/external/ois/linux/LinuxKeyboard.h

    r5781 r8284  
    3434        {
    3535        public:
    36                 LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat );
     36                LinuxKeyboard(InputManager* creator, bool buffered, bool grab);
    3737                virtual ~LinuxKeyboard();
    3838
     
    5959
    6060        protected:
     61                inline bool _isKeyRepeat(XEvent &event)
     62                {
     63                        //When a key is repeated, there will be two events: released, followed by another immediate pressed. So check to see if another pressed is present     
     64                        if(!XPending(display))
     65                                return false;
     66
     67                        XEvent e;
     68                        XPeekEvent(display, &e);
     69                        if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2)
     70                        {
     71                                XNextEvent(display, &e);
     72                                return true;
     73                        }
     74
     75                        return false;
     76                }
     77
    6178                bool _injectKeyDown( KeySym key, int text );
    6279                bool _injectKeyUp( KeySym key );
     
    7592                bool keyFocusLost;
    7693
    77                 bool xAutoRepeat;
    78                 bool oldXAutoRepeat;
    79 
    8094                std::string mGetString;
    8195        };
  • code/branches/kicklib2/src/external/ois/linux/LinuxMouse.cpp

    r5781 r8284  
    173173
    174174                        //Compute this frames Relative X & Y motion
    175                         mState.X.rel = event.xmotion.x - oldXMouseX;
    176                         mState.Y.rel = event.xmotion.y - oldXMouseY;
     175                        int dx = event.xmotion.x - oldXMouseX;
     176                        int dy = event.xmotion.y - oldXMouseY;
    177177               
    178178                        //Store old values for next time to compute relative motion
     
    180180                        oldXMouseY = event.xmotion.y;
    181181
    182                         mState.X.abs += mState.X.rel;
    183                         mState.Y.abs += mState.Y.rel;
     182                        mState.X.abs += dx;
     183                        mState.Y.abs += dy;
     184                        mState.X.rel += dx;
     185                        mState.Y.rel += dy;
    184186
    185187                        //Check to see if we are grabbing the mouse to the window (requires clipping and warping)
  • code/branches/kicklib2/src/external/ois/linux/LinuxPrereqs.h

    r5781 r8284  
    3232
    3333//! Max number of elements to collect from buffered input
    34 #define JOY_BUFFERSIZE 10
     34#define JOY_BUFFERSIZE 64
    3535
    3636namespace OIS
Note: See TracChangeset for help on using the changeset viewer.