Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Engine.PlayerInput

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

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

    class PlayerInput extends Core.Object within PlayerController
    	config(User)
    	native
    	transient;

    var globalconfig	bool	bInvertMouse;

    var bool		bWasForward;	// used for doubleclick move
    var bool		bWasBack;
    var bool		bWasLeft;
    var bool		bWasRight;
    var bool		bEdgeForward;
    var bool		bEdgeBack;
    var bool		bEdgeLeft;
    var bool 		bEdgeRight;
    var	bool		bAdjustSampling;

    // Mouse smoothing
    var globalconfig byte   MouseSmoothingMode;
    var globalconfig float  MouseSmoothingStrength;
    var globalconfig float	MouseSensitivity;
    var globalconfig float  MouseSamplingTime;
    var globalconfig float  MouseAccelThreshold;

    var float SmoothedMouse[2], ZeroTime[2], SamplingTime[2], MaybeTime[2], OldSamples[4];
    var int MouseSamples[2];

    var	float DoubleClickTimer; // max double click interval for double click move
    var globalconfig float	DoubleClickTime;

    //=============================================================================
    // Input related functions.

    function bool InvertLook();

    // Postprocess the player's input.
    event PlayerInput( float DeltaTime )
    {
    	local float FOVScale, MouseScale;

    	// Ignore input if we're playing back a client-side demo.
    	if( Outer.bDemoOwner && !Outer.default.bDemoOwner )
    		return;

    	// Check for Double click move
    	// flag transitions
    	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);

    	// Smooth and amplify mouse movement
    	FOVScale = DesiredFOV * 0.01111; // 0.01111 = 1/90
    	MouseScale = MouseSensitivity * FOVScale;
    	aMouseX = SmoothMouse(aMouseX*MouseScale, DeltaTime,bXAxis,0);
    	aMouseY = SmoothMouse(aMouseY*MouseScale, DeltaTime,bYAxis,1);

    	aMouseX = AccelerateMouse(aMouseX);
    	aMouseY = AccelerateMouse(aMouseY);

    	// adjust keyboard and joystick movements
    	aLookUp *= FOVScale;
    	aTurn   *= FOVScale;

    	// Remap raw x-axis movement.
    	if( bStrafe!=0 ) // strafe
    		aStrafe += aBaseX * 7.5 + aMouseX;
    	else // forward
    		aTurn  += aBaseX * FOVScale + aMouseX;
    	aBaseX = 0;

    	// Remap mouse y-axis movement.
    	if( (bStrafe == 0) && (bAlwaysMouseLook || (bLook!=0)) )
    	{
    		// Look up/down.
    		if ( bInvertMouse )
    			aLookUp -= aMouseY;
    		else
    			aLookUp += aMouseY;
    	}
    	else // Move forward/backward.
    		aForward += aMouseY;

    	if ( bSnapLevel != 0 )
    	{
    		bCenterView = true;
    		bKeyboardLook = false;
    	}
    	else if (aLookUp != 0)
    	{
    		bCenterView = false;
    		bKeyboardLook = true;
    	}
    	else if ( bSnapToLevel && !bAlwaysMouseLook )
    	{
    		bCenterView = true;
    		bKeyboardLook = false;
    	}

    	// Remap other y-axis movement.
    	if ( bFreeLook != 0 )
    	{
    		bKeyboardLook = true;
    		aLookUp += 0.5 * aBaseY * FOVScale;
    	}
    	else
    		aForward += aBaseY;

    	aBaseY = 0;

    	// Handle walking.
    	HandleWalking();
    }

    exec function SetSmoothingMode(byte B)
    {
    	MouseSmoothingMode = B;
    	Log("Smoothing mode "$MouseSmoothingMode);
    }

    exec function SetSmoothingStrength(float F)
    {
    	MouseSmoothingStrength = FClamp(F,0,1);
    }

    function float AccelerateMouse(float aMouse)
    {
    	local float Accel;

    	if ( Abs(aMouse) == 0 )
    		return 0;

    	Accel = MouseAccelThreshold * MouseSensitivity;
    	if ( Abs(aMouse) < Accel )
    	{
    		if ( Abs(aMouse) < 0.1 * Accel )
    			aMouse *= 0.1;
    		else
    			aMouse = aMouse * Abs(aMouse)/Accel;
    	}
    	return aMouse;
    }

    function float SmoothMouse(float aMouse, float DeltaTime, out byte SampleCount, int Index)
    {
    	local int i, sum;

    	if ( MouseSmoothingMode == 0 )
    		return aMouse;

    	if ( aMouse == 0 )
    	{
    		ZeroTime[Index] += DeltaTime;
    		if ( ZeroTime[Index] < MouseSamplingTime )
    		{
    			SamplingTime[Index] += DeltaTime;
    			MaybeTime[Index] += DeltaTime;
    			aMouse = SmoothedMouse[Index];
    		}
    		else
    		{
    			if ( bAdjustSampling && (MouseSamples[Index] > 9) )
    			{
    				SamplingTime[Index] -= MaybeTime[Index];
    				MouseSamplingTime = 0.9 * MouseSamplingTime + 0.1 * SamplingTime[Index]/MouseSamples[Index];
    			}
    			SamplingTime[Index] = 0;
    			SmoothedMouse[Index] = 0;
    			MouseSamples[Index] = 0;
    		}
    	}
    	else
    	{
    		MaybeTime[Index] = 0;

    		if ( SmoothedMouse[Index] != 0 )
    		{
    			MouseSamples[Index] += SampleCount;
    			if ( DeltaTime > MouseSamplingTime * (SampleCount + 1) )
    				SamplingTime[Index] += MouseSamplingTime * SampleCount;
    			else
    			{
    				SamplingTime[Index] += DeltaTime;
    				aMouse = aMouse * DeltaTime/(MouseSamplingTime * SampleCount);
    			}
    		}
    		else
    			SamplingTime[Index] = 0.5 * MouseSamplingTime;

    		SmoothedMouse[Index] = aMouse/SampleCount;
    		ZeroTime[Index] = 0;
    	}
    	SampleCount = 0;

    	if ( MouseSmoothingMode > 1 )
    	{
    		if ( aMouse == 0 )
    		{
    			// stop in next tick
    			for ( i=0; i<3; i++ )
    			{
    				sum += (i+1) * 0.1;
    				aMouse += sum * OldSamples[i];
    				OldSamples[i] = 0;
    			}
    			OldSamples[3] = 0;
    		}
    		else
    		{
    			aMouse = 0.4 * aMouse;
    			OldSamples[3] = aMouse;
    			for ( i=0; i<3; i++ )
    			{
    				aMouse += (i+1) * 0.1 * OldSamples[i];
    				OldSamples[i] = OldSamples[i+1];
    			}

    		}
    	}
    	return aMouse;
    }

    function UpdateSensitivity(float F)
    {
    	MouseSensitivity = FMax(0,F);
        default.MouseSensitivity = MouseSensitivity;
    	class'PlayerInput'.static.StaticSaveConfig();
    }

    function UpdateAccel(float F)
    {
    	MouseAccelThreshold = FMax(0,F);
    	default.MouseAccelThreshold = MouseAccelThreshold;
    	class'PlayerInput'.static.StaticSaveConfig();
    }

    function UpdateSmoothing( int Mode )
    {
        MouseSmoothingMode = Mode;
        default.MouseSmoothingMode = MouseSmoothingMode;
    	class'PlayerInput'.static.StaticSaveConfig();
    }

    function ChangeSnapView( bool B )
    {
    	bSnapToLevel = B;
    }

    // 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;
    }

    defaultproperties
    {
    	 bAdjustSampling=true
    	 MouseSamplingTime=+0.008333
    	 MouseSmoothingStrength=+0.3
    	 MouseSmoothingMode=1
         MouseSensitivity=3.000000
        MouseAccelThreshold=100.0
         DoubleClickTime=0.250000
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: ne 5.9.2004 16:01:26.000 - Creation time: st 23.5.2018 00:10:46.490 - Created with UnCodeX