Fixed player ship going sometimes crazy when switching to mouse control. Note: This fix is for the SDL builds only, not sure if Mac has a similar mouse control issue.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4585 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Nikos Barkas 2011-07-21 15:11:38 +00:00
parent af3e049cbc
commit 22bbc946c6
3 changed files with 31 additions and 17 deletions

View File

@ -532,6 +532,9 @@ static NSTimeInterval time_last_frame;
/* Ensure the keyboard pitch override (intended to lock
out the joystick if the player runs to the keyboard)
is reset */
#if OOLITE_GNUSTEP
[gameView resetMouse];
#endif
mouse_x_axis_map_to_yaw = [gameView isCtrlDown];
keyboardRollOverride = mouse_x_axis_map_to_yaw; // Getafix: set keyboardRollOverride to TRUE only if yaw is mapped to mouse x-axis
keyboardPitchOverride = NO;

View File

@ -109,6 +109,8 @@ extern int debug;
BOOL m_glContextInitialized;
NSPoint mouseDragStartPoint;
BOOL mouseWarped;
NSTimeInterval timeIntervalAtLastClick;
BOOL doubleClick;
@ -211,6 +213,7 @@ extern int debug;
- (void) clearKeys;
- (void) clearMouse;
- (void) clearKey: (int)theKey;
- (void) resetMouse;
- (BOOL) isAlphabetKeyDown;
- (void) supressKeysUntilKeyUp; // DJS
- (BOOL) isDown: (int) key;

View File

@ -225,6 +225,7 @@ MA 02110-1301, USA.
[self autoShowMouse];
virtualJoystickPosition = NSMakePoint(0.0,0.0);
mouseWarped = NO;
typedString = [[NSMutableString alloc] initWithString:@""];
allowingStringInput = gvStringInputNo;
@ -1055,6 +1056,17 @@ MA 02110-1301, USA.
}
- (void) resetMouse
{
[self setVirtualJoystick:0.0 :0.0];
if ([[PlayerEntity sharedPlayer] isMouseControlOn])
{
SDL_WarpMouse([self viewSize].width / 2, [self viewSize].height / 2);
mouseWarped = YES;
}
}
- (BOOL) isAlphabetKeyDown
{
return isAlphabetKeyDown = NO;;
@ -1163,12 +1175,6 @@ MA 02110-1301, USA.
SDL_MouseMotionEvent *mmove_event;
int mxdelta, mydelta;
// This static variable is quite important as far as mouse control is concerned. When we reset
// the virtual joystick (mouse) coordinates, we need to send a WarpMouse call because we must
// recenter the pointer physically on screen. This goes together with a mouse motion event, so
// we use sMouseWarped to simply ignore handling of motion events in this case.
static BOOL sMouseWarped = NO;
while (SDL_PollEvent(&event))
{
switch (event.type) {
@ -1188,12 +1194,13 @@ MA 02110-1301, USA.
break;
case SDL_BUTTON_RIGHT:
// Cocoa version does this in the GameController
[self setVirtualJoystick:0.0 :0.0];
if ([[PlayerEntity sharedPlayer] isMouseControlOn])
{
SDL_WarpMouse([self viewSize].width / 2, [self viewSize].height / 2);
sMouseWarped = YES;
}
/*
The mouseWarped variable is quite important as far as mouse control is concerned. When we
reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call because we
must recenter the pointer physically on screen. This goes together with a mouse motion event,
so we use mouseWarped to simply ignore handling of motion events in this case. - Nikos 20110721
*/
[self resetMouse]; // Will set mouseWarped to YES
}
break;
@ -1228,7 +1235,8 @@ MA 02110-1301, USA.
SDL_GetRelativeMouseState(&mxdelta, &mydelta);
double mxd=(double)mxdelta / MOUSE_VIRTSTICKSENSITIVITY;
double myd=(double)mydelta / MOUSE_VIRTSTICKSENSITIVITY;
if (!sMouseWarped) // Standard event, update coordinates
if (!mouseWarped) // Standard event, update coordinates
{
virtualJoystickPosition.x += mxd;
virtualJoystickPosition.y += myd;
@ -1246,8 +1254,8 @@ MA 02110-1301, USA.
else
{
// Motion event generated by WarpMouse is ignored and
// we reset sMouseWarped for the next time.
sMouseWarped = NO;
// we reset mouseWarped for the next time.
mouseWarped = NO;
}
}
else
@ -1260,7 +1268,7 @@ MA 02110-1301, USA.
int w=bounds.size.width;
int h=bounds.size.height;
if (!sMouseWarped) // standard evemt, handle it
if (!mouseWarped) // standard evemt, handle it
{
double mx = mmove_event->x - w/2.0;
double my = mmove_event->y - h/2.0;
@ -1280,7 +1288,7 @@ MA 02110-1301, USA.
else
{
// event coming from WarpMouse ignored, get ready for the next
sMouseWarped = NO;
mouseWarped = NO;
}
}
break;