Filter:   InfoImg
download in_svgalib.c
Language: C
License: GPL
Copyright: (C) 1999,2000 contributors of the QuakeForge project (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se] (C) 1996-1997 Id Software, Inc.
LOC: 317
Project Info
QuakeForge(quake)
Server: SourceForge
Type: cvs
...ake\quake\newtree32\source\
   .cvsignore
   .gdbinit
   .indent.pro
   buildnum.c
   cd_dos.c
   cd_linux.c
   cd_null.c
   cd_sdl.c
   cd_sgi.c
   cd_win.c
   checksum.c
   cl_cam.c
   cl_cmd.c
   cl_cvar.c
   cl_demo.c
   cl_ents.c
   cl_input.c
   cl_main.c
   cl_misc.c
   cl_parse.c
   cl_pred.c
   cl_slist.c
   cl_sys_sdl.c
   cl_sys_unix.c
   cl_sys_win.c
   cl_tent.c
   cmd.c
   com.c
   console.c
   context_x11.c
   crc.c
   cvar.c
   d_edge.c
   d_fill.c
   d_init.c
   d_modech.c
   d_part.c
   d_polyse.c
   d_scan.c
   d_sky.c
   d_sprite.c
   d_surf.c
   d_vars.c
   d_zpoint.c
   dga_check.c
   dirent.c
   draw.c
   fbset.c
   fbset_modes_y.y
   fnmatch.c
   fractalnoise.c
   gl_draw.c
   gl_dyn_fires.c
   gl_dyn_part.c
   gl_dyn_textures.c
   gl_mesh.c
   gl_model_alias.c
   gl_model_brush.c
   gl_model_fullbright.c
   gl_model_sprite.c
   gl_ngraph.c
   gl_rlight.c
   gl_rmain.c
   gl_rmisc.c
   gl_rsurf.c
   gl_screen.c
   gl_skin.c
   gl_sky.c
   gl_sky_clip.c
   gl_view.c
   gl_warp.c
   hash.c
   in_fbdev.c
   in_ggi.c
   in_null.c
   in_sdl.c
   in_svgalib.c
   in_win.c
   in_x11.c
   info.c
   joy_linux.c
   joy_null.c
   joy_win.c
   keys.c
   link.c
   locs.c
   Makefile.am
   makefile.mgw
   makefile.win
   mathlib.c
   mdfour.c
   menu.c
   model.c
   model_alias.c
   model_brush.c
   model_sprite.c
   msg.c
   net_chan.c
   net_com.c
   net_packetlog.c
   net_udp.c
   net_udp6.c
   nonintel.c
   pcx.c
   pmove.c
   pmovetst.c
   pr_edict.c
   pr_exec.c
   pr_offs.c
   qargs.c
   qendian.c
   qfgl_ext.c
   quakefs.c
   quakeio.c
   r_aclip.c
   r_alias.c
   r_bsp.c
   r_draw.c
   r_edge.c
   r_efrag.c
   r_light.c
   r_main.c
   r_misc.c
   r_part.c
   r_sky.c
   r_sprite.c
   r_surf.c
   r_vars.c
   r_view.c
   sbar.c
   screen.c
   sizebuf.c
   skin.c
   snd_alsa_0_5.c
   snd_alsa_0_6.c
   snd_disk.c
   snd_dma.c
   snd_mem.c
   snd_mix.c
   snd_null.c
   snd_oss.c
   snd_sdl.c
   snd_sgi.c
   snd_sun.c
   snd_win.c
   sv_ccmds.c
   sv_cvar.c
   sv_ents.c
   sv_init.c
   sv_main.c
   sv_misc.c
   sv_model.c
   sv_move.c
   sv_nchan.c
   sv_phys.c
   sv_pr_cmds.c
   sv_progs.c
   sv_send.c
   sv_sys_unix.c
   sv_sys_win.c
   sv_user.c
   sw_model_alias.c
   sw_model_brush.c
   sw_model_sprite.c
   sw_skin.c
   sw_view.c
   sys_null.c
   sys_unix.c
   sys_win.c
   teamplay.c
   tga.c
   va.c
   ver_check.c
   vid.c
   vid_3dfxsvga.c
   vid_common_gl.c
   vid_fbdev.c
   vid_ggi.c
   vid_glx.c
   vid_mgl.c
   vid_null.c
   vid_sdl.c
   vid_sgl.c
   vid_svgalib.c
   vid_wgl.c
   vid_win.c
   vid_x11.c
   wad.c
   world.c
   zone.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
	in_svgalib.c

	(description)

	Copyright (C) 1996-1997  Id Software, Inc.
	Copyright (C) 1999-2000  Marcus Sundberg [mackan@stacken.kth.se]
	Copyright (C) 1999,2000  contributors of the QuakeForge project
	Please see the file "AUTHORS" for a list of contributors

	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: in_svgalib.c,v 1.1.1.1 2001/03/06 09:34:00 lordhavoc Exp $
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgakeyboard.h>
#include <vgamouse.h>

#include "cl_input.h"
#include "client.h"
#include "cmd.h"
#include "console.h"
#include "cvar.h"
#include "host.h"
#include "input.h"
#include "joystick.h"
#include "keys.h"
#include "qargs.h"
#include "sys.h"
#include "view.h"

static int  UseKeyboard = 1;
static int  UseMouse = 1;
static int  in_svgalib_inited = 0;

static unsigned char scantokey[128];
static int  mouse_buttons;
static int  mouse_buttonstate;
static int  mouse_oldbuttonstate;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int  mx, my;

static void IN_InitKeyboard (void);
static void IN_InitMouse (void);

cvar_t		*_windowed_mouse;
cvar_t		*m_filter;

static void
keyhandler (int scancode, int state)
{
	int         sc;

	sc = scancode & 0x7f;
#if 0
	Con_Printf ("scancode=%x (%d%s)\n", scancode, sc,
				scancode & 0x80 ? "+128" : "");
#endif
	Key_Event (scantokey[sc], -1, state == KEY_EVENTPRESS);
}


static void
mousehandler (int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
{
	mouse_buttonstate = buttonstate;
	mx += dx;
	my += dy;
	if (drx > 0) {
		Key_Event (K_MWHEELUP, 0, 1);
		Key_Event (K_MWHEELUP, 0, 0);
	} else if (drx < 0) {
		Key_Event (K_MWHEELDOWN, 0, 1);
		Key_Event (K_MWHEELDOWN, 0, 0);
	}
}


void
Force_CenterView_f (void)
{
	cl.viewangles[PITCH] = 0;
}


void
IN_Init (void)
{
	if (COM_CheckParm ("-nokbd"))
		UseKeyboard = 0;
	if (COM_CheckParm ("-nomouse"))
		UseMouse = 0;

	if (UseKeyboard)
		IN_InitKeyboard ();
	if (UseMouse)
		IN_InitMouse ();

	JOY_Init ();

	in_svgalib_inited = 1;
	return;
}

void
IN_Init_Cvars (void)
{
	JOY_Init_Cvars ();
	m_filter = Cvar_Get ("m_filter", "0", 0, "Toggle mouse input filtering.");
}

static void
IN_InitKeyboard (void)
{
	int         i;

	for (i = 0; i < 128; i++) {
		scantokey[i] = ' ';
	}

	scantokey[1] = K_ESCAPE;
	scantokey[2] = '1';
	scantokey[3] = '2';
	scantokey[4] = '3';
	scantokey[5] = '4';
	scantokey[6] = '5';
	scantokey[7] = '6';
	scantokey[8] = '7';
	scantokey[9] = '8';
	scantokey[10] = '9';
	scantokey[11] = '0';
	scantokey[12] = '-';
	scantokey[13] = '=';
	scantokey[14] = K_BACKSPACE;
	scantokey[15] = K_TAB;
	scantokey[16] = 'q';
	scantokey[17] = 'w';
	scantokey[18] = 'e';
	scantokey[19] = 'r';
	scantokey[20] = 't';
	scantokey[21] = 'y';
	scantokey[22] = 'u';
	scantokey[23] = 'i';
	scantokey[24] = 'o';
	scantokey[25] = 'p';
	scantokey[26] = '[';
	scantokey[27] = ']';
	scantokey[28] = K_ENTER;
	scantokey[29] = K_CTRL;				/* left */
	scantokey[30] = 'a';
	scantokey[31] = 's';
	scantokey[32] = 'd';
	scantokey[33] = 'f';
	scantokey[34] = 'g';
	scantokey[35] = 'h';
	scantokey[36] = 'j';
	scantokey[37] = 'k';
	scantokey[38] = 'l';
	scantokey[39] = ';';
	scantokey[40] = '\'';
	scantokey[41] = '`';
	scantokey[42] = K_SHIFT;			/* left */
	scantokey[43] = '\\';
	scantokey[44] = 'z';
	scantokey[45] = 'x';
	scantokey[46] = 'c';
	scantokey[47] = 'v';
	scantokey[48] = 'b';
	scantokey[49] = 'n';
	scantokey[50] = 'm';
	scantokey[51] = ',';
	scantokey[52] = '.';
	scantokey[53] = '/';
	scantokey[54] = K_SHIFT;			/* right */
	scantokey[55] = KP_MULTIPLY;
	scantokey[56] = K_ALT;				/* left */
	scantokey[57] = ' ';
	scantokey[58] = K_CAPSLOCK;
	scantokey[59] = K_F1;
	scantokey[60] = K_F2;
	scantokey[61] = K_F3;
	scantokey[62] = K_F4;
	scantokey[63] = K_F5;
	scantokey[64] = K_F6;
	scantokey[65] = K_F7;
	scantokey[66] = K_F8;
	scantokey[67] = K_F9;
	scantokey[68] = K_F10;
	scantokey[69] = KP_NUMLCK;
	scantokey[70] = K_SCRLCK;
	scantokey[71] = KP_HOME;
	scantokey[72] = KP_UPARROW;
	scantokey[73] = KP_PGUP;
	scantokey[74] = KP_MINUS;
	scantokey[75] = KP_LEFTARROW;
	scantokey[76] = KP_5;
	scantokey[77] = KP_RIGHTARROW;
	scantokey[79] = KP_END;
	scantokey[78] = KP_PLUS;
	scantokey[80] = KP_DOWNARROW;
	scantokey[81] = KP_PGDN;
	scantokey[82] = KP_INS;
	scantokey[83] = KP_DEL;
	/* 84 to 86 not used */
	scantokey[87] = K_F11;
	scantokey[88] = K_F12;
	/* 89 to 95 not used */
	scantokey[96] = KP_ENTER;			/* keypad enter */
	scantokey[97] = K_CTRL;				/* right */
	scantokey[98] = KP_DIVIDE;
	scantokey[99] = K_PRNTSCR;			/* print screen */
	scantokey[100] = K_ALT;				/* right */

	scantokey[101] = K_PAUSE;			/* break */
	scantokey[102] = K_HOME;
	scantokey[103] = K_UPARROW;
	scantokey[104] = K_PGUP;
	scantokey[105] = K_LEFTARROW;
	scantokey[106] = K_RIGHTARROW;
	scantokey[107] = K_END;
	scantokey[108] = K_DOWNARROW;
	scantokey[109] = K_PGDN;
	scantokey[110] = K_INS;
	scantokey[111] = K_DEL;
	scantokey[119] = K_PAUSE;

	if (keyboard_init ()) {
		Sys_Error ("keyboard_init() failed");
	}
	keyboard_seteventhandler (keyhandler);
}

static void
IN_InitMouse (void)
{
	int         mtype;
	char       *mousedev;
	int         mouserate = MOUSE_DEFAULTSAMPLERATE;

	Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force viewpoint of player to center");

	mouse_buttons = 3;

	mtype = vga_getmousetype ();

	mousedev = "/dev/mouse";
	if (getenv ("MOUSEDEV"))
		mousedev = getenv ("MOUSEDEV");
	if (COM_CheckParm ("-mdev")) {
		mousedev = com_argv[COM_CheckParm ("-mdev") + 1];
	}

	if (getenv ("MOUSERATE"))
		mouserate = atoi (getenv ("MOUSERATE"));
	if (COM_CheckParm ("-mrate")) {
		mouserate = atoi (com_argv[COM_CheckParm ("-mrate") + 1]);
	}
#if 0
	printf ("Mouse: dev=%s,type=%s,speed=%d\n",
			mousedev, mice[mtype].name, mouserate);
#endif
	if (mouse_init (mousedev, mtype, mouserate)) {
		Con_Printf ("No mouse found\n");
		UseMouse = 0;
	} else {
		mouse_seteventhandler ((void *) mousehandler);
	}
}

void
IN_Shutdown (void)
{
	JOY_Shutdown ();
	Con_Printf ("IN_Shutdown\n");

	if (UseMouse)
		mouse_close ();
	if (UseKeyboard)
		keyboard_close ();
	in_svgalib_inited = 0;
}


void
IN_SendKeyEvents (void)
{
	if (!in_svgalib_inited)
		return;

	if (UseKeyboard) {
		while ((keyboard_update ()));
	}
}


void
IN_Commands (void)
{
	JOY_Command ();
	if (UseMouse) {
		/* Poll mouse values */
		while (mouse_update ());

		/* Perform button actions */
		if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
				Key_Event (K_MOUSE1, 0, true);
		else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
				 (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
			Key_Event (K_MOUSE1, 0, false);

		if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
				Key_Event (K_MOUSE2, 0, true);
		else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
				 (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
			Key_Event (K_MOUSE2, 0, false);

		if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
				Key_Event (K_MOUSE3, 0, true);
		else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
				 (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
			Key_Event (K_MOUSE3, 0, false);

		mouse_oldbuttonstate = mouse_buttonstate;
	}
}


void
IN_Move (usercmd_t *cmd)
{
	JOY_Move (cmd);
	if (!UseMouse)
		return;

	/* Poll mouse values */
	while (mouse_update ());

	if (m_filter->int_val) {
		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;
	/* Clear for next update */
	mx = my = 0;

	mouse_x *= sensitivity->value;
	mouse_y *= sensitivity->value;

	/* Add mouse X/Y movement to cmd */
	if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
		cmd->sidemove += m_side->value * mouse_x;
	} else {
		cl.viewangles[YAW] -= m_yaw->value * mouse_x;
	}

	if (freelook)
		V_StopPitchDrift ();

	if (freelook && !(in_strafe.state & 1)) {
		cl.viewangles[PITCH] += m_pitch->value * mouse_y;
		cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
	} else {
		if ((in_strafe.state & 1) && noclip_anglehack) {
			cmd->upmove -= m_forward->value * mouse_y;
		} else {
			cmd->forwardmove -= m_forward->value * mouse_y;
		}
	}
}