client: add input code from FWGS's hlsdk-portable
This commit is contained in:
parent
fda1caafd6
commit
d658b36616
1626
cl_dll/input_goldsource.cpp
Normal file
1626
cl_dll/input_goldsource.cpp
Normal file
File diff suppressed because it is too large
Load Diff
83
cl_dll/input_mouse.cpp
Normal file
83
cl_dll/input_mouse.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include "input_mouse.h"
|
||||
#include "exportdef.h"
|
||||
#include "hud.h"
|
||||
#include "cl_util.h"
|
||||
|
||||
// shared between backends
|
||||
Vector dead_viewangles(0, 0, 0);
|
||||
cvar_t *sensitivity;
|
||||
cvar_t *in_joystick;
|
||||
|
||||
FWGSInput fwgsInput;
|
||||
|
||||
#if SUPPORT_GOLDSOURCE_INPUT
|
||||
GoldSourceInput goldSourceInput;
|
||||
AbstractInput* currentInput = &goldSourceInput;
|
||||
#else
|
||||
AbstractInput* currentInput = &fwgsInput;
|
||||
#endif
|
||||
extern "C" void DLLEXPORT IN_ClientMoveEvent( float forwardmove, float sidemove )
|
||||
{
|
||||
currentInput->IN_ClientMoveEvent(forwardmove, sidemove);
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_ClientLookEvent( float relyaw, float relpitch )
|
||||
{
|
||||
currentInput->IN_ClientLookEvent(relyaw, relpitch);
|
||||
}
|
||||
|
||||
void IN_Move( float frametime, usercmd_t *cmd )
|
||||
{
|
||||
currentInput->IN_Move(frametime, cmd);
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_MouseEvent( int mstate )
|
||||
{
|
||||
currentInput->IN_MouseEvent(mstate);
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_ClearStates( void )
|
||||
{
|
||||
currentInput->IN_ClearStates();
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_ActivateMouse( void )
|
||||
{
|
||||
currentInput->IN_ActivateMouse();
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_DeactivateMouse( void )
|
||||
{
|
||||
currentInput->IN_DeactivateMouse();
|
||||
}
|
||||
|
||||
extern "C" void DLLEXPORT IN_Accumulate( void )
|
||||
{
|
||||
currentInput->IN_Accumulate();
|
||||
}
|
||||
|
||||
void IN_Commands( void )
|
||||
{
|
||||
currentInput->IN_Commands();
|
||||
}
|
||||
|
||||
void IN_Shutdown( void )
|
||||
{
|
||||
currentInput->IN_Shutdown();
|
||||
}
|
||||
|
||||
void IN_Init( void )
|
||||
{
|
||||
#if SUPPORT_GOLDSOURCE_INPUT
|
||||
//if (IsXashFWGS()) {
|
||||
// gEngfuncs.Con_Printf( "FWGS Xash3D input is in use\n" );
|
||||
// currentInput = &fwgsInput;
|
||||
//} else {
|
||||
gEngfuncs.Con_Printf( "GoldSource input is in use\n" );
|
||||
currentInput = &goldSourceInput;
|
||||
//}
|
||||
#else
|
||||
currentInput = &fwgsInput;
|
||||
#endif
|
||||
currentInput->IN_Init();
|
||||
}
|
95
cl_dll/input_mouse.h
Normal file
95
cl_dll/input_mouse.h
Normal file
@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
#if !defined(INPUT_MOUSE_H)
|
||||
#define INPUT_MOUSE_H
|
||||
#include "wrect.h"
|
||||
#include "cl_dll.h"
|
||||
#include "usercmd.h"
|
||||
#include "in_defs.h"
|
||||
|
||||
class AbstractInput
|
||||
{
|
||||
public:
|
||||
virtual void IN_ClientMoveEvent( float forwardmove, float sidemove ) = 0;
|
||||
virtual void IN_ClientLookEvent( float relyaw, float relpitch ) = 0;
|
||||
virtual void IN_Move( float frametime, usercmd_t *cmd ) = 0;
|
||||
virtual void IN_MouseEvent( int mstate ) = 0;
|
||||
virtual void IN_ClearStates( void ) = 0;
|
||||
virtual void IN_ActivateMouse( void ) = 0;
|
||||
virtual void IN_DeactivateMouse( void ) = 0;
|
||||
virtual void IN_Accumulate( void ) = 0;
|
||||
virtual void IN_Commands( void ) = 0;
|
||||
virtual void IN_Shutdown( void ) = 0;
|
||||
virtual void IN_Init( void ) = 0;
|
||||
};
|
||||
|
||||
class FWGSInput : public AbstractInput
|
||||
{
|
||||
public:
|
||||
virtual void IN_ClientMoveEvent( float forwardmove, float sidemove );
|
||||
virtual void IN_ClientLookEvent( float relyaw, float relpitch );
|
||||
virtual void IN_Move( float frametime, usercmd_t *cmd );
|
||||
virtual void IN_MouseEvent( int mstate );
|
||||
virtual void IN_ClearStates( void );
|
||||
virtual void IN_ActivateMouse( void );
|
||||
virtual void IN_DeactivateMouse( void );
|
||||
virtual void IN_Accumulate( void );
|
||||
virtual void IN_Commands( void );
|
||||
virtual void IN_Shutdown( void );
|
||||
virtual void IN_Init( void );
|
||||
|
||||
protected:
|
||||
float ac_forwardmove;
|
||||
float ac_sidemove;
|
||||
int ac_movecount;
|
||||
float rel_yaw;
|
||||
float rel_pitch;
|
||||
};
|
||||
|
||||
// No need for goldsource input support on the platforms that are not supported by GoldSource.
|
||||
#if GOLDSOURCE_SUPPORT && (_WIN32 || (__linux__ && !__ANDROID__) || __APPLE__) && (__i386 || _M_IX86)
|
||||
#define SUPPORT_GOLDSOURCE_INPUT 1
|
||||
|
||||
#if _WIN32
|
||||
#define HSPRITE WINDOWS_HSPRITE
|
||||
#include <windows.h>
|
||||
#undef HSPRITE
|
||||
#else
|
||||
typedef struct point_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} POINT;
|
||||
#define GetCursorPos(x)
|
||||
#define SetCursorPos(x,y)
|
||||
#endif
|
||||
|
||||
class GoldSourceInput : public AbstractInput
|
||||
{
|
||||
public:
|
||||
virtual void IN_ClientMoveEvent( float forwardmove, float sidemove ) {}
|
||||
virtual void IN_ClientLookEvent( float relyaw, float relpitch ) {}
|
||||
virtual void IN_Move( float frametime, usercmd_t *cmd );
|
||||
virtual void IN_MouseEvent( int mstate );
|
||||
virtual void IN_ClearStates( void );
|
||||
virtual void IN_ActivateMouse( void );
|
||||
virtual void IN_DeactivateMouse( void );
|
||||
virtual void IN_Accumulate( void );
|
||||
virtual void IN_Commands( void );
|
||||
virtual void IN_Shutdown( void );
|
||||
virtual void IN_Init( void );
|
||||
|
||||
protected:
|
||||
void IN_GetMouseDelta( int *pOutX, int *pOutY);
|
||||
void IN_MouseMove ( float frametime, usercmd_t *cmd);
|
||||
void IN_StartupMouse (void);
|
||||
|
||||
int mouse_buttons;
|
||||
int mouse_oldbuttonstate;
|
||||
POINT current_pos;
|
||||
int old_mouse_x, old_mouse_y, mx_accum, my_accum;
|
||||
int mouseinitialized;
|
||||
void* sdl2Lib;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
282
cl_dll/input_xash3d.cpp
Normal file
282
cl_dll/input_xash3d.cpp
Normal file
@ -0,0 +1,282 @@
|
||||
#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;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
#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
|
||||
|
||||
#define BUTTON_DOWN 1
|
||||
#define IMPULSE_DOWN 2
|
||||
#define IMPULSE_UP 4
|
||||
|
||||
int CL_IsDead( void );
|
||||
extern Vector dead_viewangles;
|
||||
|
||||
void IN_ToggleButtons( float forwardmove, float sidemove )
|
||||
{
|
||||
static unsigned int moveflags = T | S;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if( forwardmove > 0.7f && !( moveflags & F ) )
|
||||
{
|
||||
moveflags |= F;
|
||||
in_forward.state |= BUTTON_DOWN;
|
||||
}
|
||||
if( forwardmove < 0.7f && ( moveflags & F ) )
|
||||
{
|
||||
moveflags &= ~F;
|
||||
in_forward.state &= ~BUTTON_DOWN;
|
||||
}
|
||||
if( forwardmove < -0.7f && !( moveflags & B ) )
|
||||
{
|
||||
moveflags |= B;
|
||||
in_back.state |= BUTTON_DOWN;
|
||||
}
|
||||
if( forwardmove > -0.7f && ( moveflags & B ) )
|
||||
{
|
||||
moveflags &= ~B;
|
||||
in_back.state &= ~BUTTON_DOWN;
|
||||
}
|
||||
if( sidemove > 0.9f && !( moveflags & R ) )
|
||||
{
|
||||
moveflags |= R;
|
||||
in_moveright.state |= BUTTON_DOWN;
|
||||
}
|
||||
if( sidemove < 0.9f && ( moveflags & R ) )
|
||||
{
|
||||
moveflags &= ~R;
|
||||
in_moveright.state &= ~BUTTON_DOWN;
|
||||
}
|
||||
if( sidemove < -0.9f && !( moveflags & L ) )
|
||||
{
|
||||
moveflags |= L;
|
||||
in_moveleft.state |= BUTTON_DOWN;
|
||||
}
|
||||
if( sidemove > -0.9f && ( moveflags & L ) )
|
||||
{
|
||||
moveflags &= ~L;
|
||||
in_moveleft.state &= ~BUTTON_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void FWGSInput::IN_ClientMoveEvent( float forwardmove, float sidemove )
|
||||
{
|
||||
//gEngfuncs.Con_Printf("IN_MoveEvent\n");
|
||||
|
||||
ac_forwardmove += forwardmove;
|
||||
ac_sidemove += sidemove;
|
||||
ac_movecount++;
|
||||
}
|
||||
|
||||
void FWGSInput::IN_ClientLookEvent( float relyaw, float relpitch )
|
||||
{
|
||||
rel_yaw += relyaw;
|
||||
rel_pitch += relpitch;
|
||||
}
|
||||
|
||||
// Rotate camera and add move values to usercmd
|
||||
void FWGSInput::IN_Move( float frametime, usercmd_t *cmd )
|
||||
{
|
||||
Vector viewangles;
|
||||
bool fLadder = false;
|
||||
|
||||
if( gHUD.m_iIntermission )
|
||||
return; // we can't move during intermission
|
||||
|
||||
if( cl_laddermode->value != 2 )
|
||||
{
|
||||
cl_entity_t *pplayer = gEngfuncs.GetLocalPlayer();
|
||||
if( pplayer )
|
||||
fLadder = pplayer->curstate.movetype == MOVETYPE_FLY;
|
||||
}
|
||||
//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() )
|
||||
{
|
||||
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;
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
dead_viewangles = viewangles; // keep them actual
|
||||
if( ac_movecount )
|
||||
{
|
||||
IN_ToggleButtons( ac_forwardmove / ac_movecount, ac_sidemove / ac_movecount );
|
||||
|
||||
if( ac_forwardmove )
|
||||
cmd->forwardmove = ac_forwardmove * cl_forwardspeed->value / ac_movecount;
|
||||
if( ac_sidemove )
|
||||
cmd->sidemove = ac_sidemove * cl_sidespeed->value / ac_movecount;
|
||||
if( ( in_speed.state & 1 ) && ( ac_sidemove || ac_forwardmove ) )
|
||||
{
|
||||
cmd->forwardmove *= cl_movespeedkey->value;
|
||||
cmd->sidemove *= cl_movespeedkey->value;
|
||||
}
|
||||
}
|
||||
|
||||
ac_sidemove = ac_forwardmove = rel_pitch = rel_yaw = 0;
|
||||
ac_movecount = 0;
|
||||
}
|
||||
|
||||
void FWGSInput::IN_MouseEvent( int mstate )
|
||||
{
|
||||
static int mouse_oldbuttonstate;
|
||||
// perform button actions
|
||||
for( int i = 0; i < 5; i++ )
|
||||
{
|
||||
if( ( mstate & ( 1 << i ) ) && !( mouse_oldbuttonstate & ( 1 << i ) ) )
|
||||
{
|
||||
gEngfuncs.Key_Event( K_MOUSE1 + i, 1 );
|
||||
}
|
||||
|
||||
if( !( mstate & ( 1 << i ) ) && ( mouse_oldbuttonstate & ( 1 << i ) ) )
|
||||
{
|
||||
gEngfuncs.Key_Event( K_MOUSE1 + i, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
mouse_oldbuttonstate = mstate;
|
||||
}
|
||||
|
||||
// Stubs
|
||||
|
||||
void FWGSInput::IN_ClearStates( void )
|
||||
{
|
||||
//gEngfuncs.Con_Printf( "IN_ClearStates\n" );
|
||||
}
|
||||
|
||||
void FWGSInput::IN_ActivateMouse( void )
|
||||
{
|
||||
//gEngfuncs.Con_Printf( "IN_ActivateMouse\n" );
|
||||
}
|
||||
|
||||
void FWGSInput::IN_DeactivateMouse( void )
|
||||
{
|
||||
//gEngfuncs.Con_Printf( "IN_DeactivateMouse\n" );
|
||||
}
|
||||
|
||||
void FWGSInput::IN_Accumulate( void )
|
||||
{
|
||||
//gEngfuncs.Con_Printf( "IN_Accumulate\n" );
|
||||
}
|
||||
|
||||
void FWGSInput::IN_Commands( void )
|
||||
{
|
||||
//gEngfuncs.Con_Printf( "IN_Commands\n" );
|
||||
}
|
||||
|
||||
void FWGSInput::IN_Shutdown( void )
|
||||
{
|
||||
}
|
||||
|
||||
// Register cvars and reset data
|
||||
void FWGSInput::IN_Init( void )
|
||||
{
|
||||
sensitivity = gEngfuncs.pfnRegisterVariable( "sensitivity", "3", FCVAR_ARCHIVE );
|
||||
in_joystick = gEngfuncs.pfnRegisterVariable( "joystick", "0", FCVAR_ARCHIVE );
|
||||
cl_laddermode = gEngfuncs.pfnRegisterVariable( "cl_laddermode", "2", FCVAR_ARCHIVE );
|
||||
ac_forwardmove = ac_sidemove = rel_yaw = rel_pitch = 0;
|
||||
}
|
@ -57,7 +57,6 @@
|
||||
#include "vgui_ScorePanel.h"
|
||||
#include "tw_common.h"
|
||||
|
||||
extern int g_iVisibleMouse;
|
||||
class CCommandMenu;
|
||||
int g_iPlayerClass;
|
||||
int g_iTeamNumber;
|
||||
@ -76,6 +75,7 @@ int g_iUser3;
|
||||
#define SBOARD_INDENT_X_400 0
|
||||
#define SBOARD_INDENT_Y_400 20
|
||||
|
||||
void IN_SetVisibleMouse( bool );
|
||||
void IN_ResetMouse( void );
|
||||
extern CMenuPanel *CMessageWindowPanel_Create( const char *szMOTD, const char *szTitle, int iShadeFullscreen, int iRemoveMe, int iTextType, int x, int y, int wide, int tall );
|
||||
extern CMenuPanel *CItemSelectionPanel_Create(int x,int y,int wide,int tall);
|
||||
@ -1443,7 +1443,7 @@ void TheWastesViewport::UpdateCursorState()
|
||||
// Need cursor if any VGUI window is up
|
||||
if ( m_pCurrentMenu || m_pTeamMenu->isVisible() || m_pServerBrowser->isVisible() || GetClientVoiceMgr()->IsInSquelchMode() )
|
||||
{
|
||||
g_iVisibleMouse = true;
|
||||
IN_SetVisibleMouse( true );
|
||||
App::getInstance()->setCursorOveride( App::getInstance()->getScheme()->getCursor(Scheme::scu_arrow) );
|
||||
return;
|
||||
}
|
||||
@ -1452,14 +1452,14 @@ void TheWastesViewport::UpdateCursorState()
|
||||
// commandmenu doesn't have cursor if hud_capturemouse is turned off
|
||||
if ( gHUD.m_pCvarStealMouse->value != 0.0f )
|
||||
{
|
||||
g_iVisibleMouse = true;
|
||||
IN_SetVisibleMouse( true );
|
||||
App::getInstance()->setCursorOveride( App::getInstance()->getScheme()->getCursor(Scheme::scu_arrow) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
IN_ResetMouse();
|
||||
g_iVisibleMouse = false;
|
||||
IN_SetVisibleMouse( false );
|
||||
App::getInstance()->setCursorOveride( App::getInstance()->getScheme()->getCursor(Scheme::scu_none) );
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ def configure(conf):
|
||||
conf.env.INCLUDES_SDL = ['../external/SDL2']
|
||||
conf.env.LIBPATH_SDL = ['../linux']
|
||||
conf.env.LIB_SDL = ['SDL2']
|
||||
conf.define('GOLDSOURCE_SUPPORT', 1)
|
||||
conf.load('vgui')
|
||||
if not conf.check_vgui():
|
||||
conf.fatal('VGUI was enabled but VGUI cannot be used')
|
||||
@ -69,7 +70,9 @@ def build(bld):
|
||||
'./hud_update.cpp',
|
||||
'./in_camera.cpp',
|
||||
'./input.cpp',
|
||||
'./inputw32.cpp',
|
||||
'./input_mouse.cpp',
|
||||
'./input_goldsource.cpp',
|
||||
'./input_xash3d.cpp',
|
||||
'./menu.cpp',
|
||||
'./message.cpp',
|
||||
'./parsebsp.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user