2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 BFG Edition GPL Source Code
2012-11-28 15:47:07 +00:00
Copyright ( C ) 1993 - 2012 id Software LLC , a ZeniMax Media company .
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ( " Doom 3 BFG Edition Source Code " ) .
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code 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 3 of the License , or
( at your option ) any later version .
Doom 3 BFG Edition Source Code 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 Doom 3 BFG Edition Source Code . If not , see < http : //www.gnu.org/licenses/>.
In addition , the Doom 3 BFG Edition Source Code is also subject to certain additional terms . You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code . If not , please request a copy in writing from id Software at the address below .
If you have questions concerning this license or the applicable additional terms , you may contact in writing id Software LLC , c / o ZeniMax Media Inc . , Suite 120 , Rockville , Maryland 20850 USA .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-12-22 15:18:19 +00:00
# include "precompiled.h"
2012-11-26 18:58:24 +00:00
# pragma hdrstop
idCVar joy_mergedThreshold ( " joy_mergedThreshold " , " 1 " , CVAR_BOOL | CVAR_ARCHIVE , " If the thresholds aren't merged, you drift more off center " ) ;
idCVar joy_newCode ( " joy_newCode " , " 1 " , CVAR_BOOL | CVAR_ARCHIVE , " Use the new codepath " ) ;
idCVar joy_triggerThreshold ( " joy_triggerThreshold " , " 0.05 " , CVAR_FLOAT | CVAR_ARCHIVE , " how far the joystick triggers have to be pressed before they register as down " ) ;
idCVar joy_deadZone ( " joy_deadZone " , " 0.2 " , CVAR_FLOAT | CVAR_ARCHIVE , " specifies how large the dead-zone is on the joystick " ) ;
idCVar joy_range ( " joy_range " , " 1.0 " , CVAR_FLOAT | CVAR_ARCHIVE , " allow full range to be mapped to a smaller offset " ) ;
idCVar joy_gammaLook ( " joy_gammaLook " , " 1 " , CVAR_INTEGER | CVAR_ARCHIVE , " use a log curve instead of a power curve for movement " ) ;
idCVar joy_powerScale ( " joy_powerScale " , " 2 " , CVAR_FLOAT | CVAR_ARCHIVE , " Raise joystick values to this power " ) ;
idCVar joy_pitchSpeed ( " joy_pitchSpeed " , " 100 " , CVAR_ARCHIVE | CVAR_FLOAT , " pitch speed when pressing up or down on the joystick " , 60 , 600 ) ;
idCVar joy_yawSpeed ( " joy_yawSpeed " , " 240 " , CVAR_ARCHIVE | CVAR_FLOAT , " pitch speed when pressing left or right on the joystick " , 60 , 600 ) ;
// these were a bad idea!
idCVar joy_dampenLook ( " joy_dampenLook " , " 1 " , CVAR_BOOL | CVAR_ARCHIVE , " Do not allow full acceleration on look " ) ;
idCVar joy_deltaPerMSLook ( " joy_deltaPerMSLook " , " 0.003 " , CVAR_FLOAT | CVAR_ARCHIVE , " Max amount to be added on look per MS " ) ;
idCVar in_mouseSpeed ( " in_mouseSpeed " , " 1 " , CVAR_ARCHIVE | CVAR_FLOAT , " speed at which the mouse moves " , 0.25f , 4.0f ) ;
idCVar in_alwaysRun ( " in_alwaysRun " , " 1 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_BOOL , " always run (reverse _speed button) - only in MP " ) ;
idCVar in_useJoystick ( " in_useJoystick " , " 0 " , CVAR_ARCHIVE | CVAR_BOOL , " enables/disables the gamepad for PC use " ) ;
idCVar in_joystickRumble ( " in_joystickRumble " , " 1 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_BOOL , " enable joystick rumble " ) ;
idCVar in_invertLook ( " in_invertLook " , " 0 " , CVAR_ARCHIVE | CVAR_BOOL , " inverts the look controls so the forward looks up (flight controls) - the proper way to play games ! " ) ;
idCVar in_mouseInvertLook ( " in_mouseInvertLook " , " 0 " , CVAR_ARCHIVE | CVAR_BOOL , " inverts the look controls so the forward looks up (flight controls) - the proper way to play games ! " ) ;
/*
= = = = = = = = = = = = = = = =
usercmd_t : : ByteSwap
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void usercmd_t : : ByteSwap ( )
{
2012-11-26 18:58:24 +00:00
angles [ 0 ] = LittleShort ( angles [ 0 ] ) ;
angles [ 1 ] = LittleShort ( angles [ 1 ] ) ;
angles [ 2 ] = LittleShort ( angles [ 2 ] ) ;
}
/*
= = = = = = = = = = = = = = = =
usercmd_t : : Serialize
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void usercmd_t : : Serialize ( idSerializer & ser , const usercmd_t & base )
{
2012-11-26 18:58:24 +00:00
ser . SerializeDelta ( buttons , base . buttons ) ;
ser . SerializeDelta ( forwardmove , base . forwardmove ) ;
ser . SerializeDelta ( rightmove , base . rightmove ) ;
ser . SerializeDelta ( angles [ 0 ] , base . angles [ 0 ] ) ;
ser . SerializeDelta ( angles [ 1 ] , base . angles [ 1 ] ) ;
ser . SerializeDelta ( angles [ 2 ] , base . angles [ 2 ] ) ;
ser . SerializeDelta ( pos . x , base . pos . x ) ;
ser . SerializeDelta ( pos . y , base . pos . y ) ;
ser . SerializeDelta ( pos . z , base . pos . z ) ;
ser . SerializeDelta ( clientGameMilliseconds , base . clientGameMilliseconds ) ;
ser . SerializeDelta ( serverGameMilliseconds , base . serverGameMilliseconds ) ;
ser . SerializeDelta ( fireCount , base . fireCount ) ;
ser . SerializeDelta ( speedSquared , base . speedSquared ) ;
ser . SerializeDelta ( impulse , base . impulse ) ;
ser . SerializeDelta ( impulseSequence , base . impulseSequence ) ;
}
/*
= = = = = = = = = = = = = = = =
usercmd_t : : operator = =
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool usercmd_t : : operator = = ( const usercmd_t & rhs ) const
{
2012-11-26 18:58:24 +00:00
return ( buttons = = rhs . buttons & &
2012-11-28 15:47:07 +00:00
forwardmove = = rhs . forwardmove & &
rightmove = = rhs . rightmove & &
angles [ 0 ] = = rhs . angles [ 0 ] & &
angles [ 1 ] = = rhs . angles [ 1 ] & &
angles [ 2 ] = = rhs . angles [ 2 ] & &
impulse = = rhs . impulse & &
impulseSequence = = rhs . impulseSequence & &
mx = = rhs . mx & &
my = = rhs . my & &
fireCount = = rhs . fireCount & &
speedSquared = = speedSquared ) ;
2012-11-26 18:58:24 +00:00
}
const int KEY_MOVESPEED = 127 ;
2012-11-28 15:47:07 +00:00
userCmdString_t userCmdStrings [ ] =
{
2012-11-26 18:58:24 +00:00
{ " _moveUp " , UB_MOVEUP } ,
{ " _moveDown " , UB_MOVEDOWN } ,
{ " _left " , UB_LOOKLEFT } ,
{ " _right " , UB_LOOKRIGHT } ,
{ " _forward " , UB_MOVEFORWARD } ,
{ " _back " , UB_MOVEBACK } ,
{ " _lookUp " , UB_LOOKUP } ,
{ " _lookDown " , UB_LOOKDOWN } ,
{ " _moveLeft " , UB_MOVELEFT } ,
{ " _moveRight " , UB_MOVERIGHT } ,
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
{ " _attack " , UB_ATTACK } ,
{ " _speed " , UB_SPEED } ,
{ " _zoom " , UB_ZOOM } ,
{ " _showScores " , UB_SHOWSCORES } ,
{ " _use " , UB_USE } ,
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
{ " _impulse0 " , UB_IMPULSE0 } ,
{ " _impulse1 " , UB_IMPULSE1 } ,
{ " _impulse2 " , UB_IMPULSE2 } ,
{ " _impulse3 " , UB_IMPULSE3 } ,
{ " _impulse4 " , UB_IMPULSE4 } ,
{ " _impulse5 " , UB_IMPULSE5 } ,
{ " _impulse6 " , UB_IMPULSE6 } ,
{ " _impulse7 " , UB_IMPULSE7 } ,
{ " _impulse8 " , UB_IMPULSE8 } ,
{ " _impulse9 " , UB_IMPULSE9 } ,
{ " _impulse10 " , UB_IMPULSE10 } ,
{ " _impulse11 " , UB_IMPULSE11 } ,
{ " _impulse12 " , UB_IMPULSE12 } ,
{ " _impulse13 " , UB_IMPULSE13 } ,
{ " _impulse14 " , UB_IMPULSE14 } ,
{ " _impulse15 " , UB_IMPULSE15 } ,
{ " _impulse16 " , UB_IMPULSE16 } ,
{ " _impulse17 " , UB_IMPULSE17 } ,
{ " _impulse18 " , UB_IMPULSE18 } ,
{ " _impulse19 " , UB_IMPULSE19 } ,
{ " _impulse20 " , UB_IMPULSE20 } ,
{ " _impulse21 " , UB_IMPULSE21 } ,
{ " _impulse22 " , UB_IMPULSE22 } ,
{ " _impulse23 " , UB_IMPULSE23 } ,
{ " _impulse24 " , UB_IMPULSE24 } ,
{ " _impulse25 " , UB_IMPULSE25 } ,
{ " _impulse26 " , UB_IMPULSE26 } ,
{ " _impulse27 " , UB_IMPULSE27 } ,
{ " _impulse28 " , UB_IMPULSE28 } ,
{ " _impulse29 " , UB_IMPULSE29 } ,
{ " _impulse30 " , UB_IMPULSE30 } ,
{ " _impulse31 " , UB_IMPULSE31 } ,
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
{ NULL , UB_NONE } ,
} ;
2012-11-28 15:47:07 +00:00
class buttonState_t
{
public :
2012-11-26 18:58:24 +00:00
int on ;
bool held ;
2012-11-28 15:47:07 +00:00
buttonState_t ( )
{
Clear ( ) ;
} ;
2012-11-26 18:58:24 +00:00
void Clear ( ) ;
void SetKeyState ( int keystate , bool toggle ) ;
} ;
/*
= = = = = = = = = = = = = = = =
buttonState_t : : Clear
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void buttonState_t : : Clear ( )
{
2012-11-26 18:58:24 +00:00
held = false ;
on = 0 ;
}
/*
= = = = = = = = = = = = = = = =
buttonState_t : : SetKeyState
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void buttonState_t : : SetKeyState ( int keystate , bool toggle )
{
if ( ! toggle )
{
2012-11-26 18:58:24 +00:00
held = false ;
on = keystate ;
2012-11-28 15:47:07 +00:00
}
else if ( ! keystate )
{
2012-11-26 18:58:24 +00:00
held = false ;
2012-11-28 15:47:07 +00:00
}
else if ( ! held )
{
2012-11-26 18:58:24 +00:00
held = true ;
on ^ = 1 ;
}
}
2012-11-28 15:47:07 +00:00
const int NUM_USER_COMMANDS = sizeof ( userCmdStrings ) / sizeof ( userCmdString_t ) ;
2012-11-26 18:58:24 +00:00
const int MAX_CHAT_BUFFER = 127 ;
2012-11-28 15:47:07 +00:00
class idUsercmdGenLocal : public idUsercmdGen
{
2012-11-26 18:58:24 +00:00
public :
2012-11-28 15:47:07 +00:00
idUsercmdGenLocal ( ) ;
2012-11-26 18:58:24 +00:00
void Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void InitForNewMap ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void Clear ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void ClearAngles ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void InhibitUsercmd ( inhibit_t subsystem , bool inhibit ) ;
2012-11-28 15:47:07 +00:00
int CommandStringUsercmdData ( const char * cmdString ) ;
2012-11-26 18:58:24 +00:00
void BuildCurrentUsercmd ( int deviceNum ) ;
2012-11-28 15:47:07 +00:00
usercmd_t GetCurrentUsercmd ( )
{
return cmd ;
} ;
void MouseState ( int * x , int * y , int * button , bool * down ) ;
2012-11-26 18:58:24 +00:00
int ButtonState ( int key ) ;
int KeyState ( int key ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
private :
void MakeCurrent ( ) ;
void InitCurrent ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
bool Inhibited ( ) ;
void AdjustAngles ( ) ;
void KeyMove ( ) ;
2012-11-28 15:47:07 +00:00
void CircleToSquare ( float & axis_x , float & axis_y ) const ;
2012-11-26 18:58:24 +00:00
void HandleJoystickAxis ( int keyNum , float unclampedValue , float threshold , bool positive ) ;
void JoystickMove ( ) ;
void JoystickMove2 ( ) ;
void MouseMove ( ) ;
void CmdButtons ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void AimAssist ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void Mouse ( ) ;
void Keyboard ( ) ;
void Joystick ( int deviceNum ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
void Key ( int keyNum , bool down ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec3 viewangles ;
int impulseSequence ;
int impulse ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
buttonState_t toggled_crouch ;
buttonState_t toggled_run ;
buttonState_t toggled_zoom ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int buttonState [ UB_MAX_BUTTONS ] ;
bool keyState [ K_LAST_KEY ] ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int inhibitCommands ; // true when in console or menu locally
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
bool initialized ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
usercmd_t cmd ; // the current cmd being built
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int continuousMouseX , continuousMouseY ; // for gui event generatioin, never zerod
int mouseButton ; // for gui event generatioin
bool mouseDown ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int mouseDx , mouseDy ; // added to by mouse events
float joystickAxis [ MAX_JOYSTICK_AXIS ] ; // set by joystick events
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int pollTime ;
int lastPollTime ;
float lastLookValuePitch ;
float lastLookValueYaw ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
static idCVar in_yawSpeed ;
static idCVar in_pitchSpeed ;
static idCVar in_angleSpeedKey ;
static idCVar in_toggleRun ;
static idCVar in_toggleCrouch ;
static idCVar in_toggleZoom ;
static idCVar sensitivity ;
static idCVar m_pitch ;
static idCVar m_yaw ;
static idCVar m_smooth ;
static idCVar m_showMouseRate ;
} ;
idCVar idUsercmdGenLocal : : in_yawSpeed ( " in_yawspeed " , " 140 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " yaw change speed when holding down _left or _right button " ) ;
idCVar idUsercmdGenLocal : : in_pitchSpeed ( " in_pitchspeed " , " 140 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " pitch change speed when holding down look _lookUp or _lookDown button " ) ;
idCVar idUsercmdGenLocal : : in_angleSpeedKey ( " in_anglespeedkey " , " 1.5 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " angle change scale when holding down _speed button " ) ;
idCVar idUsercmdGenLocal : : in_toggleRun ( " in_toggleRun " , " 0 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_BOOL , " pressing _speed button toggles run on/off - only in MP " ) ;
idCVar idUsercmdGenLocal : : in_toggleCrouch ( " in_toggleCrouch " , " 0 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_BOOL , " pressing _movedown button toggles player crouching/standing " ) ;
idCVar idUsercmdGenLocal : : in_toggleZoom ( " in_toggleZoom " , " 0 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_BOOL , " pressing _zoom button toggles zoom on/off " ) ;
idCVar idUsercmdGenLocal : : sensitivity ( " sensitivity " , " 5 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " mouse view sensitivity " ) ;
idCVar idUsercmdGenLocal : : m_pitch ( " m_pitch " , " 0.022 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " mouse pitch scale " ) ;
idCVar idUsercmdGenLocal : : m_yaw ( " m_yaw " , " 0.022 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_FLOAT , " mouse yaw scale " ) ;
2012-11-28 15:47:07 +00:00
idCVar idUsercmdGenLocal : : m_smooth ( " m_smooth " , " 1 " , CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER , " number of samples blended for mouse viewing " , 1 , 8 , idCmdSystem : : ArgCompletion_Integer < 1 , 8 > ) ;
2012-11-26 18:58:24 +00:00
idCVar idUsercmdGenLocal : : m_showMouseRate ( " m_showMouseRate " , " 0 " , CVAR_SYSTEM | CVAR_BOOL , " shows mouse movement " ) ;
static idUsercmdGenLocal localUsercmdGen ;
2012-11-28 15:47:07 +00:00
idUsercmdGen * usercmdGen = & localUsercmdGen ;
2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : idUsercmdGenLocal
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idUsercmdGenLocal : : idUsercmdGenLocal ( )
{
2012-11-26 18:58:24 +00:00
initialized = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
pollTime = 0 ;
lastPollTime = 0 ;
lastLookValuePitch = 0.0f ;
lastLookValueYaw = 0.0f ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
impulseSequence = 0 ;
impulse = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
toggled_crouch . Clear ( ) ;
toggled_run . Clear ( ) ;
toggled_zoom . Clear ( ) ;
toggled_run . on = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ClearAngles ( ) ;
Clear ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : InhibitUsercmd
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : InhibitUsercmd ( inhibit_t subsystem , bool inhibit )
{
if ( inhibit )
{
2012-11-26 18:58:24 +00:00
inhibitCommands | = 1 < < subsystem ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
inhibitCommands & = ( 0xffffffff ^ ( 1 < < subsystem ) ) ;
}
}
/*
= = = = = = = = = = = = = = =
idUsercmdGenLocal : : ButtonState
Returns ( the fraction of the frame ) that the key was down
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
int idUsercmdGenLocal : : ButtonState ( int key )
{
if ( key < 0 | | key > = UB_MAX_BUTTONS )
{
2012-11-26 18:58:24 +00:00
return - 1 ;
}
return ( buttonState [ key ] > 0 ) ? 1 : 0 ;
}
/*
= = = = = = = = = = = = = = =
idUsercmdGenLocal : : KeyState
Returns ( the fraction of the frame ) that the key was down
bk20060111
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
int idUsercmdGenLocal : : KeyState ( int key )
{
if ( key < 0 | | key > = K_LAST_KEY )
{
2012-11-26 18:58:24 +00:00
return - 1 ;
}
return ( keyState [ key ] ) ? 1 : 0 ;
}
//=====================================================================
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Inhibited
is user cmd generation inhibited
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idUsercmdGenLocal : : Inhibited ( )
{
return ( inhibitCommands ! = 0 ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : AdjustAngles
Moves the local angle positions
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : AdjustAngles ( )
{
2012-11-26 18:58:24 +00:00
float speed = MS2SEC ( 16 ) ;
2012-11-28 15:47:07 +00:00
if ( toggled_run . on | | ( in_alwaysRun . GetBool ( ) & & common - > IsMultiplayer ( ) ) )
{
2012-11-26 18:58:24 +00:00
speed * = in_angleSpeedKey . GetFloat ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
viewangles [ YAW ] - = speed * in_yawSpeed . GetFloat ( ) * ButtonState ( UB_LOOKRIGHT ) ;
viewangles [ YAW ] + = speed * in_yawSpeed . GetFloat ( ) * ButtonState ( UB_LOOKLEFT ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
viewangles [ PITCH ] - = speed * in_pitchSpeed . GetFloat ( ) * ButtonState ( UB_LOOKUP ) ;
viewangles [ PITCH ] + = speed * in_pitchSpeed . GetFloat ( ) * ButtonState ( UB_LOOKDOWN ) ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : KeyMove
Sets the usercmd_t based on key states
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : KeyMove ( )
{
2012-11-26 18:58:24 +00:00
int forward = 0 ;
int side = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
side + = KEY_MOVESPEED * ButtonState ( UB_MOVERIGHT ) ;
side - = KEY_MOVESPEED * ButtonState ( UB_MOVELEFT ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
forward + = KEY_MOVESPEED * ButtonState ( UB_MOVEFORWARD ) ;
forward - = KEY_MOVESPEED * ButtonState ( UB_MOVEBACK ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
cmd . forwardmove + = idMath : : ClampChar ( forward ) ;
cmd . rightmove + = idMath : : ClampChar ( side ) ;
}
/*
= = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : MouseMove
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : MouseMove ( )
{
2012-11-26 18:58:24 +00:00
float mx , my ;
static int history [ 8 ] [ 2 ] ;
static int historyCounter ;
int i ;
2012-11-28 15:47:07 +00:00
history [ historyCounter & 7 ] [ 0 ] = mouseDx ;
history [ historyCounter & 7 ] [ 1 ] = mouseDy ;
2012-11-26 18:58:24 +00:00
// allow mouse movement to be smoothed together
int smooth = m_smooth . GetInteger ( ) ;
2012-11-28 15:47:07 +00:00
if ( smooth < 1 )
{
2012-11-26 18:58:24 +00:00
smooth = 1 ;
}
2012-11-28 15:47:07 +00:00
if ( smooth > 8 )
{
2012-11-26 18:58:24 +00:00
smooth = 8 ;
}
mx = 0 ;
my = 0 ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < smooth ; i + + )
{
mx + = history [ ( historyCounter - i + 8 ) & 7 ] [ 0 ] ;
my + = history [ ( historyCounter - i + 8 ) & 7 ] [ 1 ] ;
2012-11-26 18:58:24 +00:00
}
mx / = smooth ;
my / = smooth ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
historyCounter + + ;
2012-11-28 15:47:07 +00:00
if ( idMath : : Fabs ( mx ) > 1000 | | idMath : : Fabs ( my ) > 1000 )
{
2012-11-26 18:58:24 +00:00
Sys_DebugPrintf ( " idUsercmdGenLocal::MouseMove: Ignoring ridiculous mouse delta. \n " ) ;
mx = my = 0 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mx * = sensitivity . GetFloat ( ) ;
my * = sensitivity . GetFloat ( ) ;
2012-11-28 15:47:07 +00:00
if ( m_showMouseRate . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
Sys_DebugPrintf ( " [%3i %3i = %5.1f %5.1f] " , mouseDx , mouseDy , mx , my ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mouseDx = 0 ;
mouseDy = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
viewangles [ YAW ] - = m_yaw . GetFloat ( ) * mx * in_mouseSpeed . GetFloat ( ) ;
viewangles [ PITCH ] + = m_pitch . GetFloat ( ) * in_mouseSpeed . GetFloat ( ) * ( in_mouseInvertLook . GetBool ( ) ? - my : my ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : CircleToSquare
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : CircleToSquare ( float & axis_x , float & axis_y ) const
{
2012-11-26 18:58:24 +00:00
// bring everything in the first quadrant
bool flip_x = false ;
2012-11-28 15:47:07 +00:00
if ( axis_x < 0.0f )
{
2012-11-26 18:58:24 +00:00
flip_x = true ;
axis_x * = - 1.0f ;
}
bool flip_y = false ;
2012-11-28 15:47:07 +00:00
if ( axis_y < 0.0f )
{
2012-11-26 18:58:24 +00:00
flip_y = true ;
axis_y * = - 1.0f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// swap the two axes so we project against the vertical line X = 1
bool swap = false ;
2012-11-28 15:47:07 +00:00
if ( axis_y > axis_x )
{
2012-11-26 18:58:24 +00:00
float tmp = axis_x ;
axis_x = axis_y ;
axis_y = tmp ;
swap = true ;
}
2012-11-28 15:47:07 +00:00
if ( axis_x < 0.001f )
{
2012-11-26 18:58:24 +00:00
// on one of the axes where no correction is needed
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// length (max 1.0f at the unit circle)
float len = idMath : : Sqrt ( axis_x * axis_x + axis_y * axis_y ) ;
2012-11-28 15:47:07 +00:00
if ( len > 1.0f )
{
2012-11-26 18:58:24 +00:00
len = 1.0f ;
}
// thales
float axis_y_us = axis_y / axis_x ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// use a power curve to shift the correction to happen closer to the unit circle
float correctionRatio = Square ( len ) ;
axis_x + = correctionRatio * ( len - axis_x ) ;
axis_y + = correctionRatio * ( axis_y_us - axis_y ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// go back through the symmetries
2012-11-28 15:47:07 +00:00
if ( swap )
{
2012-11-26 18:58:24 +00:00
float tmp = axis_x ;
axis_x = axis_y ;
axis_y = tmp ;
}
2012-11-28 15:47:07 +00:00
if ( flip_x )
{
2012-11-26 18:58:24 +00:00
axis_x * = - 1.0f ;
}
2012-11-28 15:47:07 +00:00
if ( flip_y )
{
2012-11-26 18:58:24 +00:00
axis_y * = - 1.0f ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : HandleJoystickAxis
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : HandleJoystickAxis ( int keyNum , float unclampedValue , float threshold , bool positive )
{
if ( ( unclampedValue > 0.0f ) & & ! positive )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ( unclampedValue < 0.0f ) & & positive )
{
2012-11-26 18:58:24 +00:00
return ;
}
float value = 0.0f ;
bool pressed = false ;
2012-11-28 15:47:07 +00:00
if ( unclampedValue > threshold )
{
2012-11-26 18:58:24 +00:00
value = idMath : : Fabs ( ( unclampedValue - threshold ) / ( 1.0f - threshold ) ) ;
pressed = true ;
2012-11-28 15:47:07 +00:00
}
else if ( unclampedValue < - threshold )
{
2012-11-26 18:58:24 +00:00
value = idMath : : Fabs ( ( unclampedValue + threshold ) / ( 1.0f - threshold ) ) ;
pressed = true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int action = idKeyInput : : GetUsercmdAction ( keyNum ) ;
2012-11-28 15:47:07 +00:00
if ( action > = UB_ATTACK )
{
2012-11-26 18:58:24 +00:00
Key ( keyNum , pressed ) ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! pressed )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float lookValue = 0.0f ;
2012-11-28 15:47:07 +00:00
if ( joy_gammaLook . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
lookValue = idMath : : Pow ( 1.04712854805f , value * 100.0f ) * 0.01f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
lookValue = idMath : : Pow ( value , joy_powerScale . GetFloat ( ) ) ;
}
2012-11-28 15:47:07 +00:00
idGame * game = common - > Game ( ) ;
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
lookValue * = game - > GetAimAssistSensitivity ( ) ;
}
2012-11-28 15:47:07 +00:00
switch ( action )
{
case UB_MOVEFORWARD :
{
float move = ( float ) cmd . forwardmove + ( KEY_MOVESPEED * value ) ;
2012-11-26 18:58:24 +00:00
cmd . forwardmove = idMath : : ClampChar ( idMath : : Ftoi ( move ) ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_MOVEBACK :
{
float move = ( float ) cmd . forwardmove - ( KEY_MOVESPEED * value ) ;
2012-11-26 18:58:24 +00:00
cmd . forwardmove = idMath : : ClampChar ( idMath : : Ftoi ( move ) ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_MOVELEFT :
{
float move = ( float ) cmd . rightmove - ( KEY_MOVESPEED * value ) ;
2012-11-26 18:58:24 +00:00
cmd . rightmove = idMath : : ClampChar ( idMath : : Ftoi ( move ) ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_MOVERIGHT :
{
float move = ( float ) cmd . rightmove + ( KEY_MOVESPEED * value ) ;
2012-11-26 18:58:24 +00:00
cmd . rightmove = idMath : : ClampChar ( idMath : : Ftoi ( move ) ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_LOOKUP :
{
if ( joy_dampenLook . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
lookValue = Min ( lookValue , ( pollTime - lastPollTime ) * joy_deltaPerMSLook . GetFloat ( ) + lastLookValuePitch ) ;
lastLookValuePitch = lookValue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float invertPitch = in_invertLook . GetBool ( ) ? - 1.0f : 1.0f ;
viewangles [ PITCH ] - = MS2SEC ( pollTime - lastPollTime ) * lookValue * joy_pitchSpeed . GetFloat ( ) * invertPitch ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_LOOKDOWN :
{
if ( joy_dampenLook . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
lookValue = Min ( lookValue , ( pollTime - lastPollTime ) * joy_deltaPerMSLook . GetFloat ( ) + lastLookValuePitch ) ;
lastLookValuePitch = lookValue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float invertPitch = in_invertLook . GetBool ( ) ? - 1.0f : 1.0f ;
viewangles [ PITCH ] + = MS2SEC ( pollTime - lastPollTime ) * lookValue * joy_pitchSpeed . GetFloat ( ) * invertPitch ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_LOOKLEFT :
{
if ( joy_dampenLook . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
lookValue = Min ( lookValue , ( pollTime - lastPollTime ) * joy_deltaPerMSLook . GetFloat ( ) + lastLookValueYaw ) ;
lastLookValueYaw = lookValue ;
}
viewangles [ YAW ] + = MS2SEC ( pollTime - lastPollTime ) * lookValue * joy_yawSpeed . GetFloat ( ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case UB_LOOKRIGHT :
{
if ( joy_dampenLook . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
lookValue = Min ( lookValue , ( pollTime - lastPollTime ) * joy_deltaPerMSLook . GetFloat ( ) + lastLookValueYaw ) ;
lastLookValueYaw = lookValue ;
}
viewangles [ YAW ] - = MS2SEC ( pollTime - lastPollTime ) * lookValue * joy_yawSpeed . GetFloat ( ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : JoystickMove
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : JoystickMove ( )
{
2012-11-26 18:58:24 +00:00
float threshold = joy_deadZone . GetFloat ( ) ;
float triggerThreshold = joy_triggerThreshold . GetFloat ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float axis_y = joystickAxis [ AXIS_LEFT_Y ] ;
float axis_x = joystickAxis [ AXIS_LEFT_X ] ;
CircleToSquare ( axis_x , axis_y ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
HandleJoystickAxis ( K_JOY_STICK1_UP , axis_y , threshold , false ) ;
HandleJoystickAxis ( K_JOY_STICK1_DOWN , axis_y , threshold , true ) ;
HandleJoystickAxis ( K_JOY_STICK1_LEFT , axis_x , threshold , false ) ;
HandleJoystickAxis ( K_JOY_STICK1_RIGHT , axis_x , threshold , true ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
axis_y = joystickAxis [ AXIS_RIGHT_Y ] ;
axis_x = joystickAxis [ AXIS_RIGHT_X ] ;
CircleToSquare ( axis_x , axis_y ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
HandleJoystickAxis ( K_JOY_STICK2_UP , axis_y , threshold , false ) ;
HandleJoystickAxis ( K_JOY_STICK2_DOWN , axis_y , threshold , true ) ;
HandleJoystickAxis ( K_JOY_STICK2_LEFT , axis_x , threshold , false ) ;
HandleJoystickAxis ( K_JOY_STICK2_RIGHT , axis_x , threshold , true ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
HandleJoystickAxis ( K_JOY_TRIGGER1 , joystickAxis [ AXIS_LEFT_TRIG ] , triggerThreshold , true ) ;
HandleJoystickAxis ( K_JOY_TRIGGER2 , joystickAxis [ AXIS_RIGHT_TRIG ] , triggerThreshold , true ) ;
}
2012-11-28 15:47:07 +00:00
enum transferFunction_t
{
2012-11-26 18:58:24 +00:00
FUNC_LINEAR ,
FUNC_LOGARITHMIC ,
FUNC_EXPONENTIAL
} ;
/*
= = = = = = = = = = = = = = = = =
JoypadFunction
= = = = = = = = = = = = = = = = =
*/
idVec2 JoypadFunction (
const idVec2 raw ,
const float aimAssistScale ,
const float threshold ,
const float range ,
const transferFunction_t shape ,
2012-11-28 15:47:07 +00:00
const bool mergedThreshold )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( range < = threshold )
{
2012-11-26 18:58:24 +00:00
return idVec2 ( 0.0f , 0.0f ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec2 threshed ;
2012-11-28 15:47:07 +00:00
if ( ! mergedThreshold )
{
2012-11-26 18:58:24 +00:00
// if the thresholding is performed independently, you can more easily move
// or look in a pure axial direction without drifting
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < 2 ; i + + )
{
2012-11-26 18:58:24 +00:00
const float v = raw [ i ] ;
float t ;
2012-11-28 15:47:07 +00:00
if ( v > 0.0f )
{
2012-11-26 18:58:24 +00:00
t = Max ( 0.0f , v - threshold ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
t = Min ( 0.0f , v + threshold ) ;
}
threshed [ i ] = t ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// thresholding together is the most predictable in free-form movement,
// but you tend to slide off axis based on which side your thumb is
// on the pad
const float rawLength = raw . Length ( ) ;
const float afterThreshold = Max ( 0.0f , rawLength - threshold ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec2 rawDir = raw ;
rawDir . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
threshed = rawDir * afterThreshold ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// threshold and range reduce the range of raw values, but we
// scale them back up to the full 0.0 - 1.0 range
const float rangeScale = 1.0f / ( range - threshold ) ;
idVec2 reScaled = threshed * rangeScale ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const float rescaledLen = reScaled . Length ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if inside the deadband area, return a solid 0,0
2012-11-28 15:47:07 +00:00
if ( rescaledLen < = 0.0f )
{
2012-11-26 18:58:24 +00:00
return idVec2 ( 0.0f , 0.0f ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
reScaled . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// apply the acceleration
float accelerated ;
2012-11-28 15:47:07 +00:00
if ( shape = = FUNC_EXPONENTIAL )
{
2012-11-26 18:58:24 +00:00
accelerated = idMath : : Pow ( 1.04712854805f , rescaledLen * 100.0f ) * 0.01f ;
2012-11-28 15:47:07 +00:00
}
else if ( shape = = FUNC_LOGARITHMIC )
{
2012-11-26 18:58:24 +00:00
const float power = 2.0f ;
accelerated = idMath : : Pow ( rescaledLen , power ) ;
2012-11-28 15:47:07 +00:00
}
else // FUNC_LINEAR
{
2012-11-26 18:58:24 +00:00
accelerated = rescaledLen ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// optionally slow down for aim-assist
const float aimAssisted = accelerated * aimAssistScale ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const float clamped = ( aimAssisted > 1.0f ) ? 1.0f : aimAssisted ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return reScaled * clamped ;
}
/*
= = = = = = = = = = = = = = = = =
DrawJoypadTexture
Draws axis and threshold / range rings into an RGBA image
= = = = = = = = = = = = = = = = =
*/
void DrawJoypadTexture (
const int size ,
byte image [ ] ,
const idVec2 raw ,
const float threshold ,
const float range ,
const transferFunction_t shape ,
2012-11-28 15:47:07 +00:00
const bool mergedThreshold )
{
2012-11-26 18:58:24 +00:00
// assert( raw.x >= -1.0f && raw.x <= 1.0f && raw.y >= -1.0f && raw.y <= 1.0f );
idVec2 clamped ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < 2 ; i + + )
{
2012-11-26 18:58:24 +00:00
clamped [ i ] = Max ( - 1.0f , Min ( raw [ i ] , 1.0f ) ) ;
}
2012-11-28 15:47:07 +00:00
const int halfSize = size / 2 ;
2012-11-26 18:58:24 +00:00
// find the offsets that will give certain values for
// the rings
static const int NUM_RINGS = 5 ;
float ringSizes [ NUM_RINGS ] = { } ;
float ringValue [ NUM_RINGS ] = { 0.0f , 0.25f , 0.5f , 0.75f , 0.99f } ;
int ringNum = 0 ;
2012-11-28 15:47:07 +00:00
for ( int i = 1 ; i < size ; i + + )
{
const float v = ( float ) i / ( size - 1 ) ;
2012-11-26 18:58:24 +00:00
const idVec2 mapped = JoypadFunction (
2012-11-28 15:47:07 +00:00
idVec2 ( v , 0.0f ) , 1.0f , threshold , range , shape , mergedThreshold ) ;
if ( mapped . x > ringValue [ ringNum ] )
{
2012-11-26 18:58:24 +00:00
ringSizes [ ringNum ] = v * halfSize ;
ringNum + + ;
2012-11-28 15:47:07 +00:00
if ( ringNum = = NUM_RINGS )
{
2012-11-26 18:58:24 +00:00
break ;
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
memset ( image , 0 , size * size * 4 ) ;
# define PLOT(x,y) ((int *)image)[(int)(y)*size+(int)(x)]=0xffffffff
# define CPLOT(x,y) ((int *)image)[(int)(halfSize+y)*size+(int)(halfSize+x)]=0xffffffff
2012-11-28 15:47:07 +00:00
int clampedX = halfSize + Min ( halfSize - 1 , ( int ) ( halfSize * clamped . x ) ) ;
int clampedY = halfSize + Min ( halfSize - 1 , ( int ) ( halfSize * clamped . y ) ) ;
2012-11-26 18:58:24 +00:00
// draw the box edge outline and center lines
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < size ; i + + )
{
2012-11-26 18:58:24 +00:00
PLOT ( i , 0 ) ;
2012-11-28 15:47:07 +00:00
PLOT ( i , size - 1 ) ;
2012-11-26 18:58:24 +00:00
PLOT ( 0 , i ) ;
2012-11-28 15:47:07 +00:00
PLOT ( size - 1 , i ) ;
2012-11-26 18:58:24 +00:00
PLOT ( i , clampedY ) ;
PLOT ( clampedX , i ) ;
}
const int iThresh = size * threshold * 0.5f ;
2012-11-28 15:47:07 +00:00
if ( ! mergedThreshold )
{
2012-11-26 18:58:24 +00:00
const int open = size * 0.5f - iThresh ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < open ; i + + )
{
2012-11-26 18:58:24 +00:00
PLOT ( i , halfSize - iThresh ) ;
PLOT ( i , halfSize + iThresh ) ;
2012-11-28 15:47:07 +00:00
PLOT ( size - 1 - i , halfSize - iThresh ) ;
PLOT ( size - 1 - i , halfSize + iThresh ) ;
2012-11-26 18:58:24 +00:00
PLOT ( halfSize - iThresh , i ) ;
PLOT ( halfSize + iThresh , i ) ;
2012-11-28 15:47:07 +00:00
PLOT ( halfSize - iThresh , size - 1 - i ) ;
PLOT ( halfSize + iThresh , size - 1 - i ) ;
2012-11-26 18:58:24 +00:00
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// I'm not going to bother writing a proper circle drawing algorithm...
const int octantPoints = size * 2 ;
float rad = 0.0f ;
float radStep = idMath : : PI / ( 4 * octantPoints ) ;
2012-11-28 15:47:07 +00:00
for ( int point = 0 ; point < octantPoints ; point + + , rad + = radStep )
{
2012-11-26 18:58:24 +00:00
float s , c ;
idMath : : SinCos ( rad , s , c ) ;
2012-11-28 15:47:07 +00:00
for ( int ringNum = 0 ; ringNum < NUM_RINGS ; ringNum + + )
{
2012-11-26 18:58:24 +00:00
const float ringSize = ringSizes [ ringNum ] ;
const int ix = idMath : : Floor ( ringSize * c ) ;
const int iy = idMath : : Floor ( ringSize * s ) ;
#if 0
2012-11-28 15:47:07 +00:00
if ( ! mergedThreshold & & ( ix < iThresh | | iy < iThresh ) )
{
2012-11-26 18:58:24 +00:00
continue ;
}
# endif
CPLOT ( ix , iy ) ;
CPLOT ( iy , ix ) ;
CPLOT ( - ix , iy ) ;
CPLOT ( - iy , ix ) ;
CPLOT ( ix , - iy ) ;
CPLOT ( iy , - ix ) ;
CPLOT ( - ix , - iy ) ;
CPLOT ( - iy , - ix ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
# undef PLOT
}
static idVec2 lastLookJoypad ;
/*
= = = = = = = = = = = = = = = = =
DrawJoypadTexture
Can be called to fill in a scratch texture for visualization
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void DrawJoypadTexture ( const int size , byte image [ ] )
{
2012-11-26 18:58:24 +00:00
const float threshold = joy_deadZone . GetFloat ( ) ;
const float range = joy_range . GetFloat ( ) ;
const bool mergedThreshold = joy_mergedThreshold . GetBool ( ) ;
2012-11-28 15:47:07 +00:00
const transferFunction_t shape = ( transferFunction_t ) joy_gammaLook . GetInteger ( ) ;
2012-11-26 18:58:24 +00:00
DrawJoypadTexture ( size , image , lastLookJoypad , threshold , range , shape , mergedThreshold ) ;
}
/*
= = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : JoystickMove2
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : JoystickMove2 ( )
{
2012-11-26 18:58:24 +00:00
const bool invertLook = in_invertLook . GetBool ( ) ;
const float threshold = joy_deadZone . GetFloat ( ) ;
const float range = joy_range . GetFloat ( ) ;
2012-11-28 15:47:07 +00:00
const transferFunction_t shape = ( transferFunction_t ) joy_gammaLook . GetInteger ( ) ;
2012-11-26 18:58:24 +00:00
const bool mergedThreshold = joy_mergedThreshold . GetBool ( ) ;
const float pitchSpeed = joy_pitchSpeed . GetFloat ( ) ;
const float yawSpeed = joy_yawSpeed . GetFloat ( ) ;
2012-11-28 15:47:07 +00:00
idGame * game = common - > Game ( ) ;
2012-11-26 18:58:24 +00:00
const float aimAssist = game ! = NULL ? game - > GetAimAssistSensitivity ( ) : 1.0f ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec2 leftRaw ( joystickAxis [ AXIS_LEFT_X ] , joystickAxis [ AXIS_LEFT_Y ] ) ;
idVec2 rightRaw ( joystickAxis [ AXIS_RIGHT_X ] , joystickAxis [ AXIS_RIGHT_Y ] ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// optional stick swap
2012-11-28 15:47:07 +00:00
if ( idKeyInput : : GetUsercmdAction ( K_JOY_STICK1_LEFT ) = = UB_LOOKLEFT )
{
2012-11-26 18:58:24 +00:00
const idVec2 temp = leftRaw ;
leftRaw = rightRaw ;
rightRaw = temp ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// optional invert look by inverting the right Y axis
2012-11-28 15:47:07 +00:00
if ( invertLook )
{
2012-11-26 18:58:24 +00:00
rightRaw . y = - rightRaw . y ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// save for visualization
lastLookJoypad = rightRaw ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec2 leftMapped = JoypadFunction ( leftRaw , 1.0f , threshold , range , shape , mergedThreshold ) ;
idVec2 rightMapped = JoypadFunction ( rightRaw , aimAssist , threshold , range , shape , mergedThreshold ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// because idPhysics_Player::CmdScale scales mvoement values down so that 1,1 = sqrt(2), sqrt(2),
// we need to expand our circular values out to a square
CircleToSquare ( leftMapped . x , leftMapped . y ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// add on top of mouse / keyboard move values
cmd . forwardmove = idMath : : ClampChar ( cmd . forwardmove + KEY_MOVESPEED * - leftMapped . y ) ;
cmd . rightmove = idMath : : ClampChar ( cmd . rightmove + KEY_MOVESPEED * leftMapped . x ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
viewangles [ PITCH ] + = MS2SEC ( pollTime - lastPollTime ) * rightMapped . y * pitchSpeed ;
viewangles [ YAW ] + = MS2SEC ( pollTime - lastPollTime ) * - rightMapped . x * yawSpeed ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const float triggerThreshold = joy_triggerThreshold . GetFloat ( ) ;
HandleJoystickAxis ( K_JOY_TRIGGER1 , joystickAxis [ AXIS_LEFT_TRIG ] , triggerThreshold , true ) ;
HandleJoystickAxis ( K_JOY_TRIGGER2 , joystickAxis [ AXIS_RIGHT_TRIG ] , triggerThreshold , true ) ;
}
/*
= = = = = = = = = = = = = =
idUsercmdGenLocal : : CmdButtons
= = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : CmdButtons ( )
{
2012-11-26 18:58:24 +00:00
cmd . buttons = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check the attack button
2012-11-28 15:47:07 +00:00
if ( ButtonState ( UB_ATTACK ) )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_ATTACK ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check the use button
2012-11-28 15:47:07 +00:00
if ( ButtonState ( UB_USE ) )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_USE ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check the run button
2012-11-28 15:47:07 +00:00
if ( toggled_run . on | | ( in_alwaysRun . GetBool ( ) & & common - > IsMultiplayer ( ) ) )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_RUN ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check the zoom button
2012-11-28 15:47:07 +00:00
if ( toggled_zoom . on )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_ZOOM ;
}
2012-11-28 15:47:07 +00:00
if ( ButtonState ( UB_MOVEUP ) )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_JUMP ;
}
2012-11-28 15:47:07 +00:00
if ( toggled_crouch . on )
{
2012-11-26 18:58:24 +00:00
cmd . buttons | = BUTTON_CROUCH ;
}
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : InitCurrent
inits the current command for this frame
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : InitCurrent ( )
{
2012-11-26 18:58:24 +00:00
memset ( & cmd , 0 , sizeof ( cmd ) ) ;
cmd . impulseSequence = impulseSequence ;
cmd . impulse = impulse ;
cmd . buttons | = ( in_alwaysRun . GetBool ( ) & & common - > IsMultiplayer ( ) ) ? BUTTON_RUN : 0 ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : MakeCurrent
creates the current command for this frame
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : MakeCurrent ( )
{
2012-11-26 18:58:24 +00:00
idVec3 oldAngles = viewangles ;
2012-11-28 15:47:07 +00:00
if ( ! Inhibited ( ) )
{
2012-11-26 18:58:24 +00:00
// update toggled key states
toggled_crouch . SetKeyState ( ButtonState ( UB_MOVEDOWN ) , in_toggleCrouch . GetBool ( ) ) ;
toggled_run . SetKeyState ( ButtonState ( UB_SPEED ) , in_toggleRun . GetBool ( ) & & common - > IsMultiplayer ( ) ) ;
toggled_zoom . SetKeyState ( ButtonState ( UB_ZOOM ) , in_toggleZoom . GetBool ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// get basic movement from mouse
MouseMove ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// get basic movement from joystick and set key bits
// must be done before CmdButtons!
2012-11-28 15:47:07 +00:00
if ( joy_newCode . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
JoystickMove2 ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
JoystickMove ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// keyboard angle adjustment
AdjustAngles ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set button bits
CmdButtons ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// get basic movement from keyboard
KeyMove ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// aim assist
AimAssist ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check to make sure the angles haven't wrapped
2012-11-28 15:47:07 +00:00
if ( viewangles [ PITCH ] - oldAngles [ PITCH ] > 90 )
{
2012-11-26 18:58:24 +00:00
viewangles [ PITCH ] = oldAngles [ PITCH ] + 90 ;
2012-11-28 15:47:07 +00:00
}
else if ( oldAngles [ PITCH ] - viewangles [ PITCH ] > 90 )
{
2012-11-26 18:58:24 +00:00
viewangles [ PITCH ] = oldAngles [ PITCH ] - 90 ;
2012-11-28 15:47:07 +00:00
}
}
else
{
2012-11-26 18:58:24 +00:00
mouseDx = 0 ;
mouseDy = 0 ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < 3 ; i + + )
{
2012-11-26 18:58:24 +00:00
cmd . angles [ i ] = ANGLE2SHORT ( viewangles [ i ] ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
cmd . mx = continuousMouseX ;
cmd . my = continuousMouseY ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
impulseSequence = cmd . impulseSequence ;
impulse = cmd . impulse ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : AimAssist
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : AimAssist ( )
{
2012-11-26 18:58:24 +00:00
// callback to the game to update the aim assist for the current device
idAngles aimAssistAngles ( 0.0f , 0.0f , 0.0f ) ;
2012-11-28 15:47:07 +00:00
idGame * game = common - > Game ( ) ;
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
game - > GetAimAssistAngles ( aimAssistAngles ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
viewangles [ YAW ] + = aimAssistAngles . yaw ;
viewangles [ PITCH ] + = aimAssistAngles . pitch ;
viewangles [ ROLL ] + = aimAssistAngles . roll ;
}
//=====================================================================
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : CommandStringUsercmdData
Returns the button if the command string is used by the usercmd generator .
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
int idUsercmdGenLocal : : CommandStringUsercmdData ( const char * cmdString )
{
for ( userCmdString_t * ucs = userCmdStrings ; ucs - > string ; ucs + + )
{
if ( idStr : : Icmp ( cmdString , ucs - > string ) = = 0 )
{
2012-11-26 18:58:24 +00:00
return ucs - > button ;
}
}
return UB_NONE ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Init
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Init ( )
{
2012-11-26 18:58:24 +00:00
initialized = true ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : InitForNewMap
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : InitForNewMap ( )
{
2012-11-26 18:58:24 +00:00
impulseSequence = 0 ;
impulse = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
toggled_crouch . Clear ( ) ;
toggled_run . Clear ( ) ;
toggled_zoom . Clear ( ) ;
toggled_run . on = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Clear ( ) ;
ClearAngles ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Shutdown
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Shutdown ( )
{
2012-11-26 18:58:24 +00:00
initialized = false ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Clear
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Clear ( )
{
// clears all key states
2012-11-26 18:58:24 +00:00
memset ( buttonState , 0 , sizeof ( buttonState ) ) ;
memset ( keyState , false , sizeof ( keyState ) ) ;
memset ( joystickAxis , 0 , sizeof ( joystickAxis ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
inhibitCommands = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mouseDx = mouseDy = 0 ;
mouseButton = 0 ;
mouseDown = false ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : ClearAngles
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : ClearAngles ( )
{
2012-11-26 18:58:24 +00:00
viewangles . Zero ( ) ;
}
//======================================================================
/*
= = = = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Key
Handles mouse / keyboard button actions
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Key ( int keyNum , bool down )
{
2012-11-26 18:58:24 +00:00
// Sanity check, sometimes we get double message :(
2012-11-28 15:47:07 +00:00
if ( keyState [ keyNum ] = = down )
{
2012-11-26 18:58:24 +00:00
return ;
}
keyState [ keyNum ] = down ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int action = idKeyInput : : GetUsercmdAction ( keyNum ) ;
2012-11-28 15:47:07 +00:00
if ( down )
{
2012-11-26 18:58:24 +00:00
buttonState [ action ] + + ;
2012-11-28 15:47:07 +00:00
if ( ! Inhibited ( ) )
{
if ( action > = UB_IMPULSE0 & & action < = UB_IMPULSE31 )
{
2012-11-26 18:58:24 +00:00
cmd . impulse = action - UB_IMPULSE0 ;
cmd . impulseSequence + + ;
}
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
buttonState [ action ] - - ;
// we might have one held down across an app active transition
2012-11-28 15:47:07 +00:00
if ( buttonState [ action ] < 0 )
{
2012-11-26 18:58:24 +00:00
buttonState [ action ] = 0 ;
}
}
}
/*
= = = = = = = = = = = = = = = = = = =
idUsercmdGenLocal : : Mouse
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Mouse ( )
{
2012-11-26 18:58:24 +00:00
int mouseEvents [ MAX_MOUSE_EVENTS ] [ 2 ] ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int numEvents = Sys_PollMouseInputEvents ( mouseEvents ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Study each of the buffer elements and process them.
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < numEvents ; i + + )
{
2012-11-26 18:58:24 +00:00
int action = mouseEvents [ i ] [ 0 ] ;
int value = mouseEvents [ i ] [ 1 ] ;
2012-11-28 15:47:07 +00:00
switch ( action )
{
case M_ACTION1 :
case M_ACTION2 :
case M_ACTION3 :
case M_ACTION4 :
case M_ACTION5 :
case M_ACTION6 :
case M_ACTION7 :
case M_ACTION8 :
mouseButton = K_MOUSE1 + ( action - M_ACTION1 ) ;
mouseDown = ( value ! = 0 ) ;
Key ( mouseButton , mouseDown ) ;
break ;
case M_DELTAX :
mouseDx + = value ;
continuousMouseX + = value ;
break ;
case M_DELTAY :
mouseDy + = value ;
continuousMouseY + = value ;
break ;
case M_DELTAZ : // mouse wheel, may have multiple clicks
2012-11-26 18:58:24 +00:00
{
int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP ;
value = abs ( value ) ;
2012-11-28 15:47:07 +00:00
while ( value - - > 0 )
{
2012-11-26 18:58:24 +00:00
Key ( key , true ) ;
Key ( key , false ) ;
mouseButton = key ;
mouseDown = true ;
}
}
break ;
2012-11-28 15:47:07 +00:00
default : // some other undefined button
break ;
2012-11-26 18:58:24 +00:00
}
}
}
/*
= = = = = = = = = = = = = = =
idUsercmdGenLocal : : Keyboard
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Keyboard ( )
{
2012-11-26 18:58:24 +00:00
int numEvents = Sys_PollKeyboardInputEvents ( ) ;
2012-11-28 15:47:07 +00:00
// Study each of the buffer elements and process them.
for ( int i = 0 ; i < numEvents ; i + + )
{
2012-11-26 18:58:24 +00:00
int key ;
bool state ;
2012-11-28 15:47:07 +00:00
if ( Sys_ReturnKeyboardInputEvent ( i , key , state ) )
{
2012-11-26 18:58:24 +00:00
Key ( key , state ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Sys_EndKeyboardInputEvents ( ) ;
}
/*
= = = = = = = = = = = = = = =
idUsercmdGenLocal : : Joystick
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : Joystick ( int deviceNum )
{
2012-11-26 18:58:24 +00:00
int numEvents = Sys_PollJoystickInputEvents ( deviceNum ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Study each of the buffer elements and process them.
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < numEvents ; i + + )
{
2012-11-26 18:58:24 +00:00
int action ;
int value ;
2012-11-28 15:47:07 +00:00
if ( Sys_ReturnJoystickInputEvent ( i , action , value ) )
{
if ( action > = J_ACTION1 & & action < = J_ACTION_MAX )
{
2012-11-26 18:58:24 +00:00
int joyButton = K_JOY1 + ( action - J_ACTION1 ) ;
Key ( joyButton , ( value ! = 0 ) ) ;
2012-11-28 15:47:07 +00:00
}
else if ( ( action > = J_AXIS_MIN ) & & ( action < = J_AXIS_MAX ) )
{
2012-11-26 18:58:24 +00:00
joystickAxis [ action - J_AXIS_MIN ] = static_cast < float > ( value ) / 32767.0f ;
2012-11-28 15:47:07 +00:00
}
else if ( action > = J_DPAD_UP & & action < = J_DPAD_RIGHT )
{
2012-11-26 18:58:24 +00:00
int joyButton = K_JOY_DPAD_UP + ( action - J_DPAD_UP ) ;
Key ( joyButton , ( value ! = 0 ) ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
assert ( ! " Unknown joystick event " ) ;
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Sys_EndJoystickInputEvents ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : MouseState
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : MouseState ( int * x , int * y , int * button , bool * down )
{
2012-11-26 18:58:24 +00:00
* x = continuousMouseX ;
* y = continuousMouseY ;
* button = mouseButton ;
* down = mouseDown ;
}
/*
= = = = = = = = = = = = = = = =
idUsercmdGenLocal : : BuildCurrentUsercmd
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idUsercmdGenLocal : : BuildCurrentUsercmd ( int deviceNum )
{
2012-11-26 18:58:24 +00:00
pollTime = Sys_Milliseconds ( ) ;
2012-11-28 15:47:07 +00:00
if ( pollTime - lastPollTime > 100 )
{
2012-11-26 18:58:24 +00:00
lastPollTime = pollTime - 100 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize current usercmd
InitCurrent ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// process the system mouse events
Mouse ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// process the system keyboard events
Keyboard ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// process the system joystick events
2012-11-28 15:47:07 +00:00
if ( deviceNum > = 0 & & in_useJoystick . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
Joystick ( deviceNum ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// create the usercmd
MakeCurrent ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastPollTime = pollTime ;
}