⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vid_sunx.c

📁 quake1 dos源代码最新版本
💻 C
📖 第 1 页 / 共 3 页
字号:
{
	Con_Printf("VID_Shutdown\n");
	//XAutoRepeatOn(x_disp);
	if (mouse_grabbed) {
		/* ungrab the pointer */
		XUngrabPointer(x_disp, CurrentTime);
		XUndefineCursor(x_disp, x_win);
	}
	XCloseDisplay(x_disp);
}

int XLateKey(XKeyEvent *ev)
{

	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;
		case XK_BackSpace:
		case XK_Delete: key = K_BACKSPACE; break;
		case XK_Pause:	key = K_PAUSE;		 break;
		case XK_Shift_L:
		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;
// various other keys on the keyboard
		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;

		default:
			key = *buf;
			break;
	}

	return key;

}

struct
{
	int key;
	int down;
} keyq[64];
int keyq_head=0;
int keyq_tail=0;

int config_notify=0;
int config_notify_width;
int config_notify_height;

void GetEvent(void)
{
	XEvent x_event;

	XNextEvent(x_disp, &x_event);
	switch(x_event.type)
	{
		case KeyPress:
			Key_Event(XLateKey(&x_event.xkey), true);
			break;
		case KeyRelease:
			Key_Event(XLateKey(&x_event.xkey), false);
			break;
		case ButtonPress:
			//printf( "button %d down\n", x_event.xbutton.button );
			Key_Event( K_MOUSE1 + x_event.xbutton.button - 1, true );
			break;
		case ButtonRelease:
			//printf( "button %d up\n", x_event.xbutton.button );
			Key_Event( K_MOUSE1 + x_event.xbutton.button - 1, false );
			break;
		case MotionNotify:
			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;

		case ConfigureNotify:
//			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;
		case ClientMessage:
			if (x_event.xclient.data.l[0] == aWMDelete) Host_Quit_f();
			break;
		case EnterNotify:
			mouse_in_window = true;
			break;
		case LeaveNotify:
			mouse_in_window = false;
			break;

		default:
			if (doShm && x_event.type == x_shmeventtype)
				oktodraw = true;
	}

	if (mouse_avail) {
		if (key_dest == key_game && !mouse_grabbed && mouse_in_window) {
			mouse_grabbed = true;
			/* grab the pointer */
			XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
				GrabModeAsync,x_win,None,CurrentTime);
			// inviso cursor
			XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
		} else if ((key_dest != key_game || !mouse_in_window) && mouse_grabbed) {
			mouse_grabbed = false;
			/* ungrab the pointer */
			XUngrabPointer(x_disp, CurrentTime);
			XUndefineCursor(x_disp, x_win);
		}
	}
}

// flushes the given rectangles from the view buffer to the screen

void	VID_Update (vrect_t *rects)
{
#if 0
	static int count;
	static long long s;
	long long gethrtime();

	if (count == 0)
		s = gethrtime();

	if (count++ == 50) {
		count = 1;
		printf("%lf frames/secs\n", 50.0/((double)(gethrtime()-s) / 1e9));
		s = gethrtime();
	}
#endif

// if the window changes dimension, skip this frame

	if (config_notify)
	{
		printf("config notify\n");
		config_notify = 0;
		vid.width = config_notify_width & ~3;
		vid.height = config_notify_height;

		printf("w = %d, h = %d\n", vid.width, vid.height);

		if (doShm)
			ResetSharedFrameBuffers();
		else
			ResetFrameBuffer();
		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;
		vid.recalc_refdef = 1;				// force a surface cache flush
		return;
	}

	if (doShm)
	{
//		long long s, gethrtime();
//		s = gethrtime();

		while (rects)
		{
printf("update: %d,%d (%d,%d)\n", rects->x, rects->y, rects->width, rects->height);
			if (x_visinfo->depth == 16)
				st2_fixup( x_framebuffer[current_framebuffer],
					rects->x, rects->y, rects->width,
					rects->height);
			else if (x_visinfo->depth == 24)
				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");
			oktodraw = false;
			while (!oktodraw) GetEvent();
			rects = rects->pnext;
		}
//		printf("%lf\n", (double)(gethrtime()-s)/1.0e9);
		current_framebuffer = !current_framebuffer;
		vid.buffer = x_framebuffer[current_framebuffer]->data;
		vid.conbuffer = vid.buffer;
		XSync(x_disp, False);

	}
	else
	{
		while (rects)
		{
			if (x_visinfo->depth == 16)
				st2_fixup( x_framebuffer[current_framebuffer],
					rects->x, rects->y, rects->width,
					rects->height);
			else if (x_visinfo->depth == 24)
				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);
			rects = rects->pnext;
		}
		XSync(x_disp, False);
	}
}

static int dither;

void VID_DitherOn(void)
{
    if (dither == 0)
    {
		vid.recalc_refdef = 1;
        dither = 1;
    }
}

void VID_DitherOff(void)
{
    if (dither)
    {
		vid.recalc_refdef = 1;
        dither = 0;
    }
}

void VID_SetDefaultMode( void )
{
}

int I_OpenWindow(void)
{
	return 0;
}

void I_EraseWindow(int window)
{
}

void I_DrawCircle(int window, int x, int y, int r)
{
}

void I_DisplayWindow(int window)
{
}

void Sys_SendKeyEvents(void)
{
// get events from x server
	if (x_disp)
	{
		while (XPending(x_disp)) GetEvent();
		while (keyq_head != keyq_tail)
		{
			Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down);
			keyq_tail = (keyq_tail + 1) & 63;
		}
	}
}

#if 0
char *Sys_ConsoleInput (void)
{

	static char	text[256];
	int		len;
	fd_set  readfds;
	int		ready;
	struct timeval timeout;

	timeout.tv_sec = 0;
	timeout.tv_usec = 0;
	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
			return text;
		}
	}

	return 0;

}
#endif

// 2001-09-18 New cvar system by Maddes (Init)  start
/*
===================
IN_Init_Cvars
===================
*/
void IN_Init_Cvars (void)
{
	m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
}
// 2001-09-18 New cvar system by Maddes (Init)  end

void IN_Init (void)
{
//	m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);	// 2001-09-18 New cvar system by Maddes (Init)
 	if ( COM_CheckParm ("-nomouse") )
		return;
	mouse_x = mouse_y = 0.0;
	mouse_avail = 1;
}

void IN_Shutdown (void)
{
	mouse_avail = 0;
}

void IN_Commands (void)
{
	int i;

	if (!mouse_avail) return;

	for (i=0 ; i<mouse_buttons ; i++) {
		if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
			Key_Event (K_MOUSE1 + i, true);

		if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
			Key_Event (K_MOUSE1 + i, false);
	}
	mouse_oldbuttonstate = mouse_buttonstate;
}

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

	if (m_filter->value) {
		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;

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

	if ( (in_strafe.state & 1) || (lookstrafe->value && ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) ))	// 2001-12-16 M_LOOK cvar by Heffo/Maddes
		cmd->sidemove += m_side->value * mouse_x;
	else
		cl.viewangles[YAW] -= m_yaw->value * mouse_x;
	if ((in_mlook.state & 1) ^ ((int)m_look->value & 1))	// 2001-12-16 M_LOOK cvar by Heffo/Maddes
		V_StopPitchDrift ();

	if ( ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) && !(in_strafe.state & 1)) {	// 2001-12-16 M_LOOK cvar by Heffo/Maddes
		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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -