hacky, but it works

This commit is contained in:
Bill Currie 2001-12-22 08:23:10 +00:00
parent f71b23e88d
commit 89842bdf60
3 changed files with 802 additions and 86 deletions

View file

@ -1003,7 +1003,6 @@ REF_GL_OBJS = \
\
$(BUILDDIR)/ref_gl/qgl_linux.o \
$(BUILDDIR)/ref_gl/gl_glx.o \
$(BUILDDIR)/ref_gl/rw_in_svgalib.o \
$(BUILDDIR)/ref_gl/q_shared.o \
$(BUILDDIR)/ref_gl/q_shlinux.o \
$(BUILDDIR)/ref_gl/glob.o

View file

@ -12,77 +12,134 @@
**
*/
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/vt.h>
#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include <GL/glx.h>
#include "../ref_gl/gl_local.h"
#include "../client/keys.h"
#include "../linux/rw_linux.h"
#include <GL/gl.h>
#include <GL/glx.h>
GLXContext gl_cx;
/*****************************************************************************/
static qboolean doShm;
static Display *x_disp;
static Colormap x_cmap;
static Window x_win;
static GC x_gc;
static Visual *x_vis;
static XVisualInfo *x_visinfo;
static qboolean GLimp_SwitchFullscreen( int width, int height );
qboolean GLimp_InitGL (void);
extern cvar_t *vid_fullscreen;
extern cvar_t *vid_ref;
static GLXContext fc = NULL;
/*
#define NUM_RESOLUTIONS 3
static resolutions[NUM_RESOLUTIONS][3]={
{ 512, 384, GR_RESOLUTION_512x384 },
{ 640, 400, GR_RESOLUTION_640x400 },
{ 640, 480, GR_RESOLUTION_640x480 }
static int StudlyRGBattributes[] =
{
GLX_DOUBLEBUFFER,
GLX_RGBA,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 1,
None,
};
static int findres(int *width, int *height)
static int RGBattributes[] =
{
int i;
GLX_DOUBLEBUFFER,
GLX_RGBA,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 1,
None,
};
#define STD_EVENT_MASK (StructureNotifyMask | KeyPressMask \
| KeyReleaseMask | ExposureMask | PointerMotionMask | \
ButtonPressMask | ButtonReleaseMask)
int current_framebuffer;
static int x_shmeventtype;
//static XShmSegmentInfo x_shminfo;
static qboolean oktodraw = false;
static qboolean X11_active = false;
struct
{
int key;
int down;
} keyq[64];
int keyq_head=0;
int keyq_tail=0;
static int mx, my;
static int p_mouse_x, p_mouse_y;
static cvar_t *_windowed_mouse;
static cvar_t *sensitivity;
static cvar_t *lookstrafe;
static cvar_t *m_side;
static cvar_t *m_yaw;
static cvar_t *m_pitch;
static cvar_t *m_forward;
static cvar_t *freelook;
int config_notify=0;
int config_notify_width;
int config_notify_height;
typedef unsigned short PIXEL;
// Console variables that we need to access from this module
/*****************************************************************************/
/* MOUSE */
/*****************************************************************************/
// this is inside the renderer shared lib, so these are called from vid_so
static qboolean mouse_avail;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static float old_windowed_mouse;
static int p_mouse_x, p_mouse_y;
static cvar_t *_windowed_mouse;
static cvar_t *m_filter;
static cvar_t *in_mouse;
static qboolean mlooking;
// state struct passed in Init
static in_state_t *in_state;
int XShmQueryExtension(Display *);
int XShmGetEventBase(Display *);
for(i=0;i<NUM_RESOLUTIONS;i++)
if((*width<=resolutions[i][0]) && (*height<=resolutions[i][1])) {
*width = resolutions[i][0];
*height = resolutions[i][1];
return resolutions[i][2];
}
*width = 640;
*height = 480;
return GR_RESOLUTION_640x480;
}
*/
static void signal_handler(int sig)
{
printf("Received signal %d, exiting...\n", sig);
fprintf(stderr, "Received signal %d, exiting...\n", sig);
GLimp_Shutdown();
_exit(0);
}
static void InitSig(void)
{
signal(SIGHUP, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGILL, signal_handler);
signal(SIGTRAP, signal_handler);
signal(SIGIOT, signal_handler);
signal(SIGBUS, signal_handler);
signal(SIGFPE, signal_handler);
signal(SIGSEGV, signal_handler);
signal(SIGTERM, signal_handler);
struct sigaction sa;
sigaction(SIGINT, 0, &sa);
sa.sa_handler = signal_handler;
sigaction(SIGINT, &sa, 0);
sigaction(SIGTERM, &sa, 0);
}
extern Display *x_disp;
extern XVisualInfo *x_visinfo;
qboolean GLimp_InitGraphics( qboolean fullscreen );
/*
** GLimp_SetMode
@ -91,7 +148,9 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
int width, height;
GLint attribs[32];
*pwidth=640; *pheight=480;
fprintf(stderr, "GLimp_SetMode\n");
ri.Con_Printf( PRINT_ALL, "Initializing OpenGL display\n");
ri.Con_Printf (PRINT_ALL, "...setting mode %d:", mode );
@ -106,29 +165,19 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
// destroy the existing window
GLimp_Shutdown ();
/*
// set fx attribs
attribs[0] = FXMESA_DOUBLEBUFFER;
attribs[1] = FXMESA_ALPHA_SIZE;
attribs[2] = 1;
attribs[3] = FXMESA_DEPTH_SIZE;
attribs[4] = 1;
attribs[5] = FXMESA_NONE;
fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
attribs);
*/
fc = glXCreateContext (x_disp, x_visinfo, NULL, True);
if (!fc)
return rserr_invalid_mode;
*pwidth = width;
*pheight = height;
if ( !GLimp_InitGraphics( fullscreen ) ) {
// failed to set a valid mode in windowed mode
return rserr_invalid_mode;
}
/* gl_cx = glXCreateContext( x_disp, x_visinfo, 0, True ); */
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (width, height);
fxMesaMakeCurrent(fc);
return rserr_ok;
}
@ -143,10 +192,15 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
*/
void GLimp_Shutdown( void )
{
if (fc) {
fxMesaDestroyContext(fc);
fc = NULL;
}
fprintf(stderr, "GLimp_Shutdown\n");
if (!x_disp)
return;
XSynchronize( x_disp, True );
XAutoRepeatOn(x_disp);
XCloseDisplay(x_disp);
x_disp = NULL;
}
/*
@ -157,6 +211,7 @@ void GLimp_Shutdown( void )
*/
int GLimp_Init( void *hinstance, void *wndproc )
{
// catch signals so i can turn on auto-repeat and stuff
InitSig();
return true;
@ -179,7 +234,7 @@ void GLimp_BeginFrame( float camera_seperation )
void GLimp_EndFrame (void)
{
glFlush();
fxMesaSwapBuffers();
glXSwapBuffers( x_disp, x_win );
}
/*
@ -189,23 +244,685 @@ void GLimp_AppActivate( qboolean active )
{
}
extern void gl3DfxSetPaletteEXT(GLuint *pal);
// ========================================================================
// makes a null cursor
// ========================================================================
void Fake_glColorTableEXT( GLenum target, GLenum internalformat,
GLsizei width, GLenum format, GLenum type,
const GLvoid *table )
static Cursor CreateNullCursor(Display *display, Window root)
{
byte temptable[256][4];
byte *intbl;
int i;
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
Cursor cursor;
for (intbl = (byte *)table, i = 0; i < 256; i++) {
temptable[i][2] = *intbl++;
temptable[i][1] = *intbl++;
temptable[i][0] = *intbl++;
temptable[i][3] = 255;
cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
xgc.function = GXclear;
gc = XCreateGC(display, cursormask, GCFunction, &xgc);
XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
dummycolour.pixel = 0;
dummycolour.red = 0;
dummycolour.flags = 04;
cursor = XCreatePixmapCursor(display, cursormask, cursormask,
&dummycolour,&dummycolour, 0,0);
XFreePixmap(display,cursormask);
XFreeGC(display,gc);
return cursor;
}
/*
** GLimp_InitGraphics
**
** This initializes the GL implementation specific
** graphics subsystem.
**
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*/
qboolean GLimp_InitGraphics( qboolean fullscreen )
{
int pnum, i;
XVisualInfo template;
int num_visuals;
int template_mask;
fprintf(stderr, "GLimp_InitGraphics\n");
srandom(getpid());
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (vid.width, vid.height);
// open the display
x_disp = XOpenDisplay(NULL);
if (!x_disp)
{
if (getenv("DISPLAY"))
Sys_Error("VID: Could not open display [%s]\n",
getenv("DISPLAY"));
else
Sys_Error("VID: Could not open local display\n");
}
gl3DfxSetPaletteEXT((GLuint *)temptable);
else
fprintf(stderr, "VID: Opened display %s\n", getenv("DISPLAY"));
XAutoRepeatOff(x_disp);
// for debugging only
XSynchronize(x_disp, True);
// check for command-line window size
template_mask = 0;
#if 0
// specify a visual id
if ((pnum=COM_CheckParm("-visualid")))
{
if (pnum >= com_argc-1)
Sys_Error("VID: -visualid <id#>\n");
template.visualid = Q_atoi(com_argv[pnum+1]);
template_mask = VisualIDMask;
}
// If not specified, use default visual
else
#endif
{
int screen;
screen = XDefaultScreen(x_disp);
template.visualid =
XVisualIDFromVisual(XDefaultVisual(x_disp, screen));
template_mask = VisualIDMask;
}
// pick a visual- warn if more than one was available
x_visinfo = glXChooseVisual( x_disp, DefaultScreen( x_disp ),
StudlyRGBattributes );
if (!x_visinfo)
{
fprintf(stderr, "Using non studly RGB attributes\n");
x_visinfo = glXChooseVisual( x_disp, DefaultScreen( x_disp ),
RGBattributes );
if (!x_visinfo) Sys_Error( "No matching visual available!\n" );
}
ri.Con_Printf(PRINT_ALL, "Using visualid 0x%x:\n",
(int)(x_visinfo->visualid));
#if 0
if (verbose)
{
printf("Using visualid %d:\n", (int)(x_visinfo->visualid));
printf(" screen %d\n", x_visinfo->screen);
printf(" red_mask 0x%x\n", (int)(x_visinfo->red_mask));
printf(" green_mask 0x%x\n", (int)(x_visinfo->green_mask));
printf(" blue_mask 0x%x\n", (int)(x_visinfo->blue_mask));
printf(" colormap_size %d\n", x_visinfo->colormap_size);
printf(" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
}
#endif
x_vis = x_visinfo->visual;
// setup attributes for main window
{
int attribmask = CWEventMask | CWColormap | CWBorderPixel;
XSetWindowAttributes attribs;
Colormap tmpcmap;
Window root_win = XRootWindow(x_disp, x_visinfo->screen);
tmpcmap = XCreateColormap(x_disp, root_win, x_vis, AllocNone);
attribs.event_mask = STD_EVENT_MASK;
attribs.border_pixel = 0;
attribs.colormap = tmpcmap;
// create the main window
x_win = XCreateWindow( x_disp,
root_win,
0, 0, // x, y
vid.width, vid.height,
0, // borderwidth
x_visinfo->depth,
InputOutput,
x_vis,
attribmask,
&attribs );
XStoreName(x_disp, x_win, "Quake II");
if (x_visinfo->class != TrueColor)
XFreeColormap(x_disp, tmpcmap);
}
if (x_visinfo->depth == 8)
{
// create and upload the palette
if (x_visinfo->class == PseudoColor)
{
x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll);
XSetWindowColormap(x_disp, x_win, x_cmap);
}
}
// inviso cursor
XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
// create the GC
{
XGCValues xgcvalues;
int valuemask = GCGraphicsExposures;
xgcvalues.graphics_exposures = False;
x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
}
// set window properties for full screen
if (fullscreen) {
//MotifWmHints wmhints;
//Atom aHints;
XSizeHints sizehints;
XWindowChanges changes;
/*
aHints = XInternAtom( x_disp, "_MOTIF_WM_HINTS", 0 );
if (aHints == None)
{
ri.Con_Printf( PRINT_ALL, "Could not intern X atom for _MOTIF_WM_HINTS." );
// return( false );
}
else {
wmhints.flags = MWM_HINTS_DECORATIONS;
wmhints.decorations = 0; // Absolutely no decorations.
XChangeProperty(x_disp, x_win, aHints, aHints, 32,
PropModeReplace, (unsigned char *)&wmhints,
4 );
sizehints.flags = USPosition | USSize;
sizehints.x = 0;
sizehints.y = 0;
sizehints.width = vid.width;
sizehints.height = vid.height;
XSetWMNormalHints( x_disp, x_win, &sizehints );
changes.x = 0;
changes.y = 0;
changes.width = vid.width;
changes.height = vid.height;
changes.stack_mode = TopIf;
XConfigureWindow(x_disp, x_win,
CWX | CWY | CWWidth | CWHeight | CWStackMode,
&changes);
}
*/
}
// map the window
XMapWindow(x_disp, x_win);
// wait for first exposure event
{
XEvent event;
do
{
XNextEvent(x_disp, &event);
if (event.type == Expose && !event.xexpose.count)
oktodraw = true;
} while (!oktodraw);
}
// now safe to draw
gl_cx = glXCreateContext( x_disp, x_visinfo, 0, True );
if (!glXMakeCurrent( x_disp, x_win, gl_cx ))
Sys_Error( "Can't make window current to context\n" );
// even if MITSHM is available, make sure it's a local connection
#if 0
// This is messing up the DISPLAY environment variable so can't close and
// reopen the window (it lops off the :0.0)...
if (XShmQueryExtension(x_disp))
{
char *displayname;
doShm = true;
displayname = (char *) getenv("DISPLAY");
if (displayname)
{
char *d = displayname;
while (*d && (*d != ':')) d++;
if (*d) *d = 0;
if (!(!strcasecmp(displayname, "unix") || !*displayname))
doShm = false;
}
}
#endif
#if 0
if (doShm)
{
x_shmeventtype = XShmGetEventBase(x_disp) + ShmCompletion;
ResetSharedFrameBuffers();
}
else
ResetFrameBuffer();
#endif
current_framebuffer = 0;
/* vid.rowbytes = x_framebuffer[0]->bytes_per_line; */
/* vid.buffer = x_framebuffer[0]->data; */
// XSynchronize(x_disp, False);
X11_active = true;
return true;
}
/*****************************************************************************/
int XLateKey(XKeyEvent *ev)
{
int key;
char buf[64];
KeySym keysym;
key = 0;
XLookupString(ev, buf, sizeof buf, &keysym, 0);
switch(keysym)
{
case XK_KP_Page_Up: key = K_KP_PGUP; break;
case XK_Page_Up: key = K_PGUP; break;
case XK_KP_Page_Down: key = K_KP_PGDN; break;
case XK_Page_Down: key = K_PGDN; break;
case XK_KP_Home: key = K_KP_HOME; break;
case XK_Home: key = K_HOME; break;
case XK_KP_End: key = K_KP_END; break;
case XK_End: key = K_END; break;
case XK_KP_Left: key = K_KP_LEFTARROW; break;
case XK_Left: key = K_LEFTARROW; break;
case XK_KP_Right: key = K_KP_RIGHTARROW; break;
case XK_Right: key = K_RIGHTARROW; break;
case XK_KP_Down: key = K_KP_DOWNARROW; break;
case XK_Down: key = K_DOWNARROW; break;
case XK_KP_Up: key = K_KP_UPARROW; break;
case XK_Up: key = K_UPARROW; break;
case XK_Escape: key = K_ESCAPE; break;
case XK_KP_Enter: key = K_KP_ENTER; break;
case XK_Return: key = K_ENTER; break;
case XK_Tab: key = K_TAB; break;
case XK_F1: key = K_F1; break;
case XK_F2: key = K_F2; break;
case XK_F3: key = K_F3; break;
case XK_F4: key = K_F4; break;
case XK_F5: key = K_F5; break;
case XK_F6: key = K_F6; break;
case XK_F7: key = K_F7; break;
case XK_F8: key = K_F8; break;
case XK_F9: key = K_F9; break;
case XK_F10: key = K_F10; break;
case XK_F11: key = K_F11; break;
case XK_F12: key = K_F12; break;
case XK_BackSpace: key = K_BACKSPACE; break;
case XK_KP_Delete: key = K_KP_DEL; break;
case XK_Delete: key = K_DEL; break;
case XK_Pause: key = K_PAUSE; break;
case XK_Shift_L:
case XK_Shift_R: key = K_SHIFT; break;
case XK_Execute:
case XK_Control_L:
case XK_Control_R: key = K_CTRL; break;
case XK_Alt_L:
case XK_Meta_L:
case XK_Alt_R:
case XK_Meta_R: key = K_ALT; break;
case XK_KP_Begin: key = K_KP_5; break;
case XK_Insert:key = K_INS; break;
case XK_KP_Insert: key = K_KP_INS; break;
case XK_KP_Multiply: key = '*'; break;
case XK_KP_Add: key = K_KP_PLUS; break;
case XK_KP_Subtract: key = K_KP_MINUS; break;
case XK_KP_Divide: key = K_KP_SLASH; break;
#if 0
case 0x021: key = '1';break;/* [!] */
case 0x040: key = '2';break;/* [@] */
case 0x023: key = '3';break;/* [#] */
case 0x024: key = '4';break;/* [$] */
case 0x025: key = '5';break;/* [%] */
case 0x05e: key = '6';break;/* [^] */
case 0x026: key = '7';break;/* [&] */
case 0x02a: key = '8';break;/* [*] */
case 0x028: key = '9';;break;/* [(] */
case 0x029: key = '0';break;/* [)] */
case 0x05f: key = '-';break;/* [_] */
case 0x02b: key = '=';break;/* [+] */
case 0x07c: key = '\'';break;/* [|] */
case 0x07d: key = '[';break;/* [}] */
case 0x07b: key = ']';break;/* [{] */
case 0x022: key = '\'';break;/* ["] */
case 0x03a: key = ';';break;/* [:] */
case 0x03f: key = '/';break;/* [?] */
case 0x03e: key = '.';break;/* [>] */
case 0x03c: key = ',';break;/* [<] */
#endif
default:
key = *(unsigned char*)buf;
if (key >= 'A' && key <= 'Z')
key = key - 'A' + 'a';
break;
}
return key;
}
void GetEvent(void)
{
XEvent x_event;
int b;
XNextEvent(x_disp, &x_event);
switch(x_event.type) {
case KeyPress:
keyq[keyq_head].key = XLateKey(&x_event.xkey);
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
break;
case KeyRelease:
keyq[keyq_head].key = XLateKey(&x_event.xkey);
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
break;
case MotionNotify:
if (_windowed_mouse->value) {
mx += ((int)x_event.xmotion.x - (int)(vid.width/2));
my += ((int)x_event.xmotion.y - (int)(vid.height/2));
/* move the mouse to the window center again */
XSelectInput(x_disp,x_win, STD_EVENT_MASK & ~PointerMotionMask);
XWarpPointer(x_disp,None,x_win,0,0,0,0,
(vid.width/2),(vid.height/2));
XSelectInput(x_disp,x_win, STD_EVENT_MASK);
} else {
mx = ((int)x_event.xmotion.x - (int)p_mouse_x);
my = ((int)x_event.xmotion.y - (int)p_mouse_y);
p_mouse_x=x_event.xmotion.x;
p_mouse_y=x_event.xmotion.y;
}
break;
case ButtonPress:
b=-1;
if (x_event.xbutton.button == 1)
b = 0;
else if (x_event.xbutton.button == 2)
b = 2;
else if (x_event.xbutton.button == 3)
b = 1;
if (b>=0)
mouse_buttonstate |= 1<<b;
break;
case ButtonRelease:
b=-1;
if (x_event.xbutton.button == 1)
b = 0;
else if (x_event.xbutton.button == 2)
b = 2;
else if (x_event.xbutton.button == 3)
b = 1;
if (b>=0)
mouse_buttonstate &= ~(1<<b);
break;
case ConfigureNotify:
config_notify_width = x_event.xconfigure.width;
config_notify_height = x_event.xconfigure.height;
config_notify = 1;
break;
default:
if (doShm && x_event.type == x_shmeventtype)
oktodraw = true;
}
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
/* ungrab the pointer */
XUngrabPointer(x_disp,CurrentTime);
} else {
/* grab the pointer */
XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
GrabModeAsync,x_win,None,CurrentTime);
}
}
}
/*****************************************************************************/
/*****************************************************************************/
/* KEYBOARD */
/*****************************************************************************/
Key_Event_fp_t Key_Event_fp;
void KBD_Init(Key_Event_fp_t fp)
{
_windowed_mouse = ri.Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE);
Key_Event_fp = fp;
}
void KBD_Update(void)
{
// get events from x server
if (x_disp)
{
while (XPending(x_disp))
GetEvent();
while (keyq_head != keyq_tail)
{
Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
keyq_tail = (keyq_tail + 1) & 63;
}
}
}
void KBD_Close(void)
{
}
static void Force_CenterView_f (void)
{
in_state->viewangles[PITCH] = 0;
}
static void RW_IN_MLookDown (void)
{
mlooking = true;
}
static void RW_IN_MLookUp (void)
{
mlooking = false;
in_state->IN_CenterView_fp ();
}
void RW_IN_Init(in_state_t *in_state_p)
{
int mtype;
int i;
fprintf(stderr, "GL RW_IN_Init\n");
in_state = in_state_p;
// mouse variables
_windowed_mouse = ri.Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE);
m_filter = ri.Cvar_Get ("m_filter", "0", 0);
in_mouse = ri.Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE);
freelook = ri.Cvar_Get( "freelook", "0", 0 );
lookstrafe = ri.Cvar_Get ("lookstrafe", "0", 0);
sensitivity = ri.Cvar_Get ("sensitivity", "3", 0);
m_pitch = ri.Cvar_Get ("m_pitch", "0.022", 0);
m_yaw = ri.Cvar_Get ("m_yaw", "0.022", 0);
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);
mouse_x = mouse_y = 0.0;
mouse_avail = true;
}
void RW_IN_Shutdown(void)
{
mouse_avail = false;
ri.Cmd_RemoveCommand ("force_centerview");
ri.Cmd_RemoveCommand ("+mlook");
ri.Cmd_RemoveCommand ("-mlook");
}
/*
===========
IN_Commands
===========
*/
void RW_IN_Commands (void)
{
int i;
if (!mouse_avail)
return;
for (i=0 ; i<3 ; i++) {
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
in_state->Key_Event_fp (K_MOUSE1 + i, true);
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
in_state->Key_Event_fp (K_MOUSE1 + i, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
/*
===========
IN_Move
===========
*/
void RW_IN_Move (usercmd_t *cmd)
{
if (!mouse_avail)
return;
if (m_filter->value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
if (!mouse_x && !mouse_y)
return;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ( (*in_state->in_strafe_state & 1) ||
(lookstrafe->value && mlooking ))
cmd->sidemove += m_side->value * mouse_x;
else
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
if ( (mlooking || freelook->value) &&
!(*in_state->in_strafe_state & 1))
{
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
}
else
{
cmd->forwardmove -= m_forward->value * mouse_y;
}
mx = my = 0;
}
void RW_IN_Frame (void)
{
}
void RW_IN_Activate(void)
{
}
//===============================================================================
/*
================
Sys_MakeCodeWriteable
================
*/
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
int r;
unsigned long addr;
int psize = getpagesize();
addr = (startaddr & ~(psize-1)) - psize;
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
// addr, startaddr+length, length);
r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
if (r < 0)
Sys_Error("Protection change failed\n");
}

View file

@ -219,7 +219,7 @@ qboolean VID_LoadRefresh( char *name )
strcat(fn, name);
// permission checking
if (strstr(fn, "softx") == NULL) { // softx doesn't require root
if (0 && strstr(fn, "softx") == NULL) { // softx doesn't require root
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return false;