ref: 9bb72cc699a6eaf192df2df56715d2245f4b5118
parent: ddfc34d648ca21ff2c1eeab72cee2a960b8357fc
author: cinap_lenrek <cinap_lenrek@localhost>
date: Fri May 27 11:16:06 EDT 2011
ac97: max buffer should be full samples, games/doom: enable/disable mouse grabbing when switching to the menu
--- a/sys/src/9/pc/audioac97.c
+++ b/sys/src/9/pc/audioac97.c
@@ -139,7 +139,7 @@
{
long m;
- m = (r->nbuf - 1) - buffered(r);
+ m = (r->nbuf - BytesPerSample) - buffered(r);
if(m < 0)
m = 0;
return m;
--- a/sys/src/games/doom/i_system.c
+++ b/sys/src/games/doom/i_system.c
@@ -17,6 +17,7 @@
{
I_InitSound();
I_InitGraphics();
+ I_MouseEnable(1);
}
byte* I_ZoneBase (int *size)
--- a/sys/src/games/doom/i_video.c
+++ b/sys/src/games/doom/i_video.c
@@ -10,6 +10,7 @@
#include <keyboard.h>
static int resized;
+static int mouseactive;
static Rectangle grabout;
static Point center;
@@ -19,19 +20,6 @@
static uchar cmap[3*256];
-static void
-nocursor(void)
-{
- char curs[2*4+2*2*16];
- int fd;
-
- if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0)
- return;
- memset(curs, 0, sizeof curs);
- write(fd, curs, sizeof curs);
-}
-
-
void I_InitGraphics(void)
{
if(initdraw(nil, nil, "doom") < 0)
@@ -41,7 +29,6 @@
center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
grabout = insetrect(screen->r, Dx(screen->r)/8);
- nocursor();
proccreate(kbdproc, nil, 8*1024);
proccreate(mouseproc, nil, 8*1024);
@@ -131,7 +118,23 @@
flushimage(display, 1);
}
+void I_MouseEnable(int on)
+{
+ static char nocurs[2*4+2*2*16];
+ static int fd = -1;
+ if(mouseactive == on)
+ return;
+ if(mouseactive = on){
+ if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0)
+ return;
+ write(fd, nocurs, sizeof(nocurs));
+ }else if(fd >= 0) {
+ close(fd);
+ fd = -1;
+ }
+}
+
void I_ReadScreen(byte *scr)
{
memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
@@ -277,6 +280,9 @@
resized = 1;
/* fall through */
case 'm':
+ if(!mouseactive)
+ break;
+
m.xy.x = atoi(buf+1+0*12);
m.xy.y = atoi(buf+1+1*12);
m.buttons = atoi(buf+1+2*12);
--- a/sys/src/games/doom/i_video.h
+++ b/sys/src/games/doom/i_video.h
@@ -44,6 +44,7 @@
void I_UpdateNoBlit (void);
void I_FinishUpdate (void);
+void I_MouseEnable (int);
// Wait for vertical retrace or pause a bit.
void I_WaitVBL(int count);
@@ -52,7 +53,6 @@
void I_BeginRead (void);
void I_EndRead (void);
-
#endif
--- a/sys/src/games/doom/m_menu.c
+++ b/sys/src/games/doom/m_menu.c
@@ -1710,10 +1710,12 @@
// intro might call this repeatedly
if (menuactive)
return;
-
+
menuactive = 1;
currentMenu = &MainDef; // JDC
itemOn = currentMenu->lastOn; // JDC
+
+ I_MouseEnable(0); // disable mouse grab
}
@@ -1796,6 +1798,8 @@
void M_ClearMenus (void)
{
menuactive = 0;
+ I_MouseEnable(1); // enable mouse grabbing
+
// if (!netgame && usergame && paused)
// sendpause = true;
}