Skip to content

Commit

Permalink
Input code fixes
Browse files Browse the repository at this point in the history
Fixes ValveSoftware/halflife#1546
- fixed m_rawinput 1 mouse trapped inside a rectangle
- fixed thirdperson camera not working as it should

Fixes ValveSoftware/halflife#1558
- recoded mousethread and made it somewhat useful for very fast mouse
  movements (will reset CursorPos now) and thus also fixed some thread
  synchronization issues (hopefully)

Further fixes:
- Fixed IN_JoyMove doing nothing on Linux for ricochet client
- Limited mouse thread sleep to sane values between 0 and 1000
  • Loading branch information
dtugend authored and SmileyAG committed Oct 13, 2014
1 parent 867221d commit 9d06062
Show file tree
Hide file tree
Showing 12 changed files with 621 additions and 433 deletions.
1 change: 0 additions & 1 deletion cl_dll/hud_redraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ int grgLogoFrame[MAX_LOGO_FRAMES] =
};


extern int g_iVisibleMouse;

float HUD_GetFOV( void );

Expand Down
110 changes: 43 additions & 67 deletions cl_dll/in_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "in_defs.h"
#include "Exports.h"

#include "SDL2/SDL_mouse.h"
#include "port.h"

float CL_KeyState (kbutton_t *key);
Expand All @@ -29,12 +28,13 @@ extern cl_enginefunc_t gEngfuncs;
#define CAM_ANGLE_DELTA 2.5
#define CAM_ANGLE_SPEED 2.5
#define CAM_MIN_DIST 30.0
#define CAM_ANGLE_MOVE .5
#define MAX_ANGLE_DIFF 10.0
#define PITCH_MAX 90.0
#define PITCH_MIN 0
#define YAW_MAX 135.0
#define YAW_MIN -135.0
#define CAM_DIST_MOUSEFAC 0.05
#define CAM_ANGLE_MOUSEFAC 1.67

enum ECAM_Command
{
Expand All @@ -45,6 +45,11 @@ enum ECAM_Command

//-------------------------------------------------- Global Variables

extern cvar_t *m_pitch;
extern cvar_t *m_yaw;
extern cvar_t *m_forward;
extern cvar_t *m_side;

cvar_t *cam_command;
cvar_t *cam_snapto;
cvar_t *cam_idealyaw;
Expand All @@ -68,9 +73,7 @@ int cam_thirdperson;
int cam_mousemove; //true if we are moving the cam with the mouse, False if not
int iMouseInUse=0;
int cam_distancemove;
extern int mouse_x, mouse_y; //used to determine what the current x and y values are
int cam_old_mouse_x, cam_old_mouse_y; //holds the last ticks mouse movement
POINT cam_mouse;

//-------------------------------------------------- Local Variables

static kbutton_t cam_pitchup, cam_pitchdown, cam_yawleft, cam_yawright;
Expand All @@ -83,14 +86,26 @@ void CAM_ToFirstPerson(void);
void CAM_StartDistance(void);
void CAM_EndDistance(void);

void SDL_GetCursorPos( POINT *p )
{
gEngfuncs.GetMousePosition( (int *)&p->x, (int *)&p->y );
// SDL_GetMouseState( (int *)&p->x, (int *)&p->y );
}
//--------------------------------------------------

// defined in inputw32.cpp:
void IN_GetMouseDelta( int *pOutX, int *pOuty);
void IN_ScaleMouse( float *x, float *y );

void SDL_SetCursorPos( const int x, const int y )
void CAM_GetScaledMouseDelta( float *pOutX, float *pOutY )
{
int x,y;
float fx, fy;

IN_GetMouseDelta( &x, &y );

fx = x;
fy = y;

IN_ScaleMouse( &fx, &fy );

if(pOutX) *pOutX = fx;
if(pOutY) *pOutY = fy;
}

//-------------------------------------------------- Local Functions
Expand Down Expand Up @@ -154,12 +169,12 @@ void CL_DLLEXPORT CAM_Think( void )
{
// RecClCamThink();

float cam_mouse_x, cam_mouse_y;
vec3_t origin;
vec3_t ext, pnt, camForward, camRight, camUp;
moveclip_t clip;
float dist;
vec3_t camAngles;
float flSensitivity;
#ifdef LATER
int i;
#endif
Expand Down Expand Up @@ -199,34 +214,34 @@ void CL_DLLEXPORT CAM_Think( void )
//
if (cam_mousemove)
{
//get windows cursor position
SDL_GetCursorPos (&cam_mouse);
//get mouse cursor delta
CAM_GetScaledMouseDelta (&cam_mouse_x,&cam_mouse_y);
//check for X delta values and adjust accordingly
//eventually adjust YAW based on amount of movement
//don't do any movement of the cam using YAW/PITCH if we are zooming in/out the camera
if (!cam_distancemove)
{

//keep the camera within certain limits around the player (ie avoid certain bad viewing angles)
if (cam_mouse.x>gEngfuncs.GetWindowCenterX())
if (cam_mouse_x>0)
{
//if ((camAngles[YAW]>=225.0)||(camAngles[YAW]<135.0))
if (camAngles[YAW]<c_maxyaw->value)
{
camAngles[ YAW ] += (CAM_ANGLE_MOVE)*((cam_mouse.x-gEngfuncs.GetWindowCenterX())/2);
camAngles[ YAW ] += CAM_ANGLE_MOUSEFAC * m_yaw->value * cam_mouse_x;
}
if (camAngles[YAW]>c_maxyaw->value)
{

camAngles[YAW]=c_maxyaw->value;
}
}
else if (cam_mouse.x<gEngfuncs.GetWindowCenterX())
else if (cam_mouse_x<0)
{
//if ((camAngles[YAW]<=135.0)||(camAngles[YAW]>225.0))
if (camAngles[YAW]>c_minyaw->value)
{
camAngles[ YAW ] -= (CAM_ANGLE_MOVE)* ((gEngfuncs.GetWindowCenterX()-cam_mouse.x)/2);
camAngles[ YAW ] -= CAM_ANGLE_MOUSEFAC * m_yaw->value * -cam_mouse_x;

}
if (camAngles[YAW]<c_minyaw->value)
Expand All @@ -239,43 +254,28 @@ void CL_DLLEXPORT CAM_Think( void )
//check for y delta values and adjust accordingly
//eventually adjust PITCH based on amount of movement
//also make sure camera is within bounds
if (cam_mouse.y>gEngfuncs.GetWindowCenterY())
if (cam_mouse_y>0)
{
if(camAngles[PITCH]<c_maxpitch->value)
{
camAngles[PITCH] +=(CAM_ANGLE_MOVE)* ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2);
camAngles[PITCH] += CAM_ANGLE_MOUSEFAC * m_pitch->value * cam_mouse_y;
}
if (camAngles[PITCH]>c_maxpitch->value)
{
camAngles[PITCH]=c_maxpitch->value;
}
}
else if (cam_mouse.y<gEngfuncs.GetWindowCenterY())
else if (cam_mouse_y<0)
{
if (camAngles[PITCH]>c_minpitch->value)
{
camAngles[PITCH] -= (CAM_ANGLE_MOVE)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2);
camAngles[PITCH] -= CAM_ANGLE_MOUSEFAC * m_pitch->value * -cam_mouse_y;
}
if (camAngles[PITCH]<c_minpitch->value)
{
camAngles[PITCH]=c_minpitch->value;
}
}

//set old mouse coordinates to current mouse coordinates
//since we are done with the mouse

if ( ( flSensitivity = gHUD.GetSensitivity() ) != 0 )
{
cam_old_mouse_x=cam_mouse.x*flSensitivity;
cam_old_mouse_y=cam_mouse.y*flSensitivity;
}
else
{
cam_old_mouse_x=cam_mouse.x;
cam_old_mouse_y=cam_mouse.y;
}
SDL_SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
}

Expand Down Expand Up @@ -307,33 +307,28 @@ void CL_DLLEXPORT CAM_Think( void )

if (cam_distancemove)
{
if (cam_mouse.y>gEngfuncs.GetWindowCenterY())
if (cam_mouse_y>0)
{
if(dist<c_maxdistance->value)
{
dist +=CAM_DIST_DELTA * ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2);
dist += CAM_DIST_MOUSEFAC * m_forward->value * cam_mouse_y;
}
if (dist>c_maxdistance->value)
{
dist=c_maxdistance->value;
}
}
else if (cam_mouse.y<gEngfuncs.GetWindowCenterY())
else if (cam_mouse_y<0)
{
if (dist>c_mindistance->value)
{
dist -= (CAM_DIST_DELTA)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2);
dist -= CAM_DIST_MOUSEFAC * m_forward->value * -cam_mouse_y;
}
if (dist<c_mindistance->value)
{
dist=c_mindistance->value;
}
}
//set old mouse coordinates to current mouse coordinates
//since we are done with the mouse
cam_old_mouse_x=cam_mouse.x*gHUD.GetSensitivity();
cam_old_mouse_y=cam_mouse.y*gHUD.GetSensitivity();
SDL_SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
#ifdef LATER
if( cam_contain->value )
Expand Down Expand Up @@ -535,29 +530,14 @@ void CAM_ClearStates( void )

void CAM_StartMouseMove(void)
{
float flSensitivity;

//only move the cam with mouse if we are in third person.
if (cam_thirdperson)
{
//set appropriate flags and initialize the old mouse position
//variables for mouse camera movement
//set appropriate flags
if (!cam_mousemove)
{
cam_mousemove=1;
iMouseInUse=1;
SDL_GetCursorPos (&cam_mouse);

if ( ( flSensitivity = gHUD.GetSensitivity() ) != 0 )
{
cam_old_mouse_x=cam_mouse.x*flSensitivity;
cam_old_mouse_y=cam_mouse.y*flSensitivity;
}
else
{
cam_old_mouse_x=cam_mouse.x;
cam_old_mouse_y=cam_mouse.y;
}
}
}
//we are not in 3rd person view..therefore do not allow camera movement
Expand Down Expand Up @@ -586,16 +566,12 @@ void CAM_StartDistance(void)
//only move the cam with mouse if we are in third person.
if (cam_thirdperson)
{
//set appropriate flags and initialize the old mouse position
//variables for mouse camera movement
//set appropriate flags
if (!cam_distancemove)
{
cam_distancemove=1;
cam_mousemove=1;
iMouseInUse=1;
SDL_GetCursorPos (&cam_mouse);
cam_old_mouse_x=cam_mouse.x*gHUD.GetSensitivity();
cam_old_mouse_y=cam_mouse.y*gHUD.GetSensitivity();
}
}
//we are not in 3rd person view..therefore do not allow camera movement
Expand Down
Loading

0 comments on commit 9d06062

Please sign in to comment.