Thread: [Opentnl-cvs] tnl/zap winJoystick.cpp,NONE,1.1 UIMenus.cpp,1.5,1.6 UIMenus.h,1.3,1.4 ZAP.vcproj,1.4,
Brought to you by:
mark_frohnmayer,
s_alanet
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16447/zap Modified Files: UIMenus.cpp UIMenus.h ZAP.vcproj game.cpp game.h gameNetInterface.cpp main.cpp masterConnection.cpp ship.cpp ship.h Added Files: winJoystick.cpp Log Message: Added controller support dinput rudimentary win32 Fixed bug in netInterface for debug message requests Messed around with some ship movement parameters Other misc stuff. Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** main.cpp 23 Apr 2004 01:49:46 -0000 1.8 --- main.cpp 24 Apr 2004 23:52:33 -0000 1.9 *************** *** 252,255 **** --- 252,257 ---- } + extern void InitController(); + }; *************** *** 357,360 **** --- 359,366 ---- glutIdleFunc(idle); + #ifdef TNL_OS_WIN32 + InitController(); + #endif + glutSetCursor(GLUT_CURSOR_NONE); glMatrixMode(GL_PROJECTION); Index: UIMenus.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIMenus.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** UIMenus.h 23 Apr 2004 08:10:03 -0000 1.3 --- UIMenus.h 24 Apr 2004 23:52:33 -0000 1.4 *************** *** 74,77 **** --- 74,78 ---- static bool controlsRelative; static bool fullscreen; + static bool joystickEnabled; OptionsMenuUserInterface(); Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ZAP.vcproj 23 Apr 2004 08:10:03 -0000 1.4 --- ZAP.vcproj 24 Apr 2004 23:52:33 -0000 1.5 *************** *** 34,38 **** <Tool Name="VCLinkerTool" ! AdditionalDependencies="../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAPd.exe" LinkIncremental="2" --- 34,38 ---- <Tool Name="VCLinkerTool" ! AdditionalDependencies="../glut/dxguid.lib ../glut/dinput8.lib ../glut/dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAPd.exe" LinkIncremental="2" *************** *** 84,88 **** <Tool Name="VCLinkerTool" ! AdditionalDependencies="../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAP.exe" LinkIncremental="1" --- 84,88 ---- <Tool Name="VCLinkerTool" ! AdditionalDependencies="../glut/dxguid.lib ../glut/dinput8.lib ../glut/dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAP.exe" LinkIncremental="1" *************** *** 283,286 **** --- 283,289 ---- </File> <File + RelativePath=".\winJoystick.cpp"> + </File> + <File RelativePath=".\winmain.cpp"> </File> Index: game.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** game.h 22 Apr 2004 00:35:44 -0000 1.4 --- game.h 24 Apr 2004 23:52:33 -0000 1.5 *************** *** 184,187 **** --- 184,188 ---- extern void endGame(); + #define ZAP_GAME_STRING "ZAP 1.1.1" }; Index: masterConnection.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/masterConnection.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** masterConnection.cpp 23 Apr 2004 08:10:03 -0000 1.5 --- masterConnection.cpp 24 Apr 2004 23:52:33 -0000 1.6 *************** *** 182,186 **** Parent::writeConnectRequest(bstream); ! bstream->writeString("ZAP1.3"); // Game Name if(bstream->writeFlag(mIsGameServer)) { --- 182,186 ---- Parent::writeConnectRequest(bstream); ! bstream->writeString(ZAP_GAME_STRING); // Game Name if(bstream->writeFlag(mIsGameServer)) { --- NEW FILE: winJoystick.cpp --- //----------------------------------------------------------------------------------- // // Torque Network Library - ZAP example multiplayer vector graphics space game // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #define STRICT #define DIRECTINPUT_VERSION 0x0800 #include <windows.h> #include <dinput.h> #include "gameConnection.h" #include "point.h" namespace Zap { BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ); LPDIRECTINPUT8 gDirectInput = NULL; LPDIRECTINPUTDEVICE8 gJoystick = NULL; void InitController() { if(FAILED(DirectInput8Create ( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&gDirectInput, NULL ) ) ) return; if(FAILED(gDirectInput->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ) ) return; if(!gJoystick) return; // since we passed in a NULL window, we don't bother setting the cooperative level. } BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { // Obtain an interface to the enumerated joystick. if(FAILED(gDirectInput->CreateDevice( pdidInstance->guidInstance, &gJoystick, NULL ))) return DIENUM_CONTINUE; return DIENUM_STOP; } void JoystickUpdateMove( Move *theMove ) { DIJOYSTATE2 js; // DInput joystick state if(!gJoystick) return; if(FAILED(gJoystick->Poll() ) ) { HRESULT hr; hr = gJoystick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = gJoystick->Acquire(); return; } // Get the input's device state if(FAILED(gJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &js ) ) ) return; // The device should have been acquired during the Poll() S32 x = js.lX; F32 deadZone = 8192.0f; F32 controls[4]; controls[0] = F32( js.lX ) - 32768.0f; controls[1] = F32( js.lY ) - 32768.0f; controls[2] = F32( js.lRz ) - 32768.0f; controls[3] = F32( js.rglSlider[0] ) - 32768.0f; for(U32 i = 0; i < 4; i++) { if(controls[i] < -deadZone) controls[i] = -(-controls[i] - deadZone) / F32(32768.0f - deadZone); else if(controls[i] > deadZone) controls[i] = (controls[i] - deadZone) / F32(32768.0f - deadZone); else controls[i] = 0; } if(controls[0] < 0) { theMove->left = -controls[0]; theMove->right = 0; } else { theMove->left = 0; theMove->right = controls[0]; } if(controls[1] < 0) { theMove->up = -controls[1]; theMove->down = 0; } else { theMove->down = controls[1]; theMove->up = 0; } Point p(controls[2], controls[3]); if(p.len() > 0.1) { theMove->angle = atan2(p.x, p.y); theMove->fire = true; } else theMove->fire = false; } void FreeDirectInput() { // Unacquire the device one last time just in case // the app tried to exit while the device is still acquired. if( gJoystick ) gJoystick->Unacquire(); // Release any DirectInput objects. if(gJoystick) gJoystick->Release(); if(gDirectInput) gDirectInput->Release(); } }; Index: ship.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ship.h 23 Apr 2004 01:49:46 -0000 1.4 --- ship.h 24 Apr 2004 23:52:33 -0000 1.5 *************** *** 39,44 **** public: enum { ! MaxVelocity = 500, // points per second ! Acceleration = 800, // points per second per second InterpMaxVelocity = 900, // velocity to use to interpolate to proper position InterpAcceleration = 1800, --- 39,44 ---- public: enum { ! MaxVelocity = 400, // points per second ! Acceleration = 3000, // points per second per second InterpMaxVelocity = 900, // velocity to use to interpolate to proper position InterpAcceleration = 1800, Index: UIMenus.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIMenus.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** UIMenus.cpp 23 Apr 2004 08:10:03 -0000 1.5 --- UIMenus.cpp 24 Apr 2004 23:52:33 -0000 1.6 *************** *** 168,171 **** --- 168,172 ---- bool OptionsMenuUserInterface::controlsRelative = false; bool OptionsMenuUserInterface::fullscreen = false; + bool OptionsMenuUserInterface::joystickEnabled = false; OptionsMenuUserInterface::OptionsMenuUserInterface() *************** *** 194,197 **** --- 195,203 ---- menuItems.push_back("SET FULLSCREEN MODE"); + if(joystickEnabled) + menuItems.push_back("DISABLE JOYSTICK/CONTROLLER"); + else + menuItems.push_back("ENABLE JOYSTICK/CONTROLLER"); + if(gClientGame->getConnectionToServer()) menuItems.push_back("RETURN TO GAME"); *************** *** 238,241 **** --- 244,250 ---- break; case 2: + joystickEnabled = !joystickEnabled; + break; + case 3: if(gClientGame->getConnectionToServer()) gGameUserInterface.activate(); Index: gameNetInterface.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameNetInterface.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gameNetInterface.cpp 20 Apr 2004 04:27:20 -0000 1.1 --- gameNetInterface.cpp 24 Apr 2004 23:52:33 -0000 1.2 *************** *** 48,51 **** --- 48,56 ---- Nonce clientNonce; clientNonce.read(stream); + char string[256]; + stream->readString(string); + if(strcmp(string, ZAP_GAME_STRING)) + break; + U32 token = computeClientIdentityToken(remoteAddress, clientNonce); PacketStream pingResponse; *************** *** 108,111 **** --- 113,117 ---- packet.write(U8(Ping)); clientNonce.write(&packet); + packet.writeString(ZAP_GAME_STRING); packet.sendto(mSocket, theAddress); } Index: game.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** game.cpp 22 Apr 2004 00:35:43 -0000 1.6 --- game.cpp 24 Apr 2004 23:52:33 -0000 1.7 *************** *** 38,41 **** --- 38,42 ---- #include "ship.h" #include "UIGame.h" + #include "UIMenus.h" #include "SweptEllipsoid.h" #include "sparkManager.h" *************** *** 95,98 **** --- 96,101 ---- if(!mConnectionToMaster.isValid()) { + if(gMasterAddress == Address()) + return; if(mNextMasterTryTime < timeDelta) { *************** *** 246,249 **** --- 249,254 ---- } + extern void JoystickUpdateMove( Move *theMove ); + void ClientGame::idle(U32 timeDelta) { *************** *** 257,260 **** --- 262,270 ---- Move *theMove = gGameUserInterface.getCurrentMove(); + + #ifdef TNL_OS_WIN32 + if(OptionsMenuUserInterface::joystickEnabled) + JoystickUpdateMove(theMove); + #endif theMove->prepare(); Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ship.cpp 23 Apr 2004 08:10:03 -0000 1.10 --- ship.cpp 24 Apr 2004 23:52:33 -0000 1.11 *************** *** 139,143 **** lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); ! Point projVel = mMoveState[ActualState].vel + dir * 500; Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * (CollisionRadius-1), projVel, 1000, this); proj->addToGame(getGame()); --- 139,143 ---- lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); ! Point projVel = dir * 600 + dir * mMoveState[ActualState].vel.dot(dir); //mMoveState[ActualState].vel + dir * 500; Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * (CollisionRadius-1), projVel, 1000, this); proj->addToGame(getGame()); *************** *** 181,256 **** lastMove.time = deltaT; processMove(&lastMove, ActualState); if(interpTime) { ! mMoveState[RenderState].angle = mMoveState[ActualState].angle; ! float time = deltaT * 0.001; ! Point deltap = mMoveState[ActualState].pos - ! mMoveState[RenderState].pos; ! Point requestVel = deltap; ! requestVel *= 1 / time; ! float requestVelLen = deltap.len(); ! bool hit = false; ! if(requestVelLen > InterpMaxVelocity) ! { ! hit = false; ! requestVel.normalize(InterpMaxVelocity); ! } ! ! Point velDelta = requestVel - mMoveState[RenderState].vel; ! F32 accRequested = velDelta.len(); ! F32 maxAccel = InterpAcceleration * time; ! if(accRequested > maxAccel) { hit = false; ! velDelta *= maxAccel / accRequested; ! mMoveState[RenderState].vel += velDelta; ! } ! else ! mMoveState[RenderState].vel = requestVel; ! if(hit) ! { ! interpTime = 0; ! mMoveState[RenderState] = mMoveState[ActualState]; } ! else ! mMoveState[RenderState].pos += mMoveState[RenderState].vel * time; ! } ! else ! mMoveState[RenderState] = mMoveState[ActualState]; ! /* ! ! U32 timeUsed = deltaT; ! if(interpTime) ! { ! if(interpTime < timeUsed) { ! timeUsed -= interpTime; ! interpTime = 0; ! mMoveState[RenderState] = mMoveState[ActualState]; } - else - { - Point totalDelta = mMoveState[ActualState].pos - - mMoveState[RenderState].pos; ! mMoveState[RenderState].pos += ! totalDelta * (timeUsed / F32(interpTime)); ! interpTime -= timeUsed; ! timeUsed = 0; ! } } ! ! if(timeUsed) { ! lastMove.time = timeUsed; ! processMove(&lastMove, ActualState); mMoveState[RenderState] = mMoveState[ActualState]; ! }*/ updateExtent(); --- 181,240 ---- lastMove.time = deltaT; processMove(&lastMove, ActualState); + mMoveState[RenderState].angle = mMoveState[ActualState].angle; if(interpTime) { ! // first step is to constrain the render velocity to ! // the vector of difference between the current position and ! // the actual position. ! // we can also clamp to zero, the actual velocity, or the ! // render velocity, depending on which one is best. ! Point deltaP = mMoveState[ActualState].pos - mMoveState[RenderState].pos; ! F32 distance = deltaP.len(); ! if(!distance) ! goto interpDone; ! deltaP.normalize(); ! F32 vel = deltaP.dot(mMoveState[RenderState].vel); ! F32 avel = deltaP.dot(mMoveState[ActualState].vel); ! if(avel > vel) ! vel = avel; ! if(vel < 0) ! vel = 0; ! ! bool hit = true; ! float time = deltaT * 0.001; ! if(vel * time > distance) ! goto interpDone; ! ! float requestVel = distance / time; ! if(requestVel > InterpMaxVelocity) { hit = false; ! requestVel = InterpMaxVelocity; } ! F32 a = (requestVel - vel) / time; ! if(a > InterpAcceleration) { ! a = InterpAcceleration; ! hit = false; } ! if(hit) ! goto interpDone; ! vel += a * time; ! mMoveState[RenderState].vel = deltaP * vel; ! mMoveState[RenderState].pos += mMoveState[RenderState].vel * time; } ! else { ! interpDone: ! interpTime = 0; mMoveState[RenderState] = mMoveState[ActualState]; ! } updateExtent(); *************** *** 396,400 **** { interpTime = InterpMS; ! mMoveState[RenderState].vel = mMoveState[ActualState].vel; } else --- 380,385 ---- { interpTime = InterpMS; ! // if the actual velocity is in the direction of the actual position ! // then we'll set it into the render velocity } else |