## Engine
Class PlayerInput

source: C:\XIII\Engine\Classes\PlayerInput.uc

    Core.Object
       |
       +--Engine.PlayerInput

Direct Known Subclasses:None

class PlayerInput
extends Core.Object

    //=============================================================================
    // PlayerInput
    // Object within playercontroller that manages player input.
    // only spawned on client
    //=============================================================================

Variables
`BorrowedMouseX,` | `BorrowedMouseY` Used to force crouching when going back from flashback
`float` | `CurrentInput` used to accelerate the view rotation
`int` | `CurrentInputAngle` used to accelerate the view rotation
`float` | `CurrentTurnInput` used to accelerate the view rotation
`int` | `CurrentTurnInputAngle` used to accelerate the view rotation
`float` | `DoubleClickTime` Used to force crouching when going back from flashback
`float` | `MouseSensitivity` Used to force crouching when going back from flashback
`float` | `MouseSmoothThreshold` Used to force crouching when going back from flashback
`float` | `MouseZeroTime` Used to force crouching when going back from flashback
`MoveRange,` | `TurnRange` used to accelerate the view rotation
`float` | `ViewTurnAcc` used to accelerate the view rotation
`float` | `ViewTurnBoost` used to accelerate the view rotation
`float` | `ViewUpAcc` used to accelerate the view rotation
`float` | `WeaponViewTurnAcc` used to accelerate the view rotation
`bool` | `bCheckInputRanges` used to accelerate the view rotation
`bool` | `bDuckCheck` Used for the duck SwitchMode
`bool` | `bEdgeBack` used for doubleclick move
`bool` | `bEdgeForward` used for doubleclick move
`bool` | `bEdgeLeft` used for doubleclick move
`bool` | `bEdgeRight` used for doubleclick move
`bool` | `bForceCrouch` Used to force crouching when going back from flashback
`bool` | `bInvertMouse`
`bool` | `bMaxMouseSmoothing`
`bool` | `bUseSnapTimer` Used to force crouching when going back from flashback
`bool` | `bWasBack` used for doubleclick move
`bool` | `bWasForward` used for doubleclick move
`bool` | `bWasLeft` used for doubleclick move
`bool` | `bWasRight` used for doubleclick move
`fInputRange,` | `fPctWalkRun` Used for the duck SwitchMode
`float` | `fSnaptimer` Used for the duck SwitchMode
`int` | `iDuckMem` Used for the duck SwitchMode
`int` | `iMemaLookUpSign` used to accelerate the view rotation
`int` | `iMemaTurnSign` used to accelerate the view rotation

Function Summary
`void` | `ChangeSnapView(bool B)`
    //_____________________________________________________________________________
`void` | `SetMouseSmoothThreshold(float F)`
    //_____________________________________________________________________________
`void` | `SmoothMouse(float aMouse, float MouseTime, out float, out float, out float)`
    /* --> exists now only on C++ side
`void` | `UpdateSensitivity(float F)`
    //_____________________________________________________________________________

Source Code

    00001	//=============================================================================
    00002	// PlayerInput
    00003	// Object within playercontroller that manages player input.
    00004	// only spawned on client
    00005	//=============================================================================
    00006
    00007	class PlayerInput extends Object within PlayerController
    00008	  config(User)
    00009	  native
    00010	  transient;
    00011
    00012	var globalconfig	bool	bMaxMouseSmoothing;
    00013	var globalconfig	bool	bInvertMouse;
    00014
    00015	var bool bWasForward;	// used for doubleclick move
    00016	var bool bWasBack;
    00017	var bool bWasLeft;
    00018	var bool bWasRight;
    00019	var bool bEdgeForward;
    00020	var bool bEdgeBack;
    00021	var bool bEdgeLeft;
    00022	var bool bEdgeRight;
    00023	var bool bForceCrouch;    // Used to force crouching when going back from flashback
    00024
    00025	// Mouse smoothing
    00026	var globalconfig float MouseSensitivity;
    00027	var float SmoothMouseX, SmoothMouseY, BorrowedMouseX, BorrowedMouseY;
    00028	var globalconfig float MouseSmoothThreshold;
    00029	var float MouseZeroTime;
    00030
    00031	var	float DoubleClickTimer; // max double click interval for double click move
    00032	var globalconfig float	DoubleClickTime;
    00033
    00034	// XIII Added
    00035	var bool bUseSnapTimer;
    00036	var bool bDuckCheck;                  // Used for the duck SwitchMode
    00037	var int iDuckMem;                     // Used for the duck SwitchMode
    00038	var float fSnaptimer;
    00039	var float fInputRange, fPctWalkRun;
    00040	var float ViewTurnAcc;                // used to accelerate the view rotation
    00041	var float ViewTurnBoost;
    00042	var float ViewUpAcc;                // used to accelerate the view rotation
    00043	var float WeaponViewTurnAcc;          // used to accelerate the view rotation
    00044	var int iMemaTurnSign;                // used to accelerate the view rotation
    00045	var int iMemaLookUpSign;                // used to accelerate the view rotation
    00046
    00047	var array<float> MoveRange, TurnRange;
    00048	var float CurrentInput;
    00049	var int CurrentInputAngle;
    00050	var float CurrentTurnInput;
    00051	var int CurrentTurnInputAngle;
    00052	var globalconfig bool bCheckInputRanges;
    00053
    00054	CONST VIEWTURNACCSPEED=3;
    00055	CONST VIEWUPACCSPEED=3;
    00056	CONST VIEWTURNBOOSTSPEED=1.0;
    00057	CONST MAXBOOSTSPEED=1.0;
    00058	//
    00059
    00060	//=============================================================================
    00061	// Input related functions.
    00062
    00063	//_____________________________________________________________________________
    00064	// Postprocess the player's input.
    00065	/*  --> completely managed in the engine
    00066	event PlayerInput( float DeltaTime )
    00067	{
    00068	  DealWithXIIIInputEvent( DeltaTime );
    00069	  DealWithPlayerInputEvent( DeltaTime );
    00070
    00071	  // Handle walking.
    00072	  HandleWalking();
    00073	}
    00074	*/
    00075
    00076	//_____________________________________________________________________________
    00077	//native function DealWithPlayerInputEvent( float DeltaTime );
    00078	/* Old Script Code
    00079		local float FOVScale, MouseScale, AbsSmoothX, AbsSmoothY, MouseTime;
    00080
    00081		// Check for Double click move
    00082		// flag transitions
    00083		bEdgeForward = (bWasForward ^^ (aBaseY > 0));
    00084		bEdgeBack = (bWasBack ^^ (aBaseY < 0));
    00085		bEdgeLeft = (bWasLeft ^^ (aStrafe > 0));
    00086		bEdgeRight = (bWasRight ^^ (aStrafe < 0));
    00087		bWasForward = (aBaseY > 0);
    00088		bWasBack = (aBaseY < 0);
    00089		bWasLeft = (aStrafe > 0);
    00090		bWasRight = (aStrafe < 0);
    00091
    00092		// Smooth and amplify mouse movement
    00093		FOVScale = DesiredFOV * 0.01111;
    00094		MouseScale = MouseSensitivity * FOVScale;
    00095
    00096		aMouseX *= MouseScale;
    00097		aMouseY *= MouseScale;
    00098		MouseTime = (Level.TimeSeconds - MouseZeroTime)/Level.TimeDilation;
    00099		SmoothMouse(aMouseX, MouseTime, SmoothMouseX, BorrowedMouseX, AbsSmoothX);
    00100		SmoothMouse(aMouseY, MouseTime, SmoothMouseY, BorrowedMouseY, AbsSmoothY);
    00101
    00102		if ( (aMouseX != 0) || (aMouseY != 0) )
    00103			MouseZeroTime = Level.TimeSeconds;
    00104
    00105		// adjust keyboard and joystick movements
    00106		aLookUp *= FOVScale;
    00107		aTurn   *= FOVScale;
    00108
    00109		// Remap raw x-axis movement.
    00110		if( bStrafe!=0 ) // strafe
    00111			aStrafe += aBaseX + SmoothMouseX;
    00112		else // forward
    00113			aTurn  += aBaseX * FOVScale + SmoothMouseX;
    00114		aBaseX = 0;
    00115
    00116		// Remap mouse y-axis movement.
    00117		if( (bStrafe == 0) && (bAlwaysMouseLook || (bLook!=0)) )
    00118		{
    00119			// Look up/down.
    00120			if ( bInvertMouse )
    00121				aLookUp -= SmoothMouseY;
    00122			else
    00123				aLookUp += SmoothMouseY;
    00124		}
    00125		else // Move forward/backward.
    00126			aForward += SmoothMouseY;
    00127
    00128		SmoothMouseX = AbsSmoothX;
    00129		SmoothMouseY = AbsSmoothY;
    00130
    00131		if ( bSnapLevel != 0 )
    00132		{
    00133			bCenterView = true;
    00134			bKeyboardLook = false;
    00135		}
    00136		else if (aLookUp != 0)
    00137		{
    00138			bCenterView = false;
    00139			bKeyboardLook = true;
    00140		}
    00141		else if ( bSnapToLevel && !bAlwaysMouseLook )
    00142		{
    00143			bCenterView = true;
    00144			bKeyboardLook = false;
    00145		}
    00146
    00147		// Remap other y-axis movement.
    00148		if ( bFreeLook != 0 )
    00149		{
    00150			bKeyboardLook = true;
    00151			aLookUp += 0.5 * aBaseY * FOVScale;
    00152		}
    00153		else
    00154			aForward += aBaseY;
    00155		aBaseY = 0;
    00156
    00157		// scale inputs FIXME REMOVE
    00158			aForward *= 4;
    00159			aStrafe  *= 4;
    00160			aLookup  *= 0.24;
    00161			aTurn    *= 0.24;
    00162			aUp		 *= 1;
    00163	*/
    00164	/* --> exists now only on C++ side
    00165	function SmoothMouse(float aMouse, float MouseTime, out float SmoothMouse, out float BorrowedMouse, out float AbsSmooth)
    00166	{
    00167		AbsSmooth = SmoothMouse;
    00168		if ( bMaxMouseSmoothing && (aMouse == 0) && (MouseTime < MouseSmoothThreshold) )
    00169		{
    00170			SmoothMouse = 0.5 * (MouseSmoothThreshold - MouseTime) * AbsSmooth/MouseSmoothThreshold;
    00171			BorrowedMouse += SmoothMouse;
    00172		}
    00173		else
    00174		{
    00175			if ( (SmoothMouse == 0) || (aMouse == 0)
    00176					|| ((SmoothMouse > 0) != (aMouse > 0)) )
    00177			{
    00178				SmoothMouse = aMouse;
    00179				BorrowedMouse = 0;
    00180			}
    00181			else
    00182			{
    00183				SmoothMouse = 0.5 * (SmoothMouse + aMouse - BorrowedMouse);
    00184				if ( (SmoothMouse > 0) != (aMouse > 0) )
    00185				{
    00186					if ( AMouse > 0 )
    00187						SmoothMouse = 1;
    00188					else
    00189						SmoothMouse = -1;
    00190				}
    00191				BorrowedMouse = SmoothMouse - aMouse;
    00192			}
    00193			AbsSmooth = SmoothMouse;
    00194		}
    00195	}
    00196	*/
    00197
    00198	//_____________________________________________________________________________
    00199	//native function DealWithXIIIInputEvent( float DeltaTime );
    00200	/* Old Script Code
    00201	    local float faTan, fDistFact;
    00202
    00203	    // DON'T PUT ANYTHING BEFORE THIS ELSE THE VALUES WILL NOT BE CALIBRATED VS fInputRange nor DeltaTime
    00204	    // Kill the PAD Input/FrameRate dependance
    00205	    aBaseY *= (DeltaTime / (0.05/3));
    00206	    if ( bInverseLook )
    00207	      aLookUp *= - (DeltaTime / (0.05/3)) * fLookSpeed;
    00208	    else
    00209	      aLookUp *= (DeltaTime / (0.05/3)) * fLookSpeed;
    00210	    aTurn *= (DeltaTime / (0.05/3)) * fLookSpeed;
    00211	    aStrafe *= (DeltaTime / (0.05/3));
    00212
    00213	    // Change turn input to have acceleration & boost w/ 'pure' turn command
    00214	    if ( aTurn > 0 )
    00215	    {
    00216	      if ( iMemaTurnSign < 0 )
    00217	      {
    00218	        ViewTurnAcc = 0.0;
    00219	        ViewTurnBoost = 0.0;
    00220	      }
    00221	      else
    00222	        ViewTurnAcc = fMin(ViewTurnAcc+DeltaTime*VIEWTURNACCSPEED, 1.0);
    00223	      if ( (ViewTurnAcc == 1) && (aTurn > 0.95*fInputRange) && (aBaseY < 0.05*fInputRange) )
    00224	        ViewTurnBoost = fMin(ViewTurnBoost+DeltaTime*VIEWTURNBOOSTSPEED, MAXBOOSTSPEED);
    00225	      else
    00226	        ViewTurnBoost = 0.0;
    00227
    00228	      iMemaTurnSign = 1;
    00229	      if ( aTurn > 0 )
    00230	      {
    00231	        if ( WeaponViewTurnAcc > 0 )
    00232	          WeaponViewTurnAcc = fMin(WeaponViewTurnAcc+DeltaTime*VIEWTURNACCSPEED, 1.0);
    00233	        else
    00234	          WeaponViewTurnAcc = fMin(WeaponViewTurnAcc+DeltaTime*VIEWTURNACCSPEED*2, 1.0);
    00235	      }
    00236	      else
    00237	      {
    00238	        if ( WeaponViewTurnAcc > 0 )
    00239	          WeaponViewTurnAcc = fMax(WeaponViewTurnAcc-DeltaTime*VIEWTURNACCSPEED*2, 0.0);
    00240	        else
    00241	          WeaponViewTurnAcc = fMin(WeaponViewTurnAcc+DeltaTime*VIEWTURNACCSPEED*2, 0.0);
    00242	      }
    00243	    }
    00244	    else if ( aTurn < 0 )
    00245
{ 00246 if ( iMemaTurnSign < 0 ) 00247 ViewTurnAcc = fMin(ViewTurnAcc+DeltaTime*VIEWTURNACCSPEED, 1.0); 00248 else 00249 { 00250 ViewTurnAcc = 0.0; 00251 ViewTurnBoost = 0.0; 00252 } 00253 if ( (ViewTurnAcc == 1) && (aTurn < -0.95*fInputRange) && (aBaseY < 0.05*fInputRange) ) 00254 ViewTurnBoost = fMin(ViewTurnBoost+DeltaTime*VIEWTURNBOOSTSPEED, MAXBOOSTSPEED); 00255 else 00256 ViewTurnBoost = 0.0; 00257 00258 iMemaTurnSign = -1; 00259 if ( aTurn < 0 ) 00260 { 00261 if ( WeaponViewTurnAcc > 0 ) 00262 WeaponViewTurnAcc = fMax(WeaponViewTurnAcc-DeltaTime*VIEWTURNACCSPEED*2, -1.0); 00263 else 00264 WeaponViewTurnAcc = fMax(WeaponViewTurnAcc-DeltaTime*VIEWTURNACCSPEED, -1.0); 00265 } 00266 else 00267 { 00268 if ( WeaponViewTurnAcc > 0 ) 00269 WeaponViewTurnAcc = fMax(WeaponViewTurnAcc-DeltaTime*VIEWTURNACCSPEED*2, 0.0); 00270 else 00271 WeaponViewTurnAcc = fMin(WeaponViewTurnAcc+DeltaTime*VIEWTURNACCSPEED*2, 0.0); 00272 } 00273 } 00274 else // no turn, reset ViewTurnAcc 00275 { 00276 ViewTurnAcc = fMax(ViewTurnAcc-DeltaTime*VIEWTURNACCSPEED*2, 0.0); 00277 ViewTurnBoost = 0.0; 00278 if ( WeaponViewTurnAcc > 0 ) 00279 WeaponViewTurnAcc = fMax(WeaponViewTurnAcc-DeltaTime*VIEWTURNACCSPEED*2, 0.0); 00280 else 00281 WeaponViewTurnAcc = fMin(WeaponViewTurnAcc+DeltaTime*VIEWTURNACCSPEED*2, 0.0); 00282 } 00283 aTurn *= (ViewTurnBoost + ViewTurnAcc); 00284 00285 // Reduce pad lookup sensibility while strafing 00286 if ( (ConfigType == CT_StrafeLookSameAxis) && (abs(aLookUp) < abs(aStrafe)) ) aLookUp = 0; 00287 if ( (ConfigType == CT_StrafeLookNotSameAxis) && (aStrafe != 0) ) 00288 { // normalize the pad values as at 45 degrees the max are not attained (we have only 0.707* the max value) 00289 fAtan = atan(aBaseY / aStrafe); // Angle 00290 if ( abs(faTan) < pi/4.0 ) 00291 fDistFact = abs(1.414 / cos(faTan)); 00292 else 00293 fDistFact = abs(1.414 / sin(faTan)); 00294 aStrafe *= fDistFact; 00295 aBaseY *= fDistFact; 00296 } 00297 if ( (ConfigType == CT_StrafeLookSameAxis) && (aTurn != 0) ) 00298 { // normalize the pad values as at 45 degrees the max are not attained (we have only 0.707* the max value) 00299 fAtan = atan(aBaseY / aTurn); // Angle 00300 if ( abs(faTan) < pi/4.0 ) 00301 fDistFact = abs(1.414 / cos(faTan)); 00302 else 00303 fDistFact = abs(1.414 / sin(faTan)); 00304 aTurn *= fDistFact; 00305 aBaseY *= fDistFact; 00306 } 00307 00308 // do this to have same SpeedBase for all inputs and quite good movements. 00309 aTurn *= 2; 00310 aLookUp *= -2; 00311 00312 // Map the keys onto the PadInput 00313 if ( bUp>0 ) aBaseY = fInputRange; 00314 if ( bDown>0 ) aBaseY = -fInputRange; 00315 if ( bLeft>0 ) aStrafe = -fInputRange; 00316 if ( bRight>0 ) aStrafe = fInputRange; 00317 00318 // On a Ladder = No SnapLevel 00319 // Check pawn as it is no more available if dead. 00320 if ( (pawn!= none) && ( (Pawn.Physics == PHYS_Ladder) || (bFreeLook != 0) ) ) 00321 { 00322 bSnapLevel = 0; 00323 bUseSnapTimer = False; 00324 } 00325 else if ( bWalkCenterView ) 00326 { 00327 // AutoCenter only if moving (and not for the strafe) after 1.0 second. 00328 if ( aBaseY != 0 ) 00329 { 00330 if ( !bUseSnapTimer ) 00331 { 00332 bUseSnaptimer = True; 00333 fSnaptimer = DeltaTime; 00334 } 00335 else 00336 fSnaptimer += DeltaTime; 00337 if ( fSnaptimer>1.0 ) 00338 { 00339 bSnapLevel = 1.0; 00340 bSnapToLevel = True; 00341 } 00342 } 00343 else 00344 { 00345 bSnapLevel = 0.0; 00346 bSnapToLevel = false; 00347 bUseSnapTimer = False; 00348 } 00349 } 00350 // Switch Walk/Run upon the Pad Input 00351 // (BEWARE [ bRun=1 ] = Walking and not running :) 00352 if ( (abs(aBaseY)<fPctWalkRun*fInputRange && abs(aStrafe)<fPctWalkRun*fInputRange) || (bAltRun != 0) ) 00353 bRun=1; 00354 else 00355 bRun=0; 00356 00357 // Handle alternate (switch on/off) duck mode 00358 if ( (pawn!= none) && (Pawn.Physics == PHYS_Walking) && (Level.Game != none) && Level.Game.bAltDuckMode ) 00359 { 00360 // ::DBUG:: 00361 //log(self$" bDuck="$bDuck$" bDuckCheck="$bDuckCheck$" iDuckMem="$iDuckMem); 00362 if ( (bAltDuck==1) && bDuckCheck ) 00363 { 00364 bDuckCheck = false; 00365 iDuckMem = abs(iDuckMem-1); 00366 } 00367 else if ( bAltDuck==0 ) 00368 { 00369 bDuckCheck = true; 00370 } 00371 bDuck = iDuckMem; 00372 } 00373 else 00374 { 00375 bDuck = bAltDuck; 00376 bDuckCheck = true; 00377 iDuckMem = 0; 00378 } 00379 */ 00380 00381 //_____________________________________________________________________________ 00382 function UpdateSensitivity(float F) 00383 { 00384 MouseSensitivity = FMax(0,F); 00385 } 00386 00387 //_____________________________________________________________________________ 00388 function ChangeSnapView( bool B ) 00389 { 00390 bSnapToLevel = B; 00391 } 00392 00393 //_____________________________________________________________________________ 00394 exec function SetMouseSmoothThreshold( float F ) 00395 { 00396 MouseSmoothThreshold = FClamp(F, 0, 0.1); 00397 SaveConfig(); 00398 } 00399 00400 //_____________________________________________________________________________ 00401 // check for double click move 00402 function Actor.eDoubleClickDir CheckForDoubleClickMove(float DeltaTime) 00403 { 00404 local Actor.eDoubleClickDir DoubleClickMove, OldDoubleClick; 00405 00406 if ( DoubleClickDir == DCLICK_Active ) 00407 DoubleClickMove = DCLICK_Active; 00408 else 00409 DoubleClickMove = DCLICK_None; 00410 if (DoubleClickTime > 0.0) 00411 { 00412 if ( DoubleClickDir < DCLICK_Active ) 00413 { 00414 OldDoubleClick = DoubleClickDir; 00415 DoubleClickDir = DCLICK_None; 00416 00417 if (bEdgeForward && bWasForward) 00418 DoubleClickDir = DCLICK_Forward; 00419 else if (bEdgeBack && bWasBack) 00420 DoubleClickDir = DCLICK_Back; 00421 else if (bEdgeLeft && bWasLeft) 00422 DoubleClickDir = DCLICK_Left; 00423 else if (bEdgeRight && bWasRight) 00424 DoubleClickDir = DCLICK_Right; 00425 00426 if ( DoubleClickDir == DCLICK_None) 00427 DoubleClickDir = OldDoubleClick; 00428 else if ( DoubleClickDir != OldDoubleClick ) 00429 DoubleClickTimer = DoubleClickTime + 0.5 * DeltaTime; 00430 else 00431 DoubleClickMove = DoubleClickDir; 00432 } 00433 00434 if (DoubleClickDir == DCLICK_Done) 00435 { 00436 DoubleClickTimer -= DeltaTime; 00437 if (DoubleClickTimer < -0.35) 00438 { 00439 DoubleClickDir = DCLICK_None; 00440 DoubleClickTimer = DoubleClickTime; 00441 } 00442 } 00443 else if ((DoubleClickDir != DCLICK_None) && (DoubleClickDir != DCLICK_Active)) 00444 { 00445 DoubleClickTimer -= DeltaTime; 00446 if (DoubleClickTimer < 0) 00447 { 00448 DoubleClickDir = DCLICK_None; 00449 DoubleClickTimer = DoubleClickTime; 00450 } 00451 } 00452 } 00453 return DoubleClickMove; 00454 } 00455 00456 defaultproperties 00457 { 00458 bMaxMouseSmoothing=True 00459 MouseSensitivity=3.000000 00460 MouseSmoothThreshold=0.070000 00461 DoubleClickTime=0.250000 00462 fInputRange=1150.000000 00463 fPctWalkRun=0.875000 00464 ViewTurnAcc=1.000000 00465 }

End Source Code