9front - general discussion about 9front
 help / color / mirror / Atom feed
* several patches for games/doom
@ 2015-04-25 23:38 qux
  0 siblings, 0 replies; only message in thread
From: qux @ 2015-04-25 23:38 UTC (permalink / raw)
  To: 9front

Hello,

I've been having some issues while playing games/doom, and I wrote a
couple of patches in an attempt to fix those.
All of these were tested on amd64 only.

First, I'm getting very glitchy movement when playing with the mouse.
I have no mouse-related problems when using 9front otherwise,
including with quake, so I assumed it might be a bug in games/doom.
I don't know if anyone else has had similar issues.
The following patch fixes the glitches for me:

diff -Naur a/sys/src/games/doom/g_game.c b/sys/src/games/doom/g_game.c
--- a/sys/src/games/doom/g_game.c	Sun Apr 26 00:26:32 2015
+++ b/sys/src/games/doom/g_game.c	Sun Apr 26 00:25:11 2015
@@ -566,8 +566,8 @@
 	mousebuttons[0] = ev->data1 & 1;
 	mousebuttons[1] = ev->data1 & 2;
 	mousebuttons[2] = ev->data1 & 4;
-	mousex = ev->data2*(mouseSensitivity+5)/10;
-	mousey = ev->data3*(mouseSensitivity+5)/10;
+	mousex += ev->data2*(mouseSensitivity+5)/10;
+	mousey += ev->data3*(mouseSensitivity+5)/10;
 	return true;    // eat events

       case ev_joystick:
diff -Naur a/sys/src/games/doom/i_video.c b/sys/src/games/doom/i_video.c
--- a/sys/src/games/doom/i_video.c	Sun Apr 26 00:24:55 2015
+++ b/sys/src/games/doom/i_video.c	Sun Apr 26 00:30:43 2015
@@ -344,8 +344,8 @@
 			
 			e.type = ev_mouse;
 			e.data1 = m.buttons;
-			e.data2 = 10*(m.xy.x - om.xy.x);
-			e.data3 = 10*(om.xy.y - m.xy.y);
+			e.data2 = m.xy.x - om.xy.x;
+			e.data3 = om.xy.y - m.xy.y;
 			D_PostEvent(&e);
 			om = m;


I've compared the behavior obtained with what I get when playing
Chocolate Doom on linux, and it seems fairly similar (e.g. sensitivity
isn't either too boosted or lowered in comparison).

Next, my mouse leaved the window too often while playing.
Rather than using ptinrect(2), with which it might not be warping the
mouse to the window's center often enough, I just made it fprint
whenever the mouse moves.
That might be too often for slower systems though.
This patch is applied on top of the previous one.

diff -Naur a/sys/src/games/doom/i_video.c b/sys/src/games/doom/i_video.c
--- a/sys/src/games/doom/i_video.c	Sun Apr 26 00:46:24 2015
+++ b/sys/src/games/doom/i_video.c	Sun Apr 26 00:46:57 2015
@@ -11,8 +11,6 @@

 static int resized;
 static int mouseactive;
-
-static Rectangle grabout;
 static Point center;

 static void kbdproc(void);
@@ -44,7 +42,6 @@
 	draw(screen, screen->r, display->black, nil, ZP);

 	center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
-	grabout = insetrect(screen->r, Dx(screen->r)/8);

 	if((pid = rfork(RFPROC|RFMEM|RFFDG)) == 0){
 		kbdproc();
@@ -98,7 +95,6 @@
 		draw(screen, screen->r, display->black, nil, ZP);

 		center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
-		grabout = insetrect(screen->r, Dx(screen->r)/8);
 	}

 	scale = Dx(screen->r)/SCREENWIDTH;
@@ -303,7 +299,7 @@
 mouseproc(void)
 {
 	int fd, n, nerr;
-	Mouse m, om;
+	Mouse m;
 	char buf[1+5*12];
 	event_t e;

@@ -311,7 +307,6 @@
 		sysfatal("can't open mouse: %r");

 	memset(&m, 0, sizeof m);
-	memset(&om, 0, sizeof om);
 	nerr = 0;
 	for(;;){
 		n = read(fd, buf, sizeof buf);
@@ -334,20 +329,14 @@
 			m.xy.y = atoi(buf+1+1*12);
 			m.buttons = atoi(buf+1+2*12);
 			m.msec = atoi(buf+1+3*12);
-
-			if(!ptinrect(m.xy, grabout)){
-				fprint(fd, "m%d %d", center.x, center.y);
-
-				m.xy = center;
-				om.xy = center;
-			}
 			
 			e.type = ev_mouse;
 			e.data1 = m.buttons;
-			e.data2 = m.xy.x - om.xy.x;
-			e.data3 = om.xy.y - m.xy.y;
+			e.data2 = m.xy.x - center.x;
+			e.data3 = center.y - m.xy.y;
 			D_PostEvent(&e);
-			om = m;
+			if(!eqpt(m.xy, (Point){0,0}))
+				fprint(fd, "m%d %d", center.x, center.y);

 			break;
 		}


Finally, the following patch allows to play back recorded demos.
There just was one unimplemented function that made doom exit.
I don't know if this way of getting a file's length is frowned upon or not.
To test:

% games/doom -record dicks	# saves it as dicks.lmp; press 'q' to stop
recording and exit
% games/doom -playdemo dicks

Demo playback is a bit buggered (at least for me), but it's not
related to any of this, and I haven't had much time to look at it yet.
(monsters don't behave as they should on the recording, probably a
randomness thing)


diff -Naur a/sys/src/games/doom/w_wad.c b/sys/src/games/doom/w_wad.c
--- a/sys/src/games/doom/w_wad.c	Wed Jan 18 01:13:24 2012
+++ b/sys/src/games/doom/w_wad.c	Sun Mar 15 00:17:08 2015
@@ -64,19 +64,15 @@
     while (*s) { *s = toupper(*s); s++; }
 }

-int filelength (int handle)
+int filelength (int fd)
 {
-	USED(handle);
-	I_Error ("PORTME w_wad.c filelength");
-	return -1;
-/*
-    struct stat	fileinfo;
-
-    if (fstat (handle,&fileinfo) == -1)
-	I_Error ("Error fstating");
+	uchar bs[1024];

-    return fileinfo.st_size;
-*/
+	if (fstat (fd, bs, sizeof bs) < 0){
+		fprint(2, "filelength: fstat: %r\n");
+		I_Error ("Error fstating");
+	}
+	return (int)*((vlong *)(bs+33));
 }


Happy killing.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-25 23:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-25 23:38 several patches for games/doom qux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).