Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Pages: [1] 2

Author Topic: Issues with OIS Mouse (bug?), Found the bug!  (Read 4985 times)

Entelin

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 13
    • View Profile
Issues with OIS Mouse (bug?), Found the bug!
« on: April 18, 2008, 01:30:32 PM »

Relative mouse movement seems to work incorrectly. In all of the ogre samples, as well as in my own code I have observed that mouse motion becomes slower as the fps goes down, eventually becoming almost completely dysfunctional at very low fps (10 or less). It doesn't seem to capture all of the motion of the mouse between capture calls. This effect can be easily seen using the ogre crowd demo, move the mouse around, scale up the instances until you have a low fps and observe the mouse moving slower as the fps decreases. I see this issue in both windows and linux. However I also have apps that use SDL for mouse motion, and they have no such issues.

Anyone looked into this yet? I figure it must be something that many people are encountering if they use ois for movement?
« Last Edit: May 03, 2008, 11:48:48 AM by entelin »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Issues with OIS Mouse (bug?)
« Reply #1 on: April 18, 2008, 03:13:26 PM »

I assume this is under Windows? Try increasing the buffer size of the DirectInput mouse (win32/Win32Prereqs.h). Also, make sure you are not returning false in any circumstance (unless you specifically know the consequence of what you want there) from any mouse event callback.
Logged

Entelin

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 13
    • View Profile
Re: Issues with OIS Mouse (bug?)
« Reply #2 on: April 18, 2008, 06:48:51 PM »

As I mentioned in my post  "I see this issue in both windows and linux".
Logged

OvermindDL1

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 288
    • View Profile
    • http://www.overminddl1.com/forum/
Re: Issues with OIS Mouse (bug?)
« Reply #3 on: April 20, 2008, 10:40:32 AM »

I am pretty certain that is due to the design of ExampleFrameListener.h as I never had those issues, and my input design was vastly different.  It has also been stated all over the Ogre3D website to *not* use ExampleFrameListener (or any of the other Example*.h files) as a base for any real project.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Issues with OIS Mouse (bug?)
« Reply #4 on: April 20, 2008, 01:31:17 PM »

You never stated if you tried increasing the buffer size. It may or may not help your problem, but is worth trying. As for Linux, there is no reason for lost mouse values, as the buffer is handled entirely from X11 side of things. i suggest for Linux, unhide the mouse during creation, and dump the values out to a console so you can see the real mouse, your fake mouse cursor, and what values are being reported.. Then, you will determine what the issue is you are seeing since you will clearly know what values you are seeing, and when the cursor starts behaving weird.
Logged

Entelin

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 13
    • View Profile
Re: Issues with OIS Mouse (bug?)
« Reply #5 on: April 26, 2008, 12:55:47 PM »

I tried it out with the OIS console app as well now, same issue. By default the console app is running at thousands of fps with only a usleep of 500. Now if you increase that to bring the fps down lower into the 60fps or lower range you will see that where as before it only took a flick of the wrist to move the mouse from 0,0 to 100,100 now it takes much much more mouse movement and time to get across the screen. So in a game that might fluctuate in fps depending on the complexity of the scene that becomes a real problem, especially under 60fps where the mouse almost stops working completely.

As I mentioned previously, I have an sdl game I wrote that just does 2d graphics and I can scale the fps from 5 to 180 and the mouse (though skippy at low fps) will move the same overall speed.
« Last Edit: April 26, 2008, 12:59:44 PM by entelin »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Issues with OIS Mouse (bug?)
« Reply #6 on: April 27, 2008, 07:49:39 AM »

OIS simply gets X11 events and totals relative motion values to send out to apps. The speed at which you query OIS should not affect how fast or slow your mouse appears to function, but would affect the smoothness of updates. I have seen little difference between running OIS in the console demo or an Ogre app with low or high FPS. Mouse seems to work the same. However, with higher FPS, means that unless you are scaling your movement updates by time, movement will appear to be that much faster. At least, from what I've seen.

If you seriously think you have found a bug, i would appreciate a patch/fix, unfortunately, I cannot reproduce what you describe. Which is why I suggested earlier that you allow the real OS mouse to be seen, while display values that OIS is returning to you and try to find out where the issue is coming from. Perhaps by adding some more logging inside OIS.
Logged

Entelin

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 13
    • View Profile
Re: Issues with OIS Mouse (bug?)
« Reply #7 on: May 03, 2008, 11:00:09 AM »

I found the issue! :)

Here's the deal, as I mentioned before this issue exists in both linux and windows (I don't have a mac but I assume it would be the same).  I fixed it in linux, I'll leave windows to you guys since I don't know much about it, the issue is in the event processing function, for linux its  void LinuxMouse::_processXEvents() . As the fps falls there are an increasing number of events to frames, in the old code the entire event stack is processed each frame, however the relative motion is calculated each event, rather than each frame resulting in only the very last events relative motion to be passed to the application. This finally results in the mouse becoming slower and slower as the fps drops in the application, and becoming essentially unusable below 30fps. The following code resolves that issue by simply querying the mouse one time each call. Using this code all of the ogre sample apps, the ois console app, and my app :), work perfect at very very low fps, the mouse moves at the same speed if your running at 2fps or 2000fps. To test in any app, or the oisconsole you can increase the usleep/sleep to 500000 instead of just 50 or 500, when moving the mouse you will see that the values change at the same general pace.

void LinuxMouse::_processXEvents()
{
   Window u1; int u2;
   Window current_win;
   int x, y;
   unsigned int mmask;

   if ( XQueryPointer(display, window, &u1, &current_win, &u2, &u2, &x, &y, &mmask) )
      {
      //Ignore out of bounds mouse if we just warped
      if( mWarped && (x < 5 || x > mState.width - 5 || y < 5 || y > mState.height - 5))
         {
         }
      else if (!(oldXMouseX == x && oldXMouseY == y))
         {
         //Compute this frames Relative X & Y motion
         mState.X.rel = x - oldXMouseX;
         mState.Y.rel = y - oldXMouseY;
      
         //Store old values for next time to compute relative motion
         oldXMouseX = x;
         oldXMouseY = y;

         mState.X.abs += mState.X.rel;
         mState.Y.abs += mState.Y.rel;

         //Check to see if we are grabbing the mouse to the window (requires clipping and warping)
         if( grabMouse )
            {
            if( mState.X.abs < 0 )
               mState.X.abs = 0;
            else if( mState.X.abs > mState.width )
               mState.X.abs = mState.width;
   
            if( mState.Y.abs < 0 )
               mState.Y.abs = 0;
            else if( mState.Y.abs > mState.height )
               mState.Y.abs = mState.height;
   
            if( mouseFocusLost == false )
               {
               //Keep mouse in window (fudge factor)
               if(x < 5 || x > mState.width - 5 ||
                  y < 5 || y > mState.height - 5 )
                  {
                  oldXMouseX = mState.width >> 1;  //center x
                  oldXMouseY = mState.height >> 1; //center y
                  XWarpPointer(display, None, window, 0, 0, 0, 0, oldXMouseX, oldXMouseY);
                  mWarped = true;
                  }
               }
            }
         mMoved = true;
         }
      }

   //X11 Button Events: 1=left 2=middle 3=right; Our Bit Postion: 1=Left 2=Right 3=Middle
   char mask[4] = {0,1,4,2};
   XEvent event;

   //Poll x11 for events mouse events
   while( XPending(display) > 0 )
   {
      XNextEvent(display, &event);

      //if( event.type == MotionNotify )
      //{   //Mouse moved
      //}
      if( event.type == ButtonPress )
      {   //Button down
         static_cast<LinuxInputManager*>(mCreator)->_setGrabState(true);

         if( event.xbutton.button < 4 )
         {
            mState.buttons |= mask[event.xbutton.button];
            if( mBuffered && mListener )
               if( mListener->mousePressed( MouseEvent( this, mState ),
                  (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false )
                  return;
         }
      }
      else if( event.type == ButtonRelease )
      {   //Button up
         if( event.xbutton.button < 4 )
         {
            mState.buttons &= ~mask[event.xbutton.button];
            if( mBuffered && mListener )
               if( mListener->mouseReleased( MouseEvent( this, mState ),
                  (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false )
                  return;
         }
         //The Z axis gets pushed/released pair message (this is up)
         else if( event.xbutton.button == 4 )
         {
            mState.Z.rel += 120;
            mState.Z.abs += 120;
            mMoved = true;
         }
         //The Z axis gets pushed/released pair message (this is down)
         else if( event.xbutton.button == 5 )
         {
            mState.Z.rel -= 120;
            mState.Z.abs -= 120;
            mMoved = true;
         }
      }
   }
}
« Last Edit: April 21, 2010, 12:19:32 AM by Entelin »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #8 on: May 03, 2008, 02:14:11 PM »

Would be easier to see differences/changes if you could submit this as a patch to the sourceforge page.

Thanks for working through this and finding a solution :)
Logged

Entelin

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 13
    • View Profile
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #9 on: May 03, 2008, 03:15:48 PM »

I looked at sourceforge, I can't remember my user/pass. But heres a diff, I don't consider myself a great programmer so please review it yourself. Also remember this issue exists on windows too, I havn't looked at that code but I would assume its the same logical issue. Hopefully being that this is an issue with a core feature of ois we could see an official fix soon.

diff ois/src/linux/LinuxMouse.cpp oisnew/src/linux/LinuxMouse.cpp
155,171c155,164
<       //X11 Button Events: 1=left 2=middle 3=right; Our Bit Postion: 1=Left 2=Right 3=Middle
<       char mask[4] = {0,1,4,2};
<       XEvent event;
<
<       //Poll x11 for events mouse events
<       while( XPending(display) > 0 )
<       {
<               XNextEvent(display, &event);
<
<               if( event.type == MotionNotify )
<               {       //Mouse moved
<                       //Ignore out of bounds mouse if we just warped
<                       if( mWarped )
<                       {
<                               if(event.xmotion.x < 5 || event.xmotion.x > mState.width - 5 ||
<                                  event.xmotion.y < 5 || event.xmotion.y > mState.height - 5)
<                                       continue;
---
>       Window u1; int u2;
>       Window current_win;
>       int x, y;
>       unsigned int mmask;
>
>       if ( XQueryPointer(display, window, &u1, &current_win, &u2, &u2, &x, &y, &mmask) )
>               {
>               //Ignore out of bounds mouse if we just warped
>               if( mWarped && (x < 5 || x > mState.width - 5 || y < 5 || y > mState.height - 5))
>                       {
173c166,167
<
---
>               else if (!(oldXMouseX == x && oldXMouseY == y))
>                       {
175,176c169,170
<                       mState.X.rel = event.xmotion.x - oldXMouseX;
<                       mState.Y.rel = event.xmotion.y - oldXMouseY;
---
>                       mState.X.rel = x - oldXMouseX;
>                       mState.Y.rel = y - oldXMouseY;
179,180c173,174
<                       oldXMouseX = event.xmotion.x;
<                       oldXMouseY = event.xmotion.y;
---
>                       oldXMouseX = x;
>                       oldXMouseY = y;
187c181
<                       {
---
>                               {
192c186
<
---
>
197c191
<
---
>
199,202d192
<                               {
<                                       //Keep mouse in window (fudge factor)
<                                       if(event.xmotion.x < 5 || event.xmotion.x > mState.width - 5 ||
<                                          event.xmotion.y < 5 || event.xmotion.y > mState.height - 5 )
203a194,197
>                                       //Keep mouse in window (fudge factor)
>                                       if(x < 5 || x > mState.width - 5 ||
>                                          y < 5 || y > mState.height - 5 )
>                                               {
207a202
>                                               }
210d204
<                       }
211a206
>                       }
213c208,221
<               else if( event.type == ButtonPress )
---
>
>       //X11 Button Events: 1=left 2=middle 3=right; Our Bit Postion: 1=Left 2=Right 3=Middle
>       char mask[4] = {0,1,4,2};
>       XEvent event;
>
>       //Poll x11 for events mouse events
>       while( XPending(display) > 0 )
>       {
>               XNextEvent(display, &event);
>
>               //if( event.type == MotionNotify )
>               //{     //Mouse moved
>               //}
>               if( event.type == ButtonPress )
Logged

tdev

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 20
    • View Profile
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #10 on: June 01, 2008, 02:38:48 AM »

I looked at sourceforge, I can't remember my user/pass. But heres a diff, I don't consider myself a great programmer so please review it yourself. Also remember this issue exists on windows too, I havn't looked at that code but I would assume its the same logical issue. Hopefully being that this is an issue with a core feature of ois we could see an official fix soon.
i had a look at the patch and it really seems to solve the issues i also experienced. I have cleaned the patch and will submit it to the SF patchtracker for you. Thanks! :)

cleaned it up and submitted:
https://sourceforge.net/tracker/index.php?func=detail&aid=1981254&group_id=149835&atid=775955

seems the bug aso resolved some mouse stuttering issue i had under linux :)
« Last Edit: June 01, 2008, 02:48:55 AM by tdev »
Logged

lonewolff

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 6
    • View Profile
    • Windows game and software programming in C++
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #11 on: October 17, 2008, 08:48:26 PM »

Did this ever get written into the current OIS release?

I had the same problem a while back with OIS so wrote my own basic input system. I would rather use OIS if this has been resolved as my input system is platform locked to Win32.

fame

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 2
    • View Profile
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #12 on: January 18, 2009, 07:54:11 AM »

I tried the patch with Ogre 1.49 but still got a very slow mouse-cursor with low fps.

Did the patch still works with OIS 1.2? What i have to do exactly?


Regards,
fame
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #13 on: January 18, 2009, 10:50:51 AM »

At some point, if you are not calling capture enough, your events will only come in as slow as your FPS. You can try decoupling your mouse input into a different thread to attain a more constant update. Though, this would probably only work best under Windows / and maybe x11.
Logged

fame

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 2
    • View Profile
Re: Issues with OIS Mouse (bug?), Found the bug!
« Reply #14 on: January 19, 2009, 01:36:34 AM »

Ill give that one a try :) Thanks!
Logged
Pages: [1] 2