Räume das neue SDL Input Backend auf

This commit is contained in:
Yamagi Burmeister 2010-10-19 08:25:47 +00:00
parent aabf1567ae
commit 1807604001
4 changed files with 148 additions and 156 deletions

View file

@ -30,14 +30,17 @@
#include "../client/input/header/keyboard.h"
#include "../unix/header/unix.h"
#define MOUSE_MAX 3000
#define MOUSE_MIN 40
static int old_windowed_mouse;
static cvar_t *windowed_mouse;
static cvar_t *windowed_mouse_always;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static qboolean mouse_avail;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
struct
{
@ -52,10 +55,10 @@ int my;
Key_Event_fp_t Key_Event_fp;
extern SDL_Surface *surface;
static in_state_t *in_state;
extern SDL_Surface *surface;
static in_state_t *in_state;
static unsigned char KeyStates[SDLK_LAST];
static qboolean mlooking;
static qboolean mlooking;
static cvar_t *sensitivity;
static cvar_t *exponential_speedup;
@ -68,8 +71,13 @@ static cvar_t *freelook;
static cvar_t *m_filter;
static cvar_t *in_mouse;
/*
* This function translates the SDL keycodes
* to the internal key representation of the
* id Tech 2 engine.
*/
int
RW_IN_TranslateSDLtoQ2Key(unsigned int keysym)
IN_TranslateSDLtoQ2Key(unsigned int keysym)
{
int key = 0;
@ -170,40 +178,11 @@ RW_IN_TranslateSDLtoQ2Key(unsigned int keysym)
return key;
}
/*
* Input event processing
*/
void
RW_IN_PlatformInit()
{
/*if( !SDL_WasInit( SDL_INIT_VIDEO ) )
{
Com_Error( ERR_FATAL, "RW_IN_PlatformInit called before GLimp_Init( SDL_INIT_VIDEO )\n" );
return;
} */
Com_Printf( "\n------- Input Initialization -------\n" );
SDL_EnableUNICODE( 0 );
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_ARCHIVE);
windowed_mouse_always = ri.Cvar_Get ("windowed_mouse_always", "2", CVAR_ARCHIVE);
Com_Printf( "\n------------------------------------\n" );
}
void
KBD_Init(Key_Event_fp_t fp)
{
Key_Event_fp = fp;
}
static void
Force_CenterView_f ( void )
{
in_state->viewangles [ PITCH ] = 0;
}
void
GetEvent(SDL_Event *event)
IN_GetEvent(SDL_Event *event)
{
unsigned int key;
@ -258,7 +237,7 @@ GetEvent(SDL_Event *event)
KeyStates[event->key.keysym.sym] = 1;
/* Get the pressed key and add it to the key list */
key = RW_IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
@ -274,7 +253,7 @@ GetEvent(SDL_Event *event)
KeyStates[event->key.keysym.sym] = 0;
/* Get the pressed key and remove it from the key list */
key = RW_IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
@ -286,24 +265,26 @@ GetEvent(SDL_Event *event)
}
}
void KBD_Update(void)
/*
* Updates the state of the input queue
*/
void IN_Update(void)
{
SDL_Event event;
static int KBD_Update_Flag;
static int IN_Update_Flag;
int bstate;
/* Protection against multiple calls */
if (KBD_Update_Flag == 1)
if (IN_Update_Flag == 1)
{
return;
}
KBD_Update_Flag = 1;
in_state_t *in_state = getState();
IN_Update_Flag = 1;
while (SDL_PollEvent(&event))
{
GetEvent(&event);
IN_GetEvent(&event);
}
/* Mouse button processing. Button 4
@ -373,10 +354,14 @@ void KBD_Update(void)
keyq_tail = (keyq_tail + 1) & 63;
}
KBD_Update_Flag = 0;
IN_Update_Flag = 0;
}
void KBD_Close(void)
/*
* Closes all inputs and clears
* the input queue.
*/
void IN_Close(void)
{
keyq_head = 0;
keyq_tail = 0;
@ -384,42 +369,66 @@ void KBD_Close(void)
memset(keyq, 0, sizeof(keyq));
}
void getMouse(int *x, int *y, int *state) {
/*
* Gets the mouse state
*/
void IN_GetMouseState(int *x, int *y, int *state) {
*x = mx;
*y = my;
*state = mouse_buttonstate;
}
void doneMouse() {
mx = my = 0;
}
void RW_IN_Activate(qboolean active)
/*
* Cleares the mouse state
*/
void IN_ClearMouseState()
{
mx = my = 0;
}
in_state_t *
getState ()
{
return ( in_state );
}
/*
* Centers the view
*/
static void
RW_IN_MLookDown ( void )
IN_ForceCenterView ( void )
{
in_state->viewangles [ PITCH ] = 0;
}
/*
* Look up
*/
static void
IN_MLookDown ( void )
{
mlooking = true;
}
/*
* Look down
*/
static void
RW_IN_MLookUp ( void )
IN_MLookUp ( void )
{
mlooking = false;
in_state->IN_CenterView_fp();
}
/*
* Keyboard initialisation. Called
* by the client via function pointer
*/
void
RW_IN_Init ( in_state_t *in_state_p )
IN_KeyboardInit(Key_Event_fp_t fp)
{
Key_Event_fp = fp;
}
/*
* Initializes the backend
*/
void
IN_BackendInit ( in_state_t *in_state_p )
{
in_state = in_state_p;
m_filter = ri.Cvar_Get( "m_filter", "0", 0 );
@ -435,18 +444,28 @@ RW_IN_Init ( in_state_t *in_state_p )
m_forward = ri.Cvar_Get( "m_forward", "1", 0 );
m_side = ri.Cvar_Get( "m_side", "0.8", 0 );
ri.Cmd_AddCommand( "+mlook", RW_IN_MLookDown );
ri.Cmd_AddCommand( "-mlook", RW_IN_MLookUp );
ri.Cmd_AddCommand( "force_centerview", Force_CenterView_f );
ri.Cmd_AddCommand( "+mlook", IN_MLookDown );
ri.Cmd_AddCommand( "-mlook", IN_MLookUp );
ri.Cmd_AddCommand( "force_centerview", IN_ForceCenterView );
mouse_x = mouse_y = 0.0;
mouse_avail = true;
RW_IN_PlatformInit();
/* SDL stuff */
SDL_EnableUNICODE( 0 );
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_ARCHIVE);
windowed_mouse_always = ri.Cvar_Get ("windowed_mouse_always", "2", CVAR_ARCHIVE);
Com_Printf( "Input initialized.\n" );
}
/*
* Shuts the backend down
*/
void
RW_IN_Shutdown ( void )
IN_BackendShutdown ( void )
{
if ( mouse_avail )
{
@ -459,13 +478,13 @@ RW_IN_Shutdown ( void )
}
void
RW_IN_Commands ( void )
IN_BackendMouseButtons ( void )
{
int i;
if ( mouse_avail )
{
getMouse( &mouse_x, &mouse_y, &mouse_buttonstate );
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
for ( i = 0; i < 3; i++ )
{
@ -505,11 +524,11 @@ RW_IN_Commands ( void )
}
void
RW_IN_Move ( usercmd_t *cmd )
IN_BackendMove ( usercmd_t *cmd )
{
if ( mouse_avail )
{
getMouse( &mouse_x, &mouse_y, &mouse_buttonstate );
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
if ( m_filter->value )
{
@ -576,7 +595,7 @@ RW_IN_Move ( usercmd_t *cmd )
cmd->forwardmove -= m_forward->value * mouse_y;
}
doneMouse();
IN_ClearMouseState();
}
}
}

View file

@ -26,17 +26,7 @@
*/
typedef void ( *Key_Event_fp_t )( int key, qboolean down );
extern void ( *KBD_Update_fp )( void );
extern void ( *KBD_Init_fp )( Key_Event_fp_t fp );
extern void ( *KBD_Close_fp )( void );
void RW_IN_PlatformInit ();
#define MOUSE_MAX 3000
#define MOUSE_MIN 40
void getMouse ( int *x, int *y, int *state );
extern void ( *IN_Update_fp )( void );
typedef struct in_state
{
@ -48,5 +38,3 @@ typedef struct in_state
int *in_speed_state;
} in_state_t;
in_state_t *getState ();

View file

@ -481,9 +481,9 @@ Sys_SendKeyEvents ( void )
{
#ifndef DEDICATED_ONLY
if ( KBD_Update_fp )
if ( IN_Update_fp )
{
KBD_Update_fp();
IN_Update_fp();
}
#endif

View file

@ -58,20 +58,18 @@ qboolean reflib_active = 0;
#define VID_NUM_MODES ( sizeof ( vid_modes ) / sizeof ( vid_modes [ 0 ] ) )
/* KEYBOARD */
/* INPUT */
void Do_Key_Event ( int key, qboolean down );
void ( *KBD_Update_fp )( void );
void ( *KBD_Init_fp )( Key_Event_fp_t fp );
void ( *KBD_Close_fp )( void );
void ( *IN_Update_fp )( void );
void ( *IN_KeyboardInit_fp )( Key_Event_fp_t fp );
void ( *IN_Close_fp )( void );
/* MOUSE */
in_state_t in_state;
void ( *RW_IN_Init_fp )( in_state_t *in_state_p );
void ( *RW_IN_Shutdown_fp )( void );
void ( *RW_IN_Activate_fp )( qboolean active );
void ( *RW_IN_Commands_fp )( void );
void ( *RW_IN_Move_fp )( usercmd_t *cmd );
void ( *IN_BackendInit_fp )( in_state_t *in_state_p );
void ( *IN_BackendShutdown_fp )( void );
void ( *IN_BackendMouseButtons_fp )( void );
void ( *IN_BackendMove_fp )( usercmd_t *cmd );
void ( *RW_IN_Frame_fp )( void );
void IN_Init ( void );
@ -186,27 +184,26 @@ VID_FreeReflib ( void )
{
if ( reflib_library )
{
if ( KBD_Close_fp )
if ( IN_Close_fp )
{
KBD_Close_fp();
IN_Close_fp();
}
if ( RW_IN_Shutdown_fp )
if ( IN_BackendShutdown_fp )
{
RW_IN_Shutdown_fp();
IN_BackendShutdown_fp();
}
dlclose( reflib_library );
}
KBD_Init_fp = NULL;
KBD_Update_fp = NULL;
KBD_Close_fp = NULL;
RW_IN_Init_fp = NULL;
RW_IN_Shutdown_fp = NULL;
RW_IN_Activate_fp = NULL;
RW_IN_Commands_fp = NULL;
RW_IN_Move_fp = NULL;
IN_KeyboardInit_fp = NULL;
IN_Update_fp = NULL;
IN_Close_fp = NULL;
IN_BackendInit_fp = NULL;
IN_BackendShutdown_fp = NULL;
IN_BackendMouseButtons_fp = NULL;
IN_BackendMove_fp = NULL;
RW_IN_Frame_fp = NULL;
RW_Sys_GetClipboardData_fp = NULL;
@ -227,18 +224,18 @@ VID_LoadRefresh ( char *name )
if ( reflib_active )
{
if ( KBD_Close_fp )
if ( IN_Close_fp )
{
KBD_Close_fp();
IN_Close_fp();
}
if ( RW_IN_Shutdown_fp )
if ( IN_BackendShutdown_fp )
{
RW_IN_Shutdown_fp();
IN_BackendShutdown_fp();
}
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
IN_Close_fp = NULL;
IN_BackendShutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib();
}
@ -303,10 +300,10 @@ VID_LoadRefresh ( char *name )
in_state.in_strafe_state = &in_strafe.state;
in_state.in_speed_state = &in_speed.state;
if ( ( ( RW_IN_Init_fp = dlsym( reflib_library, "RW_IN_Init" ) ) == NULL ) ||
( ( RW_IN_Shutdown_fp = dlsym( reflib_library, "RW_IN_Shutdown" ) ) == NULL ) ||
( ( RW_IN_Commands_fp = dlsym( reflib_library, "RW_IN_Commands" ) ) == NULL ) ||
( ( RW_IN_Move_fp = dlsym( reflib_library, "RW_IN_Move" ) ) == NULL ) )
if ( ( ( IN_BackendInit_fp = dlsym( reflib_library, "IN_BackendInit" ) ) == NULL ) ||
( ( IN_BackendShutdown_fp = dlsym( reflib_library, "IN_BackendShutdown" ) ) == NULL ) ||
( ( IN_BackendMouseButtons_fp = dlsym( reflib_library, "IN_BackendMouseButtons" ) ) == NULL ) ||
( ( IN_BackendMove_fp = dlsym( reflib_library, "IN_BackendMove" ) ) == NULL ) )
{
Sys_Error( "No RW_IN functions in REF.\n" );
}
@ -323,15 +320,15 @@ VID_LoadRefresh ( char *name )
return ( false );
}
/* Init KBD */
if ( ( ( KBD_Init_fp = dlsym( reflib_library, "KBD_Init" ) ) == NULL ) ||
( ( KBD_Update_fp = dlsym( reflib_library, "KBD_Update" ) ) == NULL ) ||
( ( KBD_Close_fp = dlsym( reflib_library, "KBD_Close" ) ) == NULL ) )
/* Init IN */
if ( ( ( IN_KeyboardInit_fp = dlsym( reflib_library, "IN_KeyboardInit" ) ) == NULL ) ||
( ( IN_Update_fp = dlsym( reflib_library, "IN_Update" ) ) == NULL ) ||
( ( IN_Close_fp = dlsym( reflib_library, "IN_Close" ) ) == NULL ) )
{
Sys_Error( "No KBD functions in REF.\n" );
}
KBD_Init_fp( Do_Key_Event );
IN_KeyboardInit_fp( Do_Key_Event );
Key_ClearStates();
/* give up root now */
@ -402,18 +399,18 @@ VID_Shutdown ( void )
{
if ( reflib_active )
{
if ( KBD_Close_fp )
if ( IN_Close_fp )
{
KBD_Close_fp();
IN_Close_fp();
}
if ( RW_IN_Shutdown_fp )
if ( IN_BackendShutdown_fp )
{
RW_IN_Shutdown_fp();
IN_BackendShutdown_fp();
}
KBD_Close_fp = NULL;
RW_IN_Shutdown_fp = NULL;
IN_Close_fp = NULL;
IN_BackendShutdown_fp = NULL;
re.Shutdown();
VID_FreeReflib();
}
@ -450,54 +447,42 @@ VID_CheckRefExists ( const char *ref )
void
IN_Init ( void )
{
if ( RW_IN_Init_fp )
if ( IN_BackendInit_fp )
{
RW_IN_Init_fp( &in_state );
IN_BackendInit_fp( &in_state );
}
}
void
IN_Shutdown ( void )
{
if ( RW_IN_Shutdown_fp )
if ( IN_BackendShutdown_fp )
{
RW_IN_Shutdown_fp();
IN_BackendShutdown_fp();
}
}
void
IN_Commands ( void )
{
if ( RW_IN_Commands_fp )
if ( IN_BackendMouseButtons_fp )
{
RW_IN_Commands_fp();
IN_BackendMouseButtons_fp();
}
}
void
IN_Move ( usercmd_t *cmd )
{
if ( RW_IN_Move_fp )
if ( IN_BackendMove_fp )
{
RW_IN_Move_fp( cmd );
IN_BackendMove_fp( cmd );
}
}
void
IN_Frame ( void )
{
if ( RW_IN_Activate_fp )
{
if ( !cl.refresh_prepped || ( cls.key_dest == key_console ) || ( cls.key_dest == key_menu ) )
{
RW_IN_Activate_fp( false );
}
else
{
RW_IN_Activate_fp( true );
}
}
if ( RW_IN_Frame_fp )
{
RW_IN_Frame_fp();