vid_sunxil.c
来自「quake1 dos源代码最新版本」· C语言 代码 · 共 1,318 行 · 第 1/3 页
C
1,318 行
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:
// 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;
#if 0
case FocusIn:
printf("FocusIn...\n");
x_focus = true;
break;
case FocusOut:
printf("FocusOut...\n");
x_focus = false;
break;
#endif
}
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);
}
}
}
// flushes the given rectangles from the view buffer to the screen
void
VID_Update (vrect_t *rects)
{
void VID_Update_MT(vrect_t *);
if (count_frames) {
static int count;
static long long s;
long long gethrtime();
if (count == 0)
s = gethrtime();
if (count++ == 200) {
long long n = gethrtime();
count = 1;
printf("%lf frames/secs\n", 200.0/((double)(n-s) / 1e9));
s = n;
}
}
if (use_mt) {
VID_Update_MT(rects);
return;
}
// if the window changes dimension, skip this frame
if (config_notify) {
int w, h;
XWindowChanges chg;
unsigned int value_mask;
w = 320*current_pixel_multiply; // minimum width
h = 200*current_pixel_multiply; // minimum height
if (config_notify_width < w || config_notify_height < h) {
// We must resize the window
memset(&chg, 0, sizeof(chg));
value_mask = 0;
if (config_notify_width < w) {
config_notify_width = chg.width = w;
value_mask |= CWWidth;
}
if (config_notify_height < h) {
config_notify_height = chg.height = h;
value_mask |= CWHeight;
}
if (value_mask)
XConfigureWindow(x_disp, x_win, value_mask, &chg);
}
config_notify = 0;
vid.width = MP(config_notify_width) & ~3;
vid.height = MP(config_notify_height);
if (vid.width < 320)
vid.width = 320;
if (vid.height < 200)
vid.height = 200;
VID_ResetFramebuffer();
return;
}
// if pixel multiply changed, skip this frame
if (CheckPixelMultiply())
return;
while (rects) { // I've never seen more than one rect?
XilMemoryStorage storage;
xil_import(quake_image, TRUE); // let xil control the image
if (current_pixel_multiply < 2)
xil_copy(quake_image, display_image);
else
xil_scale(quake_image, display_image, "nearest",
(float)current_pixel_multiply, (float)current_pixel_multiply);
xil_export(quake_image); // back to quake
if (xil_get_memory_storage(quake_image, &storage) == FALSE)
Sys_Error("xil_get_memory_storage");
vid.buffer = storage.byte.data;
vid.conbuffer = vid.buffer;
rects = rects->pnext;
}
}
void
VID_Update_MT (vrect_t *rects)
{
XilImage sched_update();
// if the window changes dimension, skip this frame
if (config_notify) {
int w, h;
XWindowChanges chg;
unsigned int value_mask;
w = 320*current_pixel_multiply; // minimum width
h = 200*current_pixel_multiply; // minimum height
if (config_notify_width < w || config_notify_height < h) {
// We must resize the window
memset(&chg, 0, sizeof(chg));
value_mask = 0;
if (config_notify_width < w) {
config_notify_width = chg.width = w;
value_mask |= CWWidth;
}
if (config_notify_height < h) {
config_notify_height = chg.height = h;
value_mask |= CWHeight;
}
if (value_mask)
XConfigureWindow(x_disp, x_win, value_mask, &chg);
}
config_notify = 0;
vid.width = MP(config_notify_width) & ~3;
vid.height = MP(config_notify_height);
if (vid.width < 320)
vid.width = 320;
if (vid.height < 200)
vid.height = 200;
VID_ResetFramebuffer_MT();
return;
}
// if pixel multiply changed, skip this frame
if (CheckPixelMultiply())
return;
quake_image = sched_update(quake_image);
}
XilImage
drain_renderpipeline(XilImage old)
{
XilImage new;
XilMemoryStorage storage;
if (old)
if (read(render_pipeline[1], &new, sizeof(new)) != sizeof (new)) {
Sys_Error("drain_renderpipeline: read");
xil_destroy(new);
}
xil_destroy(old);
new = xil_create(state, vid.width, vid.height, 1, XIL_BYTE);
if (write(render_pipeline[0], &new, sizeof (new)) != sizeof(new))
Sys_Error("drain_renderpipeline: write");
new = xil_create(state, vid.width, vid.height, 1, XIL_BYTE);
xil_export(new);
if (xil_get_memory_storage(new, &storage) == FALSE)
Sys_Error("xil_get_memory_storage");
vid.rowbytes = storage.byte.scanline_stride;
vid.buffer = storage.byte.data;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.recalc_refdef = 1; // force a surface cache flush
return(new);
}
XilImage
sched_update(XilImage image)
{
XilImage new;
XilMemoryStorage storage;
if (write(render_pipeline[1], &image, sizeof(image)) != sizeof (image))
Sys_Error("sched_update:write");
if (read(render_pipeline[1], &new, sizeof(new)) != sizeof (new))
Sys_Error("sched_update:read");
xil_export(new);
if (xil_get_memory_storage(new, &storage) == FALSE)
Sys_Error("xil_get_memory_storage");
vid.buffer = storage.byte.data;
vid.conbuffer = vid.buffer;
return (new);
}
void *update_thread()
{
XilImage image;
if (!X11_active)
return;
while (read(render_pipeline[0], &image, sizeof (image)) == sizeof(image)) {
xil_import(image, TRUE); // let xil control the image
if (!display_image)
return;
if (current_pixel_multiply < 2)
xil_copy(image, display_image);
else
xil_scale(image, display_image, "nearest",
(float)current_pixel_multiply, (float)current_pixel_multiply);
if (write(render_pipeline[0], &image, sizeof (image)) != sizeof(image))
Sys_Error("update_thread: write");
}
}
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;
}
}
}
// 2001-09-18 New cvar system by Maddes (Init) start
/*
===================
IN_Init_Cvars
===================
*/
void IN_Init_Cvars (void)
{
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
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)
{
// 2001-09-18 New cvar system by Maddes (Init) start
/*
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
*/
// 2001-09-18 New cvar system by Maddes (Init) end
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;
}
//void VID_UnlockBuffer(void) { }
//void VID_LockBuffer(void) { }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?