2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
input.c - win32 input devices
|
|
|
|
Copyright (C) 2007 Uncle Mike
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "vgui_draw.h"
|
|
|
|
|
2021-06-02 16:42:24 +02:00
|
|
|
#if XASH_SDL
|
2018-04-14 01:42:41 +02:00
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-11-16 13:25:04 +01:00
|
|
|
#include "platform/platform.h"
|
|
|
|
|
2018-04-14 01:42:41 +02:00
|
|
|
void* in_mousecursor;
|
2018-04-13 18:23:45 +02:00
|
|
|
qboolean in_mouseactive; // false when not focus app
|
|
|
|
qboolean in_mouseinitialized;
|
|
|
|
qboolean in_mouse_suspended;
|
2018-04-14 01:42:41 +02:00
|
|
|
POINT in_lastvalidpos;
|
2018-04-13 18:23:45 +02:00
|
|
|
qboolean in_mouse_savedpos;
|
2022-01-13 13:52:59 +01:00
|
|
|
static int in_mstate = 0;
|
2018-04-14 01:42:41 +02:00
|
|
|
static struct inputstate_s
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2018-04-14 01:42:41 +02:00
|
|
|
float lastpitch, lastyaw;
|
|
|
|
} inputstate;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
CVAR_DEFINE_AUTO( m_pitch, "0.022", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "mouse pitch value" );
|
|
|
|
CVAR_DEFINE_AUTO( m_yaw, "0.022", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "mouse yaw value" );
|
|
|
|
CVAR_DEFINE_AUTO( m_ignore, DEFAULT_M_IGNORE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "ignore mouse events" );
|
|
|
|
static CVAR_DEFINE_AUTO( look_filter, "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "filter look events making it smoother" );
|
|
|
|
static CVAR_DEFINE_AUTO( m_rawinput, "1", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable mouse raw input" );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
static CVAR_DEFINE_AUTO( cl_forwardspeed, "400", FCVAR_ARCHIVE | FCVAR_CLIENTDLL | FCVAR_FILTERABLE, "Default forward move speed" );
|
|
|
|
static CVAR_DEFINE_AUTO( cl_backspeed, "400", FCVAR_ARCHIVE | FCVAR_CLIENTDLL | FCVAR_FILTERABLE, "Default back move speed" );
|
|
|
|
static CVAR_DEFINE_AUTO( cl_sidespeed, "400", FCVAR_ARCHIVE | FCVAR_CLIENTDLL | FCVAR_FILTERABLE, "Default side move speed" );
|
2020-08-24 17:43:15 +02:00
|
|
|
|
2019-07-09 02:40:10 +02:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
IN_CollectInputDevices
|
|
|
|
|
|
|
|
Returns a bit mask representing connected devices or, at least, enabled
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
uint IN_CollectInputDevices( void )
|
|
|
|
{
|
|
|
|
uint ret = 0;
|
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
if( !m_ignore.value ) // no way to check is mouse connected, so use cvar only
|
2019-07-09 02:40:10 +02:00
|
|
|
ret |= INPUT_DEVICE_MOUSE;
|
|
|
|
|
2022-10-12 04:18:19 +02:00
|
|
|
if( touch_enable.value )
|
2019-07-09 02:40:10 +02:00
|
|
|
ret |= INPUT_DEVICE_TOUCH;
|
|
|
|
|
|
|
|
if( Joy_IsActive() ) // connected or enabled
|
|
|
|
ret |= INPUT_DEVICE_JOYSTICK;
|
|
|
|
|
|
|
|
Con_Reportf( "Connected devices: %s%s%s%s\n",
|
|
|
|
FBitSet( ret, INPUT_DEVICE_MOUSE ) ? "mouse " : "",
|
|
|
|
FBitSet( ret, INPUT_DEVICE_TOUCH ) ? "touch " : "",
|
|
|
|
FBitSet( ret, INPUT_DEVICE_JOYSTICK ) ? "joy " : "",
|
|
|
|
FBitSet( ret, INPUT_DEVICE_VR ) ? "vr " : "");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
IN_LockInputDevices
|
|
|
|
|
|
|
|
tries to lock any possibilty to connect another input device after
|
|
|
|
player is connected to the server
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void IN_LockInputDevices( qboolean lock )
|
|
|
|
{
|
2023-05-19 06:16:31 +02:00
|
|
|
extern convar_t joy_enable; // private to input system
|
2019-07-09 02:40:10 +02:00
|
|
|
|
|
|
|
if( lock )
|
|
|
|
{
|
2023-05-19 05:10:58 +02:00
|
|
|
SetBits( m_ignore.flags, FCVAR_READ_ONLY );
|
2023-05-19 06:16:31 +02:00
|
|
|
SetBits( joy_enable.flags, FCVAR_READ_ONLY );
|
2022-10-12 04:18:19 +02:00
|
|
|
SetBits( touch_enable.flags, FCVAR_READ_ONLY );
|
2019-07-09 02:40:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-19 05:10:58 +02:00
|
|
|
ClearBits( m_ignore.flags, FCVAR_READ_ONLY );
|
2023-05-19 06:16:31 +02:00
|
|
|
ClearBits( joy_enable.flags, FCVAR_READ_ONLY );
|
2022-10-12 04:18:19 +02:00
|
|
|
ClearBits( touch_enable.flags, FCVAR_READ_ONLY );
|
2019-07-09 02:40:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_StartupMouse
|
|
|
|
===========
|
|
|
|
*/
|
2024-01-27 17:48:17 +01:00
|
|
|
static void IN_StartupMouse( void )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2023-05-19 05:10:58 +02:00
|
|
|
Cvar_RegisterVariable( &m_ignore );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
Cvar_RegisterVariable( &m_pitch );
|
|
|
|
Cvar_RegisterVariable( &m_yaw );
|
|
|
|
Cvar_RegisterVariable( &look_filter );
|
|
|
|
Cvar_RegisterVariable( &m_rawinput );
|
2020-08-24 17:43:15 +02:00
|
|
|
|
2018-04-14 01:42:41 +02:00
|
|
|
// You can use -nomouse argument to prevent using mouse from client
|
|
|
|
// -noenginemouse will disable all mouse input
|
|
|
|
if( Sys_CheckParm( "-noenginemouse" )) return;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-04-14 01:42:41 +02:00
|
|
|
in_mouseinitialized = true;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 02:15:54 +01:00
|
|
|
void GAME_EXPORT IN_SetCursor( void *hCursor )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
// stub
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_MouseSavePos
|
|
|
|
|
|
|
|
Save mouse pos before state change e.g. changelevel
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_MouseSavePos( void )
|
|
|
|
{
|
|
|
|
if( !in_mouseactive )
|
|
|
|
return;
|
|
|
|
|
2018-10-22 00:09:43 +02:00
|
|
|
Platform_GetMousePos( &in_lastvalidpos.x, &in_lastvalidpos.y );
|
2018-04-13 18:23:45 +02:00
|
|
|
in_mouse_savedpos = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_MouseRestorePos
|
|
|
|
|
|
|
|
Restore right position for background
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_MouseRestorePos( void )
|
|
|
|
{
|
|
|
|
if( !in_mouse_savedpos )
|
|
|
|
return;
|
|
|
|
|
2018-10-22 00:09:43 +02:00
|
|
|
Platform_SetMousePos( in_lastvalidpos.x, in_lastvalidpos.y );
|
2018-04-14 01:42:41 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
in_mouse_savedpos = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_ToggleClientMouse
|
|
|
|
|
|
|
|
Called when key_dest is changed
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_ToggleClientMouse( int newstate, int oldstate )
|
|
|
|
{
|
2022-10-13 13:49:48 +02:00
|
|
|
if( newstate == oldstate )
|
|
|
|
return;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-10-13 13:49:48 +02:00
|
|
|
// since SetCursorType controls cursor visibility
|
|
|
|
// execute it first, and then check mouse grab state
|
2023-03-27 16:18:09 +02:00
|
|
|
if( newstate == key_menu || newstate == key_console )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-10-13 13:49:48 +02:00
|
|
|
Platform_SetCursorType( dc_arrow );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-04-14 01:42:41 +02:00
|
|
|
Evdev_SetGrab( false );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-13 13:49:48 +02:00
|
|
|
Platform_SetCursorType( dc_none );
|
|
|
|
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-04-14 01:42:41 +02:00
|
|
|
Evdev_SetGrab( true );
|
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2022-10-13 13:49:48 +02:00
|
|
|
|
2023-11-03 12:42:35 +01:00
|
|
|
// don't leave the user without cursor if they enabled m_ignore
|
|
|
|
if( m_ignore.value )
|
|
|
|
return;
|
|
|
|
|
2022-10-13 13:49:48 +02:00
|
|
|
if( oldstate == key_game )
|
|
|
|
{
|
|
|
|
IN_DeactivateMouse();
|
|
|
|
}
|
|
|
|
else if( newstate == key_game )
|
|
|
|
{
|
|
|
|
IN_ActivateMouse();
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2024-01-27 17:48:17 +01:00
|
|
|
static void IN_CheckMouseState( qboolean active )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-10-13 13:49:48 +02:00
|
|
|
static qboolean s_bRawInput, s_bMouseGrab;
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
#if XASH_WIN32
|
2023-05-19 05:10:58 +02:00
|
|
|
qboolean useRawInput = ( m_rawinput.value && clgame.client_dll_uses_sdl ) || clgame.dllFuncs.pfnLookEvent != NULL;
|
2022-01-04 06:19:57 +01:00
|
|
|
#else
|
|
|
|
qboolean useRawInput = true; // always use SDL code
|
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-10-21 17:57:57 +02:00
|
|
|
if( m_ignore.value )
|
|
|
|
return;
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
if( active && useRawInput && !host.mouse_visible && cls.state == ca_active )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
if( !s_bRawInput )
|
|
|
|
{
|
2022-01-04 06:26:41 +01:00
|
|
|
#if XASH_SDL == 2
|
2022-01-04 06:19:57 +01:00
|
|
|
SDL_GetRelativeMouseState( NULL, NULL );
|
|
|
|
SDL_SetRelativeMouseMode( SDL_TRUE );
|
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
// Con_Printf( "Enable relative mode\n" );
|
|
|
|
s_bRawInput = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( s_bRawInput )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:26:41 +01:00
|
|
|
#if XASH_SDL == 2
|
2022-01-04 06:19:57 +01:00
|
|
|
SDL_GetRelativeMouseState( NULL, NULL );
|
|
|
|
SDL_SetRelativeMouseMode( SDL_FALSE );
|
2018-04-14 01:42:41 +02:00
|
|
|
#endif
|
2022-01-04 06:19:57 +01:00
|
|
|
// Con_Printf( "Disable relative mode\n" );
|
|
|
|
s_bRawInput = false;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2022-01-04 06:19:57 +01:00
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
if( active && !host.mouse_visible && cls.state == ca_active )
|
|
|
|
{
|
|
|
|
if( !s_bMouseGrab )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
#if XASH_SDL
|
|
|
|
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
|
|
|
|
#endif
|
|
|
|
// Con_Printf( "Enable grab\n" );
|
|
|
|
s_bMouseGrab = true;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-04 06:19:57 +01:00
|
|
|
else
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
if( s_bMouseGrab )
|
|
|
|
{
|
2021-06-02 16:42:24 +02:00
|
|
|
#if XASH_SDL
|
2022-01-04 06:19:57 +01:00
|
|
|
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
|
2018-04-14 01:42:41 +02:00
|
|
|
#endif
|
2022-01-04 06:19:57 +01:00
|
|
|
|
|
|
|
// Con_Printf( "Disable grab\n" );
|
|
|
|
s_bMouseGrab = false;
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_ActivateMouse
|
|
|
|
|
|
|
|
Called when the window gains focus or changes in some way
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_ActivateMouse( void )
|
|
|
|
{
|
|
|
|
if( !in_mouseinitialized )
|
|
|
|
return;
|
|
|
|
|
|
|
|
IN_CheckMouseState( true );
|
2022-07-11 01:43:26 +02:00
|
|
|
if( clgame.dllFuncs.IN_ActivateMouse )
|
|
|
|
clgame.dllFuncs.IN_ActivateMouse();
|
2022-01-04 06:19:57 +01:00
|
|
|
in_mouseactive = true;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_DeactivateMouse
|
|
|
|
|
|
|
|
Called when the window loses focus
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_DeactivateMouse( void )
|
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
if( !in_mouseinitialized )
|
2018-04-13 18:23:45 +02:00
|
|
|
return;
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
IN_CheckMouseState( false );
|
2022-07-11 01:43:26 +02:00
|
|
|
if( clgame.dllFuncs.IN_DeactivateMouse )
|
|
|
|
clgame.dllFuncs.IN_DeactivateMouse();
|
2018-04-13 18:23:45 +02:00
|
|
|
in_mouseactive = false;
|
|
|
|
}
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
IN_MouseMove
|
|
|
|
================
|
|
|
|
*/
|
2024-01-27 17:48:17 +01:00
|
|
|
static void IN_MouseMove( void )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-10-12 04:18:19 +02:00
|
|
|
int x, y;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
if( !in_mouseinitialized )
|
2018-04-13 18:23:45 +02:00
|
|
|
return;
|
|
|
|
|
2022-10-12 04:18:19 +02:00
|
|
|
if( touch_emulate.value )
|
|
|
|
{
|
|
|
|
// touch emulation overrides all input
|
|
|
|
Touch_KeyEvent( 0, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// find mouse movement
|
2022-10-12 04:18:19 +02:00
|
|
|
Platform_GetMousePos( &x, &y );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-10-12 04:18:19 +02:00
|
|
|
VGui_MouseMove( x, y );
|
2018-04-14 00:49:14 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// if the menu is visible, move the menu cursor
|
2022-10-12 04:18:19 +02:00
|
|
|
UI_MouseMove( x, y );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_MouseEvent
|
|
|
|
===========
|
|
|
|
*/
|
2022-01-13 13:52:59 +01:00
|
|
|
void IN_MouseEvent( int key, int down )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
if( !in_mouseinitialized )
|
2018-04-13 18:23:45 +02:00
|
|
|
return;
|
|
|
|
|
2022-01-13 13:52:59 +01:00
|
|
|
if( down )
|
|
|
|
SetBits( in_mstate, BIT( key ));
|
|
|
|
else ClearBits( in_mstate, BIT( key ));
|
|
|
|
|
2022-10-12 04:18:19 +02:00
|
|
|
// touch emulation overrides all input
|
|
|
|
if( touch_emulate.value )
|
|
|
|
{
|
|
|
|
Touch_KeyEvent( K_MOUSE1 + key, down );
|
|
|
|
}
|
|
|
|
else if( cls.key_dest == key_game )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2021-06-02 16:42:24 +02:00
|
|
|
// perform button actions
|
2022-10-12 04:18:19 +02:00
|
|
|
VGui_MouseEvent( K_MOUSE1 + key, down );
|
2021-06-02 16:42:24 +02:00
|
|
|
|
2022-01-13 13:52:59 +01:00
|
|
|
// don't do Key_Event here
|
|
|
|
// client may override IN_MouseEvent
|
|
|
|
// but by default it calls back to Key_Event anyway
|
2022-01-04 06:19:57 +01:00
|
|
|
if( in_mouseactive )
|
2022-01-13 13:52:59 +01:00
|
|
|
clgame.dllFuncs.IN_MouseEvent( in_mstate );
|
2018-04-14 01:42:41 +02:00
|
|
|
}
|
2022-01-13 13:52:59 +01:00
|
|
|
else
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
2022-01-13 13:52:59 +01:00
|
|
|
// perform button actions
|
|
|
|
Key_Event( K_MOUSE1 + key, down );
|
2018-04-14 01:42:41 +02:00
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 04:18:19 +02:00
|
|
|
/*
|
|
|
|
==============
|
|
|
|
IN_MWheelEvent
|
|
|
|
|
|
|
|
direction is negative for wheel down, otherwise wheel up
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void IN_MWheelEvent( int y )
|
|
|
|
{
|
|
|
|
int b = y > 0 ? K_MWHEELUP : K_MWHEELDOWN;
|
|
|
|
|
|
|
|
VGui_MWheelEvent( y );
|
|
|
|
|
|
|
|
Key_Event( b, true );
|
|
|
|
Key_Event( b, false );
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Shutdown
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_Shutdown( void )
|
|
|
|
{
|
|
|
|
IN_DeactivateMouse( );
|
2018-04-14 01:42:41 +02:00
|
|
|
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-04-14 01:42:41 +02:00
|
|
|
Evdev_Shutdown();
|
|
|
|
#endif
|
2019-09-26 21:14:47 +02:00
|
|
|
|
|
|
|
Touch_Shutdown();
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Init
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void IN_Init( void )
|
|
|
|
{
|
2023-05-19 05:10:58 +02:00
|
|
|
Cvar_RegisterVariable( &cl_forwardspeed );
|
|
|
|
Cvar_RegisterVariable( &cl_backspeed );
|
|
|
|
Cvar_RegisterVariable( &cl_sidespeed );
|
2018-04-14 01:42:41 +02:00
|
|
|
|
|
|
|
if( !Host_IsDedicated() )
|
|
|
|
{
|
|
|
|
IN_StartupMouse( );
|
|
|
|
|
|
|
|
Joy_Init(); // common joystick support init
|
|
|
|
|
2019-09-26 21:14:47 +02:00
|
|
|
Touch_Init();
|
|
|
|
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-04-14 01:42:41 +02:00
|
|
|
Evdev_Init();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
IN_JoyMove
|
|
|
|
|
|
|
|
Common function for engine joystick movement
|
|
|
|
|
|
|
|
-1 < forwardmove < 1, -1 < sidemove < 1
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
2019-09-26 21:14:47 +02:00
|
|
|
static void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove )
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
static uint moveflags = T | S;
|
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
if( forwardmove ) cmd->forwardmove = forwardmove * cl_forwardspeed.value;
|
|
|
|
if( sidemove ) cmd->sidemove = sidemove * cl_sidespeed.value;
|
2018-04-14 01:42:41 +02:00
|
|
|
|
|
|
|
if( forwardmove )
|
|
|
|
{
|
|
|
|
moveflags &= ~T;
|
|
|
|
}
|
|
|
|
else if( !( moveflags & T ) )
|
|
|
|
{
|
|
|
|
Cmd_ExecuteString( "-back" );
|
|
|
|
Cmd_ExecuteString( "-forward" );
|
|
|
|
moveflags |= T;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sidemove )
|
|
|
|
{
|
|
|
|
moveflags &= ~S;
|
|
|
|
}
|
|
|
|
else if( !( moveflags & S ) )
|
|
|
|
{
|
|
|
|
Cmd_ExecuteString( "-moveleft" );
|
|
|
|
Cmd_ExecuteString( "-moveright" );
|
|
|
|
moveflags |= S;
|
|
|
|
}
|
|
|
|
|
2019-10-06 05:49:47 +02:00
|
|
|
if ( forwardmove > 0.7f && !( moveflags & F ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags |= F;
|
|
|
|
Cmd_ExecuteString( "+forward" );
|
|
|
|
}
|
2019-10-06 05:49:47 +02:00
|
|
|
else if ( forwardmove < 0.7f && ( moveflags & F ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags &= ~F;
|
|
|
|
Cmd_ExecuteString( "-forward" );
|
|
|
|
}
|
|
|
|
|
2019-10-06 05:49:47 +02:00
|
|
|
if ( forwardmove < -0.7f && !( moveflags & B ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags |= B;
|
|
|
|
Cmd_ExecuteString( "+back" );
|
|
|
|
}
|
2019-10-06 05:49:47 +02:00
|
|
|
else if ( forwardmove > -0.7f && ( moveflags & B ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags &= ~B;
|
|
|
|
Cmd_ExecuteString( "-back" );
|
|
|
|
}
|
|
|
|
|
2019-10-06 05:49:47 +02:00
|
|
|
if ( sidemove > 0.9f && !( moveflags & R ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags |= R;
|
|
|
|
Cmd_ExecuteString( "+moveright" );
|
|
|
|
}
|
2019-10-06 05:49:47 +02:00
|
|
|
else if ( sidemove < 0.9f && ( moveflags & R ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags &= ~R;
|
|
|
|
Cmd_ExecuteString( "-moveright" );
|
|
|
|
}
|
|
|
|
|
2019-10-06 05:49:47 +02:00
|
|
|
if ( sidemove < -0.9f && !( moveflags & L ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags |= L;
|
|
|
|
Cmd_ExecuteString( "+moveleft" );
|
|
|
|
}
|
2019-10-06 05:49:47 +02:00
|
|
|
else if ( sidemove > -0.9f && ( moveflags & L ))
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
|
|
|
moveflags &= ~L;
|
|
|
|
Cmd_ExecuteString( "-moveleft" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 14:18:23 +01:00
|
|
|
static void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qboolean includeMouse )
|
2018-10-10 23:04:23 +02:00
|
|
|
{
|
2022-01-13 14:18:23 +01:00
|
|
|
if( includeMouse )
|
2018-10-10 23:04:23 +02:00
|
|
|
{
|
2020-02-08 17:00:39 +01:00
|
|
|
float x, y;
|
|
|
|
Platform_MouseMove( &x, &y );
|
2023-05-19 05:10:58 +02:00
|
|
|
*pitch += y * m_pitch.value;
|
|
|
|
*yaw -= x * m_yaw.value;
|
2018-10-21 21:04:24 +02:00
|
|
|
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-10-21 21:04:24 +02:00
|
|
|
IN_EvdevMove( yaw, pitch );
|
|
|
|
#endif
|
2018-10-10 23:04:23 +02:00
|
|
|
}
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-10-10 23:04:23 +02:00
|
|
|
Joy_FinalizeMove( forward, side, yaw, pitch );
|
2019-09-26 21:14:47 +02:00
|
|
|
Touch_GetMove( forward, side, yaw, pitch );
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
if( look_filter.value )
|
2018-10-10 23:04:23 +02:00
|
|
|
{
|
|
|
|
*pitch = ( inputstate.lastpitch + *pitch ) / 2;
|
|
|
|
*yaw = ( inputstate.lastyaw + *yaw ) / 2;
|
|
|
|
inputstate.lastpitch = *pitch;
|
|
|
|
inputstate.lastyaw = *yaw;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-14 01:42:41 +02:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
IN_EngineAppendMove
|
|
|
|
|
|
|
|
Called from cl_main.c after generating command in client
|
|
|
|
================
|
|
|
|
*/
|
2019-09-26 21:14:47 +02:00
|
|
|
void IN_EngineAppendMove( float frametime, void *cmd1, qboolean active )
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
2018-10-10 23:04:23 +02:00
|
|
|
float forward, side, pitch, yaw;
|
2019-09-26 21:14:47 +02:00
|
|
|
usercmd_t *cmd = cmd1;
|
2018-04-14 01:42:41 +02:00
|
|
|
|
|
|
|
if( clgame.dllFuncs.pfnLookEvent )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( cls.key_dest != key_game || cl.paused || cl.intermission )
|
|
|
|
return;
|
|
|
|
|
2018-10-10 23:04:23 +02:00
|
|
|
forward = side = pitch = yaw = 0;
|
2018-04-14 01:42:41 +02:00
|
|
|
|
2018-10-10 23:04:23 +02:00
|
|
|
if( active )
|
2018-04-14 01:42:41 +02:00
|
|
|
{
|
2019-09-26 21:14:47 +02:00
|
|
|
float sensitivity = 1;//( (float)cl.local.scr_fov / (float)90.0f );
|
2018-10-10 23:04:23 +02:00
|
|
|
|
2022-01-13 14:18:23 +01:00
|
|
|
IN_CollectInput( &forward, &side, &pitch, &yaw, false );
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-14 01:42:41 +02:00
|
|
|
IN_JoyAppendMove( cmd, forward, side );
|
|
|
|
|
2019-09-26 21:14:47 +02:00
|
|
|
if( pitch || yaw )
|
|
|
|
{
|
|
|
|
cmd->viewangles[YAW] += yaw * sensitivity;
|
|
|
|
cmd->viewangles[PITCH] += pitch * sensitivity;
|
|
|
|
cmd->viewangles[PITCH] = bound( -90, cmd->viewangles[PITCH], 90 );
|
2021-06-02 16:42:24 +02:00
|
|
|
VectorCopy( cmd->viewangles, cl.viewangles );
|
2019-09-26 21:14:47 +02:00
|
|
|
}
|
2018-04-14 01:42:41 +02:00
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2024-01-27 17:48:17 +01:00
|
|
|
static void IN_Commands( void )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2018-04-14 01:42:41 +02:00
|
|
|
IN_EvdevFrame();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( clgame.dllFuncs.pfnLookEvent )
|
|
|
|
{
|
2022-01-04 06:19:57 +01:00
|
|
|
float forward = 0, side = 0, pitch = 0, yaw = 0;
|
|
|
|
|
2023-05-19 05:10:58 +02:00
|
|
|
IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized && !m_ignore.value );
|
2018-04-14 01:42:41 +02:00
|
|
|
|
|
|
|
if( cls.key_dest == key_game )
|
|
|
|
{
|
|
|
|
clgame.dllFuncs.pfnLookEvent( yaw, pitch );
|
|
|
|
clgame.dllFuncs.pfnMoveEvent( forward, side );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !in_mouseinitialized )
|
|
|
|
return;
|
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
IN_CheckMouseState( in_mouseactive );
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Host_InputFrame
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2022-01-04 06:19:57 +01:00
|
|
|
Called every frame, even if not generating commands
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void Host_InputFrame( void )
|
|
|
|
{
|
|
|
|
Sys_SendKeyEvents ();
|
|
|
|
|
|
|
|
IN_Commands();
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
IN_MouseMove();
|
|
|
|
}
|