Commit f4003e54 authored by Steven Fuller's avatar Steven Fuller

Added (ingame) mouse support.

parent a6765d8f
...@@ -34,7 +34,8 @@ NASM = nasm ...@@ -34,7 +34,8 @@ NASM = nasm
.SUFFIXES: .asm .SUFFIXES: .asm
all: swolf3d xwolf3d sdlwolf3d #all: swolf3d xwolf3d sdlwolf3d
all: sdlwolf3d
$(SOBJS): version.h id_heads.h wl_def.h $(SOBJS): version.h id_heads.h wl_def.h
$(XOBJS): version.h id_heads.h wl_def.h $(XOBJS): version.h id_heads.h wl_def.h
......
...@@ -36,7 +36,7 @@ P M - position pushwall sounds ...@@ -36,7 +36,7 @@ P M - position pushwall sounds
P M - id_ca.c cache code: fix/readd/rewrite the "garbage collection" system P M - id_ca.c cache code: fix/readd/rewrite the "garbage collection" system
P M - rewrite id_ca.c: uniform memory handling system P M - rewrite id_ca.c: uniform memory handling system
P M - either move id_heads into wl_def or split header files apart P M - either move id_heads into wl_def or split header files apart
P R - rewrite fmopl.c to avoid licensing issues P R - rewrite fmopl.c to avoid licensing issues (or provide as a separate patch? may not be advisable since id owns copyright on wolf code)
P R - remove CA_LoadAllSounds now that the sound code does everything P R - remove CA_LoadAllSounds now that the sound code does everything
B I - README, etc. B I - README, etc.
B M - Code Documentation B M - Code Documentation
......
...@@ -16,6 +16,7 @@ boolean JoysPresent[MaxJoys]; ...@@ -16,6 +16,7 @@ boolean JoysPresent[MaxJoys];
// Global variables // Global variables
boolean Keyboard[NumCodes]; boolean Keyboard[NumCodes];
boolean InternalKeyboard[NumCodes];
boolean Paused; boolean Paused;
char LastASCII; char LastASCII;
ScanCode LastScan; ScanCode LastScan;
...@@ -81,12 +82,15 @@ void keyboard_handler(int code, int press) ...@@ -81,12 +82,15 @@ void keyboard_handler(int code, int press)
if (press == 0) if (press == 0)
{ {
Keyboard[k] = false; Keyboard[k] = false;
InternalKeyboard[k] = false;
} }
else // Make code else // Make code
{ {
LastCode = CurCode; LastCode = CurCode;
CurCode = LastScan = k; CurCode = LastScan = k;
Keyboard[k] = true; Keyboard[k] = true;
InternalKeyboard[k] = true;
if (k == sc_CapsLock) if (k == sc_CapsLock)
{ {
...@@ -137,19 +141,6 @@ boolean IN_UserInput(longword delay) ...@@ -137,19 +141,6 @@ boolean IN_UserInput(longword delay)
//=========================================================================== //===========================================================================
/*
===================
=
= IN_MouseButtons
=
===================
*/
byte IN_MouseButtons()
{
return 0;
}
/* /*
=================== ===================
= =
...@@ -163,29 +154,6 @@ byte IN_JoyButtons() ...@@ -163,29 +154,6 @@ byte IN_JoyButtons()
return 0; return 0;
} }
///////////////////////////////////////////////////////////////////////////
//
// INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
// mouse driver
//
///////////////////////////////////////////////////////////////////////////
static void INL_GetMouseDelta(int *x,int *y)
{
*x = 0;
*y = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetMouseButtons() - Gets the status of the mouse buttons from the
// mouse driver
//
///////////////////////////////////////////////////////////////////////////
static word INL_GetMouseButtons(void)
{
return 0;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// //
// IN_GetJoyAbs() - Reads the absolute position of the specified joystick // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
...@@ -239,16 +207,6 @@ static void INL_ShutKbd(void) ...@@ -239,16 +207,6 @@ static void INL_ShutKbd(void)
{ {
} }
///////////////////////////////////////////////////////////////////////////
//
// INL_StartMouse() - Detects and sets up the mouse
//
///////////////////////////////////////////////////////////////////////////
static boolean INL_StartMouse(void)
{
return false;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// //
// INL_ShutMouse() - Cleans up after the mouse // INL_ShutMouse() - Cleans up after the mouse
...@@ -297,22 +255,22 @@ static void INL_ShutJoy(word joy) ...@@ -297,22 +255,22 @@ static void INL_ShutJoy(word joy)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
void IN_Startup(void) void IN_Startup(void)
{ {
boolean checkjoys,checkmouse; boolean checkjoys;
word i; word i;
if (IN_Started) if (IN_Started)
return; return;
checkjoys = true; checkjoys = true;
checkmouse = true;
if (MS_CheckParm("nojoy")) if (MS_CheckParm("nojoy"))
checkjoys = false; checkjoys = false;
if (MS_CheckParm("nomouse")) if (MS_CheckParm("nomouse"))
checkmouse = false; MousePresent = false;
else
MousePresent = true;
INL_StartKbd(); INL_StartKbd();
MousePresent = checkmouse ? INL_StartMouse() : false;
for (i = 0;i < MaxJoys;i++) for (i = 0;i < MaxJoys;i++)
JoysPresent[i] = checkjoys ? INL_StartJoy(i) : false; JoysPresent[i] = checkjoys ? INL_StartJoy(i) : false;
...@@ -410,8 +368,8 @@ IN_CheckAck(); ...@@ -410,8 +368,8 @@ IN_CheckAck();
realdelta = true; realdelta = true;
break; break;
case ctrl_Mouse: case ctrl_Mouse:
INL_GetMouseDelta(&dx,&dy); IN_GetMouseDelta(&dx,&dy);
buttons = INL_GetMouseButtons(); buttons = IN_MouseButtons();
realdelta = true; realdelta = true;
break; break;
} }
......
...@@ -166,7 +166,9 @@ extern char *IN_GetScanName(ScanCode); ...@@ -166,7 +166,9 @@ extern char *IN_GetScanName(ScanCode);
byte IN_MouseButtons(); byte IN_MouseButtons();
byte IN_JoyButtons(); byte IN_JoyButtons();
void IN_GetMouseDelta(int *dx, int *dy);
void INL_GetJoyDelta(word joy,int *dx,int *dy); void INL_GetJoyDelta(word joy,int *dx,int *dy);
void IN_StartAck(); void IN_StartAck();
boolean IN_CheckAck(); boolean IN_CheckAck();
......
...@@ -6,7 +6,8 @@ byte *gfxbuf = NULL; ...@@ -6,7 +6,8 @@ byte *gfxbuf = NULL;
SDL_Surface *surface; SDL_Surface *surface;
void keyboard_handler(int code, int press); extern void keyboard_handler(int code, int press);
extern boolean InternalKeyboard[NumCodes];
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
...@@ -105,9 +106,10 @@ void VL_Startup() ...@@ -105,9 +106,10 @@ void VL_Startup()
} }
gfxbuf = surface->pixels; gfxbuf = surface->pixels;
SDL_WM_SetCaption(GAMENAME, GAMENAME); if (surface->flags & SDL_FULLSCREEN)
SDL_ShowCursor(0);
SDL_ShowCursor(0);
SDL_WM_SetCaption(GAMENAME, GAMENAME);
} }
/* /*
...@@ -175,6 +177,78 @@ void VL_GetPalette(byte *palette) ...@@ -175,6 +177,78 @@ void VL_GetPalette(byte *palette)
static int XKeysymToScancode(unsigned int keysym) static int XKeysymToScancode(unsigned int keysym)
{ {
switch (keysym) { switch (keysym) {
case SDLK_KP_ENTER:
case SDLK_RETURN:
return sc_Enter;
case SDLK_ESCAPE:
return sc_Escape;
case SDLK_SPACE:
return sc_Space;
case SDLK_BACKSPACE:
return sc_BackSpace;
case SDLK_TAB:
return sc_Tab;
case SDLK_LALT:
return sc_Alt;
case SDLK_LCTRL:
return sc_Control;
case SDLK_CAPSLOCK:
return sc_CapsLock;
case SDLK_LSHIFT:
return sc_LShift;
case SDLK_RSHIFT:
return sc_RShift;
case SDLK_UP:
case SDLK_KP8:
return sc_UpArrow;
case SDLK_DOWN:
case SDLK_KP2:
return sc_DownArrow;
case SDLK_LEFT:
case SDLK_KP4:
return sc_LeftArrow;
case SDLK_RIGHT:
case SDLK_KP6:
return sc_RightArrow;
case SDLK_HOME:
return sc_Home;
case SDLK_END:
return sc_End;
case SDLK_PAGEUP:
return sc_PgUp;
case SDLK_PAGEDOWN:
return sc_PgDn;
case SDLK_INSERT:
return sc_Insert;
case SDLK_DELETE:
return sc_Delete;
case SDLK_F1:
return sc_F1;
case SDLK_F2:
return sc_F2;
case SDLK_F3:
return sc_F3;
case SDLK_F4:
return sc_F4;
case SDLK_F5:
return sc_F5;
case SDLK_F6:
return sc_F6;
case SDLK_F7:
return sc_F7;
case SDLK_F8:
return sc_F8;
case SDLK_F9:
return sc_F9;
case SDLK_F10:
return sc_F10;
case SDLK_F11:
return sc_F11;
case SDLK_F12:
return sc_F12;
case SDLK_1: case SDLK_1:
return sc_1; return sc_1;
case SDLK_2: case SDLK_2:
...@@ -183,69 +257,72 @@ static int XKeysymToScancode(unsigned int keysym) ...@@ -183,69 +257,72 @@ static int XKeysymToScancode(unsigned int keysym)
return sc_3; return sc_3;
case SDLK_4: case SDLK_4:
return sc_4; return sc_4;
case SDLK_5:
return sc_5;
case SDLK_6:
return sc_6;
case SDLK_7:
return sc_7;
case SDLK_8:
return sc_8;
case SDLK_9:
return sc_9;
case SDLK_0:
return sc_0;
case SDLK_a: case SDLK_a:
return sc_A; return sc_A;
case SDLK_b: case SDLK_b:
return sc_B; return sc_B;
case SDLK_c: case SDLK_c:
return sc_C; return sc_C;
case SDLK_d:
return sc_D;
case SDLK_e: case SDLK_e:
return sc_E; return sc_E;
case SDLK_f:
return sc_F;
case SDLK_g: case SDLK_g:
return sc_G; return sc_G;
case SDLK_h: case SDLK_h:
return sc_H; return sc_H;
case SDLK_i: case SDLK_i:
return sc_I; return sc_I;
case SDLK_j:
return sc_J;
case SDLK_k:
return sc_K;
case SDLK_l: case SDLK_l:
return sc_L; return sc_L;
case SDLK_m: case SDLK_m:
return sc_M; return sc_M;
case SDLK_n: case SDLK_n:
return sc_N; return sc_N;
case SDLK_o:
return sc_O;
case SDLK_p:
return sc_P;
case SDLK_q:
return sc_Q;
case SDLK_r: case SDLK_r:
return sc_R; return sc_R;
case SDLK_s:
return sc_S;
case SDLK_t: case SDLK_t:
return sc_T; return sc_T;
case SDLK_u:
return sc_U;
case SDLK_v: case SDLK_v:
return sc_V; return sc_V;
case SDLK_w:
return sc_W;
case SDLK_x:
return sc_X;
case SDLK_y: case SDLK_y:
return sc_Y; return sc_Y;
case SDLK_F8: case SDLK_z:
return sc_F8; return sc_Z;
case SDLK_F9:
return sc_F9;
case SDLK_LEFT:
case SDLK_KP4:
return sc_LeftArrow;
case SDLK_RIGHT:
case SDLK_KP6:
return sc_RightArrow;
case SDLK_UP:
case SDLK_KP8:
return sc_UpArrow;
case SDLK_DOWN:
case SDLK_KP2:
return sc_DownArrow;
case SDLK_LCTRL:
return sc_Control;
case SDLK_LALT:
return sc_Alt;
case SDLK_LSHIFT:
return sc_LShift;
case SDLK_RSHIFT:
return sc_RShift;
case SDLK_ESCAPE:
return sc_Escape;
case SDLK_SPACE:
return sc_Space;
case SDLK_KP_ENTER:
case SDLK_RETURN:
return sc_Enter;
case SDLK_TAB:
return sc_Tab;
case SDLK_BACKSPACE:
return sc_BackSpace;
case SDLK_PAUSE: case SDLK_PAUSE:
return 0xE1; return 0xE1;
default: default:
...@@ -256,7 +333,10 @@ static int XKeysymToScancode(unsigned int keysym) ...@@ -256,7 +333,10 @@ static int XKeysymToScancode(unsigned int keysym)
void INL_Update() void INL_Update()
{ {
SDL_Event event; SDL_Event event;
boolean DebouncedKeyboard[NumCodes];
memcpy(DebouncedKeyboard, InternalKeyboard, sizeof(DebouncedKeyboard));
if (SDL_PollEvent(&event)) { if (SDL_PollEvent(&event)) {
do { do {
switch(event.type) { switch(event.type) {
...@@ -271,4 +351,50 @@ void INL_Update() ...@@ -271,4 +351,50 @@ void INL_Update()
} }
} while (SDL_PollEvent(&event)); } while (SDL_PollEvent(&event));
} }
if (InternalKeyboard[sc_Alt] &&
(!DebouncedKeyboard[sc_Return] && InternalKeyboard[sc_Return])) {
SDL_GrabMode gm;
SDL_WM_ToggleFullScreen(surface);
gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
if (gm == SDL_GRAB_OFF && !(surface->flags & SDL_FULLSCREEN))
SDL_ShowCursor(1);
else
SDL_ShowCursor(0);
}
if (InternalKeyboard[sc_Control] &&
(!DebouncedKeyboard[sc_G] && InternalKeyboard[sc_G])) {
SDL_GrabMode gm;
gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
SDL_WM_GrabInput((gm == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON);
gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
if (gm == SDL_GRAB_OFF && !(surface->flags & SDL_FULLSCREEN))
SDL_ShowCursor(1);
else
SDL_ShowCursor(0);
}
/* ctrl-z for iconify window? */
}
void IN_GetMouseDelta(int *dx, int *dy)
{
int x, y;
SDL_GetRelativeMouseState(&x, &y);
if (dx)
*dx = x;
if (dy)
*dy = y;
}
byte IN_MouseButtons()
{
return SDL_GetMouseState(NULL, NULL);
} }
...@@ -1896,7 +1896,7 @@ void EnterCtrlData(int index,CustomCtrls *cust,void (*DrawRtn)(int),void (*Print ...@@ -1896,7 +1896,7 @@ void EnterCtrlData(int index,CustomCtrls *cust,void (*DrawRtn)(int),void (*Print
switch(type) switch(type)
{ {
case MOUSE: case MOUSE:
button = 0; /* TODO */ button = IN_MouseButtons();
switch(button) switch(button)
{ {
case 1: result=1; break; case 1: result=1; break;
......
...@@ -310,6 +310,8 @@ void PollMouseMove() ...@@ -310,6 +310,8 @@ void PollMouseMove()
{ {
int mousexmove = 0, mouseymove = 0; int mousexmove = 0, mouseymove = 0;
IN_GetMouseDelta(&mousexmove, &mouseymove);
controlx += mousexmove*10/(13-mouseadjustment); controlx += mousexmove*10/(13-mouseadjustment);
controly += mouseymove*20/(13-mouseadjustment); controly += mouseymove*20/(13-mouseadjustment);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment