Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 |
//============================================================================= // PlayerInput // Object within playercontroller that manages player input. // only spawned on client // Copyright 1998-2011 Epic Games, Inc. All Rights Reserved. //============================================================================= class PlayerInput extends Input within PlayerController config(Input) transient native(UserInterface); cpptext { /** * Generates an IE_Released event for each key in the PressedKeys array, then clears the array. Should be called when another * interaction which swallows some (but perhaps not all) input is activated. */ virtual void FlushPressedKeys(); /** Override to detect input from a gamepad */ virtual UBOOL InputKey(INT ControllerId, FName Key, enum EInputEvent Event, FLOAT AmountDepressed = 1.f, UBOOL bGamepad = FALSE ); virtual UBOOL InputAxis(INT ControllerId, FName Key, FLOAT Delta, FLOAT DeltaTime, UBOOL bGamepad=FALSE); virtual void UpdateAxisValue( FLOAT* Axis, FLOAT Delta ); virtual UBOOL IsGamepadKey(FName Name) const; /** stub functions for mobile devices */ virtual void InputTouch(UINT Handle, BYTE Type, FVector2D TouchLocation, DOUBLE DeviceTimestamp, UINT TouchpadIndex=0) { } virtual void ProcessTouches(FLOAT DeltaTime) { } } /** Player is giving input through a gamepad */ var const bool bUsingGamepad; var const Name LastAxisKeyName; var globalconfig bool bInvertMouse; /** if true, mouse y axis is inverted from normal FPS mode */ var globalconfig bool bInvertTurn; /** if true, mouse x axis is inverted from normal FPS mode */ // Double click move flags var bool bWasForward; var bool bWasBack; var bool bWasLeft; var bool bWasRight; var bool bEdgeForward; var bool bEdgeBack; var bool bEdgeLeft; var bool bEdgeRight; var float DoubleClickTimer; /** max double click interval for double click move */ var globalconfig float DoubleClickTime; /** stores time of first click for potential double click */ var globalconfig float MouseSensitivity; // Input axes. var input float aBaseX; var input float aBaseY; var input float aBaseZ; var input float aMouseX; var input float aMouseY; var input float aForward; var input float aTurn; var input float aStrafe; var input float aUp; var input float aLookUp; // analog trigger axes var input float aRightAnalogTrigger; var input float aLeftAnalogTrigger; // PS3 SIXAXIS axes var input float aPS3AccelX; var input float aPS3AccelY; var input float aPS3AccelZ; var input float aPS3Gyro; // // Joy Raw Input // /** Joypad left thumbstick, vertical axis. Range [-1,+1] */ var transient float RawJoyUp; /** Joypad left thumbstick, horizontal axis. Range [-1,+1] */ var transient float RawJoyRight; /** Joypad right thumbstick, horizontal axis. Range [-1,+1] */ var transient float RawJoyLookRight; /** Joypad right thumbstick, vertical axis. Range [-1,+1] */ var transient float RawJoyLookUp; /** move forward speed scaling */ var() config float MoveForwardSpeed; /** strafe speed scaling */ var() config float MoveStrafeSpeed; /** Yaw turn speed scaling */ var() config float LookRightScale; /** pitch turn speed scaling */ var() config float LookUpScale; // Input buttons. var input byte bStrafe; var input byte bXAxis; var input byte bYAxis; // Mouse smoothing control var globalconfig bool bEnableMouseSmoothing; /** if true, mouse smoothing is enabled */ // Zoom Scaling var bool bEnableFOVScaling; // Mouse smoothing sample data var float ZeroTime[2]; /** How long received mouse movement has been zero. */ var float SmoothedMouse[2]; /** Current average mouse movement/sample */ var int MouseSamples; /** Number of mouse samples since mouse movement has been zero */ var float MouseSamplingTotal; /** DirectInput's mouse sampling total time */ /** If TRUE turn input will be ignored until the stick is released */ var transient bool bLockTurnUntilRelease; /** Time remaining to disable bLockTurnUntilRelease */ var transient float AutoUnlockTurnTime; //============================================================================= // Input related functions. exec function bool InvertMouse() { bInvertMouse = !bInvertMouse; SaveConfig(); return bInvertMouse; } exec function bool InvertTurn() { bInvertTurn = !bInvertTurn; SaveConfig(); return bInvertTurn; } exec function SetSensitivity(Float F) { MouseSensitivity = F; } /** Hook called from HUD actor. Gives access to HUD and Canvas */ function DrawHUD( HUD H ); function PreProcessInput(float DeltaTime); function PostProcessInput(float DeltaTime); function AdjustMouseSensitivity(float FOVScale) { // Apply mouse sensitivity. aMouseX *= MouseSensitivity * FOVScale; aMouseY *= MouseSensitivity * FOVScale; } // Postprocess the player's input. event PlayerInput( float DeltaTime ) { local float FOVScale, TimeScale; // Save Raw values RawJoyUp = aBaseY; RawJoyRight = aStrafe; RawJoyLookRight = aTurn; RawJoyLookUp = aLookUp; // PlayerInput shouldn't take timedilation into account DeltaTime /= WorldInfo.TimeDilation; if (Outer.bDemoOwner && WorldInfo.NetMode == NM_Client) { DeltaTime /= WorldInfo.DemoPlayTimeDilation; } PreProcessInput( DeltaTime ); // Scale to game speed TimeScale = 100.f*DeltaTime; aBaseY *= TimeScale * MoveForwardSpeed; aStrafe *= TimeScale * MoveStrafeSpeed; aUp *= TimeScale * MoveStrafeSpeed; aTurn *= TimeScale * LookRightScale; aLookUp *= TimeScale * LookUpScale; PostProcessInput( DeltaTime ); ProcessInputMatching(DeltaTime); // Check for Double click movement. CatchDoubleClickInput(); // Take FOV into account (lower FOV == less sensitivity). if ( bEnableFOVScaling ) { FOVScale = GetFOVAngle() * 0.01111; // 0.01111 = 1 / 90.0 } else { FOVScale = 1.0; } AdjustMouseSensitivity(FOVScale); // mouse smoothing if ( bEnableMouseSmoothing ) { aMouseX = SmoothMouse(aMouseX, DeltaTime,bXAxis,0); aMouseY = SmoothMouse(aMouseY, DeltaTime,bYAxis,1); } aLookUp *= FOVScale; aTurn *= FOVScale; // Turning and strafing share the same axis. if( bStrafe > 0 ) aStrafe += aBaseX + aMouseX; else aTurn += aBaseX + aMouseX; // Look up/down. aLookup += aMouseY; if (bInvertMouse) { aLookup *= -1.f; } if (bInvertTurn) { aTurn *= -1.f; } // Forward/ backward movement aForward += aBaseY; // Handle walking. HandleWalking(); // check for turn locking if (bLockTurnUntilRelease) { if (RawJoyLookRight != 0) { aTurn = 0.f; if (AutoUnlockTurnTime > 0.f) { AutoUnlockTurnTime -= DeltaTime; if (AutoUnlockTurnTime < 0.f) { bLockTurnUntilRelease = FALSE; } } } else { bLockTurnUntilRelease = FALSE; } } // ignore move input // Do not clear RawJoy flags, as we still want to be able to read input. if( IsMoveInputIgnored() ) { aForward = 0.f; aStrafe = 0.f; aUp = 0.f; } // ignore look input // Do not clear RawJoy flags, as we still want to be able to read input. if( IsLookInputIgnored() ) { aTurn = 0.f; aLookup = 0.f; } } function CatchDoubleClickInput() { if (!IsMoveInputIgnored()) { bEdgeForward = (bWasForward ^^ (aBaseY > 0)); bEdgeBack = (bWasBack ^^ (aBaseY < 0)); bEdgeLeft = (bWasLeft ^^ (aStrafe < 0)); bEdgeRight = (bWasRight ^^ (aStrafe > 0)); bWasForward = (aBaseY > 0); bWasBack = (aBaseY < 0); bWasLeft = (aStrafe < 0); bWasRight = (aStrafe > 0); } } // check for double click move function Actor.EDoubleClickDir CheckForDoubleClickMove(float DeltaTime) { local Actor.EDoubleClickDir DoubleClickMove, OldDoubleClick; if ( DoubleClickDir == DCLICK_Active ) DoubleClickMove = DCLICK_Active; else DoubleClickMove = DCLICK_None; if (DoubleClickTime > 0.0) { if ( DoubleClickDir == DCLICK_Active ) { if ( (Pawn != None) && (Pawn.Physics == PHYS_Walking) ) { DoubleClickTimer = 0; DoubleClickDir = DCLICK_Done; } } else if ( DoubleClickDir != DCLICK_Done ) { OldDoubleClick = DoubleClickDir; DoubleClickDir = DCLICK_None; if (bEdgeForward && bWasForward) DoubleClickDir = DCLICK_Forward; else if (bEdgeBack && bWasBack) DoubleClickDir = DCLICK_Back; else if (bEdgeLeft && bWasLeft) DoubleClickDir = DCLICK_Left; else if (bEdgeRight && bWasRight) DoubleClickDir = DCLICK_Right; if ( DoubleClickDir == DCLICK_None) DoubleClickDir = OldDoubleClick; else if ( DoubleClickDir != OldDoubleClick ) DoubleClickTimer = DoubleClickTime + 0.5 * DeltaTime; else DoubleClickMove = DoubleClickDir; } if (DoubleClickDir == DCLICK_Done) { DoubleClickTimer = FMin(DoubleClickTimer-DeltaTime,0); if (DoubleClickTimer < -0.35) { DoubleClickDir = DCLICK_None; DoubleClickTimer = DoubleClickTime; } } else if ((DoubleClickDir != DCLICK_None) && (DoubleClickDir != DCLICK_Active)) { DoubleClickTimer -= DeltaTime; if (DoubleClickTimer < 0) { DoubleClickDir = DCLICK_None; DoubleClickTimer = DoubleClickTime; } } } return DoubleClickMove; } /** * Iterates through all InputRequests on the PlayerController and * checks to see if a new input has been matched, or if the entire * match sequence should be reset. * * @param DeltaTime - time since last tick */ final function ProcessInputMatching(float DeltaTime) { local float Value; local int i,MatchIdx; local bool bMatch; // iterate through each request, for (i = 0; i < InputRequests.Length; i++) { // if we have a valid match idx if (InputRequests[i].MatchIdx >= 0 && InputRequests[i].MatchIdx < InputRequests[i].Inputs.Length) { if (InputRequests[i].MatchActor == None) { InputRequests[i].MatchActor = Outer; } MatchIdx = InputRequests[i].MatchIdx; // if we've exceeded the delta, // ignore the delta for the first match if (MatchIdx != 0 && InputRequests[i].Inputs[MatchIdx].TimeDelta > 0.f && WorldInfo.TimeSeconds - InputRequests[i].LastMatchTime >= InputRequests[i].Inputs[MatchIdx].TimeDelta) { // reset this match InputRequests[i].LastMatchTime = 0.f; InputRequests[i].MatchIdx = 0; // fire off the cancel event if (InputRequests[i].FailedFuncName != 'None') { InputRequests[i].MatchActor.SetTimer(0.01f, false, InputRequests[i].FailedFuncName ); } } else { // grab the current input value of the matching type Value = 0.f; switch (InputRequests[i].Inputs[MatchIdx].Type) { case IT_XAxis: Value = aStrafe; break; case IT_YAxis: Value = aBaseY; break; } // check to see if this matches switch (InputRequests[i].Inputs[MatchIdx].Action) { case IMA_GreaterThan: bMatch = Value >= InputRequests[i].Inputs[MatchIdx].Value; break; case IMA_LessThan: bMatch = Value <= InputRequests[i].Inputs[MatchIdx].Value; break; } if (bMatch) { // mark it as matched InputRequests[i].LastMatchTime = WorldInfo.TimeSeconds; InputRequests[i].MatchIdx++; // check to see if we've matched all inputs if (InputRequests[i].MatchIdx >= InputRequests[i].Inputs.Length) { if (InputRequests[i].MatchDelegate != None) { InputMatchDelegate = InputRequests[i].MatchDelegate; InputMatchDelegate(); } // fire off the event if (InputRequests[i].MatchFuncName != 'None') { InputRequests[i].MatchActor.SetTimer(0.01f,false,InputRequests[i].MatchFuncName); } // reset this match InputRequests[i].LastMatchTime = 0.f; InputRequests[i].MatchIdx = 0; // as well as all others } } } } } } //************************************************************************************* // Normal gameplay execs // Type the name of the exec function at the console to execute it exec function Jump() { if ( WorldInfo.Pauser == PlayerReplicationInfo ) SetPause( False ); else bPressedJump = true; } exec function SmartJump() { Jump(); } //************************************************************************************* // Mouse smoothing exec function ClearSmoothing() { local int i; for ( i=0; i<2; i++ ) { //`Log(i$" zerotime "$zerotime[i]$" smoothedmouse "$SmoothedMouse[i]); ZeroTime[i] = 0; SmoothedMouse[i] = 0; } //`Log("MouseSamplingTotal "$MouseSamplingTotal$" MouseSamples "$MouseSamples); MouseSamplingTotal = Default.MouseSamplingTotal; MouseSamples = Default.MouseSamples; } /** SmoothMouse() Smooth mouse movement, because mouse sampling doesn't match up with tick time. * @note: if we got sample event for zero mouse samples (so we didn't have to guess whether a 0 was caused by no sample occuring during the tick (at high frame rates) or because the mouse actually stopped) * @param: aMouse is the mouse axis movement received from DirectInput * @param: DeltaTime is the tick time * @param: SampleCount is the number of mouse samples received from DirectInput * @param: Index is 0 for X axis, 1 for Y axis * @return the smoothed mouse axis movement */ function float SmoothMouse(float aMouse, float DeltaTime, out byte SampleCount, int Index) { local float MouseSamplingTime; if (DeltaTime < 0.25) { MouseSamplingTime = MouseSamplingTotal/MouseSamples; if ( aMouse == 0 ) { // no mouse movement received ZeroTime[Index] += DeltaTime; if ( ZeroTime[Index] < MouseSamplingTime ) { // zero mouse movement is possibly because less than the mouse sampling interval has passed aMouse = SmoothedMouse[Index] * DeltaTime/MouseSamplingTime; } else { SmoothedMouse[Index] = 0; } } else { ZeroTime[Index] = 0; if ( SmoothedMouse[Index] != 0 ) { // this isn't the first tick with non-zero mouse movement if ( DeltaTime < MouseSamplingTime * (SampleCount + 1) ) { // smooth mouse movement so samples/tick is constant aMouse = aMouse * DeltaTime/(MouseSamplingTime * SampleCount); } else { // fewer samples, so going slow // use number of samples we should have had for sample count SampleCount = DeltaTime/MouseSamplingTime; } } SmoothedMouse[Index] = aMouse/SampleCount; } } else { // if we had an abnormally long frame, clear everything so it doesn't distort the results ClearSmoothing(); } SampleCount = 0; return aMouse; } /** * The player controller will call this function directly after creating the input system */ function InitInputSystem(); /** * Called via replication to tell the Client to Init it's input system */ function ClientInitInputSystem(); /** * The player controll will call this function directly before traveling */ function PreClientTravel( string PendingURL, ETravelType TravelType, bool bIsSeamlessTravel) { } defaultproperties { MouseSamplingTotal=+0.0083 MouseSamples=1 } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |