ref: 0f42d9aeb91c01f8932e7130f3345111485f2202
parent: 26e253158ac93bbc14cc381780f9b37ea7858bd1
author: Konstantinn Bonnet <[email protected]>
date: Sat Feb 14 14:34:31 EST 2015
fix mouselook somewhat, and free it - rework mouse event handling: grabout+insetrect didn't keep the mouse inside the window much, making it kind of unplayable w/ mouse, this attempts to remedy that - add m_freelook as a quick hack allowing to look freely in all directions without +mlook. - _windowed_mouse -> m_windowed; ungrab when unset and vice versa
--- a/README
+++ b/README
@@ -22,8 +22,8 @@
- tested on 386 and amd64 only
-some cvars useful for workarounds
----------------------------------
+some params useful for workarounds
+----------------------------------
-nosound
-nostdout
-mem %d
@@ -41,6 +41,7 @@
- Sys_Warn added again for print(2) stuff in *_9.c that uses %r, kind of stupid
since Con_Printf was often used there, and it outputs to both fd=1 and console,
so needs fixing
+ - m_freelook, as a quick hack to have (reversible) free mouse look
bugs present in linux/x11 (w/ my tweaks in early commits)
--- a/in_9.c
+++ b/in_9.c
@@ -6,13 +6,14 @@
#include <keyboard.h>
#include "quakedef.h"
-cvar_t _windowed_mouse = {"_windowed_mouse","0", true};
+cvar_t m_windowed = {"m_windowed","0", true};
cvar_t m_filter = {"m_filter","0", true};
-float old_windowed_mouse;
+cvar_t m_freelook = {"m_freelook", "0", true};
+float oldm_windowed;
qboolean mouse_avail;
int mouse_buttons = 3;
int mouse_buttonstate, mouse_oldbuttonstate;
-float mouse_x, mouse_y, old_mouse_x, old_mouse_y, p_mouse_x, p_mouse_y;
+float mouse_x, mouse_y, old_mouse_x, old_mouse_y;
struct {
int key;
@@ -31,9 +32,10 @@
void Sys_SendKeyEvents(void)
{
- if(old_windowed_mouse != _windowed_mouse.value){
- old_windowed_mouse = _windowed_mouse.value;
- if(!_windowed_mouse.value)
+ /* FIXME: sloppy */
+ if(oldm_windowed != m_windowed.value){
+ oldm_windowed = m_windowed.value;
+ if(!m_windowed.value)
IN_Grabm(0);
else
IN_Grabm(1);
@@ -80,10 +82,10 @@
cmd->sidemove += m_side.value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw.value * mouse_x;
- if(in_mlook.state & 1)
+ if(m_freelook.value || in_mlook.state & 1)
V_StopPitchDrift();
- if(in_mlook.state & 1 && ~in_strafe.state & 1){
+ if(m_freelook.value || in_mlook.state & 1 && ~in_strafe.state & 1){
cl.viewangles[PITCH] += m_pitch.value * mouse_y;
if(cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
@@ -232,19 +234,11 @@
//m.buttons = atoi(buf+1+2*12);
b = atoi(buf+1+2*12);
- /* FIXME: does not work well */
- if(_windowed_mouse.value){
- if(!ptinrect(m, grabout)){
- fprint(fd, "m%d %d", center.x, center.y);
- m = center;
- p_mouse_x = center.x;
- p_mouse_y = center.y;
- }
- }
- mouse_x = (float)(m.x - p_mouse_x);
- mouse_y = (float)(m.y - p_mouse_y);
- p_mouse_x = m.x;
- p_mouse_y = m.y;
+ /* FIXME: cursor can still get out */
+ mouse_x += (float)(m.x - center.x);
+ mouse_y += (float)(m.y - center.y);
+ if(m_windowed.value)
+ fprint(fd, "m%d %d", center.x, center.y);
mouse_buttonstate = b&1 | (b&2)<<1 | (b&4)>>1;
break;
@@ -297,10 +291,12 @@
{
int pid;
- Cvar_RegisterVariable(&_windowed_mouse);
+ Cvar_RegisterVariable(&m_windowed);
Cvar_RegisterVariable(&m_filter);
+ Cvar_RegisterVariable(&m_freelook);
notify(sucks);
- IN_Grabm(1);
+ if(m_windowed.value)
+ IN_Grabm(1);
if((pid = rfork(RFPROC|RFMEM|RFFDG)) == 0){
kproc();
exits(nil);
@@ -308,12 +304,13 @@
kpid = pid;
if(COM_CheckParm("-nomouse"))
return;
- /* FIXME: notify(catch) if crash -> disable mouse */
if((pid = rfork(RFPROC|RFMEM|RFFDG)) == 0){
mproc();
exits(nil);
}
mpid = pid;
- p_mouse_x = p_mouse_y = mouse_x = mouse_y = 0.0;
+ mouse_x = mouse_y = 0.0;
+ /* FIXME: both kind of do the same thing */
+ //mouse_avail = mouseactive = 1;
mouse_avail = 1;
}
--- a/vid_9.c
+++ b/vid_9.c
@@ -31,7 +31,6 @@
void (*vid_menudrawfn)(void);
void (*vid_menukeyfn)(int key);
-
void shiftmask_init (void)
{
uint x;
@@ -205,6 +204,13 @@
// the palette data will go away after the call, so it must be copied off if
// the video driver will need it again
+void resetscr(void)
+{
+ ResetFrameBuffer();
+ center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
+ grabout = insetrect(screen->r, Dx(screen->r)/8);
+}
+
void VID_Init (unsigned char *palette)
{
int pnum;
@@ -259,9 +265,7 @@
if(screen->chan == CMAP8)
VID_SetPalette(palette);
- ResetFrameBuffer();
- center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
- grabout = insetrect(screen->r, Dx(screen->r)/8);
+ resetscr();
vid.rowbytes = Dx(screen->r) * screen->depth/8;
vid.buffer = framebuf;
vid.direct = 0;
@@ -323,9 +327,7 @@
Sys_Error("VID_Update:getwindow");
vid.width = Dx(screen->r);
vid.height = Dy(screen->r);
- ResetFrameBuffer();
- center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
- grabout = insetrect(screen->r, Dx(screen->r)/8);
+ resetscr();
vid.rowbytes = vid.width * screen->depth/8;
vid.buffer = framebuf;
vid.conbuffer = framebuf;