Ein neues Inputsystem in SDL. Das ist alles noch sehr Alpha...

This commit is contained in:
Yamagi Burmeister 2010-10-19 07:14:05 +00:00
parent 578e2bd3bf
commit 010aa5b498
3 changed files with 243 additions and 375 deletions

View file

@ -344,6 +344,7 @@ OPENGL_POSIX_OBJS = \
build/ref_gl_unix/input.o \
build/ref_gl_unix/glob.o \
build/ref_gl_unix/hunk.o \
build/ref_gl_unix/input2.o \
build/ref_gl_unix/misc.o \
build/ref_gl_unix/qgl.o \
build/ref_gl_unix/refresh.o
@ -819,6 +820,9 @@ build/ref_gl_unix/qgl.o: src/unix/qgl/qgl.c
build/ref_gl_unix/refresh.o: src/sdl/refresh.c
$(CC) $(CFLAGS_OPENGL) $(SDLCFLAGS) -o $@ -c $<
build/ref_gl_unix/input2.o: src/sdl/input.c
$(CC) $(CFLAGS_OPENGL) $(SDLCFLAGS) -o $@ -c $<
# ----------
# Quake II build

View file

@ -35,97 +35,246 @@ enum QKEYS {
K_ESCAPE = 27,
K_SPACE = 32,
/* normal keys should be passed as lowercased ascii */
K_BACKSPACE = 127,
K_UPARROW = 128,
K_DOWNARROW = 129,
K_LEFTARROW = 130,
K_RIGHTARROW = 131,
K_ALT = 132,
K_CTRL = 133,
K_SHIFT = 134,
K_F1 = 135,
K_F2 = 136,
K_F3 = 137,
K_F4 = 138,
K_F5 = 139,
K_F6 = 140,
K_F7 = 141,
K_F8 = 142,
K_F9 = 143,
K_F10 = 144,
K_F11 = 145,
K_F12 = 146,
K_INS = 147,
K_DEL = 148,
K_PGDN = 149,
K_PGUP = 150,
K_HOME = 151,
K_END = 152,
K_COMMAND = 128,
K_CAPSLOCK,
K_POWER,
K_PAUSE,
K_KP_HOME = 160,
K_KP_UPARROW = 161,
K_KP_PGUP = 162,
K_KP_LEFTARROW = 163,
K_KP_5 = 164,
K_KP_RIGHTARROW = 165,
K_KP_END = 166,
K_KP_DOWNARROW = 167,
K_KP_PGDN = 168,
K_KP_ENTER = 169,
K_KP_INS = 170,
K_KP_DEL = 171,
K_KP_SLASH = 172,
K_KP_MINUS = 173,
K_KP_PLUS = 174,
K_UPARROW,
K_DOWNARROW,
K_LEFTARROW,
K_RIGHTARROW,
/* mouse buttons generate virtual keys */
K_MOUSE1 = 200,
K_MOUSE2 = 201,
K_MOUSE3 = 202,
K_MOUSE4 = 241,
K_MOUSE5 = 242,
K_ALT,
K_CTRL,
K_SHIFT,
K_INS,
K_DEL,
K_PGDN,
K_PGUP,
K_HOME,
K_END,
/* aux keys are for multi-buttoned joysticks to
generate so they can use the normal binding process. */
K_AUX1 = 207,
K_AUX2 = 208,
K_AUX3 = 209,
K_AUX4 = 210,
K_AUX5 = 211,
K_AUX6 = 212,
K_AUX7 = 213,
K_AUX8 = 214,
K_AUX9 = 215,
K_AUX10 = 216,
K_AUX11 = 217,
K_AUX12 = 218,
K_AUX13 = 219,
K_AUX14 = 220,
K_AUX15 = 221,
K_AUX16 = 222,
K_AUX17 = 223,
K_AUX18 = 224,
K_AUX19 = 225,
K_AUX20 = 226,
K_AUX21 = 227,
K_AUX22 = 228,
K_AUX23 = 229,
K_AUX24 = 230,
K_AUX25 = 231,
K_AUX26 = 232,
K_AUX27 = 233,
K_AUX28 = 234,
K_AUX29 = 235,
K_AUX30 = 236,
K_AUX31 = 237,
K_AUX32 = 238,
K_F1,
K_F2,
K_F3,
K_F4,
K_F5,
K_F6,
K_F7,
K_F8,
K_F9,
K_F10,
K_F11,
K_F12,
K_F13,
K_F14,
K_F15,
K_MWHEELDOWN = 239,
K_MWHEELUP = 240,
K_KP_HOME,
K_KP_UPARROW,
K_KP_PGUP,
K_KP_LEFTARROW,
K_KP_5,
K_KP_RIGHTARROW,
K_KP_END,
K_KP_DOWNARROW,
K_KP_PGDN,
K_KP_ENTER,
K_KP_INS,
K_KP_DEL,
K_KP_SLASH,
K_KP_MINUS,
K_KP_PLUS,
K_KP_NUMLOCK,
K_KP_STAR,
K_KP_EQUALS,
K_PAUSE = 255,
K_MOUSE1,
K_MOUSE2,
K_MOUSE3,
K_MOUSE4,
K_MOUSE5,
K_MWHEELDOWN,
K_MWHEELUP,
K_JOY1,
K_JOY2,
K_JOY3,
K_JOY4,
K_JOY5,
K_JOY6,
K_JOY7,
K_JOY8,
K_JOY9,
K_JOY10,
K_JOY11,
K_JOY12,
K_JOY13,
K_JOY14,
K_JOY15,
K_JOY16,
K_JOY17,
K_JOY18,
K_JOY19,
K_JOY20,
K_JOY21,
K_JOY22,
K_JOY23,
K_JOY24,
K_JOY25,
K_JOY26,
K_JOY27,
K_JOY28,
K_JOY29,
K_JOY30,
K_JOY31,
K_JOY32,
K_AUX1,
K_AUX2,
K_AUX3,
K_AUX4,
K_AUX5,
K_AUX6,
K_AUX7,
K_AUX8,
K_AUX9,
K_AUX10,
K_AUX11,
K_AUX12,
K_AUX13,
K_AUX14,
K_AUX15,
K_AUX16,
K_AUX17,
K_AUX18,
K_AUX19,
K_AUX20,
K_AUX21,
K_AUX22,
K_AUX23,
K_AUX24,
K_AUX25,
K_AUX26,
K_AUX27,
K_AUX28,
K_AUX29,
K_AUX30,
K_AUX31,
K_AUX32,
K_WORLD_0,
K_WORLD_1,
K_WORLD_2,
K_WORLD_3,
K_WORLD_4,
K_WORLD_5,
K_WORLD_6,
K_WORLD_7,
K_WORLD_8,
K_WORLD_9,
K_WORLD_10,
K_WORLD_11,
K_WORLD_12,
K_WORLD_13,
K_WORLD_14,
K_WORLD_15,
K_WORLD_16,
K_WORLD_17,
K_WORLD_18,
K_WORLD_19,
K_WORLD_20,
K_WORLD_21,
K_WORLD_22,
K_WORLD_23,
K_WORLD_24,
K_WORLD_25,
K_WORLD_26,
K_WORLD_27,
K_WORLD_28,
K_WORLD_29,
K_WORLD_30,
K_WORLD_31,
K_WORLD_32,
K_WORLD_33,
K_WORLD_34,
K_WORLD_35,
K_WORLD_36,
K_WORLD_37,
K_WORLD_38,
K_WORLD_39,
K_WORLD_40,
K_WORLD_41,
K_WORLD_42,
K_WORLD_43,
K_WORLD_44,
K_WORLD_45,
K_WORLD_46,
K_WORLD_47,
K_WORLD_48,
K_WORLD_49,
K_WORLD_50,
K_WORLD_51,
K_WORLD_52,
K_WORLD_53,
K_WORLD_54,
K_WORLD_55,
K_WORLD_56,
K_WORLD_57,
K_WORLD_58,
K_WORLD_59,
K_WORLD_60,
K_WORLD_61,
K_WORLD_62,
K_WORLD_63,
K_WORLD_64,
K_WORLD_65,
K_WORLD_66,
K_WORLD_67,
K_WORLD_68,
K_WORLD_69,
K_WORLD_70,
K_WORLD_71,
K_WORLD_72,
K_WORLD_73,
K_WORLD_74,
K_WORLD_75,
K_WORLD_76,
K_WORLD_77,
K_WORLD_78,
K_WORLD_79,
K_WORLD_80,
K_WORLD_81,
K_WORLD_82,
K_WORLD_83,
K_WORLD_84,
K_WORLD_85,
K_WORLD_86,
K_WORLD_87,
K_WORLD_88,
K_WORLD_89,
K_WORLD_90,
K_WORLD_91,
K_WORLD_92,
K_WORLD_93,
K_WORLD_94,
K_WORLD_95,
K_SUPER,
K_COMPOSE,
K_MODE,
K_HELP,
K_PRINT,
K_SYSREQ,
K_SCROLLOCK,
K_BREAK,
K_MENU,
K_EURO,
K_UNDO,
K_LAST
};

View file

@ -38,15 +38,7 @@ static qboolean X11_active = false;
qboolean have_stencil = false;
static SDL_Surface *surface;
struct
{
int key;
int down;
} keyq[64];
int keyq_head=0;
int keyq_tail=0;
SDL_Surface *surface;
int config_notify=0;
int config_notify_width;
@ -60,207 +52,9 @@ static cvar_t *use_stencil;
/* MOUSE */
/*****************************************************************************/
#define MOUSE_MAX 3000
#define MOUSE_MIN 40
qboolean mouse_active;
int mx, my, mouse_buttonstate;
static float old_windowed_mouse;
static cvar_t *windowed_mouse;
static cvar_t *windowed_mouse_always;
void RW_IN_PlatformInit() {
windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_ARCHIVE);
windowed_mouse_always = ri.Cvar_Get ("windowed_mouse_always", "2", CVAR_ARCHIVE);
}
void RW_IN_Activate(qboolean active)
{
mx = my = 0;
}
/*****************************************************************************/
int XLateKey(unsigned int keysym)
{
int key;
key = 0;
switch(keysym) {
case SDLK_KP9: key = K_KP_PGUP; break;
case SDLK_PAGEUP: key = K_PGUP; break;
case SDLK_KP3: key = K_KP_PGDN; break;
case SDLK_PAGEDOWN: key = K_PGDN; break;
case SDLK_KP7: key = K_KP_HOME; break;
case SDLK_HOME: key = K_HOME; break;
case SDLK_KP1: key = K_KP_END; break;
case SDLK_END: key = K_END; break;
case SDLK_KP4: key = K_KP_LEFTARROW; break;
case SDLK_LEFT: key = K_LEFTARROW; break;
case SDLK_KP6: key = K_KP_RIGHTARROW; break;
case SDLK_RIGHT: key = K_RIGHTARROW; break;
case SDLK_KP2: key = K_KP_DOWNARROW; break;
case SDLK_DOWN: key = K_DOWNARROW; break;
case SDLK_KP8: key = K_KP_UPARROW; break;
case SDLK_UP: key = K_UPARROW; break;
case SDLK_ESCAPE: key = K_ESCAPE; break;
case SDLK_KP_ENTER: key = K_KP_ENTER; break;
case SDLK_RETURN: key = K_ENTER; break;
case SDLK_TAB: key = K_TAB; break;
case SDLK_F1: key = K_F1; break;
case SDLK_F2: key = K_F2; break;
case SDLK_F3: key = K_F3; break;
case SDLK_F4: key = K_F4; break;
case SDLK_F5: key = K_F5; break;
case SDLK_F6: key = K_F6; break;
case SDLK_F7: key = K_F7; break;
case SDLK_F8: key = K_F8; break;
case SDLK_F9: key = K_F9; break;
case SDLK_F10: key = K_F10; break;
case SDLK_F11: key = K_F11; break;
case SDLK_F12: key = K_F12; break;
case SDLK_BACKSPACE: key = K_BACKSPACE; break;
case SDLK_KP_PERIOD: key = K_KP_DEL; break;
case SDLK_DELETE: key = K_DEL; break;
case SDLK_PAUSE: key = K_PAUSE; break;
case SDLK_LSHIFT:
case SDLK_RSHIFT: key = K_SHIFT; break;
case SDLK_LCTRL:
case SDLK_RCTRL: key = K_CTRL; break;
case SDLK_LMETA:
case SDLK_RMETA:
case SDLK_LALT:
case SDLK_RALT: key = K_ALT; break;
case SDLK_KP5: key = K_KP_5; break;
case SDLK_INSERT: key = K_INS; break;
case SDLK_KP0: key = K_KP_INS; break;
case SDLK_KP_MULTIPLY: key = '*'; break;
case SDLK_KP_PLUS: key = K_KP_PLUS; break;
case SDLK_KP_MINUS: key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: key = K_KP_SLASH; break;
case SDLK_WORLD_7: key = '`'; break;
default:
if (keysym < 128)
key = keysym;
break;
}
return key;
}
static unsigned char KeyStates[SDLK_LAST];
void getMouse(int *x, int *y, int *state) {
*x = mx;
*y = my;
*state = mouse_buttonstate;
}
void doneMouse() {
mx = my = 0;
}
void GetEvent(SDL_Event *event)
{
unsigned int key;
switch(event->type) {
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == 4) {
keyq[keyq_head].key = K_MWHEELUP;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
keyq[keyq_head].key = K_MWHEELUP;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
} else if (event->button.button == 5) {
keyq[keyq_head].key = K_MWHEELDOWN;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
keyq[keyq_head].key = K_MWHEELDOWN;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
}
break;
case SDL_MOUSEBUTTONUP:
break;
case SDL_KEYDOWN:
if ( (KeyStates[SDLK_LALT] || KeyStates[SDLK_RALT]) &&
(event->key.keysym.sym == SDLK_RETURN) ) {
cvar_t *fullscreen;
SDL_WM_ToggleFullScreen(surface);
if (surface->flags & SDL_FULLSCREEN) {
ri.Cvar_SetValue( "vid_fullscreen", 1 );
} else {
ri.Cvar_SetValue( "vid_fullscreen", 0 );
}
fullscreen = ri.Cvar_Get( "vid_fullscreen", "0", 0 );
fullscreen->modified = false;
break;
}
if ( (KeyStates[SDLK_LCTRL] || KeyStates[SDLK_RCTRL]) &&
(event->key.keysym.sym == SDLK_g) ) {
SDL_GrabMode gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
ri.Cvar_SetValue( "windowed_mouse", (gm == SDL_GRAB_ON) ? 1 : 0 );
break;
}
KeyStates[event->key.keysym.sym] = 1;
key = XLateKey(event->key.keysym.sym);
if (key) {
keyq[keyq_head].key = key;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
}
break;
case SDL_KEYUP:
if (KeyStates[event->key.keysym.sym]) {
KeyStates[event->key.keysym.sym] = 0;
key = XLateKey(event->key.keysym.sym);
if (key) {
keyq[keyq_head].key = key;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
}
}
break;
case SDL_QUIT:
ri.Cmd_ExecuteText(EXEC_NOW, "quit");
break;
}
}
/*****************************************************************************/
@ -486,85 +280,6 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
/* KEYBOARD */
/*****************************************************************************/
Key_Event_fp_t Key_Event_fp;
void KBD_Init(Key_Event_fp_t fp)
{
Key_Event_fp = fp;
}
void KBD_Update(void)
{
SDL_Event event;
static int KBD_Update_Flag;
in_state_t *in_state = getState();
if (KBD_Update_Flag == 1)
return;
KBD_Update_Flag = 1;
if (X11_active)
{
int bstate;
while (SDL_PollEvent(&event))
GetEvent(&event);
if (!mx && !my)
SDL_GetRelativeMouseState(&mx, &my);
mouse_buttonstate = 0;
bstate = SDL_GetMouseState(NULL, NULL);
if (SDL_BUTTON(1) & bstate)
mouse_buttonstate |= (1 << 0);
if (SDL_BUTTON(3) & bstate)
mouse_buttonstate |= (1 << 1);
if (SDL_BUTTON(2) & bstate)
mouse_buttonstate |= (1 << 2);
if (SDL_BUTTON(6) & bstate)
mouse_buttonstate |= (1 << 3);
if (SDL_BUTTON(7) & bstate)
mouse_buttonstate |= (1 << 4);
if (windowed_mouse_always->value == 2)
{
if (old_windowed_mouse != windowed_mouse->value) {
old_windowed_mouse = windowed_mouse->value;
if (!windowed_mouse->value) {
SDL_WM_GrabInput(SDL_GRAB_OFF);
} else {
SDL_WM_GrabInput(SDL_GRAB_ON);
}
}
}
else if (windowed_mouse_always->value == 1)
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
else
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
while (keyq_head != keyq_tail)
{
in_state->Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
keyq_tail = (keyq_tail + 1) & 63;
}
}
KBD_Update_Flag = 0;
}
void KBD_Close(void)
{
keyq_head = 0;
keyq_tail = 0;
memset(keyq, 0, sizeof(keyq));
}
void Fake_glColorTableEXT( GLenum target, GLenum internalformat,
GLsizei width, GLenum format, GLenum type,