Makefile.am: misc. fixes to changelog building.

input.h: Use int_val for freelook
cl_input.c: Use freelook macro instead of in_mlook.state
in_svgalib.c: freelook support and whitespace
in_win.c: whitespace and minor optimization in mouse support
in_x11.c: freelook support
vid_ggi.c: joystick support and minor opt in mouse support
vid_sdl.c: joystick support, freelook support, minor mouse opt, spaces->tabs
This commit is contained in:
Jeff Teunissen 2000-10-13 05:36:46 +00:00
parent 40269b2bb5
commit 8903d650d2
8 changed files with 389 additions and 360 deletions

View file

@ -10,9 +10,7 @@ EXTRA_DIST = README.WIN newtree.dsw ChangeLog \
tools/gas2masm/gas2masm.mak tools/gas2masm/gas2masm.mdp \ tools/gas2masm/gas2masm.mak tools/gas2masm/gas2masm.mdp \
tools/zpak tools/zpak
bin_SCRIPTS = ChangeLog changelog::
ChangeLog:
-touch ChangeLog -touch ChangeLog
-tools/cvs2cl/cvs2cl.pl -tools/cvs2cl/cvs2cl.pl
-rm -f ChangeLog.bak -rm -f ChangeLog.bak

View file

@ -32,7 +32,7 @@
#include "protocol.h" #include "protocol.h"
#include "cvar.h" #include "cvar.h"
#define freelook (in_mlook.state&1 || cl_freelook->value) #define freelook (in_mlook.state&1 || cl_freelook->int_val)
void IN_Init (void); void IN_Init (void);

View file

@ -29,7 +29,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif #endif
#include "in_win.h" #include "input.h"
#include "sys.h" #include "sys.h"
#include "sys.h" #include "sys.h"
#include "cvar.h" #include "cvar.h"
@ -145,7 +145,7 @@ void IN_KLookUp (void) {KeyUp(&in_klook);}
void IN_MLookDown (void) {KeyDown(&in_mlook);} void IN_MLookDown (void) {KeyDown(&in_mlook);}
void IN_MLookUp (void) { void IN_MLookUp (void) {
KeyUp(&in_mlook); KeyUp(&in_mlook);
if ( !(in_mlook.state&1 || cl_freelook->value) && lookspring->value) if ( !freelook && lookspring->value)
V_StartPitchDrift(); V_StartPitchDrift();
} }
void IN_UpDown(void) {KeyDown(&in_up);} void IN_UpDown(void) {KeyDown(&in_up);}

View file

@ -38,6 +38,7 @@
#include "cvar.h" #include "cvar.h"
#include "cmd.h" #include "cmd.h"
#include "qargs.h" #include "qargs.h"
#include "input.h"
#include "joystick.h" #include "joystick.h"
#include <stdio.h> #include <stdio.h>
@ -102,7 +103,8 @@ void Force_CenterView_f(void)
} }
int IN_Init(void) void
IN_Init (void)
{ {
if (COM_CheckParm("-nokbd")) UseKeyboard = 0; if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
if (COM_CheckParm("-nomouse")) UseMouse = 0; if (COM_CheckParm("-nomouse")) UseMouse = 0;
@ -115,10 +117,11 @@ int IN_Init(void)
JOY_Init(); JOY_Init();
in_svgalib_inited = 1; in_svgalib_inited = 1;
return 1; return;
} }
static void IN_init_kb() static void
IN_init_kb (void)
{ {
int i; int i;
@ -232,13 +235,14 @@ static void IN_init_kb()
scantokey[111] = K_DEL; scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE; scantokey[119] = K_PAUSE;
if (keyboard_init()) { if (keyboard_init ()) {
Sys_Error("keyboard_init() failed"); Sys_Error ("keyboard_init() failed");
} }
keyboard_seteventhandler(keyhandler); keyboard_seteventhandler(keyhandler);
} }
static void IN_init_mouse() static void
IN_init_mouse()
{ {
int mtype; int mtype;
char *mousedev; char *mousedev;
@ -339,7 +343,7 @@ void IN_Move(usercmd_t *cmd)
while (mouse_update()) while (mouse_update())
; ;
if (m_filter->value) { if (m_filter->int_val) {
mouse_x = (mx + old_mouse_x) * 0.5; mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5; mouse_y = (my + old_mouse_y) * 0.5;
} else { } else {
@ -355,23 +359,18 @@ void IN_Move(usercmd_t *cmd)
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
/* Add mouse X/Y movement to cmd */ /* Add mouse X/Y movement to cmd */
if ( (in_strafe.state & 1) || if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
(lookstrafe->value && (in_mlook.state & 1) )) {
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
} else { } else {
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
} }
if ((in_mlook.state & 1)) V_StopPitchDrift(); if (freelook)
V_StopPitchDrift();
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) { cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80;
}
if (cl.viewangles[PITCH] < -70) {
cl.viewangles[PITCH] = -70;
}
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) { if ((in_strafe.state & 1) && noclip_anglehack) {
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;

View file

@ -717,7 +717,7 @@ void IN_MouseMove (usercmd_t *cmd)
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd // add mouse X/Y movement to cmd
if ( (in_strafe.state & 1) || (lookstrafe->value && freelook )) if ( (in_strafe.state & 1) || (lookstrafe->value && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
@ -725,16 +725,10 @@ void IN_MouseMove (usercmd_t *cmd)
if (freelook) if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( freelook && !(in_strafe.state & 1)) if ( freelook && !(in_strafe.state & 1)) {
{
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80; } else {
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;
else else

View file

@ -35,11 +35,18 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
@ -59,12 +66,9 @@
#include "console.h" #include "console.h"
#include "client.h" #include "client.h"
#include "context_x11.h" #include "context_x11.h"
#include "qargs.h" #include "input.h"
#include "joystick.h" #include "joystick.h"
#include "qargs.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
cvar_t *_windowed_mouse; cvar_t *_windowed_mouse;
cvar_t *m_filter; cvar_t *m_filter;
@ -302,18 +306,19 @@ void
IN_Commands (void) IN_Commands (void)
{ {
JOY_Command (); JOY_Command ();
if (old__windowed_mouse != _windowed_mouse->value) {
old__windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) { if (old__windowed_mouse != _windowed_mouse->int_val) {
old__windowed_mouse = _windowed_mouse->int_val;
if (!_windowed_mouse->int_val) {
/* ungrab the pointer */ /* ungrab the pointer */
XUngrabPointer(x_disp,CurrentTime); XUngrabPointer (x_disp, CurrentTime);
} else { } else {
/* grab the pointer */ /* grab the pointer */
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync, XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime); GrabModeAsync, x_win, None, CurrentTime);
//XGrabPointer(x_disp,x_win,True,0,GrabModeAsync, // XGrabPointer (x_disp,x_win,True,0,GrabModeAsync,
// GrabModeAsync,x_win,None,CurrentTime); // GrabModeAsync,x_win,None,CurrentTime);
} }
} }
} }
@ -335,7 +340,7 @@ IN_Move (usercmd_t *cmd)
if (!mouse_avail) if (!mouse_avail)
return; return;
if (m_filter->value) { if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5; mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5; mouse_y = (mouse_y + old_mouse_y) * 0.5;
} }
@ -346,14 +351,15 @@ IN_Move (usercmd_t *cmd)
mouse_x *= sensitivity->value; mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80); cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else { } else {
@ -390,13 +396,14 @@ void
IN_Shutdown (void) IN_Shutdown (void)
{ {
JOY_Shutdown (); JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0; mouse_avail = 0;
if (x_disp) { if (x_disp) {
XAutoRepeatOn(x_disp); XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA #ifdef HAVE_DGA
XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0); XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif #endif
} }
x11_close_display(); x11_close_display();
@ -404,7 +411,7 @@ IN_Shutdown (void)
extern int scr_width, scr_height; extern int scr_width, scr_height;
int void
IN_Init (void) IN_Init (void)
{ {
// open the display // open the display
@ -433,7 +440,8 @@ IN_Init (void)
XAutoRepeatOff(x_disp); XAutoRepeatOff(x_disp);
if (COM_CheckParm("-nomouse")) return 1; if (COM_CheckParm("-nomouse"))
return;
#ifdef HAVE_DGA #ifdef HAVE_DGA
in_dgamouse = Cvar_Get ("in_dgamouse", "0", CVAR_ROM, in_dgamouse = Cvar_Get ("in_dgamouse", "0", CVAR_ROM,
"1 if you have DGA mouse support"); "1 if you have DGA mouse support");
@ -473,5 +481,5 @@ IN_Init (void)
x11_add_event(ButtonRelease, &event_button); x11_add_event(ButtonRelease, &event_button);
x11_add_event(MotionNotify, &event_motion); x11_add_event(MotionNotify, &event_motion);
return 1; return;
} }

View file

@ -67,6 +67,8 @@
#include "d_local.h" #include "d_local.h"
#include "input.h" #include "input.h"
#include "joystick.h"
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
@ -910,6 +912,8 @@ void IN_SendKeyEvents(void)
void void
IN_Init(void) IN_Init(void)
{ {
JOY_Init ();
_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); _windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
old_windowed_mouse = -1; /* Force update */ old_windowed_mouse = -1; /* Force update */
m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None"); m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None");
@ -923,6 +927,9 @@ IN_Init(void)
void void
IN_Shutdown(void) IN_Shutdown(void)
{ {
JOY_Shutdown ();
Con_Printf("IN_Shutdown\n");
mouse_avail = 0; mouse_avail = 0;
} }
@ -930,6 +937,8 @@ IN_Shutdown(void)
void void
IN_Commands (void) IN_Commands (void)
{ {
JOY_Command ();
/* Only supported by LibGII 0.7 or later. */ /* Only supported by LibGII 0.7 or later. */
#ifdef GII_CMDCODE_PREFER_RELPTR #ifdef GII_CMDCODE_PREFER_RELPTR
if (old_windowed_mouse != _windowed_mouse->value) { if (old_windowed_mouse != _windowed_mouse->value) {
@ -952,9 +961,12 @@ IN_Commands (void)
void void
IN_Move(usercmd_t *cmd) IN_Move(usercmd_t *cmd)
{ {
if (!mouse_avail) return; JOY_Move (cmd);
if (!mouse_avail)
return;
if (m_filter->value) { if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5; mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5; mouse_y = (mouse_y + old_mouse_y) * 0.5;
} }
@ -965,19 +977,16 @@ IN_Move(usercmd_t *cmd)
mouse_x *= sensitivity->value; mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->value && freelook )) if ( (in_strafe.state & 1) || (lookstrafe->int_val && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (freelook) if (freelook)
V_StopPitchDrift (); V_StopPitchDrift ();
if ( freelook && !(in_strafe.state & 1)) { if (freelook && !(in_strafe.state & 1)) {
cl.viewangles[PITCH] += m_pitch->value * mouse_y; cl.viewangles[PITCH] += m_pitch->value * mouse_y;
if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;

View file

@ -38,26 +38,26 @@
#include "menu.h" #include "menu.h"
#include "vid.h" #include "vid.h"
#include "sys.h" #include "sys.h"
#include "mathlib.h" // needed by: protocol.h, render.h, client.h, #include "mathlib.h" // needed by: protocol.h, render.h, client.h,
// modelgen.h, glmodel.h // modelgen.h, glmodel.h
#include "wad.h" #include "wad.h"
#include "draw.h" #include "draw.h"
#include "cvar.h" #include "cvar.h"
#include "net.h" // needed by: client.h #include "net.h" // needed by: client.h
#include "protocol.h" // needed by: client.h #include "protocol.h" // needed by: client.h
#include "cmd.h" #include "cmd.h"
#include "keys.h" #include "keys.h"
#include "sbar.h" #include "sbar.h"
#include "sound.h" #include "sound.h"
#include "render.h" // needed by: client.h, gl_model.h, glquake.h #include "render.h" // needed by: client.h, gl_model.h, glquake.h
#include "client.h" // need cls in this file #include "client.h" // need cls in this file
#include "console.h" #include "console.h"
#include "qendian.h" #include "qendian.h"
#include "qargs.h" #include "qargs.h"
#include "compat.h" #include "compat.h"
#include "d_local.h" #include "d_local.h"
#include "input.h" #include "input.h"
#include "joystick.h"
cvar_t *_windowed_mouse; cvar_t *_windowed_mouse;
@ -65,7 +65,7 @@ int old_windowed_mouse;
// static float oldin_grab = 0; // static float oldin_grab = 0;
extern viddef_t vid; // global video state extern viddef_t vid; // global video state
unsigned short d_8to16table[256]; unsigned short d_8to16table[256];
#ifdef WIN32 #ifdef WIN32
@ -75,16 +75,16 @@ HWND mainwindow;
#endif #endif
int modestate; // fixme: just to avoid cross-comp. errors - remove later int modestate; // fixme: just to avoid cross-comp. errors - remove later
// The original defaults // The original defaults
//#define BASEWIDTH 320 //#define BASEWIDTH 320
//#define BASEHEIGHT 200 //#define BASEHEIGHT 200
// Much better for high resolution displays // Much better for high resolution displays
#define BASEWIDTH (320*2) #define BASEWIDTH (320*2)
#define BASEHEIGHT (200*2) #define BASEHEIGHT (200*2)
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0; int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
byte *VGA_pagebase; byte *VGA_pagebase;
static SDL_Surface *screen = NULL; static SDL_Surface *screen = NULL;
@ -92,134 +92,137 @@ static qboolean mouse_avail;
static float mouse_x, mouse_y; static float mouse_x, mouse_y;
static int mouse_oldbuttonstate = 0; static int mouse_oldbuttonstate = 0;
void VID_SetPalette (unsigned char *palette) void
VID_SetPalette (unsigned char *palette)
{ {
int i; int i;
SDL_Color colors[256]; SDL_Color colors[256];
for ( i=0; i<256; ++i ) for ( i=0; i<256; ++i ) {
{ colors[i].r = *palette++;
colors[i].r = *palette++; colors[i].g = *palette++;
colors[i].g = *palette++; colors[i].b = *palette++;
colors[i].b = *palette++; }
} SDL_SetColors(screen, colors, 0, 256);
SDL_SetColors(screen, colors, 0, 256);
} }
void VID_ShiftPalette (unsigned char *palette) void
VID_ShiftPalette (unsigned char *palette)
{ {
VID_SetPalette(palette); VID_SetPalette(palette);
} }
void VID_Init (unsigned char *palette) void
VID_Init (unsigned char *palette)
{ {
int pnum, chunk; int pnum, chunk;
byte *cache; byte *cache;
int cachesize; int cachesize;
//Uint8 video_bpp; //Uint8 video_bpp;
//Uint16 video_w, video_h; //Uint16 video_w, video_h;
Uint32 flags; Uint32 flags;
// Load the SDL library // Load the SDL library
if (SDL_Init(SDL_INIT_VIDEO)<0) //|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0) if (SDL_Init (SDL_INIT_VIDEO) < 0) //|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0)
Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError()); Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());
// Set up display mode (width and height) // Set up display mode (width and height)
vid.width = BASEWIDTH; vid.width = BASEWIDTH;
vid.height = BASEHEIGHT; vid.height = BASEHEIGHT;
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
if ((pnum=COM_CheckParm("-winsize"))) if ((pnum=COM_CheckParm("-winsize"))) {
{ if (pnum >= com_argc-2)
if (pnum >= com_argc-2) Sys_Error("VID: -winsize <width> <height>\n");
Sys_Error("VID: -winsize <width> <height>\n"); vid.width = atoi(com_argv[pnum+1]);
vid.width = atoi(com_argv[pnum+1]); vid.height = atoi(com_argv[pnum+2]);
vid.height = atoi(com_argv[pnum+2]); if (!vid.width || !vid.height)
if (!vid.width || !vid.height) Sys_Error("VID: Bad window width/height\n");
Sys_Error("VID: Bad window width/height\n"); }
}
// Set video width, height and flags // Set video width, height and flags
flags = (SDL_SWSURFACE|SDL_HWPALETTE); flags = (SDL_SWSURFACE|SDL_HWPALETTE);
if ( COM_CheckParm ("-fullscreen") ) if ( COM_CheckParm ("-fullscreen") )
flags |= SDL_FULLSCREEN; flags |= SDL_FULLSCREEN;
// Initialize display // Initialize display
if (!(screen = SDL_SetVideoMode(vid.width, vid.height, 8, flags))) if (!(screen = SDL_SetVideoMode(vid.width, vid.height, 8, flags)))
Sys_Error("VID: Couldn't set video mode: %s\n", SDL_GetError()); Sys_Error("VID: Couldn't set video mode: %s\n", SDL_GetError());
VID_SetPalette(palette); VID_SetPalette(palette);
VID_SetCaption(""); VID_SetCaption("");
// now know everything we need to know about the buffer // now know everything we need to know about the buffer
VGA_width = vid.conwidth = vid.width; VGA_width = vid.conwidth = vid.width;
VGA_height = vid.conheight = vid.height; VGA_height = vid.conheight = vid.height;
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0); vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
vid.numpages = 1; vid.numpages = 1;
vid.colormap = host_colormap; vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
VGA_pagebase = vid.buffer = screen->pixels; VGA_pagebase = vid.buffer = screen->pixels;
VGA_rowbytes = vid.rowbytes = screen->pitch; VGA_rowbytes = vid.rowbytes = screen->pitch;
vid.conbuffer = vid.buffer; vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes; vid.conrowbytes = vid.rowbytes;
vid.direct = 0; vid.direct = 0;
// allocate z buffer and surface cache // allocate z buffer and surface cache
chunk = vid.width * vid.height * sizeof (*d_pzbuffer); chunk = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height); cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
chunk += cachesize; chunk += cachesize;
d_pzbuffer = Hunk_HighAllocName(chunk, "video"); d_pzbuffer = Hunk_HighAllocName(chunk, "video");
if (d_pzbuffer == NULL) if (d_pzbuffer == NULL)
Sys_Error ("Not enough memory for video mode\n"); Sys_Error ("Not enough memory for video mode\n");
// initialize the cache memory // initialize the cache memory
cache = (byte *) d_pzbuffer cache = (byte *) d_pzbuffer + vid.width * vid.height * sizeof (*d_pzbuffer);
+ vid.width * vid.height * sizeof (*d_pzbuffer); D_InitCaches (cache, cachesize);
D_InitCaches (cache, cachesize);
// initialize the mouse // initialize the mouse
SDL_ShowCursor(0); SDL_ShowCursor(0);
#ifdef WIN32 #ifdef WIN32
// fixme: EVIL thing - but needed for win32 until we get // fixme: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails. // SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo // could replace this with SDL_SysWMInfo
mainwindow=GetActiveWindow(); mainwindow=GetActiveWindow();
#endif #endif
} }
void VID_Shutdown (void) void
VID_Shutdown (void)
{ {
SDL_Quit(); SDL_Quit();
} }
void VID_Update (vrect_t *rects) void
VID_Update (vrect_t *rects)
{ {
SDL_Rect *sdlrects; SDL_Rect *sdlrects;
int n, i; int n, i;
vrect_t *rect; vrect_t *rect;
// Two-pass system, since Quake doesn't do it the SDL way... // Two-pass system, since Quake doesn't do it the SDL way...
// First, count the number of rectangles // First, count the number of rectangles
n = 0; n = 0;
for (rect = rects; rect; rect = rect->pnext) for (rect = rects; rect; rect = rect->pnext)
++n; ++n;
// Second, copy them to SDL rectangles and update // Second, copy them to SDL rectangles and update
if(!(sdlrects=(SDL_Rect *)calloc(1,n*sizeof(SDL_Rect)))) if(!(sdlrects=(SDL_Rect *)calloc(1,n*sizeof(SDL_Rect))))
Sys_Error("Out of memory!"); Sys_Error("Out of memory!");
i = 0;
for (rect = rects; rect; rect = rect->pnext) i = 0;
{
sdlrects[i].x = rect->x; for (rect = rects; rect; rect = rect->pnext) {
sdlrects[i].y = rect->y; sdlrects[i].x = rect->x;
sdlrects[i].w = rect->width; sdlrects[i].y = rect->y;
sdlrects[i].h = rect->height; sdlrects[i].w = rect->width;
++i; sdlrects[i].h = rect->height;
} ++i;
SDL_UpdateRects(screen, n, sdlrects); }
SDL_UpdateRects (screen, n, sdlrects);
} }
/* /*
@ -227,20 +230,23 @@ void VID_Update (vrect_t *rects)
D_BeginDirectRect D_BeginDirectRect
================ ================
*/ */
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{ {
Uint8 *offset; Uint8 *offset;
if (!screen)
return;
if (!screen) return; if ( x < 0 )
if ( x < 0 ) x = screen->w+x-1; x = screen->w+x-1;
offset = (Uint8 *)screen->pixels + y*screen->pitch + x;
while ( height-- ) offset = (Uint8 *)screen->pixels + y*screen->pitch + x;
{ while (height--) {
memcpy(offset, pbitmap, width); memcpy (offset, pbitmap, width);
offset += screen->pitch; offset += screen->pitch;
pbitmap += width; pbitmap += width;
} }
} }
@ -249,11 +255,16 @@ void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
D_EndDirectRect D_EndDirectRect
================ ================
*/ */
void D_EndDirectRect (int x, int y, int width, int height) void
D_EndDirectRect (int x, int y, int width, int height)
{ {
if (!screen) return; if (!screen)
if (x < 0) x = screen->w+x-1; return;
SDL_UpdateRect(screen, x, y, width, height);
if (x < 0)
x = screen->w+x-1;
SDL_UpdateRect(screen, x, y, width, height);
} }
@ -269,105 +280,105 @@ void IN_SendKeyEvents (void)
int sym, state, but; int sym, state, but;
int modstate; int modstate;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
switch (event.type) { switch (event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
sym = event.key.keysym.sym; sym = event.key.keysym.sym;
state = event.key.state; state = event.key.state;
modstate = SDL_GetModState(); modstate = SDL_GetModState();
switch(sym) switch(sym)
{ {
case SDLK_DELETE: sym = K_DEL; break; case SDLK_DELETE: sym = K_DEL; break;
case SDLK_BACKSPACE: sym = K_BACKSPACE; break; case SDLK_BACKSPACE: sym = K_BACKSPACE; break;
case SDLK_F1: sym = K_F1; break; case SDLK_F1: sym = K_F1; break;
case SDLK_F2: sym = K_F2; break; case SDLK_F2: sym = K_F2; break;
case SDLK_F3: sym = K_F3; break; case SDLK_F3: sym = K_F3; break;
case SDLK_F4: sym = K_F4; break; case SDLK_F4: sym = K_F4; break;
case SDLK_F5: sym = K_F5; break; case SDLK_F5: sym = K_F5; break;
case SDLK_F6: sym = K_F6; break; case SDLK_F6: sym = K_F6; break;
case SDLK_F7: sym = K_F7; break; case SDLK_F7: sym = K_F7; break;
case SDLK_F8: sym = K_F8; break; case SDLK_F8: sym = K_F8; break;
case SDLK_F9: sym = K_F9; break; case SDLK_F9: sym = K_F9; break;
case SDLK_F10: sym = K_F10; break; case SDLK_F10: sym = K_F10; break;
case SDLK_F11: sym = K_F11; break; case SDLK_F11: sym = K_F11; break;
case SDLK_F12: sym = K_F12; break; case SDLK_F12: sym = K_F12; break;
case SDLK_BREAK: case SDLK_BREAK:
case SDLK_PAUSE: sym = K_PAUSE; break; case SDLK_PAUSE: sym = K_PAUSE; break;
case SDLK_UP: sym = K_UPARROW; break; case SDLK_UP: sym = K_UPARROW; break;
case SDLK_DOWN: sym = K_DOWNARROW; break; case SDLK_DOWN: sym = K_DOWNARROW; break;
case SDLK_RIGHT: sym = K_RIGHTARROW; break; case SDLK_RIGHT: sym = K_RIGHTARROW; break;
case SDLK_LEFT: sym = K_LEFTARROW; break; case SDLK_LEFT: sym = K_LEFTARROW; break;
case SDLK_INSERT: sym = K_INS; break; case SDLK_INSERT: sym = K_INS; break;
case SDLK_HOME: sym = K_HOME; break; case SDLK_HOME: sym = K_HOME; break;
case SDLK_END: sym = K_END; break; case SDLK_END: sym = K_END; break;
case SDLK_PAGEUP: sym = K_PGUP; break; case SDLK_PAGEUP: sym = K_PGUP; break;
case SDLK_PAGEDOWN: sym = K_PGDN; break; case SDLK_PAGEDOWN: sym = K_PGDN; break;
case SDLK_RSHIFT: case SDLK_RSHIFT:
case SDLK_LSHIFT: sym = K_SHIFT; break; case SDLK_LSHIFT: sym = K_SHIFT; break;
case SDLK_RCTRL: case SDLK_RCTRL:
case SDLK_LCTRL: sym = K_CTRL; break; case SDLK_LCTRL: sym = K_CTRL; break;
case SDLK_RALT: case SDLK_RALT:
case SDLK_LALT: sym = K_ALT; break; case SDLK_LALT: sym = K_ALT; break;
case SDLK_CAPSLOCK: sym = K_CAPSLOCK; break; case SDLK_CAPSLOCK: sym = K_CAPSLOCK; break;
case SDLK_KP0: case SDLK_KP0:
if(modstate & KMOD_NUM) sym = K_INS; if(modstate & KMOD_NUM) sym = K_INS;
else sym = SDLK_0; else sym = SDLK_0;
break; break;
case SDLK_KP1: case SDLK_KP1:
if(modstate & KMOD_NUM) sym = K_END; if(modstate & KMOD_NUM) sym = K_END;
else sym = SDLK_1; else sym = SDLK_1;
break; break;
case SDLK_KP2: case SDLK_KP2:
if(modstate & KMOD_NUM) sym = K_DOWNARROW; if(modstate & KMOD_NUM) sym = K_DOWNARROW;
else sym = SDLK_2; else sym = SDLK_2;
break; break;
case SDLK_KP3: case SDLK_KP3:
if(modstate & KMOD_NUM) sym = K_PGDN; if(modstate & KMOD_NUM) sym = K_PGDN;
else sym = SDLK_3; else sym = SDLK_3;
break; break;
case SDLK_KP4: case SDLK_KP4:
if(modstate & KMOD_NUM) sym = K_LEFTARROW; if(modstate & KMOD_NUM) sym = K_LEFTARROW;
else sym = SDLK_4; else sym = SDLK_4;
break; break;
case SDLK_KP5: sym = SDLK_5; break; case SDLK_KP5: sym = SDLK_5; break;
case SDLK_KP6: case SDLK_KP6:
if(modstate & KMOD_NUM) sym = K_RIGHTARROW; if(modstate & KMOD_NUM) sym = K_RIGHTARROW;
else sym = SDLK_6; else sym = SDLK_6;
break; break;
case SDLK_KP7: case SDLK_KP7:
if(modstate & KMOD_NUM) sym = K_HOME; if(modstate & KMOD_NUM) sym = K_HOME;
else sym = SDLK_7; else sym = SDLK_7;
break; break;
case SDLK_KP8: case SDLK_KP8:
if(modstate & KMOD_NUM) sym = K_UPARROW; if(modstate & KMOD_NUM) sym = K_UPARROW;
else sym = SDLK_8; else sym = SDLK_8;
break; break;
case SDLK_KP9: case SDLK_KP9:
if(modstate & KMOD_NUM) sym = K_PGUP; if(modstate & KMOD_NUM) sym = K_PGUP;
else sym = SDLK_9; else sym = SDLK_9;
break; break;
case SDLK_KP_PERIOD: case SDLK_KP_PERIOD:
if(modstate & KMOD_NUM) sym = K_DEL; if(modstate & KMOD_NUM) sym = K_DEL;
else sym = SDLK_PERIOD; else sym = SDLK_PERIOD;
break; break;
case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break; case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break;
case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break; case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break;
case SDLK_KP_MINUS: sym = SDLK_MINUS; break; case SDLK_KP_MINUS: sym = SDLK_MINUS; break;
case SDLK_KP_PLUS: sym = SDLK_PLUS; break; case SDLK_KP_PLUS: sym = SDLK_PLUS; break;
case SDLK_KP_ENTER: sym = SDLK_RETURN; break; case SDLK_KP_ENTER: sym = SDLK_RETURN; break;
case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break; case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break;
} }
// If we're not directly handled and still above 255 // If we're not directly handled and still above 255
// just force it to 0 // just force it to 0
if(sym > 255) sym = 0; if(sym > 255) sym = 0;
Key_Event(sym, state); Key_Event(sym, state);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
but = event.button.button; but = event.button.button;
if (but == 2) if (but == 2)
but = 3; but = 3;
@ -393,116 +404,126 @@ void IN_SendKeyEvents (void)
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (_windowed_mouse->value) if (_windowed_mouse->value)
{ {
if ((event.motion.x != (vid.width/2)) if ((event.motion.x != (vid.width/2))
|| (event.motion.y != (vid.height/2)) ) || (event.motion.y != (vid.height/2)) )
{ {
mouse_x = event.motion.xrel*10; mouse_x = event.motion.xrel*10;
mouse_y = event.motion.yrel*10; mouse_y = event.motion.yrel*10;
if ((event.motion.x < ((vid.width/2)-(vid.width/4))) || if ((event.motion.x < ((vid.width/2)-(vid.width/4))) ||
(event.motion.x > ((vid.width/2)+(vid.width/4))) || (event.motion.x > ((vid.width/2)+(vid.width/4))) ||
(event.motion.y < ((vid.height/2)-(vid.height/4))) || (event.motion.y < ((vid.height/2)-(vid.height/4))) ||
(event.motion.y > ((vid.height/2)+(vid.height/4))) ) (event.motion.y > ((vid.height/2)+(vid.height/4))) )
SDL_WarpMouse(vid.width/2, vid.height/2); SDL_WarpMouse(vid.width/2, vid.height/2);
} }
} }
else else
{ {
mouse_x = event.motion.xrel*10; mouse_x = event.motion.xrel*10;
mouse_y = event.motion.yrel*10; mouse_y = event.motion.yrel*10;
} }
break; break;
case SDL_QUIT: case SDL_QUIT:
CL_Disconnect (); CL_Disconnect ();
Sys_Quit (); Sys_Quit ();
break; break;
default: default:
break; break;
} }
} }
} }
void void
IN_Commands (void) IN_Commands (void)
{ {
if (old_windowed_mouse != _windowed_mouse->value) JOY_Command ();
{
if (old_windowed_mouse != _windowed_mouse->int_val) {
old_windowed_mouse = _windowed_mouse->value; old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value)
SDL_WM_GrabInput (SDL_GRAB_OFF); if (_windowed_mouse->int_val)
else
SDL_WM_GrabInput (SDL_GRAB_ON); SDL_WM_GrabInput (SDL_GRAB_ON);
else
SDL_WM_GrabInput (SDL_GRAB_OFF);
} }
} }
void IN_Init (void) void
IN_Init (void)
{ {
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None"); JOY_Init ();
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
if ( COM_CheckParm("-nomouse") && !_windowed_mouse->value) if ( COM_CheckParm("-nomouse") && !_windowed_mouse->value)
return; return;
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
mouse_avail = 1; mouse_avail = 1;
} }
void IN_Shutdown (void) void
IN_Shutdown (void)
{ {
mouse_avail = 0; JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0;
} }
void IN_Frame(void) void IN_Frame(void)
{ {
int i; int i;
int mouse_buttonstate; int mouse_buttonstate;
if (!mouse_avail) return; if (!mouse_avail) return;
i = SDL_GetMouseState(NULL, NULL); i = SDL_GetMouseState(NULL, NULL);
/* Quake swaps the second and third buttons */ /* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02)<<1) | ((i & 0x04)>>1); mouse_buttonstate = (i & ~0x06) | ((i & 0x02)<<1) | ((i & 0x04)>>1);
for (i=0 ; i<3 ; i++) { for (i=0 ; i<3 ; i++) {
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) ) if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, true); Key_Event (K_MOUSE1 + i, true);
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) ) if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
Key_Event (K_MOUSE1 + i, false); Key_Event (K_MOUSE1 + i, false);
} }
mouse_oldbuttonstate = mouse_buttonstate; mouse_oldbuttonstate = mouse_buttonstate;
} }
void IN_Move (usercmd_t *cmd) void
IN_Move (usercmd_t *cmd)
{ {
if (!mouse_avail) JOY_Move (cmd);
return;
if (!mouse_avail)
return;
mouse_x *= sensitivity->value; mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value; mouse_y *= sensitivity->value;
if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) if ( (in_strafe.state & 1) || (lookstrafe->value && freelook))
cmd->sidemove += m_side->value * mouse_x; cmd->sidemove += m_side->value * mouse_x;
else else
cl.viewangles[YAW] -= m_yaw->value * mouse_x; cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if (in_mlook.state & 1)
V_StopPitchDrift ();
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { if (freelook)
cl.viewangles[PITCH] += m_pitch->value * mouse_y; V_StopPitchDrift ();
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80; if (freelook && !(in_strafe.state & 1)) {
if (cl.viewangles[PITCH] < -70) cl.viewangles[PITCH] += m_pitch->value * mouse_y;
cl.viewangles[PITCH] = -70; cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
} else { } else {
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward->value * mouse_y; cmd->upmove -= m_forward->value * mouse_y;
else else
cmd->forwardmove -= m_forward->value * mouse_y; cmd->forwardmove -= m_forward->value * mouse_y;
} }
mouse_x = mouse_y = 0.0; mouse_x = mouse_y = 0.0;
} }
@ -511,15 +532,15 @@ void VID_InitCvars ()
// It may not look like it, but this is important // It may not look like it, but this is important
} }
void void
VID_LockBuffer ( void ) VID_LockBuffer ( void )
{ {
} }
void void
VID_UnlockBuffer ( void ) VID_UnlockBuffer ( void )
{ {
} }
void void
VID_SetCaption (char *text) VID_SetCaption (char *text)