[Opentnl-cvs] tnl/zap UIMenus.cpp,1.23,1.24 huntersGame.cpp,1.10,1.11 input.cpp,1.1,1.2 input.h,1.1,
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-09-25 01:26:47
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18487/zap Modified Files: UIMenus.cpp huntersGame.cpp input.cpp input.h quickChat.cpp winJoystick.cpp Log Message: Added much improved controller support for circular analog sticks Added D-pad support for menu navigation Added proper rendering and bindings for PS2 dual shock controllers Updated README with correct controls for PS2 and XBox controllers Index: input.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/input.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** input.h 29 Jun 2004 18:52:28 -0000 1.1 --- input.h 25 Sep 2004 01:26:37 -0000 1.2 *************** *** 39,47 **** PS2DualShock, XBoxController, }; ! enum { MaxJoystickAxes = 12, ! MaxJoystickButtons = 12, }; --- 39,63 ---- PS2DualShock, XBoxController, + XBoxControllerOnXBox, }; ! enum ButtonInfo { MaxJoystickAxes = 12, ! MaxJoystickButtons = 14, ! ControllerButton1 = 1 << 0, ! ControllerButton2 = 1 << 1, ! ControllerButton3 = 1 << 2, ! ControllerButton4 = 1 << 3, ! ControllerButton5 = 1 << 4, ! ControllerButton6 = 1 << 5, ! ControllerButtonLeftTrigger = 1 << 6, ! ControllerButtonRightTrigger = 1 << 7, ! ControllerGameButtonCount = 8, ! ControllerButtonStart = 1 << 16, ! ControllerButtonBack = 1 << 17, ! ControllerButtonDPadUp = 1 << 18, ! ControllerButtonDPadDown = 1 << 19, ! ControllerButtonDPadLeft = 1 << 20, ! ControllerButtonDPadRight = 1 << 21, }; Index: UIMenus.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIMenus.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** UIMenus.cpp 6 Aug 2004 00:02:46 -0000 1.23 --- UIMenus.cpp 25 Sep 2004 01:26:37 -0000 1.24 *************** *** 116,120 **** void MenuUserInterface::onSpecialKeyDown(U32 key) { ! if(key == GLUT_KEY_UP || key == GLUT_KEY_LEFT) { selectionIndex--; --- 116,120 ---- void MenuUserInterface::onSpecialKeyDown(U32 key) { ! if(key == GLUT_KEY_UP) { selectionIndex--; *************** *** 131,135 **** UserInterface::playBoop(); } ! else if(key == GLUT_KEY_DOWN || key == GLUT_KEY_RIGHT) { selectionIndex++; --- 131,135 ---- UserInterface::playBoop(); } ! else if(key == GLUT_KEY_DOWN) { selectionIndex++; *************** *** 297,300 **** --- 297,303 ---- menuItems.push_back(MenuItem("INPUT: XBOX CONTROLLER USB",2)); break; + case 4: + menuItems.push_back(MenuItem("INPUT: XBOX CONTROLLER",2)); + break; default: menuItems.push_back(MenuItem("INPUT: UNKNOWN",2)); Index: huntersGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/huntersGame.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** huntersGame.cpp 26 Jun 2004 18:07:44 -0000 1.10 --- huntersGame.cpp 25 Sep 2004 01:26:37 -0000 1.11 *************** *** 175,179 **** U32 minsRemaining = timeLeft / (60000); U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000; ! UserInterface::drawStringf(720, 550, 20, "%02d:%02d", minsRemaining, secsRemaining); } --- 175,180 ---- U32 minsRemaining = timeLeft / (60000); U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000; ! UserInterface::drawStringf(UserInterface::canvasWidth - UserInterface::horizMargin - 65, ! UserInterface::canvasHeight - UserInterface::vertMargin - 45, 20, "%02d:%02d", minsRemaining, secsRemaining); } Index: quickChat.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/quickChat.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** quickChat.cpp 28 Jul 2004 23:01:31 -0000 1.15 --- quickChat.cpp 25 Sep 2004 01:26:37 -0000 1.16 *************** *** 31,34 **** --- 31,35 ---- #include "UIMenus.h" #include "gameObjectRender.h" + #include "input.h" #include <ctype.h> namespace Zap *************** *** 106,110 **** if(joy == -1) UserInterface::drawStringf(x, y, 15, "%c", keyIndex); ! else if(joy == 0) { glColor3f(1,1,1); --- 107,111 ---- if(joy == -1) UserInterface::drawStringf(x, y, 15, "%c", keyIndex); ! else if(joy == LogitechWingman) { glColor3f(1,1,1); *************** *** 113,117 **** UserInterface::drawStringf(x + 4, y + 2, 12, "%c", buttons[buttonIndex]); } ! else if(joy == 1) { glColor3f(1,1,1); --- 114,118 ---- UserInterface::drawStringf(x + 4, y + 2, 12, "%c", buttons[buttonIndex]); } ! else if(joy == SaitekDualAnalog) { glColor3f(1,1,1); *************** *** 120,135 **** UserInterface::drawStringf(x + 4, y + 2, 12, "%c", buttons[buttonIndex]); } ! else if(joy == 2) { ! UserInterface::drawStringf(x, y, 15, "%c", buttonIndex + '1'); } ! else if(joy == 3) { ! static F32 color[6][3] = { { 0, 0, 1 }, { 0, 1, 0 }, { 1, 1, 1 }, { 1, 1, 0 }, { 1, 0, 0}, { 0, 0, 0} }; Color c(color[buttonIndex][0], color[buttonIndex][1], color[buttonIndex][2]); glColor(c * 0.8f); fillCircle(Point(x + 8, y + 8), 8); ! const char buttons[] = "XA YB "; glColor3f(1,1,1); drawCircle(Point(x + 8, y + 8), 8); --- 121,195 ---- UserInterface::drawStringf(x + 4, y + 2, 12, "%c", buttons[buttonIndex]); } ! else if(joy == PS2DualShock) { ! static F32 color[6][3] = { { 0.5, 0.5, 1 }, ! { 1, 0.5, 0.5 }, ! { 1, 0.5, 1 }, ! { 0.5, 1, 0.5 }, ! { 0.7, 0.7, 0.7 }, ! { 0.7, 0.7, 0.7 } ! }; ! Color c(color[buttonIndex][0], color[buttonIndex][1], color[buttonIndex][2]); ! glColor3f(1.0, 1.0, 1.0); ! Point center(x + 8, y + 8); ! if(buttonIndex < 4) ! { ! drawCircle(center, 8); ! glColor(c); ! switch(buttonIndex) ! { ! case 0: ! glBegin(GL_LINES); ! glVertex(center + Point(-5, -5)); ! glVertex(center + Point(5, 5)); ! glVertex(center + Point(-5, 5)); ! glVertex(center + Point(5, -5)); ! glEnd(); ! break; ! case 1: ! drawCircle(center, 5); ! break; ! case 2: ! glBegin(GL_LINE_LOOP); ! glVertex(center + Point(-5, -5)); ! glVertex(center + Point(-5, 5)); ! glVertex(center + Point(5, 5)); ! glVertex(center + Point(5, -5)); ! glEnd(); ! break; ! case 3: ! glBegin(GL_LINE_LOOP); ! glVertex(center + Point(0, -5)); ! glVertex(center + Point(5, 3)); ! glVertex(center + Point(-5, 3)); ! glEnd(); ! break; ! } ! } ! else ! { ! glBegin(GL_LINE_LOOP); ! glVertex(center + Point(-8, -8)); ! glVertex(center + Point(-8, 8)); ! glVertex(center + Point(10, 8)); ! glVertex(center + Point(10, -8)); ! glEnd(); ! ! UserInterface::drawString(x + 2, y + 2, 11, buttonIndex == 4 ? "L2" : "R2"); ! } } ! else if(joy == XBoxController || joy == XBoxControllerOnXBox) { ! static F32 color[6][3] = { { 0, 1, 0 }, ! { 1, 0, 0 }, ! { 0, 0, 1 }, ! { 1, 1, 0 }, ! { 1, 1, 1 }, ! { 0, 0, 0} }; Color c(color[buttonIndex][0], color[buttonIndex][1], color[buttonIndex][2]); glColor(c * 0.8f); fillCircle(Point(x + 8, y + 8), 8); ! const char buttons[] = "ABXY "; glColor3f(1,1,1); drawCircle(Point(x + 8, y + 8), 8); Index: input.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/input.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** input.cpp 29 Jun 2004 18:52:28 -0000 1.1 --- input.cpp 25 Sep 2004 01:26:37 -0000 1.2 *************** *** 31,34 **** --- 31,35 ---- #include "tnlJournal.h" #include <math.h> + #include "glutInclude.h" namespace Zap *************** *** 47,50 **** --- 48,74 ---- controls[0] = axes[0]; controls[1] = axes[1]; + + // xbox control inputs are in a circle, not a square, which makes + // diagonal movement inputs "slower" + if(OptionsMenuUserInterface::joystickType == XBoxController || + OptionsMenuUserInterface::joystickType == XBoxControllerOnXBox) + { + Point dir(controls[0], controls[1]); + F32 absX = fabs(dir.x); + F32 absY = fabs(dir.y); + + // push out to the edge of the square (-1,-1 -> 1,1 ) + + F32 dirLen = dir.len() * 1.25; + if(dirLen > 1) + dirLen = 1; + + if(absX > absY) + dir *= F32(dirLen / absX); + else + dir *= F32(dirLen / absY); + controls[0] = dir.x; + controls[1] = dir.y; + } switch(OptionsMenuUserInterface::joystickType) { *************** *** 62,65 **** --- 86,90 ---- break; case XBoxController: + case XBoxControllerOnXBox: controls[2] = axes[3]; controls[3] = axes[4]; *************** *** 109,132 **** theMove->fire = false; // Remap crazy xbox inputs... ! if(OptionsMenuUserInterface::joystickType == XBoxController) { U32 retMask = 0; ! if(buttonMask & BIT(2)) ! retMask |= BIT(0); ! if(buttonMask & BIT(0)) ! retMask |= BIT(1); ! if(buttonMask & BIT(5)) ! retMask |= BIT(2); ! if(buttonMask & BIT(3)) ! retMask |= BIT(3); ! if(buttonMask & BIT(1)) ! retMask |= BIT(4); ! if(buttonMask & BIT(4)) ! retMask |= BIT(5); ! if(buttonMask & BIT(10)) ! retMask |= BIT(6); ! if(buttonMask & BIT(11)) ! retMask |= BIT(7); buttonMask = retMask; } --- 134,189 ---- theMove->fire = false; + // Remap crazy xbox inputs... ! if(OptionsMenuUserInterface::joystickType == LogitechWingman) ! { ! if(buttonMask & (1 << 8)) ! { ! buttonMask |= ControllerButtonBack; ! buttonMask &= ~(1 << 8); ! } ! } ! else if(OptionsMenuUserInterface::joystickType == PS2DualShock) { + static U32 retMasks[12] = { + ControllerButton4, + ControllerButton2, + ControllerButton1, + ControllerButton3, + ControllerButton5, + ControllerButton6, + ControllerButtonLeftTrigger, + ControllerButtonRightTrigger, + ControllerButtonBack, + 0, + ControllerButton1, + ControllerButtonStart, + }; U32 retMask = 0; ! for(S32 i = 0; i < 12; i++) ! if(buttonMask & (1 << i)) ! retMask |= retMasks[i]; ! buttonMask = retMask; ! } ! else if(OptionsMenuUserInterface::joystickType == XBoxController) ! { ! static U32 retMasks[12] = { ! ControllerButton1, ! ControllerButton2, ! ControllerButton3, ! ControllerButton4, ! ControllerButton6, ! ControllerButton5, ! ControllerButtonStart, ! ControllerButtonBack, ! 0, ! ControllerButton1, ! ControllerButtonLeftTrigger, ! ControllerButtonRightTrigger, ! }; ! U32 retMask = 0; ! for(S32 i = 0; i < 12; i++) ! if(buttonMask & (1 << i)) ! retMask |= retMasks[i]; buttonMask = retMask; } *************** *** 172,184 **** return; ! for(U32 i = 0; i < MaxJoystickButtons; i++) { U32 mask = 1 << i; ! if(buttonsPressed & ~lastButtonsPressed & mask) UserInterface::current->onControllerButtonDown(i); ! else if(~buttonsPressed & lastButtonsPressed & mask) UserInterface::current->onControllerButtonUp(i); } ! lastButtonsPressed = buttonsPressed; } --- 229,269 ---- return; ! U32 buttonDown = buttonsPressed & ~lastButtonsPressed; ! U32 buttonUp = ~buttonsPressed & lastButtonsPressed; ! lastButtonsPressed = buttonsPressed; ! ! for(U32 i = 0; i < ControllerGameButtonCount; i++) { U32 mask = 1 << i; ! if(buttonDown & mask) UserInterface::current->onControllerButtonDown(i); ! else if(buttonUp & mask) UserInterface::current->onControllerButtonUp(i); } ! if(buttonDown & ControllerButtonStart) ! UserInterface::current->onKeyDown('\r'); ! if(buttonDown & ControllerButtonBack) ! UserInterface::current->onKeyDown(27); ! if(buttonDown & ControllerButtonDPadUp) ! UserInterface::current->onSpecialKeyDown(GLUT_KEY_UP); ! if(buttonDown & ControllerButtonDPadDown) ! UserInterface::current->onSpecialKeyDown(GLUT_KEY_DOWN); ! if(buttonDown & ControllerButtonDPadLeft) ! UserInterface::current->onSpecialKeyDown(GLUT_KEY_LEFT); ! if(buttonDown & ControllerButtonDPadRight) ! UserInterface::current->onSpecialKeyDown(GLUT_KEY_RIGHT); ! ! if(buttonUp & ControllerButtonStart) ! UserInterface::current->onKeyUp('\r'); ! if(buttonUp & ControllerButtonBack) ! UserInterface::current->onKeyUp(27); ! if(buttonUp & ControllerButtonDPadUp) ! UserInterface::current->onSpecialKeyUp(GLUT_KEY_UP); ! if(buttonUp & ControllerButtonDPadDown) ! UserInterface::current->onSpecialKeyUp(GLUT_KEY_DOWN); ! if(buttonUp & ControllerButtonDPadLeft) ! UserInterface::current->onSpecialKeyUp(GLUT_KEY_LEFT); ! if(buttonUp & ControllerButtonDPadRight) ! UserInterface::current->onSpecialKeyUp(GLUT_KEY_RIGHT); } Index: winJoystick.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/winJoystick.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** winJoystick.cpp 29 Jun 2004 18:52:28 -0000 1.18 --- winJoystick.cpp 25 Sep 2004 01:26:37 -0000 1.19 *************** *** 150,154 **** return false; // The device should have been acquired during the Poll() ! F32 scale = 1 / 32768.0f; axes[0] = (F32(js.lX) - 32768.0f) * scale; axes[1] = (F32(js.lY) - 32768.0f) * scale; --- 150,154 ---- return false; // The device should have been acquired during the Poll() ! F32 scale = 1.15 / 32768.0f; axes[0] = (F32(js.lX) - 32768.0f) * scale; axes[1] = (F32(js.lY) - 32768.0f) * scale; *************** *** 163,173 **** --- 163,214 ---- axes[10] = 0; axes[11] = 0; + for(S32 i = 0; i < 12; i++) + { + if(axes[i] > 1) + axes[i] = 1; + if(axes[i] < -1) + axes[i] = -1; + } // check the state of the buttons: buttonMask = 0; + U32 pov = js.rgdwPOV[0]; for( U32 i = 0; i < 12; i++ ) + { if((js.rgbButtons[i] & 0x80) != 0) + { + logprintf("Button down %d", i); buttonMask |= BIT(i); + } + } + + switch(pov) + { + case 0: + buttonMask |= ControllerButtonDPadUp; + break; + case 4500: + buttonMask |= ControllerButtonDPadUp | ControllerButtonDPadRight; + break; + case 9000: + buttonMask |= ControllerButtonDPadRight; + break; + case 13500: + buttonMask |= ControllerButtonDPadRight | ControllerButtonDPadDown; + break; + case 18000: + buttonMask |= ControllerButtonDPadDown; + break; + case 22500: + buttonMask |= ControllerButtonDPadDown | ControllerButtonDPadLeft; + break; + case 27000: + buttonMask |= ControllerButtonDPadLeft; + break; + case 31500: + buttonMask |= ControllerButtonDPadLeft | ControllerButtonDPadUp; + break; + } return true; } |