hlsdk-xash3d/cl_dll/input_xash3d.cpp

286 lines
6.6 KiB
C++
Raw Normal View History

2016-02-24 22:26:16 +01:00
#include "hud.h"
#include "usercmd.h"
#include "cvardef.h"
#include "kbutton.h"
#include "keydefs.h"
#include "input_mouse.h"
extern cvar_t *sensitivity;
extern cvar_t *in_joystick;
2016-02-24 22:26:16 +01:00
extern kbutton_t in_strafe;
extern kbutton_t in_mlook;
extern kbutton_t in_speed;
extern kbutton_t in_jlook;
extern kbutton_t in_forward;
extern kbutton_t in_back;
extern kbutton_t in_moveleft;
extern kbutton_t in_moveright;
extern cvar_t *m_pitch;
extern cvar_t *m_yaw;
extern cvar_t *m_forward;
extern cvar_t *m_side;
extern cvar_t *lookstrafe;
extern cvar_t *lookspring;
extern cvar_t *cl_pitchdown;
extern cvar_t *cl_pitchup;
extern cvar_t *cl_yawspeed;
extern cvar_t *cl_sidespeed;
extern cvar_t *cl_forwardspeed;
extern cvar_t *cl_pitchspeed;
extern cvar_t *cl_movespeedkey;
cvar_t *cl_laddermode;
2016-03-01 21:18:42 +01:00
#define F 1U<<0 // Forward
#define B 1U<<1 // Back
#define L 1U<<2 // Left
#define R 1U<<3 // Right
#define T 1U<<4 // Forward stop
#define S 1U<<5 // Side stop
2016-02-24 22:26:16 +01:00
#define BUTTON_DOWN 1
#define IMPULSE_DOWN 2
#define IMPULSE_UP 4
2017-01-10 10:45:52 +01:00
int CL_IsDead( void );
extern Vector dead_viewangles;
2016-02-24 22:26:16 +01:00
void IN_ToggleButtons( float forwardmove, float sidemove )
{
2016-03-01 21:18:42 +01:00
static unsigned int moveflags = T | S;
2016-02-24 22:26:16 +01:00
if( forwardmove )
moveflags &= ~T;
else
{
//if( in_forward.state || in_back.state ) gEngfuncs.Con_Printf("Buttons pressed f%d b%d\n", in_forward.state, in_back.state);
if( !( moveflags & T ) )
{
//IN_ForwardUp();
//IN_BackUp();
//gEngfuncs.Con_Printf("Reset forwardmove state f%d b%d\n", in_forward.state, in_back.state);
in_forward.state &= ~BUTTON_DOWN;
in_back.state &= ~BUTTON_DOWN;
moveflags |= T;
}
}
if( sidemove )
moveflags &= ~S;
else
{
//gEngfuncs.Con_Printf("l%d r%d\n", in_moveleft.state, in_moveright.state);
//if( in_moveleft.state || in_moveright.state ) gEngfuncs.Con_Printf("Buttons pressed l%d r%d\n", in_moveleft.state, in_moveright.state);
if( !( moveflags & S ) )
{
//IN_MoverightUp();
//IN_MoveleftUp();
//gEngfuncs.Con_Printf("Reset sidemove state f%d b%d\n", in_moveleft.state, in_moveright.state);
in_moveleft.state &= ~BUTTON_DOWN;
in_moveright.state &= ~BUTTON_DOWN;
moveflags |= S;
}
}
2016-07-03 15:39:55 +02:00
if( forwardmove > 0.7 && !( moveflags & F ) )
2016-02-24 22:26:16 +01:00
{
moveflags |= F;
in_forward.state |= BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( forwardmove < 0.7 && ( moveflags & F ) )
2016-02-24 22:26:16 +01:00
{
moveflags &= ~F;
in_forward.state &= ~BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( forwardmove < -0.7 && !( moveflags & B ) )
2016-02-24 22:26:16 +01:00
{
moveflags |= B;
in_back.state |= BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( forwardmove > -0.7 && ( moveflags & B ) )
2016-02-24 22:26:16 +01:00
{
moveflags &= ~B;
in_back.state &= ~BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( sidemove > 0.9 && !( moveflags & R ) )
2016-02-24 22:26:16 +01:00
{
moveflags |= R;
in_moveright.state |= BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( sidemove < 0.9 && ( moveflags & R ) )
2016-02-24 22:26:16 +01:00
{
moveflags &= ~R;
in_moveright.state &= ~BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( sidemove < -0.9 && !( moveflags & L ) )
2016-02-24 22:26:16 +01:00
{
moveflags |= L;
in_moveleft.state |= BUTTON_DOWN;
}
2016-07-03 15:39:55 +02:00
if( sidemove > -0.9 && ( moveflags & L ) )
2016-02-24 22:26:16 +01:00
{
moveflags &= ~L;
in_moveleft.state &= ~BUTTON_DOWN;
}
}
void FWGSInput::IN_ClientMoveEvent( float forwardmove, float sidemove )
2016-02-24 22:26:16 +01:00
{
//gEngfuncs.Con_Printf("IN_MoveEvent\n");
ac_forwardmove += forwardmove;
ac_sidemove += sidemove;
ac_movecount++;
}
void FWGSInput::IN_ClientLookEvent( float relyaw, float relpitch )
2016-02-24 22:26:16 +01:00
{
rel_yaw += relyaw;
rel_pitch += relpitch;
}
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
// Rotate camera and add move values to usercmd
void FWGSInput::IN_Move( float frametime, usercmd_t *cmd )
2016-02-24 22:26:16 +01:00
{
Vector viewangles;
bool fLadder = false;
if( gHUD.m_iIntermission )
return; // we can't move during intermission
2016-07-03 15:39:55 +02:00
if( cl_laddermode->value != 2 )
{
cl_entity_t *pplayer = gEngfuncs.GetLocalPlayer();
if( pplayer )
fLadder = pplayer->curstate.movetype == MOVETYPE_FLY;
}
2016-02-24 22:26:16 +01:00
//if(ac_forwardmove || ac_sidemove)
//gEngfuncs.Con_Printf("Move: %f %f %f %f\n", ac_forwardmove, ac_sidemove, rel_pitch, rel_yaw);
#if 0
if( in_mlook.state & 1 )
{
V_StopPitchDrift();
}
#endif
if( CL_IsDead() )
2016-02-24 22:26:16 +01:00
{
viewangles = dead_viewangles; // HACKHACK: see below
}
else
{
gEngfuncs.GetViewAngles( viewangles );
}
if( gHUD.GetSensitivity() != 0 )
{
rel_yaw *= gHUD.GetSensitivity();
rel_pitch *= gHUD.GetSensitivity();
}
else
{
rel_yaw *= sensitivity->value;
rel_pitch *= sensitivity->value;
}
viewangles[YAW] += rel_yaw;
if( fLadder )
{
if( cl_laddermode->value == 1 )
viewangles[YAW] -= ac_sidemove * 5;
ac_sidemove = 0;
}
if( gHUD.m_MOTD.m_bShow )
gHUD.m_MOTD.scroll += rel_pitch;
else
2016-02-24 22:26:16 +01:00
viewangles[PITCH] += rel_pitch;
if( viewangles[PITCH] > cl_pitchdown->value )
viewangles[PITCH] = cl_pitchdown->value;
if( viewangles[PITCH] < -cl_pitchup->value )
viewangles[PITCH] = -cl_pitchup->value;
// HACKHACK: change viewangles directly in viewcode,
// so viewangles when player is dead will not be changed on server
if( !CL_IsDead() )
{
gEngfuncs.SetViewAngles( viewangles );
2016-02-24 22:26:16 +01:00
}
2016-07-03 15:39:55 +02:00
dead_viewangles = viewangles; // keep them actual
2016-02-24 22:26:16 +01:00
if( ac_movecount )
{
IN_ToggleButtons( ac_forwardmove / ac_movecount, ac_sidemove / ac_movecount );
2016-07-03 15:39:55 +02:00
if( ac_forwardmove )
cmd->forwardmove = ac_forwardmove * cl_forwardspeed->value / ac_movecount;
2016-07-03 15:39:55 +02:00
if( ac_sidemove )
cmd->sidemove = ac_sidemove * cl_sidespeed->value / ac_movecount;
if( ( in_speed.state & 1 ) && ( ac_sidemove || ac_forwardmove ) )
2016-04-17 16:31:24 +02:00
{
cmd->forwardmove *= cl_movespeedkey->value;
cmd->sidemove *= cl_movespeedkey->value;
}
2016-02-24 22:26:16 +01:00
}
2016-02-24 22:26:16 +01:00
ac_sidemove = ac_forwardmove = rel_pitch = rel_yaw = 0;
ac_movecount = 0;
}
void FWGSInput::IN_MouseEvent( int mstate )
2016-02-24 22:26:16 +01:00
{
static int mouse_oldbuttonstate;
// perform button actions
for( int i = 0; i < 5; i++ )
{
2016-07-03 15:39:55 +02:00
if( ( mstate & ( 1 << i ) ) && !( mouse_oldbuttonstate & ( 1 << i ) ) )
2016-02-24 22:26:16 +01:00
{
gEngfuncs.Key_Event( K_MOUSE1 + i, 1 );
}
2016-07-03 15:39:55 +02:00
if( !( mstate & ( 1 << i ) ) && ( mouse_oldbuttonstate & ( 1 << i ) ) )
2016-02-24 22:26:16 +01:00
{
gEngfuncs.Key_Event( K_MOUSE1 + i, 0 );
}
}
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
mouse_oldbuttonstate = mstate;
}
// Stubs
void FWGSInput::IN_ClearStates( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//gEngfuncs.Con_Printf( "IN_ClearStates\n" );
2016-02-24 22:26:16 +01:00
}
void FWGSInput::IN_ActivateMouse( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//gEngfuncs.Con_Printf( "IN_ActivateMouse\n" );
2016-02-24 22:26:16 +01:00
}
void FWGSInput::IN_DeactivateMouse( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//gEngfuncs.Con_Printf( "IN_DeactivateMouse\n" );
2016-02-24 22:26:16 +01:00
}
void FWGSInput::IN_Accumulate( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//gEngfuncs.Con_Printf( "IN_Accumulate\n" );
2016-02-24 22:26:16 +01:00
}
void FWGSInput::IN_Commands( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//gEngfuncs.Con_Printf( "IN_Commands\n" );
2016-02-24 22:26:16 +01:00
}
void FWGSInput::IN_Shutdown( void )
2016-02-24 22:26:16 +01:00
{
}
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
// Register cvars and reset data
void FWGSInput::IN_Init( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
sensitivity = gEngfuncs.pfnRegisterVariable( "sensitivity", "3", FCVAR_ARCHIVE );
in_joystick = gEngfuncs.pfnRegisterVariable( "joystick", "0", FCVAR_ARCHIVE );
cl_laddermode = gEngfuncs.pfnRegisterVariable( "cl_laddermode", "2", FCVAR_ARCHIVE );
2016-02-24 22:26:16 +01:00
ac_forwardmove = ac_sidemove = rel_yaw = rel_pitch = 0;
}