2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
vid_sunx.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
|
|
|
|
#include "d_local.h"
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *m_filter;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean mouse_avail;
|
|
|
|
int mouse_buttons = 3;
|
|
|
|
int mouse_oldbuttonstate;
|
|
|
|
int mouse_buttonstate;
|
|
|
|
float mouse_x, mouse_y;
|
|
|
|
float old_mouse_x, old_mouse_y;
|
|
|
|
int p_mouse_x;
|
|
|
|
int p_mouse_y;
|
|
|
|
qboolean mouse_grabbed = false; // we grab it when console is up
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
|
|
|
|
byte *VGA_pagebase;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// The following X property format is defined in Motif 1.1's
|
|
|
|
// Xm/MwmUtils.h, but QUAKE should not depend on that header
|
|
|
|
// file. Note: Motif 1.2 expanded this structure with
|
|
|
|
// uninteresting fields (to QUAKE) so just stick with the
|
|
|
|
// smaller Motif 1.1 structure.
|
|
|
|
|
|
|
|
#define MWM_HINTS_DECORATIONS 2
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef struct {
|
|
|
|
long flags;
|
|
|
|
long functions;
|
|
|
|
long decorations;
|
|
|
|
long input_mode;
|
2001-02-19 21:15:25 +00:00
|
|
|
} MotifWmHints;
|
|
|
|
|
|
|
|
#define MAX_COLUMN_SIZE 11
|
|
|
|
|
|
|
|
#define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef struct {
|
|
|
|
int modenum;
|
|
|
|
int iscur;
|
|
|
|
char desc[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
} modedesc_t;
|
|
|
|
|
|
|
|
extern void M_Menu_Options_f (void);
|
|
|
|
extern void M_Print (int cx, int cy, char *str);
|
|
|
|
extern void M_PrintWhite (int cx, int cy, char *str);
|
|
|
|
extern void M_DrawCharacter (int cx, int line, int num);
|
|
|
|
extern void M_DrawTransPic (int x, int y, qpic_t *pic);
|
|
|
|
extern void M_DrawPic (int x, int y, qpic_t *pic);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extern int sb_updates;
|
|
|
|
extern int x_root, y_root; // root window relative mouse coords
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef struct {
|
|
|
|
int input;
|
|
|
|
int output;
|
2001-02-19 21:15:25 +00:00
|
|
|
} keymap_t;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
viddef_t vid; // global video state
|
|
|
|
unsigned short d_8to16table[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int num_shades = 32;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int d_con_indirect = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int vid_buffersize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define STD_EVENT_MASK \
|
|
|
|
( KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \
|
|
|
|
PointerMotionMask | EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | \
|
|
|
|
ExposureMask | StructureNotifyMask )
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean x_fullscreen = true;
|
|
|
|
Display *x_disp = NULL;
|
|
|
|
int x_screen, x_screen_width, x_screen_height;
|
|
|
|
int x_center_width, x_center_height;
|
|
|
|
int x_std_event_mask = STD_EVENT_MASK;
|
|
|
|
Window x_win, x_root_win;
|
|
|
|
qboolean mouse_in_window = false;
|
|
|
|
int global_dx, global_dy;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean doShm;
|
|
|
|
static Colormap x_cmap;
|
|
|
|
static GC x_gc;
|
|
|
|
static Visual *x_vis;
|
|
|
|
static XVisualInfo *x_visinfo;
|
|
|
|
static Atom aHints = 0;
|
|
|
|
static Atom aWMDelete = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int x_shmeventtype;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
//static XShmSegmentInfo x_shminfo;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean oktodraw = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int XShmQueryExtension (Display *);
|
|
|
|
int XShmGetEventBase (Display *);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int current_framebuffer;
|
|
|
|
static XImage *x_framebuffer[2] = { 0, 0 };
|
|
|
|
static XShmSegmentInfo x_shminfo[2];
|
|
|
|
|
|
|
|
static int verbose = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
static byte current_palette[768];
|
|
|
|
|
|
|
|
typedef unsigned short PIXEL16;
|
|
|
|
typedef unsigned long PIXEL24;
|
|
|
|
static PIXEL16 st2d_8to16table[256];
|
|
|
|
static PIXEL24 st2d_8to24table[256];
|
2001-02-26 06:48:02 +00:00
|
|
|
static int shiftmask_fl = 0;
|
|
|
|
static long r_shift, g_shift, b_shift;
|
|
|
|
static unsigned long r_mask, g_mask, b_mask;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_InitCvars (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
shiftmask_init ()
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
r_mask = x_vis->red_mask;
|
|
|
|
g_mask = x_vis->green_mask;
|
|
|
|
b_mask = x_vis->blue_mask;
|
|
|
|
for (r_shift = -8, x = 1; x < r_mask; x = x << 1)
|
|
|
|
r_shift++;
|
|
|
|
for (g_shift = -8, x = 1; x < g_mask; x = x << 1)
|
|
|
|
g_shift++;
|
|
|
|
for (b_shift = -8, x = 1; x < b_mask; x = x << 1)
|
|
|
|
b_shift++;
|
|
|
|
shiftmask_fl = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL16
|
|
|
|
xlib_rgb16 (int r, int g, int b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL16 p;
|
|
|
|
|
|
|
|
if (shiftmask_fl == 0)
|
|
|
|
shiftmask_init ();
|
|
|
|
p = 0;
|
|
|
|
|
|
|
|
if (r_shift > 0) {
|
|
|
|
p = (r << (r_shift)) & r_mask;
|
|
|
|
} else if (r_shift < 0) {
|
|
|
|
p = (r >> (-r_shift)) & r_mask;
|
|
|
|
} else
|
|
|
|
p |= (r & r_mask);
|
|
|
|
|
|
|
|
if (g_shift > 0) {
|
|
|
|
p |= (g << (g_shift)) & g_mask;
|
|
|
|
} else if (g_shift < 0) {
|
|
|
|
p |= (g >> (-g_shift)) & g_mask;
|
|
|
|
} else
|
|
|
|
p |= (g & g_mask);
|
|
|
|
|
|
|
|
if (b_shift > 0) {
|
|
|
|
p |= (b << (b_shift)) & b_mask;
|
|
|
|
} else if (b_shift < 0) {
|
|
|
|
p |= (b >> (-b_shift)) & b_mask;
|
|
|
|
} else
|
|
|
|
p |= (b & b_mask);
|
|
|
|
|
|
|
|
return p;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL24
|
|
|
|
xlib_rgb24 (int r, int g, int b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL24 p;
|
|
|
|
|
|
|
|
if (shiftmask_fl == 0)
|
|
|
|
shiftmask_init ();
|
|
|
|
p = 0;
|
|
|
|
|
|
|
|
if (r_shift > 0) {
|
|
|
|
p = (r << (r_shift)) & r_mask;
|
|
|
|
} else if (r_shift < 0) {
|
|
|
|
p = (r >> (-r_shift)) & r_mask;
|
|
|
|
} else
|
|
|
|
p |= (r & r_mask);
|
|
|
|
|
|
|
|
if (g_shift > 0) {
|
|
|
|
p |= (g << (g_shift)) & g_mask;
|
|
|
|
} else if (g_shift < 0) {
|
|
|
|
p |= (g >> (-g_shift)) & g_mask;
|
|
|
|
} else
|
|
|
|
p |= (g & g_mask);
|
|
|
|
|
|
|
|
if (b_shift > 0) {
|
|
|
|
p |= (b << (b_shift)) & b_mask;
|
|
|
|
} else if (b_shift < 0) {
|
|
|
|
p |= (b >> (-b_shift)) & b_mask;
|
|
|
|
} else
|
|
|
|
p |= (b & b_mask);
|
|
|
|
|
|
|
|
return p;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
st2_fixup (XImage * framebuf, int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int xi, yi;
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned char *src;
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL16 *dest;
|
2001-02-19 21:15:25 +00:00
|
|
|
register int count, n;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((x < 0) || (y < 0))
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (yi = y; yi < (y + height); yi++) {
|
|
|
|
src = &framebuf->data[yi * framebuf->bytes_per_line];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Duff's Device
|
|
|
|
count = width;
|
|
|
|
n = (count + 7) / 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
dest = ((PIXEL16 *) src) + x + width - 1;
|
|
|
|
src += x + width - 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
switch (count % 8) {
|
2001-02-26 06:48:02 +00:00
|
|
|
case 0:
|
|
|
|
do {
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 7:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 6:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 5:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 4:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 3:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 2:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
case 1:
|
|
|
|
*dest-- = st2d_8to16table[*src--];
|
|
|
|
} while (--n > 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// for(xi = (x+width-1); xi >= x; xi--) {
|
|
|
|
// dest[xi] = st2d_8to16table[src[xi]];
|
|
|
|
// }
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
st3_fixup (XImage * framebuf, int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int xi, yi;
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned char *src;
|
2001-02-26 06:48:02 +00:00
|
|
|
PIXEL24 *dest;
|
2001-02-19 21:15:25 +00:00
|
|
|
register int count, n;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((x < 0) || (y < 0))
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (yi = y; yi < (y + height); yi++) {
|
|
|
|
src = &framebuf->data[yi * framebuf->bytes_per_line];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Duff's Device
|
|
|
|
count = width;
|
|
|
|
n = (count + 7) / 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
dest = ((PIXEL24 *) src) + x + width - 1;
|
|
|
|
src += x + width - 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
switch (count % 8) {
|
2001-02-26 06:48:02 +00:00
|
|
|
case 0:
|
|
|
|
do {
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 7:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 6:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 5:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 4:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 3:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 2:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
case 1:
|
|
|
|
*dest-- = st2d_8to24table[*src--];
|
|
|
|
} while (--n > 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// for(xi = (x+width-1); xi >= x; xi--) {
|
|
|
|
// dest[xi] = st2d_8to16table[src[xi]];
|
|
|
|
// }
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_BeginDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported under Nextstep
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_EndDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported under Nextstep
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_Gamma_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte vid_gamma[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Gamma_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
float g, f, inf;
|
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (Cmd_Argc () == 2) {
|
|
|
|
g = Q_atof (Cmd_Argv (1));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 255; i++) {
|
|
|
|
f = pow ((i + 1) / 256.0, g);
|
|
|
|
inf = f * 255 + 0.5;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (inf < 0)
|
|
|
|
inf = 0;
|
|
|
|
if (inf > 255)
|
|
|
|
inf = 255;
|
|
|
|
vid_gamma[i] = inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_SetPalette (current_palette);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// Tragic death handler
|
|
|
|
// ========================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
TragicDeath (int signal_num)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
// XAutoRepeatOn(x_disp);
|
|
|
|
VID_Shutdown ();
|
|
|
|
Sys_Error ("This death brought to you by the number %d\n", signal_num);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// makes a null cursor
|
|
|
|
// ========================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static Cursor
|
|
|
|
CreateNullCursor (Display * display, Window root)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
Pixmap cursormask;
|
|
|
|
XGCValues xgc;
|
|
|
|
GC gc;
|
|
|
|
XColor dummycolour;
|
|
|
|
Cursor cursor;
|
|
|
|
|
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
ResetFrameBuffer (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int mem;
|
|
|
|
int pwidth;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_framebuffer[0]) {
|
|
|
|
Z_Free (x_framebuffer[0]->data);
|
|
|
|
// Z_Free(d_pzbuffer);
|
|
|
|
free (x_framebuffer[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pwidth = x_visinfo->depth / 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (pwidth == 3)
|
|
|
|
pwidth = 4;
|
|
|
|
mem = ((vid.width * pwidth + 3) & ~3) * vid.height;
|
|
|
|
|
|
|
|
// d_pzbuffer = (unsigned short *) Z_Malloc(vid.width*vid.height*
|
|
|
|
// sizeof(*d_pzbuffer));
|
|
|
|
d_pzbuffer = (short *) Hunk_HighAllocName (vid.width * vid.height *
|
|
|
|
sizeof (*d_pzbuffer), "zbuff");
|
|
|
|
|
|
|
|
x_framebuffer[0] = XCreateImage (x_disp,
|
|
|
|
x_vis,
|
|
|
|
x_visinfo->depth,
|
|
|
|
ZPixmap,
|
|
|
|
0,
|
|
|
|
Z_Malloc (mem),
|
|
|
|
vid.width, vid.height, 32, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!x_framebuffer[0])
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: XCreateImage failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
ResetSharedFrameBuffers (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int size;
|
|
|
|
int key;
|
|
|
|
int minsize = getpagesize ();
|
|
|
|
int frm;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// if (d_pzbuffer)
|
|
|
|
// Z_Free(d_pzbuffer);
|
|
|
|
d_pzbuffer =
|
|
|
|
Hunk_HighAllocName (vid.width * vid.height * sizeof (*d_pzbuffer),
|
|
|
|
"zbuff");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (frm = 0; frm < 2; frm++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// free up old frame buffer memory
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_framebuffer[frm]) {
|
|
|
|
XShmDetach (x_disp, &x_shminfo[frm]);
|
|
|
|
free (x_framebuffer[frm]);
|
|
|
|
shmdt (x_shminfo[frm].shmaddr);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// create the image
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_framebuffer[frm] = XShmCreateImage (x_disp,
|
|
|
|
x_vis,
|
|
|
|
x_visinfo->depth,
|
|
|
|
ZPixmap,
|
|
|
|
0,
|
|
|
|
&x_shminfo[frm],
|
|
|
|
vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// grab shared memory
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
size = x_framebuffer[frm]->bytes_per_line * x_framebuffer[frm]->height;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (size < minsize)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Window must use at least %d bytes\n", minsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
key = random ();
|
|
|
|
x_shminfo[frm].shmid = shmget ((key_t) key, size, IPC_CREAT | 0777);
|
|
|
|
if (x_shminfo[frm].shmid == -1)
|
|
|
|
Sys_Error ("VID: Could not get any shared memory\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// attach to the shared memory segment
|
2001-02-26 06:48:02 +00:00
|
|
|
x_shminfo[frm].shmaddr = (void *) shmat (x_shminfo[frm].shmid, 0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("VID: shared memory id=%d, addr=0x%x\n", x_shminfo[frm].shmid,
|
|
|
|
(int) x_shminfo[frm].shmaddr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get the X server to attach to it
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!XShmAttach (x_disp, &x_shminfo[frm]))
|
|
|
|
Sys_Error ("VID: XShmAttach() failed\n");
|
|
|
|
XSync (x_disp, 0);
|
|
|
|
shmctl (x_shminfo[frm].shmid, IPC_RMID, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_MenuDraw (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
qpic_t *p;
|
|
|
|
char *ptr;
|
|
|
|
int i, j, column, row, dup;
|
|
|
|
char temp[100];
|
|
|
|
|
|
|
|
p = Draw_CachePic ("gfx/vidmodes.lmp");
|
|
|
|
M_DrawPic ((320 - p->width) / 2, 4, p);
|
|
|
|
M_Print (4 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8,
|
|
|
|
"Video mode switching unavailable");
|
|
|
|
M_Print (9 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 6, "Press any key...");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_MenuKey (int key)
|
|
|
|
{
|
|
|
|
M_Menu_Options_f ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Called at startup to set up translation tables, takes 256 8 bit RGB values
|
|
|
|
// the palette data will go away after the call, so it must be copied off if
|
|
|
|
// the video driver will need it again
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte surfcache[1024 * 1024];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// VID_SetWindowTitle - set the window and icon titles
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_SetWindowTitle (Window win, char *pszName)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XTextProperty textprop;
|
|
|
|
XWMHints *wmHints;
|
|
|
|
|
|
|
|
// Setup ICCCM properties
|
|
|
|
textprop.value = (unsigned char *) pszName;
|
|
|
|
textprop.encoding = XA_STRING;
|
|
|
|
textprop.format = 8;
|
|
|
|
textprop.nitems = strlen (pszName);
|
|
|
|
wmHints = XAllocWMHints ();
|
|
|
|
wmHints->initial_state = NormalState;
|
|
|
|
wmHints->flags = StateHint;
|
|
|
|
XSetWMProperties (x_disp, win, &textprop, &textprop,
|
2001-02-19 21:15:25 +00:00
|
|
|
// Only put WM_COMMAND property on first window.
|
2001-02-26 06:48:02 +00:00
|
|
|
com_argv, com_argc, NULL, NULL, NULL);
|
|
|
|
XFree (wmHints);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
|
|
|
|
XSetWMProtocols (x_disp, win, &aWMDelete, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// VID_FullScreen - open the window in full screen mode
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_FullScreen (Window win)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
MotifWmHints hints;
|
|
|
|
XWindowChanges changes;
|
|
|
|
|
|
|
|
aHints = XInternAtom (x_disp, "_MOTIF_WM_HINTS", 0);
|
|
|
|
if (aHints == None) {
|
|
|
|
Con_Printf ("Could not intern X atom for _MOTIF_WM_HINTS.");
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
hints.flags = MWM_HINTS_DECORATIONS;
|
|
|
|
hints.decorations = 0; // Absolutely no decorations.
|
|
|
|
XChangeProperty (x_disp, win, aHints, aHints, 32, PropModeReplace,
|
|
|
|
(unsigned char *) &hints, 4);
|
|
|
|
|
|
|
|
changes.x = 0;
|
|
|
|
changes.y = 0;
|
|
|
|
changes.width = x_screen_width;
|
|
|
|
changes.height = x_screen_height;
|
|
|
|
changes.stack_mode = TopIf;
|
|
|
|
XConfigureWindow (x_disp, win, CWX | CWY | CWWidth | CWHeight | CWStackMode,
|
|
|
|
&changes);
|
|
|
|
return (true);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int pnum, i;
|
2001-02-19 21:15:25 +00:00
|
|
|
XVisualInfo template;
|
2001-02-26 06:48:02 +00:00
|
|
|
int num_visuals;
|
|
|
|
int template_mask;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_AddCommand ("gamma", VID_Gamma_f, "No Description");
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_gamma[i] = i;
|
|
|
|
|
|
|
|
vid.width = 320;
|
|
|
|
vid.height = 200;
|
|
|
|
vid.aspect = 1.0;
|
|
|
|
vid.numpages = 2;
|
|
|
|
vid.colormap = host_colormap;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
|
|
|
// vid.cbits = VID_CBITS;
|
|
|
|
// vid.grades = VID_GRADES;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
srandom (getpid ());
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
verbose = COM_CheckParm ("-verbose");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// open the display
|
2001-02-26 06:48:02 +00:00
|
|
|
x_disp = XOpenDisplay (0);
|
|
|
|
if (!x_disp) {
|
|
|
|
if (getenv ("DISPLAY"))
|
|
|
|
Sys_Error ("VID: Could not open display [%s]\n",
|
|
|
|
getenv ("DISPLAY"));
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Could not open local display\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_screen = XDefaultScreen (x_disp);
|
|
|
|
x_screen_width = WidthOfScreen (ScreenOfDisplay (x_disp, x_screen));
|
|
|
|
x_screen_height = HeightOfScreen (ScreenOfDisplay (x_disp, x_screen));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_center_width = x_screen_width / 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_center_height = x_screen_height / 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf ("Using screen %d: %dx%d\n", x_screen, x_screen_width,
|
|
|
|
x_screen_height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
x_root_win = XRootWindow (x_disp, x_screen);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// catch signals so i can turn on auto-repeat
|
|
|
|
// we never run full-screen, so no auto-repeat nukage
|
2001-02-26 06:48:02 +00:00
|
|
|
if (0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
struct sigaction sa;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
sigaction (SIGINT, 0, &sa);
|
2001-02-19 21:15:25 +00:00
|
|
|
sa.sa_handler = TragicDeath;
|
2001-02-26 06:48:02 +00:00
|
|
|
sigaction (SIGINT, &sa, 0);
|
|
|
|
sigaction (SIGTERM, &sa, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// XAutoRepeatOff(x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// for debugging only
|
2001-02-26 06:48:02 +00:00
|
|
|
// XSynchronize(x_disp, True);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// check for command-line window size
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((pnum = COM_CheckParm ("-winsize"))) {
|
|
|
|
if (pnum >= com_argc - 2)
|
|
|
|
Sys_Error ("VID: -winsize <width> <height>\n");
|
|
|
|
vid.width = Q_atoi (com_argv[pnum + 1]);
|
|
|
|
vid.height = Q_atoi (com_argv[pnum + 2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!vid.width || !vid.height)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Bad window width/height\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template_mask = 0;
|
|
|
|
|
|
|
|
// specify a visual id
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((pnum = COM_CheckParm ("-visualid"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
|
|
|
Sys_Error ("VID: -visualid <id#>\n");
|
|
|
|
template.visualid = Q_atoi (com_argv[pnum + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
template_mask = VisualIDMask;
|
|
|
|
}
|
|
|
|
// If not specified, use default visual
|
2001-02-26 06:48:02 +00:00
|
|
|
else {
|
|
|
|
int screen;
|
|
|
|
|
|
|
|
screen = XDefaultScreen (x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
template.visualid =
|
2001-02-26 06:48:02 +00:00
|
|
|
XVisualIDFromVisual (XDefaultVisual (x_disp, screen));
|
2001-02-19 21:15:25 +00:00
|
|
|
template_mask = VisualIDMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pick a visual- warn if more than one was available
|
2001-02-26 06:48:02 +00:00
|
|
|
x_visinfo = XGetVisualInfo (x_disp, template_mask, &template, &num_visuals);
|
|
|
|
if (num_visuals > 1) {
|
|
|
|
printf ("Found more than one visual id at depth %d:\n", template.depth);
|
|
|
|
for (i = 0; i < num_visuals; i++)
|
|
|
|
printf (" -visualid %d\n", (int) (x_visinfo[i].visualid));
|
|
|
|
} else if (num_visuals == 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (template_mask == VisualIDMask)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: Bad visual id %d\n", template.visualid);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("VID: No visuals at depth %d\n", template.depth);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (verbose) {
|
|
|
|
printf ("Using visualid %d:\n", (int) (x_visinfo->visualid));
|
|
|
|
printf (" class %d\n", x_visinfo->class);
|
|
|
|
printf (" screen %d\n", x_visinfo->screen);
|
|
|
|
printf (" depth %d\n", x_visinfo->depth);
|
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x_vis = x_visinfo->visual;
|
|
|
|
|
|
|
|
// setup attributes for main window
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int attribmask = CWEventMask | CWColormap | CWBorderPixel;
|
2001-02-19 21:15:25 +00:00
|
|
|
XSetWindowAttributes attribs;
|
2001-02-26 06:48:02 +00:00
|
|
|
Colormap tmpcmap;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
tmpcmap = XCreateColormap (x_disp, XRootWindow (x_disp,
|
|
|
|
x_visinfo->screen),
|
|
|
|
x_vis, AllocNone);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
attribs.event_mask = x_std_event_mask;
|
|
|
|
attribs.border_pixel = 0;
|
|
|
|
attribs.colormap = tmpcmap;
|
|
|
|
|
|
|
|
// create the main window
|
2001-02-26 06:48:02 +00:00
|
|
|
x_win = XCreateWindow (x_disp,
|
|
|
|
XRootWindow (x_disp, x_visinfo->screen), 0, 0, // x,
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// y
|
|
|
|
vid.width, vid.height, 0, // borderwidth
|
|
|
|
x_visinfo->depth,
|
|
|
|
InputOutput, x_vis, attribmask, &attribs);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (x_visinfo->class != TrueColor)
|
2001-02-26 06:48:02 +00:00
|
|
|
XFreeColormap (x_disp, tmpcmap);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_visinfo->depth == 8) {
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// create and upload the palette
|
|
|
|
if (x_visinfo->class == PseudoColor) {
|
|
|
|
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
XSetWindowColormap (x_disp, x_win, x_cmap);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetWindowTitle (x_win, "Quake");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// create the GC
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XGCValues xgcvalues;
|
|
|
|
int valuemask = GCGraphicsExposures;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
xgcvalues.graphics_exposures = False;
|
2001-02-26 06:48:02 +00:00
|
|
|
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// map the window
|
2001-02-26 06:48:02 +00:00
|
|
|
XMapWindow (x_disp, x_win);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// wait for first exposure event
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
do {
|
|
|
|
XNextEvent (x_disp, &event);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (event.type == Expose && !event.xexpose.count)
|
|
|
|
oktodraw = true;
|
|
|
|
} while (!oktodraw);
|
|
|
|
}
|
|
|
|
// now safe to draw
|
|
|
|
|
|
|
|
// even if MITSHM is available, make sure it's a local connection
|
2001-02-26 06:48:02 +00:00
|
|
|
if (XShmQueryExtension (x_disp)) {
|
|
|
|
char *displayname;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
doShm = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
displayname = (char *) getenv ("DISPLAY");
|
|
|
|
if (displayname) {
|
|
|
|
char *d = displayname;
|
|
|
|
|
|
|
|
while (*d && (*d != ':'))
|
|
|
|
d++;
|
|
|
|
if (*d)
|
|
|
|
*d = 0;
|
|
|
|
if (!(!strcasecmp (displayname, "unix") || !*displayname))
|
2001-02-19 21:15:25 +00:00
|
|
|
doShm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (doShm) {
|
|
|
|
x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion;
|
|
|
|
ResetSharedFrameBuffers ();
|
|
|
|
} else
|
|
|
|
ResetFrameBuffer ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
current_framebuffer = 0;
|
|
|
|
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
|
|
|
|
vid.buffer = x_framebuffer[0]->data;
|
|
|
|
vid.conbuffer = x_framebuffer[0]->data;
|
|
|
|
vid.conrowbytes = vid.rowbytes;
|
|
|
|
vid.conwidth = vid.width;
|
|
|
|
vid.conheight = vid.height;
|
|
|
|
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
D_InitCaches (surfcache, sizeof (surfcache));
|
|
|
|
|
|
|
|
// XSynchronize(x_disp, False);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_menudrawfn = VID_MenuDraw;
|
|
|
|
vid_menukeyfn = VID_MenuKey;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_ShiftPalette (unsigned char *p)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetPalette (p);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_SetPalette (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
XColor colors[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
st2d_8to16table[i] =
|
|
|
|
xlib_rgb16 (palette[i * 3], palette[i * 3 + 1], palette[i * 3 + 2]);
|
|
|
|
st2d_8to24table[i] =
|
|
|
|
xlib_rgb24 (palette[i * 3], palette[i * 3 + 1], palette[i * 3 + 2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (palette != current_palette)
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy (current_palette, palette, 768);
|
|
|
|
for (i = 0; i < 256; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
colors[i].pixel = i;
|
2001-02-26 06:48:02 +00:00
|
|
|
colors[i].flags = DoRed | DoGreen | DoBlue;
|
|
|
|
colors[i].red = vid_gamma[palette[i * 3]] * 257;
|
|
|
|
colors[i].green = vid_gamma[palette[i * 3 + 1]] * 257;
|
|
|
|
colors[i].blue = vid_gamma[palette[i * 3 + 2]] * 257;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XStoreColors (x_disp, x_cmap, colors, 256);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called at shutdown
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf ("VID_Shutdown\n");
|
|
|
|
// XAutoRepeatOn(x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mouse_grabbed) {
|
|
|
|
/* ungrab the pointer */
|
2001-02-26 06:48:02 +00:00
|
|
|
XUngrabPointer (x_disp, CurrentTime);
|
|
|
|
XUndefineCursor (x_disp, x_win);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XCloseDisplay (x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
XLateKey (XKeyEvent * ev)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int key;
|
|
|
|
char buf[64];
|
|
|
|
KeySym keysym;
|
|
|
|
|
|
|
|
XLookupString (ev, buf, sizeof buf, &keysym, 0);
|
|
|
|
|
|
|
|
switch (keysym) {
|
|
|
|
case XK_Page_Up:
|
|
|
|
key = K_PGUP;
|
|
|
|
break;
|
|
|
|
case XK_Page_Down:
|
|
|
|
key = K_PGDN;
|
|
|
|
break;
|
|
|
|
case XK_Home:
|
|
|
|
key = K_HOME;
|
|
|
|
break;
|
|
|
|
case XK_End:
|
|
|
|
key = K_END;
|
|
|
|
break;
|
|
|
|
case XK_Left:
|
|
|
|
key = K_LEFTARROW;
|
|
|
|
break;
|
|
|
|
case XK_Right:
|
|
|
|
key = K_RIGHTARROW;
|
|
|
|
break;
|
|
|
|
case XK_Down:
|
|
|
|
key = K_DOWNARROW;
|
|
|
|
break;
|
|
|
|
case XK_Up:
|
|
|
|
key = K_UPARROW;
|
|
|
|
break;
|
|
|
|
case XK_Escape:
|
|
|
|
key = K_ESCAPE;
|
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
case XK_BackSpace:
|
2001-02-26 06:48:02 +00:00
|
|
|
case XK_Delete:
|
|
|
|
key = K_BACKSPACE;
|
|
|
|
break;
|
|
|
|
case XK_Pause:
|
|
|
|
key = K_PAUSE;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case XK_Shift_L:
|
2001-02-26 06:48:02 +00:00
|
|
|
case XK_Shift_R:
|
|
|
|
key = K_SHIFT;
|
|
|
|
break;
|
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
// various other keys on the keyboard
|
2001-02-26 06:48:02 +00:00
|
|
|
case XK_F27:
|
|
|
|
key = K_HOME;
|
|
|
|
break;
|
|
|
|
case XK_F29:
|
|
|
|
key = K_PGUP;
|
|
|
|
break;
|
|
|
|
case XK_F33:
|
|
|
|
key = K_END;
|
|
|
|
break;
|
|
|
|
case XK_F35:
|
|
|
|
key = K_PGDN;
|
|
|
|
break;
|
|
|
|
case XK_KP_Insert:
|
|
|
|
key = K_INS;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
key = *buf;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
struct {
|
|
|
|
int key;
|
|
|
|
int down;
|
2001-02-19 21:15:25 +00:00
|
|
|
} keyq[64];
|
2001-02-26 06:48:02 +00:00
|
|
|
int keyq_head = 0;
|
|
|
|
int keyq_tail = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int config_notify = 0;
|
|
|
|
int config_notify_width;
|
|
|
|
int config_notify_height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
GetEvent (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
XEvent x_event;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
XNextEvent (x_disp, &x_event);
|
|
|
|
switch (x_event.type) {
|
2001-02-19 21:15:25 +00:00
|
|
|
case KeyPress:
|
2001-02-26 06:48:02 +00:00
|
|
|
Key_Event (XLateKey (&x_event.xkey), true);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case KeyRelease:
|
2001-02-26 06:48:02 +00:00
|
|
|
Key_Event (XLateKey (&x_event.xkey), false);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case ButtonPress:
|
2001-02-26 06:48:02 +00:00
|
|
|
// printf( "button %d down\n", x_event.xbutton.button );
|
|
|
|
Key_Event (K_MOUSE1 + x_event.xbutton.button - 1, true);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case ButtonRelease:
|
2001-02-26 06:48:02 +00:00
|
|
|
// printf( "button %d up\n", x_event.xbutton.button );
|
|
|
|
Key_Event (K_MOUSE1 + x_event.xbutton.button - 1, false);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case MotionNotify:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (mouse_avail && mouse_grabbed) {
|
|
|
|
mouse_x = (float) ((int) x_event.xmotion.x - (int) (vid.width / 2));
|
|
|
|
mouse_y =
|
|
|
|
(float) ((int) x_event.xmotion.y - (int) (vid.height / 2));
|
|
|
|
// printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n",
|
|
|
|
// x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y);
|
|
|
|
|
|
|
|
/* 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 {
|
|
|
|
mouse_x = (float) (x_event.xmotion.x - p_mouse_x);
|
|
|
|
mouse_y = (float) (x_event.xmotion.y - p_mouse_y);
|
|
|
|
p_mouse_x = x_event.xmotion.x;
|
|
|
|
p_mouse_y = x_event.xmotion.y;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case ConfigureNotify:
|
2001-02-26 06:48:02 +00:00
|
|
|
// printf("config notify\n");
|
|
|
|
config_notify_width = x_event.xconfigure.width;
|
|
|
|
config_notify_height = x_event.xconfigure.height;
|
|
|
|
config_notify = 1;
|
|
|
|
sb_updates = 0;
|
|
|
|
break;
|
|
|
|
case Expose:
|
|
|
|
sb_updates = 0;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case ClientMessage:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_event.xclient.data.l[0] == aWMDelete)
|
|
|
|
Host_Quit_f ();
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case EnterNotify:
|
2001-02-26 06:48:02 +00:00
|
|
|
mouse_in_window = true;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
case LeaveNotify:
|
2001-02-26 06:48:02 +00:00
|
|
|
mouse_in_window = false;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (doShm && x_event.type == x_shmeventtype)
|
|
|
|
oktodraw = true;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mouse_avail) {
|
|
|
|
if (key_dest == key_game && !mouse_grabbed && mouse_in_window) {
|
|
|
|
mouse_grabbed = true;
|
|
|
|
/* grab the pointer */
|
2001-02-26 06:48:02 +00:00
|
|
|
XGrabPointer (x_disp, x_win, True, 0, GrabModeAsync,
|
|
|
|
GrabModeAsync, x_win, None, CurrentTime);
|
2001-02-19 21:15:25 +00:00
|
|
|
// inviso cursor
|
2001-02-26 06:48:02 +00:00
|
|
|
XDefineCursor (x_disp, x_win, CreateNullCursor (x_disp, x_win));
|
2001-02-19 21:15:25 +00:00
|
|
|
} else if ((key_dest != key_game || !mouse_in_window) && mouse_grabbed) {
|
|
|
|
mouse_grabbed = false;
|
|
|
|
/* ungrab the pointer */
|
2001-02-26 06:48:02 +00:00
|
|
|
XUngrabPointer (x_disp, CurrentTime);
|
|
|
|
XUndefineCursor (x_disp, x_win);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// flushes the given rectangles from the view buffer to the screen
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Update (vrect_t *rects)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2001-02-26 06:48:02 +00:00
|
|
|
static int count;
|
2001-02-19 21:15:25 +00:00
|
|
|
static long long s;
|
2001-02-26 06:48:02 +00:00
|
|
|
long long gethrtime ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (count == 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
s = gethrtime ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (count++ == 50) {
|
|
|
|
count = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("%lf frames/secs\n",
|
|
|
|
50.0 / ((double) (gethrtime () - s) / 1e9));
|
|
|
|
s = gethrtime ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// if the window changes dimension, skip this frame
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (config_notify) {
|
|
|
|
printf ("config notify\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
config_notify = 0;
|
|
|
|
vid.width = config_notify_width & ~3;
|
|
|
|
vid.height = config_notify_height;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("w = %d, h = %d\n", vid.width, vid.height);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (doShm)
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetSharedFrameBuffers ();
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
ResetFrameBuffer ();
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
|
|
|
|
vid.buffer = x_framebuffer[current_framebuffer]->data;
|
|
|
|
vid.conbuffer = vid.buffer;
|
|
|
|
vid.conwidth = vid.width;
|
|
|
|
vid.conheight = vid.height;
|
|
|
|
vid.conrowbytes = vid.rowbytes;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (doShm) {
|
|
|
|
// long long s, gethrtime();
|
|
|
|
// s = gethrtime();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (rects) {
|
|
|
|
printf ("update: %d,%d (%d,%d)\n", rects->x, rects->y, rects->width,
|
2001-02-19 21:15:25 +00:00
|
|
|
rects->height);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_visinfo->depth == 16)
|
|
|
|
st2_fixup (x_framebuffer[current_framebuffer], rects->x,
|
|
|
|
rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (x_visinfo->depth == 24)
|
2001-02-26 06:48:02 +00:00
|
|
|
st3_fixup (x_framebuffer[current_framebuffer], rects->x,
|
|
|
|
rects->y, rects->width, rects->height);
|
|
|
|
if (!XShmPutImage
|
|
|
|
(x_disp, x_win, x_gc, x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->x, rects->y, rects->width,
|
|
|
|
rects->height, True))
|
|
|
|
Sys_Error ("VID_Update: XShmPutImage failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
oktodraw = false;
|
2001-02-26 06:48:02 +00:00
|
|
|
while (!oktodraw)
|
|
|
|
GetEvent ();
|
2001-02-19 21:15:25 +00:00
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// printf("%lf\n", (double)(gethrtime()-s)/1.0e9);
|
2001-02-19 21:15:25 +00:00
|
|
|
current_framebuffer = !current_framebuffer;
|
|
|
|
vid.buffer = x_framebuffer[current_framebuffer]->data;
|
|
|
|
vid.conbuffer = vid.buffer;
|
2001-02-26 06:48:02 +00:00
|
|
|
XSync (x_disp, False);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
while (rects) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (x_visinfo->depth == 16)
|
2001-02-26 06:48:02 +00:00
|
|
|
st2_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (x_visinfo->depth == 24)
|
2001-02-26 06:48:02 +00:00
|
|
|
st3_fixup (x_framebuffer[current_framebuffer],
|
|
|
|
rects->x, rects->y, rects->width, rects->height);
|
|
|
|
XPutImage (x_disp, x_win, x_gc, x_framebuffer[0], rects->x,
|
|
|
|
rects->y, rects->x, rects->y, rects->width,
|
|
|
|
rects->height);
|
2001-02-19 21:15:25 +00:00
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
XSync (x_disp, False);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int dither;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_DitherOn (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dither == 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.recalc_refdef = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
dither = 1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_DitherOff (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dither) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.recalc_refdef = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
dither = 0;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_SetDefaultMode (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
I_OpenWindow (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
I_EraseWindow (int window)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
I_DrawCircle (int window, int x, int y, int r)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
I_DisplayWindow (int window)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_SendKeyEvents (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// get events from x server
|
2001-02-26 06:48:02 +00:00
|
|
|
if (x_disp) {
|
|
|
|
while (XPending (x_disp))
|
|
|
|
GetEvent ();
|
|
|
|
while (keyq_head != keyq_tail) {
|
|
|
|
Key_Event (keyq[keyq_tail].key, keyq[keyq_tail].down);
|
2001-02-19 21:15:25 +00:00
|
|
|
keyq_tail = (keyq_tail + 1) & 63;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
Sys_ConsoleInput (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static char text[256];
|
|
|
|
int len;
|
|
|
|
fd_set readfds;
|
|
|
|
int ready;
|
2001-02-19 21:15:25 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
FD_ZERO (&readfds);
|
|
|
|
FD_SET (0, &readfds);
|
|
|
|
ready = select (1, &readfds, 0, 0, &timeout);
|
|
|
|
|
|
|
|
if (ready > 0) {
|
|
|
|
len = read (0, text, sizeof (text));
|
|
|
|
if (len >= 1) {
|
|
|
|
text[len - 1] = 0; // rip off the /n and terminate
|
2001-02-19 21:15:25 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-31 01:02:52 +00:00
|
|
|
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, 0, "None");
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-nomouse"))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
mouse_x = mouse_y = 0.0;
|
|
|
|
mouse_avail = 1;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
mouse_avail = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Commands (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!mouse_avail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < mouse_buttons; i++) {
|
|
|
|
if ((mouse_buttonstate & (1 << i))
|
|
|
|
&& !(mouse_oldbuttonstate & (1 << i)))
|
2001-02-19 21:15:25 +00:00
|
|
|
Key_Event (K_MOUSE1 + i, true);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!(mouse_buttonstate & (1 << i))
|
|
|
|
&& (mouse_oldbuttonstate & (1 << i)))
|
2001-02-19 21:15:25 +00:00
|
|
|
Key_Event (K_MOUSE1 + i, false);
|
|
|
|
}
|
|
|
|
mouse_oldbuttonstate = mouse_buttonstate;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Move (usercmd_t *cmd)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!mouse_avail)
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (m_filter->int_val) {
|
|
|
|
mouse_x = (mouse_x + old_mouse_x) * 0.5;
|
|
|
|
mouse_y = (mouse_y + old_mouse_y) * 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_mouse_x = mouse_x;
|
|
|
|
old_mouse_y = mouse_y;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
mouse_x *= sensitivity->value;
|
|
|
|
mouse_y *= sensitivity->value;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if ((in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1)))
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->sidemove += m_side->value * mouse_x;
|
|
|
|
else
|
|
|
|
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
|
|
|
|
if (in_mlook.state & 1)
|
|
|
|
V_StopPitchDrift ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
|
|
|
|
if (cl.viewangles[PITCH] > 80)
|
|
|
|
cl.viewangles[PITCH] = 80;
|
|
|
|
if (cl.viewangles[PITCH] < -70)
|
|
|
|
cl.viewangles[PITCH] = -70;
|
|
|
|
} else {
|
|
|
|
if ((in_strafe.state & 1) && noclip_anglehack)
|
|
|
|
cmd->upmove -= m_forward->value * mouse_y;
|
|
|
|
else
|
|
|
|
cmd->forwardmove -= m_forward->value * mouse_y;
|
|
|
|
}
|
|
|
|
mouse_x = mouse_y = 0.0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_HandlePause (qboolean pause)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|