rotatesprite and multivoc have a rape baby

No, seriously.  Adds widescreen aware rotatesprite and works out half a dozen huge problems in the sound system, among other things.


git-svn-id: https://svn.eduke32.com/eduke32@1658 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-06-22 21:50:01 +00:00
parent 4c3c64286a
commit 9143833fc8
45 changed files with 1115 additions and 770 deletions

View file

@ -465,7 +465,7 @@ void drawmasks(void);
void clearview(int32_t dacol); void clearview(int32_t dacol);
void clearallviews(int32_t dacol); void clearallviews(int32_t dacol);
void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang); void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang);
void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col);
int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize); int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize);
void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize); void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize);

View file

@ -20,7 +20,6 @@ void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr);
void suckcache(intptr_t *suckptr); void suckcache(intptr_t *suckptr);
void agecache(void); void agecache(void);
mutex_t cachemutex;
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode) extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
int32_t addsearchpath(const char *p); int32_t addsearchpath(const char *p);
int32_t findfrompath(const char *fn, char **where); int32_t findfrompath(const char *fn, char **where);

View file

@ -299,7 +299,7 @@ void polymer_loadboard(void);
void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t daposz, int16_t daang, int32_t dahoriz, int16_t dacursectnum); void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t daposz, int16_t daang, int32_t dahoriz, int16_t dacursectnum);
void polymer_drawmasks(void); void polymer_drawmasks(void);
void polymer_editorpick(void); void polymer_editorpick(void);
void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
void polymer_drawmaskwall(int32_t damaskwallcnt); void polymer_drawmaskwall(int32_t damaskwallcnt);
void polymer_drawsprite(int32_t snum); void polymer_drawsprite(int32_t snum);
void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio); void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio);

View file

@ -38,7 +38,7 @@ void uploadtexture(int32_t doalloc, int32_t xsiz, int32_t ysiz, int32_t intexfmt
void polymost_drawsprite(int32_t snum); void polymost_drawsprite(int32_t snum);
void polymost_drawmaskwall(int32_t damaskwallcnt); void polymost_drawmaskwall(int32_t damaskwallcnt);
void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid); int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid);
void polymost_fillpolygon(int32_t npoints); void polymost_fillpolygon(int32_t npoints);
void polymost_initosdfuncs(void); void polymost_initosdfuncs(void);
void polymost_drawrooms(void); void polymost_drawrooms(void);
@ -130,7 +130,7 @@ static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t
f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) :
(float)(gvisibility*(vis+16+f)); (float)(gvisibility*(vis+16+f));
fogresult = clamp(f, 0.0f, 100.f); fogresult = clamp(f, 0.001f, 100.f);
Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol)); Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol));
} }

View file

@ -9,7 +9,6 @@
#include "cache1d.h" #include "cache1d.h"
#include "pragmas.h" #include "pragmas.h"
#include "baselayer.h" #include "baselayer.h"
#include "mutex.h"
#ifdef WITHKPLIB #ifdef WITHKPLIB
#include "kplib.h" #include "kplib.h"
@ -60,7 +59,6 @@ static intptr_t kzipopen(char *filnam)
#define MAXCACHEOBJECTS 9216 #define MAXCACHEOBJECTS 9216
mutex_t cachemutex;
static int32_t cachesize = 0; static int32_t cachesize = 0;
int32_t cachecount = 0; int32_t cachecount = 0;
char zerochar = 0; char zerochar = 0;
@ -101,7 +99,6 @@ void initcache(intptr_t dacachestart, int32_t dacachesize)
cac[0].lock = &zerochar; cac[0].lock = &zerochar;
cacnum = 1; cacnum = 1;
mutex_init(&cachemutex);
initprintf("Initialized %.1fM cache\n", (float)(dacachesize/1024.f/1024.f)); initprintf("Initialized %.1fM cache\n", (float)(dacachesize/1024.f/1024.f));
} }
@ -189,7 +186,6 @@ void suckcache(intptr_t *suckptr)
{ {
int32_t i; int32_t i;
while(mutex_lock(&cachemutex));
//Can't exit early, because invalid pointer might be same even though lock = 0 //Can't exit early, because invalid pointer might be same even though lock = 0
for (i=0; i<cacnum; i++) for (i=0; i<cacnum; i++)
{ {
@ -211,9 +207,7 @@ void suckcache(intptr_t *suckptr)
cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype));
} }
} }
} }
mutex_unlock(&cachemutex);
} }
void agecache(void) void agecache(void)
@ -222,7 +216,7 @@ void agecache(void)
if (agecount >= cacnum) agecount = cacnum-1; if (agecount >= cacnum) agecount = cacnum-1;
if (agecount < 0 || !cnt) return; if (agecount < 0 || !cnt) return;
while(mutex_lock(&cachemutex));
for (; cnt>=0; cnt--) for (; cnt>=0; cnt--)
{ {
if (cac[agecount].lock && (((*cac[agecount].lock)-2)&255) < 198) if (cac[agecount].lock && (((*cac[agecount].lock)-2)&255) < 198)
@ -231,7 +225,6 @@ void agecache(void)
agecount--; agecount--;
if (agecount < 0) agecount = cacnum-1; if (agecount < 0) agecount = cacnum-1;
} }
mutex_unlock(&cachemutex);
} }
static void reportandexit(char *errormessage) static void reportandexit(char *errormessage)

View file

@ -42,6 +42,8 @@
#include "engine_priv.h" #include "engine_priv.h"
#define CACHEAGETIME 16
#ifdef SUPERBUILD #ifdef SUPERBUILD
void loadvoxel(int32_t voxindex) { voxindex=0; } void loadvoxel(int32_t voxindex) { voxindex=0; }
int32_t tiletovox[MAXTILES]; int32_t tiletovox[MAXTILES];
@ -4478,7 +4480,8 @@ static int32_t clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
// dorotatesprite (internal) // dorotatesprite (internal)
// //
//JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function //JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function
static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid) static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade,
char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid)
{ {
int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by; int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by;
int32_t i, x, y, x1, y1, x2, y2, gx1, gy1 ; int32_t i, x, y, x1, y1, x2, y2, gx1, gy1 ;
@ -6256,6 +6259,11 @@ void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang)
int32_t s, w, ox, oy, startwall, cx1, cy1, cx2, cy2; int32_t s, w, ox, oy, startwall, cx1, cy1, cx2, cy2;
int32_t bakgxvect, bakgyvect, sortnum, gap, npoints; int32_t bakgxvect, bakgyvect, sortnum, gap, npoints;
int32_t xvect, yvect, xvect2, yvect2, daslope; int32_t xvect, yvect, xvect2, yvect2, daslope;
int32_t oydim=ydim;
ydim = (int32_t)((double)xdim * 0.625f);
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
ydim = oydim;
beforedrawrooms = 0; beforedrawrooms = 0;
@ -6535,6 +6543,7 @@ void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang)
} }
enddrawing(); //}}} enddrawing(); //}}}
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
} }
@ -6544,7 +6553,7 @@ void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang)
int32_t loadboard(char *filename, char fromwhere, int32_t *daposx, int32_t *daposy, int32_t *daposz, int32_t loadboard(char *filename, char fromwhere, int32_t *daposx, int32_t *daposy, int32_t *daposz,
int16_t *daang, int16_t *dacursectnum) int16_t *daang, int16_t *dacursectnum)
{ {
int16_t fil, i, numsprites; int16_t fil, i, numsprites, dq[MAXSPRITES], dnum = 0;
i = strlen(filename)-1; i = strlen(filename)-1;
if (filename[i] == 255) { filename[i] = 0; fromwhere = 1; } // JBF 20040119: "compatibility" if (filename[i] == 255) { filename[i] = 0; fromwhere = 1; } // JBF 20040119: "compatibility"
@ -6642,15 +6651,58 @@ int32_t loadboard(char *filename, char fromwhere, int32_t *daposx, int32_t *dapo
if (sprite[i].sectnum<0||sprite[i].sectnum>=MYMAXSECTORS) if (sprite[i].sectnum<0||sprite[i].sectnum>=MYMAXSECTORS)
{ {
initprintf("Map error: sprite #%d(%d,%d) with an illegal sector(%d)\n",i,sprite[i].x,sprite[i].y,sprite[i].sectnum); initprintf(OSD_ERROR "Map error: sprite #%d(%d,%d) with illegal sector(%d). Map is corrupt!\n",i,sprite[i].x,sprite[i].y,sprite[i].sectnum);
sprite[i].sectnum=MYMAXSECTORS-1; updatesector(sprite[i].x, sprite[i].y, &sprite[i].sectnum);
}
if (sprite[i].picnum<0||sprite[i].picnum>=MAXTILES)
{
initprintf(OSD_ERROR "Map error: sprite #%d(%d,%d) with illegal picnum(%d). Map is corrupt!\n",i,sprite[i].x,sprite[i].y,sprite[i].picnum);
dq[dnum++] = i;
} }
} }
for (i=0; i<numsprites; i++) for (i=0; i<numsprites; i++)
{ {
int32_t k;
int16_t sect;
if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48; if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48;
insertsprite(sprite[i].sectnum,sprite[i].statnum);
k = insertsprite(sprite[i].sectnum,sprite[i].statnum);
sect = sprite[k].sectnum;
updatesector(sprite[k].x, sprite[k].y, &sect);
if (sect == -1)
{
updatesector(sprite[k].x+1, sprite[k].y+1, &sect);
if (sect == -1)
{
updatesector(sprite[k].x-1, sprite[k].y-1, &sect);
if (sect == -1)
{
updatesector(sprite[k].x+1, sprite[k].y-1, &sect);
if (sect == -1)
{
updatesector(sprite[k].x-1, sprite[k].y+1, &sect);
/* fuck it, the sprite is clearly not legitimately in any sector at this point
so let's queue it up for deletion */
if (sect == -1)
dq[dnum++] = k;
}
}
}
}
}
while (--dnum > -1)
{
initprintf(OSD_ERROR "Map error: removing sprite #%d(%d,%d) in null space. Map is corrupt!\n",dq[dnum],sprite[dq[dnum]].x,sprite[dq[dnum]].y);
deletesprite(dq[dnum]);
} }
//Must be after loading sectors, etc! //Must be after loading sectors, etc!
@ -7742,7 +7794,7 @@ void nextpage(void)
} }
faketimerhandler(); faketimerhandler();
if ((totalclock >= lastageclock+8) || (totalclock < lastageclock)) if ((totalclock >= lastageclock+CACHEAGETIME) || (totalclock < lastageclock))
{ lastageclock = totalclock; agecache(); } { lastageclock = totalclock; agecache(); }
#ifdef USE_OPENGL #ifdef USE_OPENGL
@ -9730,7 +9782,7 @@ void flushperms(void)
// //
// rotatesprite // rotatesprite
// //
void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2) void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
{ {
int32_t i; int32_t i;
permfifotype *per, *per2; permfifotype *per, *per2;

View file

@ -11,6 +11,7 @@
#include "scancodes.h" #include "scancodes.h"
#include "crc32.h" #include "crc32.h"
static mutex_t m_osdprintf;
symbol_t *symbols = NULL; symbol_t *symbols = NULL;
static symbol_t *addnewsymbol(const char *name); static symbol_t *addnewsymbol(const char *name);
static symbol_t *findsymbol(const char *name, symbol_t *startingat); static symbol_t *findsymbol(const char *name, symbol_t *startingat);
@ -729,6 +730,8 @@ void OSD_Init(void)
{ "logcutoff","logcutoff: sets the maximal line count of the log file",(void *)&logcutoff, CVAR_INT, 0, 262144 }, { "logcutoff","logcutoff: sets the maximal line count of the log file",(void *)&logcutoff, CVAR_INT, 0, 262144 },
}; };
mutex_init(&m_osdprintf);
Bmemset(osdtext, asc_Space, TEXTSIZE); Bmemset(osdtext, asc_Space, TEXTSIZE);
Bmemset(osdfmt, osdtextpal+(osdtextshade<<5), TEXTSIZE); Bmemset(osdfmt, osdtextpal+(osdtextshade<<5), TEXTSIZE);
Bmemset(osdsymbptrs, 0, sizeof(osdsymbptrs)); Bmemset(osdsymbptrs, 0, sizeof(osdsymbptrs));
@ -1504,8 +1507,12 @@ void OSD_Printf(const char *fmt, ...)
char *chp, p=osdtextpal, s=osdtextshade; char *chp, p=osdtextpal, s=osdtextshade;
va_list va; va_list va;
/*
if ((osdflags & OSD_INITIALIZED) == 0) if ((osdflags & OSD_INITIALIZED) == 0)
OSD_Init(); OSD_Init();
*/
mutex_lock(&m_osdprintf);
va_start(va, fmt); va_start(va, fmt);
Bvsnprintf(tmpstr, 8192, fmt, va); Bvsnprintf(tmpstr, 8192, fmt, va);
@ -1517,6 +1524,7 @@ void OSD_Printf(const char *fmt, ...)
else else
{ {
OSD_errors=MAX_ERRORS+2; OSD_errors=MAX_ERRORS+2;
mutex_unlock(&m_osdprintf);
return; return;
} }
} }
@ -1593,6 +1601,8 @@ void OSD_Printf(const char *fmt, ...)
} }
} }
while (*(++chp)); while (*(++chp));
mutex_unlock(&m_osdprintf);
} }

View file

@ -994,7 +994,8 @@ void polymer_editorpick(void)
searchit = 0; searchit = 0;
} }
void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2) void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade,
char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
{ {
UNREFERENCED_PARAMETER(sx); UNREFERENCED_PARAMETER(sx);
UNREFERENCED_PARAMETER(sy); UNREFERENCED_PARAMETER(sy);
@ -3091,7 +3092,7 @@ static void polymer_extractfrustum(GLfloat* modelview, GLfloat* projecti
static inline int32_t polymer_planeinfrustum(_prplane *plane, float* frustum) static inline int32_t polymer_planeinfrustum(_prplane *plane, float* frustum)
{ {
int32_t i, j, k; int32_t i, j, k = -1;
i = 4; i = 4;
do do

View file

@ -5186,7 +5186,7 @@ void polymost_drawsprite(int32_t snum)
//dastat&128 1:draw all pages (permanent) //dastat&128 1:draw all pages (permanent)
//cx1,... clip window (actual screen coords) //cx1,... clip window (actual screen coords)
void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid) int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid)
{ {
static int32_t onumframes = 0; static int32_t onumframes = 0;
int32_t n, nn, x, zz, xoff, yoff, xsiz, ysiz, method; int32_t n, nn, x, zz, xoff, yoff, xsiz, ysiz, method;
@ -5196,6 +5196,8 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
double ogrhalfxdown10, ogrhalfxdown10x; double ogrhalfxdown10, ogrhalfxdown10x;
double d, cosang, sinang, cosang2, sinang2, px[8], py[8], px2[8], py2[8]; double d, cosang, sinang, cosang2, sinang2, px[8], py[8], px2[8], py2[8];
float m[4][4]; float m[4][4];
int32_t oxdim = xdim, oydim = ydim;
#ifdef USE_OPENGL #ifdef USE_OPENGL
if (rendmode >= 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) if (rendmode >= 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd)
@ -5378,22 +5380,53 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
if (dastat&2) //Auto window size scaling if (dastat&2) //Auto window size scaling
{ {
// nasty hacks go here
if (!(dastat&8)) if (!(dastat&8))
{ {
x = xdimenscale; //= scale(xdimen,yxaspect,320); x = xdimenscale; //= scale(xdimen,yxaspect,320);
sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),oxdimen,320);
if (!(dastat & 1024) && ((double)ydim/(double)xdim) <= .75f)
{
xdim = (int32_t)((double)ydim * 1.33333333333333334f);
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
}
if (dastat & 512)
sx = ((cx1+cx2+2+scale((oxdim-xdim), cx1+cx2+2, oxdim))<<15)+scale(sx-(320<<15),scale(xdimen, xdim, oxdim),320);
else if (dastat & 256)
sx = ((cx1+cx2+2-scale((oxdim-xdim), cx1+cx2+2, oxdim))<<15)+scale(sx-(320<<15),scale(xdimen, xdim, oxdim),320);
else
sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),scale(xdimen, xdim, oxdim),320);
sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x); sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x);
} }
else else
{ {
//If not clipping to startmosts, & auto-scaling on, as a //If not clipping to startmosts, & auto-scaling on, as a
//hard-coded bonus, scale to full screen instead //hard-coded bonus, scale to full screen instead
if (!(dastat & 1024) && ((double)ydim/(double)xdim) <= .75f)
{
xdim = (int32_t)((double)ydim * 1.33333333333333334f);
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
}
x = scale(xdim,yxaspect,320); x = scale(xdim,yxaspect,320);
sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320);
sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x);
if (dastat & 512)
sx += (oxdim-xdim)<<16;
else if ((dastat & 256) == 0)
sx += (oxdim-xdim)<<15;
} }
z = mulscale16(z,x); z = mulscale16(z,x);
} }
else if (!(dastat & 1024) && ((double)ydim/(double)xdim) <= .75f)
{
ydim = (int32_t)((double)xdim * 0.75f);
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
}
d = (double)z/(65536.0*16384.0); d = (double)z/(65536.0*16384.0);
cosang2 = cosang = (double)sintable[(a+512)&2047]*d; cosang2 = cosang = (double)sintable[(a+512)&2047]*d;
@ -5496,6 +5529,9 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
gshang = ogshang; gshang = ogshang;
gctang = ogctang; gctang = ogctang;
gstang = ogstang; gstang = ogstang;
xdim = oxdim;
ydim = oydim;
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
} }
#ifdef USE_OPENGL #ifdef USE_OPENGL

View file

@ -84,6 +84,8 @@ static int32_t buildkeytranslationtable(void);
static SDL_Surface * appicon = NULL; static SDL_Surface * appicon = NULL;
static SDL_Surface * loadappicon(void); static SDL_Surface * loadappicon(void);
static mutex_t m_initprintf;
int32_t wm_msgbox(char *name, char *fmt, ...) int32_t wm_msgbox(char *name, char *fmt, ...)
{ {
char buf[2048]; char buf[2048];
@ -251,6 +253,8 @@ int32_t initsystem(void)
SDL_VERSION(&compiled); SDL_VERSION(&compiled);
mutex_init(&m_initprintf);
initprintf("Initializing SDL system interface " initprintf("Initializing SDL system interface "
"(compiled against SDL version %d.%d.%d, found version %d.%d.%d)\n", "(compiled against SDL version %d.%d.%d, found version %d.%d.%d)\n",
compiled.major, compiled.minor, compiled.patch, compiled.major, compiled.minor, compiled.patch,
@ -361,6 +365,7 @@ void initprintf(const char *f, ...)
OSD_Printf(buf); OSD_Printf(buf);
Bprintf("%s", buf); Bprintf("%s", buf);
mutex_lock(&m_initprintf);
if (Bstrlen(dabuf) + Bstrlen(buf) > 1022) if (Bstrlen(dabuf) + Bstrlen(buf) > 1022)
{ {
startwin_puts(dabuf); startwin_puts(dabuf);
@ -375,6 +380,7 @@ void initprintf(const char *f, ...)
startwin_idle(NULL); startwin_idle(NULL);
Bmemset(dabuf, 0, sizeof(dabuf)); Bmemset(dabuf, 0, sizeof(dabuf));
} }
mutex_unlock(&m_initprintf);
} }
// //

View file

@ -34,10 +34,13 @@
#include "osd.h" #include "osd.h"
#include "rawinput.h" #include "rawinput.h"
#include "nedmalloc.h" #include "nedmalloc.h"
#include "mutex.h"
// undefine to restrict windowed resolutions to conventional sizes // undefine to restrict windowed resolutions to conventional sizes
#define ANY_WINDOWED_SIZE #define ANY_WINDOWED_SIZE
static mutex_t m_initprintf;
int32_t _buildargc = 0; int32_t _buildargc = 0;
const char **_buildargv = NULL; const char **_buildargv = NULL;
static char *argvbuf = NULL; static char *argvbuf = NULL;
@ -348,6 +351,8 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
nedcreatepool(SYSTEM_POOL_SIZE, -1); nedcreatepool(SYSTEM_POOL_SIZE, -1);
// atexit(neddestroysyspool); // atexit(neddestroysyspool);
#else #else
// don't want to mix msvcrt with msvcrtd!
#ifndef DEBUGGINGAIDS
if ((nedhandle = LoadLibrary("nedmalloc.dll"))) if ((nedhandle = LoadLibrary("nedmalloc.dll")))
{ {
nedpool *(WINAPI *nedcreatepool)(size_t, int); nedpool *(WINAPI *nedcreatepool)(size_t, int);
@ -355,6 +360,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
if ((nedcreatepool = (void *)GetProcAddress(nedhandle, "nedcreatepool"))) if ((nedcreatepool = (void *)GetProcAddress(nedhandle, "nedcreatepool")))
nedcreatepool(SYSTEM_POOL_SIZE, -1); nedcreatepool(SYSTEM_POOL_SIZE, -1);
} }
#endif
#endif #endif
hdc = GetDC(NULL); hdc = GetDC(NULL);
@ -593,6 +599,8 @@ int32_t initsystem(void)
// initprintf("Initializing Windows DirectX/GDI system interface\n"); // initprintf("Initializing Windows DirectX/GDI system interface\n");
mutex_init(&m_initprintf);
// get the desktop dimensions before anything changes them // get the desktop dimensions before anything changes them
ZeroMemory(&desktopmode, sizeof(DEVMODE)); ZeroMemory(&desktopmode, sizeof(DEVMODE));
desktopmode.dmSize = sizeof(DEVMODE); desktopmode.dmSize = sizeof(DEVMODE);
@ -668,6 +676,7 @@ void initprintf(const char *f, ...)
OSD_Printf(buf); OSD_Printf(buf);
mutex_lock(&m_initprintf);
if ((Bstrlen(dabuf) + Bstrlen(buf) + 2) > sizeof(dabuf)) if ((Bstrlen(dabuf) + Bstrlen(buf) + 2) > sizeof(dabuf))
{ {
startwin_puts(dabuf); startwin_puts(dabuf);
@ -682,6 +691,7 @@ void initprintf(const char *f, ...)
handleevents(); handleevents();
Bmemset(dabuf, 0, sizeof(dabuf)); Bmemset(dabuf, 0, sizeof(dabuf));
} }
mutex_unlock(&m_initprintf);
} }

View file

@ -88,12 +88,14 @@ char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
"Next_Weapon", "Next_Weapon",
"Previous_Weapon", "Previous_Weapon",
"Show_Console", "Show_Console",
"Show_DukeMatch_Scores" "Show_DukeMatch_Scores",
"Dpad_Select",
"Dpad_Aiming"
}; };
#ifdef __SETUP__ #ifdef __SETUP__
#define NUMKEYENTRIES 54 #define NUMKEYENTRIES 56
char keydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] = char keydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] =
{ {
@ -150,7 +152,9 @@ char keydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] =
"Next_Weapon", "'", "", "Next_Weapon", "'", "",
"Previous_Weapon", ";", "", "Previous_Weapon", ";", "",
"Show_Console", "`", "", "Show_Console", "`", "",
"Show_DukeMatch_Scores," "", "" "Show_DukeMatch_Scores", "", "",
"Dpad_Select", "", "",
"Dpad_Aiming", "", "",
}; };
const char oldkeydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] = const char oldkeydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] =
@ -208,7 +212,9 @@ const char oldkeydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] =
"Next_Weapon", "'", "", "Next_Weapon", "'", "",
"Previous_Weapon", ";", "", "Previous_Weapon", ";", "",
"Show_Console", "`", "", "Show_Console", "`", "",
"Show_DukeMatch_Scores", "", "" "Show_DukeMatch_Scores", "", "",
"Dpad_Select", "", "",
"Dpad_Aiming", "", "",
}; };
static char * mousedefaults[] = static char * mousedefaults[] =

View file

@ -2164,8 +2164,7 @@ CLEAR_THE_BOLT:
if (t[1]) if (t[1])
{ {
t[1]--; if (--t[1] == 0)
if (t[1] == 0)
s->cstat &= 32767; s->cstat &= 32767;
} }
else else

View file

@ -275,7 +275,7 @@ void G_PlayAnim(const char *fn,char t)
g_restorePalette = 0; g_restorePalette = 0;
} }
rotatesprite(0<<16,0<<16,65536L,512,TILE_ANIM,0,0,2+4+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0<<16,0<<16,65536L,512,TILE_ANIM,0,0,2+4+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
nextpage(); nextpage();
} }

View file

@ -335,7 +335,7 @@ typedef struct {
int16_t cameraang, camerasect, camerahoriz; int16_t cameraang, camerasect, camerahoriz;
int16_t pause_on,from_bonus; int16_t pause_on,from_bonus;
int16_t camerasprite,last_camsprite; int16_t camerasprite,last_camsprite;
int16_t last_level,secretlevel; int16_t last_level,secretlevel, bgstretch;
struct { struct {
int32_t UseJoystick; int32_t UseJoystick;

View file

@ -6,6 +6,7 @@ EROOT?=build
RELEASE?=1 RELEASE?=1
OPTLEVEL?=2 OPTLEVEL?=2
SRC=src SRC=src
INC=include
include ../../$(EROOT)/Makefile.shared include ../../$(EROOT)/Makefile.shared
@ -25,14 +26,15 @@ CFLAGS=$(debug) -W -Wall -Wimplicit -Werror-implicit-function-declaration \
-funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \ -funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \
-fjump-tables -fno-stack-protector -fjump-tables -fno-stack-protector
CPPFLAGS=-Iinclude -Isrc CPPFLAGS=-I$(INC) -I$(SRC)
OBJECTS=$(OBJ)/callbacks.o \ OBJECTS=$(OBJ)/callbacks.o \
$(OBJ)/host.o \ $(OBJ)/host.o \
$(OBJ)/list.o \ $(OBJ)/list.o \
$(OBJ)/packet.o \ $(OBJ)/packet.o \
$(OBJ)/peer.o \ $(OBJ)/peer.o \
$(OBJ)/protocol.o $(OBJ)/protocol.o \
$(OBJ)/compress.o
ifeq ($(PLATFORM),WINDOWS) ifeq ($(PLATFORM),WINDOWS)
OBJECTS+= $(OBJ)/win32.o OBJECTS+= $(OBJ)/win32.o
@ -47,7 +49,7 @@ endif
$(OBJNAME): $(OBJECTS) $(OBJNAME): $(OBJECTS)
$(AR) cr $@ $^ $(AR) cr $@ $^
$(OBJECTS): $(OBJ)/%.o: $(SRC)/%.c $(OBJECTS): $(OBJ)/%.o: $(SRC)/%.c $(INC)/enet/*.h
-mkdir -p $(OBJ) -mkdir -p $(OBJ)
$(COMPILE_STATUS) $(COMPILE_STATUS)
if $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi if $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi

View file

@ -31,7 +31,8 @@ OBJECTS=$(OBJ)\callbacks.o \
$(OBJ)\packet.o \ $(OBJ)\packet.o \
$(OBJ)\peer.o \ $(OBJ)\peer.o \
$(OBJ)\protocol.o \ $(OBJ)\protocol.o \
$(OBJ)\win32.o $(OBJ)\win32.o \
$(OBJ)\compress.o
{$(SRC)}.c{$(OBJ)}.o: {$(SRC)}.c{$(OBJ)}.o:
$(CC) /c $(CFLAGS) /Fo$@ $< $(CC) /c $(CFLAGS) /Fo$@ $<

View file

@ -11,7 +11,6 @@ typedef struct _ENetCallbacks
{ {
void * (ENET_CALLBACK * malloc) (size_t size); void * (ENET_CALLBACK * malloc) (size_t size);
void (ENET_CALLBACK * free) (void * memory); void (ENET_CALLBACK * free) (void * memory);
int (ENET_CALLBACK * rand) (void);
void (ENET_CALLBACK * no_memory) (void); void (ENET_CALLBACK * no_memory) (void);
} ENetCallbacks; } ENetCallbacks;
@ -21,7 +20,6 @@ typedef struct _ENetCallbacks
*/ */
extern void * enet_malloc (size_t); extern void * enet_malloc (size_t);
extern void enet_free (void *); extern void enet_free (void *);
extern int enet_rand (void);
/** @} */ /** @} */

View file

@ -24,8 +24,8 @@ extern "C"
#include "enet/callbacks.h" #include "enet/callbacks.h"
#define ENET_VERSION_MAJOR 1 #define ENET_VERSION_MAJOR 1
#define ENET_VERSION_MINOR 2 #define ENET_VERSION_MINOR 3
#define ENET_VERSION_PATCH 2 #define ENET_VERSION_PATCH 0
#define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch)) #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH) #define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
@ -233,7 +233,9 @@ typedef struct _ENetPeer
struct _ENetHost * host; struct _ENetHost * host;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 incomingPeerID; enet_uint16 incomingPeerID;
enet_uint32 sessionID; enet_uint32 connectID;
enet_uint8 outgoingSessionID;
enet_uint8 incomingSessionID;
ENetAddress address; /**< Internet address of the peer */ ENetAddress address; /**< Internet address of the peer */
void * data; /**< Application private data, may be freely modified */ void * data; /**< Application private data, may be freely modified */
ENetPeerState state; ENetPeerState state;
@ -267,7 +269,7 @@ typedef struct _ENetPeer
enet_uint32 highestRoundTripTimeVariance; enet_uint32 highestRoundTripTimeVariance;
enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */ enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */
enet_uint32 roundTripTimeVariance; enet_uint32 roundTripTimeVariance;
enet_uint16 mtu; enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 reliableDataInTransit; enet_uint32 reliableDataInTransit;
enet_uint16 outgoingReliableSequenceNumber; enet_uint16 outgoingReliableSequenceNumber;
@ -281,12 +283,29 @@ typedef struct _ENetPeer
enet_uint16 incomingUnsequencedGroup; enet_uint16 incomingUnsequencedGroup;
enet_uint16 outgoingUnsequencedGroup; enet_uint16 outgoingUnsequencedGroup;
enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32]; enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
enet_uint32 disconnectData; enet_uint32 eventData;
} ENetPeer; } ENetPeer;
/** An ENet packet compressor for compressing UDP packets before socket sends or receives.
*/
typedef struct _ENetCompressor
{
/** Context data for the compressor. Must be non-NULL. */
void * context;
/** Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
/** Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
/** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
void (ENET_CALLBACK * destroy) (void * context);
} ENetCompressor;
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
/** An ENet host for communicating with peers. /** An ENet host for communicating with peers.
* *
* No fields should be modified. * No fields should be modified unless otherwise stated.
@sa enet_host_create() @sa enet_host_create()
@sa enet_host_destroy() @sa enet_host_destroy()
@ -294,6 +313,8 @@ typedef struct _ENetPeer
@sa enet_host_service() @sa enet_host_service()
@sa enet_host_flush() @sa enet_host_flush()
@sa enet_host_broadcast() @sa enet_host_broadcast()
@sa enet_host_compress()
@sa enet_host_compress_with_range_coder()
@sa enet_host_channel_limit() @sa enet_host_channel_limit()
@sa enet_host_bandwidth_limit() @sa enet_host_bandwidth_limit()
@sa enet_host_bandwidth_throttle() @sa enet_host_bandwidth_throttle()
@ -306,6 +327,7 @@ typedef struct _ENetHost
enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */ enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
enet_uint32 bandwidthThrottleEpoch; enet_uint32 bandwidthThrottleEpoch;
enet_uint32 mtu; enet_uint32 mtu;
enet_uint32 randomSeed;
int recalculateBandwidthLimits; int recalculateBandwidthLimits;
ENetPeer * peers; /**< array of peers allocated for this host */ ENetPeer * peers; /**< array of peers allocated for this host */
size_t peerCount; /**< number of peers allocated for this host */ size_t peerCount; /**< number of peers allocated for this host */
@ -319,8 +341,11 @@ typedef struct _ENetHost
size_t commandCount; size_t commandCount;
ENetBuffer buffers [ENET_BUFFER_MAXIMUM]; ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
size_t bufferCount; size_t bufferCount;
ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */
ENetCompressor compressor;
enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
ENetAddress receivedAddress; ENetAddress receivedAddress;
enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU]; enet_uint8 * receivedData;
size_t receivedDataLength; size_t receivedDataLength;
enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */ enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */ enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
@ -470,13 +495,15 @@ ENET_API void enet_packet_destroy (ENetPacket *);
ENET_API int enet_packet_resize (ENetPacket *, size_t); ENET_API int enet_packet_resize (ENetPacket *, size_t);
extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t); extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, enet_uint32, enet_uint32); ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
ENET_API void enet_host_destroy (ENetHost *); ENET_API void enet_host_destroy (ENetHost *);
ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t); ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
ENET_API int enet_host_check_events (ENetHost *, ENetEvent *); ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32); ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
ENET_API void enet_host_flush (ENetHost *); ENET_API void enet_host_flush (ENetHost *);
ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *); ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
ENET_API void enet_host_channel_limit (ENetHost *, size_t); ENET_API void enet_host_channel_limit (ENetHost *, size_t);
ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32); ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
extern void enet_host_bandwidth_throttle (ENetHost *); extern void enet_host_bandwidth_throttle (ENetHost *);
@ -495,6 +522,13 @@ extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetO
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16); extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32); extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32);
extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16); extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *);
extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *);
ENET_API void * enet_range_coder_create (void);
ENET_API void enet_range_coder_destroy (void *);
ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
extern size_t enet_protocol_command_size (enet_uint8); extern size_t enet_protocol_command_size (enet_uint8);

View file

@ -16,7 +16,7 @@ enum
ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768, ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768,
ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1, ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255, ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0x7FFF ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF
}; };
typedef enum _ENetProtocolCommand typedef enum _ENetProtocolCommand
@ -43,8 +43,12 @@ typedef enum _ENetProtocolFlag
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7), ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6), ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14),
ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15), ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15),
ENET_PROTOCOL_HEADER_FLAG_MASK = 0x8000 ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME,
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12),
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
} ENetProtocolFlag; } ENetProtocolFlag;
#ifdef _MSC_VER_ #ifdef _MSC_VER_
@ -58,7 +62,6 @@ typedef enum _ENetProtocolFlag
typedef struct _ENetProtocolHeader typedef struct _ENetProtocolHeader
{ {
enet_uint32 checksum;
enet_uint16 peerID; enet_uint16 peerID;
enet_uint16 sentTime; enet_uint16 sentTime;
} ENET_PACKED ENetProtocolHeader; } ENET_PACKED ENetProtocolHeader;
@ -81,7 +84,9 @@ typedef struct _ENetProtocolConnect
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 mtu; enet_uint8 incomingSessionID;
enet_uint8 outgoingSessionID;
enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 channelCount; enet_uint32 channelCount;
enet_uint32 incomingBandwidth; enet_uint32 incomingBandwidth;
@ -89,14 +94,17 @@ typedef struct _ENetProtocolConnect
enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration; enet_uint32 packetThrottleDeceleration;
enet_uint32 sessionID; enet_uint32 connectID;
enet_uint32 data;
} ENET_PACKED ENetProtocolConnect; } ENET_PACKED ENetProtocolConnect;
typedef struct _ENetProtocolVerifyConnect typedef struct _ENetProtocolVerifyConnect
{ {
ENetProtocolCommandHeader header; ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID; enet_uint16 outgoingPeerID;
enet_uint16 mtu; enet_uint8 incomingSessionID;
enet_uint8 outgoingSessionID;
enet_uint32 mtu;
enet_uint32 windowSize; enet_uint32 windowSize;
enet_uint32 channelCount; enet_uint32 channelCount;
enet_uint32 incomingBandwidth; enet_uint32 incomingBandwidth;
@ -104,6 +112,7 @@ typedef struct _ENetProtocolVerifyConnect
enet_uint32 packetThrottleInterval; enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration; enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration; enet_uint32 packetThrottleDeceleration;
enet_uint32 connectID;
} ENET_PACKED ENetProtocolVerifyConnect; } ENET_PACKED ENetProtocolVerifyConnect;
typedef struct _ENetProtocolBandwidthLimit typedef struct _ENetProtocolBandwidthLimit

View file

@ -6,11 +6,13 @@
#define __ENET_WIN32_H__ #define __ENET_WIN32_H__
#ifdef ENET_BUILDING_LIB #ifdef ENET_BUILDING_LIB
#ifdef _MSC_VER
#pragma warning (disable: 4996) // 'strncpy' was declared deprecated #pragma warning (disable: 4996) // 'strncpy' was declared deprecated
#pragma warning (disable: 4267) // size_t to int conversion #pragma warning (disable: 4267) // size_t to int conversion
#pragma warning (disable: 4244) // 64bit to 32bit int #pragma warning (disable: 4244) // 64bit to 32bit int
#pragma warning (disable: 4018) // signed/unsigned mismatch #pragma warning (disable: 4018) // signed/unsigned mismatch
#endif #endif
#endif
#include <stdlib.h> #include <stdlib.h>
#include <winsock2.h> #include <winsock2.h>

View file

@ -5,11 +5,14 @@
#define ENET_BUILDING_LIB 1 #define ENET_BUILDING_LIB 1
#include "enet/enet.h" #include "enet/enet.h"
static ENetCallbacks callbacks = { malloc, free, rand, abort }; static ENetCallbacks callbacks = { malloc, free, abort };
int int
enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits) enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
{ {
if (version < ENET_VERSION_CREATE (1, 3, 0))
return -1;
if (inits -> malloc != NULL || inits -> free != NULL) if (inits -> malloc != NULL || inits -> free != NULL)
{ {
if (inits -> malloc == NULL || inits -> free == NULL) if (inits -> malloc == NULL || inits -> free == NULL)
@ -19,14 +22,8 @@ enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits
callbacks.free = inits -> free; callbacks.free = inits -> free;
} }
if (inits -> rand != NULL)
callbacks.rand = inits -> rand;
if (version >= ENET_VERSION_CREATE(1, 2, 2))
{
if (inits -> no_memory != NULL) if (inits -> no_memory != NULL)
callbacks.no_memory = inits -> no_memory; callbacks.no_memory = inits -> no_memory;
}
return enet_initialize (); return enet_initialize ();
} }
@ -48,9 +45,3 @@ enet_free (void * memory)
callbacks.free (memory); callbacks.free (memory);
} }
int
enet_rand (void)
{
return callbacks.rand ();
}

View file

@ -4,6 +4,7 @@
*/ */
#define ENET_BUILDING_LIB 1 #define ENET_BUILDING_LIB 1
#include <string.h> #include <string.h>
#include <time.h>
#include "enet/enet.h" #include "enet/enet.h"
/** @defgroup host ENet host functions /** @defgroup host ENet host functions
@ -14,6 +15,7 @@
@param address the address at which other peers may connect to this host. If NULL, then no peers may connect to the host. @param address the address at which other peers may connect to this host. If NULL, then no peers may connect to the host.
@param peerCount the maximum number of peers that should be allocated for the host. @param peerCount the maximum number of peers that should be allocated for the host.
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
@param incomingBandwidth downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. @param incomingBandwidth downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
@param outgoingBandwidth upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. @param outgoingBandwidth upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
@ -25,7 +27,7 @@
at any given time. at any given time.
*/ */
ENetHost * ENetHost *
enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth) enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelLimit, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
{ {
ENetHost * host; ENetHost * host;
ENetPeer * currentPeer; ENetPeer * currentPeer;
@ -66,7 +68,15 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
if (address != NULL) if (address != NULL)
host -> address = * address; host -> address = * address;
host -> channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> randomSeed = (enet_uint32) time(NULL) + (enet_uint32) (size_t) host;
host -> randomSeed = (host -> randomSeed << 16) | (host -> randomSeed >> 16);
host -> channelLimit = channelLimit;
host -> incomingBandwidth = incomingBandwidth; host -> incomingBandwidth = incomingBandwidth;
host -> outgoingBandwidth = outgoingBandwidth; host -> outgoingBandwidth = outgoingBandwidth;
host -> bandwidthThrottleEpoch = 0; host -> bandwidthThrottleEpoch = 0;
@ -75,8 +85,10 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
host -> peerCount = peerCount; host -> peerCount = peerCount;
host -> commandCount = 0; host -> commandCount = 0;
host -> bufferCount = 0; host -> bufferCount = 0;
host -> checksum = NULL;
host -> receivedAddress.host = ENET_HOST_ANY; host -> receivedAddress.host = ENET_HOST_ANY;
host -> receivedAddress.port = 0; host -> receivedAddress.port = 0;
host -> receivedData = NULL;
host -> receivedDataLength = 0; host -> receivedDataLength = 0;
host -> totalSentData = 0; host -> totalSentData = 0;
@ -84,6 +96,11 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
host -> totalReceivedData = 0; host -> totalReceivedData = 0;
host -> totalReceivedPackets = 0; host -> totalReceivedPackets = 0;
host -> compressor.context = NULL;
host -> compressor.compress = NULL;
host -> compressor.decompress = NULL;
host -> compressor.destroy = NULL;
enet_list_clear (& host -> dispatchQueue); enet_list_clear (& host -> dispatchQueue);
for (currentPeer = host -> peers; for (currentPeer = host -> peers;
@ -92,6 +109,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
{ {
currentPeer -> host = host; currentPeer -> host = host;
currentPeer -> incomingPeerID = currentPeer - host -> peers; currentPeer -> incomingPeerID = currentPeer - host -> peers;
currentPeer -> outgoingSessionID = currentPeer -> incomingSessionID = 0xFF;
currentPeer -> data = NULL; currentPeer -> data = NULL;
enet_list_clear (& currentPeer -> acknowledgements); enet_list_clear (& currentPeer -> acknowledgements);
@ -124,6 +142,9 @@ enet_host_destroy (ENetHost * host)
enet_peer_reset (currentPeer); enet_peer_reset (currentPeer);
} }
if (host -> compressor.context != NULL && host -> compressor.destroy)
(* host -> compressor.destroy) (host -> compressor.context);
enet_free (host -> peers); enet_free (host -> peers);
enet_free (host); enet_free (host);
} }
@ -132,12 +153,13 @@ enet_host_destroy (ENetHost * host)
@param host host seeking the connection @param host host seeking the connection
@param address destination for the connection @param address destination for the connection
@param channelCount number of channels to allocate @param channelCount number of channels to allocate
@param data user data supplied to the receiving host
@returns a peer representing the foreign host on success, NULL on failure @returns a peer representing the foreign host on success, NULL on failure
@remarks The peer returned will have not completed the connection until enet_host_service() @remarks The peer returned will have not completed the connection until enet_host_service()
notifies of an ENET_EVENT_TYPE_CONNECT event for the peer. notifies of an ENET_EVENT_TYPE_CONNECT event for the peer.
*/ */
ENetPeer * ENetPeer *
enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelCount) enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelCount, enet_uint32 data)
{ {
ENetPeer * currentPeer; ENetPeer * currentPeer;
ENetChannel * channel; ENetChannel * channel;
@ -166,7 +188,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
currentPeer -> channelCount = channelCount; currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_CONNECTING; currentPeer -> state = ENET_PEER_STATE_CONNECTING;
currentPeer -> address = * address; currentPeer -> address = * address;
currentPeer -> sessionID = (enet_uint32) enet_rand (); currentPeer -> connectID = ++ host -> randomSeed;
if (host -> outgoingBandwidth == 0) if (host -> outgoingBandwidth == 0)
currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
@ -199,7 +221,9 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.header.channelID = 0xFF; command.header.channelID = 0xFF;
command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
command.connect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu); command.connect.incomingSessionID = currentPeer -> incomingSessionID;
command.connect.outgoingSessionID = currentPeer -> outgoingSessionID;
command.connect.mtu = ENET_HOST_TO_NET_32 (currentPeer -> mtu);
command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize); command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize);
command.connect.channelCount = ENET_HOST_TO_NET_32 (channelCount); command.connect.channelCount = ENET_HOST_TO_NET_32 (channelCount);
command.connect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth); command.connect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth);
@ -207,29 +231,14 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval);
command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration);
command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration);
command.connect.sessionID = currentPeer -> sessionID; command.connect.connectID = currentPeer -> connectID;
command.connect.data = ENET_HOST_TO_NET_32 (data);
enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0); enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0);
return currentPeer; return currentPeer;
} }
/** Limits the maximum allowed channels of future incoming connections.
@param host host to limit
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
*/
void
enet_host_channel_limit (ENetHost * host, size_t channelLimit)
{
if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> channelLimit = channelLimit;
}
/** Queues a packet to be sent to all peers associated with the host. /** Queues a packet to be sent to all peers associated with the host.
@param host host on which to broadcast the packet @param host host on which to broadcast the packet
@param channelID channel on which to broadcast @param channelID channel on which to broadcast
@ -254,6 +263,39 @@ enet_host_broadcast (ENetHost * host, enet_uint8 channelID, ENetPacket * packet)
enet_packet_destroy (packet); enet_packet_destroy (packet);
} }
/** Sets the packet compressor the host should use to compress and decompress packets.
@param host host to enable or disable compression for
@param compressor callbacks for for the packet compressor; if NULL, then compression is disabled
*/
void
enet_host_compress (ENetHost * host, const ENetCompressor * compressor)
{
if (host -> compressor.context != NULL && host -> compressor.destroy)
(* host -> compressor.destroy) (host -> compressor.context);
if (compressor)
host -> compressor = * compressor;
else
host -> compressor.context = NULL;
}
/** Limits the maximum allowed channels of future incoming connections.
@param host host to limit
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
*/
void
enet_host_channel_limit (ENetHost * host, size_t channelLimit)
{
if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> channelLimit = channelLimit;
}
/** Adjusts the bandwidth limits of a host. /** Adjusts the bandwidth limits of a host.
@param host host to adjust @param host host to adjust
@param incomingBandwidth new incoming bandwidth @param incomingBandwidth new incoming bandwidth

View file

@ -325,7 +325,7 @@ void
enet_peer_reset (ENetPeer * peer) enet_peer_reset (ENetPeer * peer)
{ {
peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID; peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID;
peer -> sessionID = 0; peer -> connectID = 0;
peer -> state = ENET_PEER_STATE_DISCONNECTED; peer -> state = ENET_PEER_STATE_DISCONNECTED;
@ -363,7 +363,7 @@ enet_peer_reset (ENetPeer * peer)
peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
peer -> incomingUnsequencedGroup = 0; peer -> incomingUnsequencedGroup = 0;
peer -> outgoingUnsequencedGroup = 0; peer -> outgoingUnsequencedGroup = 0;
peer -> disconnectData = 0; peer -> eventData = 0;
memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow)); memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow));
@ -477,7 +477,7 @@ enet_peer_disconnect_later (ENetPeer * peer, enet_uint32 data)
enet_list_empty (& peer -> sentReliableCommands))) enet_list_empty (& peer -> sentReliableCommands)))
{ {
peer -> state = ENET_PEER_STATE_DISCONNECT_LATER; peer -> state = ENET_PEER_STATE_DISCONNECT_LATER;
peer -> disconnectData = data; peer -> eventData = data;
} }
else else
enet_peer_disconnect (peer, data); enet_peer_disconnect (peer, data);
@ -585,7 +585,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
return outgoingCommand; return outgoingCommand;
} }
static void void
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel) enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
{ {
ENetListIterator currentCommand; ENetListIterator currentCommand;
@ -614,7 +614,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
} }
} }
static void void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel) enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{ {
ENetListIterator currentCommand; ENetListIterator currentCommand;

View file

@ -48,6 +48,7 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
event -> type = ENET_EVENT_TYPE_CONNECT; event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = peer; event -> peer = peer;
event -> data = peer -> eventData;
return 1; return 1;
@ -56,7 +57,7 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
event -> type = ENET_EVENT_TYPE_DISCONNECT; event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer; event -> peer = peer;
event -> data = peer -> disconnectData; event -> data = peer -> eventData;
enet_peer_reset (peer); enet_peer_reset (peer);
@ -111,6 +112,7 @@ enet_protocol_notify_connect (ENetHost * host, ENetPeer * peer, ENetEvent * even
event -> type = ENET_EVENT_TYPE_CONNECT; event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = peer; event -> peer = peer;
event -> data = peer -> eventData;
} }
else else
enet_protocol_dispatch_state (host, peer, peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING); enet_protocol_dispatch_state (host, peer, peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING);
@ -134,8 +136,12 @@ enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * e
enet_peer_reset (peer); enet_peer_reset (peer);
} }
else else
{
peer -> eventData = 0;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
} }
}
static void static void
enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer) enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer)
@ -238,32 +244,13 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
static ENetPeer * static ENetPeer *
enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command) enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command)
{ {
enet_uint16 mtu; enet_uint8 incomingSessionID, outgoingSessionID;
enet_uint32 windowSize; enet_uint32 mtu, windowSize;
ENetChannel * channel; ENetChannel * channel;
size_t channelCount; size_t channelCount;
ENetPeer * currentPeer; ENetPeer * currentPeer;
ENetProtocol verifyCommand; ENetProtocol verifyCommand;
#ifdef USE_CRC32
{
enet_uint32 crc = header -> checksum;
ENetBuffer buffer;
command -> header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (command -> header.reliableSequenceNumber);
header -> checksum = command -> connect.sessionID;
buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength;
if (enet_crc32 (& buffer, 1) != crc)
return NULL;
command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber);
}
#endif
channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount); channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount);
if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT ||
@ -277,7 +264,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED && if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&
currentPeer -> address.host == host -> receivedAddress.host && currentPeer -> address.host == host -> receivedAddress.host &&
currentPeer -> address.port == host -> receivedAddress.port && currentPeer -> address.port == host -> receivedAddress.port &&
currentPeer -> sessionID == command -> connect.sessionID) currentPeer -> connectID == command -> connect.connectID)
return NULL; return NULL;
} }
@ -299,7 +286,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
return NULL; return NULL;
currentPeer -> channelCount = channelCount; currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT; currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT;
currentPeer -> sessionID = command -> connect.sessionID; currentPeer -> connectID = command -> connect.connectID;
currentPeer -> address = host -> receivedAddress; currentPeer -> address = host -> receivedAddress;
currentPeer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> connect.outgoingPeerID); currentPeer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> connect.outgoingPeerID);
currentPeer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.incomingBandwidth); currentPeer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.incomingBandwidth);
@ -307,6 +294,19 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval); currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval);
currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration); currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration);
currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration); currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration);
currentPeer -> eventData = ENET_NET_TO_HOST_32 (command -> connect.data);
incomingSessionID = command -> connect.incomingSessionID == 0xFF ? currentPeer -> outgoingSessionID : command -> connect.incomingSessionID;
incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
if (incomingSessionID == currentPeer -> outgoingSessionID)
incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
currentPeer -> outgoingSessionID = incomingSessionID;
outgoingSessionID = command -> connect.outgoingSessionID == 0xFF ? currentPeer -> incomingSessionID : command -> connect.outgoingSessionID;
outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
if (outgoingSessionID == currentPeer -> incomingSessionID)
outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT);
currentPeer -> incomingSessionID = outgoingSessionID;
for (channel = currentPeer -> channels; for (channel = currentPeer -> channels;
channel < & currentPeer -> channels [channelCount]; channel < & currentPeer -> channels [channelCount];
@ -323,7 +323,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows));
} }
mtu = ENET_NET_TO_HOST_16 (command -> connect.mtu); mtu = ENET_NET_TO_HOST_32 (command -> connect.mtu);
if (mtu < ENET_PROTOCOL_MINIMUM_MTU) if (mtu < ENET_PROTOCOL_MINIMUM_MTU)
mtu = ENET_PROTOCOL_MINIMUM_MTU; mtu = ENET_PROTOCOL_MINIMUM_MTU;
@ -371,6 +371,8 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
verifyCommand.header.command = ENET_PROTOCOL_COMMAND_VERIFY_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; verifyCommand.header.command = ENET_PROTOCOL_COMMAND_VERIFY_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
verifyCommand.header.channelID = 0xFF; verifyCommand.header.channelID = 0xFF;
verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
verifyCommand.verifyConnect.incomingSessionID = incomingSessionID;
verifyCommand.verifyConnect.outgoingSessionID = outgoingSessionID;
verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu); verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu);
verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize); verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize);
verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount); verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount);
@ -379,6 +381,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
verifyCommand.verifyConnect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); verifyCommand.verifyConnect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval);
verifyCommand.verifyConnect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); verifyCommand.verifyConnect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration);
verifyCommand.verifyConnect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); verifyCommand.verifyConnect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration);
verifyCommand.verifyConnect.connectID = currentPeer -> connectID;
enet_peer_queue_outgoing_command (currentPeer, & verifyCommand, NULL, 0, 0); enet_peer_queue_outgoing_command (currentPeer, & verifyCommand, NULL, 0, 0);
@ -590,6 +593,9 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
memcpy (startCommand -> packet -> data + fragmentOffset, memcpy (startCommand -> packet -> data + fragmentOffset,
(enet_uint8 *) command + sizeof (ENetProtocolSendFragment), (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
fragmentLength); fragmentLength);
if (startCommand -> fragmentsRemaining <= 0)
enet_peer_dispatch_incoming_reliable_commands (peer, channel);
} }
return 0; return 0;
@ -655,7 +661,9 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
else else
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
peer -> disconnectData = ENET_NET_TO_HOST_32 (command -> disconnect.data); if (peer -> state != ENET_PEER_STATE_DISCONNECTED)
peer -> eventData = ENET_NET_TO_HOST_32 (command -> disconnect.data);
return 0; return 0;
} }
@ -735,7 +743,7 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
if (enet_list_empty (& peer -> outgoingReliableCommands) && if (enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) && enet_list_empty (& peer -> outgoingUnreliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands)) enet_list_empty (& peer -> sentReliableCommands))
enet_peer_disconnect (peer, peer -> disconnectData); enet_peer_disconnect (peer, peer -> eventData);
break; break;
} }
@ -745,8 +753,7 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
static int static int
enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command) enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command)
{ {
enet_uint16 mtu; enet_uint32 mtu, windowSize;
enet_uint32 windowSize;
size_t channelCount; size_t channelCount;
if (peer -> state != ENET_PEER_STATE_CONNECTING) if (peer -> state != ENET_PEER_STATE_CONNECTING)
@ -757,8 +764,11 @@ enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPee
if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT || if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval || ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration || ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration) ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration ||
command -> verifyConnect.connectID != peer -> connectID)
{ {
peer -> eventData = 0;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
return -1; return -1;
@ -770,8 +780,10 @@ enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPee
peer -> channelCount = channelCount; peer -> channelCount = channelCount;
peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID); peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID);
peer -> incomingSessionID = command -> verifyConnect.incomingSessionID;
peer -> outgoingSessionID = command -> verifyConnect.outgoingSessionID;
mtu = ENET_NET_TO_HOST_16 (command -> verifyConnect.mtu); mtu = ENET_NET_TO_HOST_32 (command -> verifyConnect.mtu);
if (mtu < ENET_PROTOCOL_MINIMUM_MTU) if (mtu < ENET_PROTOCOL_MINIMUM_MTU)
mtu = ENET_PROTOCOL_MINIMUM_MTU; mtu = ENET_PROTOCOL_MINIMUM_MTU;
@ -809,15 +821,21 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
enet_uint8 * currentData; enet_uint8 * currentData;
size_t headerSize; size_t headerSize;
enet_uint16 peerID, flags; enet_uint16 peerID, flags;
enet_uint8 sessionID;
if (host -> receivedDataLength < sizeof (ENetProtocolHeader)) if (host -> receivedDataLength < (size_t) & ((ENetProtocolHeader *) 0) -> sentTime)
return 0; return 0;
header = (ENetProtocolHeader *) host -> receivedData; header = (ENetProtocolHeader *) host -> receivedData;
peerID = ENET_NET_TO_HOST_16 (header -> peerID); peerID = ENET_NET_TO_HOST_16 (header -> peerID);
sessionID = (peerID & ENET_PROTOCOL_HEADER_SESSION_MASK) >> ENET_PROTOCOL_HEADER_SESSION_SHIFT;
flags = peerID & ENET_PROTOCOL_HEADER_FLAG_MASK; flags = peerID & ENET_PROTOCOL_HEADER_FLAG_MASK;
peerID &= ~ ENET_PROTOCOL_HEADER_FLAG_MASK; peerID &= ~ (ENET_PROTOCOL_HEADER_FLAG_MASK | ENET_PROTOCOL_HEADER_SESSION_MASK);
headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof (ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader *) 0) -> sentTime);
if (host -> checksum != NULL)
headerSize += sizeof (enet_uint32);
if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID) if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID)
peer = NULL; peer = NULL;
@ -831,33 +849,53 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
if (peer -> state == ENET_PEER_STATE_DISCONNECTED || if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ZOMBIE ||
(host -> receivedAddress.host != peer -> address.host && (host -> receivedAddress.host != peer -> address.host &&
peer -> address.host != ENET_HOST_BROADCAST)) peer -> address.host != ENET_HOST_BROADCAST) ||
(peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
sessionID != peer -> incomingSessionID))
return 0;
}
if (flags & ENET_PROTOCOL_HEADER_FLAG_COMPRESSED)
{
size_t originalSize;
if (host -> compressor.context == NULL || host -> compressor.decompress == NULL)
return 0; return 0;
#ifdef USE_CRC32 originalSize = host -> compressor.decompress (host -> compressor.context,
host -> receivedData + headerSize,
host -> receivedDataLength - headerSize,
host -> packetData [1] + headerSize,
sizeof (host -> packetData [1]) - headerSize);
if (originalSize <= 0 || originalSize > sizeof (host -> packetData [1]) - headerSize)
return 0;
memcpy (host -> packetData [1], header, headerSize);
host -> receivedData = host -> packetData [1];
host -> receivedDataLength = headerSize + originalSize;
}
if (host -> checksum != NULL)
{ {
enet_uint32 crc = header -> checksum; enet_uint32 * checksum = (enet_uint32 *) & host -> receivedData [headerSize - sizeof (enet_uint32)],
desiredChecksum = * checksum;
ENetBuffer buffer; ENetBuffer buffer;
header -> checksum = peer -> sessionID; * checksum = peer != NULL ? peer -> connectID : 0;
buffer.data = host -> receivedData; buffer.data = host -> receivedData;
buffer.dataLength = host -> receivedDataLength; buffer.dataLength = host -> receivedDataLength;
if (enet_crc32 (& buffer, 1) != crc) if (host -> checksum (& buffer, 1) != desiredChecksum)
return 0; return 0;
} }
#else
if (header -> checksum != peer -> sessionID)
return 0;
#endif
if (peer != NULL)
{
peer -> address.host = host -> receivedAddress.host; peer -> address.host = host -> receivedAddress.host;
peer -> address.port = host -> receivedAddress.port; peer -> address.port = host -> receivedAddress.port;
peer -> incomingDataTotal += host -> receivedDataLength; peer -> incomingDataTotal += host -> receivedDataLength;
} }
headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof (ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader *) 0) -> sentTime);
currentData = host -> receivedData + headerSize; currentData = host -> receivedData + headerSize;
while (currentData < & host -> receivedData [host -> receivedDataLength]) while (currentData < & host -> receivedData [host -> receivedDataLength])
@ -990,8 +1028,8 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
int receivedLength; int receivedLength;
ENetBuffer buffer; ENetBuffer buffer;
buffer.data = host -> receivedData; buffer.data = host -> packetData [0];
buffer.dataLength = sizeof (host -> receivedData); buffer.dataLength = sizeof (host -> packetData [0]);
receivedLength = enet_socket_receive (host -> socket, receivedLength = enet_socket_receive (host -> socket,
& host -> receivedAddress, & host -> receivedAddress,
@ -1004,6 +1042,7 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
if (receivedLength == 0) if (receivedLength == 0)
return 0; return 0;
host -> receivedData = host -> packetData [0];
host -> receivedDataLength = receivedLength; host -> receivedDataLength = receivedLength;
host -> totalReceivedData += receivedLength; host -> totalReceivedData += receivedLength;
@ -1157,7 +1196,7 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
enet_list_empty (& peer -> outgoingReliableCommands) && enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) && enet_list_empty (& peer -> outgoingUnreliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands)) enet_list_empty (& peer -> sentReliableCommands))
enet_peer_disconnect (peer, peer -> disconnectData); enet_peer_disconnect (peer, peer -> eventData);
} }
static int static int
@ -1320,9 +1359,11 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
static int static int
enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int checkForTimeouts) enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int checkForTimeouts)
{ {
ENetProtocolHeader header; enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)];
ENetProtocolHeader * header = (ENetProtocolHeader *) headerData;
ENetPeer * currentPeer; ENetPeer * currentPeer;
int sentLength; int sentLength;
size_t shouldCompress = 0;
host -> continueSending = 1; host -> continueSending = 1;
@ -1402,22 +1443,57 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
currentPeer -> packetsLost = 0; currentPeer -> packetsLost = 0;
} }
header.checksum = currentPeer -> sessionID; host -> buffers -> data = headerData;
header.peerID = ENET_HOST_TO_NET_16 (currentPeer -> outgoingPeerID | host -> headerFlags);
host -> buffers -> data = & header;
if (host -> headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) if (host -> headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)
{ {
header.sentTime = ENET_HOST_TO_NET_16 (host -> serviceTime & 0xFFFF); header -> sentTime = ENET_HOST_TO_NET_16 (host -> serviceTime & 0xFFFF);
host -> buffers -> dataLength = sizeof (ENetProtocolHeader); host -> buffers -> dataLength = sizeof (ENetProtocolHeader);
} }
else else
host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime; host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime;
#ifdef USE_CRC32 shouldCompress = 0;
header.checksum = enet_crc32 (host -> buffers, host -> bufferCount); if (host -> compressor.context != NULL && host -> compressor.compress != NULL)
{
size_t originalSize = host -> packetSize - sizeof(ENetProtocolHeader),
compressedSize = host -> compressor.compress (host -> compressor.context,
& host -> buffers [1], host -> bufferCount - 1,
originalSize,
host -> packetData [1],
originalSize);
if (compressedSize > 0 && compressedSize < originalSize)
{
host -> headerFlags |= ENET_PROTOCOL_HEADER_FLAG_COMPRESSED;
shouldCompress = compressedSize;
#ifdef ENET_DEBUG_COMPRESS
#ifdef WIN32
printf (
#else
fprintf (stderr,
#endif #endif
"peer %u: compressed %u -> %u (%u%%)\n", currentPeer -> incomingPeerID, originalSize, compressedSize, (compressedSize * 100) / originalSize);
#endif
}
}
if (currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID)
host -> headerFlags |= currentPeer -> outgoingSessionID << ENET_PROTOCOL_HEADER_SESSION_SHIFT;
header -> peerID = ENET_HOST_TO_NET_16 (currentPeer -> outgoingPeerID | host -> headerFlags);
if (host -> checksum != NULL)
{
enet_uint32 * checksum = (enet_uint32 *) & headerData [host -> buffers -> dataLength];
* checksum = currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer -> connectID : 0;
host -> buffers -> dataLength += sizeof (enet_uint32);
* checksum = host -> checksum (host -> buffers, host -> bufferCount);
}
if (shouldCompress > 0)
{
host -> buffers [1].data = host -> packetData [1];
host -> buffers [1].dataLength = shouldCompress;
host -> bufferCount = 2;
}
currentPeer -> lastSendTime = host -> serviceTime; currentPeer -> lastSendTime = host -> serviceTime;

View file

@ -30,11 +30,9 @@
#include <sys/poll.h> #include <sys/poll.h>
#endif #endif
/* sys/socket.h always has this type but never defines this as far as I can tell #ifndef __socklen_t_defined
#ifndef HAS_SOCKLEN_T
typedef int socklen_t; typedef int socklen_t;
#endif #endif
*/
#ifndef MSG_NOSIGNAL #ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0 #define MSG_NOSIGNAL 0

View file

@ -40,6 +40,7 @@ extern int32_t A_PlaySound(uint32_t num,int32_t i);
extern void S_StopSound(int32_t num); extern void S_StopSound(int32_t num);
extern void S_StopEnvSound(int32_t num,int32_t i); extern void S_StopEnvSound(int32_t num,int32_t i);
extern void S_Update(void); extern void S_Update(void);
extern void S_Cleanup(void);
extern void S_Callback(uint32_t num); extern void S_Callback(uint32_t num);
extern void S_ClearSoundLocks(void); extern void S_ClearSoundLocks(void);
extern int32_t A_CallSound(int32_t sn,int32_t whatsprite); extern int32_t A_CallSound(int32_t sn,int32_t whatsprite);

View file

@ -34,8 +34,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern "C" { extern "C" {
#endif #endif
#define NUMKEYENTRIES 54 #define NUMKEYENTRIES 56
#define NUMGAMEFUNCTIONS 54 #define NUMGAMEFUNCTIONS 56
#define MAXGAMEFUNCLEN 32 #define MAXGAMEFUNCLEN 32
extern char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN]; extern char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
@ -96,7 +96,9 @@ enum GameFunction_t
gamefunc_Next_Weapon, gamefunc_Next_Weapon,
gamefunc_Previous_Weapon, gamefunc_Previous_Weapon,
gamefunc_Show_Console, gamefunc_Show_Console,
gamefunc_Show_DukeMatch_Scores gamefunc_Show_DukeMatch_Scores,
gamefunc_Dpad_Select,
gamefunc_Dpad_Aiming
}; };
#ifdef __cplusplus #ifdef __cplusplus
}; };

View file

@ -48,6 +48,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "enet/enet.h" #include "enet/enet.h"
#include "quicklz.h" #include "quicklz.h"
#define ROTATESPRITE_MAX 2048
#if KRANDDEBUG #if KRANDDEBUG
# define GAME_INLINE # define GAME_INLINE
# define GAME_STATIC # define GAME_STATIC
@ -157,7 +159,10 @@ static int32_t user_quote_time[MAXUSERQUOTES];
static char user_quote[MAXUSERQUOTES][178]; static char user_quote[MAXUSERQUOTES][178];
// char typebuflen,typebuf[41]; // char typebuflen,typebuf[41];
static int32_t MAXCACHE1DSIZE = (32*1048576); // This was 32 for a while, but I think lowering it to 24 will help things like the Dingoo.
// Ideally, we would look at our memory usage on our most cramped platform and figure out
// how much of that is needed for the underlying OS and things like SDL instead of guessing
static int32_t MAXCACHE1DSIZE = (24*1048576);
int32_t tempwallptr; int32_t tempwallptr;
@ -337,7 +342,7 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
if (t == NULL) if (t == NULL)
return -1; return -1;
if (o & 256) if (o & ROTATESPRITE_MAX)
{ {
widthx = 320<<16; widthx = 320<<16;
shift = 0; shift = 0;
@ -379,7 +384,7 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
x = (f & 4) ? x = (f & 4) ?
(xres>>1)-textsc(newx>>1) : (xres>>1)-textsc(newx>>1) :
(widthx>>1)-((o & 256)?newx<<15:newx>>1); (widthx>>1)-((o & ROTATESPRITE_MAX)?newx<<15:newx>>1);
} }
ox = x; ox = x;
@ -419,7 +424,7 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
if (ac < tile || ac > (tile + 93)) if (ac < tile || ac > (tile + 93))
break; break;
if (o&256) if (o&ROTATESPRITE_MAX)
{ {
ox = x += (x-ox)<<16; ox = x += (x-ox)<<16;
oy = y += (y-oy)<<16; oy = y += (y-oy)<<16;
@ -439,7 +444,7 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
if ((*t >= '0' && *t <= '9')) if ((*t >= '0' && *t <= '9'))
x -= i - ((8 * z)>>16); x -= i - ((8 * z)>>16);
if ((o&256) == 0) // wrapping long strings doesn't work for precise coordinates due to overflow if ((o&ROTATESPRITE_MAX) == 0) // wrapping long strings doesn't work for precise coordinates due to overflow
{ {
if (((f&4) ? textsc(x) : x) > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET)) if (((f&4) ? textsc(x) : x) > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET))
x = origx, y += (8 * z)>>16; x = origx, y += (8 * z)>>16;
@ -487,8 +492,8 @@ int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t
int32_t ac; int32_t ac;
char ch, cmode; char ch, cmode;
cmode = (sb&256)!=0; cmode = (sb&ROTATESPRITE_MAX)!=0;
sb &= 255; sb &= ROTATESPRITE_MAX-1;
do do
{ {
@ -594,7 +599,7 @@ void Net_Connect(const char * srvaddr)
Net_Disconnect(); Net_Disconnect();
g_netClient = enet_host_create(NULL, 1, 0, 0); g_netClient = enet_host_create(NULL, 1, CHAN_MAX, 0, 0);
if (g_netClient == NULL) if (g_netClient == NULL)
{ {
@ -606,7 +611,7 @@ void Net_Connect(const char * srvaddr)
enet_address_set_host(&address, addrstr); enet_address_set_host(&address, addrstr);
address.port = atoi((addrstr = strtok(NULL, ":")) == NULL ? "23513" : addrstr); address.port = atoi((addrstr = strtok(NULL, ":")) == NULL ? "23513" : addrstr);
g_netClientPeer = enet_host_connect(g_netClient, &address, CHAN_MAX); g_netClientPeer = enet_host_connect(g_netClient, &address, CHAN_MAX, 0);
if (g_netClientPeer == NULL) if (g_netClientPeer == NULL)
{ {
@ -1757,6 +1762,7 @@ void Net_GetPackets(void)
{ {
sampletimer(); sampletimer();
MUSIC_Update(); MUSIC_Update();
S_Update();
G_HandleSpecialKeys(); G_HandleSpecialKeys();
@ -2292,7 +2298,8 @@ void G_DrawTile(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t or
if (orientation&4) if (orientation&4)
a = 1024; a = 1024;
rotatesprite((orientation&256)?x:(x<<16),(orientation&256)?y:(y<<16),65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2); rotatesprite((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
} }
void G_DrawTilePal(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p) void G_DrawTilePal(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p)
@ -2302,7 +2309,8 @@ void G_DrawTilePal(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t
if (orientation&4) if (orientation&4)
a = 1024; a = 1024;
rotatesprite((orientation&256)?x:(x<<16),(orientation&256)?y:(y<<16),65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2); rotatesprite((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
} }
void G_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation) void G_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation)
@ -2312,7 +2320,8 @@ void G_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32
if (orientation&4) if (orientation&4)
a = 1024; a = 1024;
rotatesprite((orientation&256)?x:(x<<16),(orientation&256)?y:(y<<16),32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2); rotatesprite((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
} }
void G_DrawTilePalSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p) void G_DrawTilePalSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p)
@ -2322,14 +2331,15 @@ void G_DrawTilePalSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, in
if (orientation&4) if (orientation&4)
a = 1024; a = 1024;
rotatesprite((orientation&256)?x:(x<<16),(orientation&256)?y:(y<<16),32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2); rotatesprite((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
} }
#define POLYMOSTTRANS (1) #define POLYMOSTTRANS (1)
#define POLYMOSTTRANS2 (1|32) #define POLYMOSTTRANS2 (1|32)
// draws inventory numbers in the HUD for both the full and mini status bars // draws inventory numbers in the HUD for both the full and mini status bars
static void G_DrawInvNum(int32_t x,int32_t y,char num1,char ha,char sbits) static void G_DrawInvNum(int32_t x,int32_t y,char num1,char ha,int32_t sbits)
{ {
char dabuf[80] = {0}; char dabuf[80] = {0};
int32_t shd = (x < 0); int32_t shd = (x < 0);
@ -2366,7 +2376,7 @@ static void G_DrawInvNum(int32_t x,int32_t y,char num1,char ha,char sbits)
rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1); rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
} }
static void G_DrawWeapNum(int16_t ind,int32_t x,int32_t y,int32_t num1, int32_t num2,char ha) static void G_DrawWeapNum(int16_t ind,int32_t x,int32_t y,int32_t num1, int32_t num2,int32_t ha)
{ {
char dabuf[80] = {0}; char dabuf[80] = {0};
@ -2375,7 +2385,7 @@ static void G_DrawWeapNum(int16_t ind,int32_t x,int32_t y,int32_t num1, int32_t
if (VOLUMEONE && (ind > HANDBOMB_WEAPON || ind < 0)) if (VOLUMEONE && (ind > HANDBOMB_WEAPON || ind < 0))
{ {
minitextshade(x+1,y-4,"ORDER",20,11,2+8+16+256); minitextshade(x+1,y-4,"ORDER",20,11,2+8+16+ROTATESPRITE_MAX);
return; return;
} }
@ -2529,7 +2539,7 @@ static void G_DrawWeapAmounts(DukePlayer_t *p,int32_t x,int32_t y,int32_t u)
} }
} }
static void G_DrawDigiNum(int32_t x,int32_t y,int32_t n,char s,char cs) static void G_DrawDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs)
{ {
int32_t i, j = 0, k, p, c; int32_t i, j = 0, k, p, c;
char b[10]; char b[10];
@ -2553,11 +2563,12 @@ static void G_DrawDigiNum(int32_t x,int32_t y,int32_t n,char s,char cs)
} }
} }
void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal,int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z) void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal,
int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z)
{ {
int32_t i, j = 0, k, p, c; int32_t i, j = 0, k, p, c;
char b[10]; char b[10];
int32_t shift = (cs&256)?0:16; int32_t shift = (cs&ROTATESPRITE_MAX)?0:16;
//ltoa(n,b,10); //ltoa(n,b,10);
Bsnprintf(b,10,"%d",n); Bsnprintf(b,10,"%d",n);
@ -2568,7 +2579,7 @@ void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s
p = starttile+*(b+k)-'0'; p = starttile+*(b+k)-'0';
j += (1+tilesizx[p]*z)>>16; j += (1+tilesizx[p]*z)>>16;
} }
if (cs&256) j<<=16; if (cs&ROTATESPRITE_MAX) j<<=16;
c = x-(j>>1); c = x-(j>>1);
j = 0; j = 0;
@ -2576,11 +2587,11 @@ void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s
{ {
p = starttile+*(b+k)-'0'; p = starttile+*(b+k)-'0';
rotatesprite((c+j)<<shift,y<<shift,z,0,p,s,pal,2|cs,x1,y1,x2,y2); rotatesprite((c+j)<<shift,y<<shift,z,0,p,s,pal,2|cs,x1,y1,x2,y2);
j += ((1+tilesizx[p]*z)>>((cs&256)?0:16)); j += ((1+tilesizx[p]*z)>>((cs&ROTATESPRITE_MAX)?0:16));
} }
} }
static void G_DrawAltDigiNum(int32_t x,int32_t y,int32_t n,char s,char cs) static void G_DrawAltDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs)
{ {
int32_t i, j = 0, k, p, c; int32_t i, j = 0, k, p, c;
char b[10]; char b[10];
@ -2762,51 +2773,52 @@ static void G_DrawStatusBar(int32_t snum)
// rotatesprite(sbarx(5+1),sbary(200-25+1),sbarsc(49152L),0,SIXPAK,0,4,10+16+1+32,0,0,xdim-1,ydim-1); // rotatesprite(sbarx(5+1),sbary(200-25+1),sbarsc(49152L),0,SIXPAK,0,4,10+16+1+32,0,0,xdim-1,ydim-1);
// rotatesprite(sbarx(5),sbary(200-25),sbarsc(49152L),0,SIXPAK,0,0,10+16,0,0,xdim-1,ydim-1); // rotatesprite(sbarx(5),sbary(200-25),sbarsc(49152L),0,SIXPAK,0,0,10+16,0,0,xdim-1,ydim-1);
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
rotatesprite(sbarx(2+1),sbary(200-21+1),sbarsc(49152L),0,COLA,0,4,10+16+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); rotatesprite(sbarx(2+1),sbary(200-21+1),sbarsc(49152L),0,COLA,0,4,10+16+256+POLYMOSTTRANS2,0,0,xdim-1,ydim-1);
rotatesprite(sbarx(2),sbary(200-21),sbarsc(49152L),0,COLA,0,0,10+16,0,0,xdim-1,ydim-1); rotatesprite(sbarx(2),sbary(200-21),sbarsc(49152L),0,COLA,0,0,10+16+256,0,0,xdim-1,ydim-1);
if (sprite[p->i].pal == 1 && p->last_extra < 2) if (sprite[p->i].pal == 1 && p->last_extra < 2)
G_DrawAltDigiNum(40,-(200-22),1,-16,10+16); G_DrawAltDigiNum(40,-(200-22),1,-16,10+16+256);
else if (!althud_flashing || p->last_extra > (p->max_player_health>>2) || totalclock&32) else if (!althud_flashing || p->last_extra > (p->max_player_health>>2) || totalclock&32)
{ {
int32_t s = -8; int32_t s = -8;
if (althud_flashing && p->last_extra > p->max_player_health) if (althud_flashing && p->last_extra > p->max_player_health)
s += (sintable[(totalclock<<5)&2047]>>10); s += (sintable[(totalclock<<5)&2047]>>10);
G_DrawAltDigiNum(40,-(200-22),p->last_extra,s,10+16); G_DrawAltDigiNum(40,-(200-22),p->last_extra,s,10+16+256);
} }
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
rotatesprite(sbarx(62+1),sbary(200-25+1),sbarsc(49152L),0,SHIELD,0,4,10+16+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); rotatesprite(sbarx(62+1),sbary(200-25+1),sbarsc(49152L),0,SHIELD,0,4,10+16+POLYMOSTTRANS2+256,0,0,xdim-1,ydim-1);
rotatesprite(sbarx(62),sbary(200-25),sbarsc(49152L),0,SHIELD,0,0,10+16,0,0,xdim-1,ydim-1); rotatesprite(sbarx(62),sbary(200-25),sbarsc(49152L),0,SHIELD,0,0,10+16+256,0,0,xdim-1,ydim-1);
{ {
int32_t lAmount=Gv_GetVarByLabel("PLR_MORALE",-1, p->i, snum); int32_t lAmount=Gv_GetVarByLabel("PLR_MORALE",-1, p->i, snum);
if (lAmount == -1) lAmount = p->inv_amount[GET_SHIELD]; if (lAmount == -1) lAmount = p->inv_amount[GET_SHIELD];
G_DrawAltDigiNum(105,-(200-22),lAmount,-16,10+16); G_DrawAltDigiNum(105,-(200-22),lAmount,-16,10+16+256);
} }
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
{ {
if (p->got_access&1) rotatesprite(sbarxr(39-1),sbary(200-43+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); if (p->got_access&1) rotatesprite(sbarxr(39-1),sbary(200-43+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512,0,0,xdim-1,ydim-1);
if (p->got_access&4) rotatesprite(sbarxr(34-1),sbary(200-41+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); if (p->got_access&4) rotatesprite(sbarxr(34-1),sbary(200-41+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512,0,0,xdim-1,ydim-1);
if (p->got_access&2) rotatesprite(sbarxr(29-1),sbary(200-39+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); if (p->got_access&2) rotatesprite(sbarxr(29-1),sbary(200-39+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512,0,0,xdim-1,ydim-1);
} }
if (p->got_access&1) rotatesprite(sbarxr(39),sbary(200-43),sbarsc(32768),0,ACCESSCARD,0,0,10+16,0,0,xdim-1,ydim-1); if (p->got_access&1) rotatesprite(sbarxr(39),sbary(200-43),sbarsc(32768),0,ACCESSCARD,0,0,10+16+512,0,0,xdim-1,ydim-1);
if (p->got_access&4) rotatesprite(sbarxr(34),sbary(200-41),sbarsc(32768),0,ACCESSCARD,0,23,10+16,0,0,xdim-1,ydim-1); if (p->got_access&4) rotatesprite(sbarxr(34),sbary(200-41),sbarsc(32768),0,ACCESSCARD,0,23,10+16+512,0,0,xdim-1,ydim-1);
if (p->got_access&2) rotatesprite(sbarxr(29),sbary(200-39),sbarsc(32768),0,ACCESSCARD,0,21,10+16,0,0,xdim-1,ydim-1); if (p->got_access&2) rotatesprite(sbarxr(29),sbary(200-39),sbarsc(32768),0,ACCESSCARD,0,21,10+16+512,0,0,xdim-1,ydim-1);
i = (p->curr_weapon == PISTOL_WEAPON) ? 16384 : 32768;
i = 32768;
if (p->curr_weapon == PISTOL_WEAPON) i = 16384;
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
rotatesprite(sbarxr(57-1),sbary(200-15+1),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,4,2+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); rotatesprite(sbarxr(57-1),sbary(200-15+1),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,4,10+POLYMOSTTRANS2+512,0,0,xdim-1,ydim-1);
rotatesprite(sbarxr(57),sbary(200-15),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,0,2,0,0,xdim-1,ydim-1); rotatesprite(sbarxr(57),sbary(200-15),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,0,10+512,0,0,xdim-1,ydim-1);
if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON;
else i = p->curr_weapon; else i = p->curr_weapon;
if (p->curr_weapon != KNEE_WEAPON && if (p->curr_weapon != KNEE_WEAPON &&
(!althud_flashing || totalclock&32 || p->ammo_amount[i] > (p->max_ammo_amount[i]/10))) (!althud_flashing || totalclock&32 || p->ammo_amount[i] > (p->max_ammo_amount[i]/10)))
G_DrawAltDigiNum(-20,-(200-22),p->ammo_amount[i],-16,10+16); G_DrawAltDigiNum(-20,-(200-22),p->ammo_amount[i],-16,10+16+512);
o = 102; o = 102;
permbit = 0; permbit = 0;
@ -2842,13 +2854,13 @@ static void G_DrawStatusBar(int32_t snum)
if (i >= 0) if (i >= 0)
{ {
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
rotatesprite(sbarx(231-o+1),sbary(200-21-2+1),sbarsc(65536L),0,i,0,4,10+16+permbit+POLYMOSTTRANS2,0,0,xdim-1,ydim-1); rotatesprite(sbarx(231-o+1),sbary(200-21-2+1),sbarsc(65536L),0,i,0,4,10+16+permbit+POLYMOSTTRANS2+256,0,0,xdim-1,ydim-1);
rotatesprite(sbarx(231-o),sbary(200-21-2),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1); rotatesprite(sbarx(231-o),sbary(200-21-2),sbarsc(65536L),0,i,0,0,10+16+permbit+256,0,0,xdim-1,ydim-1);
} }
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
minitext(292-30-o+1,190-3+1,"%",4,POLYMOSTTRANS+10+16+permbit + 256); minitext(292-30-o+1,190-3+1,"%",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
minitext(292-30-o,190-3,"%",6,10+16+permbit + 256); minitext(292-30-o,190-3,"%",6,10+16+permbit+256 + ROTATESPRITE_MAX);
j = 0x80000000; j = 0x80000000;
switch (p->inven_icon) switch (p->inven_icon)
@ -2878,42 +2890,43 @@ static void G_DrawStatusBar(int32_t snum)
i = (p->inv_amount[GET_BOOTS]>>1); i = (p->inv_amount[GET_BOOTS]>>1);
break; break;
} }
G_DrawInvNum(-(284-30-o),200-6-3,(uint8_t)i,0,10+permbit); G_DrawInvNum(-(284-30-o),200-6-3,(uint8_t)i,0,10+permbit+256);
if (j > 0) if (j > 0)
{ {
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
minitext(288-30-o+1,180-3+1,"ON",4,POLYMOSTTRANS+10+16+permbit + 256); minitext(288-30-o+1,180-3+1,"ON",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
minitext(288-30-o,180-3,"ON",0,10+16+permbit + 256); minitext(288-30-o,180-3,"ON",0,10+16+permbit+256 + ROTATESPRITE_MAX);
} }
else if ((uint32_t)j != 0x80000000) else if ((uint32_t)j != 0x80000000)
{ {
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
minitext(284-30-o+1,180-3+1,"OFF",4,POLYMOSTTRANS+10+16+permbit + 256); minitext(284-30-o+1,180-3+1,"OFF",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
minitext(284-30-o,180-3,"OFF",2,10+16+permbit + 256); minitext(284-30-o,180-3,"OFF",2,10+16+permbit+256 + ROTATESPRITE_MAX);
} }
if (p->inven_icon >= 6) if (p->inven_icon >= 6)
{ {
if (getrendermode() >= 3 && althud_shadows) if (getrendermode() >= 3 && althud_shadows)
minitext(284-35-o+1,180-3+1,"AUTO",4,POLYMOSTTRANS+10+16+permbit + 256); minitext(284-35-o+1,180-3+1,"AUTO",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
minitext(284-35-o,180-3,"AUTO",2,10+16+permbit + 256); minitext(284-35-o,180-3,"AUTO",2,10+16+permbit+256 + ROTATESPRITE_MAX);
} }
} }
return; return;
} }
rotatesprite(sbarx(5),sbary(200-28),sbarsc(65536L),0,HEALTHBOX,0,21,10+16,0,0,xdim-1,ydim-1);
rotatesprite(sbarx(5),sbary(200-28),sbarsc(65536L),0,HEALTHBOX,0,21,10+16+256,0,0,xdim-1,ydim-1);
if (p->inven_icon) if (p->inven_icon)
rotatesprite(sbarx(69),sbary(200-30),sbarsc(65536L),0,INVENTORYBOX,0,21,10+16,0,0,xdim-1,ydim-1); rotatesprite(sbarx(69),sbary(200-30),sbarsc(65536L),0,INVENTORYBOX,0,21,10+16+256,0,0,xdim-1,ydim-1);
if (sprite[p->i].pal == 1 && p->last_extra < 2) // frozen if (sprite[p->i].pal == 1 && p->last_extra < 2) // frozen
G_DrawDigiNum(20,200-17,1,-16,10+16); G_DrawDigiNum(20,200-17,1,-16,10+16+256);
else G_DrawDigiNum(20,200-17,p->last_extra,-16,10+16); else G_DrawDigiNum(20,200-17,p->last_extra,-16,10+16+256);
rotatesprite(sbarx(37),sbary(200-28),sbarsc(65536L),0,AMMOBOX,0,21,10+16,0,0,xdim-1,ydim-1); rotatesprite(sbarx(37),sbary(200-28),sbarsc(65536L),0,AMMOBOX,0,21,10+16+256,0,0,xdim-1,ydim-1);
if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON;
else i = p->curr_weapon; else i = p->curr_weapon;
G_DrawDigiNum(53,200-17,p->ammo_amount[i],-16,10+16); G_DrawDigiNum(53,200-17,p->ammo_amount[i],-16,10+16+256);
o = 158; o = 158;
permbit = 0; permbit = 0;
@ -2945,9 +2958,9 @@ static void G_DrawStatusBar(int32_t snum)
default: default:
i = -1; i = -1;
} }
if (i >= 0) rotatesprite(sbarx(231-o),sbary(200-21),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1); if (i >= 0) rotatesprite(sbarx(231-o),sbary(200-21),sbarsc(65536L),0,i,0,0,10+16+permbit+256,0,0,xdim-1,ydim-1);
minitext(292-30-o,190,"%",6,10+16+permbit + 256); minitext(292-30-o,190,"%",6,10+16+permbit+256 + ROTATESPRITE_MAX);
j = 0x80000000; j = 0x80000000;
switch (p->inven_icon) switch (p->inven_icon)
@ -2977,10 +2990,10 @@ static void G_DrawStatusBar(int32_t snum)
i = (p->inv_amount[GET_BOOTS]>>1); i = (p->inv_amount[GET_BOOTS]>>1);
break; break;
} }
G_DrawInvNum(284-30-o,200-6,(uint8_t)i,0,10+permbit); G_DrawInvNum(284-30-o,200-6,(uint8_t)i,0,10+permbit+256);
if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit + 256); if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit+256 + ROTATESPRITE_MAX);
else if ((uint32_t)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit + 256); else if ((uint32_t)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit+256 + ROTATESPRITE_MAX);
if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit + 256); if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit+256 + ROTATESPRITE_MAX);
} }
return; return;
} }
@ -3235,8 +3248,8 @@ static void G_DrawStatusBar(int32_t snum)
break; break;
} }
rotatesprite(sbarx(231-o),sbary(SBY+13),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1); rotatesprite(sbarx(231-o),sbary(SBY+13),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
minitext(292-30-o,SBY+24,"%",6,10+16+permbit + 256); minitext(292-30-o,SBY+24,"%",6,10+16+permbit + ROTATESPRITE_MAX);
if (p->inven_icon >= 6) minitext(284-35-o,SBY+14,"AUTO",2,10+16+permbit + 256); if (p->inven_icon >= 6) minitext(284-35-o,SBY+14,"AUTO",2,10+16+permbit + ROTATESPRITE_MAX);
} }
if (u&(2048+4096)) if (u&(2048+4096))
{ {
@ -3254,8 +3267,8 @@ static void G_DrawStatusBar(int32_t snum)
default: default:
j = 0x80000000; j = 0x80000000;
} }
if (j > 0) minitext(288-30-o,SBY+14,"ON",0,10+16+permbit + 256); if (j > 0) minitext(288-30-o,SBY+14,"ON",0,10+16+permbit + ROTATESPRITE_MAX);
else if ((uint32_t)j != 0x80000000) minitext(284-30-o,SBY+14,"OFF",2,10+16+permbit + 256); else if ((uint32_t)j != 0x80000000) minitext(284-30-o,SBY+14,"OFF",2,10+16+permbit + ROTATESPRITE_MAX);
} }
if (u&8192) if (u&8192)
{ {
@ -3551,7 +3564,7 @@ void fadepaltile(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, in
KB_ClearKeyDown(sc_Space); KB_ClearKeyDown(sc_Space);
return; return;
} }
rotatesprite(0,0,65536L,0,tile,0,0,2+8+16, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,tile,0,0,2+8+16+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
G_FadePalette(r,g,b,start); G_FadePalette(r,g,b,start);
} }
} }
@ -3562,7 +3575,7 @@ void fadepaltile(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, in
KB_ClearKeyDown(sc_Space); KB_ClearKeyDown(sc_Space);
return; return;
} }
rotatesprite(0,0,65536L,0,tile,0,0,2+8+16, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,tile,0,0,2+8+16+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
G_FadePalette(r,g,b,start); G_FadePalette(r,g,b,start);
} }
} }
@ -3582,7 +3595,7 @@ static void G_DisplayExtraScreens(void)
P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308
fadepal(0,0,0, 0,64,7); fadepal(0,0,0, 0,64,7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,3291,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,3291,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepaltile(0,0,0, 63,0,-7, 3291); fadepaltile(0,0,0, 63,0,-7, 3291);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -3592,7 +3605,7 @@ static void G_DisplayExtraScreens(void)
fadepaltile(0,0,0, 0,64,7, 3291); fadepaltile(0,0,0, 0,64,7, 3291);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,3290,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,3290,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepaltile(0,0,0, 63,0,-7,3290); fadepaltile(0,0,0, 63,0,-7,3290);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -3609,7 +3622,7 @@ static void G_DisplayExtraScreens(void)
P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308
fadepal(0,0,0, 0,64,7); fadepal(0,0,0, 0,64,7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,TENSCREEN,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,TENSCREEN,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepaltile(0,0,0, 63,0,-7,TENSCREEN); fadepaltile(0,0,0, 63,0,-7,TENSCREEN);
while (!KB_KeyWaiting() && totalclock < 2400) while (!KB_KeyWaiting() && totalclock < 2400)
{ {
@ -3930,6 +3943,11 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16
char col; char col;
walltype *wal, *wal2; walltype *wal, *wal2;
spritetype *spr; spritetype *spr;
int32_t oydim=ydim;
ydim = (int32_t)((double)xdim * 0.625f);
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
ydim = oydim;
xvect = sintable[(-cang)&2047] * czoom; xvect = sintable[(-cang)&2047] * czoom;
yvect = sintable[(1536-cang)&2047] * czoom; yvect = sintable[(1536-cang)&2047] * czoom;
@ -4170,6 +4188,8 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16
} }
} }
setaspect(65536L,(int32_t)divscale16(ydim*320L,xdim*200L));
TRAVERSE_CONNECT(p) TRAVERSE_CONNECT(p)
{ {
if (ud.scrollmode && p == screenpeek) continue; if (ud.scrollmode && p == screenpeek) continue;
@ -4201,7 +4221,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16
rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),j,daang,i,sprite[g_player[p].ps->i].shade, rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),j,daang,i,sprite[g_player[p].ps->i].shade,
(g_player[p].ps->cursectnum > -1)?sector[g_player[p].ps->cursectnum].floorpal:0, (g_player[p].ps->cursectnum > -1)?sector[g_player[p].ps->cursectnum].floorpal:0,
(sprite[g_player[p].ps->i].cstat&2)>>1,windowx1,windowy1,windowx2,windowy2); 0,windowx1,windowy1,windowx2,windowy2);
} }
} }
} }
@ -4493,8 +4513,8 @@ void G_DisplayRest(int32_t smoothratio)
{ {
if (ud.screen_size > 0) a = 147; if (ud.screen_size > 0) a = 147;
else a = 179; else a = 179;
minitext(5,a+6,EpisodeNames[ud.volume_number],0,2+8+16); minitext(5,a+6,EpisodeNames[ud.volume_number],0,2+8+16+256);
minitext(5,a+6+6,MapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name,0,2+8+16); minitext(5,a+6+6,MapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name,0,2+8+16+256);
} }
} }
} }
@ -4783,7 +4803,7 @@ void G_DrawBackground(void)
for (x=0; x<xdim; x+=tilesizx[aGameVars[g_iReturnVarID].val.lValue]) for (x=0; x<xdim; x+=tilesizx[aGameVars[g_iReturnVarID].val.lValue])
rotatesprite(x<<16,y<<16,65536L,0,aGameVars[g_iReturnVarID].val.lValue,bpp==8?16:8,0,8+16+64,0,0,xdim-1,ydim-1); rotatesprite(x<<16,y<<16,65536L,0,aGameVars[g_iReturnVarID].val.lValue,bpp==8?16:8,0,8+16+64,0,0,xdim-1,ydim-1);
} }
else rotatesprite(320<<15,200<<15,65536L,0,aGameVars[g_iReturnVarID].val.lValue,bpp==8?16:8,0,2+8+64,0,0,xdim-1,ydim-1); else rotatesprite(320<<15,200<<15,65536L,0,aGameVars[g_iReturnVarID].val.lValue,bpp==8?16:8,0,2+8+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
return; return;
} }
@ -4812,7 +4832,7 @@ void G_DrawBackground(void)
} }
// draw in the bits to the left and right of the non-fullsize status bar // draw in the bits to the left and right of the non-fullsize status bar
if (ud.statusbarscale < 100 && ud.screen_size >= 8 && ud.statusbarmode == 0) if (ud.screen_size >= 8 && ud.statusbarmode == 0)
{ {
/* /*
y1 = y2; y1 = y2;
@ -4827,7 +4847,7 @@ void G_DrawBackground(void)
} }
*/ */
// when not rendering a game, fullscreen wipe // when not rendering a game, fullscreen wipe
x2 = (xdim - scale(xdim,ud.statusbarscale,100)) >> 1; x2 = (xdim - scale((int32_t)(ydim*1.333333333333333333f),ud.statusbarscale,100)) >> 1;
for (y=y2-y2%tilesizy[dapicnum]; y<ydim; y+=tilesizy[dapicnum]) for (y=y2-y2%tilesizy[dapicnum]; y<ydim; y+=tilesizy[dapicnum])
for (x=0; x<xdim>>1; x+=tilesizx[dapicnum]) for (x=0; x<xdim>>1; x+=tilesizx[dapicnum])
{ {
@ -5071,7 +5091,7 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio)
else else
{ {
i = divscale22(1,sprite[p->i].yrepeat+28); i = divscale22(1,sprite[p->i].yrepeat+28);
if (i != oyrepeat) // if (i != oyrepeat)
{ {
oyrepeat = i; oyrepeat = i;
setaspect(oyrepeat,yxaspect); setaspect(oyrepeat,yxaspect);
@ -9208,9 +9228,23 @@ GAME_STATIC void G_HandleLocalKeys(void)
inputloc = 0; inputloc = 0;
} }
if (KB_UnBoundKeyPressed(sc_F1) || (ud.show_help && (KB_KeyPressed(sc_Space) || KB_KeyPressed(sc_Enter) || KB_KeyPressed(sc_kpad_Enter) || MOUSE_GetButtons()&LEFT_MOUSE))) if (KB_UnBoundKeyPressed(sc_F1)/* || (ud.show_help && (KB_KeyPressed(sc_Space) || KB_KeyPressed(sc_Enter) || KB_KeyPressed(sc_kpad_Enter) || MOUSE_GetButtons()&LEFT_MOUSE))*/)
{ {
KB_ClearKeyDown(sc_F1); KB_ClearKeyDown(sc_F1);
ChangeToMenu(400);
FX_StopAllSounds();
S_ClearSoundLocks();
g_player[myconnectindex].ps->gm |= MODE_MENU;
if ((!g_netServer && ud.multimode < 2))
{
ready2send = 0;
totalclock = ototalclock;
screenpeek = myconnectindex;
}
/*
KB_ClearKeyDown(sc_Space); KB_ClearKeyDown(sc_Space);
KB_ClearKeyDown(sc_kpad_Enter); KB_ClearKeyDown(sc_kpad_Enter);
KB_ClearKeyDown(sc_Enter); KB_ClearKeyDown(sc_Enter);
@ -9232,6 +9266,7 @@ GAME_STATIC void G_HandleLocalKeys(void)
totalclock = ototalclock; totalclock = ototalclock;
} }
} }
*/
} }
// if((!net_server && ud.multimode < 2)) // if((!net_server && ud.multimode < 2))
@ -10081,7 +10116,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
address.host = ENET_HOST_ANY; address.host = ENET_HOST_ANY;
address.port = g_netPort; address.port = g_netPort;
g_netServer = enet_host_create(&address, MAXPLAYERS, 0, 0); g_netServer = enet_host_create(&address, MAXPLAYERS, CHAN_MAX, 0, 0);
if (g_netServer == NULL) if (g_netServer == NULL)
initprintf("An error occurred while trying to create an ENet server host.\n"); initprintf("An error occurred while trying to create an ENet server host.\n");
@ -10480,13 +10515,13 @@ static void G_DisplayLogo(void)
P_SetGamePalette(g_player[myconnectindex].ps, drealms, 11); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, drealms, 11); // JBF 20040308
fadepal(0,0,0, 0,64,7); fadepal(0,0,0, 0,64,7);
flushperms(); flushperms();
rotatesprite(0,0,65536L,0,DREALMS,0,0,2+8+16, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,DREALMS,0,0,2+8+16+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
nextpage(); nextpage();
fadepaltile(0,0,0, 63,0,-7,DREALMS); fadepaltile(0,0,0, 63,0,-7,DREALMS);
totalclock = 0; totalclock = 0;
while (totalclock < (120*7) && !KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open)) while (totalclock < (120*7) && !KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open))
{ {
rotatesprite(0,0,65536L,0,DREALMS,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,DREALMS,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
handleevents(); handleevents();
Net_GetPackets(); Net_GetPackets();
if (g_restorePalette) if (g_restorePalette)
@ -10517,7 +10552,7 @@ static void G_DisplayLogo(void)
while (totalclock < (860+120) && !KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open)) while (totalclock < (860+120) && !KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open))
{ {
rotatesprite(0,0,65536L,0,BETASCREEN,0,0,2+8+16+64,0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,BETASCREEN,0,0,2+8+16+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (logoflags & LOGO_DUKENUKEM) if (logoflags & LOGO_DUKENUKEM)
{ {
if (totalclock > 120 && totalclock < (120+60)) if (totalclock > 120 && totalclock < (120+60))
@ -11084,7 +11119,7 @@ void app_main(int32_t argc,const char **argv)
int32_t i = 0, j; int32_t i = 0, j;
char cwd[BMAX_PATH]; char cwd[BMAX_PATH];
// extern char datetimestring[]; // extern char datetimestring[];
ENetCallbacks callbacks = { Bmalloc, Bfree, NULL, NULL }; ENetCallbacks callbacks = { Bmalloc, Bfree, NULL };
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN
if (argc > 1) if (argc > 1)
@ -11714,7 +11749,7 @@ CLEAN_DIRECTORY:
//g_player[myconnectindex].ps->palette = palette; //g_player[myconnectindex].ps->palette = palette;
//G_FadePalette(0,0,0,0); //G_FadePalette(0,0,0,0);
P_SetGamePalette(g_player[myconnectindex].ps, palette, 0); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 0); // JBF 20040308
rotatesprite(320<<15,200<<15,65536L,0,LOADSCREEN,0,0,2+8+64,0,0,xdim-1,ydim-1); rotatesprite(320<<15,200<<15,65536L,0,LOADSCREEN,0,0,2+8+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
menutext(160,105,0,0,"LOADING SAVED GAME..."); menutext(160,105,0,0,"LOADING SAVED GAME...");
nextpage(); nextpage();
@ -11909,7 +11944,6 @@ MAIN_LOOP_RESTART:
G_DisplayRest(i); G_DisplayRest(i);
if (getrendermode() >= 3) if (getrendermode() >= 3)
G_DrawBackground(); G_DrawBackground();
S_Update();
framewaiting++; framewaiting++;
} }
@ -12764,7 +12798,7 @@ static void G_DoOrderScreen(void)
//g_player[myconnectindex].ps->palette = palette; //g_player[myconnectindex].ps->palette = palette;
P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 1); // JBF 20040308
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,ORDERING,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,ORDERING,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-7); fadepal(0,0,0, 63,0,-7);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -12774,7 +12808,7 @@ static void G_DoOrderScreen(void)
fadepal(0,0,0, 0,63,7); fadepal(0,0,0, 0,63,7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,ORDERING+1,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,ORDERING+1,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-7); fadepal(0,0,0, 63,0,-7);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -12784,7 +12818,7 @@ static void G_DoOrderScreen(void)
fadepal(0,0,0, 0,63,7); fadepal(0,0,0, 0,63,7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,ORDERING+2,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,ORDERING+2,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-7); fadepal(0,0,0, 63,0,-7);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -12794,7 +12828,7 @@ static void G_DoOrderScreen(void)
fadepal(0,0,0, 0,63,7); fadepal(0,0,0, 0,63,7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
rotatesprite(0,0,65536L,0,ORDERING+3,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,ORDERING+3,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-7); fadepal(0,0,0, 63,0,-7);
while (!KB_KeyWaiting()) while (!KB_KeyWaiting())
{ {
@ -12839,7 +12873,12 @@ void G_BonusScreen(int32_t bonusonly)
if (!lastmapname) lastmapname = Bstrrchr(boardfilename,'/'); if (!lastmapname) lastmapname = Bstrrchr(boardfilename,'/');
if (!lastmapname) lastmapname = boardfilename; if (!lastmapname) lastmapname = boardfilename;
} }
else lastmapname = MapInfo[(ud.volume_number*MAXLEVELS)+ud.last_level-1].name; else
{
lastmapname = MapInfo[(ud.volume_number*MAXLEVELS)+ud.last_level-1].name;
if (!lastmapname) // this isn't right but it's better than no name at all
lastmapname = MapInfo[(ud.m_volume_number*MAXLEVELS)+ud.last_level-1].name;
}
bonuscnt = 0; bonuscnt = 0;
@ -12864,7 +12903,7 @@ void G_BonusScreen(int32_t bonusonly)
{ {
P_SetGamePalette(g_player[myconnectindex].ps, endingpal, 11); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, endingpal, 11); // JBF 20040308
clearview(0L); clearview(0L);
rotatesprite(0,50<<16,65536L,0,VICTORY1,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(0,50<<16,65536L,0,VICTORY1,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
nextpage(); nextpage();
//g_player[myconnectindex].ps->palette = endingpal; //g_player[myconnectindex].ps->palette = endingpal;
fadepal(0,0,0, 63,0,-1); fadepal(0,0,0, 63,0,-1);
@ -12875,7 +12914,7 @@ void G_BonusScreen(int32_t bonusonly)
while (1) while (1)
{ {
clearview(0L); clearview(0L);
rotatesprite(0,50<<16,65536L,0,VICTORY1,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(0,50<<16,65536L,0,VICTORY1,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
// boss // boss
if (totalclock > 390 && totalclock < 780) if (totalclock > 390 && totalclock < 780)
@ -12887,7 +12926,7 @@ void G_BonusScreen(int32_t bonusonly)
S_PlaySound(SQUISHED); S_PlaySound(SQUISHED);
bonuscnt++; bonuscnt++;
} }
rotatesprite(bossmove[t+3]<<16,bossmove[t+4]<<16,65536L,0,bossmove[t+2],0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(bossmove[t+3]<<16,bossmove[t+4]<<16,65536L,0,bossmove[t+2],0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
} }
// Breathe // Breathe
@ -12895,7 +12934,7 @@ void G_BonusScreen(int32_t bonusonly)
{ {
if (totalclock >= 750) if (totalclock >= 750)
{ {
rotatesprite(86<<16,59<<16,65536L,0,VICTORY1+8,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(86<<16,59<<16,65536L,0,VICTORY1+8,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (totalclock >= 750 && bonuscnt == 2) if (totalclock >= 750 && bonuscnt == 2)
{ {
S_PlaySound(DUKETALKTOBOSS); S_PlaySound(DUKETALKTOBOSS);
@ -12911,7 +12950,7 @@ void G_BonusScreen(int32_t bonusonly)
S_PlaySound(BOSSTALKTODUKE); S_PlaySound(BOSSTALKTODUKE);
bonuscnt++; bonuscnt++;
} }
rotatesprite(breathe[t+3]<<16,breathe[t+4]<<16,65536L,0,breathe[t+2],0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(breathe[t+3]<<16,breathe[t+4]<<16,65536L,0,breathe[t+2],0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
} }
} }
handleevents(); handleevents();
@ -12927,7 +12966,7 @@ void G_BonusScreen(int32_t bonusonly)
//g_player[myconnectindex].ps->palette = palette; //g_player[myconnectindex].ps->palette = palette;
P_SetGamePalette(g_player[myconnectindex].ps, palette, 11); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 11); // JBF 20040308
rotatesprite(0,0,65536L,0,3292,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,3292,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-1); fadepal(0,0,0, 63,0,-1);
while (!KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open)) while (!KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open))
{ {
@ -12959,7 +12998,7 @@ void G_BonusScreen(int32_t bonusonly)
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
//g_player[myconnectindex].ps->palette = palette; //g_player[myconnectindex].ps->palette = palette;
P_SetGamePalette(g_player[myconnectindex].ps, palette, 11); // JBF 20040308 P_SetGamePalette(g_player[myconnectindex].ps, palette, 11); // JBF 20040308
rotatesprite(0,0,65536L,0,3293,0,0,2+8+16+64, 0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,3293,0,0,2+8+16+64+(ud.bgstretch?1024:0), 0,0,xdim-1,ydim-1);
fadepal(0,0,0, 63,0,-1); fadepal(0,0,0, 63,0,-1);
while (!KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open)) while (!KB_KeyWaiting() && !MOUSE_GetButtons()&LEFT_MOUSE && !BUTTON(gamefunc_Fire) && !BUTTON(gamefunc_Open))
{ {
@ -13144,7 +13183,7 @@ FRAGBONUS:
if (!(ud.config.MusicToggle == 0 || ud.config.MusicDevice < 0)) if (!(ud.config.MusicToggle == 0 || ud.config.MusicDevice < 0))
S_PlaySound(BONUSMUSIC); S_PlaySound(BONUSMUSIC);
rotatesprite(0,0,65536L,0,MENUSCREEN,16,0,2+8+16+64,0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,MENUSCREEN,16,0,2+8+16+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
rotatesprite(160<<16,34<<16,65536L,0,INGAMEDUKETHREEDEE,0,0,10,0,0,xdim-1,ydim-1); rotatesprite(160<<16,34<<16,65536L,0,INGAMEDUKETHREEDEE,0,0,10,0,0,xdim-1,ydim-1);
if (PLUTOPAK) // JBF 20030804 if (PLUTOPAK) // JBF 20030804
rotatesprite((260)<<16,36<<16,65536L,0,PLUTOPAKSPRITE+2,0,0,2+8,0,0,xdim-1,ydim-1); rotatesprite((260)<<16,36<<16,65536L,0,PLUTOPAKSPRITE+2,0,0,2+8,0,0,xdim-1,ydim-1);
@ -13245,8 +13284,9 @@ FRAGBONUS:
break; break;
} }
rotatesprite(0,0,65536L,0,BONUSSCREEN+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,BONUSSCREEN+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (lastmapname)
menutext(160,20-6,0,0,lastmapname); menutext(160,20-6,0,0,lastmapname);
menutext(160,36-6,0,0,"COMPLETED"); menutext(160,36-6,0,0,"COMPLETED");
@ -13300,7 +13340,7 @@ FRAGBONUS:
if (g_player[myconnectindex].ps->gm&MODE_EOL) if (g_player[myconnectindex].ps->gm&MODE_EOL)
{ {
rotatesprite(0,0,65536L,0,BONUSSCREEN+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(0,0,65536L,0,BONUSSCREEN+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (totalclock > (1000000000L) && totalclock < (1000000320L)) if (totalclock > (1000000000L) && totalclock < (1000000320L))
{ {
@ -13330,11 +13370,11 @@ FRAGBONUS:
case 1: case 1:
case 4: case 4:
case 5: case 5:
rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+3+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+3+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
break; break;
case 2: case 2:
case 3: case 3:
rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+4+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+4+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
break; break;
} }
} }
@ -13345,14 +13385,15 @@ FRAGBONUS:
{ {
case 1: case 1:
case 3: case 3:
rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+1+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+1+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
break; break;
case 2: case 2:
rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+2+gfx_offset,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1); rotatesprite(199<<16,31<<16,65536L,0,BONUSSCREEN+2+gfx_offset,0,0,2+8+16+64+128+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
break; break;
} }
} }
if (lastmapname)
menutext(160,20-6,0,0,lastmapname); menutext(160,20-6,0,0,lastmapname);
menutext(160,36-6,0,0,"COMPLETED"); menutext(160,36-6,0,0,"COMPLETED");

View file

@ -3868,7 +3868,7 @@ static int32_t C_ParseCommand(void)
g_scriptPtr--; g_scriptPtr--;
if (g_dynamicTileMapping++) if (g_dynamicTileMapping++)
{ {
initprintf("%s:%d: warning: duplicate g_dynamicTileMapping statement\n",g_szScriptFileName,g_lineNumber); initprintf("%s:%d: warning: duplicate dynamicremap statement\n",g_szScriptFileName,g_lineNumber);
g_numCompilerWarnings++; g_numCompilerWarnings++;
} }
else initprintf("Using dynamic tile remapping\n"); else initprintf("Using dynamic tile remapping\n");

View file

@ -2359,13 +2359,13 @@ nullquote:
int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++);
int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++);
if (tw == CON_ROTATESPRITE && !(orientation & 256)) if (tw == CON_ROTATESPRITE)
{ {
x<<=16; x<<=16;
y<<=16; y<<=16;
} }
if (x < (-160)<<16 || x >= (480<<16) || y < (-100)<<16 || y >= (300<<16)) if (x < (-320)<<16 || x >= (640<<16) || y < (-200)<<16 || y >= (400<<16))
{ {
OSD_Printf(CON_ERROR "invalid coordinates: %d, %d\n",g_errorLineNum, keyw[g_tw], x, y); OSD_Printf(CON_ERROR "invalid coordinates: %d, %d\n",g_errorLineNum, keyw[g_tw], x, y);
continue; continue;
@ -2748,7 +2748,7 @@ nullquote:
{ {
curtime = time(NULL); curtime = time(NULL);
Bstrcpy(tempbuf,asctime(localtime(&curtime))); Bstrcpy(tempbuf,asctime(localtime(&curtime)));
clearbuf(ud.savegame[g_lastSaveSlot],sizeof(ud.savegame[g_lastSaveSlot]),0); clearbufbyte(ud.savegame[g_lastSaveSlot],sizeof(ud.savegame[g_lastSaveSlot]),0);
Bsprintf(ud.savegame[g_lastSaveSlot],"Auto"); Bsprintf(ud.savegame[g_lastSaveSlot],"Auto");
// for (j=0;j<13;j++) // for (j=0;j<13;j++)
// Bmemcpy(&ud.savegame[g_lastSaveSlot][j+4],&tempbuf[j+3],sizeof(tempbuf[j+3])); // Bmemcpy(&ud.savegame[g_lastSaveSlot][j+4],&tempbuf[j+3],sizeof(tempbuf[j+3]));
@ -4601,8 +4601,18 @@ nullquote:
{ {
int32_t j = MAXSOUNDS-1; int32_t j = MAXSOUNDS-1;
for (; j>=0; j--) for (; j>=0; j--)
if (g_sounds[j].SoundOwner[0].i == vm.g_i) {
int32_t k = 0;
for (;k<MAXSOUNDINSTANCES;k++)
{
if (g_sounds[j].SoundOwner[k].i == vm.g_i)
break; break;
}
if (k != MAXSOUNDINSTANCES)
break;
}
VM_DoConditional(j < 0); VM_DoConditional(j < 0);
} }

View file

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "duke3d.h" #include "duke3d.h"
const char *s_buildDate = "20100514"; const char *s_buildDate = "20100617";
char *MusicPtr = NULL; char *MusicPtr = NULL;
int32_t g_musicSize; int32_t g_musicSize;

View file

@ -108,4 +108,7 @@ int32_t FX_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *le
int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
int32_t priority, uint32_t callbackval ); int32_t priority, uint32_t callbackval );
int32_t FX_SetVoiceCallback(int32_t handle, uint32_t callbackval);
int32_t FX_SetPrintf(void (*function)(const char *, ...));
#endif #endif

View file

@ -31,6 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include "driver_directsound.h" #include "driver_directsound.h"
#include "multivoc.h"
enum { enum {
DSErr_Warning = -2, DSErr_Warning = -2,
@ -73,10 +74,10 @@ static HANDLE mutex = 0;
static void FillBufferPortion(char * ptr, int32_t remaining) static void FillBufferPortion(char * ptr, int32_t remaining)
{ {
int32_t len; int32_t len = 0;
char *sptr; char *sptr;
while (remaining > 0) { while (remaining >= len) {
if (MixBufferUsed == MixBufferSize) { if (MixBufferUsed == MixBufferSize) {
MixCallBack(); MixCallBack();
@ -87,7 +88,7 @@ static void FillBufferPortion(char * ptr, int32_t remaining)
} }
} }
while (remaining > 0 && MixBufferUsed < MixBufferSize) { while (remaining >= len && MixBufferUsed < MixBufferSize) {
sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed; sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed;
len = MixBufferSize - MixBufferUsed; len = MixBufferSize - MixBufferUsed;
@ -111,7 +112,7 @@ static void FillBuffer(int32_t bufnum)
DWORD remaining, remaining2; DWORD remaining, remaining2;
int32_t retries = 1; int32_t retries = 1;
//fprintf(stderr, "DirectSound FillBuffer: filling %d\n", bufnum); //initprintf( "DirectSound FillBuffer: filling %d\n", bufnum);
do { do {
err = IDirectSoundBuffer_Lock(lpdsbsec, err = IDirectSoundBuffer_Lock(lpdsbsec,
@ -131,7 +132,8 @@ static void FillBuffer(int32_t bufnum)
continue; continue;
} }
} }
fprintf(stderr, "DirectSound FillBuffer: err %x\n", (uint32_t) err); if (MV_Printf)
MV_Printf("DirectSound FillBuffer: err %x\n", (uint32_t) err);
return; return;
} }
break; break;
@ -149,12 +151,12 @@ static void FillBuffer(int32_t bufnum)
static DWORD WINAPI fillDataThread(LPVOID lpParameter) static DWORD WINAPI fillDataThread(LPVOID lpParameter)
{ {
HANDLE handles[3];
DWORD waitret, waitret2; DWORD waitret, waitret2;
HANDLE handles[] = { handles[0] = notifyPositions[0].hEventNotify,
handles[1] = notifyPositions[1].hEventNotify,
handles[2] = notifyPositions[2].hEventNotify };
handles[0] = notifyPositions[0].hEventNotify; UNREFERENCED_PARAMETER(lpParameter);
handles[1] = notifyPositions[1].hEventNotify;
handles[2] = notifyPositions[2].hEventNotify;
do { do {
waitret = WaitForMultipleObjects(3, handles, FALSE, INFINITE); waitret = WaitForMultipleObjects(3, handles, FALSE, INFINITE);
@ -166,15 +168,17 @@ static DWORD WINAPI fillDataThread(LPVOID lpParameter)
FillBuffer(WAIT_OBJECT_0 + 1 - waitret); FillBuffer(WAIT_OBJECT_0 + 1 - waitret);
ReleaseMutex(mutex); ReleaseMutex(mutex);
} else { } else {
fprintf(stderr, "DirectSound fillDataThread: wfso err %d\n", (int32_t) waitret2); if (MV_Printf)
MV_Printf( "DirectSound fillDataThread: wfso err %d\n", (int32_t) waitret2);
} }
break; break;
case WAIT_OBJECT_0+2: case WAIT_OBJECT_0+2:
fprintf(stderr, "DirectSound fillDataThread: exiting\n"); // initprintf( "DirectSound fillDataThread: exiting\n");
ExitThread(0); ExitThread(0);
break; break;
default: default:
fprintf(stderr, "DirectSound fillDataThread: wfmo err %d\n", (int32_t) waitret); if (MV_Printf)
MV_Printf( "DirectSound fillDataThread: wfmo err %d\n", (int32_t) waitret);
break; break;
} }
} while (1); } while (1);
@ -272,7 +276,8 @@ const char *DirectSoundDrv_ErrorString( int32_t ErrorNumber )
static void TeardownDSound(HRESULT err) static void TeardownDSound(HRESULT err)
{ {
if (FAILED(err)) { if (FAILED(err)) {
fprintf(stderr, "Dying error: %x\n", (uint32_t) err); if (MV_Printf)
MV_Printf( "Dying error: %x\n", (uint32_t) err);
} }
if (lpdsnotify) IDirectSoundNotify_Release(lpdsnotify); if (lpdsnotify) IDirectSoundNotify_Release(lpdsnotify);
@ -404,7 +409,7 @@ int32_t DirectSoundDrv_PCM_Init(int32_t *mixrate, int32_t *numchannels, int32_t
Initialised = 1; Initialised = 1;
fprintf(stderr, "DirectSound Init: yay\n"); // initprintf("DirectSound Init: yay\n");
return DSErr_Ok; return DSErr_Ok;
} }
@ -450,7 +455,7 @@ int32_t DirectSoundDrv_PCM_BeginPlayback(char *BufferStart, int32_t BufferSize,
return DSErr_Error; return DSErr_Error;
} }
SetThreadPriority(mixThread, THREAD_PRIORITY_HIGHEST); SetThreadPriority(mixThread, THREAD_PRIORITY_ABOVE_NORMAL);
err = IDirectSoundBuffer_Play(lpdsbsec, 0, 0, DSBPLAY_LOOPING); err = IDirectSoundBuffer_Play(lpdsbsec, 0, 0, DSBPLAY_LOOPING);
if (FAILED( err )) { if (FAILED( err )) {
@ -481,7 +486,8 @@ void DirectSoundDrv_PCM_Lock(void)
err = WaitForSingleObject(mutex, INFINITE); err = WaitForSingleObject(mutex, INFINITE);
if (err != WAIT_OBJECT_0) { if (err != WAIT_OBJECT_0) {
fprintf(stderr, "DirectSound lock: wfso %d\n", (int32_t) err); if (MV_Printf)
MV_Printf( "DirectSound lock: wfso %d\n", (int32_t) err);
} }
} }

View file

@ -812,13 +812,7 @@ int32_t FX_PlayLoopedRaw
with the specified handle. with the specified handle.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t FX_Pan3D int32_t FX_Pan3D(int32_t handle,int32_t angle,int32_t distance)
(
int32_t handle,
int32_t angle,
int32_t distance
)
{ {
int32_t status; int32_t status;
@ -839,11 +833,7 @@ int32_t FX_Pan3D
Tests if the specified sound is currently playing. Tests if the specified sound is currently playing.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t FX_SoundActive int32_t FX_SoundActive(int32_t handle)
(
int32_t handle
)
{ {
return(MV_VoicePlaying(handle)); return(MV_VoicePlaying(handle));
} }
@ -855,11 +845,7 @@ int32_t FX_SoundActive
Reports the number of voices playing. Reports the number of voices playing.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t FX_SoundsPlaying int32_t FX_SoundsPlaying(void)
(
void
)
{ {
return(MV_VoicesPlaying()); return(MV_VoicesPlaying());
} }
@ -871,11 +857,7 @@ int32_t FX_SoundsPlaying
Halts playback of a specific voice Halts playback of a specific voice
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t FX_StopSound int32_t FX_StopSound(int32_t handle)
(
int32_t handle
)
{ {
int32_t status; int32_t status;
@ -979,7 +961,7 @@ int32_t FX_PlayAuto(char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol
break; break;
} }
if (handle < MV_Ok) if (handle <= MV_Ok)
{ {
FX_SetErrorCode(FX_MultiVocError); FX_SetErrorCode(FX_MultiVocError);
handle = FX_Warning; handle = FX_Warning;
@ -988,6 +970,14 @@ int32_t FX_PlayAuto(char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol
return handle; return handle;
} }
int32_t FX_SetPrintf(void (*function)(const char *, ...))
{
MV_SetPrintf(function);
return FX_Ok;
}
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
Function: FX_PlayLoopedAuto Function: FX_PlayLoopedAuto
@ -1021,7 +1011,7 @@ int32_t FX_PlayLoopedAuto(char *ptr, uint32_t length, int32_t loopstart, int32_t
} }
if (handle < MV_Ok) if (handle <= MV_Ok)
{ {
FX_SetErrorCode(FX_MultiVocError); FX_SetErrorCode(FX_MultiVocError);
handle = FX_Warning; handle = FX_Warning;
@ -1061,7 +1051,7 @@ int32_t FX_PlayAuto3D(char *ptr, uint32_t length, int32_t pitchoffset, int32_t a
break; break;
} }
if (handle < MV_Ok) if (handle <= MV_Ok)
{ {
FX_SetErrorCode(FX_MultiVocError); FX_SetErrorCode(FX_MultiVocError);
handle = FX_Warning; handle = FX_Warning;
@ -1069,3 +1059,17 @@ int32_t FX_PlayAuto3D(char *ptr, uint32_t length, int32_t pitchoffset, int32_t a
return handle; return handle;
} }
int32_t FX_SetVoiceCallback(int32_t handle, uint32_t callbackval)
{
int32_t status;
status = MV_SetVoiceCallback(handle, callbackval);
if (status != MV_Ok)
{
FX_SetErrorCode(FX_MultiVocError);
return(FX_Warning);
}
return(FX_Ok);
}

View file

@ -140,6 +140,7 @@ static volatile VoiceNode VoicePool;
static int32_t MV_MixPage = 0; static int32_t MV_MixPage = 0;
static int32_t MV_VoiceHandle = MV_MinVoiceHandle; static int32_t MV_VoiceHandle = MV_MinVoiceHandle;
void (*MV_Printf)(const char *fmt, ...) = NULL;
static void (*MV_CallBackFunc)(uint32_t) = NULL; static void (*MV_CallBackFunc)(uint32_t) = NULL;
static void (*MV_MixFunction)(VoiceNode *voice, int32_t buffer); static void (*MV_MixFunction)(VoiceNode *voice, int32_t buffer);
@ -157,7 +158,8 @@ uint32_t MV_MixPosition;
int32_t MV_ErrorCode = MV_Ok; int32_t MV_ErrorCode = MV_Ok;
static int32_t lockdepth = 0; static int32_t lockdepth = 0;
static void DisableInterrupts(void)
static inline void DisableInterrupts(void)
{ {
if (lockdepth++ > 0) if (lockdepth++ > 0)
return; return;
@ -165,7 +167,7 @@ static void DisableInterrupts(void)
return; return;
} }
static void RestoreInterrupts(void) static inline void RestoreInterrupts(void)
{ {
if (--lockdepth > 0) if (--lockdepth > 0)
return; return;
@ -180,71 +182,50 @@ static void RestoreInterrupts(void)
number. A -1 returns a pointer the current error. number. A -1 returns a pointer the current error.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
const char *MV_ErrorString const char *MV_ErrorString(int32_t ErrorNumber)
(
int32_t ErrorNumber
)
{ {
const char *ErrorString;
switch (ErrorNumber) switch (ErrorNumber)
{ {
case MV_Warning : case MV_Warning :
case MV_Error : case MV_Error :
ErrorString = MV_ErrorString(MV_ErrorCode); return MV_ErrorString(MV_ErrorCode);
break;
case MV_Ok : case MV_Ok :
ErrorString = "Multivoc ok."; return "Multivoc ok.";
break;
case MV_UnsupportedCard : case MV_UnsupportedCard :
ErrorString = "Selected sound card is not supported by Multivoc."; return "Selected sound card is not supported by Multivoc.";
break;
case MV_NotInstalled : case MV_NotInstalled :
ErrorString = "Multivoc not installed."; return "Multivoc not installed.";
break;
case MV_DriverError : case MV_DriverError :
ErrorString = SoundDriver_ErrorString(SoundDriver_GetError()); return SoundDriver_ErrorString(SoundDriver_GetError());
break;
case MV_NoVoices : case MV_NoVoices :
ErrorString = "No free voices available to Multivoc."; return "No free voices available to Multivoc.";
break;
case MV_NoMem : case MV_NoMem :
ErrorString = "Out of memory in Multivoc."; return "Out of memory in Multivoc.";
break;
case MV_VoiceNotFound : case MV_VoiceNotFound :
ErrorString = "No voice with matching handle found."; return "No voice with matching handle found.";
break;
case MV_InvalidVOCFile : case MV_InvalidVOCFile :
ErrorString = "Invalid VOC file passed in to Multivoc."; return "Invalid VOC file passed in to Multivoc.";
break;
case MV_InvalidWAVFile : case MV_InvalidWAVFile :
ErrorString = "Invalid WAV file passed in to Multivoc."; return "Invalid WAV file passed in to Multivoc.";
break;
case MV_InvalidVorbisFile : case MV_InvalidVorbisFile :
ErrorString = "Invalid OggVorbis file passed in to Multivoc."; return "Invalid OggVorbis file passed in to Multivoc.";
break;
case MV_InvalidMixMode : case MV_InvalidMixMode :
ErrorString = "Invalid mix mode request in Multivoc."; return "Invalid mix mode request in Multivoc.";
break;
default : default :
ErrorString = "Unknown Multivoc error code."; return "Unknown Multivoc error code.";
break;
} }
return(ErrorString);
} }
@ -254,12 +235,7 @@ const char *MV_ErrorString
Mixes the sound into the buffer. Mixes the sound into the buffer.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
static void MV_Mix static void MV_Mix(VoiceNode *voice,int32_t buffer)
(
VoiceNode *voice,
int32_t buffer
)
{ {
char *start; char *start;
int32_t length; int32_t length;
@ -308,14 +284,10 @@ static void MV_Mix
} }
} }
else else
{
voclength = length; voclength = length;
}
if (voice->mix) if (voice->mix)
{
voice->mix(position, rate, start, voclength); voice->mix(position, rate, start, voclength);
}
voice->position = MV_MixPosition; voice->position = MV_MixPosition;
@ -325,9 +297,7 @@ static void MV_Mix
{ {
// Get the next block of sound // Get the next block of sound
if (voice->GetSound(voice) != KeepPlaying) if (voice->GetSound(voice) != KeepPlaying)
{
return; return;
}
if (length > (voice->channels - 1)) if (length > (voice->channels - 1))
{ {
@ -345,16 +315,10 @@ static void MV_Mix
Adds a voice to the play list. Adds a voice to the play list.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
void MV_PlayVoice void MV_PlayVoice(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
DisableInterrupts(); DisableInterrupts();
LL_SortedInsertion(&VoiceList, voice, prev, next, VoiceNode, priority); LL_SortedInsertion(&VoiceList, voice, prev, next, VoiceNode, priority);
RestoreInterrupts(); RestoreInterrupts();
} }
@ -365,11 +329,7 @@ void MV_PlayVoice
Removes the voice from the play list and adds it to the free list. Removes the voice from the play list and adds it to the free list.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
void MV_StopVoice void MV_StopVoice(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
DisableInterrupts(); DisableInterrupts();
@ -380,9 +340,9 @@ void MV_StopVoice
RestoreInterrupts(); RestoreInterrupts();
if (voice->wavetype == Vorbis) if (voice->wavetype == Vorbis)
{
MV_ReleaseVorbisVoice(voice); MV_ReleaseVorbisVoice(voice);
}
voice->handle = 0;
} }
@ -403,22 +363,16 @@ void MV_StopVoice
MV_GetNextWAVBlock MV_GetNextWAVBlock
MV_SetVoiceMixMode MV_SetVoiceMixMode
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
void MV_ServiceVoc void MV_ServiceVoc(void)
(
void
)
{ {
VoiceNode *voice; VoiceNode *voice;
VoiceNode *next; VoiceNode *next;
//int32_t flags; //int32_t flags;
int32_t iter;
// Toggle which buffer we'll mix next // Toggle which buffer we'll mix next
MV_MixPage++; if (++MV_MixPage >= MV_NumberOfBuffers)
if (MV_MixPage >= MV_NumberOfBuffers)
{
MV_MixPage -= MV_NumberOfBuffers; MV_MixPage -= MV_NumberOfBuffers;
}
if (MV_ReverbLevel == 0) if (MV_ReverbLevel == 0)
{ {
@ -443,42 +397,31 @@ void MV_ServiceVoc
end = MV_MixBuffer[ 0 ] + MV_BufferLength;; end = MV_MixBuffer[ 0 ] + MV_BufferLength;;
dest = MV_MixBuffer[ MV_MixPage ]; dest = MV_MixBuffer[ MV_MixPage ];
source = MV_MixBuffer[ MV_MixPage ] - MV_ReverbDelay; source = MV_MixBuffer[ MV_MixPage ] - MV_ReverbDelay;
if (source < MV_MixBuffer[ 0 ]) if (source < MV_MixBuffer[ 0 ])
{
source += MV_BufferLength; source += MV_BufferLength;
}
length = MV_BufferSize; length = MV_BufferSize;
while (length > 0) while (length > 0)
{ {
count = length; count = length;
if (source + count > end) if (source + count > end)
{
count = end - source; count = end - source;
}
if (MV_Bits == 16) if (MV_Bits == 16)
{ {
if (MV_ReverbTable != NULL) if (MV_ReverbTable != NULL)
{
MV_16BitReverb(source, dest, MV_ReverbTable, count / 2); MV_16BitReverb(source, dest, MV_ReverbTable, count / 2);
}
else else
{
MV_16BitReverbFast(source, dest, count / 2, MV_ReverbLevel); MV_16BitReverbFast(source, dest, count / 2, MV_ReverbLevel);
} }
}
else else
{ {
if (MV_ReverbTable != NULL) if (MV_ReverbTable != NULL)
{
MV_8BitReverb((int8_t *) source, (int8_t *) dest, MV_ReverbTable, count); MV_8BitReverb((int8_t *) source, (int8_t *) dest, MV_ReverbTable, count);
}
else else
{
MV_8BitReverbFast((int8_t *) source, (int8_t *) dest, count, MV_ReverbLevel); MV_8BitReverbFast((int8_t *) source, (int8_t *) dest, count, MV_ReverbLevel);
} }
}
// if we go through the loop again, it means that we've wrapped around the buffer // if we go through the loop again, it means that we've wrapped around the buffer
source = MV_MixBuffer[ 0 ]; source = MV_MixBuffer[ 0 ];
@ -493,9 +436,15 @@ void MV_ServiceVoc
if (!VoiceList.next || (voice = VoiceList.next) == &VoiceList) if (!VoiceList.next || (voice = VoiceList.next) == &VoiceList)
return; return;
iter = 0;
do do
{ {
next = voice->next; next = voice->next;
iter++;
if (iter > MV_MaxVoices && MV_Printf)
MV_Printf("more iterations than voices! iter: %d\n",iter);
if (voice->Paused) if (voice->Paused)
continue; continue;
@ -515,6 +464,8 @@ void MV_ServiceVoc
if (voice->wavetype == Vorbis) if (voice->wavetype == Vorbis)
MV_ReleaseVorbisVoice(voice); MV_ReleaseVorbisVoice(voice);
voice->handle = 0;
if (MV_CallBackFunc) if (MV_CallBackFunc)
MV_CallBackFunc(voice->callbackval); MV_CallBackFunc(voice->callbackval);
} }
@ -531,11 +482,7 @@ void MV_ServiceVoc
Interpret the information of a VOC format sound file. Interpret the information of a VOC format sound file.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
playbackstatus MV_GetNextVOCBlock playbackstatus MV_GetNextVOCBlock(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
uint8_t *ptr; uint8_t *ptr;
int32_t blocktype; int32_t blocktype;
@ -756,13 +703,9 @@ playbackstatus MV_GetNextVOCBlock
if (voice->LoopEnd != NULL) if (voice->LoopEnd != NULL)
{ {
if (blocklength > (uint32_t)voice->LoopEnd) if (blocklength > (uint32_t)voice->LoopEnd)
{
blocklength = (uint32_t)voice->LoopEnd; blocklength = (uint32_t)voice->LoopEnd;
}
else else
{
voice->LoopEnd = (char *)blocklength; voice->LoopEnd = (char *)blocklength;
}
voice->LoopStart = voice->sound + (uint32_t)voice->LoopStart; voice->LoopStart = voice->sound + (uint32_t)voice->LoopStart;
voice->LoopEnd = voice->sound + (uint32_t)voice->LoopEnd; voice->LoopEnd = voice->sound + (uint32_t)voice->LoopEnd;
@ -770,13 +713,10 @@ playbackstatus MV_GetNextVOCBlock
} }
if (voice->bits == 16) if (voice->bits == 16)
{
blocklength /= 2; blocklength /= 2;
}
if (voice->channels == 2) if (voice->channels == 2)
{
blocklength /= 2; blocklength /= 2;
}
voice->position = 0; voice->position = 0;
voice->length = min(blocklength, 0x8000); voice->length = min(blocklength, 0x8000);
@ -798,11 +738,7 @@ playbackstatus MV_GetNextVOCBlock
Controls playback of demand fed data. Controls playback of demand fed data.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
playbackstatus MV_GetNextDemandFeedBlock playbackstatus MV_GetNextDemandFeedBlock(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
if (voice->BlockLength > 0) if (voice->BlockLength > 0)
{ {
@ -816,9 +752,7 @@ playbackstatus MV_GetNextDemandFeedBlock
} }
if (voice->DemandFeed == NULL) if (voice->DemandFeed == NULL)
{
return(NoMoreData); return(NoMoreData);
}
voice->position = 0; voice->position = 0;
(voice->DemandFeed)(&voice->sound, &voice->BlockLength); (voice->DemandFeed)(&voice->sound, &voice->BlockLength);
@ -826,11 +760,7 @@ playbackstatus MV_GetNextDemandFeedBlock
voice->BlockLength -= voice->length; voice->BlockLength -= voice->length;
voice->length <<= 16; voice->length <<= 16;
if ((voice->length > 0) && (voice->sound != NULL)) return((voice->length > 0) && (voice->sound != NULL) ? KeepPlaying : NoMoreData);
{
return(KeepPlaying);
}
return(NoMoreData);
} }
@ -840,11 +770,7 @@ playbackstatus MV_GetNextDemandFeedBlock
Controls playback of demand fed data. Controls playback of demand fed data.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
playbackstatus MV_GetNextRawBlock playbackstatus MV_GetNextRawBlock(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
if (voice->BlockLength <= 0) if (voice->BlockLength <= 0)
{ {
@ -877,11 +803,7 @@ playbackstatus MV_GetNextRawBlock
Controls playback of demand fed data. Controls playback of demand fed data.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
playbackstatus MV_GetNextWAVBlock playbackstatus MV_GetNextWAVBlock(VoiceNode *voice)
(
VoiceNode *voice
)
{ {
if (voice->BlockLength <= 0) if (voice->BlockLength <= 0)
{ {
@ -914,33 +836,31 @@ playbackstatus MV_GetNextWAVBlock
Locates the voice with the specified handle. Locates the voice with the specified handle.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
VoiceNode *MV_GetVoice VoiceNode *MV_GetVoice(int32_t handle)
(
int32_t handle
)
{ {
VoiceNode *voice; VoiceNode *voice;
if (handle < MV_MinVoiceHandle || handle > MV_MaxVoices)
{
if (MV_Printf)
MV_Printf("MV_GetVoice(): bad handle (%d)!\n", handle);
return NULL;
}
DisableInterrupts(); DisableInterrupts();
for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next) for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next)
{ {
if (handle == voice->handle) if (handle == voice->handle)
{ {
break; RestoreInterrupts();
return voice;
} }
} }
RestoreInterrupts(); RestoreInterrupts();
if (voice == &VoiceList)
{
MV_SetErrorCode(MV_VoiceNotFound); MV_SetErrorCode(MV_VoiceNotFound);
voice = 0; return NULL;
}
return(voice);
} }
@ -951,28 +871,15 @@ VoiceNode *MV_GetVoice
playing. playing.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t MV_VoicePlaying int32_t MV_VoicePlaying(int32_t handle)
(
int32_t handle
)
{ {
VoiceNode *voice;
if (!MV_Installed) if (!MV_Installed)
{ {
MV_SetErrorCode(MV_NotInstalled); MV_SetErrorCode(MV_NotInstalled);
return(FALSE); return(FALSE);
} }
voice = MV_GetVoice(handle); return MV_GetVoice(handle) ? TRUE : FALSE;
if (voice == NULL)
{
return(FALSE);
}
return(TRUE);
} }
@ -982,13 +889,9 @@ int32_t MV_VoicePlaying
Stops output of all currently active voices. Stops output of all currently active voices.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t MV_KillAllVoices int32_t MV_KillAllVoices(void)
(
void
)
{ {
VoiceNode * voice = VoiceList.prev; VoiceNode * voice;
if (!MV_Installed) if (!MV_Installed)
{ {
@ -996,11 +899,16 @@ int32_t MV_KillAllVoices
return(MV_Error); return(MV_Error);
} }
if (&VoiceList == VoiceList.next)
return(MV_Ok);
DisableInterrupts(); DisableInterrupts();
if (&VoiceList == VoiceList.next)
{
RestoreInterrupts();
return(MV_Ok);
}
voice = VoiceList.prev;
// Remove all the voices from the list // Remove all the voices from the list
while (voice != &VoiceList) while (voice != &VoiceList)
{ {
@ -1026,11 +934,7 @@ int32_t MV_KillAllVoices
Stops output of the voice associated with the specified handle. Stops output of the voice associated with the specified handle.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t MV_Kill int32_t MV_Kill(int32_t handle)
(
int32_t handle
)
{ {
VoiceNode *voice; VoiceNode *voice;
uint32_t callbackval; uint32_t callbackval;
@ -1043,8 +947,7 @@ int32_t MV_Kill
DisableInterrupts(); DisableInterrupts();
voice = MV_GetVoice(handle); if ((voice = MV_GetVoice(handle)) == NULL)
if (voice == NULL)
{ {
RestoreInterrupts(); RestoreInterrupts();
MV_SetErrorCode(MV_VoiceNotFound); MV_SetErrorCode(MV_VoiceNotFound);
@ -1058,9 +961,7 @@ int32_t MV_Kill
RestoreInterrupts(); RestoreInterrupts();
if (MV_CallBackFunc) if (MV_CallBackFunc)
{
MV_CallBackFunc(callbackval); MV_CallBackFunc(callbackval);
}
return(MV_Ok); return(MV_Ok);
} }
@ -1072,11 +973,7 @@ int32_t MV_Kill
Determines the number of currently active voices. Determines the number of currently active voices.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t MV_VoicesPlaying int32_t MV_VoicesPlaying(void)
(
void
)
{ {
VoiceNode *voice; VoiceNode *voice;
int32_t NumVoices = 0; int32_t NumVoices = 0;
@ -1090,9 +987,7 @@ int32_t MV_VoicesPlaying
DisableInterrupts(); DisableInterrupts();
for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next) for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next)
{
NumVoices++; NumVoices++;
}
RestoreInterrupts(); RestoreInterrupts();
@ -1106,11 +1001,7 @@ int32_t MV_VoicesPlaying
Retrieve an inactive or lower priority voice for output. Retrieve an inactive or lower priority voice for output.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
VoiceNode *MV_AllocVoice VoiceNode *MV_AllocVoice(int32_t priority)
(
int32_t priority
)
{ {
VoiceNode *voice; VoiceNode *voice;
VoiceNode *node; VoiceNode *node;
@ -1125,87 +1016,72 @@ VoiceNode *MV_AllocVoice
for (node = voice->next; node != &VoiceList; node = node->next) for (node = voice->next; node != &VoiceList; node = node->next)
{ {
if (node->priority < voice->priority) if (node->priority < voice->priority)
{
voice = node; voice = node;
} }
}
if (priority >= voice->priority) if (priority >= voice->priority && voice->handle > MV_Ok)
{
MV_Kill(voice->handle); MV_Kill(voice->handle);
}
}
// Check if any voices are in the voice pool
if (LL_Empty(&VoicePool, next, prev)) if (LL_Empty(&VoicePool, next, prev))
{ {
// No free voices // No free voices
RestoreInterrupts(); RestoreInterrupts();
return(NULL); return NULL;
}
} }
voice = VoicePool.next; voice = VoicePool.next;
LL_Remove(voice, next, prev); LL_Remove(voice, next, prev);
RestoreInterrupts(); RestoreInterrupts();
MV_VoiceHandle = MV_MinVoiceHandle;
// Find a free voice handle // Find a free voice handle
do do
{ {
MV_VoiceHandle++; if (++MV_VoiceHandle < MV_MinVoiceHandle || MV_VoiceHandle > MV_MaxVoices)
if (MV_VoiceHandle < MV_MinVoiceHandle)
{
MV_VoiceHandle = MV_MinVoiceHandle; MV_VoiceHandle = MV_MinVoiceHandle;
} }
}
while (MV_VoicePlaying(MV_VoiceHandle)); while (MV_VoicePlaying(MV_VoiceHandle));
voice->handle = MV_VoiceHandle; voice->handle = MV_VoiceHandle;
return(voice); return voice;
} }
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
Function: MV_VoiceAvailable Function: MV_VoiceAvailable
Checks if a voice can be play at the specified priority. Checks if a voice can be played at the specified priority.
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
int32_t MV_VoiceAvailable int32_t MV_VoiceAvailable(int32_t priority)
(
int32_t priority
)
{ {
VoiceNode *voice; VoiceNode *voice;
VoiceNode *node; VoiceNode *node;
// Check if we have any free voices // Check if we have any free voices
if (!LL_Empty(&VoicePool, next, prev)) if (!LL_Empty(&VoicePool, next, prev))
{ return TRUE;
return(TRUE);
}
DisableInterrupts(); DisableInterrupts();
// check if we have a higher priority than a voice that is playing. // check if we have a higher priority than a voice that is playing.
voice = VoiceList.next; for (voice = node = VoiceList.next; node != &VoiceList; node = node->next)
for (node = VoiceList.next; node != &VoiceList; node = node->next)
{ {
if (node->priority < voice->priority) if (node->priority < voice->priority)
{
voice = node; voice = node;
} }
}
RestoreInterrupts();
if ((voice != &VoiceList) && (priority >= voice->priority)) if ((voice != &VoiceList) && (priority >= voice->priority))
{ {
return(TRUE); RestoreInterrupts();
return TRUE;
} }
return(FALSE); RestoreInterrupts();
return FALSE;
} }
@ -1938,10 +1814,8 @@ void MV_StopPlayback
MV_StopVoice(voice); MV_StopVoice(voice);
if (MV_CallBackFunc) if (MV_CallBackFunc)
{
MV_CallBackFunc(voice->callbackval); MV_CallBackFunc(voice->callbackval);
} }
}
RestoreInterrupts(); RestoreInterrupts();
} }
@ -2213,6 +2087,9 @@ int32_t MV_PlayLoopedWAV
VoiceNode *voice; VoiceNode *voice;
int32_t length; int32_t length;
UNREFERENCED_PARAMETER(ptrlength);
UNREFERENCED_PARAMETER(loopend);
if (!MV_Installed) if (!MV_Installed)
{ {
MV_SetErrorCode(MV_NotInstalled); MV_SetErrorCode(MV_NotInstalled);
@ -2425,6 +2302,8 @@ int32_t MV_PlayLoopedVOC
VoiceNode *voice; VoiceNode *voice;
int32_t status; int32_t status;
UNREFERENCED_PARAMETER(ptrlength);
if (!MV_Installed) if (!MV_Installed)
{ {
MV_SetErrorCode(MV_NotInstalled); MV_SetErrorCode(MV_NotInstalled);
@ -2854,4 +2733,36 @@ int32_t MV_Shutdown
return(MV_Ok); return(MV_Ok);
} }
int32_t MV_SetVoiceCallback(int32_t handle, uint32_t callbackval)
{
VoiceNode *voice;
if (!MV_Installed)
{
MV_SetErrorCode(MV_NotInstalled);
return(MV_Error);
}
DisableInterrupts();
if ((voice = MV_GetVoice(handle)) == NULL)
{
RestoreInterrupts();
MV_SetErrorCode(MV_VoiceNotFound);
return(MV_Error);
}
voice->callbackval = callbackval;
RestoreInterrupts();
return(MV_Ok);
}
void MV_SetPrintf(void (*function)(const char *, ...))
{
MV_Printf = function;
}
// vim:ts=3:expandtab: // vim:ts=3:expandtab:

View file

@ -31,6 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __MULTIVOC_H #ifndef __MULTIVOC_H
#define __MULTIVOC_H #define __MULTIVOC_H
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(x) x=x
#endif
#define MV_MinVoiceHandle 1 #define MV_MinVoiceHandle 1
extern int32_t MV_ErrorCode; extern int32_t MV_ErrorCode;
@ -53,6 +57,7 @@ enum MV_Errors
MV_NullRecordFunction MV_NullRecordFunction
}; };
void (*MV_Printf)(const char *fmt, ...);
const char *MV_ErrorString( int32_t ErrorNumber ); const char *MV_ErrorString( int32_t ErrorNumber );
int32_t MV_VoicePlaying( int32_t handle ); int32_t MV_VoicePlaying( int32_t handle );
int32_t MV_KillAllVoices( void ); int32_t MV_KillAllVoices( void );
@ -113,5 +118,7 @@ int32_t MV_GetReverseStereo( void );
int32_t MV_Init( int32_t soundcard, int32_t MixRate, int32_t Voices, int32_t numchannels, int32_t MV_Init( int32_t soundcard, int32_t MixRate, int32_t Voices, int32_t numchannels,
int32_t samplebits, void * initdata ); int32_t samplebits, void * initdata );
int32_t MV_Shutdown( void ); int32_t MV_Shutdown( void );
int32_t MV_SetVoiceCallback(int32_t handle, uint32_t callbackval);
void MV_SetPrintf(void (*function)(const char *fmt, ...));
#endif #endif

View file

@ -115,6 +115,7 @@ static int32_t seek_vorbis(void * datasource, ogg_int64_t offset, int32_t whence
static int32_t close_vorbis(void * datasource) static int32_t close_vorbis(void * datasource)
{ {
UNREFERENCED_PARAMETER(datasource);
return 0; return 0;
} }
@ -161,7 +162,7 @@ static playbackstatus MV_GetNextVorbisBlock
if (voice->LoopStart) { if (voice->LoopStart) {
err = ov_pcm_seek_page(&vd->vf, 0); err = ov_pcm_seek_page(&vd->vf, 0);
if (err != 0) { if (err != 0) {
fprintf(stderr, "MV_GetNextVorbisBlock ov_pcm_seek_page_lap: err %d\n", err); MV_Printf("MV_GetNextVorbisBlock ov_pcm_seek_page_lap: err %d\n", err);
} else { } else {
continue; continue;
} }
@ -169,7 +170,7 @@ static playbackstatus MV_GetNextVorbisBlock
break; break;
} }
} else if (bytes < 0) { } else if (bytes < 0) {
fprintf(stderr, "MV_GetNextVorbisBlock ov_read: err %d\n", bytes); MV_Printf("MV_GetNextVorbisBlock ov_read: err %d\n", bytes);
voice->Playing = FALSE; voice->Playing = FALSE;
return NoMoreData; return NoMoreData;
} }
@ -317,6 +318,8 @@ int32_t MV_PlayLoopedVorbis
vorbis_data * vd = 0; vorbis_data * vd = 0;
vorbis_info * vi = 0; vorbis_info * vi = 0;
UNREFERENCED_PARAMETER(loopend);
if ( !MV_Installed ) if ( !MV_Installed )
{ {
MV_SetErrorCode( MV_NotInstalled ); MV_SetErrorCode( MV_NotInstalled );
@ -337,7 +340,7 @@ int32_t MV_PlayLoopedVorbis
status = ov_open_callbacks((void *) vd, &vd->vf, 0, 0, vorbis_callbacks); status = ov_open_callbacks((void *) vd, &vd->vf, 0, 0, vorbis_callbacks);
if (status < 0) { if (status < 0) {
fprintf(stderr, "MV_PlayLoopedVorbis: err %d\n", status); MV_Printf("MV_PlayLoopedVorbis: err %d\n", status);
MV_SetErrorCode( MV_InvalidVorbisFile ); MV_SetErrorCode( MV_InvalidVorbisFile );
return MV_Error; return MV_Error;
} }

View file

@ -70,7 +70,7 @@ extern "C" {
#define JoyMax 0xa00 #define JoyMax 0xa00
#define MaxJoyValue 5000 #define MaxJoyValue 5000
#define DEFAULTMOUSESENSITIVITY 10 // 0x7000+MINIMUMMOUSESENSITIVITY #define DEFAULTMOUSESENSITIVITY 7 // 0x7000+MINIMUMMOUSESENSITIVITY
#define INSTANT_ONOFF 0 #define INSTANT_ONOFF 0
#define TOGGLE_ONOFF 1 #define TOGGLE_ONOFF 1

View file

@ -4934,7 +4934,23 @@ VOLUME_ALL_40x:
if (x == -1) if (x == -1)
{ {
if (g_player[myconnectindex].ps->gm&MODE_GAME) if (g_player[myconnectindex].ps->gm&MODE_GAME)
{
switch (g_currentMenu)
{
case 400:
case 401:
g_player[myconnectindex].ps->gm = MODE_GAME;
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
}
break;
default:
ChangeToMenu(50); ChangeToMenu(50);
break;
}
}
else ChangeToMenu(0); else ChangeToMenu(0);
return; return;
} }

View file

@ -1404,6 +1404,7 @@ int32_t registerosdcommands(void)
{ "demoplay_showsync","demoplay_showsync: enable/disable display of sync status",(void*)&demoplay_showsync, CVAR_BOOL, 0, 1 }, { "demoplay_showsync","demoplay_showsync: enable/disable display of sync status",(void*)&demoplay_showsync, CVAR_BOOL, 0, 1 },
{ "hud_althud", "hud_althud: enable/disable alternate mini-hud", (void*)&ud.althud, CVAR_BOOL, 0, 1 }, { "hud_althud", "hud_althud: enable/disable alternate mini-hud", (void*)&ud.althud, CVAR_BOOL, 0, 1 },
{ "hud_bgstretch", "hud_bgstretch: enable/disable background image stretching in wide resolutions", (void*)&ud.bgstretch, CVAR_BOOL, 0, 1 },
{ "hud_messagetime", "hud_messagetime: length of time to display multiplayer chat messages", (void*)&ud.msgdisptime, CVAR_INT, 0, 3600 }, { "hud_messagetime", "hud_messagetime: length of time to display multiplayer chat messages", (void*)&ud.msgdisptime, CVAR_INT, 0, 3600 },
{ "hud_numbertile", "hud_numbertile: first tile in alt hud number set", (void*)&althud_numbertile, CVAR_INT, 0, MAXTILES-10 }, { "hud_numbertile", "hud_numbertile: first tile in alt hud number set", (void*)&althud_numbertile, CVAR_INT, 0, MAXTILES-10 },
{ "hud_numberpal", "hud_numberpal: pal for alt hud numbers", (void*)&althud_numberpal, CVAR_INT, 0, MAXPALOOKUPS }, { "hud_numberpal", "hud_numberpal: pal for alt hud numbers", (void*)&althud_numberpal, CVAR_INT, 0, MAXPALOOKUPS },

View file

@ -455,10 +455,11 @@ int32_t A_Shoot(int32_t i,int32_t atwith)
{ {
if (ProjectileData[atwith].decal >= 0) if (ProjectileData[atwith].decal >= 0)
{ {
if (!(SpriteFlags[ProjectileData[atwith].decal] & SPRITE_DECAL))
SpriteFlags[ProjectileData[atwith].decal] |= SPRITE_DECAL;
k = A_Spawn(i,ProjectileData[atwith].decal); k = A_Spawn(i,ProjectileData[atwith].decal);
if (!A_CheckSpriteFlags(k , SPRITE_DECAL))
actor[k].flags |= SPRITE_DECAL;
sprite[k].xvel = -1; sprite[k].xvel = -1;
sprite[k].ang = getangle(wall[hitinfo.hitwall].x-wall[wall[hitinfo.hitwall].point2].x, sprite[k].ang = getangle(wall[hitinfo.hitwall].x-wall[wall[hitinfo.hitwall].point2].x,
wall[hitinfo.hitwall].y-wall[wall[hitinfo.hitwall].point2].y)+512; wall[hitinfo.hitwall].y-wall[wall[hitinfo.hitwall].point2].y)+512;
@ -841,6 +842,10 @@ int32_t A_Shoot(int32_t i,int32_t atwith)
if (ProjectileData[atwith].decal >= 0) if (ProjectileData[atwith].decal >= 0)
{ {
l = A_Spawn(k,ProjectileData[atwith].decal); l = A_Spawn(k,ProjectileData[atwith].decal);
if (!A_CheckSpriteFlags(l , SPRITE_DECAL))
actor[l].flags |= SPRITE_DECAL;
sprite[l].xvel = -1; sprite[l].xvel = -1;
sprite[l].ang = getangle(wall[hitinfo.hitwall].x-wall[wall[hitinfo.hitwall].point2].x, sprite[l].ang = getangle(wall[hitinfo.hitwall].x-wall[wall[hitinfo.hitwall].point2].x,
wall[hitinfo.hitwall].y-wall[wall[hitinfo.hitwall].point2].y)+512; wall[hitinfo.hitwall].y-wall[wall[hitinfo.hitwall].point2].y)+512;
@ -1400,6 +1405,10 @@ DOSKIPBULLETHOLE:
l = nextspritestat[l]; l = nextspritestat[l];
} }
l = A_Spawn(k,BULLETHOLE); l = A_Spawn(k,BULLETHOLE);
if (!A_CheckSpriteFlags(l , SPRITE_DECAL))
actor[l].flags |= SPRITE_DECAL;
sprite[l].xvel = -1; sprite[l].xvel = -1;
sprite[l].x = hitinfo.pos.x; sprite[l].x = hitinfo.pos.x;
sprite[l].y = hitinfo.pos.y; sprite[l].y = hitinfo.pos.y;
@ -2020,9 +2029,9 @@ static void G_DrawTileScaled(int32_t x, int32_t y, int32_t tilenum, int32_t shad
if (getrendermode() >= 3 && usemodels && md_tilehasmodel(tilenum,p) > 0) if (getrendermode() >= 3 && usemodels && md_tilehasmodel(tilenum,p) > 0)
y += (224-weapsc(224)); y += (224-weapsc(224));
#endif #endif
rotatesprite(weapsc((orientation&256)?x:(x<<16))+((xoff-weapsc(xoff))<<16), rotatesprite(weapsc((orientation&1024)?x:(x<<16))+((xoff-weapsc(xoff))<<16),
weapsc((orientation&256)?y:(y<<16))+((200-weapsc(200))<<16), weapsc((orientation&1024)?y:(y<<16))+((200-weapsc(200))<<16),
weapsc(65536L),a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2); weapsc(65536L),a,tilenum,shade,p,(2|orientation),windowx1,windowy1,windowx2,windowy2);
} }
static void G_DrawWeaponTile(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p) static void G_DrawWeaponTile(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p)
@ -2473,12 +2482,12 @@ void P_DisplayWeapon(int32_t snum)
if (*kb < 8) if (*kb < 8)
{ {
G_DrawWeaponTile(weapon_xoffset+164,(looking_arc<<1)+176-gun_pos, G_DrawWeaponTile(weapon_xoffset+164,(looking_arc<<1)+176-gun_pos,
RPGGUN+((*kb)>>1),gs,o,pal); RPGGUN+((*kb)>>1),gs,o|512,pal);
} }
} }
G_DrawWeaponTile(weapon_xoffset+164,(looking_arc<<1)+176-gun_pos, G_DrawWeaponTile(weapon_xoffset+164,(looking_arc<<1)+176-gun_pos,
RPGGUN,gs,o,pal); RPGGUN,gs,o|512,pal);
} }
break; break;
@ -2666,42 +2675,42 @@ void P_DisplayWeapon(int32_t snum)
if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-17) if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-17)
{ {
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(194-(p->look_ang>>1),looking_arc+230-gun_pos,FIRSTGUN+4,gs,o,pal); G_DrawWeaponTile(194-(p->look_ang>>1),looking_arc+230-gun_pos,FIRSTGUN+4,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-12) else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-12)
{ {
G_DrawWeaponTile(244-((*kb)<<3)-(p->look_ang>>1),looking_arc+130-gun_pos+((*kb)<<4),FIRSTGUN+6,gs,o,pal); G_DrawWeaponTile(244-((*kb)<<3)-(p->look_ang>>1),looking_arc+130-gun_pos+((*kb)<<4),FIRSTGUN+6,gs,o|512,pal);
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o,pal); G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-7) else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-7)
{ {
G_DrawWeaponTile(124+((*kb)<<1)-(p->look_ang>>1),looking_arc+430-gun_pos-((*kb)<<3),FIRSTGUN+6,gs,o,pal); G_DrawWeaponTile(124+((*kb)<<1)-(p->look_ang>>1),looking_arc+430-gun_pos-((*kb)<<3),FIRSTGUN+6,gs,o|512,pal);
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o,pal); G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-4) else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-4)
{ {
G_DrawWeaponTile(184-(p->look_ang>>1),looking_arc+235-gun_pos,FIRSTGUN+8,gs,o,pal); G_DrawWeaponTile(184-(p->look_ang>>1),looking_arc+235-gun_pos,FIRSTGUN+8,gs,o|512,pal);
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+210-gun_pos,FIRSTGUN+5,gs,o,pal); G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+210-gun_pos,FIRSTGUN+5,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-2) else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]-2)
{ {
G_DrawWeaponTile(164-(p->look_ang>>1),looking_arc+245-gun_pos,FIRSTGUN+8,gs,o,pal); G_DrawWeaponTile(164-(p->look_ang>>1),looking_arc+245-gun_pos,FIRSTGUN+8,gs,o|512,pal);
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o,pal); G_DrawWeaponTile(224-(p->look_ang>>1),looking_arc+220-gun_pos,FIRSTGUN+5,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON]) else if ((*kb) < *aplWeaponReload[PISTOL_WEAPON])
{ {
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(194-(p->look_ang>>1),looking_arc+235-gun_pos,FIRSTGUN+5,gs,o,pal); G_DrawWeaponTile(194-(p->look_ang>>1),looking_arc+235-gun_pos,FIRSTGUN+5,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
@ -2841,15 +2850,15 @@ void P_DisplayWeapon(int32_t snum)
} }
gun_pos -= 16; gun_pos -= 16;
guniqhudid = 0; guniqhudid = 0;
G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+261-gun_pos,FREEZE+2,-32,o,pal); G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+261-gun_pos,FREEZE+2,-32,o|512,pal);
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+235-gun_pos,FREEZE+3+cat_frames[*kb%6],-32,o,pal); G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+235-gun_pos,FREEZE+3+cat_frames[*kb%6],-32,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
else else
{ {
guniqhudid = cw; guniqhudid = cw;
G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+261-gun_pos,FREEZE,gs,o,pal); G_DrawWeaponTile(weapon_xoffset+210-(p->look_ang>>1),looking_arc+261-gun_pos,FREEZE,gs,o|512,pal);
guniqhudid = 0; guniqhudid = 0;
} }
} }
@ -3065,72 +3074,6 @@ void getinput(int32_t snum)
return; return;
} }
if (BUTTON(gamefunc_Jump) && p->on_ground)
jump_timer = 4;
loc.bits = (jump_timer > 0 || BUTTON(gamefunc_Jump))<<SK_JUMP;
loc.bits |= BUTTON(gamefunc_Crouch)<<SK_CROUCH;
loc.bits |= BUTTON(gamefunc_Fire)<<SK_FIRE;
loc.bits |= BUTTON(gamefunc_Aim_Up)<<SK_AIM_UP;
loc.bits |= BUTTON(gamefunc_Aim_Down)<<SK_AIM_DOWN;
if (ud.runkey_mode) loc.bits |= (ud.auto_run | BUTTON(gamefunc_Run))<<SK_RUN;
else loc.bits |= (BUTTON(gamefunc_Run) ^ ud.auto_run)<<SK_RUN;
loc.bits |= BUTTON(gamefunc_Look_Left)<<SK_LOOK_LEFT;
loc.bits |= BUTTON(gamefunc_Look_Right)<<SK_LOOK_RIGHT;
if (aplWeaponFlags[g_player[snum].ps->curr_weapon][snum] & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
CONTROL_ClearButton(gamefunc_Fire);
if (jump_timer > 0)
jump_timer--;
j=0;
if (BUTTON(gamefunc_Weapon_1))
j = 1;
if (BUTTON(gamefunc_Weapon_2))
j = 2;
if (BUTTON(gamefunc_Weapon_3))
j = 3;
if (BUTTON(gamefunc_Weapon_4))
j = 4;
if (BUTTON(gamefunc_Weapon_5))
j = 5;
if (BUTTON(gamefunc_Weapon_6))
j = 6;
if (BUTTON(gamefunc_Weapon_7))
j = 7;
if (BUTTON(gamefunc_Weapon_8))
j = 8;
if (BUTTON(gamefunc_Weapon_9))
j = 9;
if (BUTTON(gamefunc_Weapon_10))
j = 10;
if (BUTTON(gamefunc_Previous_Weapon))
j = 11;
if (BUTTON(gamefunc_Next_Weapon))
j = 12;
loc.bits |= j<<SK_WEAPON_BITS;
loc.bits |= BUTTON(gamefunc_Steroids)<<SK_STEROIDS;
loc.bits |= BUTTON(gamefunc_Look_Up)<<SK_LOOK_UP;
loc.bits |= BUTTON(gamefunc_Look_Down)<<SK_LOOK_DOWN;
loc.bits |= BUTTON(gamefunc_NightVision)<<SK_NIGHTVISION;
loc.bits |= BUTTON(gamefunc_MedKit)<<SK_MEDKIT;
loc.bits |= BUTTON(gamefunc_Center_View)<<SK_CENTER_VIEW;
loc.bits |= BUTTON(gamefunc_Holster_Weapon)<<SK_HOLSTER;
loc.bits |= BUTTON(gamefunc_Inventory_Left)<<SK_INV_LEFT;
loc.bits |= KB_KeyPressed(sc_Pause)<<SK_PAUSE;
loc.bits |= BUTTON(gamefunc_Quick_Kick)<<SK_QUICK_KICK;
loc.bits |= g_myAimMode<<SK_AIMMODE;
loc.bits |= BUTTON(gamefunc_Holo_Duke)<<SK_HOLODUKE;
loc.bits |= BUTTON(gamefunc_Jetpack)<<SK_JETPACK;
loc.bits |= (((int32_t)g_gameQuit)<<SK_GAMEQUIT);
loc.bits |= BUTTON(gamefunc_Inventory_Right)<<SK_INV_RIGHT;
loc.bits |= BUTTON(gamefunc_TurnAround)<<SK_TURNAROUND;
loc.bits |= BUTTON(gamefunc_Open)<<SK_OPEN;
loc.bits |= BUTTON(gamefunc_Inventory)<<SK_INVENTORY;
loc.bits |= KB_KeyPressed(sc_Escape)<<SK_ESCAPE;
// running = BUTTON(gamefunc_Run)|ud.auto_run; // running = BUTTON(gamefunc_Run)|ud.auto_run;
// JBF: Run key behaviour is selectable // JBF: Run key behaviour is selectable
@ -3220,6 +3163,79 @@ void getinput(int32_t snum)
if (horiz < -MAXHORIZ) horiz = -MAXHORIZ; if (horiz < -MAXHORIZ) horiz = -MAXHORIZ;
if (horiz > MAXHORIZ) horiz = MAXHORIZ; if (horiz > MAXHORIZ) horiz = MAXHORIZ;
j=0;
if (BUTTON(gamefunc_Weapon_1))
j = 1;
if (BUTTON(gamefunc_Weapon_2))
j = 2;
if (BUTTON(gamefunc_Weapon_3))
j = 3;
if (BUTTON(gamefunc_Weapon_4))
j = 4;
if (BUTTON(gamefunc_Weapon_5))
j = 5;
if (BUTTON(gamefunc_Weapon_6))
j = 6;
if (BUTTON(gamefunc_Weapon_7))
j = 7;
if (BUTTON(gamefunc_Weapon_8))
j = 8;
if (BUTTON(gamefunc_Weapon_9))
j = 9;
if (BUTTON(gamefunc_Weapon_10))
j = 10;
if (BUTTON(gamefunc_Previous_Weapon) || (BUTTON(gamefunc_Dpad_Select) && vel < 0))
j = 11;
if (BUTTON(gamefunc_Next_Weapon) || (BUTTON(gamefunc_Dpad_Select) && vel > 0))
j = 12;
if (BUTTON(gamefunc_Jump) && p->on_ground)
jump_timer = 4;
if (aplWeaponFlags[g_player[snum].ps->curr_weapon][snum] & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
CONTROL_ClearButton(gamefunc_Fire);
loc.bits = (jump_timer > 0 || BUTTON(gamefunc_Jump))<<SK_JUMP;
if (jump_timer > 0)
jump_timer--;
loc.bits |= BUTTON(gamefunc_Crouch)<<SK_CROUCH;
loc.bits |= BUTTON(gamefunc_Fire)<<SK_FIRE;
loc.bits |= (BUTTON(gamefunc_Aim_Up) || (BUTTON(gamefunc_Dpad_Aiming) && vel > 0))<<SK_AIM_UP;
loc.bits |= (BUTTON(gamefunc_Aim_Down) || (BUTTON(gamefunc_Dpad_Aiming) && vel < 0))<<SK_AIM_DOWN;
if (ud.runkey_mode) loc.bits |= (ud.auto_run | BUTTON(gamefunc_Run))<<SK_RUN;
else loc.bits |= (BUTTON(gamefunc_Run) ^ ud.auto_run)<<SK_RUN;
loc.bits |= BUTTON(gamefunc_Look_Left)<<SK_LOOK_LEFT;
loc.bits |= BUTTON(gamefunc_Look_Right)<<SK_LOOK_RIGHT;
loc.bits |= j<<SK_WEAPON_BITS;
loc.bits |= BUTTON(gamefunc_Steroids)<<SK_STEROIDS;
loc.bits |= BUTTON(gamefunc_Look_Up)<<SK_LOOK_UP;
loc.bits |= BUTTON(gamefunc_Look_Down)<<SK_LOOK_DOWN;
loc.bits |= BUTTON(gamefunc_NightVision)<<SK_NIGHTVISION;
loc.bits |= BUTTON(gamefunc_MedKit)<<SK_MEDKIT;
loc.bits |= BUTTON(gamefunc_Center_View)<<SK_CENTER_VIEW;
loc.bits |= BUTTON(gamefunc_Holster_Weapon)<<SK_HOLSTER;
loc.bits |= (BUTTON(gamefunc_Inventory_Left) || (BUTTON(gamefunc_Dpad_Select) && (svel > 0 || angvel < 0))) <<SK_INV_LEFT;
loc.bits |= KB_KeyPressed(sc_Pause)<<SK_PAUSE;
loc.bits |= BUTTON(gamefunc_Quick_Kick)<<SK_QUICK_KICK;
loc.bits |= g_myAimMode<<SK_AIMMODE;
loc.bits |= BUTTON(gamefunc_Holo_Duke)<<SK_HOLODUKE;
loc.bits |= BUTTON(gamefunc_Jetpack)<<SK_JETPACK;
loc.bits |= (((int32_t)g_gameQuit)<<SK_GAMEQUIT);
loc.bits |= (BUTTON(gamefunc_Inventory_Right) || (BUTTON(gamefunc_Dpad_Select) && (svel < 0 || angvel > 0))) <<SK_INV_RIGHT;
loc.bits |= BUTTON(gamefunc_TurnAround)<<SK_TURNAROUND;
loc.bits |= BUTTON(gamefunc_Open)<<SK_OPEN;
loc.bits |= BUTTON(gamefunc_Inventory)<<SK_INVENTORY;
loc.bits |= KB_KeyPressed(sc_Escape)<<SK_ESCAPE;
if (BUTTON(gamefunc_Dpad_Select))
vel = svel = angvel = 0;
if (BUTTON(gamefunc_Dpad_Aiming))
vel = 0;
loc.extbits = 0; loc.extbits = 0;
// if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_MOVEFORWARD]) // if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_MOVEFORWARD])
loc.extbits |= BUTTON(gamefunc_Move_Forward) || (vel > 0); loc.extbits |= BUTTON(gamefunc_Move_Forward) || (vel > 0);
@ -3240,10 +3256,7 @@ void getinput(int32_t snum)
{ {
ud.folfvel = vel; ud.folfvel = vel;
ud.folavel = angvel; ud.folavel = angvel;
loc.fvel = 0; loc.fvel = loc.svel = loc.avel = loc.horz = 0;
loc.svel = 0;
loc.avel = 0;
loc.horz = 0;
return; return;
} }
@ -3838,9 +3851,10 @@ void P_FragPlayer(int32_t snum)
p->holoduke_on = -1; p->holoduke_on = -1;
S_StopEnvSound(DUKE_JETPACK_IDLE,p->i); S_StopEnvSound(DUKE_JETPACK_IDLE,p->i);
if (p->scream_voice >= FX_Ok) if (p->scream_voice > FX_Ok)
{ {
FX_StopSound(p->scream_voice); FX_StopSound(p->scream_voice);
S_Cleanup();
// S_TestSoundCallback(DUKE_SCREAM); // S_TestSoundCallback(DUKE_SCREAM);
p->scream_voice = -1; p->scream_voice = -1;
} }
@ -4065,7 +4079,7 @@ void P_ProcessWeapon(int32_t snum)
if (p->ammo_amount[p->curr_weapon] > 0) if (p->ammo_amount[p->curr_weapon] > 0)
{ {
(*kb)=1; (*kb)=1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
break; break;
@ -4073,7 +4087,7 @@ void P_ProcessWeapon(int32_t snum)
case HANDREMOTE_WEAPON: case HANDREMOTE_WEAPON:
p->hbomb_hold_delay = 0; p->hbomb_hold_delay = 0;
(*kb) = 1; (*kb) = 1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
break; break;
@ -4081,7 +4095,7 @@ void P_ProcessWeapon(int32_t snum)
if (p->ammo_amount[p->curr_weapon] > 0 && p->random_club_frame == 0) if (p->ammo_amount[p->curr_weapon] > 0 && p->random_club_frame == 0)
{ {
(*kb)=1; (*kb)=1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
break; break;
@ -4126,7 +4140,7 @@ void P_ProcessWeapon(int32_t snum)
p->pos.z = p->opos.z; p->pos.z = p->opos.z;
p->posvel.z = 0; p->posvel.z = 0;
(*kb) = 1; (*kb) = 1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
{ {
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
@ -4143,7 +4157,7 @@ void P_ProcessWeapon(int32_t snum)
if (p->ammo_amount[p->curr_weapon] > 0) if (p->ammo_amount[p->curr_weapon] > 0)
{ {
(*kb) = 1; (*kb) = 1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
break; break;
@ -4153,7 +4167,7 @@ void P_ProcessWeapon(int32_t snum)
{ {
(*kb) = 1; (*kb) = 1;
p->hbomb_hold_delay = !p->hbomb_hold_delay; p->hbomb_hold_delay = !p->hbomb_hold_delay;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
break; break;
@ -4162,7 +4176,7 @@ void P_ProcessWeapon(int32_t snum)
if (p->quick_kick == 0) if (p->quick_kick == 0)
{ {
(*kb) = 1; (*kb) = 1;
if (aplWeaponInitialSound[p->curr_weapon][snum]) if (aplWeaponInitialSound[p->curr_weapon][snum] > 0)
A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i); A_PlaySound(aplWeaponInitialSound[p->curr_weapon][snum], p->i);
} }
break; break;
@ -5025,7 +5039,7 @@ void P_ProcessInput(int32_t snum)
if (p->posvel.z > 2400 && p->falling_counter < 255) if (p->posvel.z > 2400 && p->falling_counter < 255)
{ {
p->falling_counter++; p->falling_counter++;
if (p->falling_counter >= 38 && p->scream_voice == -1) if (p->falling_counter >= 38 && p->scream_voice <= FX_Ok)
p->scream_voice = A_PlaySound(DUKE_SCREAM,p->i); p->scream_voice = A_PlaySound(DUKE_SCREAM,p->i);
} }
@ -5066,9 +5080,10 @@ void P_ProcessInput(int32_t snum)
{ {
p->falling_counter = 0; p->falling_counter = 0;
if (p->scream_voice >= FX_Ok) if (p->scream_voice > FX_Ok)
{ {
FX_StopSound(p->scream_voice); FX_StopSound(p->scream_voice);
S_Cleanup();
p->scream_voice = -1; p->scream_voice = -1;
} }

View file

@ -350,7 +350,7 @@ static void G_DoLoadScreen(char *statustext, int32_t percent)
clearview(0L); clearview(0L);
} }
rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1); rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (j > MAXTILES-1) if (j > MAXTILES-1)
{ {
@ -402,7 +402,7 @@ static void G_DoLoadScreen(char *statustext, int32_t percent)
aGameVars[g_iReturnVarID].val.lValue = LOADSCREEN; aGameVars[g_iReturnVarID].val.lValue = LOADSCREEN;
VM_OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1); VM_OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
j = aGameVars[g_iReturnVarID].val.lValue; j = aGameVars[g_iReturnVarID].val.lValue;
rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1); rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64+(ud.bgstretch?1024:0),0,0,xdim-1,ydim-1);
if (j > MAXTILES-1) if (j > MAXTILES-1)
{ {
nextpage(); nextpage();

View file

@ -2968,10 +2968,9 @@ CHECKINV1:
if (p->jetpack_on) if (p->jetpack_on)
{ {
p->inven_icon = 4; p->inven_icon = 4;
if (p->scream_voice >= FX_Ok) if (p->scream_voice > FX_Ok)
{ {
FX_StopSound(p->scream_voice); FX_StopSound(p->scream_voice);
// S_TestSoundCallback(DUKE_SCREAM);
p->scream_voice = -1; p->scream_voice = -1;
} }

View file

@ -42,6 +42,9 @@ static int32_t MusicLen = 0;
static int32_t MusicVoice = -1; static int32_t MusicVoice = -1;
static int32_t MusicPaused = 0; static int32_t MusicPaused = 0;
static mutex_t s_mutex;
static uint32_t dq[128], dnum = 0;
/* /*
=================== ===================
= =
@ -71,9 +74,12 @@ void S_SoundStartup(void)
G_GameExit(tempbuf); G_GameExit(tempbuf);
} }
S_ClearSoundLocks();
FX_SetVolume(ud.config.FXVolume); FX_SetVolume(ud.config.FXVolume);
FX_SetReverseStereo(ud.config.ReverseStereo); FX_SetReverseStereo(ud.config.ReverseStereo);
FX_SetCallBack(S_Callback); FX_SetCallBack(S_Callback);
FX_SetPrintf(initprintf);
mutex_init(&s_mutex);
} }
/* /*
@ -267,7 +273,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
{ {
if ((MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, ud.config.MusicVolume, if ((MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, ud.config.MusicVolume,
ud.config.MusicVolume, ud.config.MusicVolume, ud.config.MusicVolume, ud.config.MusicVolume,
FX_MUSIC_PRIORITY, MUSIC_ID)) >= FX_Ok) FX_MUSIC_PRIORITY, MUSIC_ID)) > FX_Ok)
MusicIsWaveform = 1; MusicIsWaveform = 1;
} }
return (alt != 0); return (alt != 0);
@ -294,6 +300,67 @@ void S_StopMusic(void)
} }
} }
void S_Cleanup(void)
{
// process from our own local copy of the delete queue so we don't hold the lock long
uint32_t ldq[128], ldnum;
mutex_lock(&s_mutex);
if (!dnum)
{
mutex_unlock(&s_mutex);
return;
}
Bmemcpy(ldq, dq, sizeof(int32_t) * (ldnum = dnum));
dnum = 0;
mutex_unlock(&s_mutex);
do
{
uint32_t num = ldq[--ldnum];
if (num >= 65536)
{
g_soundlocks[num-65536]--;
continue;
}
// negative index is RTS playback
if ((int32_t)num < 0)
{
if (lumplockbyte[-(int32_t)num] >= 200)
lumplockbyte[-(int32_t)num]--;
continue;
}
{
int32_t j = num & (MAXSOUNDINSTANCES-1);
num = (num - j) / MAXSOUNDINSTANCES;
if (g_sounds[num].num > MAXSOUNDINSTANCES)
OSD_Printf(OSD_ERROR "S_Cleanup(): num exceeds MAXSOUNDINSTANCES! g_sounds[%d].num %d wtf?\n", num, g_sounds[num].num);
if (g_sounds[num].num > 0)
{
int32_t i = g_sounds[num].SoundOwner[j].i;
// MUSICANDSFX uses t_data[0] to control restarting the sound
if (i != -1 && sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
actor[i].t_data[0] = 0;
g_sounds[num].SoundOwner[j].i = -1;
g_sounds[num].SoundOwner[j].voice = 0;
g_sounds[num].num--;
}
}
g_soundlocks[num]--;
}
while (ldnum);
}
// returns number of bytes read // returns number of bytes read
int32_t S_LoadSound(uint32_t num) int32_t S_LoadSound(uint32_t num)
{ {
@ -317,11 +384,9 @@ int32_t S_LoadSound(uint32_t num)
g_sounds[num].soundsiz = l = kfilelength(fp); g_sounds[num].soundsiz = l = kfilelength(fp);
while(mutex_lock(&cachemutex));
g_soundlocks[num] = 200; g_soundlocks[num] = 200;
allocache((intptr_t *)&g_sounds[num].ptr, l, (char *)&g_soundlocks[num]); allocache((intptr_t *)&g_sounds[num].ptr, l, (char *)&g_soundlocks[num]);
mutex_unlock(&cachemutex);
l = kread(fp, g_sounds[num].ptr , l); l = kread(fp, g_sounds[num].ptr , l);
kclose(fp); kclose(fp);
@ -340,18 +405,15 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
((g_sounds[num].m&8) && ud.lockout) || ((g_sounds[num].m&8) && ud.lockout) ||
ud.config.SoundToggle == 0 || ud.config.SoundToggle == 0 ||
g_sounds[num].num >= MAXSOUNDINSTANCES || g_sounds[num].num >= MAXSOUNDINSTANCES ||
i < 0 || i >= MAXSPRITES ||
FX_VoiceAvailable(g_sounds[num].pr) == 0 || FX_VoiceAvailable(g_sounds[num].pr) == 0 ||
(g_player[myconnectindex].ps->timebeforeexit > 0 && g_player[myconnectindex].ps->timebeforeexit <= GAMETICSPERSEC*3) || (g_player[myconnectindex].ps->timebeforeexit > 0 && g_player[myconnectindex].ps->timebeforeexit <= GAMETICSPERSEC*3) ||
g_player[myconnectindex].ps->gm&MODE_MENU) return -1; g_player[myconnectindex].ps->gm&MODE_MENU) return -1;
if (g_sounds[num].m&128) if (g_sounds[num].m&128)
{ {
if (g_sounds[num].num < MAXSOUNDINSTANCES && i >= 0 && i < MAXSPRITES)
{
while(mutex_lock(&cachemutex));
while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0) while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0)
j++; j++;
mutex_unlock(&cachemutex);
if (j >= MAXSOUNDINSTANCES) if (j >= MAXSOUNDINSTANCES)
{ {
@ -359,21 +421,21 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
return -1; return -1;
} }
if ((voice = S_PlaySound(num)) >= FX_Ok) if ((voice = S_PlaySound(num)) <= FX_Ok)
return -1;
if (FX_SetVoiceCallback(voice, (num * MAXSOUNDINSTANCES) + j))
{ {
while(mutex_lock(&cachemutex)); OSD_Printf(OSD_ERROR "S_PlaySound3D(): error setting callback!\n");
return -1;
}
g_sounds[num].SoundOwner[j].i = i; g_sounds[num].SoundOwner[j].i = i;
g_sounds[num].num++; g_sounds[num].num++;
g_sounds[num].SoundOwner[j].voice = voice; g_sounds[num].SoundOwner[j].voice = voice;
mutex_unlock(&cachemutex);
return voice; return voice;
} }
return -1;
}
return -1;
}
// Duke talk // Duke talk
if (g_sounds[num].m&4) if (g_sounds[num].m&4)
{ {
@ -447,11 +509,9 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
} }
else else
{ {
while(mutex_lock(&cachemutex));
if (g_soundlocks[num] < 200) if (g_soundlocks[num] < 200)
g_soundlocks[num] = 200; g_soundlocks[num] = 200;
else g_soundlocks[num]++; else g_soundlocks[num]++;
mutex_unlock(&cachemutex);
} }
if (g_sounds[num].m&16) sndist = 0; if (g_sounds[num].m&16) sndist = 0;
@ -461,22 +521,22 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
j = 0; j = 0;
while(mutex_lock(&cachemutex));
while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0) while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0)
j++; j++;
if (j >= MAXSOUNDINSTANCES) if (j >= MAXSOUNDINSTANCES)
{ {
g_soundlocks[num]--; g_soundlocks[num]--;
mutex_unlock(&cachemutex);
return -1; return -1;
} }
mutex_unlock(&cachemutex);
if (g_sounds[num].m&1) if (g_sounds[num].m&1)
{ {
if (g_sounds[num].num > 0) return -1; if (g_sounds[num].num > 0)
{
g_soundlocks[num]--;
return -1;
}
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1, voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,(num * MAXSOUNDINSTANCES) + j); pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,(num * MAXSOUNDINSTANCES) + j);
@ -487,19 +547,15 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
(num * MAXSOUNDINSTANCES) + j); (num * MAXSOUNDINSTANCES) + j);
} }
while(mutex_lock(&cachemutex)); if (voice > FX_Ok)
if (voice >= FX_Ok)
{ {
g_sounds[num].SoundOwner[j].i = i; g_sounds[num].SoundOwner[j].i = i;
g_sounds[num].num++; g_sounds[num].num++;
g_sounds[num].SoundOwner[j].voice = voice; g_sounds[num].SoundOwner[j].voice = voice;
mutex_unlock(&cachemutex);
return voice; return voice;
} }
g_soundlocks[num]--; g_soundlocks[num]--;
mutex_unlock(&cachemutex);
return -1; return -1;
} }
@ -530,23 +586,19 @@ int32_t S_PlaySound(int32_t num)
} }
else else
{ {
while(mutex_lock(&cachemutex));
if (g_soundlocks[num] < 200) if (g_soundlocks[num] < 200)
g_soundlocks[num] = 200; g_soundlocks[num] = 200;
else g_soundlocks[num]++; else g_soundlocks[num]++;
mutex_unlock(&cachemutex);
} }
voice = (g_sounds[num].m&1) ? voice = (g_sounds[num].m&1) ?
FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1, FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz,num * MAXSOUNDINSTANCES) : pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz, 65536 + num) :
FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num * MAXSOUNDINSTANCES); FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, 65536 + num);
if (voice < FX_Ok) if (voice <= FX_Ok)
{ {
while(mutex_lock(&cachemutex));
g_soundlocks[num]--; g_soundlocks[num]--;
mutex_unlock(&cachemutex);
return -1; return -1;
} }
@ -568,17 +620,28 @@ void S_StopSound(int32_t num)
{ {
int32_t j=MAXSOUNDINSTANCES-1; int32_t j=MAXSOUNDINSTANCES-1;
while(mutex_lock(&cachemutex));
for (; j>=0; j--) for (; j>=0; j--)
{ {
if (g_sounds[num].SoundOwner[j].voice) if (g_sounds[num].SoundOwner[j].voice)
{ {
mutex_unlock(&cachemutex); if (g_sounds[num].SoundOwner[j].voice > FX_Ok && g_sounds[num].SoundOwner[j].voice <= ud.config.NumVoices)
{
if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice))
FX_StopSound(g_sounds[num].SoundOwner[j].voice); FX_StopSound(g_sounds[num].SoundOwner[j].voice);
S_Cleanup();
goto retry;
}
else
{
initprintf(OSD_ERROR "S_StopSound(): bad voice %d for sound ID %d index %d!\n", g_sounds[num].SoundOwner[j].voice, num, j);
mutex_lock(&s_mutex);
dq[dnum++] = (num * MAXSOUNDINSTANCES) + j;
mutex_unlock(&s_mutex);
S_Cleanup();
goto retry; goto retry;
} }
} }
mutex_unlock(&cachemutex); }
} }
} }
@ -591,17 +654,28 @@ void S_StopEnvSound(int32_t num,int32_t i)
{ {
int32_t j=MAXSOUNDINSTANCES-1; int32_t j=MAXSOUNDINSTANCES-1;
while(mutex_lock(&cachemutex));
for (; j>=0; j--) for (; j>=0; j--)
{ {
if (g_sounds[num].SoundOwner[j].i == i && g_sounds[num].SoundOwner[j].voice) if (g_sounds[num].SoundOwner[j].i == i)
{ {
mutex_unlock(&cachemutex); if (g_sounds[num].SoundOwner[j].voice > FX_Ok && g_sounds[num].SoundOwner[j].voice <= ud.config.NumVoices)
{
if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice))
FX_StopSound(g_sounds[num].SoundOwner[j].voice); FX_StopSound(g_sounds[num].SoundOwner[j].voice);
S_Cleanup();
goto retry;
}
else
{
initprintf(OSD_ERROR "S_StopEnvSound(): bad voice %d for sound ID %d index %d!\n", g_sounds[num].SoundOwner[j].voice, num, j);
mutex_lock(&s_mutex);
dq[dnum++] = (num * MAXSOUNDINSTANCES) + j;
mutex_unlock(&s_mutex);
S_Cleanup();
goto retry; goto retry;
} }
} }
mutex_unlock(&cachemutex); }
} }
} }
@ -610,6 +684,8 @@ void S_Update(void)
vec3_t *s, *c; vec3_t *s, *c;
int32_t sndist,sndang,ca,j,k,i,cs; int32_t sndist,sndang,ca,j,k,i,cs;
S_Cleanup();
g_numEnvSoundsPlaying = 0; g_numEnvSoundsPlaying = 0;
if (ud.camerasprite == -1) if (ud.camerasprite == -1)
@ -627,16 +703,24 @@ void S_Update(void)
j = g_maxSoundPos; j = g_maxSoundPos;
while(mutex_lock(&cachemutex));
do do
{ {
for (k=MAXSOUNDINSTANCES-1; k>=0; k--) for (k=MAXSOUNDINSTANCES-1; k>=0; k--)
{ {
i = g_sounds[j].SoundOwner[k].i; i = g_sounds[j].SoundOwner[k].i;
if (i < 0 || i >= MAXSPRITES || g_sounds[j].num == 0 || g_sounds[j].SoundOwner[k].voice < FX_Ok) if (i < 0 || i >= MAXSPRITES || g_sounds[j].num == 0 || g_sounds[j].SoundOwner[k].voice <= FX_Ok)
continue; continue;
if (!FX_SoundActive(g_sounds[j].SoundOwner[k].voice))
{
/*
OSD_Printf("S_Update(): stale voice %d from sound %d position %d sprite %d\n",
g_sounds[j].SoundOwner[k].voice, j, k, g_sounds[j].SoundOwner[k].i);
*/
continue;
}
s = (vec3_t *)&sprite[i]; s = (vec3_t *)&sprite[i];
if (PN == APLAYER && sprite[i].yvel == screenpeek) if (PN == APLAYER && sprite[i].yvel == screenpeek)
@ -674,13 +758,10 @@ void S_Update(void)
if (sndist < ((255-LOUDESTVOLUME)<<6)) if (sndist < ((255-LOUDESTVOLUME)<<6))
sndist = ((255-LOUDESTVOLUME)<<6); sndist = ((255-LOUDESTVOLUME)<<6);
mutex_unlock(&cachemutex);
FX_Pan3D(g_sounds[j].SoundOwner[k].voice, sndang>>4, sndist>>6); FX_Pan3D(g_sounds[j].SoundOwner[k].voice, sndang>>4, sndist>>6);
mutex_lock(&cachemutex);
} }
} }
while (j--); while (j--);
mutex_unlock(&cachemutex);
} }
void S_Callback(uint32_t num) void S_Callback(uint32_t num)
@ -688,53 +769,33 @@ void S_Callback(uint32_t num)
if ((int32_t)num == MUSIC_ID) if ((int32_t)num == MUSIC_ID)
return; return;
while(mutex_lock(&cachemutex)); mutex_lock(&s_mutex);
dq[dnum++] = num;
// negative index is RTS playback mutex_unlock(&s_mutex);
if ((int32_t)num < 0)
{
if (lumplockbyte[-(int32_t)num] >= 200)
lumplockbyte[-(int32_t)num]--;
mutex_unlock(&cachemutex);
return;
}
{
int32_t j = num & (MAXSOUNDINSTANCES-1);
num = (num - j) / MAXSOUNDINSTANCES;
if (g_sounds[num].num > 0)
{
int32_t i = g_sounds[num].SoundOwner[j].i;
// MUSICANDSFX uses t_data[0] to control restarting the sound
if (sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
actor[i].t_data[0] = 0;
g_sounds[num].SoundOwner[j].i = -1;
g_sounds[num].SoundOwner[j].voice = 0;
g_sounds[num].num--;
}
}
g_soundlocks[num]--;
mutex_unlock(&cachemutex);
} }
void S_ClearSoundLocks(void) void S_ClearSoundLocks(void)
{ {
int32_t i; int32_t i;
while(mutex_lock(&cachemutex));
for (i=g_maxSoundPos; i >= 0 ; i--) for (i=g_maxSoundPos; i >= 0 ; i--)
{
int32_t j = MAXSOUNDINSTANCES-1;
for (; j>=0; j--)
{
g_sounds[i].num = 0;
g_sounds[i].SoundOwner[j].voice = 0;
g_sounds[i].SoundOwner[j].i = -1;
}
if (g_soundlocks[i] >= 200) if (g_soundlocks[i] >= 200)
g_soundlocks[i] = 199; g_soundlocks[i] = 199;
}
for (i=0; i<11; i++) for (i=0; i<11; i++)
if (lumplockbyte[i] >= 200) if (lumplockbyte[i] >= 200)
lumplockbyte[i] = 199; lumplockbyte[i] = 199;
mutex_unlock(&cachemutex);
} }
int32_t A_CheckSoundPlaying(int32_t i, int32_t num) int32_t A_CheckSoundPlaying(int32_t i, int32_t num)