From 3d0c34863d5f5d875cfd7846fa2ce2add6e1751b Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 24 Jun 2009 08:20:10 +0000 Subject: [PATCH] Generic non-descript commit message git-svn-id: https://svn.eduke32.com/eduke32@1440 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/build.c | 30 +- polymer/eduke32/build/src/engine.c | 10 +- polymer/eduke32/build/src/kplib.c | 914 ++++----- polymer/eduke32/build/src/mdsprite.c | 24 +- polymer/eduke32/build/src/nedmalloc.c | 1270 ++++++------ polymer/eduke32/build/src/osd.c | 132 +- polymer/eduke32/build/src/polymost.c | 14 +- polymer/eduke32/build/src/textfont.c | 10 +- polymer/eduke32/build/src/winlayer.c | 72 +- polymer/eduke32/source/actors.c | 74 +- polymer/eduke32/source/astub.c | 6 +- polymer/eduke32/source/duke3d.h | 2 + polymer/eduke32/source/funct.h | 12 +- polymer/eduke32/source/game.c | 50 +- polymer/eduke32/source/gamedef.c | 88 +- polymer/eduke32/source/gameexec.c | 885 +++++---- polymer/eduke32/source/gamestructures.c | 2350 ++++++++--------------- polymer/eduke32/source/gamevars.c | 333 ++-- polymer/eduke32/source/global.c | 2 + polymer/eduke32/source/player.c | 122 +- polymer/eduke32/source/premap.c | 5 +- 21 files changed, 2867 insertions(+), 3538 deletions(-) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 231784a56..8ccad8edc 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -1522,16 +1522,16 @@ void overheadeditor(void) drawlinepat = 0xffffffff; Bsprintf(tempbuf,"(%d,%d)",mousxplc,mousyplc); -/* - i = (Bstrlen(tempbuf)<<3)+6; - if ((searchx+i) < (xdim2d-1)) - i = 0; - else i = (searchx+i)-(xdim2d-1); - if ((searchy+16) < (ydim2d-STATUS2DSIZ2-1)) - j = 0; - else j = (searchy+16)-(ydim2d-STATUS2DSIZ2-1); - printext16(searchx+6-i,searchy+6-j,editorcolors[11],-1,tempbuf,0); -*/ + /* + i = (Bstrlen(tempbuf)<<3)+6; + if ((searchx+i) < (xdim2d-1)) + i = 0; + else i = (searchx+i)-(xdim2d-1); + if ((searchy+16) < (ydim2d-STATUS2DSIZ2-1)) + j = 0; + else j = (searchy+16)-(ydim2d-STATUS2DSIZ2-1); + printext16(searchx+6-i,searchy+6-j,editorcolors[11],-1,tempbuf,0); + */ _printmessage16(tempbuf); } drawline16(searchx,0,searchx,8,editorcolors[15]); @@ -2115,12 +2115,12 @@ void overheadeditor(void) // for (i=0; i>8)+(a<<8)); } #if !defined(_WIN32) && !defined(__DOS__) #include #include -typedef long long __int64; -static __inline int32_t _lrotl(int32_t i, int32_t sh) +typedef int32_t int32_t __int64; +static __inline int32_t _lrotl(int32_t i, int sh) { return((i>>(-sh))|(i< 0x8000000) + if (((uint32_t)cpb[0]) > 0x80000000) { cpuid(0x80000001,cpb); i |= (cpb[3]&(1<<31)); @@ -384,7 +382,7 @@ static int32_t getcputype() return(i); } -static char fakebuf[8], *nfilptr; +static uint8_t fakebuf[8], *nfilptr; static int32_t nbitpos; static void suckbitsnextblock() { @@ -393,13 +391,12 @@ static void suckbitsnextblock() if (!zipfilmode) { if (!nfilptr) - { - //|===|===|crc|lng|typ|===|===| + { //|===|===|crc|lng|typ|===|===| // \ fakebuf: / // |===|===| //----x O---x O-------- nbitpos = LSWAPIL(*(int32_t *)&filptr[8]); - nfilptr = (char *)&filptr[nbitpos+12]; + nfilptr = (uint8_t *)&filptr[nbitpos+12]; *(int32_t *)&fakebuf[0] = *(int32_t *)&filptr[0]; //Copy last dword of IDAT chunk if (*(int32_t *)&filptr[12] == LSWAPIB(0x54414449)) //Copy 1st dword of next IDAT chunk *(int32_t *)&fakebuf[4] = *(int32_t *)&filptr[16]; @@ -447,7 +444,7 @@ static int32_t hufgetsym(int32_t *hitab, int32_t *hbmax) // return(hitab[hbmax[n]+v]); //} -static void qhufgencode(int32_t *hitab, int32_t *hbmax, int32_t *qhval, char *qhbit, int32_t numbits) +static void qhufgencode(int32_t *hitab, int32_t *hbmax, int32_t *qhval, uint8_t *qhbit, int32_t numbits) { int32_t i, j, k, n, r; @@ -532,15 +529,12 @@ static int32_t initpass() //Interlaced images have 7 "passes", non-interlaced h xsizbpl = ((0x04021301>>(coltype<<2))&15)*ixsiz; switch (bitdepth) { - case 1: - xsizbpl = ((xsizbpl+7)>>3); break; - case 2: - xsizbpl = ((xsizbpl+3)>>2); break; - case 4: - xsizbpl = ((xsizbpl+1)>>1); break; + case 1: xsizbpl = ((xsizbpl+7)>>3); break; + case 2: xsizbpl = ((xsizbpl+3)>>2); break; + case 4: xsizbpl = ((xsizbpl+1)>>1); break; } - memset(olinbuf,0,(xsizbpl+1)*sizeof(olinbuf[0])); + Bmemset(olinbuf,0,(xsizbpl+1)*sizeof(olinbuf[0])); *(int32_t *)&opixbuf0[0] = *(int32_t *)&opixbuf1[0] = 0; xplc = xsizbpl; yplc = globyoffs+iyoff; xm = 0; filt = -1; @@ -562,14 +556,11 @@ static int32_t initpass() //Interlaced images have 7 "passes", non-interlaced h { switch (bitdepth) { - case 1: - xr0 += ((-ixsiz)&7)+7; + case 1: xr0 += ((-ixsiz)&7)+7; xr1 += ((-ixsiz)&7)+7; break; - case 2: - xr0 = ((xr0+((-ixsiz)&3)+3)<<1); + case 2: xr0 = ((xr0+((-ixsiz)&3)+3)<<1); xr1 = ((xr1+((-ixsiz)&3)+3)<<1); break; - case 4: - xr0 = ((xr0+((-ixsiz)&1)+1)<<2); + case 4: xr0 = ((xr0+((-ixsiz)&1)+1)<<2); xr1 = ((xr1+((-ixsiz)&1)+1)<<2); break; } } @@ -611,26 +602,26 @@ int32_t Paeth686(int32_t, int32_t, int32_t); void rgbhlineasm(int32_t, int32_t, int32_t, int32_t); #pragma aux rgbhlineasm =\ "sub ecx, edx"\ - "jle short endit"\ + "jle int16_t endit"\ "add edx, offset olinbuf"\ "cmp dword ptr trnsrgb, 0"\ - "jz short begit2"\ + "jz int16_t begit2"\ "begit: mov eax, dword ptr [ecx+edx]"\ "or eax, 0xff000000"\ "cmp eax, dword ptr trnsrgb"\ - "jne short skipit"\ + "jne int16_t skipit"\ "and eax, 0xffffff"\ "skipit: sub ecx, 3"\ "mov [edi], eax"\ "lea edi, [edi+ebx]"\ - "jnz short begit"\ - "jmp short endit"\ + "jnz int16_t begit"\ + "jmp int16_t endit"\ "begit2: mov eax, dword ptr [ecx+edx]"\ "or eax, 0xff000000"\ "sub ecx, 3"\ "mov [edi], eax"\ "lea edi, [edi+ebx]"\ - "jnz short begit2"\ + "jnz int16_t begit2"\ "endit:"\ parm [ecx][edx][edi][ebx]\ modify exact [eax ecx edi]\ @@ -639,14 +630,14 @@ void rgbhlineasm(int32_t, int32_t, int32_t, int32_t); void pal8hlineasm(int32_t, int32_t, int32_t, int32_t); #pragma aux pal8hlineasm =\ "sub ecx, edx"\ - "jle short endit"\ + "jle int16_t endit"\ "add edx, offset olinbuf"\ "begit: movzx eax, byte ptr [ecx+edx]"\ "mov eax, dword ptr palcol[eax*4]"\ "dec ecx"\ "mov [edi], eax"\ "lea edi, [edi+ebx]"\ - "jnz short begit"\ + "jnz int16_t begit"\ "endit:"\ parm [ecx][edx][edi][ebx]\ modify exact [eax ecx edi]\ @@ -658,6 +649,9 @@ static _inline int32_t Paeth686(int32_t a, int32_t b, int32_t c) { _asm { + push ebx + push esi + push edi mov eax, a mov ebx, b mov ecx, c @@ -672,6 +666,9 @@ static _inline int32_t Paeth686(int32_t a, int32_t b, int32_t c) cmovge ecx, ebx cmp edi, [eax*4+edx] cmovl eax, ecx + pop edi + pop esi + pop ebx } } @@ -679,35 +676,40 @@ static _inline void rgbhlineasm(int32_t c, int32_t d, int32_t t, int32_t b) { _asm { + push ebx + push edi + mov ecx, c mov edx, d mov edi, t mov ebx, b sub ecx, edx - jle short endit + jle int16_t endit add edx, offset olinbuf cmp dword ptr trnsrgb, 0 - jz short begit2 + jz int16_t begit2 begit: mov eax, dword ptr [ecx+edx] or eax, 0xff000000 cmp eax, dword ptr trnsrgb - jne short skipit + jne int16_t skipit and eax, 0xffffff skipit: sub ecx, 3 mov [edi], eax lea edi, [edi+ebx] - jnz short begit - jmp short endit + jnz int16_t begit + jmp int16_t endit begit2: mov eax, dword ptr [ecx+edx] or eax, 0xff000000 sub ecx, 3 mov [edi], eax lea edi, [edi+ebx] - jnz short begit2 + jnz int16_t begit2 endit: + pop edi + pop ebx } } @@ -717,18 +719,22 @@ static _inline void pal8hlineasm(int32_t c, int32_t d, int32_t t, int32_t b) { mov ecx, c mov edx, d + sub ecx, edx + jle int16_t endit + + push ebx + push edi mov edi, t mov ebx, b - sub ecx, edx - jle short endit add edx, offset olinbuf -begit: - movzx eax, byte ptr [ecx+edx] +begit:movzx eax, byte ptr [ecx+edx] mov eax, dword ptr palcol[eax*4] sub ecx, 1 mov [edi], eax lea edi, [edi+ebx] - jnz short begit + jnz int16_t begit + pop edi + pop ebx endit: } } @@ -738,12 +744,18 @@ endit: static inline int32_t Paeth686(int32_t a, int32_t b, int32_t c) { __asm__ __volatile__( - "movl %%ecx, %%edx\n\tsubl %%eax, %%edx\n\tsubl %%ebx, %%edx\n\t" - "leal (abstab10+2048)(,%%edx,4), %%edx\n\t" - "movl (%%edx,%%ebx,4), %%esi\n\tmovl (%%edx,%%ecx,4), %%edi\n\t" - "cmpl %%esi, %%edi\n\tcmovgel %%esi, %%edi\n\tcmovgel %%ebx, %%ecx\n\t" - "cmpl (%%edx,%%eax,4), %%edi\n\tcmovgel %%eax, %%ecx" - : "+c"(c) : "a"(a), "b"(b) : "esi","edi","memory","cc" + "movl %%ecx, %%edx \n" + "subl %%eax, %%edx \n" + "subl %%ebx, %%edx \n" + "leal (abstab10+2048)(,%%edx,4), %%edx \n" + "movl (%%edx,%%ebx,4), %%esi \n" + "movl (%%edx,%%ecx,4), %%edi \n" + "cmpl %%esi, %%edi \n" + "cmovgel %%esi, %%edi \n" + "cmovgel %%ebx, %%ecx \n" + "cmpl (%%edx,%%eax,4), %%edi \n" + "cmovgel %%eax, %%ecx \n" + : "+c"(c) : "a"(a), "b"(b) : "edx","esi","edi","memory","cc" ); return c; } @@ -752,27 +764,46 @@ static inline int32_t Paeth686(int32_t a, int32_t b, int32_t c) static inline void rgbhlineasm(int32_t c, int32_t d, int32_t t, int32_t b) { __asm__ __volatile__( - "subl %%edx, %%ecx\n\tjle 3f\n\taddl $olinbuf, %%edx\n\t" - "cmpl $0, trnsrgb(,1)\n\tjz 2f\n\t" - "0: movl (%%ecx,%%edx,1), %%eax\n\torl $0xff000000, %%eax\n\tcmpl trnsrgb(,1), %%eax\n\t" - "jne 1f\n\tandl $0xffffff, %%eax\n\t" - "1: subl $3, %%ecx\n\tmovl %%eax, (%%edi)\n\tleal (%%edi,%%ebx,1), %%edi\n\t" - "jnz 0b\n\tjmp 3f\n\t" - "2: movl (%%ecx,%%edx,1), %%eax\n\torl $0xff000000, %%eax\n\tsubl $3, %%ecx\n\t" - "movl %%eax, (%%edi)\n\tleal (%%edi,%%ebx,1), %%edi\n\tjnz 2b\n\t" - "3:" - : "+c"(c), "+D"(t) : "d"(d), "b"(b) : "eax","memory","cc" + "subl %%edx, %%ecx \n" + "jle 3f \n" + "addl $olinbuf, %%edx \n" + "cmpl $0, trnsrgb(,1) \n" + "jz 2f \n" + "0: movl (%%ecx,%%edx,1), %%eax \n" + "orl $0xff000000, %%eax \n" + "cmpl trnsrgb(,1), %%eax \n" + "jne 1f \n" + "andl $0xffffff, %%eax \n" + "1: subl $3, %%ecx \n" + "movl %%eax, (%%edi) \n" + "leal (%%edi,%%ebx,1), %%edi \n" + "jnz 0b \n" + "jmp 3f \n" + "2: movl (%%ecx,%%edx,1), %%eax \n" + "orl $0xff000000, %%eax \n" + "subl $3, %%ecx \n" + "movl %%eax, (%%edi) \n" + "leal (%%edi,%%ebx,1), %%edi \n" + "jnz 2b \n" + "3: \n" + : "+c"(c), "+d"(d), "+D"(t) : "b"(b) : "eax","memory","cc" ); } static inline void pal8hlineasm(int32_t c, int32_t d, int32_t t, int32_t b) { __asm__ __volatile__( - "subl %%edx, %%ecx\n\tjle 1f\n\taddl $olinbuf, %%edx\n\t" - "0: movzbl (%%ecx,%%edx,1), %%eax\n\tmovl palcol(,%%eax,4), %%eax\n\t" - "subl $1, %%ecx\n\tmovl %%eax, (%%edi)\n\tleal (%%edi,%%ebx,1), %%edi\n\tjnz 0b\n\t" - "1:" - : "+c"(c), "+D"(t) : "d"(d), "b"(b) : "eax","memory","cc" + "subl %%edx, %%ecx \n" + "jle 1f \n" + "addl $olinbuf, %%edx \n" + "0: movzbl (%%ecx,%%edx,1), %%eax \n" + "movl palcol(,%%eax,4), %%eax \n" + "subl $1, %%ecx \n" + "movl %%eax, (%%edi) \n" + "leal (%%edi,%%ebx,1), %%edi \n" + "jnz 0b \n" + "1: \n" + : "+c"(c), "+d"(d), "+D"(t) : "b"(b) : "eax","memory","cc" ); } @@ -815,7 +846,7 @@ static inline void pal8hlineasm(int32_t x, int32_t xr1, intptr_t p, int32_t ixst // /f4: 4444444... // /f5: 0142321... static int32_t filter1st, filterest; -static void putbuf(const char *buf, int32_t leng) +static void putbuf(const uint8_t *buf, int32_t leng) { int32_t i, x; intptr_t p; @@ -841,17 +872,17 @@ static void putbuf(const char *buf, int32_t leng) case 1: while (i < x) { - olinbuf[xplc] = (opixbuf1[xm] += buf[i]); + olinbuf[xplc] = (uint8_t)(opixbuf1[xm] += buf[i]); xm = xmn[xm]; xplc--; i++; } break; case 2: - while (i < x) { olinbuf[xplc] += buf[i]; xplc--; i++; } + while (i < x) { olinbuf[xplc] += (uint8_t)buf[i]; xplc--; i++; } break; case 3: while (i < x) { - opixbuf1[xm] = olinbuf[xplc] = ((opixbuf1[xm]+olinbuf[xplc])>>1)+buf[i]; + opixbuf1[xm] = olinbuf[xplc] = (uint8_t)(((opixbuf1[xm]+olinbuf[xplc])>>1)+buf[i]); xm = xmn[xm]; xplc--; i++; } break; @@ -883,54 +914,27 @@ static void putbuf(const char *buf, int32_t leng) x = xr0; p = nfplace; switch (coltype) { - case 2: - rgbhlineasm(x,xr1,p,ixstp); - break; + case 2: rgbhlineasm(x,xr1,p,ixstp); break; case 4: for (; x>xr1; p+=ixstp,x-=2) - { -#if (PROCESSALPHAHERE == 1) - //Enable this code to process alpha right here! - if (olinbuf[x-1] == 255) { *(int32_t *)p = palcol[olinbuf[x]]; continue; } - if (!olinbuf[x-1]) { *(int32_t *)p = bakcol; continue; } - //I do >>8, but theoretically should be: /255 - *(char *)(p) = *(char *)(p+1) = *(char *)(p+2) = *(char *)(p+3) = - (((((int32_t)olinbuf[x])-bakr)*(int32_t)olinbuf[x-1])>>8) + bakr; -#else *(int32_t *)p = (palcol[olinbuf[x]]&LSWAPIB(0xffffff))|LSWAPIL((int32_t)olinbuf[x-1]); -#endif - } break; case 6: for (; x>xr1; p+=ixstp,x-=4) { -#if (PROCESSALPHAHERE == 1) - //Enable this code to process alpha right here! - if (olinbuf[x-1] == 255) { *(int32_t *)p = *(int32_t *)&olinbuf[x]; continue; } - if (!olinbuf[x-1]) { *(int32_t *)p = bakcol; continue; } - //I do >>8, but theoretically should be: /255 - *(char *)(p) = (((((int32_t)olinbuf[x ])-bakr)*(int32_t)olinbuf[x-1])>>8) + bakr; - *(char *)(p+1) = (((((int32_t)olinbuf[x+1])-bakg)*(int32_t)olinbuf[x-1])>>8) + bakg; - *(char *)(p+2) = (((((int32_t)olinbuf[x+2])-bakb)*(int32_t)olinbuf[x-1])>>8) + bakb; -#else - *(char *)(p) = olinbuf[x ]; //R + *(char *)(p) = olinbuf[x ]; //B *(char *)(p+1) = olinbuf[x+1]; //G - *(char *)(p+2) = olinbuf[x+2]; //B + *(char *)(p+2) = olinbuf[x+2]; //R *(char *)(p+3) = olinbuf[x-1]; //A -#endif } break; default: switch (bitdepth) { - case 1: - for (; x>xr1; p+=ixstp,x--) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&7)]; break; - case 2: - for (; x>xr1; p+=ixstp,x-=2) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&6)]; break; - case 4: - for (; x>xr1; p+=ixstp,x-=4) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&4)]; break; - case 8: - pal8hlineasm(x,xr1,p,ixstp); break; //for(;x>xr1;p+=ixstp,x--) *(int32_t *)p = palcol[olinbuf[x]]; break; + case 1: for (; x>xr1; p+=ixstp,x--) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&7)]; break; + case 2: for (; x>xr1; p+=ixstp,x-=2) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&6)]; break; + case 4: for (; x>xr1; p+=ixstp,x-=4) *(int32_t *)p = palcol[olinbuf[x>>3]>>(x&4)]; break; + case 8: pal8hlineasm(x,xr1,p,ixstp); break; //for(;x>xr1;p+=ixstp,x-- ) *(int32_t *)p = palcol[olinbuf[x]]; break; } break; } @@ -994,7 +998,7 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, if ((*(int32_t *)&kfilebuf[0] != LSWAPIB(0x474e5089)) || (*(int32_t *)&kfilebuf[4] != LSWAPIB(0x0a1a0a0d))) return(-1); //"Invalid PNG file signature" - filptr = (char *)&kfilebuf[8]; + filptr = (uint8_t *)&kfilebuf[8]; trnsrgb = 0; filter1st = -1; filterest = 0; @@ -1031,12 +1035,10 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, { switch (coltype) { - case 0: - case 4: + case 0: case 4: bakcol = (((int32_t)filptr[0]<<8)+(int32_t)filptr[1])*255/((1<=0; i--) palcol[i] &= LSWAPIB((((int32_t)filptr[i])<<24)|0xffffff); break; - default: - ; + default:; } } else if (i == LSWAPIB(0x54414449)) { break; } //IDAT @@ -1094,23 +1095,16 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, switch (coltype) { - case 4: - xmn[0] = 1; xmn[1] = 0; break; - case 2: - xmn[0] = 1; xmn[1] = 2; xmn[2] = 0; break; - case 6: - xmn[0] = 1; xmn[1] = 2; xmn[2] = 3; xmn[3] = 0; break; - default: - xmn[0] = 0; break; + case 4: xmn[0] = 1; xmn[1] = 0; break; + case 2: xmn[0] = 1; xmn[1] = 2; xmn[2] = 0; break; + case 6: xmn[0] = 1; xmn[1] = 2; xmn[2] = 3; xmn[3] = 0; break; + default: xmn[0] = 0; break; } switch (bitdepth) { - case 1: - for (i=2; i<256; i++) palcol[i] = palcol[i&1]; break; - case 2: - for (i=4; i<256; i++) palcol[i] = palcol[i&3]; break; - case 4: - for (i=16; i<256; i++) palcol[i] = palcol[i&15]; break; + case 1: for (i=2; i<256; i++) palcol[i] = palcol[i&1]; break; + case 2: for (i=4; i<256; i++) palcol[i] = palcol[i&3]; break; + case 4: for (i=16; i<256; i++) palcol[i] = palcol[i&15]; break; } //coltype: bitdepth: format: @@ -1122,12 +1116,9 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, xsizbpl = ((0x04021301>>(coltype<<2))&15)*xsiz; switch (bitdepth) { - case 1: - xsizbpl = ((xsizbpl+7)>>3); break; - case 2: - xsizbpl = ((xsizbpl+3)>>2); break; - case 4: - xsizbpl = ((xsizbpl+1)>>1); break; + case 1: xsizbpl = ((xsizbpl+7)>>3); break; + case 2: xsizbpl = ((xsizbpl+3)>>2); break; + case 4: xsizbpl = ((xsizbpl+1)>>1); break; } //Tests to see if xsiz > allocated space in olinbuf //Note: xsizbpl gets re-written inside initpass() @@ -1139,7 +1130,6 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, zlibcompflags = getbits(16); //Actually 2 fields: 8:compmethflags, 8:addflagscheck do { - numhufblocks++; bfinal = getbits(1); btype = getbits(2); if (btype == 0) { @@ -1170,6 +1160,7 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, } else //Dynamic Huffman { + numhufblocks++; hlit = getbits(5)+257; hdist = getbits(5)+1; j = getbits(4)+4; for (i=0; i= (unsigned)clipydim) { odc += (lcomphsamp[0]<<6); continue; } @@ -1463,7 +1453,7 @@ static void yrbrend(int32_t x, int32_t y) ox = x+xx+globxoffs; if ((unsigned)ox >= (unsigned)clipxdim) continue; p = pp+(xx<<2); dc = odc; - if (lnumcomponents > 1) dc2 = &dct[lcomphvsamp0][((yy>>lcompvsampshift0)<<3)+(xx>>lcomphsampshift0)]; + if (lnumcomponents > 1) dc2 = &ldct[(lcomphvsamp0<<6)+((yy>>lcompvsampshift0)<<3)+(xx>>lcomphsampshift0)]; xxxend = min(clipxdim-ox,8); yyyend = min(clipydim-oy,8); if ((lcomphsamp[0] == 1) && (xxxend == 8)) @@ -1473,8 +1463,8 @@ static void yrbrend(int32_t x, int32_t y) for (xxx=0; xxx<8; xxx++) { yv = dc[xxx]; - cr = (dc2[xxx+64]>>13)&~1; - cb = (dc2[xxx ]>>13)&~1; + cr = (dc2[xxx+64]>>(20-1))&~1; + cb = (dc2[xxx ]>>(20-1))&~1; ((int32_t *)p)[xxx] = colclipup16[(unsigned)(yv+crmul[cr+2048])>>22]+ colclipup8[(unsigned)(yv+crmul[cr+2049]+cbmul[cb+2048])>>22]+ colclip[(unsigned)(yv+cbmul[cb+2049])>>22]; @@ -1491,8 +1481,8 @@ static void yrbrend(int32_t x, int32_t y) for (xxx=0; xxx<8; xxx+=2) { yv = dc[xxx]; - cr = (dc2[(xxx>>1)+64]>>13)&~1; - cb = (dc2[(xxx>>1)]>>13)&~1; + cr = (dc2[(xxx>>1)+64]>>(20-1))&~1; + cb = (dc2[(xxx>>1)]>>(20-1))&~1; i = crmul[cr+2049]+cbmul[cb+2048]; cr = crmul[cr+2048]; cb = cbmul[cb+2049]; @@ -1521,8 +1511,8 @@ static void yrbrend(int32_t x, int32_t y) if (!j) { j = lcomphsamp[0]; - cr = (dc2[i+64]>>13)&~1; - cb = (dc2[i ]>>13)&~1; + cr = (dc2[i+64]>>(20-1))&~1; + cb = (dc2[i ]>>(20-1))&~1; i++; } ((int32_t *)p)[xxx] = colclipup16[(unsigned)(yv+crmul[cr+2048])>>22]+ @@ -1537,22 +1527,23 @@ static void yrbrend(int32_t x, int32_t y) } } } +void (*kplib_yrbrend_func)(int32_t,int32_t,int32_t *) = yrbrend; static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, intptr_t daframeplace, int32_t dabytesperline, int32_t daxres, int32_t dayres, int32_t daglobxoffs, int32_t daglobyoffs) { int32_t i, j, v, leng, xdim = 0, ydim = 0, index, prec, restartcnt, restartinterval; - int32_t x, y, z, xx, yy, zz, *dc = 0, num, curbits, c, daval, dabits, *hqval, *hqbits, hqcnt, *quanptr = 0; + int32_t x, y, z, xx, yy, zz, *dc = NULL, num, curbits, c, daval, dabits, *hqval, *hqbits, hqcnt, *quanptr = NULL; int32_t passcnt = 0, ghsampmax = 0, gvsampmax = 0, glhsampmax = 0, glvsampmax = 0, glhstep, glvstep; int32_t eobrun, Ss, Se, Ah, Al, Alut[2], dctx[12], dcty[12], ldctx[12], ldcty[12], lshx[4], lshy[4]; - int16_t *dctbuf = 0, *dctptr[12], *ldctptr[12], *dcs = 0; - char ch, marker, dcflag; - const char *kfileptr; + int16_t *dctbuf = 0, *dctptr[12], *ldctptr[12], *dcs = NULL; + uint8_t ch, marker, dcflag; + const uint8_t *kfileptr; if (!kpeginited) { kpeginited = 1; initkpeg(); } - kfileptr = (char *)kfilebuf; + kfileptr = (uint8_t *)kfilebuf; if (*(uint16_t *)kfileptr == SSWAPIB(0xd8ff)) kfileptr += 2; else return(-1); //"%s is not a JPEG file\n",filename @@ -1575,15 +1566,13 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, //printf("fileoffs=%08x, marker=%02x,leng=%d",((int32_t)kfileptr)-((int32_t)kfilebuf)-2,marker,leng); switch (marker) { - case 0xc0: - case 0xc1: - case 0xc2: + case 0xc0: case 0xc1: case 0xc2: //processit! kfileptr++; //numbits = *kfileptr++; ydim = SSWAPIL(*(uint16_t *)&kfileptr[0]); xdim = SSWAPIL(*(uint16_t *)&kfileptr[2]); - //printf("%s: %d / %d = %d\n",filename,xdim*ydim*3,kfilength,(xdim*ydim*3)/kfilength); + //printf("%s: %ld / %ld = %ld\n",filename,xdim*ydim*3,kfilength,(xdim*ydim*3)/kfilength); frameplace = daframeplace; bytesperline = dabytesperline; @@ -1655,7 +1644,6 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, v <<= 19; if (unzig[z]&7) v = mulshr24(v,cosqr16[unzig[z]&7 ]); if (unzig[z]>>3) v = mulshr24(v,cosqr16[unzig[z]>>3]); - if (index) v >>= 6; quantab[index][unzig[z]] = v; } leng -= 64; @@ -1697,7 +1685,7 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, } z = zz*64*sizeof(int16_t); dctbuf = (int16_t *)malloc(z); if (!dctbuf) return(-1); - memset(dctbuf,0,z); + Bmemset(dctbuf,0,z); for (z=zz=0; z= kfilength) goto kpegrend_break2; //rest of file is missing! + if (kfileptr-4-(uint8_t *)kfilebuf >= kfilength) goto kpegrend_break2; //rest of file is missing! if (!dctbuf) dc = dct[0]; for (c=0; c>lshy[c])*ldctx[c] + ((x+xx)>>lshx[c]))<<6]; @@ -1790,7 +1777,7 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, } //Get AC - if (!dctbuf) memset((void *)&dc[1],0,63*4); + if (!dctbuf) Bmemset((void *)&dc[1],0,63*4); z = max(Ss,1); dcflag = 1; if (eobrun <= 0) { @@ -1798,8 +1785,7 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, { while (curbits < 24) //Getbits { - ch = *kfileptr++; - if (ch == 255) kfileptr++; + ch = *kfileptr++; if (ch == 255) kfileptr++; num = (num<<8)+((int32_t)ch); curbits += 8; } i = ((num>>(curbits-10))&1023); @@ -1842,13 +1828,13 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, ch = *kfileptr++; if (ch == 255) kfileptr++; num = (num<<8)+((int32_t)ch); curbits += 8; } - if (num&(pow2long[--curbits])) dcs[z] += ((int16_t)Alut[dcs[z] < 0]); + if (num&(pow2long[--curbits])) dcs[z] += (int16_t)Alut[dcs[z] < 0]; } else if (--zz < 0) break; z++; } while (z <= Se); - if (daval) dcs[z] = daval; + if (daval) dcs[z] = (int16_t)daval; } else { @@ -1890,7 +1876,7 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, } } - if (!dctbuf) yrbrend(x,y); + if (!dctbuf) kplib_yrbrend_func(x,y,&dct[0][0]); restartcnt--; if (!restartcnt) @@ -1903,17 +1889,14 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, eobrun = 0; } } -kpegrend_break2: - ; +kpegrend_break2:; if (!dctbuf) return(0); passcnt++; kfileptr -= ((curbits>>3)+1); break; - case 0xd9: - break; - default: - kfileptr += leng; break; + case 0xd9: break; + default: kfileptr += leng; break; } } - while (kfileptr-(char *)kfilebuf < kfilength); + while (kfileptr-(uint8_t *)kfilebuf < kfilength); if (!dctbuf) return(0); @@ -1939,9 +1922,9 @@ kpegrend_break2: dcs = &dctptr[c][(((y+yy)>>lshy[c])*dctx[c] + ((x+xx)>>lshx[c]))<<6]; quanptr = &quantab[gcompquantab[c]][0]; for (z=0; z<64; z++) dc[z] = ((int32_t)dcs[zigit[z]])*quanptr[z]; - invdct8x8(dc,-1); + invdct8x8(dc,0xff); } - yrbrend(x,y); + kplib_yrbrend_func(x,y,&dct[0][0]); } free(dctbuf); return(0); @@ -1950,7 +1933,7 @@ kpegrend_break2: //============================== KPEGILIB ends ============================== //================================ GIF begins ================================ -static char suffix[4100], filbuffer[768], tempstack[4096]; +static uint8_t suffix[4100], filbuffer[768], tempstack[4096]; static int32_t prefix[4100]; static int32_t kgifrend(const char *kfilebuf, int32_t kfilelength, @@ -1959,9 +1942,10 @@ static int32_t kgifrend(const char *kfilebuf, int32_t kfilelength, { int32_t i, x, y, xsiz, ysiz, yinc, xend, xspan, yspan, currstr, numbitgoal; int32_t lzcols, dat, blocklen, bitcnt, xoff, transcol, backcol, *lptr; - char numbits, startnumbits, chunkind, ilacefirst; - const char *ptr, *cptr = 0; intptr_t yoff; + char numbits, startnumbits, chunkind, ilacefirst; + const uint8_t *ptr, *cptr; + UNREFERENCED_PARAMETER(kfilelength); coltype = 3; bitdepth = 8; //For PNGOUT @@ -1969,12 +1953,11 @@ static int32_t kgifrend(const char *kfilebuf, int32_t kfilelength, if ((kfilebuf[0] != 'G') || (kfilebuf[1] != 'I') || (kfilebuf[2] != 'F') || (kfilebuf[12])) return(-1); paleng = (1<<((kfilebuf[10]&7)+1)); - ptr = (char *)&kfilebuf[13]; + ptr = (uint8_t *)&kfilebuf[13]; if (kfilebuf[10]&128) { cptr = ptr; ptr += paleng*3; } transcol = -1; while ((chunkind = *ptr++) == '!') - { - //! 0xf9 leng flags ?? ?? transcol + { //! 0xf9 leng flags ?? ?? transcol if (ptr[0] == 0xf9) { if (ptr[2]&1) transcol = (int32_t)(((uint8_t)ptr[5])); } ptr++; do { i = *ptr++; ptr += i; } @@ -2078,14 +2061,10 @@ static int32_t kgifrend(const char *kfilebuf, int32_t kfilelength, if (y >= yspan) switch (yinc) { - case 8: - if (!ilacefirst) { y = daglobyoffs+2; yinc = 4; break; } + case 8: if (!ilacefirst) { y = daglobyoffs+2; yinc = 4; break; } ilacefirst = 0; y = daglobyoffs+4; yinc = 8; break; - case 4: - y = daglobyoffs+1; yinc = 2; break; - case 2: - case 1: - return(0); + case 4: y = daglobyoffs+1; yinc = 2; break; + case 2: case 1: return(0); } if ((uint32_t)y < (uint32_t)dayres) { yoff = y*dabytesperline+daframeplace; x = daglobxoffs; xend = xspan; } @@ -2101,7 +2080,7 @@ static int32_t kgifrend(const char *kfilebuf, int32_t kfilelength, //============================== CEL begins ================================= // //old .CEL format: -//short id = 0x9119, xdim, ydim, xoff, yoff, id = 0x0008; +//int16_t id = 0x9119, xdim, ydim, xoff, yoff, id = 0x0008; //int32_t imagebytes, filler[4]; //char pal6bit[256][3], image[ydim][xdim]; static int32_t kcelrend(const char *buf, int32_t fleng, @@ -2113,10 +2092,6 @@ static int32_t kcelrend(const char *buf, int32_t fleng, UNREFERENCED_PARAMETER(fleng); UNREFERENCED_PARAMETER(daglobxoffs); - UNREFERENCED_PARAMETER(daglobyoffs); - - if ((buf[0] != 0x19) || (buf[1] != 0x91) || - (buf[10] != 8) || (buf[11] != 0)) return(-1); coltype = 3; bitdepth = 8; paleng = 256; //For PNGOUT @@ -2151,17 +2126,18 @@ static int32_t ktgarend(const char *header, int32_t fleng, intptr_t daframeplace, int32_t dabytesperline, int32_t daxres, int32_t dayres, int32_t daglobxoffs, int32_t daglobyoffs) { - int32_t i = 0, x, y, pi, xi, yi, x0, x1, y0, y1, xsiz, ysiz, rlestat, colbyte, pixbyte; - const char *fptr = 0, *cptr = 0, *nptr = 0; + int32_t i, x, y, pi, xi, yi, x0, x1, y0, y1, xsiz, ysiz, rlestat, colbyte, pixbyte; intptr_t p; + const uint8_t *fptr, *cptr, *nptr; + //Ugly and unreliable identification for .TGA! if ((fleng < 20) || (header[1]&0xfe)) return(-1); if ((header[2] >= 12) || (!((1< 32)) return(-1); if (header[17]&0xc0) return(-1); - fptr = (char *)&header[header[0]+18]; + fptr = (uint8_t *)&header[header[0]+18]; xsiz = (int32_t)SSWAPIB(*(uint16_t *)&header[12]); if (xsiz <= 0) return(-1); ysiz = (int32_t)SSWAPIB(*(uint16_t *)&header[14]); if (ysiz <= 0) return(-1); colbyte = ((((int32_t)header[16])+7)>>3); @@ -2176,14 +2152,10 @@ static int32_t ktgarend(const char *header, int32_t fleng, switch (pixbyte) //For PNGOUT { - case 1: - coltype = 0; bitdepth = 8; palcol[0] = LSWAPIB(0xff000000); + case 1: coltype = 0; bitdepth = 8; palcol[0] = LSWAPIB(0xff000000); for (i=1; i<256; i++) palcol[i] = palcol[i-1]+LSWAPIB(0x10101); break; - case 2: - case 3: - coltype = 2; break; - case 4: - coltype = 6; break; + case 2: case 3: coltype = 2; break; + case 4: coltype = 6; break; } if (!(header[17]&16)) { x0 = 0; x1 = xsiz; xi = 1; } @@ -2211,16 +2183,12 @@ static int32_t ktgarend(const char *header, int32_t fleng, switch (pixbyte) { - case 1: - i = palcol[(int32_t)nptr[0]]; break; - case 2: - i = (int32_t)SSWAPIB(*(uint16_t *)&nptr[0]); + case 1: i = palcol[(int32_t)nptr[0]]; break; + case 2: i = (int32_t)SSWAPIB(*(uint16_t *)&nptr[0]); i = LSWAPIB(((i&0x7c00)<<9) + ((i&0x03e0)<<6) + ((i&0x001f)<<3) + 0xff000000); break; - case 3: - i = (*(int32_t *)&nptr[0]) | LSWAPIB(0xff000000); break; - case 4: - i = (*(int32_t *)&nptr[0]); break; + case 3: i = (*(int32_t *)&nptr[0]) | LSWAPIB(0xff000000); break; + case 4: i = (*(int32_t *)&nptr[0]); break; } fptr += colbyte; } @@ -2291,17 +2259,15 @@ static int32_t kbmprend(const char *buf, int32_t fleng, if (headsiz == LSWAPIB(12)) j = 3; else j = 4; for (i=0,cptr=&buf[headsiz+14]; cptr<&buf[rastoff]; i++,cptr+=j) palcol[i] = ((*(int32_t *)&cptr[0])|LSWAPIB(0xff000000)); - coltype = 3; bitdepth = cdim; paleng = i; //For PNGOUT + coltype = 3; bitdepth = (int8_t)cdim; paleng = i; //For PNGOUT } else if (!(cdim&15)) { coltype = 2; switch (cdim) { - case 16: - palcol[0] = 10; palcol[1] = 5; palcol[2] = 0; palcol[3] = 5; palcol[4] = 5; palcol[5] = 5; break; - case 32: - palcol[0] = 16; palcol[1] = 8; palcol[2] = 0; palcol[3] = 8; palcol[4] = 8; palcol[5] = 8; break; + case 16: palcol[0] = 10; palcol[1] = 5; palcol[2] = 0; palcol[3] = 5; palcol[4] = 5; palcol[5] = 5; break; + case 32: palcol[0] = 16; palcol[1] = 8; palcol[2] = 0; palcol[3] = 8; palcol[4] = 8; palcol[5] = 8; break; } if (comp == 3) //BI_BITFIELD (RGB masks) { @@ -2343,32 +2309,24 @@ static int32_t kbmprend(const char *buf, int32_t fleng, lptr = (int32_t *)(y*dabytesperline-(daglobyoffs<<2)+daframeplace); switch (cdim) { - case 1: - for (x=x0; x>3]>>((x&7)^7))&1)]; break; - case 4: - for (x=x0; x>1]>>(((x&1)^1)<<2))&15)]; break; - case 8: - for (x=x0; x>3]>>((x&7)^7))&1)]; break; + case 4: for (x=x0; x>1]>>(((x&1)^1)<<2))&15)]; break; + case 8: for (x=x0; x xsiz) { daxres = min(daxres,x1); x1 += bpl-xsiz; } + j = nplanes-1; daxres <<= 2; x0 <<= 2; x1 <<= 2; x <<= 2; x += j; if (nplanes == 1) //8-bit PCX { @@ -2465,10 +2422,10 @@ static int32_t kpcxrend(const char *buf, int32_t fleng, static int32_t kddsrend(const char *buf, int32_t leng, intptr_t frameptr, int32_t bpl, int32_t xdim, int32_t ydim, int32_t xoff, int32_t yoff) { - int32_t x = 0, y = 0, z = 0, xx, yy, xsiz, ysiz, dxt, al[2], ai, k, v, c0, c1, stride; - uint32_t lut[256], r[4], g[4], b[4], a[8], rr, gg, bb; - char *uptr, *wptr; + int32_t x, y, z, xx, yy, xsiz, ysiz, dxt, al[2], ai, k, v, c0, c1, stride; intptr_t j; + uint32_t lut[256], r[4], g[4], b[4], a[8], rr, gg, bb; + uint8_t *uptr, *wptr; UNREFERENCED_PARAMETER(leng); @@ -2476,11 +2433,11 @@ static int32_t kddsrend(const char *buf, int32_t leng, ysiz = LSWAPIB(*(int32_t *)&buf[12]); if ((*(int32_t *)&buf[80])&LSWAPIB(64)) //Uncompressed supports only A8R8G8B8 for now { - if ((*(int32_t *)&buf[88]) != (signed)LSWAPIB(32)) return(-1); - if ((*(int32_t *)&buf[92]) != (signed)LSWAPIB(0x00ff0000)) return(-1); - if ((*(int32_t *)&buf[96]) != (signed)LSWAPIB(0x0000ff00)) return(-1); - if ((*(int32_t *)&buf[100]) != (signed)LSWAPIB(0x000000ff)) return(-1); - if ((*(int32_t *)&buf[104]) != (signed)LSWAPIB(0xff000000)) return(-1); + if ((*(int32_t *)&buf[88]) != LSWAPIB(32)) return(-1); + if ((*(int32_t *)&buf[92]) != LSWAPIB(0x00ff0000)) return(-1); + if ((*(int32_t *)&buf[96]) != LSWAPIB(0x0000ff00)) return(-1); + if ((*(int32_t *)&buf[100]) != LSWAPIB(0x000000ff)) return(-1); + if ((*(uint32_t *)&buf[104]) != LSWAPIB(0xff000000)) return(-1); buf += 128; j = yoff*bpl + (xoff<<2) + frameptr; xx = (xsiz<<2); @@ -2508,8 +2465,8 @@ static int32_t kddsrend(const char *buf, int32_t leng, for (y=0; y>8)&0xf8); g[0] = ((c0>>3)&0xfc); b[0] = ((c0<<3)&0xfc); a[0] = 255; c1 = SSWAPIB(*(uint16_t *)&uptr[2]); @@ -2548,7 +2505,7 @@ static int32_t kddsrend(const char *buf, int32_t leng, al[0] = LSWAPIB(*(int32_t *)&uptr[-6]); al[1] = LSWAPIB(*(int32_t *)&uptr[-3]); } - wptr = (char *)((y+yoff)*bpl + ((x+xoff)<<2) + frameptr); + wptr = (uint8_t *)((y+yoff)*bpl + ((x+xoff)<<2) + frameptr); ai = 0; for (yy=0; yy<4; yy++,wptr+=bpl) { @@ -2560,14 +2517,9 @@ static int32_t kddsrend(const char *buf, int32_t leng, j = ((v>>(ai<<1))&3); switch (dxt) { - case 1: - z = a[j]; break; - case 2: - case 3: - z = ((uptr[(ai>>1)-8] >> ((xx&1)<<2))&15)*17; break; - case 4: - case 5: - z = a[(al[yy>>1] >> ((ai&7)*3))&7]; break; + case 1: z = a[j]; break; + case 2: case 3: z = ((uptr[(ai>>1)-8] >> ((xx&1)<<2))&15)*17; break; + case 4: case 5: z = a[(al[yy>>1] >> ((ai&7)*3))&7]; break; } rr = r[j]; gg = g[j]; bb = b[j]; if (!(dxt&1)) @@ -2576,10 +2528,10 @@ static int32_t kddsrend(const char *buf, int32_t leng, gg = min((gg*lut[z])>>16,255); rr = min((rr*lut[z])>>16,255); } - wptr[(xx<<2)+0] = bb; - wptr[(xx<<2)+1] = gg; - wptr[(xx<<2)+2] = rr; - wptr[(xx<<2)+3] = z; + wptr[(xx<<2)+0] = (uint8_t)bb; + wptr[(xx<<2)+1] = (uint8_t)gg; + wptr[(xx<<2)+2] = (uint8_t)rr; + wptr[(xx<<2)+3] = (uint8_t)z; } } } @@ -2592,8 +2544,8 @@ static int32_t kddsrend(const char *buf, int32_t leng, void kpgetdim(const char *buf, int32_t leng, int32_t *xsiz, int32_t *ysiz) { int32_t *lptr; - const char *cptr; - char *ubuf = (char *)buf; + const uint8_t *cptr; + uint8_t *ubuf = (uint8_t *)buf; (*xsiz) = (*ysiz) = 0; if (leng < 16) return; if ((ubuf[0] == 0x89) && (ubuf[1] == 0x50)) //.PNG @@ -2605,15 +2557,15 @@ void kpgetdim(const char *buf, int32_t leng, int32_t *xsiz, int32_t *ysiz) { if (lptr[1] == LSWAPIB(0x52444849)) //IHDR {(*xsiz) = LSWAPIL(lptr[2]); (*ysiz) = LSWAPIL(lptr[3]); break; } - lptr = (int32_t *)((intptr_t)lptr + LSWAPIL(lptr[0]) + 12); + lptr = (int32_t *)((int32_t)lptr + LSWAPIL(lptr[0]) + 12); } } else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)) //.JPG { - cptr = (char *)&buf[2]; + cptr = (uint8_t *)&buf[2]; while (((uintptr_t)cptr-(uintptr_t)buf) < (uintptr_t)(leng-8)) { - if (cptr[0] != 255) { cptr = &cptr[1]; continue; } + if ((cptr[0] != 0xff) || (cptr[1] == 0xff)) { cptr++; continue; } if ((uint32_t)(cptr[1]-0xc0) < 3) { (*ysiz) = SSWAPIL(*(uint16_t *)&cptr[5]); @@ -2659,8 +2611,7 @@ void kpgetdim(const char *buf, int32_t leng, int32_t *xsiz, int32_t *ysiz) (*ysiz) = LSWAPIB(*(int32_t *)&buf[12]); } else - { - //Unreliable .TGA identification - this MUST be final case! + { //Unreliable .TGA identification - this MUST be final case! if ((leng >= 20) && (!(ubuf[1]&0xfe))) if ((ubuf[2] < 12) && ((1< kzhashsiz) //Make sure string fits in kzhashbuf { @@ -2809,17 +2760,19 @@ static int32_t kzcalchash(const char *st) return(hashind%(sizeof(kzhashead)/sizeof(kzhashead[0]))); } -static int32_t kzcheckhash(const char *filnam, char **zipnam, int32_t *zipseek) +static int32_t kzcheckhash(const char *filnam, char **zipnam, int32_t *fileoffs, int32_t *fileleng, char *iscomp) { int32_t i; if (!kzhashbuf) return(0); if (filnam[0] == '|') filnam++; for (i=kzhashead[kzcalchash(filnam)]; i>=0; i=(*(int32_t *)&kzhashbuf[i])) - if (!filnamcmp(filnam,&kzhashbuf[i+16])) + if (!filnamcmp(filnam,&kzhashbuf[i+21])) { (*zipnam) = &kzhashbuf[*(int32_t *)&kzhashbuf[i+8]]; - (*zipseek) = *(int32_t *)&kzhashbuf[i+12]; + (*fileoffs) = *(int32_t *)&kzhashbuf[i+12]; + (*fileleng) = *(int32_t *)&kzhashbuf[i+16]; + (*iscomp) = kzhashbuf[i+20]; return(1); } return(0); @@ -2828,80 +2781,134 @@ static int32_t kzcheckhash(const char *filnam, char **zipnam, int32_t *zipseek) void kzuninit() { if (kzhashbuf) { free(kzhashbuf); kzhashbuf = 0; } - kzhashpos = kzhashsiz = 0; + kzhashpos = kzhashsiz = 0; kzdirnamhead = -1; } -//Load ZIP directory into memory (hash) to allow fast access later -int32_t kzaddstack(const char *zipnam) +//If file found, loads internal directory from ZIP/GRP into Bmemory (hash) to allow faster access later +//If file not found, assumes it's a directory and adds it to an internal list +int32_t kzaddstack(const char *filnam) { FILE *fil; - int32_t i, j, hashind, zipnamoffs, numfiles; + int32_t i, j, k, leng, hashind, zipnamoffs, numfiles; char tempbuf[260+46]; - fil = fopen(zipnam,"rb"); if (!fil) return(-1); + fil = fopen(filnam,"rb"); + if (!fil) //if file not found, assume it's a directory + { + //Add directory name to internal list (using kzhashbuf for convenience of dynamic allocation) + i = strlen(filnam)+5; if (!kzcheckhashsiz(i)) return(-1); + *(int32_t *)&kzhashbuf[kzhashpos] = kzdirnamhead; kzdirnamhead = kzhashpos; + strcpy(&kzhashbuf[kzhashpos+4],filnam); + kzhashpos += i; - //Write ZIP filename to hash - i = strlen(zipnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } - strcpy(&kzhashbuf[kzhashpos],zipnam); + return(-1); + } + + //Write ZIP/GRP filename to hash + i = strlen(filnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } + strcpy(&kzhashbuf[kzhashpos],filnam); zipnamoffs = kzhashpos; kzhashpos += i; - fseek(fil,-22,SEEK_END); - fread(tempbuf,22,1,fil); - if (*(int32_t *)&tempbuf[0] == LSWAPIB(0x06054b50)) //Fast way of finding dir info + fread(&i,4,1,fil); + if (i == LSWAPIB(0x04034b50)) //'PK\3\4' is ZIP file id { - numfiles = SSWAPIB(*(int16_t *)&tempbuf[10]); - fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[16]),SEEK_SET); - } - else //Slow way of finding dir info (used when ZIP has junk at end) - { - fseek(fil,0,SEEK_SET); numfiles = 0; - while (1) + fseek(fil,-22,SEEK_END); + fread(tempbuf,22,1,fil); + if (*(int32_t *)&tempbuf[0] == LSWAPIB(0x06054b50)) //Fast way of finding dir info { - if (!fread(&j,4,1,fil)) { numfiles = -1; break; } - if (j == LSWAPIB(0x02014b50)) break; //Found central file header :) - if (j != LSWAPIB(0x04034b50)) { numfiles = -1; break; } - fread(tempbuf,26,1,fil); - fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[14]) + SSWAPIB(*(int16_t *)&tempbuf[24]) + SSWAPIB(*(int16_t *)&tempbuf[22]),SEEK_CUR); - numfiles++; + numfiles = SSWAPIB(*(int16_t *)&tempbuf[10]); + fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[16]),SEEK_SET); + } + else //Slow way of finding dir info (used when ZIP has junk at end) + { + fseek(fil,0,SEEK_SET); numfiles = 0; + while (1) + { + if (!fread(&j,4,1,fil)) { numfiles = -1; break; } + if (j == LSWAPIB(0x02014b50)) break; //Found central file header :) + if (j != LSWAPIB(0x04034b50)) { numfiles = -1; break; } + fread(tempbuf,26,1,fil); + fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[14]) + SSWAPIB(*(int16_t *)&tempbuf[24]) + SSWAPIB(*(int16_t *)&tempbuf[22]),SEEK_CUR); + numfiles++; + } + if (numfiles < 0) { fclose(fil); return(-1); } + fseek(fil,-4,SEEK_CUR); + } + for (i=0; i 2GB-32K bytes - gslidew = 0x7fffffff; //Force reload at beginning - + kzfs.fil = fil; + kzfs.comptyp = 0; + kzfs.seek0 = fileoffs; + kzfs.leng = fileleng; + kzfs.pos = 0; + kzfs.i = 0; return((intptr_t)kzfs.fil); - default: - fclose(kzfs.fil); kzfs.fil = 0; return(0); + } + else + { + fread(tempbuf,30,1,fil); + if (*(int32_t *)&tempbuf[0] != LSWAPIB(0x04034b50)) { fclose(fil); return(0); } + fseek(fil,SSWAPIB(*(int16_t *)&tempbuf[26])+SSWAPIB(*(int16_t *)&tempbuf[28]),SEEK_CUR); + + kzfs.fil = fil; + kzfs.comptyp = SSWAPIB(*(int16_t *)&tempbuf[8]); + kzfs.seek0 = ftell(fil); + kzfs.leng = LSWAPIB(*(int32_t *)&tempbuf[22]); + kzfs.pos = 0; + switch (kzfs.comptyp) //Compression method + { + case 0: kzfs.i = 0; return((intptr_t)kzfs.fil); + case 8: + if (!pnginited) { pnginited = 1; initpngtables(); } + kzfs.comptell = 0; + kzfs.compleng = LSWAPIB(*(int32_t *)&tempbuf[18]); + + //WARNING: No file in ZIP can be > 2GB-32K bytes + gslidew = 0x7fffffff; //Force reload at beginning + + return((intptr_t)kzfs.fil); + default: fclose(kzfs.fil); kzfs.fil = 0; return(0); + } } } + + //Finally, check mounted dirs + for (i=kzdirnamhead; i>=0; i=*(int32_t *)&kzhashbuf[i]) + { + strcpy(tempbuf,&kzhashbuf[i+4]); + j = strlen(tempbuf); + if (strlen(filnam)+1+j >= sizeof(tempbuf)) continue; //don't allow int32_t filenames to buffer overrun + if ((j) && (tempbuf[j-1] != '/') && (tempbuf[j-1] != '\\') && (filnam[0] != '/') && (filnam[0] != '\\')) +#if (defined(__DOS__) || defined(_WIN32)) + strcat(tempbuf,"\\"); +#else + strcat(tempbuf,"/"); +#endif + strcat(tempbuf,filnam); + kzfs.fil = fopen(tempbuf,"rb"); + if (kzfs.fil) + { + kzfs.comptyp = 0; + kzfs.seek0 = 0; + kzfs.leng = filelength(_fileno(kzfs.fil)); + kzfs.pos = 0; + kzfs.i = 0; + return((intptr_t)kzfs.fil); + } + } + return(0); } // -------------------------------------------------------------------------- -static int32_t srchstat = -1, wildstpathleng; - #if defined(__DOS__) -static char wildst[260] = ""; +#define MAX_PATH 260 static struct find_t findata; #elif defined(_WIN32) -static char wildst[MAX_PATH] = ""; static HANDLE hfind = INVALID_HANDLE_VALUE; static WIN32_FIND_DATA findata; #else -static char wildst[260] = ""; +#define MAX_PATH 260 static DIR *hfind = NULL; static struct dirent *findata = NULL; #endif +//File find state variables. Example sequence (read top->bot, left->right): +// srchstat srchzoff srchdoff +// 0,1,2,3 +// 500,200,-1 +// 4 300 +// 0,1,2,3,4 100 +// 0,1,2,3,4 -1 +static int32_t srchstat = -1, srchzoff = 0, srchdoff = -1, wildstpathleng; +static char wildst[MAX_PATH] = "", newildst[MAX_PATH] = ""; + void kzfindfilestart(const char *st) { #if defined(__DOS__) @@ -2973,42 +3024,43 @@ void kzfindfilestart(const char *st) #else if (hfind) { closedir(hfind); hfind = NULL; } #endif - strcpy(wildst,st); - srchstat = -3; + strcpy(wildst,st); strcpy(newildst,st); + srchstat = 0; srchzoff = kzlastfnam; srchdoff = kzdirnamhead; } int32_t kzfindfile(char *filnam) { int32_t i; +kzfindfile_beg:; filnam[0] = 0; - if (srchstat == -3) + if (srchstat == 0) { - if (!wildst[0]) { srchstat = -1; return(0); } + if (!newildst[0]) { srchstat = -1; return(0); } do { - srchstat = -2; + srchstat = 1; //Extract directory from wildcard string for pre-pending wildstpathleng = 0; - for (i=0; wildst[i]; i++) - if ((wildst[i] == '/') || (wildst[i] == '\\')) + for (i=0; newildst[i]; i++) + if ((newildst[i] == '/') || (newildst[i] == '\\')) wildstpathleng = i+1; - Bmemcpy(filnam,wildst,wildstpathleng); + Bmemcpy(filnam,newildst,wildstpathleng); #if defined(__DOS__) - if (_dos_findfirst(wildst,_A_SUBDIR,&findata)) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; } + if (_dos_findfirst(newildst,_A_SUBDIR,&findata)) + { if (!kzhashbuf) return(0); srchstat = 2; continue; } i = wildstpathleng; if (findata.attrib&16) if ((findata.name[0] == '.') && (!findata.name[1])) continue; strcpy(&filnam[i],findata.name); if (findata.attrib&16) strcat(&filnam[i],"\\"); #elif defined(_WIN32) - hfind = FindFirstFile(wildst,&findata); + hfind = FindFirstFile(newildst,&findata); if (hfind == INVALID_HANDLE_VALUE) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; } + { if (!kzhashbuf) return(0); srchstat = 2; continue; } if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; i = wildstpathleng; if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) @@ -3025,21 +3077,22 @@ int32_t kzfindfile(char *filnam) s = filnam; } hfind = opendir(s); - if (!hfind) { if (!kzhashbuf) return 0; srchstat = kzlastfnam; continue; } + if (!hfind) { if (!kzhashbuf) return 0; srchstat = 2; continue; } } - break; // process srchstat == -2 + break; // process srchstat == 1 #endif return(1); } while (0); } - if (srchstat == -2) + if (srchstat == 1) + { while (1) { - Bmemcpy(filnam,wildst,wildstpathleng); + Bmemcpy(filnam,newildst,wildstpathleng); #if defined(__DOS__) if (_dos_findnext(&findata)) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; } + { if (!kzhashbuf) return(0); srchstat = 2; break; } i = wildstpathleng; if (findata.attrib&16) if ((findata.name[0] == '.') && (!findata.name[1])) continue; @@ -3047,7 +3100,7 @@ int32_t kzfindfile(char *filnam) if (findata.attrib&16) strcat(&filnam[i],"\\"); #elif defined(_WIN32) if (!FindNextFile(hfind,&findata)) - { FindClose(hfind); hfind = INVALID_HANDLE_VALUE; if (!kzhashbuf) return(0); /* srchstat = kzlastfnam; */ break; } + { FindClose(hfind); if (!kzhashbuf) return(0); srchstat = 2; break; } if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; i = wildstpathleng; if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) @@ -3056,30 +3109,48 @@ int32_t kzfindfile(char *filnam) if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\"); #else if ((findata = readdir(hfind)) == NULL) - { closedir(hfind); hfind = NULL; if (!kzhashbuf) return 0; srchstat = kzlastfnam; break; } + { closedir(hfind); hfind = NULL; if (!kzhashbuf) return 0; srchstat = 2; break; } i = wildstpathleng; if (findata->d_type == DT_DIR) { if (findata->d_name[0] == '.' && !findata->d_name[1]) continue; } //skip . else if ((findata->d_type == DT_REG) || (findata->d_type == DT_LNK)) { if (findata->d_name[0] == '.') continue; } //skip hidden (dot) files else continue; //skip devices and fifos and such - if (!wildmatch(findata->d_name,&wildst[wildstpathleng])) continue; + if (!wildmatch(findata->d_name,&newildst[wildstpathleng])) continue; strcpy(&filnam[i],findata->d_name); if (findata->d_type == DT_DIR) strcat(&filnam[i],"/"); #endif return(1); } - while (srchstat >= 0) + } + while (srchstat == 2) { - if (wildmatch(&kzhashbuf[srchstat+16],wildst)) + if (srchzoff < 0) { srchstat = 3; break; } + if (wildmatch(&kzhashbuf[srchzoff+21],newildst)) { - //strcpy(filnam,&kzhashbuf[srchstat+16]); - filnam[0] = '|'; strcpy(&filnam[1],&kzhashbuf[srchstat+16]); - srchstat = *(int32_t *)&kzhashbuf[srchstat+4]; + //strcpy(filnam,&kzhashbuf[srchzoff+21]); + filnam[0] = '|'; strcpy(&filnam[1],&kzhashbuf[srchzoff+21]); + srchzoff = *(int32_t *)&kzhashbuf[srchzoff+4]; return(1); } - srchstat = *(int32_t *)&kzhashbuf[srchstat+4]; + srchzoff = *(int32_t *)&kzhashbuf[srchzoff+4]; } + while (srchstat == 3) + { + if (srchdoff < 0) { srchstat = -1; break; } + strcpy(newildst,&kzhashbuf[srchdoff+4]); + i = strlen(newildst); + if ((i) && (newildst[i-1] != '/') && (newildst[i-1] != '\\') && (filnam[0] != '/') && (filnam[0] != '\\')) +#if (defined(__DOS__) || defined(_WIN32)) + strcat(newildst,"\\"); +#else + strcat(newildst,"/"); +#endif + strcat(newildst,wildst); + srchdoff = *(int32_t *)&kzhashbuf[srchdoff]; + srchstat = 0; goto kzfindfile_beg; + } + return(0); } @@ -3094,7 +3165,7 @@ int32_t kzfindfile(char *filnam) // -------------------------------------------------------------------------- static char *gzbufptr; -static void putbuf4zip(const char *buf, int32_t uncomp0, int32_t uncomp1) +static void putbuf4zip(const uint8_t *buf, int32_t uncomp0, int32_t uncomp1) { int32_t i0, i1; // uncomp0 ... uncomp1 @@ -3167,17 +3238,12 @@ int32_t kzread(void *buffer, int32_t leng) switch (kzfs.jmpplc) { - case 0: - goto kzreadplc0; - case 1: - goto kzreadplc1; - case 2: - goto kzreadplc2; - case 3: - goto kzreadplc3; + case 0: goto kzreadplc0; + case 1: goto kzreadplc1; + case 2: goto kzreadplc2; + case 3: goto kzreadplc3; } -kzreadplc0: - ; +kzreadplc0:; do { bfinal = getbits(1); btype = getbits(2); @@ -3217,8 +3283,7 @@ kzreadplc0: { kzfs.jmpplc = 1; kzfs.i = i; kzfs.bfinal = bfinal; goto retkzread; -kzreadplc1: - ; i = kzfs.i; bfinal = kzfs.bfinal; +kzreadplc1:; i = kzfs.i; bfinal = kzfs.bfinal; } } slidebuf[(gslidew++)&32767] = (uint8_t)getbits(8); @@ -3272,8 +3337,7 @@ kzreadplc1: if (gslider-16384 >= kzfs.endpos) { kzfs.jmpplc = 2; kzfs.bfinal = bfinal; goto retkzread; -kzreadplc2: - ; bfinal = kzfs.bfinal; +kzreadplc2:; bfinal = kzfs.bfinal; } } @@ -3303,12 +3367,10 @@ kzreadplc2: putbuf4zip(&slidebuf[gslider&32767],gslider,gslidew&~32767); putbuf4zip(slidebuf,gslidew&~32767,gslidew); } -kzreadplc3: - ; kzfs.jmpplc = 3; +kzreadplc3:; kzfs.jmpplc = 3; } -retkzread: - ; +retkzread:; i = kzfs.pos; kzfs.pos += leng; if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; return(kzfs.pos-i); @@ -3327,13 +3389,9 @@ int32_t kzseek(int32_t offset, int32_t whence) if (!kzfs.fil) return(-1); switch (whence) { - case SEEK_CUR: - kzfs.pos += offset; break; - case SEEK_END: - kzfs.pos = kzfs.leng+offset; break; - case SEEK_SET: - default: - kzfs.pos = offset; + case SEEK_CUR: kzfs.pos += offset; break; + case SEEK_END: kzfs.pos = kzfs.leng+offset; break; +case SEEK_SET: default: kzfs.pos = offset; } if (kzfs.pos < 0) kzfs.pos = 0; if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 77cb8bf7c..e12d0897e 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -85,12 +85,12 @@ void freevbos() } } - if (allocvbos) - { - bglDeleteBuffersARB(allocvbos, indexvbos); - bglDeleteBuffersARB(allocvbos, vertvbos); - allocvbos = 0; - } + if (allocvbos) + { + bglDeleteBuffersARB(allocvbos, indexvbos); + bglDeleteBuffersARB(allocvbos, vertvbos); + allocvbos = 0; + } } void freeallmodels() @@ -1458,7 +1458,9 @@ static void md3postload(md3model_t* m) m->head.frames[framei].max.x = frameverts[verti].x; m->head.frames[framei].max.y = frameverts[verti].y; m->head.frames[framei].max.z = frameverts[verti].z; - } else { + } + else + { if (m->head.frames[framei].min.x > frameverts[verti].x) m->head.frames[framei].min.x = frameverts[verti].x; if (m->head.frames[framei].max.x < frameverts[verti].x) @@ -2354,11 +2356,11 @@ static void addquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, for (yy=0; yymytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x], - &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - (x+(VOXBORDWIDTH<<1))<<2); + &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], + (x+(VOXBORDWIDTH<<1))<<2); Bmemcpy(&gvox->mytex[(shp[z].y+y+yy+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - &gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - (x+(VOXBORDWIDTH<<1))<<2); + &gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], + (x+(VOXBORDWIDTH<<1))<<2); } qptr = &gvox->quad[gvox->qcnt]; diff --git a/polymer/eduke32/build/src/nedmalloc.c b/polymer/eduke32/build/src/nedmalloc.c index 17d0d653b..40d6bbe12 100644 --- a/polymer/eduke32/build/src/nedmalloc.c +++ b/polymer/eduke32/build/src/nedmalloc.c @@ -35,28 +35,28 @@ DEALINGS IN THE SOFTWARE. #include "nedmalloc.h" #ifdef _WIN32 - #include - #include +#include +#include #endif #define MSPACES 1 #define ONLY_MSPACES 1 #ifndef USE_LOCKS - #define USE_LOCKS 1 +#define USE_LOCKS 1 #endif #define FOOTERS 1 /* Need to enable footers so frees lock the right mspace */ #if defined(DEBUG) && !defined(_DEBUG) - #define _DEBUG +#define _DEBUG #elif !defined(NDEBUG) && !defined(DEBUG) && !defined(_DEBUG) - #define NDEBUG +#define NDEBUG #endif #undef DEBUG /* dlmalloc wants DEBUG either 0 or 1 */ #ifdef _DEBUG - #define DEBUG 1 +#define DEBUG 1 #else - #define DEBUG 0 +#define DEBUG 0 #endif #ifdef NDEBUG /* Disable assert checking on release builds */ - #undef DEBUG +#undef DEBUG #endif /* The default of 64Kb means we spend too much time kernel-side */ #ifndef DEFAULT_GRANULARITY @@ -68,7 +68,7 @@ DEALINGS IN THE SOFTWARE. /*#define FORCEINLINE*/ #include "malloc.c.h" #ifdef NDEBUG /* Disable assert checking on release builds */ - #undef DEBUG +#undef DEBUG #endif #if defined(__GNUC__) && defined(DEBUG) #warning DEBUG is defined so allocator will run with assert checking! Define NDEBUG to run at full speed. @@ -86,7 +86,7 @@ DEALINGS IN THE SOFTWARE. #ifndef THREADCACHEMAX #define THREADCACHEMAX 8192 #endif -#if 0 +#if 1 /* The number of cache entries for finer grained bins. This is (topbitpos(THREADCACHEMAX)-4)*2 */ #define THREADCACHEMAXBINS ((13-4)*2) #else @@ -100,27 +100,27 @@ DEALINGS IN THE SOFTWARE. #ifdef WIN32 - #define TLSVAR DWORD - #define TLSALLOC(k) (*(k)=TlsAlloc(), TLS_OUT_OF_INDEXES==*(k)) - #define TLSFREE(k) (!TlsFree(k)) - #define TLSGET(k) TlsGetValue(k) - #define TLSSET(k, a) (!TlsSetValue(k, a)) - #ifdef DEBUG +#define TLSVAR DWORD +#define TLSALLOC(k) (*(k)=TlsAlloc(), TLS_OUT_OF_INDEXES==*(k)) +#define TLSFREE(k) (!TlsFree(k)) +#define TLSGET(k) TlsGetValue(k) +#define TLSSET(k, a) (!TlsSetValue(k, a)) +#ifdef DEBUG static LPVOID ChkedTlsGetValue(DWORD idx) { - LPVOID ret=TlsGetValue(idx); - assert(S_OK==GetLastError()); - return ret; + LPVOID ret=TlsGetValue(idx); + assert(S_OK==GetLastError()); + return ret; } - #undef TLSGET - #define TLSGET(k) ChkedTlsGetValue(k) - #endif +#undef TLSGET +#define TLSGET(k) ChkedTlsGetValue(k) +#endif #else - #define TLSVAR pthread_key_t - #define TLSALLOC(k) pthread_key_create(k, 0) - #define TLSFREE(k) pthread_key_delete(k) - #define TLSGET(k) pthread_getspecific(k) - #define TLSSET(k, a) pthread_setspecific(k, a) +#define TLSVAR pthread_key_t +#define TLSALLOC(k) pthread_key_create(k, 0) +#define TLSFREE(k) pthread_key_delete(k) +#define TLSGET(k) pthread_getspecific(k) +#define TLSSET(k, a) pthread_setspecific(k, a) #endif #if 0 @@ -134,27 +134,29 @@ static LPVOID ChkedTlsGetValue(DWORD idx) #if defined(__cplusplus) #if !defined(NO_NED_NAMESPACE) -namespace nedalloc { +namespace nedalloc +{ #else -extern "C" { +extern "C" +{ #endif #endif size_t nedblksize(void *mem) THROWSPEC { #if 0 - /* Only enable if testing with valgrind. Causes misoperation */ - return THREADCACHEMAX; + /* Only enable if testing with valgrind. Causes misoperation */ + return THREADCACHEMAX; #else - if(mem) - { - mchunkptr p=mem2chunk(mem); - mstate fm = get_mstate_for(p); - assert(ok_magic(fm)); /* If this fails, someone tried to free a block twice */ - if(ok_magic(fm)) - return chunksize(p)-overhead_for(p); - } - return 0; + if (mem) + { + mchunkptr p=mem2chunk(mem); + mstate fm = get_mstate_for(p); + assert(ok_magic(fm)); /* If this fails, someone tried to free a block twice */ + if (ok_magic(fm)) + return chunksize(p)-overhead_for(p); + } + return 0; #endif } @@ -179,117 +181,118 @@ typedef struct threadcacheblk_t threadcacheblk; struct threadcacheblk_t { /* Keep less than 16 bytes on 32 bit systems and 32 bytes on 64 bit systems */ #ifdef FULLSANITYCHECKS - unsigned int magic; + unsigned int magic; #endif - unsigned int lastUsed, size; - threadcacheblk *next, *prev; + unsigned int lastUsed, size; + threadcacheblk *next, *prev; }; typedef struct threadcache_t { #ifdef FULLSANITYCHECKS - unsigned int magic1; + unsigned int magic1; #endif - int mymspace; /* Last mspace entry this thread used */ - long threadid; - unsigned int mallocs, frees, successes; - size_t freeInCache; /* How much free space is stored in this cache */ - threadcacheblk *bins[(THREADCACHEMAXBINS+1)*2]; + int mymspace; /* Last mspace entry this thread used */ + long threadid; + unsigned int mallocs, frees, successes; + size_t freeInCache; /* How much free space is stored in this cache */ + threadcacheblk *bins[(THREADCACHEMAXBINS+1)*2]; #ifdef FULLSANITYCHECKS - unsigned int magic2; + unsigned int magic2; #endif } threadcache; struct nedpool_t { - MLOCK_T mutex; - void *uservalue; - int threads; /* Max entries in m to use */ - threadcache *caches[THREADCACHEMAXCACHES]; - TLSVAR mycache; /* Thread cache for this thread. 0 for unset, negative for use mspace-1 directly, otherwise is cache-1 */ - mstate m[MAXTHREADSINPOOL+1]; /* mspace entries for this pool */ + MLOCK_T mutex; + void *uservalue; + int threads; /* Max entries in m to use */ + threadcache *caches[THREADCACHEMAXCACHES]; + TLSVAR mycache; /* Thread cache for this thread. 0 for unset, negative for use mspace-1 directly, otherwise is cache-1 */ + mstate m[MAXTHREADSINPOOL+1]; /* mspace entries for this pool */ }; static nedpool syspool; static FORCEINLINE unsigned int size2binidx(size_t _size) THROWSPEC { /* 8=1000 16=10000 20=10100 24=11000 32=100000 48=110000 4096=1000000000000 */ - unsigned int topbit, size=(unsigned int)(_size>>4); - /* 16=1 20=1 24=1 32=10 48=11 64=100 96=110 128=1000 4096=100000000 */ + unsigned int topbit, size=(unsigned int)(_size>>4); + /* 16=1 20=1 24=1 32=10 48=11 64=100 96=110 128=1000 4096=100000000 */ #if defined(__GNUC__) - topbit = sizeof(size)*__CHAR_BIT__ - 1 - __builtin_clz(size); + topbit = sizeof(size)*__CHAR_BIT__ - 1 - __builtin_clz(size); #elif defined(_MSC_VER) && _MSC_VER>=1300 - { - unsigned long bsrTopBit; + { + unsigned long bsrTopBit; - _BitScanReverse(&bsrTopBit, size); + _BitScanReverse(&bsrTopBit, size); - topbit = bsrTopBit; - } + topbit = bsrTopBit; + } #else #if 0 - union { - unsigned asInt[2]; - double asDouble; - }; - int n; + union + { + unsigned asInt[2]; + double asDouble; + }; + int n; - asDouble = (double)size + 0.5; - topbit = (asInt[!FOX_BIGENDIAN] >> 20) - 1023; + asDouble = (double)size + 0.5; + topbit = (asInt[!FOX_BIGENDIAN] >> 20) - 1023; #else - { - unsigned int x=size; - x = x | (x >> 1); - x = x | (x >> 2); - x = x | (x >> 4); - x = x | (x >> 8); - x = x | (x >>16); - x = ~x; - x = x - ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - x = (x + (x >> 4)) & 0x0F0F0F0F; - x = x + (x << 8); - x = x + (x << 16); - topbit=31 - (x >> 24); - } + { + unsigned int x=size; + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + x = ~x; + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + topbit=31 - (x >> 24); + } #endif #endif - return topbit; + return topbit; } #ifdef FULLSANITYCHECKS static void tcsanitycheck(threadcacheblk **ptr) THROWSPEC { - assert((ptr[0] && ptr[1]) || (!ptr[0] && !ptr[1])); - if(ptr[0] && ptr[1]) - { - assert(nedblksize(ptr[0])>=sizeof(threadcacheblk)); - assert(nedblksize(ptr[1])>=sizeof(threadcacheblk)); - assert(*(unsigned int *) "NEDN"==ptr[0]->magic); - assert(*(unsigned int *) "NEDN"==ptr[1]->magic); - assert(!ptr[0]->prev); - assert(!ptr[1]->next); - if(ptr[0]==ptr[1]) - { - assert(!ptr[0]->next); - assert(!ptr[1]->prev); - } - } + assert((ptr[0] && ptr[1]) || (!ptr[0] && !ptr[1])); + if (ptr[0] && ptr[1]) + { + assert(nedblksize(ptr[0])>=sizeof(threadcacheblk)); + assert(nedblksize(ptr[1])>=sizeof(threadcacheblk)); + assert(*(unsigned int *) "NEDN"==ptr[0]->magic); + assert(*(unsigned int *) "NEDN"==ptr[1]->magic); + assert(!ptr[0]->prev); + assert(!ptr[1]->next); + if (ptr[0]==ptr[1]) + { + assert(!ptr[0]->next); + assert(!ptr[1]->prev); + } + } } static void tcfullsanitycheck(threadcache *tc) THROWSPEC { - threadcacheblk **tcbptr=tc->bins; - int n; - for(n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) - { - threadcacheblk *b, *ob=0; - tcsanitycheck(tcbptr); - for(b=tcbptr[0]; b; ob=b, b=b->next) - { - assert(*(unsigned int *) "NEDN"==b->magic); - assert(!ob || ob->next==b); - assert(!ob || b->prev==ob); - } - } + threadcacheblk **tcbptr=tc->bins; + int n; + for (n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) + { + threadcacheblk *b, *ob=0; + tcsanitycheck(tcbptr); + for (b=tcbptr[0]; b; ob=b, b=b->next) + { + assert(*(unsigned int *) "NEDN"==b->magic); + assert(!ob || ob->next==b); + assert(!ob || b->prev==ob); + } + } } #endif @@ -297,258 +300,259 @@ static NOINLINE void RemoveCacheEntries(nedpool *p, threadcache *tc, unsigned in { UNREFERENCED_PARAMETER(p); #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif - if(tc->freeInCache) - { - threadcacheblk **tcbptr=tc->bins; - int n; - for(n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) - { - threadcacheblk **tcb=tcbptr+1; /* come from oldest end of list */ - /*tcsanitycheck(tcbptr);*/ - for(; *tcb && tc->frees-(*tcb)->lastUsed>=age; ) - { - threadcacheblk *f=*tcb; - size_t blksize=f->size; /*nedblksize(f);*/ - assert(blksize<=nedblksize(f)); - assert(blksize); + if (tc->freeInCache) + { + threadcacheblk **tcbptr=tc->bins; + int n; + for (n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) + { + threadcacheblk **tcb=tcbptr+1; /* come from oldest end of list */ + /*tcsanitycheck(tcbptr);*/ + for (; *tcb && tc->frees-(*tcb)->lastUsed>=age;) + { + threadcacheblk *f=*tcb; + size_t blksize=f->size; /*nedblksize(f);*/ + assert(blksize<=nedblksize(f)); + assert(blksize); #ifdef FULLSANITYCHECKS - assert(*(unsigned int *) "NEDN"==(*tcb)->magic); + assert(*(unsigned int *) "NEDN"==(*tcb)->magic); #endif - *tcb=(*tcb)->prev; - if(*tcb) - (*tcb)->next=0; - else - *tcbptr=0; - tc->freeInCache-=blksize; - assert((long) tc->freeInCache>=0); - mspace_free(0, f); - /*tcsanitycheck(tcbptr);*/ - } - } - } + *tcb=(*tcb)->prev; + if (*tcb) + (*tcb)->next=0; + else + *tcbptr=0; + tc->freeInCache-=blksize; + assert((long) tc->freeInCache>=0); + mspace_free(0, f); + /*tcsanitycheck(tcbptr);*/ + } + } + } #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif } static void DestroyCaches(nedpool *p) THROWSPEC { - if(p->caches) - { - threadcache *tc; - int n; - for(n=0; ncaches[n])) - { - tc->frees++; - RemoveCacheEntries(p, tc, 0); - assert(!tc->freeInCache); - tc->mymspace=-1; - tc->threadid=0; - mspace_free(0, tc); - p->caches[n]=0; - } - } - } + if (p->caches) + { + threadcache *tc; + int n; + for (n=0; ncaches[n])) + { + tc->frees++; + RemoveCacheEntries(p, tc, 0); + assert(!tc->freeInCache); + tc->mymspace=-1; + tc->threadid=0; + mspace_free(0, tc); + p->caches[n]=0; + } + } + } } static NOINLINE threadcache *AllocCache(nedpool *p) THROWSPEC { - threadcache *tc=0; - int n, end; - ACQUIRE_LOCK(&p->mutex); - for(n=0; ncaches[n]; n++); - if(THREADCACHEMAXCACHES==n) - { /* List exhausted, so disable for this thread */ - RELEASE_LOCK(&p->mutex); - return 0; - } - tc=p->caches[n]=(threadcache *) mspace_calloc(p->m[0], 1, sizeof(threadcache)); - if(!tc) - { - RELEASE_LOCK(&p->mutex); - return 0; - } + threadcache *tc=0; + int n, end; + ACQUIRE_LOCK(&p->mutex); + for (n=0; ncaches[n]; n++); + if (THREADCACHEMAXCACHES==n) + { /* List exhausted, so disable for this thread */ + RELEASE_LOCK(&p->mutex); + return 0; + } + tc=p->caches[n]=(threadcache *) mspace_calloc(p->m[0], 1, sizeof(threadcache)); + if (!tc) + { + RELEASE_LOCK(&p->mutex); + return 0; + } #ifdef FULLSANITYCHECKS - tc->magic1=*(unsigned int *)"NEDMALC1"; - tc->magic2=*(unsigned int *)"NEDMALC2"; + tc->magic1=*(unsigned int *)"NEDMALC1"; + tc->magic2=*(unsigned int *)"NEDMALC2"; #endif - tc->threadid=(long)(size_t)CURRENT_THREAD; - for(end=0; p->m[end]; end++); - tc->mymspace=abs(tc->threadid) % end; - RELEASE_LOCK(&p->mutex); - if(TLSSET(p->mycache, (void *)(size_t)(n+1))) abort(); - return tc; + tc->threadid=(long)(size_t)CURRENT_THREAD; + for (end=0; p->m[end]; end++); + tc->mymspace=abs(tc->threadid) % end; + RELEASE_LOCK(&p->mutex); + if (TLSSET(p->mycache, (void *)(size_t)(n+1))) abort(); + return tc; } static void *threadcache_malloc(nedpool *p, threadcache *tc, size_t *size) THROWSPEC { - void *ret=0; - unsigned int bestsize; - unsigned int idx=size2binidx(*size); - size_t blksize=0; - threadcacheblk *blk, **binsptr; + void *ret=0; + unsigned int bestsize; + unsigned int idx=size2binidx(*size); + size_t blksize=0; + threadcacheblk *blk, **binsptr; UNREFERENCED_PARAMETER(p); #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif - /* Calculate best fit bin size */ - bestsize=1<<(idx+4); + /* Calculate best fit bin size */ + bestsize=1<<(idx+4); #if 0 - /* Finer grained bin fit */ - idx<<=1; - if(*size>bestsize) - { - idx++; - bestsize+=bestsize>>1; - } - if(*size>bestsize) - { - idx++; - bestsize=1<<(4+(idx>>1)); - } + /* Finer grained bin fit */ + idx<<=1; + if (*size>bestsize) + { + idx++; + bestsize+=bestsize>>1; + } + if (*size>bestsize) + { + idx++; + bestsize=1<<(4+(idx>>1)); + } #else - if(*size>bestsize) - { - idx++; - bestsize<<=1; - } + if (*size>bestsize) + { + idx++; + bestsize<<=1; + } #endif - assert(bestsize>=*size); - if(*sizebins[idx*2]; - /* Try to match close, but move up a bin if necessary */ - blk=*binsptr; - if(!blk || blk->size<*size) - { /* Bump it up a bin */ - if(idxsize; /*nedblksize(blk);*/ - assert(nedblksize(blk)>=blksize); - assert(blksize>=*size); - if(blk->next) - blk->next->prev=0; - *binsptr=blk->next; - if(!*binsptr) - binsptr[1]=0; + assert(bestsize>=*size); + if (*sizebins[idx*2]; + /* Try to match close, but move up a bin if necessary */ + blk=*binsptr; + if (!blk || blk->size<*size) + { /* Bump it up a bin */ + if (idxsize; /*nedblksize(blk);*/ + assert(nedblksize(blk)>=blksize); + assert(blksize>=*size); + if (blk->next) + blk->next->prev=0; + *binsptr=blk->next; + if (!*binsptr) + binsptr[1]=0; #ifdef FULLSANITYCHECKS - blk->magic=0; + blk->magic=0; #endif - assert(binsptr[0]!=blk && binsptr[1]!=blk); - assert(nedblksize(blk)>=sizeof(threadcacheblk) && nedblksize(blk)<=THREADCACHEMAX+CHUNK_OVERHEAD); - /*printf("malloc: %p, %p, %p, %lu\n", p, tc, blk, (long) size);*/ - ret=(void *) blk; - } - ++tc->mallocs; - if(ret) - { - assert(blksize>=*size); - ++tc->successes; - tc->freeInCache-=blksize; - assert((long) tc->freeInCache>=0); - } + assert(binsptr[0]!=blk && binsptr[1]!=blk); + assert(nedblksize(blk)>=sizeof(threadcacheblk) && nedblksize(blk)<=THREADCACHEMAX+CHUNK_OVERHEAD); + /*printf("malloc: %p, %p, %p, %lu\n", p, tc, blk, (long) size);*/ + ret=(void *) blk; + } + ++tc->mallocs; + if (ret) + { + assert(blksize>=*size); + ++tc->successes; + tc->freeInCache-=blksize; + assert((long) tc->freeInCache>=0); + } #if defined(DEBUG) && 0 - if(!(tc->mallocs & 0xfff)) - { - printf("*** threadcache=%u, mallocs=%u (%f), free=%u (%f), freeInCache=%u\n", (unsigned int) tc->threadid, tc->mallocs, - (float) tc->successes/tc->mallocs, tc->frees, (float) tc->successes/tc->frees, (unsigned int) tc->freeInCache); - } + if (!(tc->mallocs & 0xfff)) + { + printf("*** threadcache=%u, mallocs=%u (%f), free=%u (%f), freeInCache=%u\n", (unsigned int) tc->threadid, tc->mallocs, + (float) tc->successes/tc->mallocs, tc->frees, (float) tc->successes/tc->frees, (unsigned int) tc->freeInCache); + } #endif #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif - return ret; + return ret; } static NOINLINE void ReleaseFreeInCache(nedpool *p, threadcache *tc, int mymspace) THROWSPEC { - unsigned int age=THREADCACHEMAXFREESPACE/8192; - /*ACQUIRE_LOCK(&p->m[mymspace]->mutex);*/ + unsigned int age=THREADCACHEMAXFREESPACE/8192; + /*ACQUIRE_LOCK(&p->m[mymspace]->mutex);*/ UNREFERENCED_PARAMETER(mymspace); - while(age && tc->freeInCache>=THREADCACHEMAXFREESPACE) - { - RemoveCacheEntries(p, tc, age); - /*printf("*** Removing cache entries older than %u (%u)\n", age, (unsigned int) tc->freeInCache);*/ - age>>=1; - } - /*RELEASE_LOCK(&p->m[mymspace]->mutex);*/ + while (age && tc->freeInCache>=THREADCACHEMAXFREESPACE) + { + RemoveCacheEntries(p, tc, age); + /*printf("*** Removing cache entries older than %u (%u)\n", age, (unsigned int) tc->freeInCache);*/ + age>>=1; + } + /*RELEASE_LOCK(&p->m[mymspace]->mutex);*/ } static void threadcache_free(nedpool *p, threadcache *tc, int mymspace, void *mem, size_t size) THROWSPEC { - unsigned int bestsize; - unsigned int idx=size2binidx(size); - threadcacheblk **binsptr, *tck=(threadcacheblk *) mem; - assert(size>=sizeof(threadcacheblk) && size<=THREADCACHEMAX+CHUNK_OVERHEAD); + unsigned int bestsize; + unsigned int idx=size2binidx(size); + threadcacheblk **binsptr, *tck=(threadcacheblk *) mem; + assert(size>=sizeof(threadcacheblk) && size<=THREADCACHEMAX+CHUNK_OVERHEAD); #ifdef DEBUG - { /* Make sure this is a valid memory block */ - mchunkptr p = mem2chunk(mem); - mstate fm = get_mstate_for(p); - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } - } + { /* Make sure this is a valid memory block */ + mchunkptr p = mem2chunk(mem); + mstate fm = get_mstate_for(p); + if (!ok_magic(fm)) + { + USAGE_ERROR_ACTION(fm, p); + return; + } + } #endif #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif - /* Calculate best fit bin size */ - bestsize=1<<(idx+4); + /* Calculate best fit bin size */ + bestsize=1<<(idx+4); #if 0 - /* Finer grained bin fit */ - idx<<=1; - if(size>bestsize) - { - unsigned int biggerbestsize=bestsize+bestsize<<1; - if(size>=biggerbestsize) - { - idx++; - bestsize=biggerbestsize; - } - } + /* Finer grained bin fit */ + idx<<=1; + if (size>bestsize) + { + unsigned int biggerbestsize=bestsize+bestsize<<1; + if (size>=biggerbestsize) + { + idx++; + bestsize=biggerbestsize; + } + } #endif - if(bestsize!=size) /* dlmalloc can round up, so we round down to preserve indexing */ - size=bestsize; - binsptr=&tc->bins[idx*2]; - assert(idx<=THREADCACHEMAXBINS); - if(tck==*binsptr) - { - fprintf(stderr, "Attempt to free already freed memory block %p - aborting!\n", tck); - abort(); - } + if (bestsize!=size) /* dlmalloc can round up, so we round down to preserve indexing */ + size=bestsize; + binsptr=&tc->bins[idx*2]; + assert(idx<=THREADCACHEMAXBINS); + if (tck==*binsptr) + { + fprintf(stderr, "Attempt to free already freed memory block %p - aborting!\n", tck); + abort(); + } #ifdef FULLSANITYCHECKS - tck->magic=*(unsigned int *) "NEDN"; + tck->magic=*(unsigned int *) "NEDN"; #endif - tck->lastUsed=++tc->frees; - tck->size=(unsigned int) size; - tck->next=*binsptr; - tck->prev=0; - if(tck->next) - tck->next->prev=tck; - else - binsptr[1]=tck; - assert(!*binsptr || (*binsptr)->size==tck->size); - *binsptr=tck; - assert(tck==tc->bins[idx*2]); - assert(tc->bins[idx*2+1]==tck || binsptr[0]->next->prev==tck); - /*printf("free: %p, %p, %p, %lu\n", p, tc, mem, (long) size);*/ - tc->freeInCache+=size; + tck->lastUsed=++tc->frees; + tck->size=(unsigned int) size; + tck->next=*binsptr; + tck->prev=0; + if (tck->next) + tck->next->prev=tck; + else + binsptr[1]=tck; + assert(!*binsptr || (*binsptr)->size==tck->size); + *binsptr=tck; + assert(tck==tc->bins[idx*2]); + assert(tc->bins[idx*2+1]==tck || binsptr[0]->next->prev==tck); + /*printf("free: %p, %p, %p, %lu\n", p, tc, mem, (long) size);*/ + tc->freeInCache+=size; #ifdef FULLSANITYCHECKS - tcfullsanitycheck(tc); + tcfullsanitycheck(tc); #endif #if 1 - if(tc->freeInCache>=THREADCACHEMAXFREESPACE) - ReleaseFreeInCache(p, tc, mymspace); + if (tc->freeInCache>=THREADCACHEMAXFREESPACE) + ReleaseFreeInCache(p, tc, mymspace); #endif } @@ -557,187 +561,187 @@ static void threadcache_free(nedpool *p, threadcache *tc, int mymspace, void *me static NOINLINE int InitPool(nedpool *p, size_t capacity, int threads) THROWSPEC { /* threads is -1 for system pool */ - ensure_initialization(); - ACQUIRE_MALLOC_GLOBAL_LOCK(); - if(p->threads) goto done; - if(INITIAL_LOCK(&p->mutex)) goto err; - if(TLSALLOC(&p->mycache)) goto err; - if(!(p->m[0]=(mstate) create_mspace(capacity, 1))) goto err; - p->m[0]->extp=p; - p->threads=(threads<1 || threads>MAXTHREADSINPOOL) ? MAXTHREADSINPOOL : threads; + ensure_initialization(); + ACQUIRE_MALLOC_GLOBAL_LOCK(); + if (p->threads) goto done; + if (INITIAL_LOCK(&p->mutex)) goto err; + if (TLSALLOC(&p->mycache)) goto err; + if (!(p->m[0]=(mstate) create_mspace(capacity, 1))) goto err; + p->m[0]->extp=p; + p->threads=(threads<1 || threads>MAXTHREADSINPOOL) ? MAXTHREADSINPOOL : threads; done: - RELEASE_MALLOC_GLOBAL_LOCK(); - return 1; + RELEASE_MALLOC_GLOBAL_LOCK(); + return 1; err: - if(threads<0) - abort(); /* If you can't allocate for system pool, we're screwed */ - DestroyCaches(p); - if(p->m[0]) - { - destroy_mspace(p->m[0]); - p->m[0]=0; - } - if(p->mycache) - { - if(TLSFREE(p->mycache)) abort(); - p->mycache=0; - } - RELEASE_MALLOC_GLOBAL_LOCK(); - return 0; + if (threads<0) + abort(); /* If you can't allocate for system pool, we're screwed */ + DestroyCaches(p); + if (p->m[0]) + { + destroy_mspace(p->m[0]); + p->m[0]=0; + } + if (p->mycache) + { + if (TLSFREE(p->mycache)) abort(); + p->mycache=0; + } + RELEASE_MALLOC_GLOBAL_LOCK(); + return 0; } static NOINLINE mstate FindMSpace(nedpool *p, threadcache *tc, int *lastUsed, size_t size) THROWSPEC { /* Gets called when thread's last used mspace is in use. The strategy is to run through the list of all available mspaces looking for an unlocked one and if we fail, we create a new one so long as we don't exceed p->threads */ - int n, end; - for(n=end=*lastUsed+1; p->m[n]; end=++n) - { - if(TRY_LOCK(&p->m[n]->mutex)) goto found; - } - for(n=0; n<*lastUsed && p->m[n]; n++) - { - if(TRY_LOCK(&p->m[n]->mutex)) goto found; - } - if(endthreads) - { - mstate temp; - if(!(temp=(mstate) create_mspace(size, 1))) - goto badexit; - /* Now we're ready to modify the lists, we lock */ - ACQUIRE_LOCK(&p->mutex); - while(p->m[end] && endthreads) - end++; - if(end>=p->threads) - { /* Drat, must destroy it now */ - RELEASE_LOCK(&p->mutex); - destroy_mspace((mspace) temp); - goto badexit; - } - /* We really want to make sure this goes into memory now but we - have to be careful of breaking aliasing rules, so write it twice */ - *((volatile struct malloc_state **) &p->m[end])=p->m[end]=temp; - ACQUIRE_LOCK(&p->m[end]->mutex); - /*printf("Created mspace idx %d\n", end);*/ - RELEASE_LOCK(&p->mutex); - n=end; - goto found; - } - /* Let it lock on the last one it used */ + int n, end; + for (n=end=*lastUsed+1; p->m[n]; end=++n) +{ +if (TRY_LOCK(&p->m[n]->mutex)) goto found; +} +for (n=0; n<*lastUsed && p->m[n]; n++) +{ +if (TRY_LOCK(&p->m[n]->mutex)) goto found; +} +if (endthreads) +{ +mstate temp; +if (!(temp=(mstate) create_mspace(size, 1))) + goto badexit; + /* Now we're ready to modify the lists, we lock */ + ACQUIRE_LOCK(&p->mutex); + while (p->m[end] && endthreads) + end++; + if (end>=p->threads) + { /* Drat, must destroy it now */ + RELEASE_LOCK(&p->mutex); + destroy_mspace((mspace) temp); + goto badexit; + } + /* We really want to make sure this goes into memory now but we + have to be careful of breaking aliasing rules, so write it twice */ + *((volatile struct malloc_state **) &p->m[end])=p->m[end]=temp; + ACQUIRE_LOCK(&p->m[end]->mutex); + /*printf("Created mspace idx %d\n", end);*/ + RELEASE_LOCK(&p->mutex); + n=end; + goto found; +} +/* Let it lock on the last one it used */ badexit: - ACQUIRE_LOCK(&p->m[*lastUsed]->mutex); - return p->m[*lastUsed]; +ACQUIRE_LOCK(&p->m[*lastUsed]->mutex); +return p->m[*lastUsed]; found: - *lastUsed=n; - if(tc) - tc->mymspace=n; - else - { - if(TLSSET(p->mycache, (void *)(size_t)(-(n+1)))) abort(); - } - return p->m[n]; +*lastUsed=n; +if (tc) +tc->mymspace=n; +else +{ + if (TLSSET(p->mycache, (void *)(size_t)(-(n+1)))) abort(); + } +return p->m[n]; } nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC { - nedpool *ret; - if(!(ret=(nedpool *) nedpcalloc(0, 1, sizeof(nedpool)))) return 0; - if(!InitPool(ret, capacity, threads)) - { - nedpfree(0, ret); - return 0; - } - return ret; + nedpool *ret; + if (!(ret=(nedpool *) nedpcalloc(0, 1, sizeof(nedpool)))) return 0; + if (!InitPool(ret, capacity, threads)) + { + nedpfree(0, ret); + return 0; + } + return ret; } void neddestroypool(nedpool *p) THROWSPEC { - int n; - ACQUIRE_LOCK(&p->mutex); - DestroyCaches(p); - for(n=0; p->m[n]; n++) - { - destroy_mspace(p->m[n]); - p->m[n]=0; - } - RELEASE_LOCK(&p->mutex); - if(TLSFREE(p->mycache)) abort(); - nedpfree(0, p); + int n; + ACQUIRE_LOCK(&p->mutex); + DestroyCaches(p); + for (n=0; p->m[n]; n++) + { + destroy_mspace(p->m[n]); + p->m[n]=0; + } + RELEASE_LOCK(&p->mutex); + if (TLSFREE(p->mycache)) abort(); + nedpfree(0, p); } void neddestroysyspool() THROWSPEC { - nedpool *p=&syspool; - int n; - ACQUIRE_LOCK(&p->mutex); - DestroyCaches(p); - for(n=0; p->m[n]; n++) - { - destroy_mspace(p->m[n]); - p->m[n]=0; - } - /* Render syspool unusable */ - for(n=0; ncaches[n]=(threadcache *) 0xdeadbeef; - for(n=0; nm[n]=(mstate) 0xdeadbeef; - if(TLSFREE(p->mycache)) abort(); - RELEASE_LOCK(&p->mutex); + nedpool *p=&syspool; + int n; + ACQUIRE_LOCK(&p->mutex); + DestroyCaches(p); + for (n=0; p->m[n]; n++) + { + destroy_mspace(p->m[n]); + p->m[n]=0; + } + /* Render syspool unusable */ + for (n=0; ncaches[n]=(threadcache *) 0xdeadbeef; + for (n=0; nm[n]=(mstate) 0xdeadbeef; + if (TLSFREE(p->mycache)) abort(); + RELEASE_LOCK(&p->mutex); } void nedpsetvalue(nedpool *p, void *v) THROWSPEC { - if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } - p->uservalue=v; + if (!p) { p=&syspool; if (!syspool.threads) InitPool(&syspool, 0, -1); } + p->uservalue=v; } void *nedgetvalue(nedpool **p, void *mem) THROWSPEC { - nedpool *np=0; - mchunkptr mcp=mem2chunk(mem); - mstate fm; - if(!(is_aligned(chunk2mem(mcp))) && mcp->head != FENCEPOST_HEAD) return 0; - if(!cinuse(mcp)) return 0; - if(!next_pinuse(mcp)) return 0; - if(!is_mmapped(mcp) && !pinuse(mcp)) - { - if(next_chunk(prev_chunk(mcp))!=mcp) return 0; - } - fm=get_mstate_for(mcp); - if(!ok_magic(fm)) return 0; - if(!ok_address(fm, mcp)) return 0; - if(!fm->extp) return 0; - np=(nedpool *) fm->extp; - if(p) *p=np; - return np->uservalue; + nedpool *np=0; + mchunkptr mcp=mem2chunk(mem); + mstate fm; + if (!(is_aligned(chunk2mem(mcp))) && mcp->head != FENCEPOST_HEAD) return 0; + if (!cinuse(mcp)) return 0; + if (!next_pinuse(mcp)) return 0; + if (!is_mmapped(mcp) && !pinuse(mcp)) + { + if (next_chunk(prev_chunk(mcp))!=mcp) return 0; + } + fm=get_mstate_for(mcp); + if (!ok_magic(fm)) return 0; + if (!ok_address(fm, mcp)) return 0; + if (!fm->extp) return 0; + np=(nedpool *) fm->extp; + if (p) *p=np; + return np->uservalue; } void neddisablethreadcache(nedpool *p) THROWSPEC { - int mycache; - if(!p) - { - p=&syspool; - if(!syspool.threads) InitPool(&syspool, 0, -1); - } - mycache=(int)(size_t) TLSGET(p->mycache); - if(!mycache) - { /* Set to mspace 0 */ - if(TLSSET(p->mycache, (void *)-1)) abort(); - } - else if(mycache>0) - { /* Set to last used mspace */ - threadcache *tc=p->caches[mycache-1]; + int mycache; + if (!p) + { + p=&syspool; + if (!syspool.threads) InitPool(&syspool, 0, -1); + } + mycache=(int)(size_t) TLSGET(p->mycache); + if (!mycache) + { /* Set to mspace 0 */ + if (TLSSET(p->mycache, (void *)-1)) abort(); + } + else if (mycache>0) + { /* Set to last used mspace */ + threadcache *tc=p->caches[mycache-1]; #if defined(DEBUG) - printf("Threadcache utilisation: %lf%% in cache with %lf%% lost to other threads\n", - 100.0*tc->successes/tc->mallocs, 100.0*((double) tc->mallocs-tc->frees)/tc->mallocs); + printf("Threadcache utilisation: %lf%% in cache with %lf%% lost to other threads\n", + 100.0*tc->successes/tc->mallocs, 100.0*((double) tc->mallocs-tc->frees)/tc->mallocs); #endif - if(TLSSET(p->mycache, (void *)(size_t)(-tc->mymspace))) abort(); - tc->frees++; - RemoveCacheEntries(p, tc, 0); - assert(!tc->freeInCache); - tc->mymspace=-1; - tc->threadid=0; - mspace_free(0, p->caches[mycache-1]); - p->caches[mycache-1]=0; - } + if (TLSSET(p->mycache, (void *)(size_t)(-tc->mymspace))) abort(); + tc->frees++; + RemoveCacheEntries(p, tc, 0); + assert(!tc->freeInCache); + tc->mymspace=-1; + tc->threadid=0; + mspace_free(0, p->caches[mycache-1]); + p->caches[mycache-1]=0; + } } #define GETMSPACE(m,p,tc,ms,s,action) \ @@ -750,232 +754,232 @@ void neddisablethreadcache(nedpool *p) THROWSPEC static FORCEINLINE mstate GetMSpace(nedpool *p, threadcache *tc, int mymspace, size_t size) THROWSPEC { /* Returns a locked and ready for use mspace */ - mstate m=p->m[mymspace]; - assert(m); - if(!TRY_LOCK(&p->m[mymspace]->mutex)) m=FindMSpace(p, tc, &mymspace, size);\ - /*assert(IS_LOCKED(&p->m[mymspace]->mutex));*/ - return m; + mstate m=p->m[mymspace]; + assert(m); + if (!TRY_LOCK(&p->m[mymspace]->mutex)) m=FindMSpace(p, tc, &mymspace, size); \ + /*assert(IS_LOCKED(&p->m[mymspace]->mutex));*/ + return m; } static FORCEINLINE void GetThreadCache(nedpool **p, threadcache **tc, int *mymspace, size_t *size) THROWSPEC { - int mycache; - if(size && *sizemycache); - if(mycache>0) - { - *tc=(*p)->caches[mycache-1]; - *mymspace=(*tc)->mymspace; - } - else if(!mycache) - { - *tc=AllocCache(*p); - if(!*tc) - { /* Disable */ - if(TLSSET((*p)->mycache, (void *)-1)) abort(); - *mymspace=0; - } - else - *mymspace=(*tc)->mymspace; - } - else - { - *tc=0; - *mymspace=-mycache-1; - } - assert(*mymspace>=0); - assert((long)(size_t)CURRENT_THREAD==(*tc)->threadid); + int mycache; + if (size && *sizemycache); + if (mycache>0) + { + *tc=(*p)->caches[mycache-1]; + *mymspace=(*tc)->mymspace; + } + else if (!mycache) + { + *tc=AllocCache(*p); + if (!*tc) + { /* Disable */ + if (TLSSET((*p)->mycache, (void *)-1)) abort(); + *mymspace=0; + } + else + *mymspace=(*tc)->mymspace; + } + else + { + *tc=0; + *mymspace=-mycache-1; + } + assert(*mymspace>=0); + assert((long)(size_t)CURRENT_THREAD==(*tc)->threadid); #ifdef FULLSANITYCHECKS - if(*tc) - { - if(*(unsigned int *)"NEDMALC1"!=(*tc)->magic1 || *(unsigned int *)"NEDMALC2"!=(*tc)->magic2) - { - abort(); - } - } + if (*tc) + { + if (*(unsigned int *)"NEDMALC1"!=(*tc)->magic1 || *(unsigned int *)"NEDMALC2"!=(*tc)->magic2) + { + abort(); + } + } #endif } void * nedpmalloc(nedpool *p, size_t size) THROWSPEC { - void *ret=0; - threadcache *tc; - int mymspace; - GetThreadCache(&p, &tc, &mymspace, &size); + void *ret=0; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &size); #if THREADCACHEMAX - if(tc && size<=THREADCACHEMAX) - { /* Use the thread cache */ - ret=threadcache_malloc(p, tc, &size); - } + if (tc && size<=THREADCACHEMAX) + { /* Use the thread cache */ + ret=threadcache_malloc(p, tc, &size); + } #endif - if(!ret) - { /* Use this thread's mspace */ + if (!ret) + { /* Use this thread's mspace */ GETMSPACE(m, p, tc, mymspace, size, ret=mspace_malloc(m, size)); - } - return ret; + } + return ret; } void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC { - size_t rsize=size*no; - void *ret=0; - threadcache *tc; - int mymspace; - GetThreadCache(&p, &tc, &mymspace, &rsize); + size_t rsize=size*no; + void *ret=0; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &rsize); #if THREADCACHEMAX - if(tc && rsize<=THREADCACHEMAX) - { /* Use the thread cache */ - if((ret=threadcache_malloc(p, tc, &rsize))) - memset(ret, 0, rsize); - } + if (tc && rsize<=THREADCACHEMAX) + { /* Use the thread cache */ + if ((ret=threadcache_malloc(p, tc, &rsize))) + memset(ret, 0, rsize); + } #endif - if(!ret) - { /* Use this thread's mspace */ + if (!ret) + { /* Use this thread's mspace */ GETMSPACE(m, p, tc, mymspace, rsize, ret=mspace_calloc(m, 1, rsize)); - } - return ret; + } + return ret; } void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC { - void *ret=0; - threadcache *tc; - int mymspace; - if(!mem) return nedpmalloc(p, size); - GetThreadCache(&p, &tc, &mymspace, &size); + void *ret=0; + threadcache *tc; + int mymspace; + if (!mem) return nedpmalloc(p, size); + GetThreadCache(&p, &tc, &mymspace, &size); #if THREADCACHEMAX - if(tc && size && size<=THREADCACHEMAX) - { /* Use the thread cache */ - size_t memsize=nedblksize(mem); - assert(memsize); - if((ret=threadcache_malloc(p, tc, &size))) - { - memcpy(ret, mem, memsizem[n]; n++) - { - struct mallinfo t=mspace_mallinfo(p->m[n]); - ret.arena+=t.arena; - ret.ordblks+=t.ordblks; - ret.hblkhd+=t.hblkhd; - ret.usmblks+=t.usmblks; - ret.uordblks+=t.uordblks; - ret.fordblks+=t.fordblks; - ret.keepcost+=t.keepcost; - } - return ret; + int n; + struct mallinfo ret ={0,0,0,0,0,0,0,0,0,0}; +if (!p) { p=&syspool; if (!syspool.threads) InitPool(&syspool, 0, -1); } +for (n=0; p->m[n]; n++) +{ +struct mallinfo t=mspace_mallinfo(p->m[n]); + ret.arena+=t.arena; + ret.ordblks+=t.ordblks; + ret.hblkhd+=t.hblkhd; + ret.usmblks+=t.usmblks; + ret.uordblks+=t.uordblks; + ret.fordblks+=t.fordblks; + ret.keepcost+=t.keepcost; +} +return ret; } #endif int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC { UNREFERENCED_PARAMETER(p); - return mspace_mallopt(parno, value); + return mspace_mallopt(parno, value); } int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC { - int n, ret=0; - if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } - for(n=0; p->m[n]; n++) - { - ret+=mspace_trim(p->m[n], pad); - } - return ret; + int n, ret=0; + if (!p) { p=&syspool; if (!syspool.threads) InitPool(&syspool, 0, -1); } + for (n=0; p->m[n]; n++) + { + ret+=mspace_trim(p->m[n], pad); + } + return ret; } void nedpmalloc_stats(nedpool *p) THROWSPEC { - int n; - if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } - for(n=0; p->m[n]; n++) - { - mspace_malloc_stats(p->m[n]); - } + int n; + if (!p) { p=&syspool; if (!syspool.threads) InitPool(&syspool, 0, -1); } + for (n=0; p->m[n]; n++) + { + mspace_malloc_stats(p->m[n]); + } } size_t nedpmalloc_footprint(nedpool *p) THROWSPEC { - size_t ret=0; - int n; - if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } - for(n=0; p->m[n]; n++) - { - ret+=mspace_footprint(p->m[n]); - } - return ret; + size_t ret=0; + int n; + if (!p) { p=&syspool; if (!syspool.threads) InitPool(&syspool, 0, -1); } + for (n=0; p->m[n]; n++) + { + ret+=mspace_footprint(p->m[n]); + } + return ret; } void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC { - void **ret; - threadcache *tc; - int mymspace; - GetThreadCache(&p, &tc, &mymspace, &elemsize); + void **ret; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &elemsize); GETMSPACE(m, p, tc, mymspace, elemsno*elemsize, ret=mspace_independent_calloc(m, elemsno, elemsize, chunks)); - return ret; + return ret; } void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC { - void **ret; - threadcache *tc; - int mymspace; + void **ret; + threadcache *tc; + int mymspace; size_t i, *adjustedsizes=(size_t *) alloca(elems*sizeof(size_t)); - if(!adjustedsizes) return 0; - for(i=0; iparms[0], "%f", &val); - - if (val < cvars[i].min || val > cvars[i].max) - { - OSD_Printf("%s value out of range\n",cvars[i].name); - return OSDCMD_OK; - } - *(float*)cvars[i].var = val; - if (!OSD_ParsingScript()) - OSD_Printf("%s %f",cvars[i].name,val); + OSD_Printf("\"%s\" is \"%f\"\n%s\n",cvars[i].name,*(float*)cvars[i].var,(char*)cvars[i].helpstr); + return OSDCMD_OK; } - break; + + sscanf(parm->parms[0], "%f", &val); + + if (val < cvars[i].min || val > cvars[i].max) + { + OSD_Printf("%s value out of range\n",cvars[i].name); + return OSDCMD_OK; + } + *(float*)cvars[i].var = val; + if (!OSD_ParsingScript()) + OSD_Printf("%s %f",cvars[i].name,val); + } + break; case CVAR_DOUBLE: + { + double val; + if (showval) { - double val; - if (showval) - { - OSD_Printf("\"%s\" is \"%f\"\n%s\n",cvars[i].name,*(double*)cvars[i].var,(char*)cvars[i].helpstr); - return OSDCMD_OK; - } - - sscanf(parm->parms[0], "%lf", &val); - - if (val < cvars[i].min || val > cvars[i].max) - { - OSD_Printf("%s value out of range\n",cvars[i].name); - return OSDCMD_OK; - } - *(double*)cvars[i].var = val; - if (!OSD_ParsingScript()) - OSD_Printf("%s %f",cvars[i].name,val); + OSD_Printf("\"%s\" is \"%f\"\n%s\n",cvars[i].name,*(double*)cvars[i].var,(char*)cvars[i].helpstr); + return OSDCMD_OK; } - break; + + sscanf(parm->parms[0], "%lf", &val); + + if (val < cvars[i].min || val > cvars[i].max) + { + OSD_Printf("%s value out of range\n",cvars[i].name); + return OSDCMD_OK; + } + *(double*)cvars[i].var = val; + if (!OSD_ParsingScript()) + OSD_Printf("%s %f",cvars[i].name,val); + } + break; case CVAR_INT: case CVAR_UINT: case CVAR_BOOL: + { + int32_t val; + if (showval) { - int32_t val; - if (showval) - { - OSD_Printf("\"%s\" is \"%d\"\n%s\n",cvars[i].name,*(int32_t*)cvars[i].var,(char*)cvars[i].helpstr); - return OSDCMD_OK; - } - - val = atoi(parm->parms[0]); - if (cvars[i].type & CVAR_BOOL) val = val != 0; - - if (val < cvars[i].min || val > cvars[i].max) - { - OSD_Printf("%s value out of range\n",cvars[i].name); - return OSDCMD_OK; - } - *(int32_t*)cvars[i].var = val; - if (!OSD_ParsingScript()) - OSD_Printf("%s %d",cvars[i].name,val); + OSD_Printf("\"%s\" is \"%d\"\n%s\n",cvars[i].name,*(int32_t*)cvars[i].var,(char*)cvars[i].helpstr); + return OSDCMD_OK; } - break; + + val = atoi(parm->parms[0]); + if (cvars[i].type & CVAR_BOOL) val = val != 0; + + if (val < cvars[i].min || val > cvars[i].max) + { + OSD_Printf("%s value out of range\n",cvars[i].name); + return OSDCMD_OK; + } + *(int32_t*)cvars[i].var = val; + if (!OSD_ParsingScript()) + OSD_Printf("%s %d",cvars[i].name,val); + } + break; case CVAR_STRING: + { + if (showval) { - if (showval) - { - OSD_Printf("\"%s\" is \"%s\"\n%s\n",cvars[i].name,(char*)cvars[i].var,(char*)cvars[i].helpstr); - return OSDCMD_OK; - } - - Bstrncpy((char*)cvars[i].var, parm->parms[0], cvars[i].extra-1); - ((char*)cvars[i].var)[cvars[i].extra-1] = 0; - if (!OSD_ParsingScript()) - OSD_Printf("%s %s",cvars[i].name,(char*)cvars[i].var); + OSD_Printf("\"%s\" is \"%s\"\n%s\n",cvars[i].name,(char*)cvars[i].var,(char*)cvars[i].helpstr); + return OSDCMD_OK; } - break; + + Bstrncpy((char*)cvars[i].var, parm->parms[0], cvars[i].extra-1); + ((char*)cvars[i].var)[cvars[i].extra-1] = 0; + if (!OSD_ParsingScript()) + OSD_Printf("%s %s",cvars[i].name,(char*)cvars[i].var); + } + break; default: break; } diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index bb5a6e3b5..c59553d7d 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -5949,21 +5949,21 @@ void polymost_initosdfuncs(void) { "r_downsize","r_downsize: controls downsizing factor for hires textures",(void *)&r_downsizevar, CVAR_INT|CVAR_FUNCPTR, 0, 0, 5 }, { "r_fullbrights","r_fullbrights: enable/disable fullbright textures",(void *)&r_fullbrights, CVAR_BOOL, 0, 0, 1 }, { "r_glowmapping","r_glowmapping: enable/disable glow mapping",(void *)&r_glowmapping, CVAR_BOOL, 0, 0, 1 }, -/* - { "r_multisample","r_multisample: sets the number of samples used for antialiasing (0 = off)",(void *)&r_glowmapping, CVAR_BOOL, 0, 0, 1 } - { "r_nvmultisamplehint","r_nvmultisamplehint: enable/disable Nvidia multisampling hinting",(void *)&glnvmultisamplehint, CVAR_BOOL, 0, 0, 1 } -*/ + /* + { "r_multisample","r_multisample: sets the number of samples used for antialiasing (0 = off)",(void *)&r_glowmapping, CVAR_BOOL, 0, 0, 1 } + { "r_nvmultisamplehint","r_nvmultisamplehint: enable/disable Nvidia multisampling hinting",(void *)&glnvmultisamplehint, CVAR_BOOL, 0, 0, 1 } + */ { "r_parallaxskyclamping","r_parallaxskyclamping: enable/disable parallaxed floor/ceiling sky texture clamping", - (void *)&r_parallaxskyclamping, CVAR_BOOL, 0, 0, 1 }, + (void *)&r_parallaxskyclamping, CVAR_BOOL, 0, 0, 1 }, { "r_parallaxskypanning","r_parallaxskypanning: enable/disable parallaxed floor/ceiling panning when drawing a parallaxed sky", - (void *)&r_parallaxskypanning, CVAR_BOOL, 0, 0, 1 }, + (void *)&r_parallaxskypanning, CVAR_BOOL, 0, 0, 1 }, { "r_polygonmode","r_polygonmode: debugging feature",(void *)&glpolygonmode, CVAR_INT | CVAR_NOSAVE, 0, 0, 3 }, { "r_redbluemode","r_redbluemode: enable/disable experimental OpenGL red-blue glasses mode",(void *)&glredbluemode, CVAR_BOOL, 0, 0, 1 }, { "r_shadescale","r_shadescale: multiplier for lighting",(void *)&shadescale, CVAR_FLOAT, 0, 0, 10 }, { "r_swapinterval","r_swapinterval: sets the GL swap interval (VSync)",(void *)&vsync, CVAR_BOOL|CVAR_FUNCPTR, 0, 0, 1 }, { "r_texcachecompression","r_texcachecompression: enable/disable compression of files in the OpenGL compressed texture cache",(void *)&glusetexcachecompression, CVAR_BOOL, 0, 0, 1 }, { "r_texcache","r_texcache: enable/disable OpenGL compressed texture cache",(void *)&glusetexcache, CVAR_BOOL, 0, 0, 1 }, - { "r_texcompr","r_texcompr: enable/disable OpenGL texture compression",(void *)&glusetexcompr, CVAR_BOOL, 0, 0, 1 }, + { "r_texcompr","r_texcompr: enable/disable OpenGL texture compression",(void *)&glusetexcompr, CVAR_BOOL, 0, 0, 1 }, { "r_textureanisotropy", "r_textureanisotropy: changes the OpenGL texture anisotropy setting", (void *)&glanisotropy, CVAR_INT|CVAR_FUNCPTR, 0, 0, 16 }, { "r_texturemaxsize","r_texturemaxsize: changes the maximum OpenGL texture size limit",(void *)&gltexmaxsize, CVAR_INT, 0, 0, 4096 }, { "r_texturemiplevel","r_texturemiplevel: changes the highest OpenGL mipmap level used",(void *)&gltexmiplevel, CVAR_INT, 0, 0, 6 }, diff --git a/polymer/eduke32/build/src/textfont.c b/polymer/eduke32/build/src/textfont.c index ff9849fb0..59c6cf325 100644 --- a/polymer/eduke32/build/src/textfont.c +++ b/polymer/eduke32/build/src/textfont.c @@ -2,8 +2,8 @@ char textfont[2048] = { - 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, // . - 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x81, 0x7E, 0x00, // . + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, // . + 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x81, 0x7E, 0x00, // . 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xFF, 0x7E, 0x00, // . 0x36, 0x7F, 0x7F, 0x7F, 0x3E, 0x1C, 0x08, 0x00, // . 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08, 0x00, // . @@ -33,7 +33,7 @@ char textfont[2048] = 0x00, 0x00, 0x60, 0x60, 0x60, 0x7F, 0x00, 0x00, // . 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, // . 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, // . - 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, // + 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ! 0x06, 0x0E, 0x0C, 0x18, 0x10, 0x00, 0x20, 0x00, // " 0x6C, 0x6C, 0x24, 0x48, 0x00, 0x00, 0x00, 0x00, // # @@ -257,5 +257,5 @@ char textfont[2048] = 0x78, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, // . 0x38, 0x0C, 0x18, 0x30, 0x3C, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, // . - 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00 -}; + 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00 +}; diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index 473326d6e..df270deb7 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -620,11 +620,11 @@ void initprintf(const char *f, ...) OSD_Printf(buf); - if ((Bstrlen(dabuf) + Bstrlen(buf) + 2) > sizeof(dabuf)) - { - startwin_puts(dabuf); - Bmemset(dabuf, 0, sizeof(dabuf)); - } + if ((Bstrlen(dabuf) + Bstrlen(buf) + 2) > sizeof(dabuf)) + { + startwin_puts(dabuf); + Bmemset(dabuf, 0, sizeof(dabuf)); + } Bstrcat(dabuf,buf); @@ -3369,39 +3369,39 @@ static int32_t SetupOpenGL(int32_t width, int32_t height, int32_t bitspp) glinfo.extensions = (char *)bglGetString(GL_EXTENSIONS); // GL driver blacklist - - if (!Bstrcmp(glinfo.vendor,"Microsoft Corporation")) err = 1; - else if (!Bstrcmp(glinfo.vendor,"SiS")) err = 1; - else if (!Bstrcmp(glinfo.vendor,"3Dfx Interactive Inc.")) err = 1; - else if (!Bstrcmp(glinfo.vendor,"Intel")) - { - if (!Bstrcmp(glinfo.renderer,"Intel 865G")) - err = 0; - else if (!Bstrcmp(glinfo.renderer,"Intel 945GM")) - err = 0; - else if (!Bstrcmp(glinfo.renderer,"Intel 965/963 Graphics Media Accelerator")) - err = 0; - else err = 1; - } + + if (!Bstrcmp(glinfo.vendor,"Microsoft Corporation")) err = 1; + else if (!Bstrcmp(glinfo.vendor,"SiS")) err = 1; + else if (!Bstrcmp(glinfo.vendor,"3Dfx Interactive Inc.")) err = 1; + else if (!Bstrcmp(glinfo.vendor,"Intel")) + { + if (!Bstrcmp(glinfo.renderer,"Intel 865G")) + err = 0; + else if (!Bstrcmp(glinfo.renderer,"Intel 945GM")) + err = 0; + else if (!Bstrcmp(glinfo.renderer,"Intel 965/963 Graphics Media Accelerator")) + err = 0; + else err = 1; + } #ifdef POLYMER - else - { - if (!Bstrcmp(glinfo.vendor,"ATI Technologies Inc.")) - pr_atiworkaround = 1; - else pr_atiworkaround = 0; - } + else + { + if (!Bstrcmp(glinfo.vendor,"ATI Technologies Inc.")) + pr_atiworkaround = 1; + else pr_atiworkaround = 0; + } #endif - if (!forcegl && err) - { - OSD_Printf("Unsupported OpenGL driver detected. GL modes will be unavailable. Use -forcegl to override.\n"); - wm_msgbox("Unsupported OpenGL driver", "Unsupported OpenGL driver detected. GL modes will be unavailable."); - ReleaseOpenGL(); - unloadgldriver(); - nogl = 1; - modeschecked = 0; - getvalidmodes(); - return TRUE; - } + if (!forcegl && err) + { + OSD_Printf("Unsupported OpenGL driver detected. GL modes will be unavailable. Use -forcegl to override.\n"); + wm_msgbox("Unsupported OpenGL driver", "Unsupported OpenGL driver detected. GL modes will be unavailable."); + ReleaseOpenGL(); + unloadgldriver(); + nogl = 1; + modeschecked = 0; + getvalidmodes(); + return TRUE; + } glinfo.maxanisotropy = 1.0; glinfo.bgra = 0; diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 13e623edb..b5b250363 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -622,8 +622,8 @@ inline void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, i ActorExtra[srcsprite].lightmaxrange = 0; if (range > ActorExtra[srcsprite].lightmaxrange || - priority != ActorExtra[srcsprite].lightptr->priority || - Bmemcmp(&sprite[srcsprite], ActorExtra[srcsprite].lightptr, sizeof(int32_t) * 3)) + priority != ActorExtra[srcsprite].lightptr->priority || + Bmemcmp(&sprite[srcsprite], ActorExtra[srcsprite].lightptr, sizeof(int32_t) * 3)) { if (range > ActorExtra[srcsprite].lightmaxrange) ActorExtra[srcsprite].lightmaxrange = range; @@ -2216,9 +2216,9 @@ CLEAR_THE_BOLT: } goto BOLT; - case FLOORFLAME__STATIC: - case FIREBARREL__STATIC: - case FIREVASE__STATIC: + case FLOORFLAME__STATIC: + case FIREBARREL__STATIC: + case FIREVASE__STATIC: case EXPLODINGBARREL__STATIC: case WOODENHORSE__STATIC: case HORSEONSIDE__STATIC: @@ -5644,10 +5644,10 @@ static void G_MoveEffectors(void) //STATNUM 3 j = headspritesect[s->sectnum]; while (j >= 0) { - if (sprite[j].statnum != 10 && sector[sprite[j].sectnum].lotag != 2 && - (sprite[j].picnum != SECTOREFFECTOR || - (sprite[j].picnum == SECTOREFFECTOR && (sprite[j].lotag == 49||sprite[j].lotag == 50)) ) - && sprite[j].picnum != LOCATORS) + if (sprite[j].statnum != 10 && sector[sprite[j].sectnum].lotag != 2 && + (sprite[j].picnum != SECTOREFFECTOR || + (sprite[j].picnum == SECTOREFFECTOR && (sprite[j].lotag == 49||sprite[j].lotag == 50))) + && sprite[j].picnum != LOCATORS) { rotatepoint(s->x,s->y,sprite[j].x,sprite[j].y,q,&sprite[j].x,&sprite[j].y); @@ -7853,7 +7853,7 @@ void G_MoveWorld(void) { spritetype *s = &sprite[i]; - if(ActorExtra[i].lightptr != NULL && ActorExtra[i].lightcount) + if (ActorExtra[i].lightptr != NULL && ActorExtra[i].lightcount) { if (!(--ActorExtra[i].lightcount)) { @@ -7880,23 +7880,23 @@ void G_MoveWorld(void) case TECHSWITCH__STATIC: case ACCESSSWITCH__STATIC: case ACCESSSWITCH2__STATIC: - { - int32_t x, y; + { + int32_t x, y; - if (s->cstat & 32768 || !inside(s->x+((sintable[(s->ang+512)&2047])>>9), s->y+((sintable[(s->ang)&2047])>>9), s->sectnum)) - break; + if (s->cstat & 32768 || !inside(s->x+((sintable[(s->ang+512)&2047])>>9), s->y+((sintable[(s->ang)&2047])>>9), s->sectnum)) + break; - x = ((sintable[(s->ang+512)&2047])>>7); - y = ((sintable[(s->ang)&2047])>>7); + x = ((sintable[(s->ang+512)&2047])>>7); + y = ((sintable[(s->ang)&2047])>>7); - s->x += x; - s->y += y; + s->x += x; + s->y += y; - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), 1024, 48+(255<<8)+(48<<16),PR_LIGHT_PRIO_LOW); - s->x -= x; - s->y -= y; - } - break; + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), 1024, 48+(255<<8)+(48<<16),PR_LIGHT_PRIO_LOW); + s->x -= x; + s->y -= y; + } + break; } switch (DynamicTileMap[sprite[i].picnum]) { @@ -7935,7 +7935,7 @@ void G_MoveWorld(void) case EXPLOSION2__STATIC: if (!ActorExtra[i].lightcount) G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8), - s->yrepeat > 32 ? PR_LIGHT_PRIO_HIGH_GAME : PR_LIGHT_PRIO_LOW_GAME); + s->yrepeat > 32 ? PR_LIGHT_PRIO_HIGH_GAME : PR_LIGHT_PRIO_LOW_GAME); break; case FORCERIPPLE__STATIC: // case TRANSPORTERSTAR__STATIC: @@ -7978,23 +7978,23 @@ void G_MoveWorld(void) case TECHSWITCH__STATIC: case ACCESSSWITCH__STATIC: case ACCESSSWITCH2__STATIC: - { - int32_t x, y; + { + int32_t x, y; - if (s->cstat & 32768 || !inside(s->x+((sintable[(s->ang+512)&2047])>>9), s->y+((sintable[(s->ang)&2047])>>9), s->sectnum)) - break; + if (s->cstat & 32768 || !inside(s->x+((sintable[(s->ang+512)&2047])>>9), s->y+((sintable[(s->ang)&2047])>>9), s->sectnum)) + break; - x = ((sintable[(s->ang+512)&2047])>>7); - y = ((sintable[(s->ang)&2047])>>7); + x = ((sintable[(s->ang+512)&2047])>>7); + y = ((sintable[(s->ang)&2047])>>7); - s->x += x; - s->y += y; + s->x += x; + s->y += y; - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), 1024, 255+(48<<8)+(48<<16),PR_LIGHT_PRIO_LOW); - s->x -= x; - s->y -= y; - } - break; + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), 1024, 255+(48<<8)+(48<<16),PR_LIGHT_PRIO_LOW); + s->x -= x; + s->y -= y; + } + break; } } #endif diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index f81ba70ef..153422724 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -204,7 +204,7 @@ void create_map_snapshot(void) { mapstate->sectors = (sectortype *)Bcalloc(1, sizeof(sectortype) * numsectors); mapstate->sectsiz = j = lzf_compress(§or[0], sizeof(sectortype) * numsectors, - &mapstate->sectors[0], sizeof(sectortype) * numsectors); + &mapstate->sectors[0], sizeof(sectortype) * numsectors); mapstate->sectors = (sectortype *)Brealloc(mapstate->sectors, j); mapstate->sectcrc = tempcrc; } @@ -223,7 +223,7 @@ void create_map_snapshot(void) { mapstate->walls = (walltype *)Bcalloc(1, sizeof(walltype) * numwalls); mapstate->wallsiz = j = lzf_compress(&wall[0], sizeof(walltype) * numwalls, - &mapstate->walls[0], sizeof(walltype) * numwalls); + &mapstate->walls[0], sizeof(walltype) * numwalls); mapstate->walls = (walltype *)Brealloc(mapstate->walls, j); mapstate->wallcrc = tempcrc; } @@ -251,7 +251,7 @@ void create_map_snapshot(void) Bmemcpy(spri++,&sprite[j],sizeof(spritetype)); } mapstate->spritesiz = j = lzf_compress(&tspri[0], sizeof(spritetype) * numsprites, - &mapstate->sprites[0], sizeof(spritetype) * numsprites); + &mapstate->sprites[0], sizeof(spritetype) * numsprites); mapstate->sprites = (spritetype *)Brealloc(mapstate->sprites, j); mapstate->spritecrc = tempcrc; Bfree(tspri); diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index 7eaa5ac64..e1ae9f75a 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -667,6 +667,8 @@ extern int32_t g_cameraDistance, g_cameraClock, g_playerFriction,g_showShareware extern int32_t g_networkBroadcastMode, g_movesPerPacket; extern int32_t g_gameQuit; +extern int32_t playerswhenstarted; + extern char pus,pub; extern int32_t g_damageCameras,g_freezerSelfDamage,g_tripbombLaserMode; diff --git a/polymer/eduke32/source/funct.h b/polymer/eduke32/source/funct.h index 9e593a011..10f533f7d 100644 --- a/polymer/eduke32/source/funct.h +++ b/polymer/eduke32/source/funct.h @@ -192,7 +192,7 @@ extern void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,in extern void G_DrawTileSmall(int32_t x,int32_t y,int32_t tilenum,int32_t shade,int32_t orientation); extern void G_DrawTilePalSmall(int32_t x,int32_t y,int32_t tilenum,int32_t shade,int32_t orientation,int32_t p); extern void Gv_ResetVars(void); -extern void A_ResetVars(int32_t iActor); +extern void __fastcall A_ResetVars(register int32_t iActor); extern int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb); @@ -219,10 +219,10 @@ extern void Gv_Init(void); extern void Gv_WriteSave(FILE *fil); extern int32_t Gv_ReadSave(int32_t fil); -extern int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer); -extern void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer); -extern int32_t __fastcall Gv_GetVarX(int32_t id); -extern void __fastcall Gv_SetVarX(int32_t id, int32_t lValue); +extern int32_t __fastcall Gv_GetVar(register int32_t id, register int32_t iActor, register int32_t iPlayer); +extern void __fastcall Gv_SetVar(register int32_t id, register int32_t lValue, register int32_t iActor, register int32_t iPlayer); +extern int32_t __fastcall Gv_GetVarX(register int32_t id); +extern void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue); // extern void SetGameArrayID(int32_t id,int32_t index, int32_t lValue); @@ -232,7 +232,7 @@ extern void C_ReportError(int32_t iError); extern void onvideomodechange(int32_t newmode); -extern void X_OnEvent(int32_t iEventID, int32_t sActor, int32_t sPlayer, int32_t lDist); +extern void X_OnEvent(register int32_t iEventID, register int32_t sActor, register int32_t sPlayer, register int32_t lDist); extern int32_t A_CheckSoundPlaying(int32_t i, int32_t num); extern int32_t S_CheckSoundPlaying(int32_t i, int32_t num); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index b21c60dee..a96164668 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -63,7 +63,6 @@ int32_t g_scriptSanityChecks = 1; #define TIMERUPDATESIZ 32 int32_t g_cameraDistance = 0, g_cameraClock = 0; -static int32_t playerswhenstarted; static int32_t qe,cp; static int32_t g_commandSetup = 0; int32_t g_noSetup = 0; @@ -8892,7 +8891,7 @@ static void G_ShowDebugHelp(void) "-q#\t\tFake multiplayer with # (2-8) players\n" "-rmnet\t\tUse network config file (OBSOLETE, see -net)\n" "-stun\t\tUse UDP hole punching for multiplayer connections\n" - "-unstable \tForce EDuke32 to execute unsafe CON commands (and crash)\n" + /*"-unstable \tForce EDuke32 to execute unsafe CON commands (and crash)\n"*/ "-w\t\tShow coordinates\n" "-z#/-condebug\tEnable line-by-line CON compile debugging at level #\n" ; @@ -9685,20 +9684,20 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) continue; } #endif -/* - if (!Bstrcasecmp(c+1,"unstable")) - { - initprintf("WARNING WARNING WARNING WARNING\n" - "EDuke32's runtime script error detection has been disabled via " - "the '-unstable' command line parameter. Bug reports from this " - "mode are NOT welcome and you should expect crashes in certain " - "mods. Please run EDuke32 without '-unstable' before sending " - "any bug reports.\n"); - g_scriptSanityChecks = 0; - i++; - continue; - } -*/ + /* + if (!Bstrcasecmp(c+1,"unstable")) + { + initprintf("WARNING WARNING WARNING WARNING\n" + "EDuke32's runtime script error detection has been disabled via " + "the '-unstable' command line parameter. Bug reports from this " + "mode are NOT welcome and you should expect crashes in certain " + "mods. Please run EDuke32 without '-unstable' before sending " + "any bug reports.\n"); + g_scriptSanityChecks = 0; + i++; + continue; + } + */ if (!Bstrcasecmp(c+1,"cachesize")) { if (argc > i+1) @@ -10379,7 +10378,8 @@ static void G_LoadExtraPalettes(void) #if defined(__APPLE__) && B_BIG_ENDIAN != 0 // this is almost as bad as just setting the value to 25 :P - g_numRealPalettes = (g_numRealPalettes * (uint64)0x0202020202 & (uint64)0x010884422010) % 1023; + g_numRealPalettes = ((g_numRealPalettes * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; + #endif for (j = 0; j < 256; j++) @@ -11135,9 +11135,22 @@ void app_main(int32_t argc,const char **argv) if (mod_dir[0] != '/') { + char cwd[BMAX_PATH]; + Bstrcat(root,mod_dir); addsearchpath(root); // addsearchpath(mod_dir); + + if (getcwd(cwd,BMAX_PATH)) + { + Bsprintf(cwd,"%s/%s",cwd,mod_dir); + if (!Bstrcmp(root, cwd)) + { + if (addsearchpath(cwd) == -2) + if (Bmkdir(cwd,S_IRWXU) == 0) addsearchpath(cwd); + } + } + #if defined(POLYMOST) && defined(USE_OPENGL) Bsprintf(tempbuf,"%s/%s",mod_dir,TEXCACHEFILE); Bstrcpy(TEXCACHEFILE,tempbuf); @@ -11390,8 +11403,6 @@ CLEAN_DIRECTORY: if (ud.multimode > 1) { - playerswhenstarted = ud.multimode; - if (ud.warp_on == 0) { ud.m_monsters_off = 1; @@ -11399,6 +11410,7 @@ CLEAN_DIRECTORY: } } + playerswhenstarted = ud.multimode; ud.last_level = -1; if (Bstrcasecmp(ud.rtsname,"DUKE.RTS") == 0 || diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 95215de8b..b96512bdc 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1899,20 +1899,21 @@ static int32_t C_GetNextValue(int32_t type) static inline int32_t C_IntPow2(int32_t v) { - return ((v!=0) && (v&(v-1))==0); + return ((v!=0) && (v&(v-1))==0); } static inline uint32_t C_Pow2IntLogBase2(int32_t v) { - static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, - 0xFF00FF00, 0xFFFF0000}; - register uint32_t r = (v & b[0]) != 0; - int32_t i = 4; - - for (; i > 0; i--) - r |= ((v & b[i]) != 0) << i; - - return r; + static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, + 0xFF00FF00, 0xFFFF0000 + }; + register uint32_t r = (v & b[0]) != 0; + int32_t i = 4; + + for (; i > 0; i--) + r |= ((v & b[i]) != 0) << i; + + return r; } static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr) @@ -1929,7 +1930,7 @@ static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr) C_ReportError(-1); g_numCompilerWarnings++; initprintf("%s:%d: warning: malformed `%s' branch\n",g_szScriptFileName,g_lineNumber, - keyw[*(g_scriptPtr) & 0xFFF]); + keyw[*(g_scriptPtr) & 0xFFF]); return 1; } return 0; @@ -3904,45 +3905,52 @@ static int32_t C_ParseCommand(void) case CON_SHIFTVARL: case CON_SHIFTVARR: + { + intptr_t *inst = g_scriptPtr-1; + char *tptr = textptr; + // syntax: [rand|add|set]var + // sets var1 to const1 + // adds const1 to var1 (const1 can be negative...) + //printf("Found [add|set]var at line= %d\n",g_lineNumber); + + // get the ID of the DEF + if (tw != CON_ZSHOOT && tw != CON_EZSHOOT) + C_GetNextVarType(GAMEVAR_READONLY); + else C_GetNextVar(); + + C_GetNextValue(LABEL_DEFINE); // the number to check against... + + if (tw == CON_MULVAR && *(g_scriptPtr-1) == -1) { - intptr_t *inst = g_scriptPtr-1; - char *tptr = textptr; - // syntax: [rand|add|set]var - // sets var1 to const1 - // adds const1 to var1 (const1 can be negative...) - //printf("Found [add|set]var at line= %d\n",g_lineNumber); + *inst = CON_INV; + g_scriptPtr--; + return 0; + } - // get the ID of the DEF - if (tw != CON_ZSHOOT && tw != CON_EZSHOOT) - C_GetNextVarType(GAMEVAR_READONLY); - else C_GetNextVar(); + if (tw == CON_DIVVAR || (tw == CON_MULVAR && *(g_scriptPtr-1) > 0)) + { + int32_t i = *(g_scriptPtr-1); + j = klabs(*(g_scriptPtr-1)); - C_GetNextValue(LABEL_DEFINE); // the number to check against... - - if (tw == CON_DIVVAR || (tw == CON_MULVAR && *(g_scriptPtr-1) > 0)) + if (C_IntPow2(j)) { - int32_t i = *(g_scriptPtr-1); - j = klabs(*(g_scriptPtr-1)); - - if (C_IntPow2(j)) - { - *inst = ((tw == CON_DIVVAR) ? CON_SHIFTVARR : CON_SHIFTVARL); - *(g_scriptPtr-1) = C_Pow2IntLogBase2(j); + *inst = ((tw == CON_DIVVAR) ? CON_SHIFTVARR : CON_SHIFTVARL); + *(g_scriptPtr-1) = C_Pow2IntLogBase2(j); // initprintf("%s:%d: replacing multiply/divide with shift\n",g_szScriptFileName,g_lineNumber); - if (i == j) - return 0; + if (i == j) + return 0; - *g_scriptPtr++ = CON_INV + (g_lineNumber<<12); - textptr = tptr; - C_GetNextVarType(GAMEVAR_READONLY); - C_GetNextValue(LABEL_DEFINE); - g_scriptPtr--; + *g_scriptPtr++ = CON_INV + (g_lineNumber<<12); + textptr = tptr; + C_GetNextVarType(GAMEVAR_READONLY); + C_GetNextValue(LABEL_DEFINE); + g_scriptPtr--; // initprintf("%s:%d: adding inversion\n",g_szScriptFileName,g_lineNumber); - } } } - return 0; + } + return 0; case CON_WRITEARRAYTOFILE: case CON_READARRAYFROMFILE: C_GetNextLabelName(); diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index f015eefc1..ea0bdec43 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -39,7 +39,7 @@ vmstate_t vm; int32_t g_errorLineNum; int32_t g_tw; -static int32_t X_DoExecute(int32_t once); +static int32_t X_DoExecute(register int32_t once); #include "gamestructures.c" @@ -62,7 +62,7 @@ void X_ScriptInfo(void) } } -void X_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist) +void X_OnEvent(register int32_t iEventID, register int32_t iActor, register int32_t iPlayer, register int32_t lDist) { if (iEventID<0 || iEventID >= MAXGAMEEVENTS) { @@ -645,7 +645,7 @@ static void X_Move(void) } } -static inline void __fastcall X_DoConditional(int32_t condition) +static inline void __fastcall X_DoConditional(register int32_t condition) { if (condition) { @@ -664,9 +664,9 @@ static inline void __fastcall X_DoConditional(int32_t condition) } } -static int32_t X_DoExecute(int32_t once) +static int32_t X_DoExecute(register int32_t once) { - int32_t tw; + register int32_t tw; do { @@ -712,140 +712,140 @@ static int32_t X_DoExecute(int32_t once) break; case CON_IFCANSHOOTTARGET: + { + int32_t j; + if (vm.g_x > 1024) { - int32_t j; - if (vm.g_x > 1024) + int16_t temphit, sclip = 768, angdif = 16; + + j = A_CheckHitSprite(vm.g_i,&temphit); + + if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->xrepeat > 56) { - int16_t temphit, sclip = 768, angdif = 16; - - j = A_CheckHitSprite(vm.g_i,&temphit); - - if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->xrepeat > 56) - { - sclip = 3084; - angdif = 48; - } - - if (j == (1<<30)) - { - X_DoConditional(1); - break; - } - if (j > sclip) - { - if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else - { - vm.g_sp->ang += angdif; - j = A_CheckHitSprite(vm.g_i,&temphit); - vm.g_sp->ang -= angdif; - if (j > sclip) - { - if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else - { - vm.g_sp->ang -= angdif; - j = A_CheckHitSprite(vm.g_i,&temphit); - vm.g_sp->ang += angdif; - if (j > 768) - { - if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else j = 1; - } - else j = 0; - } - } - else j = 0; - } - } - else j = 0; + sclip = 3084; + angdif = 48; } - else j = 1; - X_DoConditional(j); + if (j == (1<<30)) + { + X_DoConditional(1); + break; + } + if (j > sclip) + { + if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) + j = 0; + else + { + vm.g_sp->ang += angdif; + j = A_CheckHitSprite(vm.g_i,&temphit); + vm.g_sp->ang -= angdif; + if (j > sclip) + { + if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) + j = 0; + else + { + vm.g_sp->ang -= angdif; + j = A_CheckHitSprite(vm.g_i,&temphit); + vm.g_sp->ang += angdif; + if (j > 768) + { + if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) + j = 0; + else j = 1; + } + else j = 0; + } + } + else j = 0; + } + } + else j = 0; } - break; + else j = 1; + + X_DoConditional(j); + } + break; case CON_IFCANSEETARGET: - { - int32_t j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-((krand()&41)<<8), - vm.g_sp->sectnum,g_player[vm.g_p].ps->posx,g_player[vm.g_p].ps->posy, - g_player[vm.g_p].ps->posz/*-((krand()&41)<<8)*/,sprite[g_player[vm.g_p].ps->i].sectnum); - X_DoConditional(j); - if (j) ActorExtra[vm.g_i].timetosleep = SLEEPTIME; - } - break; + { + int32_t j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-((krand()&41)<<8), + vm.g_sp->sectnum,g_player[vm.g_p].ps->posx,g_player[vm.g_p].ps->posy, + g_player[vm.g_p].ps->posz/*-((krand()&41)<<8)*/,sprite[g_player[vm.g_p].ps->i].sectnum); + X_DoConditional(j); + if (j) ActorExtra[vm.g_i].timetosleep = SLEEPTIME; + } + break; case CON_IFACTORNOTSTAYPUT: X_DoConditional(ActorExtra[vm.g_i].actorstayput == -1); break; case CON_IFCANSEE: + { + spritetype *s = &sprite[g_player[vm.g_p].ps->i]; + int32_t j; + + // select sprite for monster to target + // if holoduke is on, let them target holoduke first. + // + if (g_player[vm.g_p].ps->holoduke_on >= 0) { - spritetype *s = &sprite[g_player[vm.g_p].ps->i]; - int32_t j; - - // select sprite for monster to target - // if holoduke is on, let them target holoduke first. - // - if (g_player[vm.g_p].ps->holoduke_on >= 0) - { - s = &sprite[g_player[vm.g_p].ps->holoduke_on]; - j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-(krand()&((32<<8)-1)),vm.g_sp->sectnum, - s->x,s->y,s->z,s->sectnum); - - if (j == 0) - { - // they can't see player's holoduke - // check for player... - s = &sprite[g_player[vm.g_p].ps->i]; - } - } - - // can they see player, (or player's holoduke) - j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-(krand()&((47<<8))),vm.g_sp->sectnum, - s->x,s->y,s->z-(24<<8),s->sectnum); + s = &sprite[g_player[vm.g_p].ps->holoduke_on]; + j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-(krand()&((32<<8)-1)),vm.g_sp->sectnum, + s->x,s->y,s->z,s->sectnum); if (j == 0) { - // they can't see it. - - // Huh?. This does nothing.... - // (the result is always j==0....) - // if ((klabs(ActorExtra[vm.g_i].lastvx-vm.g_sp->x)+klabs(ActorExtra[vm.g_i].lastvy-vm.g_sp->y)) < - // (klabs(ActorExtra[vm.g_i].lastvx-s->x)+klabs(ActorExtra[vm.g_i].lastvy-s->y))) - // j = 0; - - // um yeah, this if() will always fire.... - // if (j == 0) - { - // search around for target player - - // also modifies 'target' x&y if found.. - - j = 1; - if (A_FurthestVisiblePoint(vm.g_i,s,&ActorExtra[vm.g_i].lastvx,&ActorExtra[vm.g_i].lastvy) == -1) - j = 0; - } + // they can't see player's holoduke + // check for player... + s = &sprite[g_player[vm.g_p].ps->i]; } - else - { - // else, they did see it. - // save where we were looking... - ActorExtra[vm.g_i].lastvx = s->x; - ActorExtra[vm.g_i].lastvy = s->y; - } - - if (j && (vm.g_sp->statnum == 1 || vm.g_sp->statnum == 6)) - ActorExtra[vm.g_i].timetosleep = SLEEPTIME; - - X_DoConditional(j); - break; } + // can they see player, (or player's holoduke) + j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-(krand()&((47<<8))),vm.g_sp->sectnum, + s->x,s->y,s->z-(24<<8),s->sectnum); + + if (j == 0) + { + // they can't see it. + + // Huh?. This does nothing.... + // (the result is always j==0....) + // if ((klabs(ActorExtra[vm.g_i].lastvx-vm.g_sp->x)+klabs(ActorExtra[vm.g_i].lastvy-vm.g_sp->y)) < + // (klabs(ActorExtra[vm.g_i].lastvx-s->x)+klabs(ActorExtra[vm.g_i].lastvy-s->y))) + // j = 0; + + // um yeah, this if() will always fire.... + // if (j == 0) + { + // search around for target player + + // also modifies 'target' x&y if found.. + + j = 1; + if (A_FurthestVisiblePoint(vm.g_i,s,&ActorExtra[vm.g_i].lastvx,&ActorExtra[vm.g_i].lastvy) == -1) + j = 0; + } + } + else + { + // else, they did see it. + // save where we were looking... + ActorExtra[vm.g_i].lastvx = s->x; + ActorExtra[vm.g_i].lastvy = s->y; + } + + if (j && (vm.g_sp->statnum == 1 || vm.g_sp->statnum == 6)) + ActorExtra[vm.g_i].timetosleep = SLEEPTIME; + + X_DoConditional(j); + break; + } + case CON_IFHITWEAPON: X_DoConditional(A_IncurDamage(vm.g_i) >= 0); break; @@ -1137,7 +1137,7 @@ static int32_t X_DoExecute(int32_t once) default: // fix for flying/jumping monsters getting stuck in water if (vm.g_sp->hitag & jumptoplayer || (actorscrptr[vm.g_sp->picnum] && - moveptr >= &script[0] && moveptr <= (&script[0]+g_scriptSize) && *(moveptr+1))) + moveptr >= &script[0] && moveptr <= (&script[0]+g_scriptSize) && *(moveptr+1))) { // OSD_Printf("%d\n",*(moveptr+1)); break; @@ -1316,7 +1316,7 @@ static int32_t X_DoExecute(int32_t once) if (*insptr > 0) { if ((j - *insptr) < (g_player[vm.g_p].ps->max_player_health>>2) && - j >= (g_player[vm.g_p].ps->max_player_health>>2)) + j >= (g_player[vm.g_p].ps->max_player_health>>2)) A_PlaySound(DUKE_GOTHEALTHATLOW,g_player[vm.g_p].ps->i); g_player[vm.g_p].ps->last_extra = j; @@ -1330,14 +1330,14 @@ static int32_t X_DoExecute(int32_t once) break; case CON_STATE: - { - intptr_t *tempscrptr=insptr+2; + { + intptr_t *tempscrptr=insptr+2; - insptr = (intptr_t *) *(insptr+1); - X_DoExecute(0); - insptr = tempscrptr; - } - break; + insptr = (intptr_t *) *(insptr+1); + X_DoExecute(0); + insptr = tempscrptr; + } + break; case CON_LEFTBRACE: insptr++; @@ -1402,7 +1402,7 @@ static int32_t X_DoExecute(int32_t once) G_OperateSectors(var1, var2); break; case CON_OPERATEACTIVATORS: - if ((var2<0 || var2>=ud.multimode) /* && g_scriptSanityChecks */) {OSD_Printf(CON_ERROR "Invalid player %d\n",g_errorLineNum,keyw[g_tw],var2); break;} + if ((var2<0 || var2>=playerswhenstarted) /* && g_scriptSanityChecks */) {OSD_Printf(CON_ERROR "Invalid player %d\n",g_errorLineNum,keyw[g_tw],var2); break;} G_OperateActivators(var1, var2); break; case CON_SETASPECT: @@ -1427,7 +1427,7 @@ static int32_t X_DoExecute(int32_t once) res=0; } else res=cansee(sprite[lVar1].x,sprite[lVar1].y,sprite[lVar1].z,sprite[lVar1].sectnum, - sprite[lVar2].x,sprite[lVar2].y,sprite[lVar2].z,sprite[lVar2].sectnum); + sprite[lVar2].x,sprite[lVar2].y,sprite[lVar2].z,sprite[lVar2].sectnum); Gv_SetVarX(*insptr++, res); break; @@ -1563,7 +1563,7 @@ static int32_t X_DoExecute(int32_t once) insptr++; { int32_t i = Gv_GetVarX(*insptr++), - f=Gv_GetVarX(*insptr++); + f=Gv_GetVarX(*insptr++); int32_t j=Gv_GetVarX(*insptr++); if ((i<0 || i>=MAXQUOTES) /* && g_scriptSanityChecks */) OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],i); @@ -1590,24 +1590,42 @@ static int32_t X_DoExecute(int32_t once) case CON_QSUBSTR: insptr++; { - char *s1,*s2; - int32_t q1,q2,st,ln; + int32_t q1 = Gv_GetVarX(*insptr++); + int32_t q2 = Gv_GetVarX(*insptr++); + int32_t st = Gv_GetVarX(*insptr++); + int32_t ln = Gv_GetVarX(*insptr++); - q1 = Gv_GetVarX(*insptr++), - q2 = Gv_GetVarX(*insptr++); - st = Gv_GetVarX(*insptr++); - ln = Gv_GetVarX(*insptr++); - - if ((q1<0 || q1>=MAXQUOTES) /* && g_scriptSanityChecks */) OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],q1); - else if ((ScriptQuotes[q1] == NULL) /* && g_scriptSanityChecks */) OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q1); - else if ((q2<0 || q2>=MAXQUOTES) /* && g_scriptSanityChecks */) OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],q2); - else if ((ScriptQuotes[q2] == NULL) /* && g_scriptSanityChecks */) OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q2); - else + if ((q1<0 || q1>=MAXQUOTES) /* && g_scriptSanityChecks */) { - s1=ScriptQuotes[q1]; - s2=ScriptQuotes[q2]; - while (*s2&&st--)s2++; - while ((*s1=*s2)&&ln--) {s1++; s2++;} + OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],q1); + break; + } + if ((ScriptQuotes[q1] == NULL) /* && g_scriptSanityChecks */) + { + OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q1); + break; + } + if ((q2<0 || q2>=MAXQUOTES) /* && g_scriptSanityChecks */) + { + OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],q2); + break; + } + if ((ScriptQuotes[q2] == NULL) /* && g_scriptSanityChecks */) + { + OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q2); + break; + } + + { + char *s1 = ScriptQuotes[q1]; + char *s2 = ScriptQuotes[q2]; + + while (*s2 && st--) s2++; + while ((*s1 = *s2) && ln--) + { + s1++; + s2++; + } *s1=0; } break; @@ -1788,20 +1806,20 @@ static int32_t X_DoExecute(int32_t once) G_DrawTile(x,y,tilenum,shade,orientation); break; case CON_MYOSPAL: - { - int32_t pal=Gv_GetVarX(*insptr++); - G_DrawTilePal(x,y,tilenum,shade,orientation,pal); - break; - } + { + int32_t pal=Gv_GetVarX(*insptr++); + G_DrawTilePal(x,y,tilenum,shade,orientation,pal); + break; + } case CON_MYOSX: G_DrawTileSmall(x,y,tilenum,shade,orientation); break; case CON_MYOSPALX: - { - int32_t pal=Gv_GetVarX(*insptr++); - G_DrawTilePalSmall(x,y,tilenum,shade,orientation,pal); - break; - } + { + int32_t pal=Gv_GetVarX(*insptr++); + G_DrawTilePalSmall(x,y,tilenum,shade,orientation,pal); + break; + } } break; } @@ -1900,25 +1918,36 @@ static int32_t X_DoExecute(int32_t once) break; } - case CON_DIST: case CON_LDIST: insptr++; { - int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++), distx=0; + int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); if ((xvar < 0 || yvar < 0 || xvar >= MAXSPRITES || yvar >= MAXSPRITES) /* && g_scriptSanityChecks */) { OSD_Printf(CON_ERROR "invalid sprite\n",g_errorLineNum,keyw[g_tw]); break; } - if (tw == CON_DIST) distx = dist(&sprite[xvar],&sprite[yvar]); - else distx = ldist(&sprite[xvar],&sprite[yvar]); - Gv_SetVarX(distvar, distx); + Gv_SetVarX(distvar, ldist(&sprite[xvar],&sprite[yvar])); + break; + } + + case CON_DIST: + insptr++; + { + int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); + + if ((xvar < 0 || yvar < 0 || xvar >= MAXSPRITES || yvar >= MAXSPRITES) /* && g_scriptSanityChecks */) + { + OSD_Printf(CON_ERROR "invalid sprite\n",g_errorLineNum,keyw[g_tw]); + break; + } + + Gv_SetVarX(distvar, dist(&sprite[xvar],&sprite[yvar])); break; } - case CON_GETINCANGLE: case CON_GETANGLE: insptr++; { @@ -1926,11 +1955,17 @@ static int32_t X_DoExecute(int32_t once) int32_t xvar = Gv_GetVarX(*insptr++); int32_t yvar = Gv_GetVarX(*insptr++); - if (tw==CON_GETANGLE) - { - Gv_SetVarX(angvar, getangle(xvar,yvar)); - break; - } + Gv_SetVarX(angvar, getangle(xvar,yvar)); + break; + } + + case CON_GETINCANGLE: + insptr++; + { + int32_t angvar = *insptr++; + int32_t xvar = Gv_GetVarX(*insptr++); + int32_t yvar = Gv_GetVarX(*insptr++); + Gv_SetVarX(angvar, G_GetAngleDelta(xvar,yvar)); break; } @@ -2059,34 +2094,34 @@ static int32_t X_DoExecute(int32_t once) case CON_ESHOOTVAR: case CON_EZSHOOTVAR: case CON_ZSHOOTVAR: + { + int32_t lReturn=-1; + int32_t j; + + insptr++; + + if (tw == CON_ZSHOOTVAR || tw == CON_EZSHOOTVAR) { - int32_t lReturn=-1; - int32_t j; + ActorExtra[vm.g_i].temp_data[9] = Gv_GetVarX(*insptr++); + if (ActorExtra[vm.g_i].temp_data[9] == 0) + ActorExtra[vm.g_i].temp_data[9] = 1; + } + j=Gv_GetVarX(*insptr++); - insptr++; - - if (tw == CON_ZSHOOTVAR || tw == CON_EZSHOOTVAR) - { - ActorExtra[vm.g_i].temp_data[9] = Gv_GetVarX(*insptr++); - if (ActorExtra[vm.g_i].temp_data[9] == 0) - ActorExtra[vm.g_i].temp_data[9] = 1; - } - j=Gv_GetVarX(*insptr++); - - if ((vm.g_sp->sectnum < 0 || vm.g_sp->sectnum >= numsectors) /* && g_scriptSanityChecks */) - { - OSD_Printf(CON_ERROR "Invalid sector %d\n",g_errorLineNum,keyw[g_tw],vm.g_sp->sectnum); - ActorExtra[vm.g_i].temp_data[9]=0; - break; - } - - lReturn = A_Shoot(vm.g_i, j); - if (tw == CON_ESHOOTVAR || tw == CON_EZSHOOTVAR) - aGameVars[g_iReturnVarID].val.lValue = lReturn; + if ((vm.g_sp->sectnum < 0 || vm.g_sp->sectnum >= numsectors) /* && g_scriptSanityChecks */) + { + OSD_Printf(CON_ERROR "Invalid sector %d\n",g_errorLineNum,keyw[g_tw],vm.g_sp->sectnum); ActorExtra[vm.g_i].temp_data[9]=0; break; } + lReturn = A_Shoot(vm.g_i, j); + if (tw == CON_ESHOOTVAR || tw == CON_EZSHOOTVAR) + aGameVars[g_iReturnVarID].val.lValue = lReturn; + ActorExtra[vm.g_i].temp_data[9]=0; + break; + } + case CON_CMENU: insptr++; ChangeToMenu(Gv_GetVarX(*insptr++)); @@ -2137,27 +2172,27 @@ static int32_t X_DoExecute(int32_t once) case CON_SAVEGAMEVAR: case CON_READGAMEVAR: + { + int32_t i=0; + insptr++; + if (ud.config.scripthandle < 0) { - int32_t i=0; insptr++; - if (ud.config.scripthandle < 0) - { - insptr++; - break; - } - switch (tw) - { - case CON_SAVEGAMEVAR: - i=Gv_GetVarX(*insptr); - SCRIPT_PutNumber(ud.config.scripthandle, "Gamevars",aGameVars[*insptr++].szLabel,i,FALSE,FALSE); - break; - case CON_READGAMEVAR: - SCRIPT_GetNumber(ud.config.scripthandle, "Gamevars",aGameVars[*insptr].szLabel,&i); - Gv_SetVarX(*insptr++, i); - break; - } break; } + switch (tw) + { + case CON_SAVEGAMEVAR: + i=Gv_GetVarX(*insptr); + SCRIPT_PutNumber(ud.config.scripthandle, "Gamevars",aGameVars[*insptr++].szLabel,i,FALSE,FALSE); + break; + case CON_READGAMEVAR: + SCRIPT_GetNumber(ud.config.scripthandle, "Gamevars",aGameVars[*insptr].szLabel,&i); + Gv_SetVarX(*insptr++, i); + break; + } + break; + } case CON_SHOWVIEW: insptr++; @@ -2210,9 +2245,9 @@ static int32_t X_DoExecute(int32_t once) #endif if (((gotpic[MIRROR>>3]&(1<<(MIRROR&7))) > 0) #if defined(POLYMER) && defined(USE_OPENGL) - && (getrendermode() != 4) + && (getrendermode() != 4) #endif - ) + ) { int32_t j, i = 0, k, dst = 0x7fffffff; @@ -2596,16 +2631,16 @@ static int32_t X_DoExecute(int32_t once) else s = (krand()%3); l = A_InsertSprite(vm.g_sp->sectnum, - vm.g_sp->x+(krand()&255)-128,vm.g_sp->y+(krand()&255)-128,vm.g_sp->z-(8<<8)-(krand()&8191), - dnum+s,vm.g_sp->shade,32+(krand()&15),32+(krand()&15), - krand()&2047,(krand()&127)+32, - -(krand()&2047),vm.g_i,5); + vm.g_sp->x+(krand()&255)-128,vm.g_sp->y+(krand()&255)-128,vm.g_sp->z-(8<<8)-(krand()&8191), + dnum+s,vm.g_sp->shade,32+(krand()&15),32+(krand()&15), + krand()&2047,(krand()&127)+32, + -(krand()&2047),vm.g_i,5); if (vm.g_sp->picnum == BLIMP && dnum == SCRAP1) sprite[l].yvel = BlimpSpawnSprites[j%14]; else sprite[l].yvel = -1; sprite[l].pal = vm.g_sp->pal; } - insptr++; + insptr++; } break; @@ -2676,90 +2711,90 @@ static int32_t X_DoExecute(int32_t once) break; case CON_RESETPLAYER: + { + insptr++; + + //AddLog("resetplayer"); + if (ud.multimode < 2) { - insptr++; - - //AddLog("resetplayer"); - if (ud.multimode < 2) + if (g_lastSaveSlot >= 0 && ud.recstat != 2) { - if (g_lastSaveSlot >= 0 && ud.recstat != 2) - { - g_player[vm.g_p].ps->gm = MODE_MENU; - KB_ClearKeyDown(sc_Space); - ChangeToMenu(15000); - } - else g_player[vm.g_p].ps->gm = MODE_RESTART; - vm.g_killitFlag = 2; + g_player[vm.g_p].ps->gm = MODE_MENU; + KB_ClearKeyDown(sc_Space); + ChangeToMenu(15000); } - else - { - vec3_t tmpvect; - - tmpvect.x = g_player[vm.g_p].ps->posx; - tmpvect.y = g_player[vm.g_p].ps->posy; - tmpvect.z = g_player[vm.g_p].ps->posz+PHEIGHT; - P_RandomSpawnPoint(vm.g_p); - vm.g_sp->x = ActorExtra[vm.g_i].bposx = g_player[vm.g_p].ps->bobposx = g_player[vm.g_p].ps->oposx = g_player[vm.g_p].ps->posx; - vm.g_sp->y = ActorExtra[vm.g_i].bposy = g_player[vm.g_p].ps->bobposy = g_player[vm.g_p].ps->oposy =g_player[vm.g_p].ps->posy; - vm.g_sp->z = ActorExtra[vm.g_i].bposy = g_player[vm.g_p].ps->oposz =g_player[vm.g_p].ps->posz; - updatesector(g_player[vm.g_p].ps->posx,g_player[vm.g_p].ps->posy,&g_player[vm.g_p].ps->cursectnum); - setsprite(g_player[vm.g_p].ps->i,&tmpvect); - vm.g_sp->cstat = 257; - - vm.g_sp->shade = -12; - vm.g_sp->clipdist = 64; - vm.g_sp->xrepeat = 42; - vm.g_sp->yrepeat = 36; - vm.g_sp->owner = vm.g_i; - vm.g_sp->xoffset = 0; - vm.g_sp->pal = g_player[vm.g_p].ps->palookup; - - g_player[vm.g_p].ps->last_extra = vm.g_sp->extra = g_player[vm.g_p].ps->max_player_health; - g_player[vm.g_p].ps->wantweaponfire = -1; - g_player[vm.g_p].ps->horiz = 100; - g_player[vm.g_p].ps->on_crane = -1; - g_player[vm.g_p].ps->frag_ps = vm.g_p; - g_player[vm.g_p].ps->horizoff = 0; - g_player[vm.g_p].ps->opyoff = 0; - g_player[vm.g_p].ps->wackedbyactor = -1; - g_player[vm.g_p].ps->shield_amount = g_startArmorAmount; - g_player[vm.g_p].ps->dead_flag = 0; - g_player[vm.g_p].ps->pals_time = 0; - g_player[vm.g_p].ps->footprintcount = 0; - g_player[vm.g_p].ps->weapreccnt = 0; - g_player[vm.g_p].ps->fta = 0; - g_player[vm.g_p].ps->ftq = 0; - g_player[vm.g_p].ps->posxv = g_player[vm.g_p].ps->posyv = 0; - g_player[vm.g_p].ps->rotscrnang = 0; - g_player[vm.g_p].ps->runspeed = g_playerFriction; - g_player[vm.g_p].ps->falling_counter = 0; - - ActorExtra[vm.g_i].extra = -1; - ActorExtra[vm.g_i].owner = vm.g_i; - - ActorExtra[vm.g_i].cgg = 0; - ActorExtra[vm.g_i].movflag = 0; - ActorExtra[vm.g_i].tempang = 0; - ActorExtra[vm.g_i].actorstayput = -1; - ActorExtra[vm.g_i].dispicnum = 0; - ActorExtra[vm.g_i].owner = g_player[vm.g_p].ps->i; - - P_ResetInventory(vm.g_p); - P_ResetWeapons(vm.g_p); - - g_player[vm.g_p].ps->reloading = 0; - - g_player[vm.g_p].ps->movement_lock = 0; - - if (apScriptGameEvent[EVENT_RESETPLAYER]) - X_OnEvent(EVENT_RESETPLAYER, g_player[vm.g_p].ps->i, vm.g_p, -1); - g_cameraDistance = 0; - g_cameraClock = totalclock; - } - P_UpdateScreenPal(g_player[vm.g_p].ps); - //AddLog("EOF: resetplayer"); + else g_player[vm.g_p].ps->gm = MODE_RESTART; + vm.g_killitFlag = 2; } - break; + else + { + vec3_t tmpvect; + + tmpvect.x = g_player[vm.g_p].ps->posx; + tmpvect.y = g_player[vm.g_p].ps->posy; + tmpvect.z = g_player[vm.g_p].ps->posz+PHEIGHT; + P_RandomSpawnPoint(vm.g_p); + vm.g_sp->x = ActorExtra[vm.g_i].bposx = g_player[vm.g_p].ps->bobposx = g_player[vm.g_p].ps->oposx = g_player[vm.g_p].ps->posx; + vm.g_sp->y = ActorExtra[vm.g_i].bposy = g_player[vm.g_p].ps->bobposy = g_player[vm.g_p].ps->oposy =g_player[vm.g_p].ps->posy; + vm.g_sp->z = ActorExtra[vm.g_i].bposy = g_player[vm.g_p].ps->oposz =g_player[vm.g_p].ps->posz; + updatesector(g_player[vm.g_p].ps->posx,g_player[vm.g_p].ps->posy,&g_player[vm.g_p].ps->cursectnum); + setsprite(g_player[vm.g_p].ps->i,&tmpvect); + vm.g_sp->cstat = 257; + + vm.g_sp->shade = -12; + vm.g_sp->clipdist = 64; + vm.g_sp->xrepeat = 42; + vm.g_sp->yrepeat = 36; + vm.g_sp->owner = vm.g_i; + vm.g_sp->xoffset = 0; + vm.g_sp->pal = g_player[vm.g_p].ps->palookup; + + g_player[vm.g_p].ps->last_extra = vm.g_sp->extra = g_player[vm.g_p].ps->max_player_health; + g_player[vm.g_p].ps->wantweaponfire = -1; + g_player[vm.g_p].ps->horiz = 100; + g_player[vm.g_p].ps->on_crane = -1; + g_player[vm.g_p].ps->frag_ps = vm.g_p; + g_player[vm.g_p].ps->horizoff = 0; + g_player[vm.g_p].ps->opyoff = 0; + g_player[vm.g_p].ps->wackedbyactor = -1; + g_player[vm.g_p].ps->shield_amount = g_startArmorAmount; + g_player[vm.g_p].ps->dead_flag = 0; + g_player[vm.g_p].ps->pals_time = 0; + g_player[vm.g_p].ps->footprintcount = 0; + g_player[vm.g_p].ps->weapreccnt = 0; + g_player[vm.g_p].ps->fta = 0; + g_player[vm.g_p].ps->ftq = 0; + g_player[vm.g_p].ps->posxv = g_player[vm.g_p].ps->posyv = 0; + g_player[vm.g_p].ps->rotscrnang = 0; + g_player[vm.g_p].ps->runspeed = g_playerFriction; + g_player[vm.g_p].ps->falling_counter = 0; + + ActorExtra[vm.g_i].extra = -1; + ActorExtra[vm.g_i].owner = vm.g_i; + + ActorExtra[vm.g_i].cgg = 0; + ActorExtra[vm.g_i].movflag = 0; + ActorExtra[vm.g_i].tempang = 0; + ActorExtra[vm.g_i].actorstayput = -1; + ActorExtra[vm.g_i].dispicnum = 0; + ActorExtra[vm.g_i].owner = g_player[vm.g_p].ps->i; + + P_ResetInventory(vm.g_p); + P_ResetWeapons(vm.g_p); + + g_player[vm.g_p].ps->reloading = 0; + + g_player[vm.g_p].ps->movement_lock = 0; + + if (apScriptGameEvent[EVENT_RESETPLAYER]) + X_OnEvent(EVENT_RESETPLAYER, g_player[vm.g_p].ps->i, vm.g_p, -1); + g_cameraDistance = 0; + g_cameraClock = totalclock; + } + P_UpdateScreenPal(g_player[vm.g_p].ps); + //AddLog("EOF: resetplayer"); + } + break; case CON_IFONWATER: X_DoConditional(sector[vm.g_sp->sectnum].lotag == 1 && klabs(vm.g_sp->z-sector[vm.g_sp->sectnum].floorz) < (32<<8)); @@ -2865,61 +2900,61 @@ static int32_t X_DoExecute(int32_t once) break; case CON_IFP: + { + // insptr++; + + int32_t l = *(++insptr); + int32_t j = 0; + int32_t s = sprite[g_player[vm.g_p].ps->i].xvel; + + if ((l&8) && g_player[vm.g_p].ps->on_ground && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_CROUCH)) + j = 1; + else if ((l&16) && g_player[vm.g_p].ps->jumping_counter == 0 && !g_player[vm.g_p].ps->on_ground && + g_player[vm.g_p].ps->poszv > 2048) + j = 1; + else if ((l&32) && g_player[vm.g_p].ps->jumping_counter > 348) + j = 1; + else if ((l&1) && s >= 0 && s < 8) + j = 1; + else if ((l&2) && s >= 8 && !TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) + j = 1; + else if ((l&4) && s >= 8 && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) + j = 1; + else if ((l&64) && g_player[vm.g_p].ps->posz < (vm.g_sp->z-(48<<8))) + j = 1; + else if ((l&128) && s <= -8 && !TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) + j = 1; + else if ((l&256) && s <= -8 && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) + j = 1; + else if ((l&512) && (g_player[vm.g_p].ps->quick_kick > 0 || (g_player[vm.g_p].ps->curr_weapon == KNEE_WEAPON && g_player[vm.g_p].ps->kickback_pic > 0))) + j = 1; + else if ((l&1024) && sprite[g_player[vm.g_p].ps->i].xrepeat < 32) + j = 1; + else if ((l&2048) && g_player[vm.g_p].ps->jetpack_on) + j = 1; + else if ((l&4096) && g_player[vm.g_p].ps->steroids_amount > 0 && g_player[vm.g_p].ps->steroids_amount < 400) + j = 1; + else if ((l&8192) && g_player[vm.g_p].ps->on_ground) + j = 1; + else if ((l&16384) && sprite[g_player[vm.g_p].ps->i].xrepeat > 32 && sprite[g_player[vm.g_p].ps->i].extra > 0 && g_player[vm.g_p].ps->timebeforeexit == 0) + j = 1; + else if ((l&32768) && sprite[g_player[vm.g_p].ps->i].extra <= 0) + j = 1; + else if ((l&65536L)) { - // insptr++; + if (vm.g_sp->picnum == APLAYER && ud.multimode > 1) + j = G_GetAngleDelta(g_player[otherp].ps->ang,getangle(g_player[vm.g_p].ps->posx-g_player[otherp].ps->posx,g_player[vm.g_p].ps->posy-g_player[otherp].ps->posy)); + else + j = G_GetAngleDelta(g_player[vm.g_p].ps->ang,getangle(vm.g_sp->x-g_player[vm.g_p].ps->posx,vm.g_sp->y-g_player[vm.g_p].ps->posy)); - int32_t l = *(++insptr); - int32_t j = 0; - int32_t s = sprite[g_player[vm.g_p].ps->i].xvel; - - if ((l&8) && g_player[vm.g_p].ps->on_ground && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_CROUCH)) + if (j > -128 && j < 128) j = 1; - else if ((l&16) && g_player[vm.g_p].ps->jumping_counter == 0 && !g_player[vm.g_p].ps->on_ground && - g_player[vm.g_p].ps->poszv > 2048) - j = 1; - else if ((l&32) && g_player[vm.g_p].ps->jumping_counter > 348) - j = 1; - else if ((l&1) && s >= 0 && s < 8) - j = 1; - else if ((l&2) && s >= 8 && !TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) - j = 1; - else if ((l&4) && s >= 8 && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) - j = 1; - else if ((l&64) && g_player[vm.g_p].ps->posz < (vm.g_sp->z-(48<<8))) - j = 1; - else if ((l&128) && s <= -8 && !TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) - j = 1; - else if ((l&256) && s <= -8 && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_RUN)) - j = 1; - else if ((l&512) && (g_player[vm.g_p].ps->quick_kick > 0 || (g_player[vm.g_p].ps->curr_weapon == KNEE_WEAPON && g_player[vm.g_p].ps->kickback_pic > 0))) - j = 1; - else if ((l&1024) && sprite[g_player[vm.g_p].ps->i].xrepeat < 32) - j = 1; - else if ((l&2048) && g_player[vm.g_p].ps->jetpack_on) - j = 1; - else if ((l&4096) && g_player[vm.g_p].ps->steroids_amount > 0 && g_player[vm.g_p].ps->steroids_amount < 400) - j = 1; - else if ((l&8192) && g_player[vm.g_p].ps->on_ground) - j = 1; - else if ((l&16384) && sprite[g_player[vm.g_p].ps->i].xrepeat > 32 && sprite[g_player[vm.g_p].ps->i].extra > 0 && g_player[vm.g_p].ps->timebeforeexit == 0) - j = 1; - else if ((l&32768) && sprite[g_player[vm.g_p].ps->i].extra <= 0) - j = 1; - else if ((l&65536L)) - { - if (vm.g_sp->picnum == APLAYER && ud.multimode > 1) - j = G_GetAngleDelta(g_player[otherp].ps->ang,getangle(g_player[vm.g_p].ps->posx-g_player[otherp].ps->posx,g_player[vm.g_p].ps->posy-g_player[otherp].ps->posy)); - else - j = G_GetAngleDelta(g_player[vm.g_p].ps->ang,getangle(vm.g_sp->x-g_player[vm.g_p].ps->posx,vm.g_sp->y-g_player[vm.g_p].ps->posy)); - - if (j > -128 && j < 128) - j = 1; - else - j = 0; - } - X_DoConditional((intptr_t) j); + else + j = 0; } - break; + X_DoConditional((intptr_t) j); + } + break; case CON_IFSTRENGTH: insptr++; @@ -3095,12 +3130,12 @@ static int32_t X_DoExecute(int32_t once) } case CON_ADDLOG: - { - insptr++; + { + insptr++; - OSD_Printf(OSDTEXT_GREEN "CONLOG: L=%d\n",g_errorLineNum); - break; - } + OSD_Printf(OSDTEXT_GREEN "CONLOG: L=%d\n",g_errorLineNum); + break; + } case CON_ADDLOGVAR: insptr++; @@ -3132,7 +3167,7 @@ static int32_t X_DoExecute(int32_t once) if ((index < aGameArrays[lVarID].size)&&(index>=0)) { OSD_Printf(OSDTEXT_GREEN "%s: L=%d %s[%d] =%d\n",keyw[g_tw],g_errorLineNum, - aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]); + aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]); break; } else @@ -3440,6 +3475,22 @@ static int32_t X_DoExecute(int32_t once) break; case CON_SETPLAYER: + insptr++; + { + // syntax [gs]etplayer[].x + // + int32_t lVar1=*insptr++, lLabelID=*insptr++, lParm2 = 0, lVar2; + // HACK: need to have access to labels structure at run-time... + + if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2) + lParm2=Gv_GetVarX(*insptr++); + lVar2=*insptr++; + + X_SetPlayer(lVar1, lLabelID, lVar2, lParm2); + break; + } + + case CON_GETPLAYER: insptr++; { @@ -3452,7 +3503,7 @@ static int32_t X_DoExecute(int32_t once) lParm2=Gv_GetVarX(*insptr++); lVar2=*insptr++; - X_AccessPlayer(tw==CON_SETPLAYER, lVar1, lLabelID, lVar2, lParm2); + X_GetPlayer(lVar1, lLabelID, lVar2, lParm2); break; } @@ -3544,7 +3595,7 @@ static int32_t X_DoExecute(int32_t once) { int32_t lVar1=*insptr++, lVar2=*insptr++; - if ((iPlayer < 0 || iPlayer >= ud.multimode) /* && g_scriptSanityChecks */) + if ((iPlayer < 0 || iPlayer >= playerswhenstarted) /* && g_scriptSanityChecks */) { OSD_Printf(CON_ERROR "invalid player ID %d\n",g_errorLineNum,keyw[g_tw],iPlayer); if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++; @@ -3563,6 +3614,24 @@ static int32_t X_DoExecute(int32_t once) } case CON_SETACTOR: + insptr++; + { + // syntax [gs]etactor[].x + // + + int32_t lVar1=*insptr++, lLabelID=*insptr++, lParm2 = 0; + + if (ActorLabels[lLabelID].flags & LABEL_HASPARM2) + lParm2=Gv_GetVarX(*insptr++); + + { + int32_t lVar2=*insptr++; + + X_SetSprite(lVar1, lLabelID, lVar2, lParm2); + } + break; + } + case CON_GETACTOR: insptr++; { @@ -3577,7 +3646,7 @@ static int32_t X_DoExecute(int32_t once) { int32_t lVar2=*insptr++; - X_AccessSprite(tw==CON_SETACTOR, lVar1, lLabelID, lVar2, lParm2); + X_GetSprite(lVar1, lLabelID, lVar2, lParm2); } break; } @@ -3622,7 +3691,7 @@ static int32_t X_DoExecute(int32_t once) insptr++; - if ((j < 0 || j >= ud.multimode) /* && g_scriptSanityChecks */) + if ((j < 0 || j >= playerswhenstarted) /* && g_scriptSanityChecks */) { OSD_Printf(CON_ERROR "Invalid player ID %d\n",g_errorLineNum,keyw[g_tw],j); break; @@ -4166,34 +4235,34 @@ static int32_t X_DoExecute(int32_t once) break; case CON_WHILEVARN: + { + intptr_t *savedinsptr=insptr+2; + int32_t j; + do { - intptr_t *savedinsptr=insptr+2; - int32_t j; - do - { - insptr=savedinsptr; - j = (Gv_GetVarX(*(insptr-1)) != *insptr); - X_DoConditional(j); - } - while (j); - break; + insptr=savedinsptr; + j = (Gv_GetVarX(*(insptr-1)) != *insptr); + X_DoConditional(j); } + while (j); + break; + } case CON_WHILEVARVARN: + { + int32_t j; + intptr_t *savedinsptr=insptr+2; + do { - int32_t j; - intptr_t *savedinsptr=insptr+2; - do - { - insptr=savedinsptr; - j = Gv_GetVarX(*(insptr-1)); - j = (j != Gv_GetVarX(*insptr++)); - insptr--; - X_DoConditional(j); - } - while (j); - break; + insptr=savedinsptr; + j = Gv_GetVarX(*(insptr-1)); + j = (j != Gv_GetVarX(*insptr++)); + insptr--; + X_DoConditional(j); } + while (j); + break; + } case CON_IFVARAND: insptr++; @@ -4307,7 +4376,7 @@ static int32_t X_DoExecute(int32_t once) if (g_player[vm.g_p].ps->knee_incs == 0 && sprite[g_player[vm.g_p].ps->i].xrepeat >= 40) if (cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-(4<<8),vm.g_sp->sectnum,g_player[vm.g_p].ps->posx,g_player[vm.g_p].ps->posy,g_player[vm.g_p].ps->posz+(16<<8),sprite[g_player[vm.g_p].ps->i].sectnum)) { - int32_t j = ud.multimode-1; + int32_t j = playerswhenstarted-1; for (; j>=0; j--) { if (g_player[j].ps->actorsqu == vm.g_i) @@ -4321,31 +4390,31 @@ static int32_t X_DoExecute(int32_t once) g_player[vm.g_p].ps->actorsqu = vm.g_i; } } - break; + break; case CON_IFAWAYFROMWALL: - { - int16_t s1=vm.g_sp->sectnum; - int32_t j = 0; + { + int16_t s1=vm.g_sp->sectnum; + int32_t j = 0; - updatesector(vm.g_sp->x+108,vm.g_sp->y+108,&s1); + updatesector(vm.g_sp->x+108,vm.g_sp->y+108,&s1); + if (s1 == vm.g_sp->sectnum) + { + updatesector(vm.g_sp->x-108,vm.g_sp->y-108,&s1); if (s1 == vm.g_sp->sectnum) { - updatesector(vm.g_sp->x-108,vm.g_sp->y-108,&s1); + updatesector(vm.g_sp->x+108,vm.g_sp->y-108,&s1); if (s1 == vm.g_sp->sectnum) { - updatesector(vm.g_sp->x+108,vm.g_sp->y-108,&s1); + updatesector(vm.g_sp->x-108,vm.g_sp->y+108,&s1); if (s1 == vm.g_sp->sectnum) - { - updatesector(vm.g_sp->x-108,vm.g_sp->y+108,&s1); - if (s1 == vm.g_sp->sectnum) - j = 1; - } + j = 1; } } - X_DoConditional(j); } - break; + X_DoConditional(j); + } + break; case CON_QUOTE: insptr++; @@ -4428,15 +4497,15 @@ static int32_t X_DoExecute(int32_t once) break; case CON_IFNOSOUNDS: - { - int32_t j = MAXSOUNDS-1; - for (; j>=0; j--) - if (g_sounds[j].SoundOwner[0].i == vm.g_i) - break; + { + int32_t j = MAXSOUNDS-1; + for (; j>=0; j--) + if (g_sounds[j].SoundOwner[0].i == vm.g_i) + break; - X_DoConditional(j < 0); - } - break; + X_DoConditional(j < 0); + } + break; case CON_SPRITEFLAGS: insptr++; @@ -4471,15 +4540,15 @@ static int32_t X_DoExecute(int32_t once) X_ScriptInfo(); G_GameExit("An error has occurred in the EDuke32 virtual machine.\n\n" - "If you are an end user, please e-mail the file eduke32.log\n" - "along with links to any mods you're using to terminx@gmail.com.\n\n" - "If you are a mod developer, please attach all of your CON files\n" - "along with instructions on how to reproduce this error.\n\n" - "Thank you!"); + "If you are an end user, please e-mail the file eduke32.log\n" + "along with links to any mods you're using to terminx@gmail.com.\n\n" + "If you are a mod developer, please attach all of your CON files\n" + "along with instructions on how to reproduce this error.\n\n" + "Thank you!"); break; } } - while(!once); + while (!once); return 0; } @@ -4745,7 +4814,7 @@ void G_RestoreMapState(mapstate_t *save) intptr_t j; char phealth[MAXPLAYERS]; - for (i=0; ii].extra; pub = NUMPAGES; @@ -4817,7 +4886,7 @@ void G_RestoreMapState(mapstate_t *save) Gv_RefreshPointers(); - for (i=0; ii].extra = phealth[i]; if (g_player[myconnectindex].ps->over_shoulder_on != 0) diff --git a/polymer/eduke32/source/gamestructures.c b/polymer/eduke32/source/gamestructures.c index 42d37fbd1..135755b15 100644 --- a/polymer/eduke32/source/gamestructures.c +++ b/polymer/eduke32/source/gamestructures.c @@ -30,14 +30,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // I got a 3-4 fps gain by inlining these... #ifndef _gamevars_c_ -static inline void X_AccessUserdef(int32_t iSet, int32_t lLabelID, int32_t lVar2) +static void __fastcall X_AccessUserdef(int32_t iSet, int32_t lLabelID, int32_t lVar2) { int32_t lValue=0; if (vm.g_p != myconnectindex) { -// if (lVar2 == MAXGAMEVARS) -// insptr++; + // if (lVar2 == MAXGAMEVARS) + // insptr++; insptr += (lVar2 == MAXGAMEVARS); return; } @@ -911,16 +911,16 @@ static inline void X_AccessUserdef(int32_t iSet, int32_t lLabelID, int32_t lVar2 } } -static inline void X_AccessActiveProjectile(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) +static void __fastcall X_AccessActiveProjectile(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) { int32_t lValue=0,proj=vm.g_i; if (lVar1 != g_iThisActorID) proj=Gv_GetVar(lVar1, vm.g_i, vm.g_p); - if ((proj < 0 || proj >= MAXSPRITES) && g_scriptSanityChecks) + if ((proj < 0 || proj >= MAXSPRITES) /* && g_scriptSanityChecks */) { -// OSD_Printf("X_AccessActiveProjectile(): invalid projectile (%d)\n",proj); + // OSD_Printf("X_AccessActiveProjectile(): invalid projectile (%d)\n",proj); OSD_Printf(CON_ERROR "tried to %s %s on invalid target projectile (%d) %d %d from %s\n",g_errorLineNum,keyw[g_tw], iSet?"set":"get",ProjectileLabels[lLabelID].name,proj,vm.g_i,vm.g_sp->picnum, (lVar1= ud.multimode) && g_scriptSanityChecks) - { -// OSD_Printf("X_AccessPlayer(): invalid target player (%d) %d\n",iPlayer,vm.g_i); - OSD_Printf(CON_ERROR "tried to %s %s on invalid target player (%d) from spr %d gv %s\n",g_errorLineNum,keyw[g_tw], - iSet?"set":"get",PlayerLabels[lLabelID].name,iPlayer,vm.g_i, - (lVar1= playerswhenstarted) /* && g_scriptSanityChecks */) + goto badplayer; - if ((PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= PlayerLabels[lLabelID].maxParm2)) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "tried to %s invalid %s position %d on player (%d) from spr %d\n",g_errorLineNum,keyw[g_tw], - iSet?"set":"get",PlayerLabels[lLabelID].name,lParm2,iPlayer,vm.g_i); - insptr += (lVar2 == MAXGAMEVARS); - return; - } - - if (iSet) - lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); + if ((PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= PlayerLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; switch (lLabelID) { case PLAYER_ZOOM: - if (iSet) - { - g_player[iPlayer].ps->zoom=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->zoom, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->zoom, vm.g_i, vm.g_p); return; case PLAYER_EXITX: - if (iSet) - { - g_player[iPlayer].ps->exitx=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->exitx, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->exitx, vm.g_i, vm.g_p); return; case PLAYER_EXITY: - if (iSet) - { - g_player[iPlayer].ps->exity=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->exity, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->exity, vm.g_i, vm.g_p); return; case PLAYER_LOOGIEX: - if (iSet) - { - g_player[iPlayer].ps->loogiex[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->loogiex[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->loogiex[lParm2], vm.g_i, vm.g_p); return; case PLAYER_LOOGIEY: - if (iSet) - { - g_player[iPlayer].ps->loogiey[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->loogiey[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->loogiey[lParm2], vm.g_i, vm.g_p); return; case PLAYER_NUMLOOGS: - if (iSet) - { - g_player[iPlayer].ps->numloogs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->numloogs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->numloogs, vm.g_i, vm.g_p); return; case PLAYER_LOOGCNT: - if (iSet) - { - g_player[iPlayer].ps->loogcnt=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->loogcnt, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->loogcnt, vm.g_i, vm.g_p); return; case PLAYER_POSX: - if (iSet) - { - g_player[iPlayer].ps->posx=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->posx, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->posx, vm.g_i, vm.g_p); return; case PLAYER_POSY: - if (iSet) - { - g_player[iPlayer].ps->posy=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->posy, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->posy, vm.g_i, vm.g_p); return; case PLAYER_POSZ: - if (iSet) - { - g_player[iPlayer].ps->posz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->posz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->posz, vm.g_i, vm.g_p); return; case PLAYER_HORIZ: - if (iSet) - { - g_player[iPlayer].ps->horiz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->horiz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->horiz, vm.g_i, vm.g_p); return; case PLAYER_OHORIZ: - if (iSet) - { - g_player[iPlayer].ps->ohoriz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->ohoriz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->ohoriz, vm.g_i, vm.g_p); return; case PLAYER_OHORIZOFF: - if (iSet) - { - g_player[iPlayer].ps->ohorizoff=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->ohorizoff, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->ohorizoff, vm.g_i, vm.g_p); return; case PLAYER_INVDISPTIME: - if (iSet) - { - g_player[iPlayer].ps->invdisptime=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->invdisptime, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->invdisptime, vm.g_i, vm.g_p); return; case PLAYER_BOBPOSX: - if (iSet) - { - g_player[iPlayer].ps->bobposx=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->bobposx, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->bobposx, vm.g_i, vm.g_p); return; case PLAYER_BOBPOSY: - if (iSet) - { - g_player[iPlayer].ps->bobposy=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->bobposy, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->bobposy, vm.g_i, vm.g_p); return; case PLAYER_OPOSX: - if (iSet) - { - g_player[iPlayer].ps->oposx=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->oposx, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->oposx, vm.g_i, vm.g_p); return; case PLAYER_OPOSY: - if (iSet) - { - g_player[iPlayer].ps->oposy=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->oposy, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->oposy, vm.g_i, vm.g_p); return; case PLAYER_OPOSZ: - if (iSet) - { - g_player[iPlayer].ps->oposz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->oposz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->oposz, vm.g_i, vm.g_p); return; case PLAYER_PYOFF: - if (iSet) - { - g_player[iPlayer].ps->pyoff=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->pyoff, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->pyoff, vm.g_i, vm.g_p); return; case PLAYER_OPYOFF: - if (iSet) - { - g_player[iPlayer].ps->opyoff=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->opyoff, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->opyoff, vm.g_i, vm.g_p); return; case PLAYER_POSXV: - if (iSet) - { - g_player[iPlayer].ps->posxv=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->posxv, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->posxv, vm.g_i, vm.g_p); return; case PLAYER_POSYV: - if (iSet) - { - g_player[iPlayer].ps->posyv=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->posyv, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->posyv, vm.g_i, vm.g_p); return; case PLAYER_POSZV: - if (iSet) - { - g_player[iPlayer].ps->poszv=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->poszv, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->poszv, vm.g_i, vm.g_p); return; case PLAYER_LAST_PISSED_TIME: - if (iSet) - { - g_player[iPlayer].ps->last_pissed_time=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->last_pissed_time, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->last_pissed_time, vm.g_i, vm.g_p); return; case PLAYER_TRUEFZ: - if (iSet) - { - g_player[iPlayer].ps->truefz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->truefz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->truefz, vm.g_i, vm.g_p); return; case PLAYER_TRUECZ: - if (iSet) - { - g_player[iPlayer].ps->truecz=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->truecz, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->truecz, vm.g_i, vm.g_p); return; case PLAYER_PLAYER_PAR: - if (iSet) - { - g_player[iPlayer].ps->player_par=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->player_par, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->player_par, vm.g_i, vm.g_p); return; case PLAYER_VISIBILITY: - if (iSet) - { - g_player[iPlayer].ps->visibility=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->visibility, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->visibility, vm.g_i, vm.g_p); return; case PLAYER_BOBCOUNTER: - if (iSet) - { - g_player[iPlayer].ps->bobcounter=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->bobcounter, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->bobcounter, vm.g_i, vm.g_p); return; case PLAYER_WEAPON_SWAY: - if (iSet) - { - g_player[iPlayer].ps->weapon_sway=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_sway, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_sway, vm.g_i, vm.g_p); return; case PLAYER_PALS_TIME: - if (iSet) - { - g_player[iPlayer].ps->pals_time=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->pals_time, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->pals_time, vm.g_i, vm.g_p); return; case PLAYER_RANDOMFLAMEX: - if (iSet) - { - g_player[iPlayer].ps->randomflamex=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->randomflamex, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->randomflamex, vm.g_i, vm.g_p); return; case PLAYER_CRACK_TIME: - if (iSet) - { - g_player[iPlayer].ps->crack_time=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->crack_time, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->crack_time, vm.g_i, vm.g_p); return; case PLAYER_AIM_MODE: - if (iSet) - { - g_player[iPlayer].ps->aim_mode=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->aim_mode, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->aim_mode, vm.g_i, vm.g_p); return; case PLAYER_ANG: - if (iSet) - { - g_player[iPlayer].ps->ang=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->ang, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->ang, vm.g_i, vm.g_p); return; case PLAYER_OANG: - if (iSet) - { - g_player[iPlayer].ps->oang=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->oang, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->oang, vm.g_i, vm.g_p); return; case PLAYER_ANGVEL: - if (iSet) - { - g_player[iPlayer].ps->angvel=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->angvel, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->angvel, vm.g_i, vm.g_p); return; case PLAYER_CURSECTNUM: - if (iSet) - { - g_player[iPlayer].ps->cursectnum=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->cursectnum, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->cursectnum, vm.g_i, vm.g_p); return; case PLAYER_LOOK_ANG: - if (iSet) - { - g_player[iPlayer].ps->look_ang=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->look_ang, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->look_ang, vm.g_i, vm.g_p); return; case PLAYER_LAST_EXTRA: - if (iSet) - { - g_player[iPlayer].ps->last_extra=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->last_extra, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->last_extra, vm.g_i, vm.g_p); return; case PLAYER_SUBWEAPON: - if (iSet) - { - g_player[iPlayer].ps->subweapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->subweapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->subweapon, vm.g_i, vm.g_p); return; case PLAYER_AMMO_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->ammo_amount[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->ammo_amount[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->ammo_amount[lParm2], vm.g_i, vm.g_p); return; case PLAYER_WACKEDBYACTOR: - if (iSet) - { - g_player[iPlayer].ps->wackedbyactor=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->wackedbyactor, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->wackedbyactor, vm.g_i, vm.g_p); return; case PLAYER_FRAG: - if (iSet) - { - g_player[iPlayer].ps->frag=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->frag, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->frag, vm.g_i, vm.g_p); return; case PLAYER_FRAGGEDSELF: - if (iSet) - { - g_player[iPlayer].ps->fraggedself=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->fraggedself, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->fraggedself, vm.g_i, vm.g_p); return; case PLAYER_CURR_WEAPON: - if (iSet) - { - g_player[iPlayer].ps->curr_weapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->curr_weapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->curr_weapon, vm.g_i, vm.g_p); return; case PLAYER_LAST_WEAPON: - if (iSet) - { - g_player[iPlayer].ps->last_weapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->last_weapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->last_weapon, vm.g_i, vm.g_p); return; case PLAYER_TIPINCS: - if (iSet) - { - g_player[iPlayer].ps->tipincs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->tipincs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->tipincs, vm.g_i, vm.g_p); return; case PLAYER_HORIZOFF: - if (iSet) - { - g_player[iPlayer].ps->horizoff=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->horizoff, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->horizoff, vm.g_i, vm.g_p); return; case PLAYER_WANTWEAPONFIRE: - if (iSet) - { - g_player[iPlayer].ps->wantweaponfire=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->wantweaponfire, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->wantweaponfire, vm.g_i, vm.g_p); return; case PLAYER_HOLODUKE_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->holoduke_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->holoduke_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->holoduke_amount, vm.g_i, vm.g_p); return; case PLAYER_NEWOWNER: - if (iSet) - { - g_player[iPlayer].ps->newowner=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->newowner, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->newowner, vm.g_i, vm.g_p); return; case PLAYER_HURT_DELAY: - if (iSet) - { - g_player[iPlayer].ps->hurt_delay=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->hurt_delay, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->hurt_delay, vm.g_i, vm.g_p); return; case PLAYER_HBOMB_HOLD_DELAY: - if (iSet) - { - g_player[iPlayer].ps->hbomb_hold_delay=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->hbomb_hold_delay, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->hbomb_hold_delay, vm.g_i, vm.g_p); return; case PLAYER_JUMPING_COUNTER: - if (iSet) - { - g_player[iPlayer].ps->jumping_counter=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->jumping_counter, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->jumping_counter, vm.g_i, vm.g_p); return; case PLAYER_AIRLEFT: - if (iSet) - { - g_player[iPlayer].ps->airleft=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->airleft, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->airleft, vm.g_i, vm.g_p); return; case PLAYER_KNEE_INCS: - if (iSet) - { - g_player[iPlayer].ps->knee_incs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->knee_incs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->knee_incs, vm.g_i, vm.g_p); return; case PLAYER_ACCESS_INCS: - if (iSet) - { - g_player[iPlayer].ps->access_incs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->access_incs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->access_incs, vm.g_i, vm.g_p); return; case PLAYER_FTA: - if (iSet) - { - g_player[iPlayer].ps->fta=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->fta, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->fta, vm.g_i, vm.g_p); return; case PLAYER_FTQ: - if (iSet) - { - g_player[iPlayer].ps->ftq=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->ftq, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->ftq, vm.g_i, vm.g_p); return; case PLAYER_ACCESS_WALLNUM: - if (iSet) - { - g_player[iPlayer].ps->access_wallnum=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->access_wallnum, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->access_wallnum, vm.g_i, vm.g_p); return; case PLAYER_ACCESS_SPRITENUM: - if (iSet) - { - g_player[iPlayer].ps->access_spritenum=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->access_spritenum, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->access_spritenum, vm.g_i, vm.g_p); return; case PLAYER_KICKBACK_PIC: - if (iSet) - { - g_player[iPlayer].ps->kickback_pic=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->kickback_pic, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->kickback_pic, vm.g_i, vm.g_p); return; case PLAYER_GOT_ACCESS: - if (iSet) - { - g_player[iPlayer].ps->got_access=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->got_access, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->got_access, vm.g_i, vm.g_p); return; case PLAYER_WEAPON_ANG: - if (iSet) - { - g_player[iPlayer].ps->weapon_ang=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_ang, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_ang, vm.g_i, vm.g_p); return; case PLAYER_FIRSTAID_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->firstaid_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->firstaid_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->firstaid_amount, vm.g_i, vm.g_p); return; case PLAYER_SOMETHINGONPLAYER: - if (iSet) - { - g_player[iPlayer].ps->somethingonplayer=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->somethingonplayer, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->somethingonplayer, vm.g_i, vm.g_p); return; case PLAYER_ON_CRANE: - if (iSet) - { - g_player[iPlayer].ps->on_crane=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->on_crane, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->on_crane, vm.g_i, vm.g_p); return; case PLAYER_I: - if (iSet) - { - g_player[iPlayer].ps->i=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->i, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->i, vm.g_i, vm.g_p); return; case PLAYER_ONE_PARALLAX_SECTNUM: - if (iSet) - { - g_player[iPlayer].ps->one_parallax_sectnum=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->one_parallax_sectnum, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->one_parallax_sectnum, vm.g_i, vm.g_p); return; case PLAYER_OVER_SHOULDER_ON: - if (iSet) - { - g_player[iPlayer].ps->over_shoulder_on=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->over_shoulder_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->over_shoulder_on, vm.g_i, vm.g_p); return; case PLAYER_RANDOM_CLUB_FRAME: - if (iSet) - { - g_player[iPlayer].ps->random_club_frame=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->random_club_frame, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->random_club_frame, vm.g_i, vm.g_p); return; case PLAYER_FIST_INCS: - if (iSet) - { - g_player[iPlayer].ps->fist_incs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->fist_incs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->fist_incs, vm.g_i, vm.g_p); return; case PLAYER_ONE_EIGHTY_COUNT: - if (iSet) - { - g_player[iPlayer].ps->one_eighty_count=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->one_eighty_count, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->one_eighty_count, vm.g_i, vm.g_p); return; case PLAYER_CHEAT_PHASE: - if (iSet) - { - g_player[iPlayer].ps->cheat_phase=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->cheat_phase, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->cheat_phase, vm.g_i, vm.g_p); return; case PLAYER_DUMMYPLAYERSPRITE: - if (iSet) - { - g_player[iPlayer].ps->dummyplayersprite=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->dummyplayersprite, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->dummyplayersprite, vm.g_i, vm.g_p); return; case PLAYER_EXTRA_EXTRA8: - if (iSet) - { - g_player[iPlayer].ps->extra_extra8=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->extra_extra8, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->extra_extra8, vm.g_i, vm.g_p); return; case PLAYER_QUICK_KICK: - if (iSet) - { - g_player[iPlayer].ps->quick_kick=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->quick_kick, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->quick_kick, vm.g_i, vm.g_p); return; case PLAYER_HEAT_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->heat_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->heat_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->heat_amount, vm.g_i, vm.g_p); return; case PLAYER_ACTORSQU: - if (iSet) - { - g_player[iPlayer].ps->actorsqu=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->actorsqu, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->actorsqu, vm.g_i, vm.g_p); return; case PLAYER_TIMEBEFOREEXIT: - if (iSet) - { - g_player[iPlayer].ps->timebeforeexit=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->timebeforeexit, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->timebeforeexit, vm.g_i, vm.g_p); return; case PLAYER_CUSTOMEXITSOUND: - if (iSet) - { - g_player[iPlayer].ps->customexitsound=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->customexitsound, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->customexitsound, vm.g_i, vm.g_p); return; case PLAYER_WEAPRECS: - if (iSet) - { - g_player[iPlayer].ps->weaprecs[15]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weaprecs[15], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weaprecs[15], vm.g_i, vm.g_p); return; case PLAYER_WEAPRECCNT: - if (iSet) - { - g_player[iPlayer].ps->weapreccnt=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weapreccnt, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weapreccnt, vm.g_i, vm.g_p); return; case PLAYER_INTERFACE_TOGGLE_FLAG: - if (iSet) - { - g_player[iPlayer].ps->interface_toggle_flag=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->interface_toggle_flag, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->interface_toggle_flag, vm.g_i, vm.g_p); return; case PLAYER_ROTSCRNANG: - if (iSet) - { - g_player[iPlayer].ps->rotscrnang=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->rotscrnang, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->rotscrnang, vm.g_i, vm.g_p); return; case PLAYER_DEAD_FLAG: - if (iSet) - { - g_player[iPlayer].ps->dead_flag=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->dead_flag, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->dead_flag, vm.g_i, vm.g_p); return; case PLAYER_SHOW_EMPTY_WEAPON: - if (iSet) - { - g_player[iPlayer].ps->show_empty_weapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->show_empty_weapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->show_empty_weapon, vm.g_i, vm.g_p); return; case PLAYER_SCUBA_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->scuba_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->scuba_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->scuba_amount, vm.g_i, vm.g_p); return; case PLAYER_JETPACK_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->jetpack_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->jetpack_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->jetpack_amount, vm.g_i, vm.g_p); return; case PLAYER_STEROIDS_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->steroids_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->steroids_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->steroids_amount, vm.g_i, vm.g_p); return; case PLAYER_SHIELD_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->shield_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->shield_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->shield_amount, vm.g_i, vm.g_p); return; case PLAYER_HOLODUKE_ON: - if (iSet) - { - g_player[iPlayer].ps->holoduke_on=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->holoduke_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->holoduke_on, vm.g_i, vm.g_p); return; case PLAYER_PYCOUNT: - if (iSet) - { - g_player[iPlayer].ps->pycount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->pycount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->pycount, vm.g_i, vm.g_p); return; case PLAYER_WEAPON_POS: - if (iSet) - { - g_player[iPlayer].ps->weapon_pos=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_pos, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weapon_pos, vm.g_i, vm.g_p); return; case PLAYER_FRAG_PS: - if (iSet) - { - g_player[iPlayer].ps->frag_ps=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->frag_ps, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->frag_ps, vm.g_i, vm.g_p); return; case PLAYER_TRANSPORTER_HOLD: - if (iSet) - { - g_player[iPlayer].ps->transporter_hold=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->transporter_hold, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->transporter_hold, vm.g_i, vm.g_p); return; case PLAYER_LAST_FULL_WEAPON: - if (iSet) - { - g_player[iPlayer].ps->last_full_weapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->last_full_weapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->last_full_weapon, vm.g_i, vm.g_p); return; case PLAYER_FOOTPRINTSHADE: - if (iSet) - { - g_player[iPlayer].ps->footprintshade=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintshade, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintshade, vm.g_i, vm.g_p); return; case PLAYER_BOOT_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->boot_amount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->boot_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->boot_amount, vm.g_i, vm.g_p); return; case PLAYER_SCREAM_VOICE: - if (iSet) - { - g_player[iPlayer].ps->scream_voice=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->scream_voice, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->scream_voice, vm.g_i, vm.g_p); return; case PLAYER_GM: - if (iSet) - { - g_player[iPlayer].ps->gm=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->gm, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->gm, vm.g_i, vm.g_p); return; case PLAYER_ON_WARPING_SECTOR: - if (iSet) - { - g_player[iPlayer].ps->on_warping_sector=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->on_warping_sector, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->on_warping_sector, vm.g_i, vm.g_p); return; case PLAYER_FOOTPRINTCOUNT: - if (iSet) - { - g_player[iPlayer].ps->footprintcount=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintcount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintcount, vm.g_i, vm.g_p); return; case PLAYER_HBOMB_ON: - if (iSet) - { - g_player[iPlayer].ps->hbomb_on=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->hbomb_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->hbomb_on, vm.g_i, vm.g_p); return; case PLAYER_JUMPING_TOGGLE: - if (iSet) - { - g_player[iPlayer].ps->jumping_toggle=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->jumping_toggle, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->jumping_toggle, vm.g_i, vm.g_p); return; case PLAYER_RAPID_FIRE_HOLD: - if (iSet) - { - g_player[iPlayer].ps->rapid_fire_hold=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->rapid_fire_hold, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->rapid_fire_hold, vm.g_i, vm.g_p); return; case PLAYER_ON_GROUND: - if (iSet) - { - g_player[iPlayer].ps->on_ground=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->on_ground, vm.g_i, vm.g_p); - return; - - /* case PLAYER_NAME: - if (iSet) - { - g_player[iPlayer].ps->name[32]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->name[32], vm.g_i, vm.g_p); - return;*/ - + Gv_SetVar(lVar2, g_player[iPlayer].ps->on_ground, vm.g_i, vm.g_p); return; case PLAYER_INVEN_ICON: - if (iSet) - { - g_player[iPlayer].ps->inven_icon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->inven_icon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->inven_icon, vm.g_i, vm.g_p); return; case PLAYER_BUTTONPALETTE: - if (iSet) - { - g_player[iPlayer].ps->buttonpalette=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->buttonpalette, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->buttonpalette, vm.g_i, vm.g_p); return; case PLAYER_JETPACK_ON: - if (iSet) - { - g_player[iPlayer].ps->jetpack_on=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->jetpack_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->jetpack_on, vm.g_i, vm.g_p); return; case PLAYER_SPRITEBRIDGE: - if (iSet) - { - g_player[iPlayer].ps->spritebridge=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->spritebridge, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->spritebridge, vm.g_i, vm.g_p); return; case PLAYER_LASTRANDOMSPOT: - if (iSet) - { - g_player[iPlayer].ps->lastrandomspot=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->lastrandomspot, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->lastrandomspot, vm.g_i, vm.g_p); return; case PLAYER_SCUBA_ON: - if (iSet) - { - g_player[iPlayer].ps->scuba_on=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->scuba_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->scuba_on, vm.g_i, vm.g_p); return; case PLAYER_FOOTPRINTPAL: - if (iSet) - { - g_player[iPlayer].ps->footprintpal=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintpal, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->footprintpal, vm.g_i, vm.g_p); return; case PLAYER_HEAT_ON: - if (iSet) - { - { - if (g_player[iPlayer].ps->heat_on != lValue) - { - g_player[iPlayer].ps->heat_on=lValue; - P_UpdateScreenPal(g_player[iPlayer].ps); - } - } - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->heat_on, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->heat_on, vm.g_i, vm.g_p); return; case PLAYER_HOLSTER_WEAPON: - if (iSet) - { - g_player[iPlayer].ps->holster_weapon=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->holster_weapon, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->holster_weapon, vm.g_i, vm.g_p); return; case PLAYER_FALLING_COUNTER: - if (iSet) - { - g_player[iPlayer].ps->falling_counter=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->falling_counter, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->falling_counter, vm.g_i, vm.g_p); return; case PLAYER_GOTWEAPON: - if (iSet) - { - g_player[iPlayer].ps->gotweapon[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->gotweapon[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->gotweapon[lParm2], vm.g_i, vm.g_p); return; case PLAYER_REFRESH_INVENTORY: - if (iSet) - { - g_player[iPlayer].ps->refresh_inventory=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->refresh_inventory, vm.g_i, vm.g_p); - return; - - // case PLAYER_PALETTE: - // if(iSet) - // { - // g_player[iPlayer].ps->palette=lValue; - // } - // return; } - // { - // Gv_SetVar(lVar2, g_player[iPlayer].ps->palette, vm.g_i, vm.g_p); - // } - // return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->refresh_inventory, vm.g_i, vm.g_p); return; case PLAYER_TOGGLE_KEY_FLAG: - if (iSet) - { - g_player[iPlayer].ps->toggle_key_flag=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->toggle_key_flag, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->toggle_key_flag, vm.g_i, vm.g_p); return; case PLAYER_KNUCKLE_INCS: - if (iSet) - { - g_player[iPlayer].ps->knuckle_incs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->knuckle_incs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->knuckle_incs, vm.g_i, vm.g_p); return; case PLAYER_WALKING_SND_TOGGLE: - if (iSet) - { - g_player[iPlayer].ps->walking_snd_toggle=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->walking_snd_toggle, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->walking_snd_toggle, vm.g_i, vm.g_p); return; case PLAYER_PALOOKUP: - if (iSet) - { - g_player[iPlayer].ps->palookup=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->palookup, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->palookup, vm.g_i, vm.g_p); return; case PLAYER_HARD_LANDING: - if (iSet) - { - g_player[iPlayer].ps->hard_landing=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->hard_landing, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->hard_landing, vm.g_i, vm.g_p); return; case PLAYER_MAX_SECRET_ROOMS: - if (iSet) - { - g_player[iPlayer].ps->max_secret_rooms=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->max_secret_rooms, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->max_secret_rooms, vm.g_i, vm.g_p); return; case PLAYER_SECRET_ROOMS: - if (iSet) - { - g_player[iPlayer].ps->secret_rooms=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->secret_rooms, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->secret_rooms, vm.g_i, vm.g_p); return; case PLAYER_PALS: - if (iSet) - { - g_player[iPlayer].ps->pals[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->pals[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->pals[lParm2], vm.g_i, vm.g_p); return; case PLAYER_MAX_ACTORS_KILLED: - if (iSet) - { - g_player[iPlayer].ps->max_actors_killed=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->max_actors_killed, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->max_actors_killed, vm.g_i, vm.g_p); return; case PLAYER_ACTORS_KILLED: - if (iSet) - { - g_player[iPlayer].ps->actors_killed=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->actors_killed, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->actors_killed, vm.g_i, vm.g_p); return; case PLAYER_RETURN_TO_CENTER: - if (iSet) - { - g_player[iPlayer].ps->return_to_center=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->return_to_center, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->return_to_center, vm.g_i, vm.g_p); return; case PLAYER_RUNSPEED: - if (iSet) - { - g_player[iPlayer].ps->runspeed=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->runspeed, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->runspeed, vm.g_i, vm.g_p); return; case PLAYER_SBS: - if (iSet) - { - g_player[iPlayer].ps->sbs=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->sbs, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->sbs, vm.g_i, vm.g_p); return; case PLAYER_RELOADING: - if (iSet) - { - g_player[iPlayer].ps->reloading=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->reloading, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->reloading, vm.g_i, vm.g_p); return; case PLAYER_AUTO_AIM: - if (iSet) - { - g_player[iPlayer].ps->auto_aim=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->auto_aim, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->auto_aim, vm.g_i, vm.g_p); return; case PLAYER_MOVEMENT_LOCK: - if (iSet) - { - g_player[iPlayer].ps->movement_lock=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->movement_lock, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->movement_lock, vm.g_i, vm.g_p); return; case PLAYER_SOUND_PITCH: - if (iSet) - { - g_player[iPlayer].ps->sound_pitch=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->sound_pitch, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->sound_pitch, vm.g_i, vm.g_p); return; case PLAYER_WEAPONSWITCH: - if (iSet) - { - g_player[iPlayer].ps->weaponswitch=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->weaponswitch, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->weaponswitch, vm.g_i, vm.g_p); return; case PLAYER_TEAM: - if (iSet) - { - g_player[iPlayer].ps->team=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->team, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->team, vm.g_i, vm.g_p); return; case PLAYER_MAX_PLAYER_HEALTH: - if (iSet) - { - g_player[iPlayer].ps->max_player_health = lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->max_player_health, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->max_player_health, vm.g_i, vm.g_p); return; case PLAYER_MAX_SHIELD_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->max_shield_amount = lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->max_shield_amount, vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->max_shield_amount, vm.g_i, vm.g_p); return; case PLAYER_MAX_AMMO_AMOUNT: - if (iSet) - { - g_player[iPlayer].ps->max_ammo_amount[lParm2]=lValue; - return; - } - Gv_SetVar(lVar2, g_player[iPlayer].ps->max_ammo_amount[lParm2], vm.g_i, vm.g_p); - return; - + Gv_SetVar(lVar2, g_player[iPlayer].ps->max_ammo_amount[lParm2], vm.g_i, vm.g_p); return; case PLAYER_LAST_QUICK_KICK: - if (iSet) - { - g_player[iPlayer].ps->last_quick_kick=lValue; - return; - } Gv_SetVar(lVar2, g_player[iPlayer].ps->last_quick_kick, vm.g_i, vm.g_p); return; default: return; } + +badplayer: + // OSD_Printf("X_AccessPlayer(): invalid target player (%d) %d\n",iPlayer,vm.g_i); + OSD_Printf(CON_ERROR "tried to get %s on invalid target player (%d) from spr %d gv %s\n",g_errorLineNum,keyw[g_tw], + PlayerLabels[lLabelID].name,iPlayer,vm.g_i, + (lVar1= playerswhenstarted) /* && g_scriptSanityChecks */) + goto badplayer; + + if ((PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= PlayerLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; + + lVar1=Gv_GetVar(lVar2, vm.g_i, vm.g_p); + + switch (lLabelID) + { + case PLAYER_ZOOM: + g_player[iPlayer].ps->zoom=lVar1; return; + case PLAYER_EXITX: + g_player[iPlayer].ps->exitx=lVar1; return; + case PLAYER_EXITY: + g_player[iPlayer].ps->exity=lVar1; return; + case PLAYER_LOOGIEX: + g_player[iPlayer].ps->loogiex[lParm2]=lVar1; return; + case PLAYER_LOOGIEY: + g_player[iPlayer].ps->loogiey[lParm2]=lVar1; return; + case PLAYER_NUMLOOGS: + g_player[iPlayer].ps->numloogs=lVar1; return; + case PLAYER_LOOGCNT: + g_player[iPlayer].ps->loogcnt=lVar1; return; + case PLAYER_POSX: + g_player[iPlayer].ps->posx=lVar1; return; + case PLAYER_POSY: + g_player[iPlayer].ps->posy=lVar1; return; + case PLAYER_POSZ: + g_player[iPlayer].ps->posz=lVar1; return; + case PLAYER_HORIZ: + g_player[iPlayer].ps->horiz=lVar1; return; + case PLAYER_OHORIZ: + g_player[iPlayer].ps->ohoriz=lVar1; return; + case PLAYER_OHORIZOFF: + g_player[iPlayer].ps->ohorizoff=lVar1; return; + case PLAYER_INVDISPTIME: + g_player[iPlayer].ps->invdisptime=lVar1; return; + case PLAYER_BOBPOSX: + g_player[iPlayer].ps->bobposx=lVar1; return; + case PLAYER_BOBPOSY: + g_player[iPlayer].ps->bobposy=lVar1; return; + case PLAYER_OPOSX: + g_player[iPlayer].ps->oposx=lVar1; return; + case PLAYER_OPOSY: + g_player[iPlayer].ps->oposy=lVar1; return; + case PLAYER_OPOSZ: + g_player[iPlayer].ps->oposz=lVar1; return; + case PLAYER_PYOFF: + g_player[iPlayer].ps->pyoff=lVar1; return; + case PLAYER_OPYOFF: + g_player[iPlayer].ps->opyoff=lVar1; return; + case PLAYER_POSXV: + g_player[iPlayer].ps->posxv=lVar1; return; + case PLAYER_POSYV: + g_player[iPlayer].ps->posyv=lVar1; return; + case PLAYER_POSZV: + g_player[iPlayer].ps->poszv=lVar1; return; + case PLAYER_LAST_PISSED_TIME: + g_player[iPlayer].ps->last_pissed_time=lVar1; return; + case PLAYER_TRUEFZ: + g_player[iPlayer].ps->truefz=lVar1; return; + case PLAYER_TRUECZ: + g_player[iPlayer].ps->truecz=lVar1; return; + case PLAYER_PLAYER_PAR: + g_player[iPlayer].ps->player_par=lVar1; return; + case PLAYER_VISIBILITY: + g_player[iPlayer].ps->visibility=lVar1; return; + case PLAYER_BOBCOUNTER: + g_player[iPlayer].ps->bobcounter=lVar1; return; + case PLAYER_WEAPON_SWAY: + g_player[iPlayer].ps->weapon_sway=lVar1; return; + case PLAYER_PALS_TIME: + g_player[iPlayer].ps->pals_time=lVar1; return; + case PLAYER_RANDOMFLAMEX: + g_player[iPlayer].ps->randomflamex=lVar1; return; + case PLAYER_CRACK_TIME: + g_player[iPlayer].ps->crack_time=lVar1; return; + case PLAYER_AIM_MODE: + g_player[iPlayer].ps->aim_mode=lVar1; return; + case PLAYER_ANG: + g_player[iPlayer].ps->ang=lVar1; return; + case PLAYER_OANG: + g_player[iPlayer].ps->oang=lVar1; return; + case PLAYER_ANGVEL: + g_player[iPlayer].ps->angvel=lVar1; return; + case PLAYER_CURSECTNUM: + g_player[iPlayer].ps->cursectnum=lVar1; return; + case PLAYER_LOOK_ANG: + g_player[iPlayer].ps->look_ang=lVar1; return; + case PLAYER_LAST_EXTRA: + g_player[iPlayer].ps->last_extra=lVar1; return; + case PLAYER_SUBWEAPON: + g_player[iPlayer].ps->subweapon=lVar1; return; + case PLAYER_AMMO_AMOUNT: + g_player[iPlayer].ps->ammo_amount[lParm2]=lVar1; return; + case PLAYER_WACKEDBYACTOR: + g_player[iPlayer].ps->wackedbyactor=lVar1; return; + case PLAYER_FRAG: + g_player[iPlayer].ps->frag=lVar1; return; + case PLAYER_FRAGGEDSELF: + g_player[iPlayer].ps->fraggedself=lVar1; return; + case PLAYER_CURR_WEAPON: + g_player[iPlayer].ps->curr_weapon=lVar1; return; + case PLAYER_LAST_WEAPON: + g_player[iPlayer].ps->last_weapon=lVar1; return; + case PLAYER_TIPINCS: + g_player[iPlayer].ps->tipincs=lVar1; return; + case PLAYER_HORIZOFF: + g_player[iPlayer].ps->horizoff=lVar1; return; + case PLAYER_WANTWEAPONFIRE: + g_player[iPlayer].ps->wantweaponfire=lVar1; return; + case PLAYER_HOLODUKE_AMOUNT: + g_player[iPlayer].ps->holoduke_amount=lVar1; return; + case PLAYER_NEWOWNER: + g_player[iPlayer].ps->newowner=lVar1; return; + case PLAYER_HURT_DELAY: + g_player[iPlayer].ps->hurt_delay=lVar1; return; + case PLAYER_HBOMB_HOLD_DELAY: + g_player[iPlayer].ps->hbomb_hold_delay=lVar1; return; + case PLAYER_JUMPING_COUNTER: + g_player[iPlayer].ps->jumping_counter=lVar1; return; + case PLAYER_AIRLEFT: + g_player[iPlayer].ps->airleft=lVar1; return; + case PLAYER_KNEE_INCS: + g_player[iPlayer].ps->knee_incs=lVar1; return; + case PLAYER_ACCESS_INCS: + g_player[iPlayer].ps->access_incs=lVar1; return; + case PLAYER_FTA: + g_player[iPlayer].ps->fta=lVar1; return; + case PLAYER_FTQ: + g_player[iPlayer].ps->ftq=lVar1; return; + case PLAYER_ACCESS_WALLNUM: + g_player[iPlayer].ps->access_wallnum=lVar1; return; + case PLAYER_ACCESS_SPRITENUM: + g_player[iPlayer].ps->access_spritenum=lVar1; return; + case PLAYER_KICKBACK_PIC: + g_player[iPlayer].ps->kickback_pic=lVar1; return; + case PLAYER_GOT_ACCESS: + g_player[iPlayer].ps->got_access=lVar1; return; + case PLAYER_WEAPON_ANG: + g_player[iPlayer].ps->weapon_ang=lVar1; return; + case PLAYER_FIRSTAID_AMOUNT: + g_player[iPlayer].ps->firstaid_amount=lVar1; return; + case PLAYER_SOMETHINGONPLAYER: + g_player[iPlayer].ps->somethingonplayer=lVar1; return; + case PLAYER_ON_CRANE: + g_player[iPlayer].ps->on_crane=lVar1; return; + case PLAYER_I: + g_player[iPlayer].ps->i=lVar1; return; + case PLAYER_ONE_PARALLAX_SECTNUM: + g_player[iPlayer].ps->one_parallax_sectnum=lVar1; return; + case PLAYER_OVER_SHOULDER_ON: + g_player[iPlayer].ps->over_shoulder_on=lVar1; return; + case PLAYER_RANDOM_CLUB_FRAME: + g_player[iPlayer].ps->random_club_frame=lVar1; return; + case PLAYER_FIST_INCS: + g_player[iPlayer].ps->fist_incs=lVar1; return; + case PLAYER_ONE_EIGHTY_COUNT: + g_player[iPlayer].ps->one_eighty_count=lVar1; return; + case PLAYER_CHEAT_PHASE: + g_player[iPlayer].ps->cheat_phase=lVar1; return; + case PLAYER_DUMMYPLAYERSPRITE: + g_player[iPlayer].ps->dummyplayersprite=lVar1; return; + case PLAYER_EXTRA_EXTRA8: + g_player[iPlayer].ps->extra_extra8=lVar1; return; + case PLAYER_QUICK_KICK: + g_player[iPlayer].ps->quick_kick=lVar1; return; + case PLAYER_HEAT_AMOUNT: + g_player[iPlayer].ps->heat_amount=lVar1; return; + case PLAYER_ACTORSQU: + g_player[iPlayer].ps->actorsqu=lVar1; return; + case PLAYER_TIMEBEFOREEXIT: + g_player[iPlayer].ps->timebeforeexit=lVar1; return; + case PLAYER_CUSTOMEXITSOUND: + g_player[iPlayer].ps->customexitsound=lVar1; return; + case PLAYER_WEAPRECS: + g_player[iPlayer].ps->weaprecs[15]=lVar1; return; + case PLAYER_WEAPRECCNT: + g_player[iPlayer].ps->weapreccnt=lVar1; return; + case PLAYER_INTERFACE_TOGGLE_FLAG: + g_player[iPlayer].ps->interface_toggle_flag=lVar1; return; + case PLAYER_ROTSCRNANG: + g_player[iPlayer].ps->rotscrnang=lVar1; return; + case PLAYER_DEAD_FLAG: + g_player[iPlayer].ps->dead_flag=lVar1; return; + case PLAYER_SHOW_EMPTY_WEAPON: + g_player[iPlayer].ps->show_empty_weapon=lVar1; return; + case PLAYER_SCUBA_AMOUNT: + g_player[iPlayer].ps->scuba_amount=lVar1; return; + case PLAYER_JETPACK_AMOUNT: + g_player[iPlayer].ps->jetpack_amount=lVar1; return; + case PLAYER_STEROIDS_AMOUNT: + g_player[iPlayer].ps->steroids_amount=lVar1; return; + case PLAYER_SHIELD_AMOUNT: + g_player[iPlayer].ps->shield_amount=lVar1; return; + case PLAYER_HOLODUKE_ON: + g_player[iPlayer].ps->holoduke_on=lVar1; return; + case PLAYER_PYCOUNT: + g_player[iPlayer].ps->pycount=lVar1; return; + case PLAYER_WEAPON_POS: + g_player[iPlayer].ps->weapon_pos=lVar1; return; + case PLAYER_FRAG_PS: + g_player[iPlayer].ps->frag_ps=lVar1; return; + case PLAYER_TRANSPORTER_HOLD: + g_player[iPlayer].ps->transporter_hold=lVar1; return; + case PLAYER_LAST_FULL_WEAPON: + g_player[iPlayer].ps->last_full_weapon=lVar1; return; + case PLAYER_FOOTPRINTSHADE: + g_player[iPlayer].ps->footprintshade=lVar1; return; + case PLAYER_BOOT_AMOUNT: + g_player[iPlayer].ps->boot_amount=lVar1; return; + case PLAYER_SCREAM_VOICE: + g_player[iPlayer].ps->scream_voice=lVar1; return; + case PLAYER_GM: + g_player[iPlayer].ps->gm=lVar1; return; + case PLAYER_ON_WARPING_SECTOR: + g_player[iPlayer].ps->on_warping_sector=lVar1; return; + case PLAYER_FOOTPRINTCOUNT: + g_player[iPlayer].ps->footprintcount=lVar1; return; + case PLAYER_HBOMB_ON: + g_player[iPlayer].ps->hbomb_on=lVar1; return; + case PLAYER_JUMPING_TOGGLE: + g_player[iPlayer].ps->jumping_toggle=lVar1; return; + case PLAYER_RAPID_FIRE_HOLD: + g_player[iPlayer].ps->rapid_fire_hold=lVar1; return; + case PLAYER_ON_GROUND: + g_player[iPlayer].ps->on_ground=lVar1; return; + case PLAYER_INVEN_ICON: + g_player[iPlayer].ps->inven_icon=lVar1; return; + case PLAYER_BUTTONPALETTE: + g_player[iPlayer].ps->buttonpalette=lVar1; return; + case PLAYER_JETPACK_ON: + g_player[iPlayer].ps->jetpack_on=lVar1; return; + case PLAYER_SPRITEBRIDGE: + g_player[iPlayer].ps->spritebridge=lVar1; return; + case PLAYER_LASTRANDOMSPOT: + g_player[iPlayer].ps->lastrandomspot=lVar1; return; + case PLAYER_SCUBA_ON: + g_player[iPlayer].ps->scuba_on=lVar1; return; + case PLAYER_FOOTPRINTPAL: + g_player[iPlayer].ps->footprintpal=lVar1; return; + case PLAYER_HEAT_ON: + if (g_player[iPlayer].ps->heat_on != lVar1) + { + g_player[iPlayer].ps->heat_on=lVar1; + P_UpdateScreenPal(g_player[iPlayer].ps); + } return; + case PLAYER_HOLSTER_WEAPON: + g_player[iPlayer].ps->holster_weapon=lVar1; return; + case PLAYER_FALLING_COUNTER: + g_player[iPlayer].ps->falling_counter=lVar1; return; + case PLAYER_GOTWEAPON: + g_player[iPlayer].ps->gotweapon[lParm2]=lVar1; return; + case PLAYER_REFRESH_INVENTORY: + g_player[iPlayer].ps->refresh_inventory=lVar1; return; + case PLAYER_TOGGLE_KEY_FLAG: + g_player[iPlayer].ps->toggle_key_flag=lVar1; return; + case PLAYER_KNUCKLE_INCS: + g_player[iPlayer].ps->knuckle_incs=lVar1; return; + case PLAYER_WALKING_SND_TOGGLE: + g_player[iPlayer].ps->walking_snd_toggle=lVar1; return; + case PLAYER_PALOOKUP: + g_player[iPlayer].ps->palookup=lVar1; return; + case PLAYER_HARD_LANDING: + g_player[iPlayer].ps->hard_landing=lVar1; return; + case PLAYER_MAX_SECRET_ROOMS: + g_player[iPlayer].ps->max_secret_rooms=lVar1; return; + case PLAYER_SECRET_ROOMS: + g_player[iPlayer].ps->secret_rooms=lVar1; return; + case PLAYER_PALS: + g_player[iPlayer].ps->pals[lParm2]=lVar1; return; + case PLAYER_MAX_ACTORS_KILLED: + g_player[iPlayer].ps->max_actors_killed=lVar1; return; + case PLAYER_ACTORS_KILLED: + g_player[iPlayer].ps->actors_killed=lVar1; return; + case PLAYER_RETURN_TO_CENTER: + g_player[iPlayer].ps->return_to_center=lVar1; return; + case PLAYER_RUNSPEED: + g_player[iPlayer].ps->runspeed=lVar1; return; + case PLAYER_SBS: + g_player[iPlayer].ps->sbs=lVar1; return; + case PLAYER_RELOADING: + g_player[iPlayer].ps->reloading=lVar1; return; + case PLAYER_AUTO_AIM: + g_player[iPlayer].ps->auto_aim=lVar1; return; + case PLAYER_MOVEMENT_LOCK: + g_player[iPlayer].ps->movement_lock=lVar1; return; + case PLAYER_SOUND_PITCH: + g_player[iPlayer].ps->sound_pitch=lVar1; return; + case PLAYER_WEAPONSWITCH: + g_player[iPlayer].ps->weaponswitch=lVar1; return; + case PLAYER_TEAM: + g_player[iPlayer].ps->team=lVar1; return; + case PLAYER_MAX_PLAYER_HEALTH: + g_player[iPlayer].ps->max_player_health = lVar1; return; + case PLAYER_MAX_SHIELD_AMOUNT: + g_player[iPlayer].ps->max_shield_amount = lVar1; return; + case PLAYER_MAX_AMMO_AMOUNT: + g_player[iPlayer].ps->max_ammo_amount[lParm2]=lVar1; return; + case PLAYER_LAST_QUICK_KICK: + g_player[iPlayer].ps->last_quick_kick=lVar1; + return; + + default: + return; + } + +badplayer: + // OSD_Printf("X_AccessPlayer(): invalid target player (%d) %d\n",iPlayer,vm.g_i); + OSD_Printf(CON_ERROR "tried to set %s on invalid target player (%d) from spr %d gv %s\n",g_errorLineNum,keyw[g_tw], + PlayerLabels[lLabelID].name,iPlayer,vm.g_i, + (lVar1= ud.multimode) && g_scriptSanityChecks) - { - insptr += (lVar2 == MAXGAMEVARS); - OSD_Printf(CON_ERROR "invalid target player (%d) %d\n",g_errorLineNum,keyw[g_tw],iPlayer,vm.g_i); - return; - } + if ((iPlayer<0 || iPlayer >= playerswhenstarted) /* && g_scriptSanityChecks */) + goto badplayer; if (iSet) lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); @@ -2633,19 +1923,20 @@ static inline void X_AccessPlayerInput(int32_t iSet, int32_t lVar1, int32_t lLab default: return; } + +badplayer: + insptr += (lVar2 == MAXGAMEVARS); + OSD_Printf(CON_ERROR "invalid target player (%d) %d\n",g_errorLineNum,keyw[g_tw],iPlayer,vm.g_i); + return; } -static inline void X_AccessWall(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) +static void __fastcall X_AccessWall(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) { int32_t lValue=0; int32_t iWall = Gv_GetVar(lVar1, vm.g_i, vm.g_p); - if ((iWall<0 || iWall >= numwalls) && g_scriptSanityChecks) - { - insptr += (lVar2 == MAXGAMEVARS); - OSD_Printf(CON_ERROR "Invalid wall %d\n",g_errorLineNum,keyw[g_tw],iWall); - return; - } + if ((iWall<0 || iWall >= numwalls) /* && g_scriptSanityChecks */) + goto badwall; if (iSet) lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); @@ -2807,9 +2098,14 @@ static inline void X_AccessWall(int32_t iSet, int32_t lVar1, int32_t lLabelID, i default: return; } + +badwall: + insptr += (lVar2 == MAXGAMEVARS); + OSD_Printf(CON_ERROR "Invalid wall %d\n",g_errorLineNum,keyw[g_tw],iWall); + return; } -static inline void X_AccessSector(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) +static void __fastcall X_AccessSector(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) { int32_t lValue=0; int32_t iSector=sprite[vm.g_i].sectnum; @@ -2817,12 +2113,8 @@ static inline void X_AccessSector(int32_t iSet, int32_t lVar1, int32_t lLabelID, if (lVar1 != g_iThisActorID) iSector=Gv_GetVar(lVar1, vm.g_i, vm.g_p); - if ((iSector<0 || iSector >= numsectors) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "Invalid sector %d\n",g_errorLineNum,keyw[g_tw],iSector); - insptr += (lVar2 == MAXGAMEVARS); - return; - } + if ((iSector<0 || iSector >= numsectors) /* && g_scriptSanityChecks */) + goto badsector; if (iSet) lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); @@ -3039,512 +2331,500 @@ static inline void X_AccessSector(int32_t iSet, int32_t lVar1, int32_t lLabelID, default: return; } + +badsector: + OSD_Printf(CON_ERROR "Invalid sector %d\n",g_errorLineNum,keyw[g_tw],iSector); + insptr += (lVar2 == MAXGAMEVARS); + return; } -static inline void X_AccessSprite(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2, int32_t lParm2) +static void __fastcall X_SetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVar2, int32_t lParm2) { - int32_t lValue=0; - int32_t iActor=vm.g_i; + register int32_t iActor=vm.g_i; if (lVar1 != g_iThisActorID) iActor=Gv_GetVar(lVar1, vm.g_i, vm.g_p); - if ((iActor < 0 || iActor >= MAXSPRITES) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "tried to %s %s on invalid target sprite (%d) from spr %d pic %d gv %s\n",g_errorLineNum,keyw[g_tw], - iSet?"set":"get",ActorLabels[lLabelID].name,iActor,vm.g_i,vm.g_sp->picnum, - (lVar1= MAXSPRITES) /* && g_scriptSanityChecks */) + goto badactor; - if ((ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= ActorLabels[lLabelID].maxParm2)) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "tried to %s invalid %s position %d on sprite (%d) from spr %d\n",g_errorLineNum,keyw[g_tw], - iSet?"set":"get",ActorLabels[lLabelID].name,lParm2,iActor,vm.g_i); - insptr += (lVar2 == MAXGAMEVARS); - return; - } + if ((ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= ActorLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; - if (iSet) - lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); + lVar1=Gv_GetVar(lVar2, vm.g_i, vm.g_p); + + switch (lLabelID) + { + case ACTOR_X: + sprite[iActor].x=lVar1; + return; + + case ACTOR_Y: + sprite[iActor].y=lVar1; + return; + + case ACTOR_Z: + sprite[iActor].z=lVar1; + return; + + case ACTOR_CSTAT: + sprite[iActor].cstat=lVar1; + return; + + case ACTOR_PICNUM: + sprite[iActor].picnum=lVar1; + return; + + case ACTOR_SHADE: + sprite[iActor].shade=lVar1; + return; + + case ACTOR_PAL: + sprite[iActor].pal=lVar1; + return; + + case ACTOR_CLIPDIST: + sprite[iActor].clipdist=lVar1; + return; + + case ACTOR_DETAIL: + sprite[iActor].filler=lVar1; + return; + + case ACTOR_XREPEAT: + sprite[iActor].xrepeat=lVar1; + return; + + case ACTOR_YREPEAT: + sprite[iActor].yrepeat=lVar1; + return; + + case ACTOR_XOFFSET: + sprite[iActor].xoffset=lVar1; + return; + + case ACTOR_YOFFSET: + sprite[iActor].yoffset=lVar1; + return; + + case ACTOR_SECTNUM: + changespritesect(iActor,lVar1); + return; + + case ACTOR_STATNUM: + changespritestat(iActor,lVar1); + return; + + case ACTOR_ANG: + sprite[iActor].ang=lVar1; + return; + + case ACTOR_OWNER: + sprite[iActor].owner=lVar1; + return; + + case ACTOR_XVEL: + sprite[iActor].xvel=lVar1; + return; + + case ACTOR_YVEL: + sprite[iActor].yvel=lVar1; + return; + + case ACTOR_ZVEL: + sprite[iActor].zvel=lVar1; + return; + + case ACTOR_LOTAG: + sprite[iActor].lotag=lVar1; + return; + + case ACTOR_HITAG: + sprite[iActor].hitag=lVar1; + return; + + case ACTOR_EXTRA: + sprite[iActor].extra=lVar1; + return; + + case ACTOR_HTCGG: + ActorExtra[iActor].cgg=lVar1; + return; + + case ACTOR_HTPICNUM : + ActorExtra[iActor].picnum=lVar1; + return; + + case ACTOR_HTANG: + ActorExtra[iActor].ang=lVar1; + return; + + case ACTOR_HTEXTRA: + ActorExtra[iActor].extra=lVar1; + return; + + case ACTOR_HTOWNER: + ActorExtra[iActor].owner=lVar1; + return; + + case ACTOR_HTMOVFLAG: + ActorExtra[iActor].movflag=lVar1; + return; + + case ACTOR_HTTEMPANG: + ActorExtra[iActor].tempang=lVar1; + return; + + case ACTOR_HTACTORSTAYPUT: + ActorExtra[iActor].actorstayput=lVar1; + return; + + case ACTOR_HTDISPICNUM: + ActorExtra[iActor].dispicnum=lVar1; + return; + + case ACTOR_HTTIMETOSLEEP: + ActorExtra[iActor].timetosleep=lVar1; + return; + + case ACTOR_HTFLOORZ: + ActorExtra[iActor].floorz=lVar1; + return; + + case ACTOR_HTCEILINGZ: + ActorExtra[iActor].ceilingz=lVar1; + return; + + case ACTOR_HTLASTVX: + ActorExtra[iActor].lastvx=lVar1; + return; + + case ACTOR_HTLASTVY: + ActorExtra[iActor].lastvy=lVar1; + return; + + case ACTOR_HTBPOSX: + ActorExtra[iActor].bposx=lVar1; + return; + + case ACTOR_HTBPOSY: + ActorExtra[iActor].bposy=lVar1; + return; + + case ACTOR_HTBPOSZ: + ActorExtra[iActor].bposz=lVar1; + return; + + case ACTOR_HTG_T: + ActorExtra[iActor].temp_data[lParm2]=lVar1; + return; + + case ACTOR_ANGOFF: + spriteext[iActor].angoff=lVar1; + return; + + case ACTOR_PITCH: + spriteext[iActor].pitch=lVar1; + return; + + case ACTOR_ROLL: + spriteext[iActor].roll=lVar1; + return; + + case ACTOR_MDXOFF: + spriteext[iActor].xoff=lVar1; + return; + + case ACTOR_MDYOFF: + spriteext[iActor].yoff=lVar1; + return; + + case ACTOR_MDZOFF: + spriteext[iActor].zoff=lVar1; + return; + + case ACTOR_MDFLAGS: + spriteext[iActor].flags=lVar1; + return; + + case ACTOR_XPANNING: + spriteext[iActor].xpanning=lVar1; + return; + + case ACTOR_YPANNING: + spriteext[iActor].ypanning=lVar1; + return; + + case ACTOR_HTFLAGS: + ActorExtra[iActor].flags=lVar1; + return; + + case ACTOR_ALPHA: + spriteext[iActor].alpha=(float)(lVar1/255.0f); + return; + + default: + return; + } + +badactor: + OSD_Printf(CON_ERROR "tried to set %s on invalid target sprite (%d) from spr %d pic %d gv %s\n",g_errorLineNum,keyw[g_tw], + ActorLabels[lLabelID].name,iActor,vm.g_i,vm.g_sp->picnum, + (lVar1= MAXSPRITES) /* && g_scriptSanityChecks */) + goto badactor; + + if ((ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= ActorLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; switch (lLabelID) { case ACTOR_X: - if (iSet) - { - sprite[iActor].x=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].x,vm.g_i,vm.g_p); return; case ACTOR_Y: - if (iSet) - { - sprite[iActor].y=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].y,vm.g_i,vm.g_p); return; case ACTOR_Z: - if (iSet) - { - sprite[iActor].z=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].z,vm.g_i,vm.g_p); return; case ACTOR_CSTAT: - if (iSet) - { - sprite[iActor].cstat=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].cstat,vm.g_i,vm.g_p); return; case ACTOR_PICNUM: - if (iSet) - { - sprite[iActor].picnum=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].picnum,vm.g_i,vm.g_p); return; case ACTOR_SHADE: - if (iSet) - { - sprite[iActor].shade=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].shade,vm.g_i,vm.g_p); return; case ACTOR_PAL: - if (iSet) - { - sprite[iActor].pal=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].pal,vm.g_i,vm.g_p); return; case ACTOR_CLIPDIST: - if (iSet) - { - sprite[iActor].clipdist=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].clipdist,vm.g_i,vm.g_p); return; case ACTOR_DETAIL: - if (iSet) - { - sprite[iActor].filler=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].filler,vm.g_i,vm.g_p); return; case ACTOR_XREPEAT: - if (iSet) - { - sprite[iActor].xrepeat=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].xrepeat,vm.g_i,vm.g_p); return; case ACTOR_YREPEAT: - if (iSet) - { - sprite[iActor].yrepeat=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].yrepeat,vm.g_i,vm.g_p); return; case ACTOR_XOFFSET: - if (iSet) - { - sprite[iActor].xoffset=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].xoffset,vm.g_i,vm.g_p); return; case ACTOR_YOFFSET: - if (iSet) - { - sprite[iActor].yoffset=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].yoffset,vm.g_i,vm.g_p); return; case ACTOR_SECTNUM: - if (iSet) - { - changespritesect(iActor,lValue); - return; - } Gv_SetVar(lVar2, sprite[iActor].sectnum,vm.g_i,vm.g_p); return; case ACTOR_STATNUM: - if (iSet) - { - changespritestat(iActor,lValue); - return; - } Gv_SetVar(lVar2, sprite[iActor].statnum,vm.g_i,vm.g_p); return; case ACTOR_ANG: - if (iSet) - { - sprite[iActor].ang=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].ang,vm.g_i,vm.g_p); return; case ACTOR_OWNER: - if (iSet) - { - sprite[iActor].owner=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].owner,vm.g_i,vm.g_p); return; case ACTOR_XVEL: - if (iSet) - { - sprite[iActor].xvel=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].xvel,vm.g_i,vm.g_p); return; case ACTOR_YVEL: - if (iSet) - { - sprite[iActor].yvel=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].yvel,vm.g_i,vm.g_p); return; case ACTOR_ZVEL: - if (iSet) - { - sprite[iActor].zvel=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].zvel,vm.g_i,vm.g_p); return; case ACTOR_LOTAG: - if (iSet) - { - sprite[iActor].lotag=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].lotag,vm.g_i,vm.g_p); return; case ACTOR_HITAG: - if (iSet) - { - sprite[iActor].hitag=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].hitag,vm.g_i,vm.g_p); return; case ACTOR_EXTRA: - if (iSet) - { - sprite[iActor].extra=lValue; - return; - } Gv_SetVar(lVar2, sprite[iActor].extra,vm.g_i,vm.g_p); return; case ACTOR_HTCGG: - if (iSet) - { - ActorExtra[iActor].cgg=lValue; - return; - } Gv_SetVar(lVar2, ActorExtra[iActor].cgg, vm.g_i, vm.g_p); return; case ACTOR_HTPICNUM : - if (iSet) - { - ActorExtra[iActor].picnum=lValue; - return; - } Gv_SetVar(lVar2, ActorExtra[iActor].picnum, vm.g_i, vm.g_p); return; case ACTOR_HTANG: - if (iSet) - { - ActorExtra[iActor].ang=lValue; - return; - } Gv_SetVar(lVar2, ActorExtra[iActor].ang, vm.g_i, vm.g_p); return; case ACTOR_HTEXTRA: - if (iSet) - { - ActorExtra[iActor].extra=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].extra, vm.g_i, vm.g_p); return; case ACTOR_HTOWNER: - if (iSet) - { - ActorExtra[iActor].owner=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].owner, vm.g_i, vm.g_p); return; case ACTOR_HTMOVFLAG: - if (iSet) - { - ActorExtra[iActor].movflag=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].movflag, vm.g_i, vm.g_p); return; case ACTOR_HTTEMPANG: - if (iSet) - { - ActorExtra[iActor].tempang=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].tempang, vm.g_i, vm.g_p); return; case ACTOR_HTACTORSTAYPUT: - if (iSet) - { - ActorExtra[iActor].actorstayput=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].actorstayput, vm.g_i, vm.g_p); return; case ACTOR_HTDISPICNUM: - if (iSet) - { - ActorExtra[iActor].dispicnum=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].dispicnum, vm.g_i, vm.g_p); return; case ACTOR_HTTIMETOSLEEP: - if (iSet) - { - ActorExtra[iActor].timetosleep=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].timetosleep, vm.g_i, vm.g_p); return; case ACTOR_HTFLOORZ: - if (iSet) - { - ActorExtra[iActor].floorz=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].floorz, vm.g_i, vm.g_p); return; case ACTOR_HTCEILINGZ: - if (iSet) - { - ActorExtra[iActor].ceilingz=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].ceilingz, vm.g_i, vm.g_p); return; case ACTOR_HTLASTVX: - if (iSet) - { - ActorExtra[iActor].lastvx=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].lastvx, vm.g_i, vm.g_p); return; case ACTOR_HTLASTVY: - if (iSet) - { - ActorExtra[iActor].lastvy=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].lastvy, vm.g_i, vm.g_p); return; case ACTOR_HTBPOSX: - if (iSet) - { - ActorExtra[iActor].bposx=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].bposx, vm.g_i, vm.g_p); return; case ACTOR_HTBPOSY: - if (iSet) - { - ActorExtra[iActor].bposy=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].bposy, vm.g_i, vm.g_p); return; case ACTOR_HTBPOSZ: - if (iSet) - { - ActorExtra[iActor].bposz=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].bposz, vm.g_i, vm.g_p); return; case ACTOR_HTG_T: - if (iSet) - { - ActorExtra[iActor].temp_data[lParm2]=lValue; - return; - } Gv_SetVar(lVar2, ActorExtra[iActor].temp_data[lParm2], vm.g_i, vm.g_p); return; case ACTOR_ANGOFF: - if (iSet) - { - spriteext[iActor].angoff=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].angoff, vm.g_i, vm.g_p); return; case ACTOR_PITCH: - if (iSet) - { - spriteext[iActor].pitch=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].pitch, vm.g_i, vm.g_p); return; case ACTOR_ROLL: - if (iSet) - { - spriteext[iActor].roll=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].roll, vm.g_i, vm.g_p); return; case ACTOR_MDXOFF: - if (iSet) - { - spriteext[iActor].xoff=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].xoff, vm.g_i, vm.g_p); return; case ACTOR_MDYOFF: - if (iSet) - { - spriteext[iActor].yoff=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].yoff, vm.g_i, vm.g_p); return; case ACTOR_MDZOFF: - if (iSet) - { - spriteext[iActor].zoff=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].zoff, vm.g_i, vm.g_p); return; case ACTOR_MDFLAGS: - if (iSet) - { - spriteext[iActor].flags=lValue; - return; - } Gv_SetVar(lVar2,spriteext[iActor].flags, vm.g_i, vm.g_p); return; case ACTOR_XPANNING: - if (iSet) - { - spriteext[iActor].xpanning=lValue; - return; - } Gv_SetVar(lVar2, spriteext[iActor].xpanning,vm.g_i,vm.g_p); return; case ACTOR_YPANNING: - if (iSet) - { - spriteext[iActor].ypanning=lValue; - return; - } Gv_SetVar(lVar2, spriteext[iActor].ypanning,vm.g_i,vm.g_p); return; case ACTOR_HTFLAGS: - if (iSet) - { - ActorExtra[iActor].flags=lValue; - return; - } Gv_SetVar(lVar2,ActorExtra[iActor].flags, vm.g_i, vm.g_p); return; case ACTOR_ALPHA: - if (iSet) - { - spriteext[iActor].alpha=(float)(lValue/255.0f); - return; - } Gv_SetVar(lVar2, (uint8_t)(spriteext[iActor].alpha * 255.0f), vm.g_i, vm.g_p); return; default: return; } + +badactor: + OSD_Printf(CON_ERROR "tried to get %s on invalid target sprite (%d) from spr %d pic %d gv %s\n",g_errorLineNum,keyw[g_tw], + ActorLabels[lLabelID].name,iActor,vm.g_i,vm.g_sp->picnum, + (lVar1= MAXSPRITES) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "invalid target sprite (%d) %d %d\n",g_errorLineNum,keyw[g_tw],iActor,vm.g_i,vm.g_sp->picnum); - insptr += (lVar2 == MAXGAMEVARS); - return; - } + goto badsprite; if (iSet) lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); if ((!spriteext[iActor].tspr) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "Internal bug, tsprite is unavailable\n",g_errorLineNum,keyw[g_tw]); - return; - } + goto badtspr; switch (lLabelID) { @@ -3782,18 +3055,23 @@ static inline void X_AccessTsprite(int32_t iSet, int32_t lVar1, int32_t lLabelID default: return; } + +badsprite: + OSD_Printf(CON_ERROR "invalid target sprite (%d) %d %d\n",g_errorLineNum,keyw[g_tw],iActor,vm.g_i,vm.g_sp->picnum); + insptr += (lVar2 == MAXGAMEVARS); + return; + +badtspr: + OSD_Printf(CON_ERROR "Internal bug, tsprite is unavailable\n",g_errorLineNum,keyw[g_tw]); + return; } -static inline void X_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) +static void __fastcall X_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) { int32_t lValue=0; - if ((lVar1 < 0 || lVar1 >= MAXTILES) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "invalid tile (%d)\n",g_errorLineNum,keyw[g_tw],lVar1); - insptr += (lVar2 == MAXGAMEVARS); - return; - } + if ((lVar1 < 0 || lVar1 >= MAXTILES) /* && g_scriptSanityChecks */) + goto badtile; if (iSet) lValue=Gv_GetVar(lVar2, vm.g_i, vm.g_p); @@ -4055,16 +3333,17 @@ static inline void X_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t lLabe default: return; } + +badtile: + OSD_Printf(CON_ERROR "invalid tile (%d)\n",g_errorLineNum,keyw[g_tw],lVar1); + insptr += (lVar2 == MAXGAMEVARS); + return; } #else static int32_t __fastcall X_AccessSpriteX(int32_t iActor, int32_t lLabelID, int32_t lParm2) { - if ((ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= ActorLabels[lLabelID].maxParm2)) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "tried to get invalid %s position %d on sprite (%d) from spr %d\n", - g_errorLineNum,keyw[g_tw],ActorLabels[lLabelID].name,lParm2,iActor,vm.g_i); - return -1; - } + if ((ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= ActorLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; switch (lLabelID) { @@ -4122,6 +3401,11 @@ static int32_t __fastcall X_AccessSpriteX(int32_t iActor, int32_t lLabelID, int3 case ACTOR_ALPHA: return (uint8_t)(spriteext[iActor].alpha*255.0f); default: return -1; } + +badpos: + OSD_Printf(CON_ERROR "tried to get invalid %s position %d on sprite (%d) from spr %d\n", + g_errorLineNum,keyw[g_tw],ActorLabels[lLabelID].name,lParm2,iActor,vm.g_i); + return -1; } static int32_t __fastcall X_AccessSectorX(int32_t iSector, int32_t lLabelID) @@ -4157,11 +3441,8 @@ static int32_t __fastcall X_AccessSectorX(int32_t iSector, int32_t lLabelID) static int32_t __fastcall X_AccessPlayerX(int32_t iPlayer, int32_t lLabelID, int32_t lParm2) { - if ((PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= PlayerLabels[lLabelID].maxParm2)) && g_scriptSanityChecks) - { - OSD_Printf(CON_ERROR "tried to %s invalid %s position %d on player (%d) from spr %d\n", - g_errorLineNum,keyw[g_tw],PlayerLabels[lLabelID].name,lParm2,iPlayer,vm.g_i); - } + if ((PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (lParm2 < 0 || lParm2 >= PlayerLabels[lLabelID].maxParm2)) /* && g_scriptSanityChecks */) + goto badpos; switch (lLabelID) { @@ -4456,6 +3737,11 @@ static int32_t __fastcall X_AccessPlayerX(int32_t iPlayer, int32_t lLabelID, int default: return -1; } + +badpos: + OSD_Printf(CON_ERROR "tried to get invalid %s position %d on player (%d) from spr %d\n", + g_errorLineNum,keyw[g_tw],PlayerLabels[lLabelID].name,lParm2,iPlayer,vm.g_i); + return -1; } static int32_t __fastcall X_AccessWallX(int32_t iWall, int32_t lLabelID) diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index ed78d27b0..bbf7ba00b 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -298,7 +298,7 @@ void Gv_WriteSave(FILE *fil) } Bsprintf(g_szBuf,"EOF: EDuke32"); - l=strlen(g_szBuf); + l=Bstrlen(g_szBuf); dfwrite(&l,sizeof(l),1,fil); dfwrite(g_szBuf,l,1,fil); } @@ -503,12 +503,15 @@ int32_t Gv_NewVar(const char *pszLabel, int32_t lValue, uint32_t dwFlags) return 1; } -void A_ResetVars(int32_t iActor) +void __fastcall A_ResetVars(register int32_t iActor) { - int32_t i=(MAXGAMEVARS-1); - for (; i>=0; i--) - if ((aGameVars[i].dwFlags & GAMEVAR_PERACTOR) && !(aGameVars[i].dwFlags & GAMEVAR_NODEFAULT)) + register int32_t i=(MAXGAMEVARS-1); + do + { + if ((aGameVars[i].dwFlags & (GAMEVAR_PERACTOR|GAMEVAR_NODEFAULT)) == GAMEVAR_PERACTOR) aGameVars[i].val.plValues[iActor]=aGameVars[i].lDefault; + } + while (i--); } static int32_t Gv_GetVarIndex(const char *szGameLabel) @@ -522,25 +525,22 @@ static int32_t Gv_GetVarIndex(const char *szGameLabel) return i; } -int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer) +int32_t __fastcall Gv_GetVar(register int32_t id, register int32_t iActor, register int32_t iPlayer) { - if (id == MAXGAMEVARS) - return(*insptr++); - if (id == g_iThisActorID) return iActor; + if (id == MAXGAMEVARS) + return(*insptr++); + { - int32_t negateResult = 0; + register intptr_t negateResult = id&(MAXGAMEVARS<<1); if (id >= g_gameVarCount || id < 0) { if (id&(MAXGAMEVARS<<2)) // array { - int32_t index=Gv_GetVar(*insptr++,iActor,iPlayer); - - if (id&(MAXGAMEVARS<<1)) // negative array access - negateResult = 1; + register int32_t index=Gv_GetVar(*insptr++,iActor,iPlayer); id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); @@ -549,174 +549,102 @@ int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer) OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index (%s[%d])\n",g_errorLineNum,keyw[g_tw],aGameArrays[id].szLabel,index); return -1; } - if (negateResult) return (-aGameArrays[id].plValues[index]); - return (aGameArrays[id].plValues[index]); + + return ((aGameArrays[id].plValues[index] ^ -negateResult) + negateResult); } if (id&(MAXGAMEVARS<<3)) // struct shortcut vars { - int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer), label; + register int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); - if (id == g_iActorVarID) + switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) { - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - label = Gv_GetVar(*insptr++, index, iPlayer); -// OSD_Printf("actorvar returned %d\n",label); - } - else label = *insptr++; - - if (id&(MAXGAMEVARS<<1)) // negative array access - negateResult = 1; - - id &= (MAXGAMEVARS-1); //~((MAXGAMEVARS<<3)|(MAXGAMEVARS<<1)); - - if (id == g_iSpriteVarID) + case 0: //if (id == g_iSpriteVarID) { - int32_t parm2 = 0; + int32_t parm2 = 0, label = *insptr++; /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ if (ActorLabels[label].flags & LABEL_HASPARM2) parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessSpriteX(index, label, parm2)); - return (X_AccessSpriteX(index, label, parm2)); + return ((X_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult); } - else if (id == g_iPlayerVarID) + case 3: //else if (id == g_iPlayerVarID) { - int32_t parm2 = 0; + int32_t parm2 = 0, label = *insptr++; if (PlayerLabels[label].flags & LABEL_HASPARM2) parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); if (index == vm.g_i) index = vm.g_p; - if (index >= MAXPLAYERS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessPlayerX(index, label, parm2)); - return (X_AccessPlayerX(index, label, parm2)); + return ((X_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult); } - else if (id == g_iActorVarID) - { - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return -label; - return label; - } - else if (id == g_iSectorVarID) - { + case 4: //else if (id == g_iActorVarID) + return ((Gv_GetVar(*insptr++, index, iPlayer) ^ -negateResult) + negateResult); + case 1: //else if (id == g_iSectorVarID) if (index == vm.g_i) index = sprite[vm.g_i].sectnum; - if (index >= MAXSECTORS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessSectorX(index, label)); - return (X_AccessSectorX(index, label)); - } - else if (id == g_iWallVarID) - { - if (index >= MAXWALLS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessWallX(index, label)); - return (X_AccessWallX(index, label)); + return ((X_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); + case 2: //else if (id == g_iWallVarID) + return ((X_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); + default: + OSD_Printf(CON_ERROR "Gv_GetVar(): WTF??\n",g_errorLineNum,keyw[g_tw]); + return -1; } } - if ((id&(MAXGAMEVARS<<1)) == 0) + id &= (MAXGAMEVARS-1); + + if (!negateResult) { OSD_Printf(CON_ERROR "Gv_GetVar(): invalid gamevar ID (%d)\n",g_errorLineNum,keyw[g_tw],id); return -1; } - - negateResult = 1; - id &= ~(MAXGAMEVARS<<1); } - switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR| - GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + switch (aGameVars[id].dwFlags & + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { default: - if (negateResult) return (-aGameVars[id].val.lValue); - return (aGameVars[id].val.lValue); + return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); case GAMEVAR_PERPLAYER: - if (iPlayer < 0 || iPlayer >= MAXPLAYERS) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid player ID (%d)\n",g_errorLineNum,keyw[g_tw],iPlayer); - return -1; - } - if (negateResult) return (-aGameVars[id].val.plValues[iPlayer]); - return (aGameVars[id].val.plValues[iPlayer]); + if (iPlayer < 0 || iPlayer >= MAXPLAYERS) goto bad_id; + return ((aGameVars[id].val.plValues[iPlayer] ^ -negateResult) + negateResult); case GAMEVAR_PERACTOR: - if (iActor < 0 || iActor >= MAXSPRITES) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid sprite ID (%d)\n",g_errorLineNum,keyw[g_tw],iActor); - return -1; - } - if (negateResult) return (-aGameVars[id].val.plValues[iActor]); - return (aGameVars[id].val.plValues[iActor]); + if (iActor < 0 || iActor >= MAXSPRITES) goto bad_id; + return ((aGameVars[id].val.plValues[iActor] ^ -negateResult) + negateResult); case GAMEVAR_INTPTR: - if (negateResult) return (-(*((int32_t*)aGameVars[id].val.lValue))); - return ((*((int32_t*)aGameVars[id].val.lValue))); + return (((*((int32_t*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); case GAMEVAR_SHORTPTR: - if (negateResult) return (-(*((int16_t*)aGameVars[id].val.lValue))); - return ((*((int16_t*)aGameVars[id].val.lValue))); + return (((*((int16_t*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); case GAMEVAR_CHARPTR: - if (negateResult) return (-(*((char*)aGameVars[id].val.lValue))); - return ((*((char*)aGameVars[id].val.lValue))); + return (((*((char*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); } - } +bad_id: + OSD_Printf(CON_ERROR "Gv_GetVar(): invalid sprite/player ID %d/%d\n",g_errorLineNum,keyw[g_tw],iActor,iPlayer); + return -1; } -void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer) +void __fastcall Gv_SetVar(register int32_t id, register int32_t lValue, register int32_t iActor, register int32_t iPlayer) { - if (id<0 || id >= g_gameVarCount) - { - OSD_Printf(CON_ERROR "Gv_SetVar(): tried to set invalid gamevar ID (%d) from sprite %d (%d), player %d\n",g_errorLineNum,keyw[g_tw],id,vm.g_i,sprite[vm.g_i].picnum,vm.g_p); - return; - } + if (id<0 || id >= g_gameVarCount) goto badvarid; + //Bsprintf(g_szBuf,"SGVI: %d ('%s') to %d for %d %d",id,aGameVars[id].szLabel,lValue,iActor,iPlayer); //AddLog(g_szBuf); - switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR| - GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + switch (aGameVars[id].dwFlags & + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { default: aGameVars[id].val.lValue=lValue; return; case GAMEVAR_PERPLAYER: - if (iPlayer < 0 || iPlayer > MAXPLAYERS-1) - { - OSD_Printf(CON_ERROR "Gv_SetVar(): invalid player (%d) for per-player gamevar %s from sprite %d, player %d\n",g_errorLineNum,keyw[g_tw],iPlayer,aGameVars[id].szLabel,vm.g_i,vm.g_p); - return; - } + if (iPlayer < 0 || iPlayer > MAXPLAYERS-1) goto badplayer; // for the current player aGameVars[id].val.plValues[iPlayer]=lValue; return; case GAMEVAR_PERACTOR: - if (iActor < 0 || iActor > MAXSPRITES-1) - { - OSD_Printf(CON_ERROR "Gv_SetVar(): invalid sprite (%d) for per-actor gamevar %s from sprite %d (%d), player %d\n",g_errorLineNum,keyw[g_tw],iActor,aGameVars[id].szLabel,vm.g_i,sprite[vm.g_i].picnum,vm.g_p); - return; - } - // for the current actor + if (iActor < 0 || iActor > MAXSPRITES-1) goto badactor; aGameVars[id].val.plValues[iActor]=lValue; return; case GAMEVAR_INTPTR: @@ -726,30 +654,39 @@ void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iP *((int16_t*)aGameVars[id].val.lValue)=(int16_t)lValue; return; case GAMEVAR_CHARPTR: - *((char*)aGameVars[id].val.lValue)=(uint8_t)lValue; + *((uint8_t*)aGameVars[id].val.lValue)=(uint8_t)lValue; return; } + +badvarid: + OSD_Printf(CON_ERROR "Gv_SetVar(): tried to set invalid gamevar ID (%d) from sprite %d (%d), player %d\n",g_errorLineNum,keyw[g_tw],id,vm.g_i,sprite[vm.g_i].picnum,vm.g_p); + return; + +badplayer: + OSD_Printf(CON_ERROR "Gv_SetVar(): invalid player (%d) for per-player gamevar %s from sprite %d, player %d\n",g_errorLineNum,keyw[g_tw],iPlayer,aGameVars[id].szLabel,vm.g_i,vm.g_p); + return; + +badactor: + OSD_Printf(CON_ERROR "Gv_SetVar(): invalid sprite (%d) for per-actor gamevar %s from sprite %d (%d), player %d\n",g_errorLineNum,keyw[g_tw],iActor,aGameVars[id].szLabel,vm.g_i,sprite[vm.g_i].picnum,vm.g_p); + return; } -int32_t __fastcall Gv_GetVarX(int32_t id) +int32_t __fastcall Gv_GetVarX(register int32_t id) { - if (id == MAXGAMEVARS) - return(*insptr++); - if (id == g_iThisActorID) return vm.g_i; + if (id == MAXGAMEVARS) + return(*insptr++); + { - int32_t negateResult = 0; + register intptr_t negateResult = id&(MAXGAMEVARS<<1); if (id >= g_gameVarCount || id < 0) { if (id&(MAXGAMEVARS<<2)) // array { - int32_t index=Gv_GetVarX(*insptr++); - - if (id&(MAXGAMEVARS<<1)) // negative array access - negateResult = 1; + register int32_t index=Gv_GetVarX(*insptr++); id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); @@ -758,134 +695,80 @@ int32_t __fastcall Gv_GetVarX(int32_t id) OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index (%s[%d])\n",g_errorLineNum,keyw[g_tw],aGameArrays[id].szLabel,index); return -1; } - if (negateResult) return (-aGameArrays[id].plValues[index]); - return (aGameArrays[id].plValues[index]); + return ((aGameArrays[id].plValues[index] ^ -negateResult) + negateResult); } if (id&(MAXGAMEVARS<<3)) // struct shortcut vars { - int32_t index=Gv_GetVarX(*insptr++), label; + register int32_t index=Gv_GetVarX(*insptr++); - if (id&(MAXGAMEVARS<<1)) // negative array access - negateResult = 1; - - id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<3)|(MAXGAMEVARS<<1)); - - if (id == g_iActorVarID) + switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) { - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - label = Gv_GetVar(*insptr++, index, vm.g_p); - } - else label = *insptr++; - - if (id == g_iSpriteVarID) + case 0: //if (id == g_iSpriteVarID) { - int32_t parm2 = 0; + int32_t parm2 = 0, label = *insptr++; /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ if (ActorLabels[label].flags & LABEL_HASPARM2) parm2 = Gv_GetVarX(*insptr++); - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessSpriteX(index, label, parm2)); - return (X_AccessSpriteX(index, label, parm2)); + return ((X_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult); } - else if (id == g_iPlayerVarID) + case 3: //else if (id == g_iPlayerVarID) { - int32_t parm2 = 0; + int32_t parm2 = 0, label = *insptr++; if (PlayerLabels[label].flags & LABEL_HASPARM2) parm2 = Gv_GetVarX(*insptr++); if (index == vm.g_i) index = vm.g_p; - if (index >= MAXPLAYERS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessPlayerX(index, label, parm2)); - return (X_AccessPlayerX(index, label, parm2)); + return ((X_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult); } - else if (id == g_iActorVarID) - { - if (index >= MAXSPRITES || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return -label; - return label; - } - else if (id == g_iSectorVarID) - { + case 4: //else if (id == g_iActorVarID) + return ((Gv_GetVar(*insptr++, index, vm.g_p) ^ -negateResult) + negateResult); + case 1: //else if (id == g_iSectorVarID) if (index == vm.g_i) index = sprite[vm.g_i].sectnum; - if (index >= MAXSECTORS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessSectorX(index, label)); - return (X_AccessSectorX(index, label)); - } - else if (id == g_iWallVarID) - { - if (index >= MAXWALLS || index < 0) - { - OSD_Printf(CON_ERROR "Gv_GetVar(): invalid array index\n",g_errorLineNum,keyw[g_tw]); - return -1; - } - if (negateResult) return (-X_AccessWallX(index, label)); - return (X_AccessWallX(index, label)); + return ((X_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); + case 2: //else if (id == g_iWallVarID) + return ((X_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); + default: + OSD_Printf(CON_ERROR "Gv_GetVar(): WTF??\n",g_errorLineNum,keyw[g_tw]); + return -1; } } - if ((id&(MAXGAMEVARS<<1)) == 0) + id &= (MAXGAMEVARS-1); + + if (!negateResult) { OSD_Printf(CON_ERROR "Gv_GetVar(): invalid gamevar ID (%d)\n",g_errorLineNum,keyw[g_tw],id); return -1; } - - negateResult = 1; - id &= ~(MAXGAMEVARS<<1); } - switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR| - GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + switch (aGameVars[id].dwFlags & + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { default: - if (negateResult) return (-aGameVars[id].val.lValue); - return (aGameVars[id].val.lValue); + return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); case GAMEVAR_PERPLAYER: - if (negateResult) return (-aGameVars[id].val.plValues[vm.g_p]); - return (aGameVars[id].val.plValues[vm.g_p]); + return ((aGameVars[id].val.plValues[vm.g_p] ^ -negateResult) + negateResult); case GAMEVAR_PERACTOR: - if (negateResult) return (-aGameVars[id].val.plValues[vm.g_i]); - return (aGameVars[id].val.plValues[vm.g_i]); + return ((aGameVars[id].val.plValues[vm.g_i] ^ -negateResult) + negateResult); case GAMEVAR_INTPTR: - if (negateResult) return (-(*((int32_t*)aGameVars[id].val.lValue))); - return (*((int32_t*)aGameVars[id].val.lValue)); + return (((*((int32_t*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); case GAMEVAR_SHORTPTR: - if (negateResult) return (-(*((int16_t*)aGameVars[id].val.lValue))); - return (*((int16_t*)aGameVars[id].val.lValue)); + return (((*((int16_t*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); case GAMEVAR_CHARPTR: - if (negateResult) return (-(*((char*)aGameVars[id].val.lValue))); - return (*((char*)aGameVars[id].val.lValue)); + return (((*((uint8_t*)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); } } } -void __fastcall Gv_SetVarX(int32_t id, int32_t lValue) +void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue) { - switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR| - GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + switch (aGameVars[id].dwFlags & + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { default: aGameVars[id].val.lValue=lValue; @@ -903,7 +786,7 @@ void __fastcall Gv_SetVarX(int32_t id, int32_t lValue) *((int16_t*)aGameVars[id].val.lValue)=(int16_t)lValue; return; case GAMEVAR_CHARPTR: - *((char*)aGameVars[id].val.lValue)=(uint8_t)lValue; + *((uint8_t*)aGameVars[id].val.lValue)=(uint8_t)lValue; return; } } diff --git a/polymer/eduke32/source/global.c b/polymer/eduke32/source/global.c index 3dc40d3b5..6146f3e4f 100644 --- a/polymer/eduke32/source/global.c +++ b/polymer/eduke32/source/global.c @@ -84,6 +84,8 @@ sound_t g_sounds[ MAXSOUNDS ]; char g_numPlayerSprites,g_loadFromGroupOnly=0,g_earthquakeTime; +int32_t playerswhenstarted; + int32_t fricxv,fricyv; playerdata_t g_player[MAXPLAYERS]; input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS]; diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 9585e93b3..738c1a6a0 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -353,39 +353,39 @@ int32_t A_Shoot(int32_t i,int32_t atwith) case CHAINGUN__STATIC: case RPG__STATIC: case MORTER__STATIC: - { - int32_t x = ((sintable[(s->ang+512)&2047])>>7), y = ((sintable[(s->ang)&2047])>>7); - s-> x += x; - s-> y += y; - G_AddGameLight(0, i, PHEIGHT, 8192, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); - ActorExtra[i].lightcount = 2; - s-> x -= x; - s-> y -= y; - } + { + int32_t x = ((sintable[(s->ang+512)&2047])>>7), y = ((sintable[(s->ang)&2047])>>7); + s-> x += x; + s-> y += y; + G_AddGameLight(0, i, PHEIGHT, 8192, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + ActorExtra[i].lightcount = 2; + s-> x -= x; + s-> y -= y; + } -/* - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(s->ang+512)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(s->ang)&2047])>>4); + /* + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(s->ang+512)&2047])>>4); + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(s->ang)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = 255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = 80; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = 0; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = 255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = 80; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = 0; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; - if (gamelightcount < PR_MAXLIGHTS) - gamelightcount++; -*/ - break; + if (gamelightcount < PR_MAXLIGHTS) + gamelightcount++; + */ + break; } #endif // POLYMER } @@ -406,28 +406,28 @@ int32_t A_Shoot(int32_t i,int32_t atwith) s-> x -= x; s-> y -= y; -/* - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(s->ang+512)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(s->ang)&2047])>>4); + /* + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(s->ang+512)&2047])>>4); + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(s->ang)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = ProjectileData[atwith].flashcolor&255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = (ProjectileData[atwith].flashcolor>>8)&255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = (ProjectileData[atwith].flashcolor>>16)&255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = ProjectileData[atwith].flashcolor&255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = (ProjectileData[atwith].flashcolor>>8)&255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = (ProjectileData[atwith].flashcolor>>16)&255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; - if (gamelightcount < PR_MAXLIGHTS) - gamelightcount++; -*/ + if (gamelightcount < PR_MAXLIGHTS) + gamelightcount++; + */ } #endif // POLYMER @@ -2202,28 +2202,28 @@ void P_FireWeapon(DukePlayer_t *p) ActorExtra[p->i].lightcount = 2; s->x -= x; s->y -= y; -/* - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(p->ang+512)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(p->ang)&2047])>>4); + /* + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].sector = s->sectnum; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].x = s->x+((sintable[(p->ang+512)&2047])>>4); + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].y = s->y+((sintable[(p->ang)&2047])>>4); - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].z = s->z-PHEIGHT; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].range = 8192; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].angle = (s->ang+1024)&2047; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].horiz = 100; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].radius = 256; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].faderadius = 200; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = aplWeaponFlashColor[p->curr_weapon][snum]&255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = (aplWeaponFlashColor[p->curr_weapon][snum]>>8)&255; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = (aplWeaponFlashColor[p->curr_weapon][snum]>>16)&255;; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[0] = aplWeaponFlashColor[p->curr_weapon][snum]&255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[1] = (aplWeaponFlashColor[p->curr_weapon][snum]>>8)&255; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].color[2] = (aplWeaponFlashColor[p->curr_weapon][snum]>>16)&255;; - gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; + gamelights[gamelightcount&(PR_MAXLIGHTS-1)].priority = PR_LIGHT_PRIO_MAX_GAME; - if (gamelightcount < PR_MAXLIGHTS) - gamelightcount++; -*/ + if (gamelightcount < PR_MAXLIGHTS) + gamelightcount++; + */ #endif // POLYMER lastvisinc = totalclock+32; p->visibility = 0; diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index cde431aa4..33b8dea33 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1868,7 +1868,10 @@ int32_t G_EnterLevel(int32_t g) } if ((g&MODE_GAME) || (g&MODE_EOL)) - g_player[myconnectindex].ps->gm = MODE_GAME; + { + TRAVERSE_CONNECT(i) + g_player[i].ps->gm = MODE_GAME; + } else if (g&MODE_RESTART) { if (ud.recstat == 2)