Use mouse input backend depending on the current engine

This commit is contained in:
Roman Chistokhodov 2017-12-03 23:52:35 +03:00
parent 31b2a68d6d
commit 1d8d1b5d2e
7 changed files with 204 additions and 57 deletions

View File

@ -27,7 +27,7 @@ set (CLDLL_LIBRARY client)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-write-strings -DLINUX -D_LINUX -Dstricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -DCLIENT_WEAPONS -DCLIENT_DLL -w")
if (GOLDSOURCE_SUPPORT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lSDL2 -Wl,--no-undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGOLDSOURCE_SUPPORT -lSDL2 -Wl,--no-undefined")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
@ -73,6 +73,9 @@ set (CLDLL_SOURCES
hud_update.cpp
in_camera.cpp
input.cpp
input_goldsource.cpp
input_mouse.cpp
input_xash3d.cpp
menu.cpp
message.cpp
overview.cpp
@ -93,12 +96,6 @@ set (CLDLL_SOURCES
scoreboard.cpp
MOTD.cpp)
if (GOLDSOURCE_SUPPORT)
set (CLDLL_SOURCES "${CLDLL_SOURCES}" input_goldsource.cpp)
else()
set (CLDLL_SOURCES "${CLDLL_SOURCES}" input_xash3d.cpp)
endif()
include_directories (. hl/ ../dlls ../dlls/wpn_shared ../common ../engine ../pm_shared ../game_shared ../public)
if(USE_VOICEMGR)

View File

@ -25,6 +25,8 @@
// - Drawing the HUD graphics every frame
// - Handling the custum HUD-update packets
//
#ifndef CL_DLL_H
#define CL_DLL_H
typedef unsigned char byte;
typedef unsigned short word;
typedef float vec_t;
@ -48,3 +50,4 @@ typedef int ( *pfnUserMsgHook )( const char *pszName, int iSize, void *pbuf );
extern cl_enginefunc_t gEngfuncs;
#include "../engine/mobility_int.h"
extern mobile_engfuncs_t *gMobileEngfuncs;
#endif

View File

@ -19,7 +19,8 @@
//
// CHud handles the message, calculation, and drawing the HUD
//
#ifndef HUD_H
#define HUD_H
#define RGB_YELLOWISH 0x00FFA000 //255,160,0
#define RGB_REDISH 0x00FF1010 //255,160,0
#define RGB_GREENISH 0x0000A000 //0,160,0
@ -677,3 +678,4 @@ extern int g_iTeamNumber;
extern int g_iUser1;
extern int g_iUser2;
extern int g_iUser3;
#endif

View File

@ -8,20 +8,20 @@
// in_win.c -- windows 95 mouse and joystick code
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
//#include "port.h"
#include "input_mouse.h"
#ifdef SUPPORT_GOLDSOURCE_INPUT
#include "hud.h"
#include "cl_util.h"
#include "camera.h"
#include "kbutton.h"
#include "cvardef.h"
#include "usercmd.h"
#include "const.h"
#include "camera.h"
#include "in_defs.h"
#include "keydefs.h"
#include "view.h"
//#include "Exports.h"
#ifndef _WIN32
#define USE_SDL2
@ -79,7 +79,7 @@ bool isMouseRelative = false;
extern globalvars_t *gpGlobals;
#endif
Vector dead_viewangles(0, 0, 0);
extern Vector dead_viewangles;
void V_StopPitchDrift( void )
{
@ -88,7 +88,7 @@ void V_StopPitchDrift( void )
// mouse variables
cvar_t *m_filter;
cvar_t *sensitivity;
extern cvar_t *sensitivity;
// Custom mouse acceleration (0 disable, 1 to enable, 2 enable with separate yaw/pitch rescale)
static cvar_t *m_customaccel;
@ -106,16 +106,11 @@ static cvar_t *m_customaccel_exponent;
static cvar_t *m_mousethread_sleep;
#endif
int mouse_buttons;
int mouse_oldbuttonstate;
POINT current_pos;
int old_mouse_x, old_mouse_y, mx_accum, my_accum;
float mouse_x, mouse_y;
static int restore_spi;
static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
static int mouseactive = 0;
int mouseinitialized;
static int mouseparmsvalid;
static int mouseshowtoggle = 1;
@ -158,7 +153,7 @@ SDL_GameController *s_pJoystick = NULL;
// each time. this avoids any problems with getting back to a default usage
// or when changing from one controller to another. this way at least something
// works.
cvar_t *in_joystick;
extern cvar_t *in_joystick;
cvar_t *joy_name;
cvar_t *joy_advanced;
cvar_t *joy_advaxisx;
@ -348,7 +343,7 @@ void IN_ResetMouse( void );
IN_ActivateMouse
===========
*/
extern "C" void DLLEXPORT IN_ActivateMouse (void)
void GoldSourceInput::IN_ActivateMouse (void)
{
if (mouseinitialized)
{
@ -376,7 +371,7 @@ extern "C" void DLLEXPORT IN_ActivateMouse (void)
IN_DeactivateMouse
===========
*/
extern "C" void DLLEXPORT IN_DeactivateMouse (void)
void GoldSourceInput::IN_DeactivateMouse (void)
{
if (mouseinitialized)
{
@ -400,7 +395,7 @@ extern "C" void DLLEXPORT IN_DeactivateMouse (void)
IN_StartupMouse
===========
*/
void IN_StartupMouse (void)
void GoldSourceInput::IN_StartupMouse (void)
{
if ( gEngfuncs.CheckParm ("-nomouse", NULL ) )
return;
@ -437,7 +432,7 @@ void IN_StartupMouse (void)
IN_Shutdown
===========
*/
void IN_Shutdown (void)
void GoldSourceInput::IN_Shutdown (void)
{
IN_DeactivateMouse ();
@ -521,7 +516,7 @@ void IN_ResetMouse( void )
IN_MouseEvent
===========
*/
extern "C" void DLLEXPORT IN_MouseEvent (int mstate)
void GoldSourceInput::IN_MouseEvent (int mstate)
{
int i;
@ -596,7 +591,7 @@ void IN_ScaleMouse( float *x, float *y )
}
}
void IN_GetMouseDelta( int *pOutX, int *pOutY)
void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY)
{
bool active = mouseactive && !iVisibleMouse;
int mx, my;
@ -715,7 +710,7 @@ void IN_GetMouseDelta( int *pOutX, int *pOutY)
IN_MouseMove
===========
*/
void IN_MouseMove ( float frametime, usercmd_t *cmd)
void GoldSourceInput::IN_MouseMove ( float frametime, usercmd_t *cmd)
{
int mx, my;
vec3_t viewangles;
@ -797,7 +792,7 @@ void IN_MouseMove ( float frametime, usercmd_t *cmd)
IN_Accumulate
===========
*/
extern "C" void DLLEXPORT IN_Accumulate (void)
void GoldSourceInput::IN_Accumulate (void)
{
//only accumulate mouse if we are not moving the camera with the mouse
if ( !iMouseInUse && !iVisibleMouse)
@ -850,7 +845,7 @@ extern "C" void DLLEXPORT IN_Accumulate (void)
IN_ClearStates
===================
*/
extern "C" void DLLEXPORT IN_ClearStates (void)
void GoldSourceInput::IN_ClearStates (void)
{
if ( !mouseactive )
return;
@ -999,7 +994,7 @@ void Joy_AdvancedUpdate_f (void)
IN_Commands
===========
*/
void IN_Commands (void)
void GoldSourceInput::IN_Commands (void)
{
int i, key_index;
@ -1274,7 +1269,7 @@ void IN_JoyMove ( float frametime, usercmd_t *cmd )
IN_Move
===========
*/
void IN_Move ( float frametime, usercmd_t *cmd)
void GoldSourceInput::IN_Move ( float frametime, usercmd_t *cmd)
{
if ( !iMouseInUse && mouseactive )
{
@ -1289,7 +1284,7 @@ void IN_Move ( float frametime, usercmd_t *cmd)
IN_Init
===========
*/
void IN_Init (void)
void GoldSourceInput::IN_Init (void)
{
m_filter = gEngfuncs.pfnRegisterVariable ( "m_filter","0", FCVAR_ARCHIVE );
sensitivity = gEngfuncs.pfnRegisterVariable ( "sensitivity","3", FCVAR_ARCHIVE ); // user mouse sensitivity setting.
@ -1355,3 +1350,5 @@ void IN_Init (void)
IN_StartupMouse ();
IN_StartupJoystick ();
}
#endif

82
cl_dll/input_mouse.cpp Normal file
View File

@ -0,0 +1,82 @@
#include "input_mouse.h"
#include "exportdef.h"
#include "hud.h"
// shared between backends
Vector dead_viewangles(0, 0, 0);
cvar_t *sensitivity;
cvar_t *in_joystick;
FWGSInput fwgsInput;
#ifdef 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 )
{
#ifdef SUPPORT_GOLDSOURCE_INPUT
if (gMobileEngfuncs) {
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();
}

77
cl_dll/input_mouse.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef INPUT_MOUSE_H
#define INPUT_MOUSE_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 defined(GOLDSOURCE_SUPPORT) && (defined(_WIN32) || defined(__linux__) || defined(__APPLE__)) && (defined(__i386) || defined(_M_IX86))
#define SUPPORT_GOLDSOURCE_INPUT
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;
};
#endif
#endif

View File

@ -3,14 +3,9 @@
#include "cvardef.h"
#include "kbutton.h"
#include "keydefs.h"
cvar_t *sensitivity;
cvar_t *in_joystick;
#define PITCH 0
#define YAW 1
#define ROLL 2
extern "C" void DLLEXPORT IN_ClientMoveEvent( float forwardmove, float sidemove );
extern "C" void DLLEXPORT IN_ClientLookEvent( float relyaw, float relpitch );
#include "input_mouse.h"
extern cvar_t *sensitivity;
extern cvar_t *in_joystick;
extern kbutton_t in_strafe;
extern kbutton_t in_mlook;
@ -37,12 +32,6 @@ extern cvar_t *cl_movespeedkey;
cvar_t *cl_laddermode;
float ac_forwardmove;
float ac_sidemove;
int ac_movecount;
float rel_yaw;
float rel_pitch;
#define F 1U<<0 // Forward
#define B 1U<<1 // Back
#define L 1U<<2 // Left
@ -55,7 +44,7 @@ float rel_pitch;
#define IMPULSE_UP 4
int CL_IsDead( void );
Vector dead_viewangles(0, 0, 0);
extern Vector dead_viewangles;
void IN_ToggleButtons( float forwardmove, float sidemove )
{
@ -135,7 +124,7 @@ void IN_ToggleButtons( float forwardmove, float sidemove )
}
}
void IN_ClientMoveEvent( float forwardmove, float sidemove )
void FWGSInput::IN_ClientMoveEvent( float forwardmove, float sidemove )
{
//gEngfuncs.Con_Printf("IN_MoveEvent\n");
@ -144,14 +133,14 @@ void IN_ClientMoveEvent( float forwardmove, float sidemove )
ac_movecount++;
}
void IN_ClientLookEvent( float relyaw, float relpitch )
void FWGSInput::IN_ClientLookEvent( float relyaw, float relpitch )
{
rel_yaw += relyaw;
rel_pitch += relpitch;
}
// Rotate camera and add move values to usercmd
void IN_Move( float frametime, usercmd_t *cmd )
void FWGSInput::IN_Move( float frametime, usercmd_t *cmd )
{
Vector viewangles;
bool fLadder = false;
@ -235,7 +224,7 @@ void IN_Move( float frametime, usercmd_t *cmd )
ac_movecount = 0;
}
extern "C" void DLLEXPORT IN_MouseEvent( int mstate )
void FWGSInput::IN_MouseEvent( int mstate )
{
static int mouse_oldbuttonstate;
// perform button actions
@ -257,37 +246,37 @@ extern "C" void DLLEXPORT IN_MouseEvent( int mstate )
// Stubs
extern "C" void DLLEXPORT IN_ClearStates( void )
void FWGSInput::IN_ClearStates( void )
{
//gEngfuncs.Con_Printf( "IN_ClearStates\n" );
}
extern "C" void DLLEXPORT IN_ActivateMouse( void )
void FWGSInput::IN_ActivateMouse( void )
{
//gEngfuncs.Con_Printf( "IN_ActivateMouse\n" );
}
extern "C" void DLLEXPORT IN_DeactivateMouse( void )
void FWGSInput::IN_DeactivateMouse( void )
{
//gEngfuncs.Con_Printf( "IN_DeactivateMouse\n" );
}
extern "C" void DLLEXPORT IN_Accumulate( void )
void FWGSInput::IN_Accumulate( void )
{
//gEngfuncs.Con_Printf( "IN_Accumulate\n" );
}
void IN_Commands( void )
void FWGSInput::IN_Commands( void )
{
//gEngfuncs.Con_Printf( "IN_Commands\n" );
}
void IN_Shutdown( void )
void FWGSInput::IN_Shutdown( void )
{
}
// Register cvars and reset data
void IN_Init( void )
void FWGSInput::IN_Init( void )
{
sensitivity = gEngfuncs.pfnRegisterVariable( "sensitivity", "3", FCVAR_ARCHIVE );
in_joystick = gEngfuncs.pfnRegisterVariable( "joystick", "0", FCVAR_ARCHIVE );