From 0d411e468e076121de5b38c13e95603822df4826 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 24 Apr 2006 19:04:22 +0000 Subject: [PATCH] Whitespace git-svn-id: https://svn.eduke32.com/eduke32@109 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/a-c.c | 354 +- polymer/build/src/baselayer.c | 284 +- polymer/build/src/bstub.c | 642 +- polymer/build/src/build.c | 12404 ++++++++++++++-------------- polymer/build/src/buildstartwin.c | 260 +- polymer/build/src/cache1d.c | 1910 ++--- polymer/build/src/compat.c | 688 +- polymer/build/src/config.c | 380 +- polymer/build/src/crc32.c | 42 +- polymer/build/src/defs.c | 1844 ++--- polymer/build/src/engine.c | 2484 +++--- polymer/build/src/game.c | 10286 +++++++++++------------ polymer/build/src/gamestartwin.c | 202 +- polymer/build/src/glbuild.c | 360 +- polymer/build/src/gtkbits.c | 268 +- polymer/build/src/hightile.c | 312 +- polymer/build/src/kplib.c | 4466 +++++----- polymer/build/src/lzf_c.c | 184 +- polymer/build/src/lzf_d.c | 76 +- polymer/build/src/lzwnew.c | 134 +- polymer/build/src/md4.c | 256 +- polymer/build/src/mdsprite.c | 1356 +-- polymer/build/src/mmulti.c | 858 +- polymer/build/src/mmulti_null.c | 14 +- polymer/build/src/osd.c | 1318 +-- polymer/build/src/polymer.c | 2 +- polymer/build/src/polymost.c | 8168 +++++++++--------- polymer/build/src/pragmas.c | 298 +- polymer/build/src/scriptfile.c | 530 +- polymer/build/src/sdlayer.c | 1706 ++-- polymer/build/src/smalltextfont.c | 346 +- polymer/build/src/sound.c | 424 +- polymer/build/src/textfont.c | 346 +- polymer/build/src/winlayer.c | 4858 +++++------ polymer/eduke32/source/game.c | 8 +- 35 files changed, 29034 insertions(+), 29034 deletions(-) diff --git a/polymer/build/src/a-c.c b/polymer/build/src/a-c.c index bc45cae91..8453757ae 100644 --- a/polymer/build/src/a-c.c +++ b/polymer/build/src/a-c.c @@ -25,268 +25,268 @@ static long bpl, transmode = 0; static long glogx, glogy, gbxinc, gbyinc, gpinc; static char *gbuf, *gpal, *ghlinepal, *gtrans; - //Global variable functions +//Global variable functions void setvlinebpl(long dabpl) { bpl = dabpl; } void fixtransluscence(long datransoff) { gtrans = (char *)datransoff; } void settransnormal(void) { transmode = 0; } void settransreverse(void) { transmode = 1; } - //Ceiling/floor horizontal line functions +//Ceiling/floor horizontal line functions void sethlinesizes(long logx, long logy, long bufplc) - { glogx = logx; glogy = logy; gbuf = (char *)bufplc; } +{ glogx = logx; glogy = logy; gbuf = (char *)bufplc; } void setpalookupaddress(char *paladdr) { ghlinepal = paladdr; } void setuphlineasm4(long bxinc, long byinc) { gbxinc = bxinc; gbyinc = byinc; } void hlineasm4(long cnt, long skiploadincs, long paloffs, unsigned long by, unsigned long bx, long p) { - char *palptr; + char *palptr; - palptr = (char *)&ghlinepal[paloffs]; - if (!skiploadincs) { gbxinc = asm1; gbyinc = asm2; } - for(;cnt>=0;cnt--) - { - *((char *)p) = palptr[gbuf[((bx>>(32-glogx))<>(32-glogy))]]; - bx -= gbxinc; - by -= gbyinc; - p--; - } + palptr = (char *)&ghlinepal[paloffs]; + if (!skiploadincs) { gbxinc = asm1; gbyinc = asm2; } + for(;cnt>=0;cnt--) + { + *((char *)p) = palptr[gbuf[((bx>>(32-glogx))<>(32-glogy))]]; + bx -= gbxinc; + by -= gbyinc; + p--; + } } - //Sloped ceiling/floor vertical line functions +//Sloped ceiling/floor vertical line functions void setupslopevlin(long logylogx, long bufplc, long pinc) { - glogx = (logylogx&255); glogy = (logylogx>>8); - gbuf = (char *)bufplc; gpinc = pinc; + glogx = (logylogx&255); glogy = (logylogx>>8); + gbuf = (char *)bufplc; gpinc = pinc; } void slopevlin(long p, long i, long slopaloffs, long cnt, long bx, long by) { - long *slopalptr, bz, bzinc; - unsigned long u, v; + long *slopalptr, bz, bzinc; + unsigned long u, v; - bz = asm3; bzinc = (asm1>>3); - slopalptr = (long *)slopaloffs; - for(;cnt>0;cnt--) - { - i = krecip(bz>>6); bz += bzinc; - u = bx+globalx3*i; - v = by+globaly3*i; - (*(char *)p) = *(char *)(slopalptr[0]+gbuf[((u>>(32-glogx))<>(32-glogy))]); - slopalptr--; - p += gpinc; - } + bz = asm3; bzinc = (asm1>>3); + slopalptr = (long *)slopaloffs; + for(;cnt>0;cnt--) + { + i = krecip(bz>>6); bz += bzinc; + u = bx+globalx3*i; + v = by+globaly3*i; + (*(char *)p) = *(char *)(slopalptr[0]+gbuf[((u>>(32-glogx))<>(32-glogy))]); + slopalptr--; + p += gpinc; + } } - //Wall,face sprite/wall sprite vertical line functions +//Wall,face sprite/wall sprite vertical line functions void setupvlineasm(long neglogy) { glogy = neglogy; } void vlineasm1(long vinc, long paloffs, long cnt, unsigned long vplc, long bufplc, long p) { - gbuf = (char *)bufplc; - gpal = (char *)paloffs; - for(;cnt>=0;cnt--) - { - *((char *)p) = gpal[gbuf[vplc>>glogy]]; - p += bpl; - vplc += vinc; - } + gbuf = (char *)bufplc; + gpal = (char *)paloffs; + for(;cnt>=0;cnt--) + { + *((char *)p) = gpal[gbuf[vplc>>glogy]]; + p += bpl; + vplc += vinc; + } } void setupmvlineasm(long neglogy) { glogy = neglogy; } void mvlineasm1(long vinc, long paloffs, long cnt, unsigned long vplc, long bufplc, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - gpal = (char *)paloffs; - for(;cnt>=0;cnt--) - { - ch = gbuf[vplc>>glogy]; if (ch != 255) *((char *)p) = gpal[ch]; - p += bpl; - vplc += vinc; - } + gbuf = (char *)bufplc; + gpal = (char *)paloffs; + for(;cnt>=0;cnt--) + { + ch = gbuf[vplc>>glogy]; if (ch != 255) *((char *)p) = gpal[ch]; + p += bpl; + vplc += vinc; + } } void setuptvlineasm(long neglogy) { glogy = neglogy; } void tvlineasm1(long vinc, long paloffs, long cnt, unsigned long vplc, long bufplc, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - gpal = (char *)paloffs; - if (transmode) - { - for(;cnt>=0;cnt--) - { - ch = gbuf[vplc>>glogy]; - if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; - p += bpl; - vplc += vinc; - } - } - else - { - for(;cnt>=0;cnt--) - { - ch = gbuf[vplc>>glogy]; - if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; - p += bpl; - vplc += vinc; - } - } + gbuf = (char *)bufplc; + gpal = (char *)paloffs; + if (transmode) + { + for(;cnt>=0;cnt--) + { + ch = gbuf[vplc>>glogy]; + if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; + p += bpl; + vplc += vinc; + } + } + else + { + for(;cnt>=0;cnt--) + { + ch = gbuf[vplc>>glogy]; + if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; + p += bpl; + vplc += vinc; + } + } } - //Floor sprite horizontal line functions +//Floor sprite horizontal line functions void msethlineshift(long logx, long logy) { glogx = logx; glogy = logy; } void mhline(long bufplc, unsigned long bx, long cntup16, long junk, unsigned long by, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - gpal = (char *)asm3; - for(cntup16>>=16;cntup16>0;cntup16--) - { - ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; - if (ch != 255) *((char *)p) = gpal[ch]; - bx += asm1; - by += asm2; - p++; - } + gbuf = (char *)bufplc; + gpal = (char *)asm3; + for(cntup16>>=16;cntup16>0;cntup16--) + { + ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; + if (ch != 255) *((char *)p) = gpal[ch]; + bx += asm1; + by += asm2; + p++; + } } void tsethlineshift(long logx, long logy) { glogx = logx; glogy = logy; } void thline(long bufplc, unsigned long bx, long cntup16, long junk, unsigned long by, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - gpal = (char *)asm3; - if (transmode) - { - for(cntup16>>=16;cntup16>0;cntup16--) - { - ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; - if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; - bx += asm1; - by += asm2; - p++; - } - } - else - { - for(cntup16>>=16;cntup16>0;cntup16--) - { - ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; - if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; - bx += asm1; - by += asm2; - p++; - } - } + gbuf = (char *)bufplc; + gpal = (char *)asm3; + if (transmode) + { + for(cntup16>>=16;cntup16>0;cntup16--) + { + ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; + if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; + bx += asm1; + by += asm2; + p++; + } + } + else + { + for(cntup16>>=16;cntup16>0;cntup16--) + { + ch = gbuf[((bx>>(32-glogx))<>(32-glogy))]; + if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; + bx += asm1; + by += asm2; + p++; + } + } } - //Rotatesprite vertical line functions +//Rotatesprite vertical line functions void setupspritevline(long paloffs, long bxinc, long byinc, long ysiz) { - gpal = (char *)paloffs; - gbxinc = bxinc; - gbyinc = byinc; - glogy = ysiz; + gpal = (char *)paloffs; + gbxinc = bxinc; + gbyinc = byinc; + glogy = ysiz; } void spritevline(long bx, long by, long cnt, long bufplc, long p) { - gbuf = (char *)bufplc; - for(;cnt>1;cnt--) - { - (*(char *)p) = gpal[gbuf[(bx>>16)*glogy+(by>>16)]]; - bx += gbxinc; - by += gbyinc; - p += bpl; - } + gbuf = (char *)bufplc; + for(;cnt>1;cnt--) + { + (*(char *)p) = gpal[gbuf[(bx>>16)*glogy+(by>>16)]]; + bx += gbxinc; + by += gbyinc; + p += bpl; + } } - //Rotatesprite vertical line functions +//Rotatesprite vertical line functions void msetupspritevline(long paloffs, long bxinc, long byinc, long ysiz) { - gpal = (char *)paloffs; - gbxinc = bxinc; - gbyinc = byinc; - glogy = ysiz; + gpal = (char *)paloffs; + gbxinc = bxinc; + gbyinc = byinc; + glogy = ysiz; } void mspritevline(long bx, long by, long cnt, long bufplc, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - for(;cnt>1;cnt--) - { - ch = gbuf[(bx>>16)*glogy+(by>>16)]; - if (ch != 255) (*(char *)p) = gpal[ch]; - bx += gbxinc; - by += gbyinc; - p += bpl; - } + gbuf = (char *)bufplc; + for(;cnt>1;cnt--) + { + ch = gbuf[(bx>>16)*glogy+(by>>16)]; + if (ch != 255) (*(char *)p) = gpal[ch]; + bx += gbxinc; + by += gbyinc; + p += bpl; + } } void tsetupspritevline(long paloffs, long bxinc, long byinc, long ysiz) { - gpal = (char *)paloffs; - gbxinc = bxinc; - gbyinc = byinc; - glogy = ysiz; + gpal = (char *)paloffs; + gbxinc = bxinc; + gbyinc = byinc; + glogy = ysiz; } void tspritevline(long bx, long by, long cnt, long bufplc, long p) { - char ch; + char ch; - gbuf = (char *)bufplc; - if (transmode) - { - for(;cnt>1;cnt--) - { - ch = gbuf[(bx>>16)*glogy+(by>>16)]; - if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; - bx += gbxinc; - by += gbyinc; - p += bpl; - } - } - else - { - for(;cnt>1;cnt--) - { - ch = gbuf[(bx>>16)*glogy+(by>>16)]; - if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; - bx += gbxinc; - by += gbyinc; - p += bpl; - } - } + gbuf = (char *)bufplc; + if (transmode) + { + for(;cnt>1;cnt--) + { + ch = gbuf[(bx>>16)*glogy+(by>>16)]; + if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)]; + bx += gbxinc; + by += gbyinc; + p += bpl; + } + } + else + { + for(;cnt>1;cnt--) + { + ch = gbuf[(bx>>16)*glogy+(by>>16)]; + if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]]; + bx += gbxinc; + by += gbyinc; + p += bpl; + } + } } void setupdrawslab (long dabpl, long pal) - { bpl = dabpl; gpal = (char *)pal; } +{ bpl = dabpl; gpal = (char *)pal; } void drawslab (long dx, long v, long dy, long vi, long vptr, long p) { - long x; - - while (dy > 0) - { - for(x=0;x>16)+vptr))]; - p += bpl; v += vi; dy--; - } + long x; + + while (dy > 0) + { + for(x=0;x>16)+vptr))]; + p += bpl; v += vi; dy--; + } } void stretchhline (long p0, long u, long cnt, long uinc, long rptr, long p) { - p0 = p-(cnt<<2); - do - { - p--; - *(char *)p = *(char *)((u>>16)+rptr); u -= uinc; - } while (p > p0); + p0 = p-(cnt<<2); + do + { + p--; + *(char *)p = *(char *)((u>>16)+rptr); u -= uinc; + } while (p > p0); } diff --git a/polymer/build/src/baselayer.c b/polymer/build/src/baselayer.c index 52d4a0480..98482c283 100644 --- a/polymer/build/src/baselayer.c +++ b/polymer/build/src/baselayer.c @@ -10,37 +10,37 @@ #ifdef USE_OPENGL struct glinfo glinfo = { - "Unknown", // vendor - "Unknown", // renderer - "0.0.0", // version - "", // extensions - - 1.0, // max anisotropy - 0, // brga texture format - 0, // clamp-to-edge support - 0, // texture compression - 0, // non-power-of-two textures - 0, // multisampling - 0, // nvidia multisampling hint -}; + "Unknown", // vendor + "Unknown", // renderer + "0.0.0", // version + "", // extensions + + 1.0, // max anisotropy + 0, // brga texture format + 0, // clamp-to-edge support + 0, // texture compression + 0, // non-power-of-two textures + 0, // multisampling + 0, // nvidia multisampling hint + }; #endif static int osdfunc_dumpbuildinfo(const osdfuncparm_t *parm) { - OSD_Printf( - "Build engine compilation:\n" - " CFLAGS: %s\n" - " LIBS: %s\n" - " Host: %s\n" - " Compiler: %s\n" - " Built: %s\n", - _engine_cflags, - _engine_libs, - _engine_uname, - _engine_compiler, - _engine_date); + OSD_Printf( + "Build engine compilation:\n" + " CFLAGS: %s\n" + " LIBS: %s\n" + " Host: %s\n" + " Compiler: %s\n" + " Built: %s\n", + _engine_cflags, + _engine_libs, + _engine_uname, + _engine_compiler, + _engine_date); - return OSDCMD_OK; + return OSDCMD_OK; } static void onvideomodechange(int newmode) { } @@ -48,159 +48,159 @@ void (*baselayer_onvideomodechange)(int) = onvideomodechange; static int osdfunc_setrendermode(const osdfuncparm_t *parm) { - int m; - char *p; + int m; + char *p; - char *modestrs[] = { - "classic software", "polygonal flat-shaded software", - "polygonal textured software", "polygonal OpenGL" - }; + char *modestrs[] = { + "classic software", "polygonal flat-shaded software", + "polygonal textured software", "polygonal OpenGL" + }; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; - m = Bstrtol(parm->parms[0], &p, 10); + if (parm->numparms != 1) return OSDCMD_SHOWHELP; + m = Bstrtol(parm->parms[0], &p, 10); - if (m < 0 || m > 3) return OSDCMD_SHOWHELP; + if (m < 0 || m > 3) return OSDCMD_SHOWHELP; - setrendermode(m); - OSD_Printf("Rendering method changed to %s\n", modestrs[ getrendermode() ] ); + setrendermode(m); + OSD_Printf("Rendering method changed to %s\n", modestrs[ getrendermode() ] ); - return OSDCMD_OK; + return OSDCMD_OK; } #if defined(POLYMOST) && defined(USE_OPENGL) #ifdef DEBUGGINGAIDS static int osdcmd_hicsetpalettetint(const osdfuncparm_t *parm) { - long pal, cols[3], eff; - char *p; - - if (parm->numparms != 5) return OSDCMD_SHOWHELP; - - pal = Batol(parm->parms[0]); - cols[0] = Batol(parm->parms[1]); - cols[1] = Batol(parm->parms[2]); - cols[2] = Batol(parm->parms[3]); - eff = Batol(parm->parms[4]); - - hicsetpalettetint(pal,cols[0],cols[1],cols[2],eff); - - return OSDCMD_OK; + long pal, cols[3], eff; + char *p; + + if (parm->numparms != 5) return OSDCMD_SHOWHELP; + + pal = Batol(parm->parms[0]); + cols[0] = Batol(parm->parms[1]); + cols[1] = Batol(parm->parms[2]); + cols[2] = Batol(parm->parms[3]); + eff = Batol(parm->parms[4]); + + hicsetpalettetint(pal,cols[0],cols[1],cols[2],eff); + + return OSDCMD_OK; } #endif static int osdcmd_glinfo(const osdfuncparm_t *parm) { - char *s,*t,*u,i; - - if (bpp == 8) { - OSD_Printf("glinfo: Not in OpenGL mode.\n"); - return OSDCMD_OK; - } - - OSD_Printf("OpenGL Information:\n" - " Version: %s\n" - " Vendor: %s\n" - " Renderer: %s\n" - " Maximum anisotropy: %.1f%s\n" - " BGRA textures: %s\n" - " Non-x^2 textures: %s\n" - " Texure compression: %s\n" - " Clamp-to-edge: %s\n" - " Multisampling: %s\n" - " Nvidia multisample hint: %s\n" - " Extensions:\n", - glinfo.version, - glinfo.vendor, - glinfo.renderer, - glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)", - glinfo.bgra ? "supported": "not supported", - glinfo.texnpot ? "supported": "not supported", - glinfo.texcompr ? "supported": "not supported", - glinfo.clamptoedge ? "supported": "not supported", - glinfo.multisample ? "supported": "not supported", - glinfo.nvmultisamplehint ? "supported": "not supported" - ); + char *s,*t,*u,i; - s = Bstrdup(glinfo.extensions); - if (!s) OSD_Printf(glinfo.extensions); - else { - i = 0; t = u = s; - while (*t) { - if (*t == ' ') { - if (i&1) { - *t = 0; - OSD_Printf(" %s\n",u); - u = t+1; - } - i++; - } - t++; - } - if (i&1) OSD_Printf(" %s\n",u); - Bfree(s); - } - - return OSDCMD_OK; + if (bpp == 8) { + OSD_Printf("glinfo: Not in OpenGL mode.\n"); + return OSDCMD_OK; + } + + OSD_Printf("OpenGL Information:\n" + " Version: %s\n" + " Vendor: %s\n" + " Renderer: %s\n" + " Maximum anisotropy: %.1f%s\n" + " BGRA textures: %s\n" + " Non-x^2 textures: %s\n" + " Texure compression: %s\n" + " Clamp-to-edge: %s\n" + " Multisampling: %s\n" + " Nvidia multisample hint: %s\n" + " Extensions:\n", + glinfo.version, + glinfo.vendor, + glinfo.renderer, + glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)", + glinfo.bgra ? "supported": "not supported", + glinfo.texnpot ? "supported": "not supported", + glinfo.texcompr ? "supported": "not supported", + glinfo.clamptoedge ? "supported": "not supported", + glinfo.multisample ? "supported": "not supported", + glinfo.nvmultisamplehint ? "supported": "not supported" + ); + + s = Bstrdup(glinfo.extensions); + if (!s) OSD_Printf(glinfo.extensions); + else { + i = 0; t = u = s; + while (*t) { + if (*t == ' ') { + if (i&1) { + *t = 0; + OSD_Printf(" %s\n",u); + u = t+1; + } + i++; + } + t++; + } + if (i&1) OSD_Printf(" %s\n",u); + Bfree(s); + } + + return OSDCMD_OK; } #endif static int osdcmd_vars(const osdfuncparm_t *parm) { - int showval = (parm->numparms < 1); - - if (!Bstrcasecmp(parm->name, "screencaptureformat")) { - const char *fmts[2][2] = { {"TGA", "PCX"}, {"0", "1"} }; - if (showval) { OSD_Printf("captureformat is %s\n", fmts[captureformat]); } - else { - int i,j; - for (j=0; j<2; j++) - for (i=0; i<2; i++) - if (!Bstrcasecmp(parm->parms[0], fmts[j][i])) break; - if (j == 2) return OSDCMD_SHOWHELP; - captureformat = i; - } - return OSDCMD_OK; - } + int showval = (parm->numparms < 1); + + if (!Bstrcasecmp(parm->name, "screencaptureformat")) { + const char *fmts[2][2] = { {"TGA", "PCX"}, {"0", "1"} }; + if (showval) { OSD_Printf("captureformat is %s\n", fmts[captureformat]); } + else { + int i,j; + for (j=0; j<2; j++) + for (i=0; i<2; i++) + if (!Bstrcasecmp(parm->parms[0], fmts[j][i])) break; + if (j == 2) return OSDCMD_SHOWHELP; + captureformat = i; + } + return OSDCMD_OK; + } #ifdef SUPERBUILD - else if (!Bstrcasecmp(parm->name, "novoxmips")) { - if (showval) { OSD_Printf("novoxmips is %d\n", novoxmips); } - else { novoxmips = (atoi(parm->parms[0]) != 0); } - } - else if (!Bstrcasecmp(parm->name, "usevoxels")) { - if (showval) { OSD_Printf("usevoxels is %d\n", usevoxels); } - else { usevoxels = (atoi(parm->parms[0]) != 0); } - } + else if (!Bstrcasecmp(parm->name, "novoxmips")) { + if (showval) { OSD_Printf("novoxmips is %d\n", novoxmips); } + else { novoxmips = (atoi(parm->parms[0]) != 0); } + } + else if (!Bstrcasecmp(parm->name, "usevoxels")) { + if (showval) { OSD_Printf("usevoxels is %d\n", usevoxels); } + else { usevoxels = (atoi(parm->parms[0]) != 0); } + } #endif - return OSDCMD_SHOWHELP; + return OSDCMD_SHOWHELP; } int baselayer_init(void) { #ifdef POLYMOST - OSD_RegisterFunction("setrendermode","setrendermode : sets the engine's rendering mode.\n" - "Mode numbers are:\n" - " 0 - Classic Build software\n" - " 1 - Polygonal flat-shaded software\n" - " 2 - Polygonal textured software\n" + OSD_RegisterFunction("setrendermode","setrendermode : sets the engine's rendering mode.\n" + "Mode numbers are:\n" + " 0 - Classic Build software\n" + " 1 - Polygonal flat-shaded software\n" + " 2 - Polygonal textured software\n" #ifdef USE_OPENGL - " 3 - Polygonal OpenGL\n" + " 3 - Polygonal OpenGL\n" #endif - , - osdfunc_setrendermode); + , + osdfunc_setrendermode); #endif - OSD_RegisterFunction("dumpbuildinfo","dumpbuildinfo: outputs engine compilation information",osdfunc_dumpbuildinfo); - OSD_RegisterFunction("screencaptureformat","screencaptureformat: sets the output format for screenshots (TGA or PCX)",osdcmd_vars); + OSD_RegisterFunction("dumpbuildinfo","dumpbuildinfo: outputs engine compilation information",osdfunc_dumpbuildinfo); + OSD_RegisterFunction("screencaptureformat","screencaptureformat: sets the output format for screenshots (TGA or PCX)",osdcmd_vars); #ifdef SUPERBUILD - OSD_RegisterFunction("novoxmips","novoxmips: turn off/on the use of mipmaps when rendering 8-bit voxels",osdcmd_vars); - OSD_RegisterFunction("usevoxels","usevoxels: enable/disable automatic sprite->voxel rendering",osdcmd_vars); + OSD_RegisterFunction("novoxmips","novoxmips: turn off/on the use of mipmaps when rendering 8-bit voxels",osdcmd_vars); + OSD_RegisterFunction("usevoxels","usevoxels: enable/disable automatic sprite->voxel rendering",osdcmd_vars); #endif #if defined(POLYMOST) && defined(USE_OPENGL) #ifdef DEBUGGINGAIDS - OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint); + OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint); #endif - OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo); + OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo); #endif - - return 0; + + return 0; } diff --git a/polymer/build/src/bstub.c b/polymer/build/src/bstub.c index 566be10a4..b26e5d391 100644 --- a/polymer/build/src/bstub.c +++ b/polymer/build/src/bstub.c @@ -21,11 +21,11 @@ static char tempbuf[256]; #define NUMOPTIONS 9 char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0,0}; char keys[NUMBUILDKEYS] = -{ - 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, - 0x1e,0x2c,0xd1,0xc9,0x33,0x34, - 0x9c,0x1c,0xd,0xc,0xf,0x45 -}; + { + 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, + 0x1e,0x2c,0xd1,0xc9,0x33,0x34, + 0x9c,0x1c,0xd,0xc,0xf,0x45 + }; @@ -67,145 +67,145 @@ int ExtPreInit(int *argc,char ***argv) int ExtInit(void) { - long i, rv = 0; + long i, rv = 0; - /*printf("------------------------------------------------------------------------------\n"); - printf(" BUILD.EXE copyright(c) 1996 by Ken Silverman. You are granted the\n"); - printf(" right to use this software for your personal use only. This is a\n"); - printf(" special version to be used with \"Happy Fun KenBuild\" and may not work\n"); - printf(" properly with other Build engine games. Please refer to license.doc\n"); - printf(" for distribution rights\n"); - printf("------------------------------------------------------------------------------\n"); - getch(); - */ + /*printf("------------------------------------------------------------------------------\n"); + printf(" BUILD.EXE copyright(c) 1996 by Ken Silverman. You are granted the\n"); + printf(" right to use this software for your personal use only. This is a\n"); + printf(" special version to be used with \"Happy Fun KenBuild\" and may not work\n"); + printf(" properly with other Build engine games. Please refer to license.doc\n"); + printf(" for distribution rights\n"); + printf("------------------------------------------------------------------------------\n"); + getch(); + */ - initgroupfile("stuff.dat"); - bpp = 8; - if (loadsetup("build.cfg") < 0) initprintf("Configuration file not found, using defaults.\n"), rv = 1; - Bmemcpy((void *)buildkeys,(void *)keys,NUMBUILDKEYS); //Trick to make build use setup.dat keys - if (option[4] > 0) option[4] = 0; - if (initengine()) { - wm_msgbox("Build Engine Initialisation Error", - "There was a problem initialising the Build engine: %s", engineerrstr); - return -1; - } - initinput(); - initmouse(); + initgroupfile("stuff.dat"); + bpp = 8; + if (loadsetup("build.cfg") < 0) initprintf("Configuration file not found, using defaults.\n"), rv = 1; + Bmemcpy((void *)buildkeys,(void *)keys,NUMBUILDKEYS); //Trick to make build use setup.dat keys + if (option[4] > 0) option[4] = 0; + if (initengine()) { + wm_msgbox("Build Engine Initialisation Error", + "There was a problem initialising the Build engine: %s", engineerrstr); + return -1; + } + initinput(); + initmouse(); - //You can load your own palette lookup tables here if you just - //copy the right code! - for(i=0;i<256;i++) - tempbuf[i] = ((i+32)&255); //remap colors for screwy palette sectors - makepalookup(16,tempbuf,0,0,0,1); + //You can load your own palette lookup tables here if you just + //copy the right code! + for(i=0;i<256;i++) + tempbuf[i] = ((i+32)&255); //remap colors for screwy palette sectors + makepalookup(16,tempbuf,0,0,0,1); - kensplayerheight = 32; - zmode = 0; - defaultspritecstat = 0; - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + kensplayerheight = 32; + zmode = 0; + defaultspritecstat = 0; + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; #ifdef SUPERBUILD - tiletovox[PLAYER] = nextvoxid++; - tiletovox[BROWNMONSTER] = nextvoxid++; + tiletovox[PLAYER] = nextvoxid++; + tiletovox[BROWNMONSTER] = nextvoxid++; #endif - + #ifdef _WIN32 -// allowtaskswitching(0); + // allowtaskswitching(0); #endif - return rv; + return rv; } void ExtUnInit(void) { - uninitgroupfile(); - writesetup("build.cfg"); + uninitgroupfile(); + writesetup("build.cfg"); } void ExtSetupSpecialSpriteCols(void) { - return; + return; } //static long daviewingrange, daaspect, horizval1, horizval2; void ExtPreCheckKeys(void) { - long /*cosang, sinang, dx, dy, mindx,*/ i, j, k; + long /*cosang, sinang, dx, dy, mindx,*/ i, j, k; - if (keystatus[0x3e]) //F4 - screen re-size - { - keystatus[0x3e] = 0; + if (keystatus[0x3e]) //F4 - screen re-size + { + keystatus[0x3e] = 0; - //cycle through all vesa modes, then screen-buffer mode - if (keystatus[0x2a]|keystatus[0x36]) { - setgamemode(!fullscreen, xdim, ydim, bpp); - } else { + //cycle through all vesa modes, then screen-buffer mode + if (keystatus[0x2a]|keystatus[0x36]) { + setgamemode(!fullscreen, xdim, ydim, bpp); + } else { - //cycle through all modes - j=-1; + //cycle through all modes + j=-1; - // work out a mask to select the mode - for (i=0; i> 3) + (xdim >> 4) + (xdim >> 6)) & (~7); - dy = (ydim + (ydim >> 3) + (ydim >> 4) + (ydim >> 6)) & (~7); - i = scale(320,ydim,xdim); - - if (waloff[4094] == 0) allocache(&waloff[4094],/*240L*384L*/dx*dy,&walock[4094]); - setviewtotile(4094,/*240L,384L*/dy,dx); + // JBF 20031117: scale each dimension by a factor of 1.2, and work out + // the aspect of the screen. Anywhere you see 'i' below was the value + // '200' before I changed it. NOTE: This whole trick crashes in resolutions + // above 800x600. I'm not sure why, and fixing it is not something I intend + // to do in a real big hurry. + dx = (xdim + (xdim >> 3) + (xdim >> 4) + (xdim >> 6)) & (~7); + dy = (ydim + (ydim >> 3) + (ydim >> 4) + (ydim >> 6)) & (~7); + i = scale(320,ydim,xdim); - cosang = sintable[(hang+512)&2047]; - sinang = sintable[hang&2047]; + if (waloff[4094] == 0) allocache(&waloff[4094],/*240L*384L*/dx*dy,&walock[4094]); + setviewtotile(4094,/*240L,384L*/dy,dx); - dx = dmulscale1(320,cosang,i,sinang); mindx = dx; - dy = dmulscale1(-i,cosang,320,sinang); - horizval1 = dy*(320>>1)/dx-1; + cosang = sintable[(hang+512)&2047]; + sinang = sintable[hang&2047]; - dx = dmulscale1(320,cosang,-i,sinang); mindx = min(dx,mindx); - dy = dmulscale1(i,cosang,320,sinang); - horizval2 = dy*(320>>1)/dx+1; + dx = dmulscale1(320,cosang,i,sinang); mindx = dx; + dy = dmulscale1(-i,cosang,320,sinang); + horizval1 = dy*(320>>1)/dx-1; - daviewingrange = scale(65536,16384*(xdim>>1),mindx-16); - daaspect = scale(daviewingrange,scale(320,tilesizx[4094],tilesizy[4094]),horizval2+6-horizval1); - setaspect(daviewingrange,scale(daaspect,ydim*320,xdim*i)); - horiz = 100-divscale15(horizval1+horizval2,daviewingrange); - } + dx = dmulscale1(320,cosang,-i,sinang); mindx = min(dx,mindx); + dy = dmulscale1(i,cosang,320,sinang); + horizval2 = dy*(320>>1)/dx+1; + + daviewingrange = scale(65536,16384*(xdim>>1),mindx-16); + daaspect = scale(daviewingrange,scale(320,tilesizx[4094],tilesizy[4094]),horizval2+6-horizval1); + setaspect(daviewingrange,scale(daaspect,ydim*320,xdim*i)); + horiz = 100-divscale15(horizval1+horizval2,daviewingrange); + } #endif } @@ -214,109 +214,109 @@ void ExtPreCheckKeys(void) extern char *voxoff[][MAXVOXMIPS]; void ExtAnalyzeSprites(void) { - long i, *longptr; - spritetype *tspr; + long i, *longptr; + spritetype *tspr; - for(i=0,tspr=&tsprite[0];ipicnum] >= 0) - { - switch(tspr->picnum) - { - case PLAYER: - if (!voxoff[ tiletovox[PLAYER] ][0]) { - if (qloadkvx(tiletovox[PLAYER],"voxel000.kvx")) { - tiletovox[PLAYER] = -1; - break; - } - } - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - longptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; - tspr->xrepeat = scale(tspr->xrepeat,56,longptr[2]); - tspr->yrepeat = scale(tspr->yrepeat,56,longptr[2]); - tspr->shade -= 6; - break; - case BROWNMONSTER: - if (!voxoff[ tiletovox[BROWNMONSTER] ][0]) { - if (qloadkvx(tiletovox[BROWNMONSTER],"voxel001.kvx")) { - tiletovox[BROWNMONSTER] = -1; - break; - } - } - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - break; - } - } + for(i=0,tspr=&tsprite[0];ipicnum] >= 0) + { + switch(tspr->picnum) + { + case PLAYER: + if (!voxoff[ tiletovox[PLAYER] ][0]) { + if (qloadkvx(tiletovox[PLAYER],"voxel000.kvx")) { + tiletovox[PLAYER] = -1; + break; + } + } + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + longptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; + tspr->xrepeat = scale(tspr->xrepeat,56,longptr[2]); + tspr->yrepeat = scale(tspr->yrepeat,56,longptr[2]); + tspr->shade -= 6; + break; + case BROWNMONSTER: + if (!voxoff[ tiletovox[BROWNMONSTER] ][0]) { + if (qloadkvx(tiletovox[BROWNMONSTER],"voxel001.kvx")) { + tiletovox[BROWNMONSTER] = -1; + break; + } + } + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + break; + } + } - tspr->shade += 6; - if (sector[tspr->sectnum].ceilingstat&1) - tspr->shade += sector[tspr->sectnum].ceilingshade; - else - tspr->shade += sector[tspr->sectnum].floorshade; - } + tspr->shade += 6; + if (sector[tspr->sectnum].ceilingstat&1) + tspr->shade += sector[tspr->sectnum].ceilingshade; + else + tspr->shade += sector[tspr->sectnum].floorshade; + } } #endif void ExtCheckKeys(void) { - long i;//, p, y, dx, dy, cosang, sinang, bufplc, tsizy, tsizyup15; - long j; + long i;//, p, y, dx, dy, cosang, sinang, bufplc, tsizy, tsizyup15; + long j; - if (qsetmode == 200) //In 3D mode - { + if (qsetmode == 200) //In 3D mode + { #if 0 - if (hang != 0) - { - bufplc = waloff[4094]+(mulscale16(horiz-100,xdimenscale)+(tilesizx[4094]>>1))*tilesizy[4094]; - setviewback(); - cosang = sintable[(hang+512)&2047]; - sinang = sintable[hang&2047]; - dx = dmulscale1(xdim,cosang,ydim,sinang); - dy = dmulscale1(-ydim,cosang,xdim,sinang); + if (hang != 0) + { + bufplc = waloff[4094]+(mulscale16(horiz-100,xdimenscale)+(tilesizx[4094]>>1))*tilesizy[4094]; + setviewback(); + cosang = sintable[(hang+512)&2047]; + sinang = sintable[hang&2047]; + dx = dmulscale1(xdim,cosang,ydim,sinang); + dy = dmulscale1(-ydim,cosang,xdim,sinang); - begindrawing(); - tsizy = tilesizy[4094]; - tsizyup15 = (tsizy<<15); - dx = mulscale14(dx,daviewingrange); - dy = mulscale14(dy,daaspect); - sinang = mulscale14(sinang,daviewingrange); - cosang = mulscale14(cosang,daaspect); - p = ylookup[windowy1]+frameplace+windowx2+1; - for(y=windowy1;y<=windowy2;y++) - { - i = divscale16(tsizyup15,dx); - stretchhline(0,(xdim>>1)*i+tsizyup15,xdim>>2,i,mulscale32(i,dy)*tsizy+bufplc,p); - dx -= sinang; dy += cosang; p += ylookup[1]; - } - walock[4094] = 1; + begindrawing(); + tsizy = tilesizy[4094]; + tsizyup15 = (tsizy<<15); + dx = mulscale14(dx,daviewingrange); + dy = mulscale14(dy,daaspect); + sinang = mulscale14(sinang,daviewingrange); + cosang = mulscale14(cosang,daaspect); + p = ylookup[windowy1]+frameplace+windowx2+1; + for(y=windowy1;y<=windowy2;y++) + { + i = divscale16(tsizyup15,dx); + stretchhline(0,(xdim>>1)*i+tsizyup15,xdim>>2,i,mulscale32(i,dy)*tsizy+bufplc,p); + dx -= sinang; dy += cosang; p += ylookup[1]; + } + walock[4094] = 1; - Bsprintf(tempbuf,"%d",(hang*180)>>10); - printext256(0L,8L,31,-1,tempbuf,1); - enddrawing(); - } + Bsprintf(tempbuf,"%d",(hang*180)>>10); + printext256(0L,8L,31,-1,tempbuf,1); + enddrawing(); + } #endif - if (keystatus[0xa]) setaspect(viewingrange+(viewingrange>>8),yxaspect+(yxaspect>>8)); - if (keystatus[0xb]) setaspect(viewingrange-(viewingrange>>8),yxaspect-(yxaspect>>8)); - if (keystatus[0xc]) setaspect(viewingrange,yxaspect-(yxaspect>>8)); - if (keystatus[0xd]) setaspect(viewingrange,yxaspect+(yxaspect>>8)); - //if (keystatus[0x38]) setrollangle(rollangle+=((keystatus[0x2a]|keystatus[0x36])*6+2)); - //if (keystatus[0xb8]) setrollangle(rollangle-=((keystatus[0x2a]|keystatus[0x36])*6+2)); - //if (keystatus[0x1d]|keystatus[0x9d]) setrollangle(rollangle=0); + if (keystatus[0xa]) setaspect(viewingrange+(viewingrange>>8),yxaspect+(yxaspect>>8)); + if (keystatus[0xb]) setaspect(viewingrange-(viewingrange>>8),yxaspect-(yxaspect>>8)); + if (keystatus[0xc]) setaspect(viewingrange,yxaspect-(yxaspect>>8)); + if (keystatus[0xd]) setaspect(viewingrange,yxaspect+(yxaspect>>8)); + //if (keystatus[0x38]) setrollangle(rollangle+=((keystatus[0x2a]|keystatus[0x36])*6+2)); + //if (keystatus[0xb8]) setrollangle(rollangle-=((keystatus[0x2a]|keystatus[0x36])*6+2)); + //if (keystatus[0x1d]|keystatus[0x9d]) setrollangle(rollangle=0); - begindrawing(); - - i = frameval[framecnt&(AVERAGEFRAMES-1)]; - j = frameval[framecnt&(AVERAGEFRAMES-1)] = getticks(); framecnt++; - if (i != j) averagefps = ((mul3(averagefps)+((AVERAGEFRAMES*1000)/(j-i)) )>>2); - Bsprintf(tempbuf,"%ld",averagefps); - printext256(0L,0L,31,-1,tempbuf,1); - - enddrawing(); - editinput(); - } - else - { - } + begindrawing(); + + i = frameval[framecnt&(AVERAGEFRAMES-1)]; + j = frameval[framecnt&(AVERAGEFRAMES-1)] = getticks(); framecnt++; + if (i != j) averagefps = ((mul3(averagefps)+((AVERAGEFRAMES*1000)/(j-i)) )>>2); + Bsprintf(tempbuf,"%ld",averagefps); + printext256(0L,0L,31,-1,tempbuf,1); + + enddrawing(); + editinput(); + } + else + { + } } void ExtCleanUp(void) @@ -329,9 +329,9 @@ void ExtPreLoadMap(void) void ExtLoadMap(const char *mapname) { - char title[256]; - Bsprintf(title, "BUILD by Ken Silverman - %s", mapname); - wm_setapptitle(title); + char title[256]; + Bsprintf(title, "BUILD by Ken Silverman - %s", mapname); + wm_setapptitle(title); } void ExtPreSaveMap(void) @@ -344,44 +344,44 @@ void ExtSaveMap(const char *mapname) const char *ExtGetSectorCaption(short sectnum) { - if ((sector[sectnum].lotag|sector[sectnum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sector[sectnum].hitag, - (unsigned short)sector[sectnum].lotag); - } - return(tempbuf); + if ((sector[sectnum].lotag|sector[sectnum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sector[sectnum].hitag, + (unsigned short)sector[sectnum].lotag); + } + return(tempbuf); } const char *ExtGetWallCaption(short wallnum) { - if ((wall[wallnum].lotag|wall[wallnum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)wall[wallnum].hitag, - (unsigned short)wall[wallnum].lotag); - } - return(tempbuf); + if ((wall[wallnum].lotag|wall[wallnum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)wall[wallnum].hitag, + (unsigned short)wall[wallnum].lotag); + } + return(tempbuf); } const char *ExtGetSpriteCaption(short spritenum) { - if ((sprite[spritenum].lotag|sprite[spritenum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sprite[spritenum].hitag, - (unsigned short)sprite[spritenum].lotag); - } - return(tempbuf); + if ((sprite[spritenum].lotag|sprite[spritenum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sprite[spritenum].hitag, + (unsigned short)sprite[spritenum].lotag); + } + return(tempbuf); } //printext16 parameters: @@ -402,132 +402,132 @@ const char *ExtGetSpriteCaption(short spritenum) void ExtShowSectorData(short sectnum) //F5 { - int i; - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar + int i; + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar - Bsprintf(tempbuf,"Sector %d",sectnum); - printext16(8,ydim16+32,11,-1,tempbuf,0); + Bsprintf(tempbuf,"Sector %d",sectnum); + printext16(8,ydim16+32,11,-1,tempbuf,0); - printext16(8,ydim16+48,11,-1,"8*8 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",0); - printext16(8,ydim16+56,11,-1,"3*5 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",1); + printext16(8,ydim16+48,11,-1,"8*8 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",0); + printext16(8,ydim16+56,11,-1,"3*5 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",1); - i=ydim16; ydim16=ydim; - drawline16(320,i+68,344,i+80,4); //Draw house - drawline16(344,i+80,344,i+116,4); - drawline16(344,i+116,296,i+116,4); - drawline16(296,i+116,296,i+80,4); - drawline16(296,i+80,320,i+68,4); - ydim16=i; - enddrawing(); - } + i=ydim16; ydim16=ydim; + drawline16(320,i+68,344,i+80,4); //Draw house + drawline16(344,i+80,344,i+116,4); + drawline16(344,i+116,296,i+116,4); + drawline16(296,i+116,296,i+80,4); + drawline16(296,i+80,320,i+68,4); + ydim16=i; + enddrawing(); + } } void ExtShowWallData(short wallnum) //F6 { - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar - Bsprintf(tempbuf,"Wall %d",wallnum); - printext16(8,ydim16+32,11,-1,tempbuf,0); - enddrawing(); - } + Bsprintf(tempbuf,"Wall %d",wallnum); + printext16(8,ydim16+32,11,-1,tempbuf,0); + enddrawing(); + } } void ExtShowSpriteData(short spritenum) //F6 { - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar - Bsprintf(tempbuf,"Sprite %d",spritenum); - printext16(8,ydim16+32,11,-1,tempbuf,0); - enddrawing(); - } + Bsprintf(tempbuf,"Sprite %d",spritenum); + printext16(8,ydim16+32,11,-1,tempbuf,0); + enddrawing(); + } } void ExtEditSectorData(short sectnum) //F7 { - short nickdata; + short nickdata; - if (qsetmode == 200) //In 3D mode - { - //Ceiling - if (searchstat == 1) - sector[searchsector].ceilingpicnum++; //Just a stupid example + if (qsetmode == 200) //In 3D mode + { + //Ceiling + if (searchstat == 1) + sector[searchsector].ceilingpicnum++; //Just a stupid example - //Floor - if (searchstat == 2) - sector[searchsector].floorshade++; //Just a stupid example - } - else //In 2D mode - { - Bsprintf(tempbuf,"Sector (%d) Nick's variable: ",sectnum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); + //Floor + if (searchstat == 2) + sector[searchsector].floorshade++; //Just a stupid example + } + else //In 2D mode + { + Bsprintf(tempbuf,"Sector (%d) Nick's variable: ",sectnum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); - printmessage16(""); //Clear message box (top right of status bar) - ExtShowSectorData(sectnum); - } + printmessage16(""); //Clear message box (top right of status bar) + ExtShowSectorData(sectnum); + } } void ExtEditWallData(short wallnum) //F8 { - short nickdata; + short nickdata; - if (qsetmode == 200) //In 3D mode - { - } - else - { - Bsprintf(tempbuf,"Wall (%d) Nick's variable: ",wallnum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); + if (qsetmode == 200) //In 3D mode + { + } + else + { + Bsprintf(tempbuf,"Wall (%d) Nick's variable: ",wallnum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); - printmessage16(""); //Clear message box (top right of status bar) - ExtShowWallData(wallnum); - } + printmessage16(""); //Clear message box (top right of status bar) + ExtShowWallData(wallnum); + } } void ExtEditSpriteData(short spritenum) //F8 { - short nickdata; + short nickdata; - if (qsetmode == 200) //In 3D mode - { - } - else - { - Bsprintf(tempbuf,"Sprite (%d) Nick's variable: ",spritenum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); - printmessage16(""); + if (qsetmode == 200) //In 3D mode + { + } + else + { + Bsprintf(tempbuf,"Sprite (%d) Nick's variable: ",spritenum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); + printmessage16(""); - printmessage16(""); //Clear message box (top right of status bar) - ExtShowSpriteData(spritenum); - } + printmessage16(""); //Clear message box (top right of status bar) + ExtShowSpriteData(spritenum); + } } void faketimerhandler(void) { - sampletimer(); + sampletimer(); } - //Just thought you might want my getnumber16 code +//Just thought you might want my getnumber16 code /* getnumber16(char namestart[80], short num, long maxnumber) { diff --git a/polymer/build/src/build.c b/polymer/build/src/build.c index 97ca4f7cf..978688c50 100644 --- a/polymer/build/src/build.c +++ b/polymer/build/src/build.c @@ -57,11 +57,11 @@ void _printmessage16(char name[82]); long vel, svel, angvel; char buildkeys[NUMBUILDKEYS] = -{ - 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, - 0x1e,0x2c,0xd1,0xc9,0x33,0x34, - 0x9c,0x1c,0xd,0xc,0xf,0x45 -}; + { + 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, + 0x1e,0x2c,0xd1,0xc9,0x33,0x34, + 0x9c,0x1c,0xd,0xc,0xf,0x45 + }; long posx, posy, posz, horiz = 100; long mousexsurp = 0, mouseysurp = 0; @@ -135,27 +135,27 @@ static long fillist[640]; long mousx, mousy; static char scantoasc[128] = -{ - 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, - 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', - 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', - 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, - 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', - '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; + { + 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, + 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', + 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', + 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, + 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', + '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + }; static char scantoascwithshift[128] = -{ - 0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0, - 'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S', - 'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V', - 'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0, - 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', - '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; + { + 0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0, + 'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S', + 'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V', + 'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0, + 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', + '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + }; @@ -198,43 +198,43 @@ void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); } static int osdcmd_restartvid(const osdfuncparm_t *parm) { - extern long qsetmode; - - if (qsetmode != 200) return OSDCMD_OK; + extern long qsetmode; - resetvideomode(); - if (setgamemode(fullscreen,xdim,ydim,bpp)) - OSD_Printf("restartvid: Reset failed...\n"); + if (qsetmode != 200) return OSDCMD_OK; - return OSDCMD_OK; + resetvideomode(); + if (setgamemode(fullscreen,xdim,ydim,bpp)) + OSD_Printf("restartvid: Reset failed...\n"); + + return OSDCMD_OK; } static int osdcmd_vidmode(const osdfuncparm_t *parm) { - long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; - extern long qsetmode; + long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; + extern long qsetmode; - if (qsetmode != 200) return OSDCMD_OK; + if (qsetmode != 200) return OSDCMD_OK; - switch (parm->numparms) { - case 1: // bpp switch - newbpp = Batol(parm->parms[0]); - break; - case 4: // fs, res, bpp switch - newfullscreen = (Batol(parm->parms[3]) != 0); - case 3: // res & bpp switch - newbpp = Batol(parm->parms[2]); - case 2: // res switch - newx = Batol(parm->parms[0]); - newy = Batol(parm->parms[1]); - break; - default: return OSDCMD_SHOWHELP; - } + switch (parm->numparms) { + case 1: // bpp switch + newbpp = Batol(parm->parms[0]); + break; + case 4: // fs, res, bpp switch + newfullscreen = (Batol(parm->parms[3]) != 0); + case 3: // res & bpp switch + newbpp = Batol(parm->parms[2]); + case 2: // res switch + newx = Batol(parm->parms[0]); + newy = Batol(parm->parms[1]); + break; + default: return OSDCMD_SHOWHELP; + } - if (setgamemode(newfullscreen,newx,newy,newbpp)) - OSD_Printf("vidmode: Mode change failed!\n"); - xdimgame = newx; ydimgame = newy; bppgame = newbpp; fullscreen = newfullscreen; - return OSDCMD_OK; + if (setgamemode(newfullscreen,newx,newy,newbpp)) + OSD_Printf("vidmode: Mode change failed!\n"); + xdimgame = newx; ydimgame = newy; bppgame = newbpp; fullscreen = newfullscreen; + return OSDCMD_OK; } #ifdef RENDERTYPEWIN @@ -244,288 +244,288 @@ int DoLaunchWindow(int initval); // buildstartwin.c extern char *defsfilename; // set in bstub.c int app_main(int argc, char **argv) { - char ch, quitflag, forcesetup = 0, grpstoadd = 0; - char **grps = NULL; - long i, j, k; - - pathsearchmode = 1; // unrestrict findfrompath so that full access to the filesystem can be had + char ch, quitflag, forcesetup = 0, grpstoadd = 0; + char **grps = NULL; + long i, j, k; + + pathsearchmode = 1; // unrestrict findfrompath so that full access to the filesystem can be had #ifdef USE_OPENGL - OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); - OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); + OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); + OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); #endif - + wm_setapptitle("Mapster32"); if ((i = ExtPreInit(&argc,&argv)) < 0) return -1; #ifdef RENDERTYPEWIN - backgroundidle = 1; + backgroundidle = 1; #endif - editstatus = 1; - boardfilename[0] = 0; - for (i=1; i 0) { - for (i=0;i 0) { + for (i=0;i k) { k = j; whitecol = i; } - } + if (setgamemode(fullscreen,xdimgame,ydimgame,bppgame) < 0) + { + ExtUnInit(); + uninitengine(); + Bprintf("%ld * %ld not supported in this graphics mode\n",xdim,ydim); + exit(0); + } + setbrightness(brightness,palette,0); - for(i=0;i k) { k = j; whitecol = i; } + } - ExtPreLoadMap(); - i = loadboard(boardfilename,(!pathsearchmode&&grponlymode?2:0),&posx,&posy,&posz,&ang,&cursectnum); - if (i == -2) i = loadoldboard(boardfilename,(!pathsearchmode&&grponlymode?2:0),&posx,&posy,&posz,&ang,&cursectnum); - if (i < 0) - { - initspritelists(); - posx = 32768; - posy = 32768; - posz = 0; - ang = 1536; - numsectors = 0; - numwalls = 0; - cursectnum = -1; - overheadeditor(); - keystatus[buildkeys[14]] = 0; - } - else - { - ExtLoadMap(boardfilename); - } + for(i=0;i 0) - { - keystatus[1] = 0; - begindrawing(); //{{{ + if (keystatus[1] > 0) + { + keystatus[1] = 0; + begindrawing(); //{{{ printext256(0,0,whitecol,0,"Are you sure you want to quit?",0); - enddrawing(); //}}} + enddrawing(); //}}} - showframe(1); - synctics = totalclock-lockclock; - lockclock += synctics; + showframe(1); + synctics = totalclock-lockclock; + lockclock += synctics; - while ((keystatus[1]|keystatus[0x1c]|keystatus[0x39]|keystatus[0x31]) == 0) - { - if (handleevents()) { - if (quitevent) { - quitflag = 1; - break; - } - } + while ((keystatus[1]|keystatus[0x1c]|keystatus[0x39]|keystatus[0x31]) == 0) + { + if (handleevents()) { + if (quitevent) { + quitflag = 1; + break; + } + } - if (keystatus[0x15] != 0) { - keystatus[0x15] = 0; - quitflag = 1; break; - } - } + if (keystatus[0x15] != 0) { + keystatus[0x15] = 0; + quitflag = 1; break; + } + } while(keystatus[1]) { keystatus[1] = 0; quitevent = 0; goto CANCEL; } - } - } + } + } - if (asksave) - { - begindrawing(); //{{{ - printext256(0,8,whitecol,0,"Save changes?",0); - showframe(1); //}}} + if (asksave) + { + begindrawing(); //{{{ + printext256(0,8,whitecol,0,"Save changes?",0); + showframe(1); //}}} while ((keystatus[1]|keystatus[0x1c]|keystatus[0x39]|keystatus[0x31]|keystatus[0x2e]) == 0) - { - if (handleevents()) if (quitevent) break; // like saying no + { + if (handleevents()) if (quitevent) break; // like saying no - if (keystatus[0x15] != 0) { - keystatus[0x15] = 0; + if (keystatus[0x15] != 0) { + keystatus[0x15] = 0; - updatesector(startposx,startposy,&startsectnum); - ExtPreSaveMap(); - saveboard(boardfilename,&startposx,&startposy,&startposz,&startang,&startsectnum); - ExtSaveMap(boardfilename); - break; - } - } + updatesector(startposx,startposy,&startsectnum); + ExtPreSaveMap(); + saveboard(boardfilename,&startposx,&startposy,&startposz,&startang,&startsectnum); + ExtSaveMap(boardfilename); + break; + } + } while(keystatus[1]||keystatus[0x2e]) { keystatus[1] = 0; keystatus[0x2e] = 0; quitevent = 0; goto CANCEL; - } + } } - clearfilenames(); - ExtUnInit(); - uninitengine(); + clearfilenames(); + ExtUnInit(); + uninitengine(); - Bprintf("Memory status: %ld(%ld) bytes\n",cachesize,artsize); - Bprintf("%s\n",kensig); - return(0); + Bprintf("Memory status: %ld(%ld) bytes\n",cachesize,artsize); + Bprintf("%s\n",kensig); + return(0); } void showmouse(void) { int i; - for(i=1;i<=4;i++) - { - plotpixel(searchx+i,searchy,whitecol); - plotpixel(searchx-i,searchy,whitecol); - plotpixel(searchx,searchy-i,whitecol); - plotpixel(searchx,searchy+i,whitecol); - } + for(i=1;i<=4;i++) + { + plotpixel(searchx+i,searchy,whitecol); + plotpixel(searchx-i,searchy,whitecol); + plotpixel(searchx,searchy-i,whitecol); + plotpixel(searchx,searchy+i,whitecol); + } } void editinput(void) { - char smooshyalign, repeatpanalign, *ptr, buffer[80]; - short sectnum, nextsectnum, startwall, endwall, dasector, daang; + char smooshyalign, repeatpanalign, *ptr, buffer[80]; + short sectnum, nextsectnum, startwall, endwall, dasector, daang; long mousz, bstatus; - long i, j, k, cnt, templong=0, doubvel, changedir, wallfind[2], daz[2]; - long dashade[2], goalz, xvect, yvect, hiz, loz; - short hitsect, hitwall, hitsprite; - long hitx, hity, hitz, dax, day, hihit, lohit; + long i, j, k, cnt, templong=0, doubvel, changedir, wallfind[2], daz[2]; + long dashade[2], goalz, xvect, yvect, hiz, loz; + short hitsect, hitwall, hitsprite; + long hitx, hity, hitz, dax, day, hihit, lohit; - if (keystatus[0x57] > 0) //F11 - brightness - { - keystatus[0x57] = 0; - brightness++; - if (brightness >= 16) brightness = 0; - setbrightness(brightness,palette,0); - } - if (keystatus[88] > 0) //F12 - { - screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); - keystatus[88] = 0; - } + if (keystatus[0x57] > 0) //F11 - brightness + { + keystatus[0x57] = 0; + brightness++; + if (brightness >= 16) brightness = 0; + setbrightness(brightness,palette,0); + } + if (keystatus[88] > 0) //F12 + { + screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); + keystatus[88] = 0; + } - mousz = 0; - getmousevalues(&mousx,&mousy,&bstatus); - mousx = (mousx<<16)+mousexsurp; - mousy = (mousy<<16)+mouseysurp; - { - ldiv_t ld; - ld = ldiv((long)((double)mousx*msens), (1<<16)); mousx = ld.quot; mousexsurp = ld.rem; - ld = ldiv((long)((double)mousy*msens), (1<<16)); mousy = ld.quot; mouseysurp = ld.rem; - } + mousz = 0; + getmousevalues(&mousx,&mousy,&bstatus); + mousx = (mousx<<16)+mousexsurp; + mousy = (mousy<<16)+mouseysurp; + { + ldiv_t ld; + ld = ldiv((long)((double)mousx*msens), (1<<16)); mousx = ld.quot; mousexsurp = ld.rem; + ld = ldiv((long)((double)mousy*msens), (1<<16)); mousy = ld.quot; mouseysurp = ld.rem; + } if (mlook == 1) { @@ -552,2430 +552,2430 @@ void editinput(void) if (searchy > ydim-5) searchy = ydim-5; } - showmouse(); + showmouse(); - if (keystatus[0x3b] > 0) posx--; - if (keystatus[0x3c] > 0) posx++; - if (keystatus[0x3d] > 0) posy--; - if (keystatus[0x3e] > 0) posy++; - if (keystatus[0x43] > 0) ang--; - if (keystatus[0x44] > 0) ang++; + if (keystatus[0x3b] > 0) posx--; + if (keystatus[0x3c] > 0) posx++; + if (keystatus[0x3d] > 0) posy--; + if (keystatus[0x3e] > 0) posy++; + if (keystatus[0x43] > 0) ang--; + if (keystatus[0x44] > 0) ang++; - if (angvel != 0) //ang += angvel * constant - { //ENGINE calculates angvel for you - doubvel = synctics; - if (keystatus[buildkeys[4]] > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (synctics>>1); - ang += ((angvel*doubvel)>>4); - ang = (ang+2048)&2047; - } - if ((vel|svel) != 0) - { - doubvel = synctics; - if (keystatus[buildkeys[4]] > 0) //Lt. shift doubles forward velocity - doubvel += synctics; - xvect = 0, yvect = 0; - if (vel != 0) - { - xvect += ((vel*doubvel*(long)sintable[(ang+2560)&2047])>>3); - yvect += ((vel*doubvel*(long)sintable[(ang+2048)&2047])>>3); - } - if (svel != 0) - { - xvect += ((svel*doubvel*(long)sintable[(ang+2048)&2047])>>3); - yvect += ((svel*doubvel*(long)sintable[(ang+1536)&2047])>>3); - } + if (angvel != 0) //ang += angvel * constant + { //ENGINE calculates angvel for you + doubvel = synctics; + if (keystatus[buildkeys[4]] > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (synctics>>1); + ang += ((angvel*doubvel)>>4); + ang = (ang+2048)&2047; + } + if ((vel|svel) != 0) + { + doubvel = synctics; + if (keystatus[buildkeys[4]] > 0) //Lt. shift doubles forward velocity + doubvel += synctics; + xvect = 0, yvect = 0; + if (vel != 0) + { + xvect += ((vel*doubvel*(long)sintable[(ang+2560)&2047])>>3); + yvect += ((vel*doubvel*(long)sintable[(ang+2048)&2047])>>3); + } + if (svel != 0) + { + xvect += ((svel*doubvel*(long)sintable[(ang+2048)&2047])>>3); + yvect += ((svel*doubvel*(long)sintable[(ang+1536)&2047])>>3); + } if (noclip) { - posx += xvect>>14; - posy += yvect>>14; - updatesector(posx,posy,&cursectnum); + posx += xvect>>14; + posy += yvect>>14; + updatesector(posx,posy,&cursectnum); } else clipmove(&posx,&posy,&posz,&cursectnum,xvect,yvect,128L,4L<<8,4L<<8,CLIPMASK0); - } - getzrange(posx,posy,posz,cursectnum,&hiz,&hihit,&loz,&lohit,128L,CLIPMASK0); + } + getzrange(posx,posy,posz,cursectnum,&hiz,&hihit,&loz,&lohit,128L,CLIPMASK0); - if (keystatus[0x3a] > 0) - { - zmode++; - if (zmode == 3) zmode = 0; - if (zmode == 1) zlock = (loz-posz)&0xfffffc00; - keystatus[0x3a] = 0; - } + if (keystatus[0x3a] > 0) + { + zmode++; + if (zmode == 3) zmode = 0; + if (zmode == 1) zlock = (loz-posz)&0xfffffc00; + keystatus[0x3a] = 0; + } - if (zmode == 0) - { - goalz = loz-(kensplayerheight<<8); //playerheight pixels above floor - if (goalz < hiz+(16<<8)) //ceiling&floor too close - goalz = ((loz+hiz)>>1); - goalz += mousz; - if (keystatus[buildkeys[8]] > 0) //A (stand high) - { - if (keystatus[0x1d] > 0) - horiz = max(-100,horiz-((keystatus[buildkeys[4]]+1)*synctics*2)); - else - { - goalz -= (16<<8); - if (keystatus[buildkeys[4]] > 0) //Either shift key - goalz -= (24<<8); - } - } - if (keystatus[buildkeys[9]] > 0) //Z (stand low) - { - if (keystatus[0x1d] > 0) - horiz = min(300,horiz+((keystatus[buildkeys[4]]+1)*synctics*2)); - else - { - goalz += (12<<8); - if (keystatus[buildkeys[4]] > 0) //Either shift key - goalz += (12<<8); - } - } + if (zmode == 0) + { + goalz = loz-(kensplayerheight<<8); //playerheight pixels above floor + if (goalz < hiz+(16<<8)) //ceiling&floor too close + goalz = ((loz+hiz)>>1); + goalz += mousz; + if (keystatus[buildkeys[8]] > 0) //A (stand high) + { + if (keystatus[0x1d] > 0) + horiz = max(-100,horiz-((keystatus[buildkeys[4]]+1)*synctics*2)); + else + { + goalz -= (16<<8); + if (keystatus[buildkeys[4]] > 0) //Either shift key + goalz -= (24<<8); + } + } + if (keystatus[buildkeys[9]] > 0) //Z (stand low) + { + if (keystatus[0x1d] > 0) + horiz = min(300,horiz+((keystatus[buildkeys[4]]+1)*synctics*2)); + else + { + goalz += (12<<8); + if (keystatus[buildkeys[4]] > 0) //Either shift key + goalz += (12<<8); + } + } - if (goalz != posz) - { - if (posz < goalz) hvel += 32; - if (posz > goalz) hvel = ((goalz-posz)>>3); + if (goalz != posz) + { + if (posz < goalz) hvel += 32; + if (posz > goalz) hvel = ((goalz-posz)>>3); - posz += hvel; - if (posz > loz-(4<<8)) posz = loz-(4<<8), hvel = 0; - if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0; - } - } - else - { - goalz = posz; - if (keystatus[buildkeys[8]] > 0) //A - { - if (keystatus[0x1d] > 0) { - horiz = max(-100,horiz-((keystatus[buildkeys[4]]+1)*synctics*2)); - } else { - if (zmode != 1) - goalz -= (8<<8); - else - { - zlock += (4<<8); - keystatus[buildkeys[8]] = 0; - } - } - } - if (keystatus[buildkeys[9]] > 0) //Z (stand low) - { - if (keystatus[0x1d] > 0) { - horiz = min(300,horiz+((keystatus[buildkeys[4]]+1)*synctics*2)); - } else { - if (zmode != 1) - goalz += (8<<8); - else if (zlock > 0) - { - zlock -= (4<<8); - keystatus[buildkeys[9]] = 0; - } - } - } + posz += hvel; + if (posz > loz-(4<<8)) posz = loz-(4<<8), hvel = 0; + if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0; + } + } + else + { + goalz = posz; + if (keystatus[buildkeys[8]] > 0) //A + { + if (keystatus[0x1d] > 0) { + horiz = max(-100,horiz-((keystatus[buildkeys[4]]+1)*synctics*2)); + } else { + if (zmode != 1) + goalz -= (8<<8); + else + { + zlock += (4<<8); + keystatus[buildkeys[8]] = 0; + } + } + } + if (keystatus[buildkeys[9]] > 0) //Z (stand low) + { + if (keystatus[0x1d] > 0) { + horiz = min(300,horiz+((keystatus[buildkeys[4]]+1)*synctics*2)); + } else { + if (zmode != 1) + goalz += (8<<8); + else if (zlock > 0) + { + zlock -= (4<<8); + keystatus[buildkeys[9]] = 0; + } + } + } - if (goalz < hiz+(4<<8)) goalz = hiz+(4<<8); - if (goalz > loz-(4<<8)) goalz = loz-(4<<8); - if (zmode == 1) goalz = loz-zlock; - if (goalz < hiz+(4<<8)) goalz = ((loz+hiz)>>1); //ceiling&floor too close - if (zmode == 1) posz = goalz; + if (goalz < hiz+(4<<8)) goalz = hiz+(4<<8); + if (goalz > loz-(4<<8)) goalz = loz-(4<<8); + if (zmode == 1) goalz = loz-zlock; + if (goalz < hiz+(4<<8)) goalz = ((loz+hiz)>>1); //ceiling&floor too close + if (zmode == 1) posz = goalz; - if (goalz != posz) - { - //if (posz < goalz) hvel += (32< goalz) hvel -= (32< goalz) hvel = ((synctics*-192)< goalz) hvel -= (32< goalz) hvel = ((synctics*-192)< loz-(4<<8)) posz = loz-(4<<8), hvel = 0; - if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0; - } - else - hvel = 0; - } + if (posz > loz-(4<<8)) posz = loz-(4<<8), hvel = 0; + if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0; + } + else + hvel = 0; + } - searchit = 2; - if (searchstat >= 0) - { + searchit = 2; + if (searchstat >= 0) + { if ((bstatus&(1|2|4)) > 0) - searchit = 0; - if (keystatus[0x4a] > 0) // - - { - keystatus[0x4a] = 0; - if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT - { - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL - { - if (visibility < 16384) visibility += visibility; - } - else - { - if ((keystatus[0x2a]|keystatus[0x36]) == 0) - k = 16; else k = 1; - - if (highlightsectorcnt >= 0) - for(i=0;i 0) - { - for(i=0;i 0) - { - sector[searchsector].visibility++; - if (sector[searchsector].visibility == 240) - sector[searchsector].visibility = 239; - k--; - } - asksave = 1; - } - } - else - { - k = 0; - if (highlightsectorcnt >= 0) - { - for(i=0;i 0) // + - { - keystatus[0x4e] = 0; - if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT - { - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL - { - if (visibility > 32) visibility >>= 1; - } - else - { - if ((keystatus[0x2a]|keystatus[0x36]) == 0) - k = 16; else k = 1; - - if (highlightsectorcnt >= 0) - for(i=0;i 0) - { - for(i=0;i 0) - { - sector[searchsector].visibility--; - if (sector[searchsector].visibility == 239) - sector[searchsector].visibility = 240; - k--; - } - asksave = 1; - } - } - else - { - k = 0; - if (highlightsectorcnt >= 0) - { - for(i=0;i 0) // PGUP - { - k = 0; - if (highlightsectorcnt >= 0) - { - for(i=0;i 0) //CTRL - put sprite on ceiling - { - sprite[searchwall].z = getceilzofslope(searchsector,sprite[searchwall].x,sprite[searchwall].y); - if (sprite[searchwall].cstat&128) sprite[searchwall].z -= ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<1); - if ((sprite[searchwall].cstat&48) != 32) - sprite[searchwall].z += ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<2); - } - else - { - k = 0; - if (highlightcnt >= 0) - for(i=0;i 0) // PGDN - { - k = 0; - if (highlightsectorcnt >= 0) - { - for(i=0;i sector[searchsector].floorz) - sector[searchsector].ceilingz = sector[searchsector].floorz; - if (searchstat == 3) - { - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL - put sprite on ground - { - sprite[searchwall].z = getflorzofslope(searchsector,sprite[searchwall].x,sprite[searchwall].y); - if (sprite[searchwall].cstat&128) sprite[searchwall].z -= ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<1); - } - else - { - k = 0; - if (highlightcnt >= 0) - for(i=0;i 0) //TAB - { - if (searchstat == 0) - { - temppicnum = wall[searchwall].picnum; - tempshade = wall[searchwall].shade; - temppal = wall[searchwall].pal; - tempxrepeat = wall[searchwall].xrepeat; - tempyrepeat = wall[searchwall].yrepeat; - tempcstat = wall[searchwall].cstat; - templotag = wall[searchwall].lotag; - temphitag = wall[searchwall].hitag; - tempextra = wall[searchwall].extra; - } - if (searchstat == 1) - { - temppicnum = sector[searchsector].ceilingpicnum; - tempshade = sector[searchsector].ceilingshade; - temppal = sector[searchsector].ceilingpal; - tempvis = sector[searchsector].visibility; - tempxrepeat = sector[searchsector].ceilingxpanning; - tempyrepeat = sector[searchsector].ceilingypanning; - tempcstat = sector[searchsector].ceilingstat; - templotag = sector[searchsector].lotag; - temphitag = sector[searchsector].hitag; - tempextra = sector[searchsector].extra; - } - if (searchstat == 2) - { - temppicnum = sector[searchsector].floorpicnum; - tempshade = sector[searchsector].floorshade; - temppal = sector[searchsector].floorpal; - tempvis = sector[searchsector].visibility; - tempxrepeat = sector[searchsector].floorxpanning; - tempyrepeat = sector[searchsector].floorypanning; - tempcstat = sector[searchsector].floorstat; - templotag = sector[searchsector].lotag; - temphitag = sector[searchsector].hitag; - tempextra = sector[searchsector].extra; - } - if (searchstat == 3) - { - temppicnum = sprite[searchwall].picnum; - tempshade = sprite[searchwall].shade; - temppal = sprite[searchwall].pal; - tempxrepeat = sprite[searchwall].xrepeat; - tempyrepeat = sprite[searchwall].yrepeat; - tempcstat = sprite[searchwall].cstat; - templotag = sprite[searchwall].lotag; - temphitag = sprite[searchwall].hitag; - tempextra = sprite[searchwall].extra; - } - if (searchstat == 4) - { - temppicnum = wall[searchwall].overpicnum; - tempshade = wall[searchwall].shade; - temppal = wall[searchwall].pal; - tempxrepeat = wall[searchwall].xrepeat; - tempyrepeat = wall[searchwall].yrepeat; - tempcstat = wall[searchwall].cstat; - templotag = wall[searchwall].lotag; - temphitag = wall[searchwall].hitag; - tempextra = wall[searchwall].extra; - } - somethingintab = searchstat; - keystatus[0x0f] = 0; - } - if (keystatus[0x1c] > 0) //Left ENTER - { - if ((keystatus[0x2a]|keystatus[0x36]) > 0) //Either shift key - { - if (((searchstat == 0) || (searchstat == 4)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0)) //Ctrl-shift Enter (auto-shade) - { - dashade[0] = 127; - dashade[1] = -128; - i = searchwall; - do - { - if ((long)wall[i].shade < dashade[0]) dashade[0] = wall[i].shade; - if ((long)wall[i].shade > dashade[1]) dashade[1] = wall[i].shade; - - i = wall[i].point2; - } - while (i != searchwall); - - daang = getangle(wall[wall[searchwall].point2].x-wall[searchwall].x,wall[wall[searchwall].point2].y-wall[searchwall].y); - i = searchwall; - do - { - j = getangle(wall[wall[i].point2].x-wall[i].x,wall[wall[i].point2].y-wall[i].y); - k = ((j+2048-daang)&2047); - if (k > 1024) - k = 2048-k; - wall[i].shade = dashade[0]+mulscale10(k,dashade[1]-dashade[0]); - - i = wall[i].point2; - } - while (i != searchwall); - } - else if (somethingintab < 255) - { - if (searchstat == 0) wall[searchwall].shade = tempshade, wall[searchwall].pal = temppal; - if (searchstat == 1) - { - sector[searchsector].ceilingshade = tempshade, sector[searchsector].ceilingpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - sector[searchsector].visibility = tempvis; - } - if (searchstat == 2) - { - sector[searchsector].floorshade = tempshade, sector[searchsector].floorpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - sector[searchsector].visibility = tempvis; - } - if (searchstat == 3) sprite[searchwall].shade = tempshade, sprite[searchwall].pal = temppal; - if (searchstat == 4) wall[searchwall].shade = tempshade, wall[searchwall].pal = temppal; - } - } - else if (((searchstat == 0) || (searchstat == 4)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0) && (somethingintab < 255)) //Either ctrl key - { - i = searchwall; - do - { - wall[i].picnum = temppicnum; - wall[i].shade = tempshade; - wall[i].pal = temppal; - if ((somethingintab == 0) || (somethingintab == 4)) - { - wall[i].xrepeat = tempxrepeat; - wall[i].yrepeat = tempyrepeat; - wall[i].cstat = tempcstat; - } - fixrepeats((short)i); - i = wall[i].point2; - } - while (i != searchwall); - } - else if (((searchstat == 1) || (searchstat == 2)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0) && (somethingintab < 255)) //Either ctrl key - { - clearbuf(&pskysearch[0],(long)((numsectors+3)>>2),0L); - if (searchstat == 1) - { - i = searchsector; - if ((sector[i].ceilingstat&1) > 0) - pskysearch[i] = 1; - - while (pskysearch[i] == 1) - { - sector[i].ceilingpicnum = temppicnum; - sector[i].ceilingshade = tempshade; - sector[i].ceilingpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - { - sector[i].ceilingxpanning = tempxrepeat; - sector[i].ceilingypanning = tempyrepeat; - sector[i].ceilingstat = tempcstat; - } - pskysearch[i] = 2; - - startwall = sector[i].wallptr; - endwall = startwall + sector[i].wallnum - 1; - for(j=startwall;j<=endwall;j++) - { - k = wall[j].nextsector; - if (k >= 0) - if ((sector[k].ceilingstat&1) > 0) - if (pskysearch[k] == 0) - pskysearch[k] = 1; - } - - for(j=0;j 0) - pskysearch[i] = 1; - - while (pskysearch[i] == 1) - { - sector[i].floorpicnum = temppicnum; - sector[i].floorshade = tempshade; - sector[i].floorpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - { - sector[i].floorxpanning = tempxrepeat; - sector[i].floorypanning = tempyrepeat; - sector[i].floorstat = tempcstat; - } - pskysearch[i] = 2; - - startwall = sector[i].wallptr; - endwall = startwall + sector[i].wallnum - 1; - for(j=startwall;j<=endwall;j++) - { - k = wall[j].nextsector; - if (k >= 0) - if ((sector[k].floorstat&1) > 0) - if (pskysearch[k] == 0) - pskysearch[k] = 1; - } - - for(j=0;j 0) && (tilesizy[k] > 0)) - { - j = k; - break; - } - sprite[searchwall].picnum = j; - } - sprite[searchwall].shade = tempshade; - sprite[searchwall].pal = temppal; - if (somethingintab == 3) - { - sprite[searchwall].xrepeat = tempxrepeat; - sprite[searchwall].yrepeat = tempyrepeat; - if (sprite[searchwall].xrepeat < 1) sprite[searchwall].xrepeat = 1; - if (sprite[searchwall].yrepeat < 1) sprite[searchwall].yrepeat = 1; - sprite[searchwall].cstat = tempcstat; - sprite[searchwall].lotag = templotag; - sprite[searchwall].hitag = temphitag; - sprite[searchwall].extra = tempextra; - } - } - if (searchstat == 4) - { - wall[searchwall].overpicnum = temppicnum; - if (wall[searchwall].nextwall >= 0) - wall[wall[searchwall].nextwall].overpicnum = temppicnum; - wall[searchwall].shade = tempshade; - wall[searchwall].pal = temppal; - if (somethingintab == 4) - { - wall[searchwall].xrepeat = tempxrepeat; - wall[searchwall].yrepeat = tempyrepeat; - wall[searchwall].cstat = tempcstat; - wall[searchwall].lotag = templotag; - wall[searchwall].hitag = temphitag; - wall[searchwall].extra = tempextra; - } - fixrepeats(searchwall); - } - } - asksave = 1; - keystatus[0x1c] = 0; - } - if (keystatus[0x2e] > 0) //C - { - keystatus[0x2e] = 0; - if (keystatus[0x38] > 0) //Alt-C - { - if (somethingintab < 255) - { - switch(searchstat) - { - case 0: - j = wall[searchwall].picnum; - for(i=0;i 0) //V - { - if (searchstat == 0) templong = wall[searchwall].picnum; - if (searchstat == 1) templong = sector[searchsector].ceilingpicnum; - if (searchstat == 2) templong = sector[searchsector].floorpicnum; - if (searchstat == 3) templong = sprite[searchwall].picnum; - if (searchstat == 4) templong = wall[searchwall].overpicnum; - templong = gettile(templong); - if (searchstat == 0) wall[searchwall].picnum = templong; - if (searchstat == 1) sector[searchsector].ceilingpicnum = templong; - if (searchstat == 2) sector[searchsector].floorpicnum = templong; - if (searchstat == 3) sprite[searchwall].picnum = templong; - if (searchstat == 4) - { - wall[searchwall].overpicnum = templong; - if (wall[searchwall].nextwall >= 0) - wall[wall[searchwall].nextwall].overpicnum = templong; - } - asksave = 1; - keystatus[0x2f] = 0; - } - - if (keystatus[0x1a]) // [ - { - keystatus[0x1a] = 0; - if (keystatus[0x38]|keystatus[0xb8]) - { - i = wall[searchwall].nextsector; - if (i >= 0) - switch(searchstat) - { - case 0: case 1: case 4: - alignceilslope(searchsector,wall[searchwall].x,wall[searchwall].y,getceilzofslope(i,wall[searchwall].x,wall[searchwall].y)); - break; - case 2: - alignflorslope(searchsector,wall[searchwall].x,wall[searchwall].y,getflorzofslope(i,wall[searchwall].x,wall[searchwall].y)); - break; - } - } - else - { - i = 512; - if (keystatus[0x36]) i = 8; - if (keystatus[0x2a]) i = 1; - - if (searchstat == 1) - { - if (!(sector[searchsector].ceilingstat&2)) - sector[searchsector].ceilingheinum = 0; - sector[searchsector].ceilingheinum = max(sector[searchsector].ceilingheinum-i,-32768); - } - if (searchstat == 2) - { - if (!(sector[searchsector].floorstat&2)) - sector[searchsector].floorheinum = 0; - sector[searchsector].floorheinum = max(sector[searchsector].floorheinum-i,-32768); - } - } - - if (sector[searchsector].ceilingheinum == 0) - sector[searchsector].ceilingstat &= ~2; - else - sector[searchsector].ceilingstat |= 2; - - if (sector[searchsector].floorheinum == 0) - sector[searchsector].floorstat &= ~2; - else - sector[searchsector].floorstat |= 2; - asksave = 1; - } - if (keystatus[0x1b]) // ] - { - keystatus[0x1b] = 0; - if (keystatus[0x38]|keystatus[0xb8]) - { - i = wall[searchwall].nextsector; - if (i >= 0) - switch(searchstat) - { - case 1: - alignceilslope(searchsector,wall[searchwall].x,wall[searchwall].y,getceilzofslope(i,wall[searchwall].x,wall[searchwall].y)); - break; - case 0: case 2: case 4: - alignflorslope(searchsector,wall[searchwall].x,wall[searchwall].y,getflorzofslope(i,wall[searchwall].x,wall[searchwall].y)); - break; - } - } - else - { - i = 512; - if (keystatus[0x36]) i = 8; - if (keystatus[0x2a]) i = 1; - - if (searchstat == 1) - { - if (!(sector[searchsector].ceilingstat&2)) - sector[searchsector].ceilingheinum = 0; - sector[searchsector].ceilingheinum = min(sector[searchsector].ceilingheinum+i,32767); - } - if (searchstat == 2) - { - if (!(sector[searchsector].floorstat&2)) - sector[searchsector].floorheinum = 0; - sector[searchsector].floorheinum = min(sector[searchsector].floorheinum+i,32767); - } - } - - if (sector[searchsector].ceilingheinum == 0) - sector[searchsector].ceilingstat &= ~2; - else - sector[searchsector].ceilingstat |= 2; - - if (sector[searchsector].floorheinum == 0) - sector[searchsector].floorstat &= ~2; - else - sector[searchsector].floorstat |= 2; - - asksave = 1; - } - - smooshyalign = keystatus[0x4c]; - repeatpanalign = (keystatus[0x2a]|keystatus[0x36]); - if ((keystatus[0x4b]|keystatus[0x4d]) > 0) // 4 & 6 (keypad) - { - if ((repeatcountx == 0) || (repeatcountx > 16)) - { - changedir = 0; - if (keystatus[0x4b] > 0) changedir = -1; - if (keystatus[0x4d] > 0) changedir = 1; - - if ((searchstat == 0) || (searchstat == 4)) - { - if (repeatpanalign == 0) - wall[searchwall].xrepeat = changechar(wall[searchwall].xrepeat,changedir,smooshyalign,1); - else - wall[searchwall].xpanning = changechar(wall[searchwall].xpanning,changedir,smooshyalign,0); - } - if ((searchstat == 1) || (searchstat == 2)) - { - if (searchstat == 1) - sector[searchsector].ceilingxpanning = changechar(sector[searchsector].ceilingxpanning,changedir,smooshyalign,0); - else - sector[searchsector].floorxpanning = changechar(sector[searchsector].floorxpanning,changedir,smooshyalign,0); - } - if (searchstat == 3) - { - sprite[searchwall].xrepeat = changechar(sprite[searchwall].xrepeat,changedir,smooshyalign,1); - if (sprite[searchwall].xrepeat < 4) - sprite[searchwall].xrepeat = 4; - } - asksave = 1; - repeatcountx = max(1,repeatcountx); - } - repeatcountx += (synctics>>1); - } - else - repeatcountx = 0; - - if ((keystatus[0x48]|keystatus[0x50]) > 0) // 2 & 8 (keypad) - { - if ((repeatcounty == 0) || (repeatcounty > 16)) - { - changedir = 0; - if (keystatus[0x48] > 0) changedir = -1; - if (keystatus[0x50] > 0) changedir = 1; - - if ((searchstat == 0) || (searchstat == 4)) - { - if (repeatpanalign == 0) - wall[searchwall].yrepeat = changechar(wall[searchwall].yrepeat,changedir,smooshyalign,1); - else - wall[searchwall].ypanning = changechar(wall[searchwall].ypanning,changedir,smooshyalign,0); - } - if ((searchstat == 1) || (searchstat == 2)) - { - if (searchstat == 1) - sector[searchsector].ceilingypanning = changechar(sector[searchsector].ceilingypanning,changedir,smooshyalign,0); - else - sector[searchsector].floorypanning = changechar(sector[searchsector].floorypanning,changedir,smooshyalign,0); - } - if (searchstat == 3) - { - sprite[searchwall].yrepeat = changechar(sprite[searchwall].yrepeat,changedir,smooshyalign,1); - if (sprite[searchwall].yrepeat < 4) - sprite[searchwall].yrepeat = 4; - } - asksave = 1; - repeatcounty = max(1,repeatcounty); - } - repeatcounty += (synctics>>1); - //} - } - else - repeatcounty = 0; - - if (keystatus[0x33] > 0) // , Search & fix panning to the left (3D) - { - if (searchstat == 3) - { - i = searchwall; - if ((keystatus[0x2a]|keystatus[0x36]) > 0) - sprite[i].ang = ((sprite[i].ang+2048-1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048-128)&2047); - keystatus[0x33] = 0; - } - } - } - if (keystatus[0x34] > 0) // . Search & fix panning to the right (3D) - { - if ((searchstat == 0) || (searchstat == 4)) - { - AutoAlignWalls((long)searchwall,0L); - - /*wallfind[0] = searchwall; - cnt = 4096; - do - { - wallfind[1] = wall[wallfind[0]].point2; - j = -1; - if (wall[wallfind[1]].picnum == wall[searchwall].picnum) - j = wallfind[1]; - k = wallfind[1]; - - while ((wall[wallfind[1]].nextwall >= 0) && (wall[wall[wallfind[1]].nextwall].point2 != k)) - { - i = wall[wall[wallfind[1]].nextwall].point2; //break if going around in circles on red lines with same picture on both sides - if (wallfind[1] == wall[wall[i].nextwall].point2) - break; - - wallfind[1] = wall[wall[wallfind[1]].nextwall].point2; - if (wall[wallfind[1]].picnum == wall[searchwall].picnum) - j = wallfind[1]; - } - wallfind[1] = j; - - if ((j >= 0) && (wallfind[1] != searchwall)) - { - j = (wall[wallfind[0]].xpanning+(wall[wallfind[0]].xrepeat<<3)) % tilesizx[wall[wallfind[0]].picnum]; - wall[wallfind[1]].cstat &= ~8; //Set to non-flip - wall[wallfind[1]].cstat |= 4; //Set y-orientation - wall[wallfind[1]].xpanning = j; - - for(k=0;k<2;k++) - { - sectnum = sectorofwall((short)wallfind[k]); - nextsectnum = wall[wallfind[k]].nextsector; - - if (nextsectnum == -1) - { - if ((wall[wallfind[k]].cstat&4) == 0) - daz[k] = sector[sectnum].ceilingz; - else - daz[k] = sector[sectnum].floorz; - } - else //topstep - { - if (sector[nextsectnum].ceilingz > sector[sectnum].ceilingz) - daz[k] = sector[nextsectnum].ceilingz; - else if (sector[nextsectnum].floorz < sector[sectnum].floorz) - daz[k] = sector[nextsectnum].floorz; - } - } - - j = (picsiz[wall[searchwall].picnum]>>4); - if ((1<>(j+3)))&255); - wall[wallfind[1]].ypanning = j; - wall[wallfind[1]].yrepeat = wall[wallfind[0]].yrepeat; - if (nextsectnum >= 0) - if (sector[nextsectnum].ceilingz >= sector[sectnum].ceilingz) - if (sector[nextsectnum].floorz <= sector[sectnum].floorz) - { - if (wall[wall[wallfind[1]].nextwall].picnum == wall[searchwall].picnum) - { - wall[wall[wallfind[1]].nextwall].yrepeat = wall[wallfind[0]].yrepeat; - if ((wall[wall[wallfind[1]].nextwall].cstat&4) == 0) - daz[1] = sector[nextsectnum].floorz; - else - daz[1] = sector[sectnum].ceilingz; - wall[wall[wallfind[1]].nextwall].ypanning = j; - } - } - } - wallfind[0] = wallfind[1]; - cnt--; - } - while ((wall[wallfind[0]].picnum == wall[searchwall].picnum) && (wallfind[0] != searchwall) && (cnt > 0)); - */ - - keystatus[0x34] = 0; - } - if (searchstat == 3) - { - i = searchwall; - if ((keystatus[0x2a]|keystatus[0x36]) > 0) - sprite[i].ang = ((sprite[i].ang+2048+1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048+128)&2047); - keystatus[0x34] = 0; - } - } - } - if (keystatus[0x35] > 0) // /? Reset panning&repeat to 0 - { - if ((searchstat == 0) || (searchstat == 4)) - { - wall[searchwall].xpanning = 0; - wall[searchwall].ypanning = 0; - wall[searchwall].xrepeat = 8; - wall[searchwall].yrepeat = 8; - wall[searchwall].cstat = 0; - fixrepeats((short)searchwall); - } - if (searchstat == 1) - { - sector[searchsector].ceilingxpanning = 0; - sector[searchsector].ceilingypanning = 0; - sector[searchsector].ceilingstat &= ~2; - sector[searchsector].ceilingheinum = 0; - } - if (searchstat == 2) - { - sector[searchsector].floorxpanning = 0; - sector[searchsector].floorypanning = 0; - sector[searchsector].floorstat &= ~2; - sector[searchsector].floorheinum = 0; - } - if (searchstat == 3) - { - if ((keystatus[0x2a]|keystatus[0x36]) > 0) - { - sprite[searchwall].xrepeat = sprite[searchwall].yrepeat; - } - else - { - sprite[searchwall].xrepeat = 64; - sprite[searchwall].yrepeat = 64; - } - } - keystatus[0x35] = 0; - asksave = 1; - } - - if (keystatus[0x19] > 0) // P (parallaxing sky) - { - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) - { - parallaxtype++; - if (parallaxtype == 3) - parallaxtype = 0; - } - else if ((keystatus[0x38]|keystatus[0xb8]) > 0) - { - switch (searchstat) - { - case 0: case 4: - Bstrcpy(buffer,"Wall pal: "); - wall[searchwall].pal = getnumber256(buffer,wall[searchwall].pal,256L,0); - break; - case 1: - Bstrcpy(buffer,"Ceiling pal: "); - sector[searchsector].ceilingpal = getnumber256(buffer,sector[searchsector].ceilingpal,256L,0); - break; - case 2: - Bstrcpy(buffer,"Floor pal: "); - sector[searchsector].floorpal = getnumber256(buffer,sector[searchsector].floorpal,256L,0); - break; - case 3: - Bstrcpy(buffer,"Sprite pal: "); - sprite[searchwall].pal = getnumber256(buffer,sprite[searchwall].pal,256L,0); - break; - } - } - else - { - if ((searchstat == 0) || (searchstat == 1) || (searchstat == 4)) - { - sector[searchsector].ceilingstat ^= 1; - asksave = 1; - } - else if (searchstat == 2) - { - sector[searchsector].floorstat ^= 1; - asksave = 1; - } - } - keystatus[0x19] = 0; - } - - if (keystatus[0x20] != 0) //Alt-D (adjust sprite[].clipdist) - { - keystatus[0x20] = 0; - if ((keystatus[0x38]|keystatus[0xb8]) > 0) - { - if (searchstat == 3) - { - Bstrcpy(buffer,"Sprite clipdist: "); - sprite[searchwall].clipdist = getnumber256(buffer,sprite[searchwall].clipdist,256L,0); - } - } - } - - if (keystatus[0x30] > 0) // B (clip Blocking xor) (3D) - { - if (searchstat == 3) - { - sprite[searchwall].cstat ^= 1; - sprite[searchwall].cstat &= ~256; - sprite[searchwall].cstat |= ((sprite[searchwall].cstat&1)<<8); - asksave = 1; - } - else - { - wall[searchwall].cstat ^= 1; - wall[searchwall].cstat &= ~64; - if ((wall[searchwall].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) - { - wall[wall[searchwall].nextwall].cstat &= ~(1+64); - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&1); - } - asksave = 1; - } - keystatus[0x30] = 0; - } - if (keystatus[0x14] > 0) // T (transluscence for sprites/masked walls) - { - /*if (searchstat == 1) //Set masked/transluscent ceilings/floors - { - i = (sector[searchsector].ceilingstat&(128+256)); - sector[searchsector].ceilingstat &= ~(128+256); - switch(i) - { - case 0: sector[searchsector].ceilingstat |= 128; break; - case 128: sector[searchsector].ceilingstat |= 256; break; - case 256: sector[searchsector].ceilingstat |= 384; break; - case 384: sector[searchsector].ceilingstat |= 0; break; - } - asksave = 1; - } - if (searchstat == 2) - { - i = (sector[searchsector].floorstat&(128+256)); - sector[searchsector].floorstat &= ~(128+256); - switch(i) - { - case 0: sector[searchsector].floorstat |= 128; break; - case 128: sector[searchsector].floorstat |= 256; break; - case 256: sector[searchsector].floorstat |= 384; break; - case 384: sector[searchsector].floorstat |= 0; break; - } - asksave = 1; - }*/ - if (searchstat == 3) - { - if ((sprite[searchwall].cstat&2) == 0) - sprite[searchwall].cstat |= 2; - else if ((sprite[searchwall].cstat&512) == 0) - sprite[searchwall].cstat |= 512; - else - sprite[searchwall].cstat &= ~(2+512); - asksave = 1; - } - if (searchstat == 4) - { - if ((wall[searchwall].cstat&128) == 0) - wall[searchwall].cstat |= 128; - else if ((wall[searchwall].cstat&512) == 0) - wall[searchwall].cstat |= 512; - else - wall[searchwall].cstat &= ~(128+512); - - if (wall[searchwall].nextwall >= 0) - { - wall[wall[searchwall].nextwall].cstat &= ~(128+512); - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&(128+512)); - } - asksave = 1; - } - keystatus[0x14] = 0; - } - - if (keystatus[0x2] > 0) // 1 (make 1-way wall) - { - if (searchstat != 3) - { - wall[searchwall].cstat ^= 32; - asksave = 1; - } - else - { - sprite[searchwall].cstat ^= 64; - i = sprite[searchwall].cstat; - if ((i&48) == 32) - { - sprite[searchwall].cstat &= ~8; - if ((i&64) > 0) - if (posz > sprite[searchwall].z) - sprite[searchwall].cstat |= 8; - } - asksave = 1; - } - keystatus[0x2] = 0; - } - if (keystatus[0x3] > 0) // 2 (bottom wall swapping) - { - if (searchstat != 3) - { - wall[searchwall].cstat ^= 2; - asksave = 1; - } - keystatus[0x3] = 0; - } - if (keystatus[0x18] > 0) // O (top/bottom orientation - for doors) - { - if ((searchstat == 0) || (searchstat == 4)) - { - wall[searchwall].cstat ^= 4; - asksave = 1; - } - if (searchstat == 3) // O (ornament onto wall) (2D) - { - asksave = 1; - i = searchwall; - - hitscan(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum, - sintable[(sprite[i].ang+2560+1024)&2047], - sintable[(sprite[i].ang+2048+1024)&2047], - 0, - &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - - sprite[i].x = hitx; - sprite[i].y = hity; - sprite[i].z = hitz; - changespritesect(i,hitsect); - if (hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); - - //Make sure sprite's in right sector - if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) - { - j = wall[hitwall].point2; - sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); - sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); - } - } - keystatus[0x18] = 0; - } - if (keystatus[0x32] > 0) // M (masking walls) - { - if (searchstat != 3) - { - i = wall[searchwall].nextwall; - templong = (keystatus[0x2a]|keystatus[0x36]); - if (i >= 0) - { - wall[searchwall].cstat ^= 16; - if ((wall[searchwall].cstat&16) > 0) - { - wall[searchwall].cstat &= ~8; - if (templong == 0) - { - wall[i].cstat |= 8; //auto other-side flip - wall[i].cstat |= 16; - wall[i].overpicnum = wall[searchwall].overpicnum; - } - } - else - { - wall[searchwall].cstat &= ~8; - if (templong == 0) - { - wall[i].cstat &= ~8; //auto other-side unflip - wall[i].cstat &= ~16; - } - } - wall[searchwall].cstat &= ~32; - if (templong == 0) wall[i].cstat &= ~32; - asksave = 1; - } - } - keystatus[0x32] = 0; - } - if (keystatus[0x23] > 0) // H (hitscan sensitivity) - { - if (searchstat == 3) - { - sprite[searchwall].cstat ^= 256; - asksave = 1; - } - else - { - wall[searchwall].cstat ^= 64; - if ((wall[searchwall].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) - { - wall[wall[searchwall].nextwall].cstat &= ~64; - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&64); - } - asksave = 1; - } - keystatus[0x23] = 0; - } - if (keystatus[0x12] > 0) // E (expand) - { - if (searchstat == 1) - { - sector[searchsector].ceilingstat ^= 8; - asksave = 1; - } - if (searchstat == 2) - { - sector[searchsector].floorstat ^= 8; - asksave = 1; - } - keystatus[0x12] = 0; - } - if (keystatus[0x13] > 0) // R (relative alignment, rotation) - { - if (searchstat == 1) - { - sector[searchsector].ceilingstat ^= 64; - asksave = 1; - } - if (searchstat == 2) - { - sector[searchsector].floorstat ^= 64; - asksave = 1; - } - if (searchstat == 3) - { - i = sprite[searchwall].cstat; - if ((i&48) < 32) i += 16; else i &= ~48; - sprite[searchwall].cstat = i; - asksave = 1; - } - keystatus[0x13] = 0; - } - if (keystatus[0x21] > 0) //F (Flip) - { - keystatus[0x21] = 0; - if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT-F (relative alignmment flip) - { - if (searchstat != 3) - { - setfirstwall(searchsector,searchwall); - asksave = 1; - } - } - else - { - if ((searchstat == 0) || (searchstat == 4)) - { - i = wall[searchwall].cstat; - i = ((i>>3)&1)+((i>>7)&2); //3-x,8-y - switch(i) - { - case 0: i = 1; break; - case 1: i = 3; break; - case 2: i = 0; break; - case 3: i = 2; break; - } - i = ((i&1)<<3)+((i&2)<<7); - wall[searchwall].cstat &= ~0x0108; - wall[searchwall].cstat |= i; - asksave = 1; - } - if (searchstat == 1) //8-way ceiling flipping (bits 2,4,5) - { - i = sector[searchsector].ceilingstat; - i = (i&0x4)+((i>>4)&3); - switch(i) - { - case 0: i = 6; break; - case 6: i = 3; break; - case 3: i = 5; break; - case 5: i = 1; break; - case 1: i = 7; break; - case 7: i = 2; break; - case 2: i = 4; break; - case 4: i = 0; break; - } - i = (i&0x4)+((i&3)<<4); - sector[searchsector].ceilingstat &= ~0x34; - sector[searchsector].ceilingstat |= i; - asksave = 1; - } - if (searchstat == 2) //8-way floor flipping (bits 2,4,5) - { - i = sector[searchsector].floorstat; - i = (i&0x4)+((i>>4)&3); - switch(i) - { - case 0: i = 6; break; - case 6: i = 3; break; - case 3: i = 5; break; - case 5: i = 1; break; - case 1: i = 7; break; - case 7: i = 2; break; - case 2: i = 4; break; - case 4: i = 0; break; - } - i = (i&0x4)+((i&3)<<4); - sector[searchsector].floorstat &= ~0x34; - sector[searchsector].floorstat |= i; - asksave = 1; - } - if (searchstat == 3) - { - i = sprite[searchwall].cstat; - if (((i&48) == 32) && ((i&64) == 0)) - { - sprite[searchwall].cstat &= ~0xc; - sprite[searchwall].cstat |= (i&4)^4; - } - else - { - i = ((i>>2)&3); - switch(i) - { - case 0: i = 1; break; - case 1: i = 3; break; - case 2: i = 0; break; - case 3: i = 2; break; - } - i <<= 2; - sprite[searchwall].cstat &= ~0xc; - sprite[searchwall].cstat |= i; - } - asksave = 1; - } - } - } - if (keystatus[0x1f] > 0) //S (insert sprite) (3D) - { - dax = 16384; - day = divscale14(searchx-(xdim>>1),xdim>>1); - rotatepoint(0,0,dax,day,ang,&dax,&day); - - hitscan(posx,posy,posz,cursectnum, //Start position - dax,day,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang - &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - - if (hitsect >= 0) - { - dax = hitx; - day = hity; - if ((gridlock > 0) && (grid > 0)) - { - if ((searchstat == 0) || (searchstat == 4)) - { - hitz = (hitz&0xfffffc00); - } - else - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - } - - i = insertsprite(hitsect,0); - sprite[i].x = dax, sprite[i].y = day; - sprite[i].cstat = defaultspritecstat; - sprite[i].shade = 0; - sprite[i].pal = 0; - sprite[i].xrepeat = 64, sprite[i].yrepeat = 64; - sprite[i].xoffset = 0, sprite[i].yoffset = 0; - sprite[i].ang = 1536; - sprite[i].xvel = 0; sprite[i].yvel = 0; sprite[i].zvel = 0; - sprite[i].owner = -1; - sprite[i].clipdist = 32; - sprite[i].lotag = 0; - sprite[i].hitag = 0; - sprite[i].extra = -1; - - for(k=0;k localartfreq[j]) - j = k; - if (localartfreq[j] > 0) - sprite[i].picnum = j; - else - sprite[i].picnum = 0; - - if (somethingintab == 3) - { - sprite[i].picnum = temppicnum; - if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) - { - j = 0; - for(k=0;k 0) && (tilesizy[k] > 0)) - { - j = k; - break; - } - sprite[i].picnum = j; - } - sprite[i].shade = tempshade; - sprite[i].pal = temppal; - sprite[i].xrepeat = tempxrepeat; - sprite[i].yrepeat = tempyrepeat; - if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; - if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; - sprite[i].cstat = tempcstat; - } - - j = ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); - if ((sprite[i].cstat&128) == 0) - sprite[i].z = min(max(hitz,getceilzofslope(hitsect,hitx,hity)+(j<<1)),getflorzofslope(hitsect,hitx,hity)); - else - sprite[i].z = min(max(hitz,getceilzofslope(hitsect,hitx,hity)+j),getflorzofslope(hitsect,hitx,hity)-j); - - if ((searchstat == 0) || (searchstat == 4)) - { - sprite[i].cstat = (sprite[i].cstat&~48)|(16+64); - if (hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); - - //Make sure sprite's in right sector - if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) - { - j = wall[hitwall].point2; - sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); - sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); - } - } - else - { - if (tilesizy[sprite[i].picnum] >= 32) sprite[i].cstat |= 1; - } - - updatenumsprites(); - asksave = 1; - } - - keystatus[0x1f] = 0; - } - if (keystatus[0xd3] > 0) - { - if (searchstat == 3) - { - deletesprite(searchwall); - updatenumsprites(); - asksave = 1; - } - keystatus[0xd3] = 0; - } - - if ((keystatus[0x3f]|keystatus[0x40]) > 0) //F5,F6 - { - switch(searchstat) - { - case 1: case 2: ExtShowSectorData(searchsector); break; - case 0: case 4: ExtShowWallData(searchwall); break; - case 3: ExtShowSpriteData(searchwall); break; - } - keystatus[0x3f] = 0, keystatus[0x40] = 0; - } - if ((keystatus[0x41]|keystatus[0x42]) > 0) //F7,F8 - { - switch(searchstat) - { - case 1: case 2: ExtEditSectorData(searchsector); break; - case 0: case 4: ExtEditWallData(searchwall); break; - case 3: ExtEditSpriteData(searchwall); break; - } - keystatus[0x41] = 0, keystatus[0x42] = 0; - } - - } - if (keystatus[buildkeys[14]] > 0) // Enter - { - overheadeditor(); - keystatus[buildkeys[14]] = 0; - } + searchit = 0; + if (keystatus[0x4a] > 0) // - + { + keystatus[0x4a] = 0; + if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT + { + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL + { + if (visibility < 16384) visibility += visibility; + } + else + { + if ((keystatus[0x2a]|keystatus[0x36]) == 0) + k = 16; else k = 1; + + if (highlightsectorcnt >= 0) + for(i=0;i 0) + { + for(i=0;i 0) + { + sector[searchsector].visibility++; + if (sector[searchsector].visibility == 240) + sector[searchsector].visibility = 239; + k--; + } + asksave = 1; + } + } + else + { + k = 0; + if (highlightsectorcnt >= 0) + { + for(i=0;i 0) // + + { + keystatus[0x4e] = 0; + if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT + { + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL + { + if (visibility > 32) visibility >>= 1; + } + else + { + if ((keystatus[0x2a]|keystatus[0x36]) == 0) + k = 16; else k = 1; + + if (highlightsectorcnt >= 0) + for(i=0;i 0) + { + for(i=0;i 0) + { + sector[searchsector].visibility--; + if (sector[searchsector].visibility == 239) + sector[searchsector].visibility = 240; + k--; + } + asksave = 1; + } + } + else + { + k = 0; + if (highlightsectorcnt >= 0) + { + for(i=0;i 0) // PGUP + { + k = 0; + if (highlightsectorcnt >= 0) + { + for(i=0;i 0) //CTRL - put sprite on ceiling + { + sprite[searchwall].z = getceilzofslope(searchsector,sprite[searchwall].x,sprite[searchwall].y); + if (sprite[searchwall].cstat&128) sprite[searchwall].z -= ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<1); + if ((sprite[searchwall].cstat&48) != 32) + sprite[searchwall].z += ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<2); + } + else + { + k = 0; + if (highlightcnt >= 0) + for(i=0;i 0) // PGDN + { + k = 0; + if (highlightsectorcnt >= 0) + { + for(i=0;i sector[searchsector].floorz) + sector[searchsector].ceilingz = sector[searchsector].floorz; + if (searchstat == 3) + { + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //CTRL - put sprite on ground + { + sprite[searchwall].z = getflorzofslope(searchsector,sprite[searchwall].x,sprite[searchwall].y); + if (sprite[searchwall].cstat&128) sprite[searchwall].z -= ((tilesizy[sprite[searchwall].picnum]*sprite[searchwall].yrepeat)<<1); + } + else + { + k = 0; + if (highlightcnt >= 0) + for(i=0;i 0) //TAB + { + if (searchstat == 0) + { + temppicnum = wall[searchwall].picnum; + tempshade = wall[searchwall].shade; + temppal = wall[searchwall].pal; + tempxrepeat = wall[searchwall].xrepeat; + tempyrepeat = wall[searchwall].yrepeat; + tempcstat = wall[searchwall].cstat; + templotag = wall[searchwall].lotag; + temphitag = wall[searchwall].hitag; + tempextra = wall[searchwall].extra; + } + if (searchstat == 1) + { + temppicnum = sector[searchsector].ceilingpicnum; + tempshade = sector[searchsector].ceilingshade; + temppal = sector[searchsector].ceilingpal; + tempvis = sector[searchsector].visibility; + tempxrepeat = sector[searchsector].ceilingxpanning; + tempyrepeat = sector[searchsector].ceilingypanning; + tempcstat = sector[searchsector].ceilingstat; + templotag = sector[searchsector].lotag; + temphitag = sector[searchsector].hitag; + tempextra = sector[searchsector].extra; + } + if (searchstat == 2) + { + temppicnum = sector[searchsector].floorpicnum; + tempshade = sector[searchsector].floorshade; + temppal = sector[searchsector].floorpal; + tempvis = sector[searchsector].visibility; + tempxrepeat = sector[searchsector].floorxpanning; + tempyrepeat = sector[searchsector].floorypanning; + tempcstat = sector[searchsector].floorstat; + templotag = sector[searchsector].lotag; + temphitag = sector[searchsector].hitag; + tempextra = sector[searchsector].extra; + } + if (searchstat == 3) + { + temppicnum = sprite[searchwall].picnum; + tempshade = sprite[searchwall].shade; + temppal = sprite[searchwall].pal; + tempxrepeat = sprite[searchwall].xrepeat; + tempyrepeat = sprite[searchwall].yrepeat; + tempcstat = sprite[searchwall].cstat; + templotag = sprite[searchwall].lotag; + temphitag = sprite[searchwall].hitag; + tempextra = sprite[searchwall].extra; + } + if (searchstat == 4) + { + temppicnum = wall[searchwall].overpicnum; + tempshade = wall[searchwall].shade; + temppal = wall[searchwall].pal; + tempxrepeat = wall[searchwall].xrepeat; + tempyrepeat = wall[searchwall].yrepeat; + tempcstat = wall[searchwall].cstat; + templotag = wall[searchwall].lotag; + temphitag = wall[searchwall].hitag; + tempextra = wall[searchwall].extra; + } + somethingintab = searchstat; + keystatus[0x0f] = 0; + } + if (keystatus[0x1c] > 0) //Left ENTER + { + if ((keystatus[0x2a]|keystatus[0x36]) > 0) //Either shift key + { + if (((searchstat == 0) || (searchstat == 4)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0)) //Ctrl-shift Enter (auto-shade) + { + dashade[0] = 127; + dashade[1] = -128; + i = searchwall; + do + { + if ((long)wall[i].shade < dashade[0]) dashade[0] = wall[i].shade; + if ((long)wall[i].shade > dashade[1]) dashade[1] = wall[i].shade; + + i = wall[i].point2; + } + while (i != searchwall); + + daang = getangle(wall[wall[searchwall].point2].x-wall[searchwall].x,wall[wall[searchwall].point2].y-wall[searchwall].y); + i = searchwall; + do + { + j = getangle(wall[wall[i].point2].x-wall[i].x,wall[wall[i].point2].y-wall[i].y); + k = ((j+2048-daang)&2047); + if (k > 1024) + k = 2048-k; + wall[i].shade = dashade[0]+mulscale10(k,dashade[1]-dashade[0]); + + i = wall[i].point2; + } + while (i != searchwall); + } + else if (somethingintab < 255) + { + if (searchstat == 0) wall[searchwall].shade = tempshade, wall[searchwall].pal = temppal; + if (searchstat == 1) + { + sector[searchsector].ceilingshade = tempshade, sector[searchsector].ceilingpal = temppal; + if ((somethingintab == 1) || (somethingintab == 2)) + sector[searchsector].visibility = tempvis; + } + if (searchstat == 2) + { + sector[searchsector].floorshade = tempshade, sector[searchsector].floorpal = temppal; + if ((somethingintab == 1) || (somethingintab == 2)) + sector[searchsector].visibility = tempvis; + } + if (searchstat == 3) sprite[searchwall].shade = tempshade, sprite[searchwall].pal = temppal; + if (searchstat == 4) wall[searchwall].shade = tempshade, wall[searchwall].pal = temppal; + } + } + else if (((searchstat == 0) || (searchstat == 4)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0) && (somethingintab < 255)) //Either ctrl key + { + i = searchwall; + do + { + wall[i].picnum = temppicnum; + wall[i].shade = tempshade; + wall[i].pal = temppal; + if ((somethingintab == 0) || (somethingintab == 4)) + { + wall[i].xrepeat = tempxrepeat; + wall[i].yrepeat = tempyrepeat; + wall[i].cstat = tempcstat; + } + fixrepeats((short)i); + i = wall[i].point2; + } + while (i != searchwall); + } + else if (((searchstat == 1) || (searchstat == 2)) && ((keystatus[0x1d]|keystatus[0x9d]) > 0) && (somethingintab < 255)) //Either ctrl key + { + clearbuf(&pskysearch[0],(long)((numsectors+3)>>2),0L); + if (searchstat == 1) + { + i = searchsector; + if ((sector[i].ceilingstat&1) > 0) + pskysearch[i] = 1; + + while (pskysearch[i] == 1) + { + sector[i].ceilingpicnum = temppicnum; + sector[i].ceilingshade = tempshade; + sector[i].ceilingpal = temppal; + if ((somethingintab == 1) || (somethingintab == 2)) + { + sector[i].ceilingxpanning = tempxrepeat; + sector[i].ceilingypanning = tempyrepeat; + sector[i].ceilingstat = tempcstat; + } + pskysearch[i] = 2; + + startwall = sector[i].wallptr; + endwall = startwall + sector[i].wallnum - 1; + for(j=startwall;j<=endwall;j++) + { + k = wall[j].nextsector; + if (k >= 0) + if ((sector[k].ceilingstat&1) > 0) + if (pskysearch[k] == 0) + pskysearch[k] = 1; + } + + for(j=0;j 0) + pskysearch[i] = 1; + + while (pskysearch[i] == 1) + { + sector[i].floorpicnum = temppicnum; + sector[i].floorshade = tempshade; + sector[i].floorpal = temppal; + if ((somethingintab == 1) || (somethingintab == 2)) + { + sector[i].floorxpanning = tempxrepeat; + sector[i].floorypanning = tempyrepeat; + sector[i].floorstat = tempcstat; + } + pskysearch[i] = 2; + + startwall = sector[i].wallptr; + endwall = startwall + sector[i].wallnum - 1; + for(j=startwall;j<=endwall;j++) + { + k = wall[j].nextsector; + if (k >= 0) + if ((sector[k].floorstat&1) > 0) + if (pskysearch[k] == 0) + pskysearch[k] = 1; + } + + for(j=0;j 0) && (tilesizy[k] > 0)) + { + j = k; + break; + } + sprite[searchwall].picnum = j; + } + sprite[searchwall].shade = tempshade; + sprite[searchwall].pal = temppal; + if (somethingintab == 3) + { + sprite[searchwall].xrepeat = tempxrepeat; + sprite[searchwall].yrepeat = tempyrepeat; + if (sprite[searchwall].xrepeat < 1) sprite[searchwall].xrepeat = 1; + if (sprite[searchwall].yrepeat < 1) sprite[searchwall].yrepeat = 1; + sprite[searchwall].cstat = tempcstat; + sprite[searchwall].lotag = templotag; + sprite[searchwall].hitag = temphitag; + sprite[searchwall].extra = tempextra; + } + } + if (searchstat == 4) + { + wall[searchwall].overpicnum = temppicnum; + if (wall[searchwall].nextwall >= 0) + wall[wall[searchwall].nextwall].overpicnum = temppicnum; + wall[searchwall].shade = tempshade; + wall[searchwall].pal = temppal; + if (somethingintab == 4) + { + wall[searchwall].xrepeat = tempxrepeat; + wall[searchwall].yrepeat = tempyrepeat; + wall[searchwall].cstat = tempcstat; + wall[searchwall].lotag = templotag; + wall[searchwall].hitag = temphitag; + wall[searchwall].extra = tempextra; + } + fixrepeats(searchwall); + } + } + asksave = 1; + keystatus[0x1c] = 0; + } + if (keystatus[0x2e] > 0) //C + { + keystatus[0x2e] = 0; + if (keystatus[0x38] > 0) //Alt-C + { + if (somethingintab < 255) + { + switch(searchstat) + { + case 0: + j = wall[searchwall].picnum; + for(i=0;i 0) //V + { + if (searchstat == 0) templong = wall[searchwall].picnum; + if (searchstat == 1) templong = sector[searchsector].ceilingpicnum; + if (searchstat == 2) templong = sector[searchsector].floorpicnum; + if (searchstat == 3) templong = sprite[searchwall].picnum; + if (searchstat == 4) templong = wall[searchwall].overpicnum; + templong = gettile(templong); + if (searchstat == 0) wall[searchwall].picnum = templong; + if (searchstat == 1) sector[searchsector].ceilingpicnum = templong; + if (searchstat == 2) sector[searchsector].floorpicnum = templong; + if (searchstat == 3) sprite[searchwall].picnum = templong; + if (searchstat == 4) + { + wall[searchwall].overpicnum = templong; + if (wall[searchwall].nextwall >= 0) + wall[wall[searchwall].nextwall].overpicnum = templong; + } + asksave = 1; + keystatus[0x2f] = 0; + } + + if (keystatus[0x1a]) // [ + { + keystatus[0x1a] = 0; + if (keystatus[0x38]|keystatus[0xb8]) + { + i = wall[searchwall].nextsector; + if (i >= 0) + switch(searchstat) + { + case 0: case 1: case 4: + alignceilslope(searchsector,wall[searchwall].x,wall[searchwall].y,getceilzofslope(i,wall[searchwall].x,wall[searchwall].y)); + break; + case 2: + alignflorslope(searchsector,wall[searchwall].x,wall[searchwall].y,getflorzofslope(i,wall[searchwall].x,wall[searchwall].y)); + break; + } + } + else + { + i = 512; + if (keystatus[0x36]) i = 8; + if (keystatus[0x2a]) i = 1; + + if (searchstat == 1) + { + if (!(sector[searchsector].ceilingstat&2)) + sector[searchsector].ceilingheinum = 0; + sector[searchsector].ceilingheinum = max(sector[searchsector].ceilingheinum-i,-32768); + } + if (searchstat == 2) + { + if (!(sector[searchsector].floorstat&2)) + sector[searchsector].floorheinum = 0; + sector[searchsector].floorheinum = max(sector[searchsector].floorheinum-i,-32768); + } + } + + if (sector[searchsector].ceilingheinum == 0) + sector[searchsector].ceilingstat &= ~2; + else + sector[searchsector].ceilingstat |= 2; + + if (sector[searchsector].floorheinum == 0) + sector[searchsector].floorstat &= ~2; + else + sector[searchsector].floorstat |= 2; + asksave = 1; + } + if (keystatus[0x1b]) // ] + { + keystatus[0x1b] = 0; + if (keystatus[0x38]|keystatus[0xb8]) + { + i = wall[searchwall].nextsector; + if (i >= 0) + switch(searchstat) + { + case 1: + alignceilslope(searchsector,wall[searchwall].x,wall[searchwall].y,getceilzofslope(i,wall[searchwall].x,wall[searchwall].y)); + break; + case 0: case 2: case 4: + alignflorslope(searchsector,wall[searchwall].x,wall[searchwall].y,getflorzofslope(i,wall[searchwall].x,wall[searchwall].y)); + break; + } + } + else + { + i = 512; + if (keystatus[0x36]) i = 8; + if (keystatus[0x2a]) i = 1; + + if (searchstat == 1) + { + if (!(sector[searchsector].ceilingstat&2)) + sector[searchsector].ceilingheinum = 0; + sector[searchsector].ceilingheinum = min(sector[searchsector].ceilingheinum+i,32767); + } + if (searchstat == 2) + { + if (!(sector[searchsector].floorstat&2)) + sector[searchsector].floorheinum = 0; + sector[searchsector].floorheinum = min(sector[searchsector].floorheinum+i,32767); + } + } + + if (sector[searchsector].ceilingheinum == 0) + sector[searchsector].ceilingstat &= ~2; + else + sector[searchsector].ceilingstat |= 2; + + if (sector[searchsector].floorheinum == 0) + sector[searchsector].floorstat &= ~2; + else + sector[searchsector].floorstat |= 2; + + asksave = 1; + } + + smooshyalign = keystatus[0x4c]; + repeatpanalign = (keystatus[0x2a]|keystatus[0x36]); + if ((keystatus[0x4b]|keystatus[0x4d]) > 0) // 4 & 6 (keypad) + { + if ((repeatcountx == 0) || (repeatcountx > 16)) + { + changedir = 0; + if (keystatus[0x4b] > 0) changedir = -1; + if (keystatus[0x4d] > 0) changedir = 1; + + if ((searchstat == 0) || (searchstat == 4)) + { + if (repeatpanalign == 0) + wall[searchwall].xrepeat = changechar(wall[searchwall].xrepeat,changedir,smooshyalign,1); + else + wall[searchwall].xpanning = changechar(wall[searchwall].xpanning,changedir,smooshyalign,0); + } + if ((searchstat == 1) || (searchstat == 2)) + { + if (searchstat == 1) + sector[searchsector].ceilingxpanning = changechar(sector[searchsector].ceilingxpanning,changedir,smooshyalign,0); + else + sector[searchsector].floorxpanning = changechar(sector[searchsector].floorxpanning,changedir,smooshyalign,0); + } + if (searchstat == 3) + { + sprite[searchwall].xrepeat = changechar(sprite[searchwall].xrepeat,changedir,smooshyalign,1); + if (sprite[searchwall].xrepeat < 4) + sprite[searchwall].xrepeat = 4; + } + asksave = 1; + repeatcountx = max(1,repeatcountx); + } + repeatcountx += (synctics>>1); + } + else + repeatcountx = 0; + + if ((keystatus[0x48]|keystatus[0x50]) > 0) // 2 & 8 (keypad) + { + if ((repeatcounty == 0) || (repeatcounty > 16)) + { + changedir = 0; + if (keystatus[0x48] > 0) changedir = -1; + if (keystatus[0x50] > 0) changedir = 1; + + if ((searchstat == 0) || (searchstat == 4)) + { + if (repeatpanalign == 0) + wall[searchwall].yrepeat = changechar(wall[searchwall].yrepeat,changedir,smooshyalign,1); + else + wall[searchwall].ypanning = changechar(wall[searchwall].ypanning,changedir,smooshyalign,0); + } + if ((searchstat == 1) || (searchstat == 2)) + { + if (searchstat == 1) + sector[searchsector].ceilingypanning = changechar(sector[searchsector].ceilingypanning,changedir,smooshyalign,0); + else + sector[searchsector].floorypanning = changechar(sector[searchsector].floorypanning,changedir,smooshyalign,0); + } + if (searchstat == 3) + { + sprite[searchwall].yrepeat = changechar(sprite[searchwall].yrepeat,changedir,smooshyalign,1); + if (sprite[searchwall].yrepeat < 4) + sprite[searchwall].yrepeat = 4; + } + asksave = 1; + repeatcounty = max(1,repeatcounty); + } + repeatcounty += (synctics>>1); + //} + } + else + repeatcounty = 0; + + if (keystatus[0x33] > 0) // , Search & fix panning to the left (3D) + { + if (searchstat == 3) + { + i = searchwall; + if ((keystatus[0x2a]|keystatus[0x36]) > 0) + sprite[i].ang = ((sprite[i].ang+2048-1)&2047); + else + { + sprite[i].ang = ((sprite[i].ang+2048-128)&2047); + keystatus[0x33] = 0; + } + } + } + if (keystatus[0x34] > 0) // . Search & fix panning to the right (3D) + { + if ((searchstat == 0) || (searchstat == 4)) + { + AutoAlignWalls((long)searchwall,0L); + + /*wallfind[0] = searchwall; + cnt = 4096; + do + { + wallfind[1] = wall[wallfind[0]].point2; + j = -1; + if (wall[wallfind[1]].picnum == wall[searchwall].picnum) + j = wallfind[1]; + k = wallfind[1]; + + while ((wall[wallfind[1]].nextwall >= 0) && (wall[wall[wallfind[1]].nextwall].point2 != k)) + { + i = wall[wall[wallfind[1]].nextwall].point2; //break if going around in circles on red lines with same picture on both sides + if (wallfind[1] == wall[wall[i].nextwall].point2) + break; + + wallfind[1] = wall[wall[wallfind[1]].nextwall].point2; + if (wall[wallfind[1]].picnum == wall[searchwall].picnum) + j = wallfind[1]; + } + wallfind[1] = j; + + if ((j >= 0) && (wallfind[1] != searchwall)) + { + j = (wall[wallfind[0]].xpanning+(wall[wallfind[0]].xrepeat<<3)) % tilesizx[wall[wallfind[0]].picnum]; + wall[wallfind[1]].cstat &= ~8; //Set to non-flip + wall[wallfind[1]].cstat |= 4; //Set y-orientation + wall[wallfind[1]].xpanning = j; + + for(k=0;k<2;k++) + { + sectnum = sectorofwall((short)wallfind[k]); + nextsectnum = wall[wallfind[k]].nextsector; + + if (nextsectnum == -1) + { + if ((wall[wallfind[k]].cstat&4) == 0) + daz[k] = sector[sectnum].ceilingz; + else + daz[k] = sector[sectnum].floorz; + } + else //topstep + { + if (sector[nextsectnum].ceilingz > sector[sectnum].ceilingz) + daz[k] = sector[nextsectnum].ceilingz; + else if (sector[nextsectnum].floorz < sector[sectnum].floorz) + daz[k] = sector[nextsectnum].floorz; + } + } + + j = (picsiz[wall[searchwall].picnum]>>4); + if ((1<>(j+3)))&255); + wall[wallfind[1]].ypanning = j; + wall[wallfind[1]].yrepeat = wall[wallfind[0]].yrepeat; + if (nextsectnum >= 0) + if (sector[nextsectnum].ceilingz >= sector[sectnum].ceilingz) + if (sector[nextsectnum].floorz <= sector[sectnum].floorz) + { + if (wall[wall[wallfind[1]].nextwall].picnum == wall[searchwall].picnum) + { + wall[wall[wallfind[1]].nextwall].yrepeat = wall[wallfind[0]].yrepeat; + if ((wall[wall[wallfind[1]].nextwall].cstat&4) == 0) + daz[1] = sector[nextsectnum].floorz; + else + daz[1] = sector[sectnum].ceilingz; + wall[wall[wallfind[1]].nextwall].ypanning = j; + } + } + } + wallfind[0] = wallfind[1]; + cnt--; + } + while ((wall[wallfind[0]].picnum == wall[searchwall].picnum) && (wallfind[0] != searchwall) && (cnt > 0)); + */ + + keystatus[0x34] = 0; + } + if (searchstat == 3) + { + i = searchwall; + if ((keystatus[0x2a]|keystatus[0x36]) > 0) + sprite[i].ang = ((sprite[i].ang+2048+1)&2047); + else + { + sprite[i].ang = ((sprite[i].ang+2048+128)&2047); + keystatus[0x34] = 0; + } + } + } + if (keystatus[0x35] > 0) // /? Reset panning&repeat to 0 + { + if ((searchstat == 0) || (searchstat == 4)) + { + wall[searchwall].xpanning = 0; + wall[searchwall].ypanning = 0; + wall[searchwall].xrepeat = 8; + wall[searchwall].yrepeat = 8; + wall[searchwall].cstat = 0; + fixrepeats((short)searchwall); + } + if (searchstat == 1) + { + sector[searchsector].ceilingxpanning = 0; + sector[searchsector].ceilingypanning = 0; + sector[searchsector].ceilingstat &= ~2; + sector[searchsector].ceilingheinum = 0; + } + if (searchstat == 2) + { + sector[searchsector].floorxpanning = 0; + sector[searchsector].floorypanning = 0; + sector[searchsector].floorstat &= ~2; + sector[searchsector].floorheinum = 0; + } + if (searchstat == 3) + { + if ((keystatus[0x2a]|keystatus[0x36]) > 0) + { + sprite[searchwall].xrepeat = sprite[searchwall].yrepeat; + } + else + { + sprite[searchwall].xrepeat = 64; + sprite[searchwall].yrepeat = 64; + } + } + keystatus[0x35] = 0; + asksave = 1; + } + + if (keystatus[0x19] > 0) // P (parallaxing sky) + { + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) + { + parallaxtype++; + if (parallaxtype == 3) + parallaxtype = 0; + } + else if ((keystatus[0x38]|keystatus[0xb8]) > 0) + { + switch (searchstat) + { + case 0: case 4: + Bstrcpy(buffer,"Wall pal: "); + wall[searchwall].pal = getnumber256(buffer,wall[searchwall].pal,256L,0); + break; + case 1: + Bstrcpy(buffer,"Ceiling pal: "); + sector[searchsector].ceilingpal = getnumber256(buffer,sector[searchsector].ceilingpal,256L,0); + break; + case 2: + Bstrcpy(buffer,"Floor pal: "); + sector[searchsector].floorpal = getnumber256(buffer,sector[searchsector].floorpal,256L,0); + break; + case 3: + Bstrcpy(buffer,"Sprite pal: "); + sprite[searchwall].pal = getnumber256(buffer,sprite[searchwall].pal,256L,0); + break; + } + } + else + { + if ((searchstat == 0) || (searchstat == 1) || (searchstat == 4)) + { + sector[searchsector].ceilingstat ^= 1; + asksave = 1; + } + else if (searchstat == 2) + { + sector[searchsector].floorstat ^= 1; + asksave = 1; + } + } + keystatus[0x19] = 0; + } + + if (keystatus[0x20] != 0) //Alt-D (adjust sprite[].clipdist) + { + keystatus[0x20] = 0; + if ((keystatus[0x38]|keystatus[0xb8]) > 0) + { + if (searchstat == 3) + { + Bstrcpy(buffer,"Sprite clipdist: "); + sprite[searchwall].clipdist = getnumber256(buffer,sprite[searchwall].clipdist,256L,0); + } + } + } + + if (keystatus[0x30] > 0) // B (clip Blocking xor) (3D) + { + if (searchstat == 3) + { + sprite[searchwall].cstat ^= 1; + sprite[searchwall].cstat &= ~256; + sprite[searchwall].cstat |= ((sprite[searchwall].cstat&1)<<8); + asksave = 1; + } + else + { + wall[searchwall].cstat ^= 1; + wall[searchwall].cstat &= ~64; + if ((wall[searchwall].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + { + wall[wall[searchwall].nextwall].cstat &= ~(1+64); + wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&1); + } + asksave = 1; + } + keystatus[0x30] = 0; + } + if (keystatus[0x14] > 0) // T (transluscence for sprites/masked walls) + { + /*if (searchstat == 1) //Set masked/transluscent ceilings/floors + { + i = (sector[searchsector].ceilingstat&(128+256)); + sector[searchsector].ceilingstat &= ~(128+256); + switch(i) + { + case 0: sector[searchsector].ceilingstat |= 128; break; + case 128: sector[searchsector].ceilingstat |= 256; break; + case 256: sector[searchsector].ceilingstat |= 384; break; + case 384: sector[searchsector].ceilingstat |= 0; break; + } + asksave = 1; + } + if (searchstat == 2) + { + i = (sector[searchsector].floorstat&(128+256)); + sector[searchsector].floorstat &= ~(128+256); + switch(i) + { + case 0: sector[searchsector].floorstat |= 128; break; + case 128: sector[searchsector].floorstat |= 256; break; + case 256: sector[searchsector].floorstat |= 384; break; + case 384: sector[searchsector].floorstat |= 0; break; + } + asksave = 1; + }*/ + if (searchstat == 3) + { + if ((sprite[searchwall].cstat&2) == 0) + sprite[searchwall].cstat |= 2; + else if ((sprite[searchwall].cstat&512) == 0) + sprite[searchwall].cstat |= 512; + else + sprite[searchwall].cstat &= ~(2+512); + asksave = 1; + } + if (searchstat == 4) + { + if ((wall[searchwall].cstat&128) == 0) + wall[searchwall].cstat |= 128; + else if ((wall[searchwall].cstat&512) == 0) + wall[searchwall].cstat |= 512; + else + wall[searchwall].cstat &= ~(128+512); + + if (wall[searchwall].nextwall >= 0) + { + wall[wall[searchwall].nextwall].cstat &= ~(128+512); + wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&(128+512)); + } + asksave = 1; + } + keystatus[0x14] = 0; + } + + if (keystatus[0x2] > 0) // 1 (make 1-way wall) + { + if (searchstat != 3) + { + wall[searchwall].cstat ^= 32; + asksave = 1; + } + else + { + sprite[searchwall].cstat ^= 64; + i = sprite[searchwall].cstat; + if ((i&48) == 32) + { + sprite[searchwall].cstat &= ~8; + if ((i&64) > 0) + if (posz > sprite[searchwall].z) + sprite[searchwall].cstat |= 8; + } + asksave = 1; + } + keystatus[0x2] = 0; + } + if (keystatus[0x3] > 0) // 2 (bottom wall swapping) + { + if (searchstat != 3) + { + wall[searchwall].cstat ^= 2; + asksave = 1; + } + keystatus[0x3] = 0; + } + if (keystatus[0x18] > 0) // O (top/bottom orientation - for doors) + { + if ((searchstat == 0) || (searchstat == 4)) + { + wall[searchwall].cstat ^= 4; + asksave = 1; + } + if (searchstat == 3) // O (ornament onto wall) (2D) + { + asksave = 1; + i = searchwall; + + hitscan(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum, + sintable[(sprite[i].ang+2560+1024)&2047], + sintable[(sprite[i].ang+2048+1024)&2047], + 0, + &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + + sprite[i].x = hitx; + sprite[i].y = hity; + sprite[i].z = hitz; + changespritesect(i,hitsect); + if (hitwall >= 0) + sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); + + //Make sure sprite's in right sector + if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) + { + j = wall[hitwall].point2; + sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); + sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); + } + } + keystatus[0x18] = 0; + } + if (keystatus[0x32] > 0) // M (masking walls) + { + if (searchstat != 3) + { + i = wall[searchwall].nextwall; + templong = (keystatus[0x2a]|keystatus[0x36]); + if (i >= 0) + { + wall[searchwall].cstat ^= 16; + if ((wall[searchwall].cstat&16) > 0) + { + wall[searchwall].cstat &= ~8; + if (templong == 0) + { + wall[i].cstat |= 8; //auto other-side flip + wall[i].cstat |= 16; + wall[i].overpicnum = wall[searchwall].overpicnum; + } + } + else + { + wall[searchwall].cstat &= ~8; + if (templong == 0) + { + wall[i].cstat &= ~8; //auto other-side unflip + wall[i].cstat &= ~16; + } + } + wall[searchwall].cstat &= ~32; + if (templong == 0) wall[i].cstat &= ~32; + asksave = 1; + } + } + keystatus[0x32] = 0; + } + if (keystatus[0x23] > 0) // H (hitscan sensitivity) + { + if (searchstat == 3) + { + sprite[searchwall].cstat ^= 256; + asksave = 1; + } + else + { + wall[searchwall].cstat ^= 64; + if ((wall[searchwall].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + { + wall[wall[searchwall].nextwall].cstat &= ~64; + wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&64); + } + asksave = 1; + } + keystatus[0x23] = 0; + } + if (keystatus[0x12] > 0) // E (expand) + { + if (searchstat == 1) + { + sector[searchsector].ceilingstat ^= 8; + asksave = 1; + } + if (searchstat == 2) + { + sector[searchsector].floorstat ^= 8; + asksave = 1; + } + keystatus[0x12] = 0; + } + if (keystatus[0x13] > 0) // R (relative alignment, rotation) + { + if (searchstat == 1) + { + sector[searchsector].ceilingstat ^= 64; + asksave = 1; + } + if (searchstat == 2) + { + sector[searchsector].floorstat ^= 64; + asksave = 1; + } + if (searchstat == 3) + { + i = sprite[searchwall].cstat; + if ((i&48) < 32) i += 16; else i &= ~48; + sprite[searchwall].cstat = i; + asksave = 1; + } + keystatus[0x13] = 0; + } + if (keystatus[0x21] > 0) //F (Flip) + { + keystatus[0x21] = 0; + if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT-F (relative alignmment flip) + { + if (searchstat != 3) + { + setfirstwall(searchsector,searchwall); + asksave = 1; + } + } + else + { + if ((searchstat == 0) || (searchstat == 4)) + { + i = wall[searchwall].cstat; + i = ((i>>3)&1)+((i>>7)&2); //3-x,8-y + switch(i) + { + case 0: i = 1; break; + case 1: i = 3; break; + case 2: i = 0; break; + case 3: i = 2; break; + } + i = ((i&1)<<3)+((i&2)<<7); + wall[searchwall].cstat &= ~0x0108; + wall[searchwall].cstat |= i; + asksave = 1; + } + if (searchstat == 1) //8-way ceiling flipping (bits 2,4,5) + { + i = sector[searchsector].ceilingstat; + i = (i&0x4)+((i>>4)&3); + switch(i) + { + case 0: i = 6; break; + case 6: i = 3; break; + case 3: i = 5; break; + case 5: i = 1; break; + case 1: i = 7; break; + case 7: i = 2; break; + case 2: i = 4; break; + case 4: i = 0; break; + } + i = (i&0x4)+((i&3)<<4); + sector[searchsector].ceilingstat &= ~0x34; + sector[searchsector].ceilingstat |= i; + asksave = 1; + } + if (searchstat == 2) //8-way floor flipping (bits 2,4,5) + { + i = sector[searchsector].floorstat; + i = (i&0x4)+((i>>4)&3); + switch(i) + { + case 0: i = 6; break; + case 6: i = 3; break; + case 3: i = 5; break; + case 5: i = 1; break; + case 1: i = 7; break; + case 7: i = 2; break; + case 2: i = 4; break; + case 4: i = 0; break; + } + i = (i&0x4)+((i&3)<<4); + sector[searchsector].floorstat &= ~0x34; + sector[searchsector].floorstat |= i; + asksave = 1; + } + if (searchstat == 3) + { + i = sprite[searchwall].cstat; + if (((i&48) == 32) && ((i&64) == 0)) + { + sprite[searchwall].cstat &= ~0xc; + sprite[searchwall].cstat |= (i&4)^4; + } + else + { + i = ((i>>2)&3); + switch(i) + { + case 0: i = 1; break; + case 1: i = 3; break; + case 2: i = 0; break; + case 3: i = 2; break; + } + i <<= 2; + sprite[searchwall].cstat &= ~0xc; + sprite[searchwall].cstat |= i; + } + asksave = 1; + } + } + } + if (keystatus[0x1f] > 0) //S (insert sprite) (3D) + { + dax = 16384; + day = divscale14(searchx-(xdim>>1),xdim>>1); + rotatepoint(0,0,dax,day,ang,&dax,&day); + + hitscan(posx,posy,posz,cursectnum, //Start position + dax,day,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang + &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + + if (hitsect >= 0) + { + dax = hitx; + day = hity; + if ((gridlock > 0) && (grid > 0)) + { + if ((searchstat == 0) || (searchstat == 4)) + { + hitz = (hitz&0xfffffc00); + } + else + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + } + + i = insertsprite(hitsect,0); + sprite[i].x = dax, sprite[i].y = day; + sprite[i].cstat = defaultspritecstat; + sprite[i].shade = 0; + sprite[i].pal = 0; + sprite[i].xrepeat = 64, sprite[i].yrepeat = 64; + sprite[i].xoffset = 0, sprite[i].yoffset = 0; + sprite[i].ang = 1536; + sprite[i].xvel = 0; sprite[i].yvel = 0; sprite[i].zvel = 0; + sprite[i].owner = -1; + sprite[i].clipdist = 32; + sprite[i].lotag = 0; + sprite[i].hitag = 0; + sprite[i].extra = -1; + + for(k=0;k localartfreq[j]) + j = k; + if (localartfreq[j] > 0) + sprite[i].picnum = j; + else + sprite[i].picnum = 0; + + if (somethingintab == 3) + { + sprite[i].picnum = temppicnum; + if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) + { + j = 0; + for(k=0;k 0) && (tilesizy[k] > 0)) + { + j = k; + break; + } + sprite[i].picnum = j; + } + sprite[i].shade = tempshade; + sprite[i].pal = temppal; + sprite[i].xrepeat = tempxrepeat; + sprite[i].yrepeat = tempyrepeat; + if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; + if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; + sprite[i].cstat = tempcstat; + } + + j = ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + if ((sprite[i].cstat&128) == 0) + sprite[i].z = min(max(hitz,getceilzofslope(hitsect,hitx,hity)+(j<<1)),getflorzofslope(hitsect,hitx,hity)); + else + sprite[i].z = min(max(hitz,getceilzofslope(hitsect,hitx,hity)+j),getflorzofslope(hitsect,hitx,hity)-j); + + if ((searchstat == 0) || (searchstat == 4)) + { + sprite[i].cstat = (sprite[i].cstat&~48)|(16+64); + if (hitwall >= 0) + sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); + + //Make sure sprite's in right sector + if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) + { + j = wall[hitwall].point2; + sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); + sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); + } + } + else + { + if (tilesizy[sprite[i].picnum] >= 32) sprite[i].cstat |= 1; + } + + updatenumsprites(); + asksave = 1; + } + + keystatus[0x1f] = 0; + } + if (keystatus[0xd3] > 0) + { + if (searchstat == 3) + { + deletesprite(searchwall); + updatenumsprites(); + asksave = 1; + } + keystatus[0xd3] = 0; + } + + if ((keystatus[0x3f]|keystatus[0x40]) > 0) //F5,F6 + { + switch(searchstat) + { + case 1: case 2: ExtShowSectorData(searchsector); break; + case 0: case 4: ExtShowWallData(searchwall); break; + case 3: ExtShowSpriteData(searchwall); break; + } + keystatus[0x3f] = 0, keystatus[0x40] = 0; + } + if ((keystatus[0x41]|keystatus[0x42]) > 0) //F7,F8 + { + switch(searchstat) + { + case 1: case 2: ExtEditSectorData(searchsector); break; + case 0: case 4: ExtEditWallData(searchwall); break; + case 3: ExtEditSpriteData(searchwall); break; + } + keystatus[0x41] = 0, keystatus[0x42] = 0; + } + + } + if (keystatus[buildkeys[14]] > 0) // Enter + { + overheadeditor(); + keystatus[buildkeys[14]] = 0; + } } char changechar(char dachar, long dadir, char smooshyalign, char boundcheck) { - if (dadir < 0) - { - if ((dachar > 0) || (boundcheck == 0)) - { - dachar--; - if (smooshyalign > 0) - dachar = (dachar&0xf8); - } - } - else if (dadir > 0) - { - if ((dachar < 255) || (boundcheck == 0)) - { - dachar++; - if (smooshyalign > 0) - { - if (dachar >= 256-8) dachar = 255; - else dachar = ((dachar+7)&0xf8); - } - } - } - return(dachar); + if (dadir < 0) + { + if ((dachar > 0) || (boundcheck == 0)) + { + dachar--; + if (smooshyalign > 0) + dachar = (dachar&0xf8); + } + } + else if (dadir > 0) + { + if ((dachar < 255) || (boundcheck == 0)) + { + dachar++; + if (smooshyalign > 0) + { + if (dachar >= 256-8) dachar = 255; + else dachar = ((dachar+7)&0xf8); + } + } + } + return(dachar); } long gettile(long tilenum) { - char snotbuf[80], ch; - long i, j, k, otilenum, topleft, gap, temp, templong; - long xtiles, ytiles, tottiles; + char snotbuf[80], ch; + long i, j, k, otilenum, topleft, gap, temp, templong; + long xtiles, ytiles, tottiles; - if (tilenum < 0) tilenum = 0; + if (tilenum < 0) tilenum = 0; - xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles; - otilenum = tilenum; + xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles; + otilenum = tilenum; - keystatus[0x2f] = 0; - for(i=0;i>1); - do - { - for(i=0;i= 0)) - { - templong = localartfreq[temp]; - localartfreq[temp] = localartfreq[temp+gap]; - localartfreq[temp+gap] = templong; - templong = localartlookup[temp]; - localartlookup[temp] = localartlookup[temp+gap]; - localartlookup[temp+gap] = templong; + keystatus[0x2f] = 0; + for(i=0;i>1); + do + { + for(i=0;i= 0)) + { + templong = localartfreq[temp]; + localartfreq[temp] = localartfreq[temp+gap]; + localartfreq[temp+gap] = templong; + templong = localartlookup[temp]; + localartlookup[temp] = localartlookup[temp+gap]; + localartlookup[temp+gap] = templong; - if (tilenum == temp) - tilenum = temp+gap; - else if (tilenum == temp+gap) - tilenum = temp; + if (tilenum == temp) + tilenum = temp+gap; + else if (tilenum == temp+gap) + tilenum = temp; - temp -= gap; - } - } - gap >>= 1; - } - while (gap > 0); - localartlookupnum = 0; - while (localartfreq[localartlookupnum] > 0) - localartlookupnum++; + temp -= gap; + } + } + gap >>= 1; + } + while (gap > 0); + localartlookupnum = 0; + while (localartfreq[localartlookupnum] > 0) + localartlookupnum++; - if (localartfreq[0] == 0) - { - tilenum = otilenum; - localartlookupnum = MAXTILES; - for(i=0;i MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); - while ((keystatus[0x1c]|keystatus[1]) == 0) - { - drawtilescreen(topleft,tilenum); + topleft = ((tilenum/(xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); + while ((keystatus[0x1c]|keystatus[1]) == 0) + { + drawtilescreen(topleft,tilenum); - if (handleevents()) { - if (quitevent) quitevent = 0; - } + if (handleevents()) { + if (quitevent) quitevent = 0; + } - synctics = totalclock-lockclock; - lockclock += synctics; + synctics = totalclock-lockclock; + lockclock += synctics; - if ((keystatus[0x37] > 0) && (gettilezoom < 2)) - { - gettilezoom++; - topleft = ((tilenum/(xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); - keystatus[0x37] = 0; - } - if ((keystatus[0xb5] > 0) && (gettilezoom > 0)) - { - gettilezoom--; - topleft = ((tilenum/(xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); - keystatus[0xb5] = 0; - } - if ((keystatus[0xcb] > 0) && (tilenum > 0)) - tilenum--, keystatus[0xcb] = 0; - if ((keystatus[0xcd] > 0) && (tilenum < MAXTILES-1)) - tilenum++, keystatus[0xcd] = 0; - if ((keystatus[0xc8] > 0) && (tilenum >= (xtiles< 0) && (tilenum < MAXTILES-(xtiles< 0) && (tilenum >= (xtiles< 0) && (tilenum < MAXTILES-(xtiles<= MAXTILES) tilenum = MAXTILES-1; - keystatus[0xd1] = 0; - } - if (keystatus[0x2f] > 0) //V - { - keystatus[0x2f] = 0; - if (tilenum < localartlookupnum) - tilenum = localartlookup[tilenum]; - else - tilenum = 0; - localartlookupnum = MAXTILES; - for(i=0;i 0) //G (goto) - { - if (tilenum < localartlookupnum) //Automatically press 'V' - tilenum = localartlookup[tilenum]; - else - tilenum = 0; - localartlookupnum = MAXTILES; - for(i=0;i 0) && (gettilezoom < 2)) + { + gettilezoom++; + topleft = ((tilenum/(xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); + keystatus[0x37] = 0; + } + if ((keystatus[0xb5] > 0) && (gettilezoom > 0)) + { + gettilezoom--; + topleft = ((tilenum/(xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); + keystatus[0xb5] = 0; + } + if ((keystatus[0xcb] > 0) && (tilenum > 0)) + tilenum--, keystatus[0xcb] = 0; + if ((keystatus[0xcd] > 0) && (tilenum < MAXTILES-1)) + tilenum++, keystatus[0xcd] = 0; + if ((keystatus[0xc8] > 0) && (tilenum >= (xtiles< 0) && (tilenum < MAXTILES-(xtiles< 0) && (tilenum >= (xtiles< 0) && (tilenum < MAXTILES-(xtiles<= MAXTILES) tilenum = MAXTILES-1; + keystatus[0xd1] = 0; + } + if (keystatus[0x2f] > 0) //V + { + keystatus[0x2f] = 0; + if (tilenum < localartlookupnum) + tilenum = localartlookup[tilenum]; + else + tilenum = 0; + localartlookupnum = MAXTILES; + for(i=0;i 0) //G (goto) + { + if (tilenum < localartlookupnum) //Automatically press 'V' + tilenum = localartlookup[tilenum]; + else + tilenum = 0; + localartlookupnum = MAXTILES; + for(i=0;i= '0' && ch <= '9') { - i = (j*10)+(ch-'0'); - if (i < MAXTILES) j = i; - } else if (ch == 8) { - j /= 10; - } else if (ch == 13) { - tilenum = j; - break; - } - } - clearkeys(); - } - while (tilenum < topleft) topleft -= (xtiles<= topleft+(tottiles<<(gettilezoom<<1))) topleft += (xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); - } + if (ch >= '0' && ch <= '9') { + i = (j*10)+(ch-'0'); + if (i < MAXTILES) j = i; + } else if (ch == 8) { + j /= 10; + } else if (ch == 13) { + tilenum = j; + break; + } + } + clearkeys(); + } + while (tilenum < topleft) topleft -= (xtiles<= topleft+(tottiles<<(gettilezoom<<1))) topleft += (xtiles< MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); + } - if (keystatus[0x1c] == 0) - { - tilenum = otilenum; - } - else - { - if (tilenum < localartlookupnum) - { - tilenum = localartlookup[tilenum]; - if ((tilesizx[tilenum] == 0) || (tilesizy[tilenum] == 0)) - tilenum = otilenum; - } - else - tilenum = otilenum; - } - keystatus[0x1] = 0; - keystatus[0x1c] = 0; - return(tilenum); + if (keystatus[0x1c] == 0) + { + tilenum = otilenum; + } + else + { + if (tilenum < localartlookupnum) + { + tilenum = localartlookup[tilenum]; + if ((tilesizx[tilenum] == 0) || (tilesizy[tilenum] == 0)) + tilenum = otilenum; + } + else + tilenum = otilenum; + } + keystatus[0x1] = 0; + keystatus[0x1c] = 0; + return(tilenum); } long drawtilescreen(long pictopleft, long picbox) { - long i, j, vidpos, vidpos2, dat, wallnum, xdime, ydime, cnt, pinc; - long dax, day, scaledown, xtiles, ytiles, tottiles; - char *picptr, snotbuf[80]; + long i, j, vidpos, vidpos2, dat, wallnum, xdime, ydime, cnt, pinc; + long dax, day, scaledown, xtiles, ytiles, tottiles; + char *picptr, snotbuf[80]; - xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles; + xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles; - begindrawing(); //{{{ + begindrawing(); //{{{ - setpolymost2dview(); // JBF 20040205: set to 2d rendering - - pinc = ylookup[1]; - clearview(0L); - for(cnt=0;cnt<(tottiles<<(gettilezoom<<1));cnt++) //draw the 5*3 grid of tiles - { - wallnum = cnt+pictopleft; - if (wallnum < localartlookupnum) - { - wallnum = localartlookup[wallnum]; - if ((tilesizx[wallnum] != 0) && (tilesizy[wallnum] != 0)) - { - if (waloff[wallnum] == 0) loadtile(wallnum); - picptr = (char *)(waloff[wallnum]); - xdime = tilesizx[wallnum]; - ydime = tilesizy[wallnum]; + setpolymost2dview(); // JBF 20040205: set to 2d rendering - dax = ((cnt%(xtiles<>gettilezoom)) { - vidpos = ylookup[day]+dax+frameplace; - if ((xdime <= (64>>gettilezoom)) && (ydime <= (64>>gettilezoom))) - { - for(i=0;i 64 - { - if (xdime > ydime) - scaledown = ((xdime+(63>>gettilezoom))>>(6-gettilezoom)); - else - scaledown = ((ydime+(63>>gettilezoom))>>(6-gettilezoom)); + pinc = ylookup[1]; + clearview(0L); + for(cnt=0;cnt<(tottiles<<(gettilezoom<<1));cnt++) //draw the 5*3 grid of tiles + { + wallnum = cnt+pictopleft; + if (wallnum < localartlookupnum) + { + wallnum = localartlookup[wallnum]; + if ((tilesizx[wallnum] != 0) && (tilesizy[wallnum] != 0)) + { + if (waloff[wallnum] == 0) loadtile(wallnum); + picptr = (char *)(waloff[wallnum]); + xdime = tilesizx[wallnum]; + ydime = tilesizy[wallnum]; - for(i=0;i>gettilezoom)) { + vidpos = ylookup[day]+dax+frameplace; + if ((xdime <= (64>>gettilezoom)) && (ydime <= (64>>gettilezoom))) + { + for(i=0;i 64 + { + if (xdime > ydime) + scaledown = ((xdime+(63>>gettilezoom))>>(6-gettilezoom)); + else + scaledown = ((ydime+(63>>gettilezoom))>>(6-gettilezoom)); - cnt = picbox-pictopleft; //draw open white box - dax = ((cnt%(xtiles<>gettilezoom);i++) - { - plotpixel(dax+i,day,whitecol); - plotpixel(dax+i,day+(63>>gettilezoom),whitecol); - plotpixel(dax,day+i,whitecol); - plotpixel(dax+(63>>gettilezoom),day+i,whitecol); - } + cnt = picbox-pictopleft; //draw open white box + dax = ((cnt%(xtiles<>gettilezoom);i++) + { + plotpixel(dax+i,day,whitecol); + plotpixel(dax+i,day+(63>>gettilezoom),whitecol); + plotpixel(dax,day+i,whitecol); + plotpixel(dax+(63>>gettilezoom),day+i,whitecol); + } - Bsprintf(snotbuf,"%dx%d",tilesizx[i],tilesizy[i]); + i = localartlookup[picbox]; + Bsprintf(snotbuf,"%ld",i); + printext256(0L,ydim-8,whitecol,-1,snotbuf,0); + printext256(xdim-(Bstrlen(names[i])<<3),ydim-8,whitecol,-1,names[i],0); + + Bsprintf(snotbuf,"%dx%d",tilesizx[i],tilesizy[i]); printext256(xdim>>2,ydim-8,whitecol,-1,snotbuf,0); - enddrawing(); //}}} - showframe(1); + enddrawing(); //}}} + showframe(1); - return(0); + return(0); } void overheadeditor(void) { - char buffer[80], *dabuffer, ch; - long i, j, k, m=0, mousxplc, mousyplc, firstx=0, firsty=0, oposz, col; - long templong, templong1, templong2, doubvel; + char buffer[80], *dabuffer, ch; + long i, j, k, m=0, mousxplc, mousyplc, firstx=0, firsty=0, oposz, col; + long templong, templong1, templong2, doubvel; long startwall=0, endwall, dax, day, daz, x1, y1, x2, y2, x3, y3, x4, y4; - long highlightx1, highlighty1, highlightx2, highlighty2, xvect, yvect; - short pag, suckwall=0, sucksect, newnumwalls, newnumsectors, split=0, bad; - short splitsect=0, danumwalls, secondstartwall, joinsector[2], joinsectnum; - short splitstartwall=0, splitendwall, loopnum; - long mousx, mousy, bstatus; - long centerx, centery, circlerad; - short circlewall, circlepoints, circleang1, circleang2, circleangdir; - long sectorhighlightx=0, sectorhighlighty=0; - short cursectorhighlight, sectorhighlightstat; - short hitsect, hitwall, hitsprite; - long hitx, hity, hitz; - walltype *wal; + long highlightx1, highlighty1, highlightx2, highlighty2, xvect, yvect; + short pag, suckwall=0, sucksect, newnumwalls, newnumsectors, split=0, bad; + short splitsect=0, danumwalls, secondstartwall, joinsector[2], joinsectnum; + short splitstartwall=0, splitendwall, loopnum; + long mousx, mousy, bstatus; + long centerx, centery, circlerad; + short circlewall, circlepoints, circleang1, circleang2, circleangdir; + long sectorhighlightx=0, sectorhighlighty=0; + short cursectorhighlight, sectorhighlightstat; + short hitsect, hitwall, hitsprite; + long hitx, hity, hitz; + walltype *wal; - //qsetmode640480(); - qsetmodeany(xdim2d,ydim2d); - xdim2d = xdim; - ydim2d = ydim; + //qsetmode640480(); + qsetmodeany(xdim2d,ydim2d); + xdim2d = xdim; + ydim2d = ydim; osearchx = searchx; osearchy = searchy; - searchx = scale(searchx,xdim2d,xdimgame); - searchy = scale(searchy,ydim2d-STATUS2DSIZ,ydimgame); - oposz = posz; + searchx = scale(searchx,xdim2d,xdimgame); + searchy = scale(searchy,ydim2d-STATUS2DSIZ,ydimgame); + oposz = posz; - begindrawing(); //{{{ + begindrawing(); //{{{ clearbuf((char *)(frameplace + (ydim16*bytesperline)), (bytesperline*STATUS2DSIZ) >> 2, 0x00000000l); clearbuf((char *)frameplace, (ydim16*bytesperline) >> 2, 0L); - ydim16 = ydim; + ydim16 = ydim; drawline16(0,ydim-STATUS2DSIZ,xdim-1,ydim-STATUS2DSIZ,1); drawline16(0,ydim-1,xdim-1,ydim-1,1); drawline16(0,ydim-STATUS2DSIZ,0,ydim-1,1); drawline16(xdim-1,ydim-STATUS2DSIZ,xdim-1,ydim-1,1); drawline16(0,ydim-STATUS2DSIZ+24,xdim-1,ydim-STATUS2DSIZ+24,1); drawline16(192,ydim-STATUS2DSIZ,192,ydim-STATUS2DSIZ+24,1); - if (totalclock < 120*5) printext16(8L,ydim-STATUS2DSIZ+32L,9,-1,kensig,0); + if (totalclock < 120*5) printext16(8L,ydim-STATUS2DSIZ+32L,9,-1,kensig,0); Bsprintf(tempbuf,"Mapster32"); printext16(9L,ydim-STATUS2DSIZ+9L,4,-1,tempbuf,0); printext16(8L,ydim-STATUS2DSIZ+8L,12,-1,tempbuf,0); -// printmessage16("Version: "VERSION); + // printmessage16("Version: "VERSION); if (totalclock < 30) printmessage16("Press F1 for help"); drawline16(0,ydim-1-20,xdim-1,ydim-1-20,1); drawline16(256,ydim-1-20,256,ydim-1,1); - ydim16 = ydim-STATUS2DSIZ; - enddrawing(); //}}} + ydim16 = ydim-STATUS2DSIZ; + enddrawing(); //}}} - pag = 0; - highlightcnt = -1; - cursectorhighlight = -1; + pag = 0; + highlightcnt = -1; + cursectorhighlight = -1; lastpm16time = -1; - //White out all bordering lines of grab that are - //not highlighted on both sides - for(i=highlightsectorcnt-1;i>=0;i--) - { - startwall = sector[highlightsector[i]].wallptr; - endwall = startwall + sector[highlightsector[i]].wallnum; - for(j=startwall;j= 0) - { - for(k=highlightsectorcnt-1;k>=0;k--) - if (highlightsector[k] == wall[j].nextsector) - break; - if (k < 0) - { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - } - } - } + //White out all bordering lines of grab that are + //not highlighted on both sides + for(i=highlightsectorcnt-1;i>=0;i--) + { + startwall = sector[highlightsector[i]].wallptr; + endwall = startwall + sector[highlightsector[i]].wallnum; + for(j=startwall;j= 0) + { + for(k=highlightsectorcnt-1;k>=0;k--) + if (highlightsector[k] == wall[j].nextsector) + break; + if (k < 0) + { + wall[wall[j].nextwall].nextwall = -1; + wall[wall[j].nextwall].nextsector = -1; + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + } + } + } - for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights - show2dwall[i] = 0; - for(i=0;i<(MAXSPRITES>>3);i++) - show2dsprite[i] = 0; + for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights + show2dwall[i] = 0; + for(i=0;i<(MAXSPRITES>>3);i++) + show2dsprite[i] = 0; - sectorhighlightstat = -1; - newnumwalls = -1; - joinsector[0] = -1; - circlewall = -1; - circlepoints = 7; - bstatus = 0; - keystatus[buildkeys[14]] = 0; - while ((keystatus[buildkeys[14]]>>1) == 0) - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } + sectorhighlightstat = -1; + newnumwalls = -1; + joinsector[0] = -1; + circlewall = -1; + circlepoints = 7; + bstatus = 0; + keystatus[buildkeys[14]] = 0; + while ((keystatus[buildkeys[14]]>>1) == 0) + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } - OSD_DispatchQueued(); + OSD_DispatchQueued(); - oldmousebstatus = bstatus; - getmousevalues(&mousx,&mousy,&bstatus); - mousx = (mousx<<16)+mousexsurp; - mousy = (mousy<<16)+mouseysurp; - { - ldiv_t ld; - ld = ldiv((long)((double)mousx*msens), (1<<16)); mousx = ld.quot; mousexsurp = ld.rem; - ld = ldiv((long)((double)mousy*msens), (1<<16)); mousy = ld.quot; mouseysurp = ld.rem; - } - searchx += mousx; - searchy += mousy; - if (searchx < 8) searchx = 8; - if (searchx > xdim-8-1) searchx = xdim-8-1; - if (searchy < 8) searchy = 8; - if (searchy > ydim-8-1) searchy = ydim-8-1; + oldmousebstatus = bstatus; + getmousevalues(&mousx,&mousy,&bstatus); + mousx = (mousx<<16)+mousexsurp; + mousy = (mousy<<16)+mouseysurp; + { + ldiv_t ld; + ld = ldiv((long)((double)mousx*msens), (1<<16)); mousx = ld.quot; mousexsurp = ld.rem; + ld = ldiv((long)((double)mousy*msens), (1<<16)); mousy = ld.quot; mouseysurp = ld.rem; + } + searchx += mousx; + searchy += mousy; + if (searchx < 8) searchx = 8; + if (searchx > xdim-8-1) searchx = xdim-8-1; + if (searchy < 8) searchy = 8; + if (searchy > ydim-8-1) searchy = ydim-8-1; -/* if (keystatus[0x3b] > 0) posx--, keystatus[0x3b] = 0; - if (keystatus[0x3c] > 0) posx++, keystatus[0x3c] = 0; - if (keystatus[0x3d] > 0) posy--, keystatus[0x3d] = 0; - if (keystatus[0x3e] > 0) posy++, keystatus[0x3e] = 0; - if (keystatus[0x43] > 0) ang--, keystatus[0x43] = 0; - if (keystatus[0x44] > 0) ang++, keystatus[0x44] = 0; */ - if (angvel != 0) //ang += angvel * constant - { //ENGINE calculates angvel for you - doubvel = synctics; - if (keystatus[buildkeys[4]] > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (synctics>>1); - ang += ((angvel*doubvel)>>4); - ang = (ang+2048)&2047; - } - if ((vel|svel) != 0) - { - doubvel = synctics; - if (keystatus[buildkeys[4]] > 0) //Lt. shift doubles forward velocity - doubvel += synctics; - xvect = 0, yvect = 0; - if (vel != 0) - { - xvect += ((vel*doubvel*(long)sintable[(ang+2560)&2047])>>3); - yvect += ((vel*doubvel*(long)sintable[(ang+2048)&2047])>>3); - } - if (svel != 0) - { - xvect += ((svel*doubvel*(long)sintable[(ang+2048)&2047])>>3); - yvect += ((svel*doubvel*(long)sintable[(ang+1536)&2047])>>3); - } + /* if (keystatus[0x3b] > 0) posx--, keystatus[0x3b] = 0; + if (keystatus[0x3c] > 0) posx++, keystatus[0x3c] = 0; + if (keystatus[0x3d] > 0) posy--, keystatus[0x3d] = 0; + if (keystatus[0x3e] > 0) posy++, keystatus[0x3e] = 0; + if (keystatus[0x43] > 0) ang--, keystatus[0x43] = 0; + if (keystatus[0x44] > 0) ang++, keystatus[0x44] = 0; */ + if (angvel != 0) //ang += angvel * constant + { //ENGINE calculates angvel for you + doubvel = synctics; + if (keystatus[buildkeys[4]] > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (synctics>>1); + ang += ((angvel*doubvel)>>4); + ang = (ang+2048)&2047; + } + if ((vel|svel) != 0) + { + doubvel = synctics; + if (keystatus[buildkeys[4]] > 0) //Lt. shift doubles forward velocity + doubvel += synctics; + xvect = 0, yvect = 0; + if (vel != 0) + { + xvect += ((vel*doubvel*(long)sintable[(ang+2560)&2047])>>3); + yvect += ((vel*doubvel*(long)sintable[(ang+2048)&2047])>>3); + } + if (svel != 0) + { + xvect += ((svel*doubvel*(long)sintable[(ang+2048)&2047])>>3); + yvect += ((svel*doubvel*(long)sintable[(ang+1536)&2047])>>3); + } if (noclip) { - posx += xvect>>14; - posy += yvect>>14; - updatesector(posx,posy,&cursectnum); + posx += xvect>>14; + posy += yvect>>14; + updatesector(posx,posy,&cursectnum); } else clipmove(&posx,&posy,&posz,&cursectnum,xvect,yvect,128L,4L<<8,4L<<8,CLIPMASK0); - } + } - getpoint(searchx,searchy,&mousxplc,&mousyplc); - linehighlight = getlinehighlight(mousxplc, mousyplc); + getpoint(searchx,searchy,&mousxplc,&mousyplc); + linehighlight = getlinehighlight(mousxplc, mousyplc); - if (newnumwalls >= numwalls) - { - dax = mousxplc; - day = mousyplc; - adjustmark(&dax,&day,newnumwalls); - wall[newnumwalls].x = dax; - wall[newnumwalls].y = day; - } + if (newnumwalls >= numwalls) + { + dax = mousxplc; + day = mousyplc; + adjustmark(&dax,&day,newnumwalls); + wall[newnumwalls].x = dax; + wall[newnumwalls].y = day; + } - ydim16 = ydim - STATUS2DSIZ; + ydim16 = ydim - STATUS2DSIZ; - templong = numwalls; - numwalls = newnumwalls; - if (numwalls < 0) numwalls = templong; + templong = numwalls; + numwalls = newnumwalls; + if (numwalls < 0) numwalls = templong; - clear2dscreen(); - draw2dgrid(posx,posy,ang,zoom,grid); + clear2dscreen(); + draw2dgrid(posx,posy,ang,zoom,grid); - x2 = mulscale14(startposx-posx,zoom); //Draw brown arrow (start) - y2 = mulscale14(startposy-posy,zoom); - if (((halfxdim16+x2) >= 2) && ((halfxdim16+x2) <= xdim-3)) - if (((midydim16+y2) >= 2) && ((midydim16+y2) <= ydim16-3)) - { - x1 = mulscale11(sintable[(startang+2560)&2047],zoom) / 768; - y1 = mulscale11(sintable[(startang+2048)&2047],zoom) / 768; - begindrawing(); //{{{ + x2 = mulscale14(startposx-posx,zoom); //Draw brown arrow (start) + y2 = mulscale14(startposy-posy,zoom); + if (((halfxdim16+x2) >= 2) && ((halfxdim16+x2) <= xdim-3)) + if (((midydim16+y2) >= 2) && ((midydim16+y2) <= ydim16-3)) + { + x1 = mulscale11(sintable[(startang+2560)&2047],zoom) / 768; + y1 = mulscale11(sintable[(startang+2048)&2047],zoom) / 768; + begindrawing(); //{{{ drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)-x1,(midydim16+y2)-y1,2); drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)+y1,(midydim16+y2)-x1,2); drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)-y1,(midydim16+y2)+x1,2); - enddrawing(); //}}} - } + enddrawing(); //}}} + } - draw2dscreen(posx,posy,ang,zoom,grid); + draw2dscreen(posx,posy,ang,zoom,grid); - begindrawing(); //{{{ - if ((showtags == 1) && (zoom >= 768)) - { - for(i=0;i startwall) - { - dax /= (endwall-startwall+1); - day /= (endwall-startwall+1); - } + begindrawing(); //{{{ + if ((showtags == 1) && (zoom >= 768)) + { + for(i=0;i startwall) + { + dax /= (endwall-startwall+1); + day /= (endwall-startwall+1); + } - dax = mulscale14(dax-posx,zoom); - day = mulscale14(day-posy,zoom); + dax = mulscale14(dax-posx,zoom); + day = mulscale14(day-posy,zoom); - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) - printext16(x1,y1,0,7,dabuffer,1); - } - } + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; + if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) + printext16(x1,y1,0,7,dabuffer,1); + } + } - x3 = divscale14(-halfxdim16,zoom)+posx; - y3 = divscale14(-(midydim16-4),zoom)+posy; - x4 = divscale14(halfxdim16,zoom)+posx; - y4 = divscale14(ydim16-(midydim16-4),zoom)+posy; + x3 = divscale14(-halfxdim16,zoom)+posx; + y3 = divscale14(-(midydim16-4),zoom)+posy; + x4 = divscale14(halfxdim16,zoom)+posx; + y4 = divscale14(ydim16-(midydim16-4),zoom)+posy; - for(i=numwalls-1,wal=&wall[i];i>=0;i--,wal--) - { - //Get average point of wall - dax = ((wal->x+wall[wal->point2].x)>>1); - day = ((wal->y+wall[wal->point2].y)>>1); - if ((dax > x3) && (dax < x4) && (day > y3) && (day < y4)) - { - dabuffer = (char *)ExtGetWallCaption(i); - if (dabuffer[0] != 0) - { - dax = mulscale14(dax-posx,zoom); - day = mulscale14(day-posy,zoom); - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) - printext16(x1,y1,0,4,dabuffer,1); - } - } - } + for(i=numwalls-1,wal=&wall[i];i>=0;i--,wal--) + { + //Get average point of wall + dax = ((wal->x+wall[wal->point2].x)>>1); + day = ((wal->y+wall[wal->point2].y)>>1); + if ((dax > x3) && (dax < x4) && (day > y3) && (day < y4)) + { + dabuffer = (char *)ExtGetWallCaption(i); + if (dabuffer[0] != 0) + { + dax = mulscale14(dax-posx,zoom); + day = mulscale14(day-posy,zoom); + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; + if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) + printext16(x1,y1,0,4,dabuffer,1); + } + } + } - i = 0; j = numsprites; - while ((j > 0) && (i < MAXSPRITES)) - { - if (sprite[i].statnum < MAXSTATUS) - { - dabuffer = (char *)ExtGetSpriteCaption(i); - if (dabuffer[0] != 0) - { - //Get average point of sprite - dax = sprite[i].x; - day = sprite[i].y; + i = 0; j = numsprites; + while ((j > 0) && (i < MAXSPRITES)) + { + if (sprite[i].statnum < MAXSTATUS) + { + dabuffer = (char *)ExtGetSpriteCaption(i); + if (dabuffer[0] != 0) + { + //Get average point of sprite + dax = sprite[i].x; + day = sprite[i].y; - dax = mulscale14(dax-posx,zoom); - day = mulscale14(day-posy,zoom); + dax = mulscale14(dax-posx,zoom); + day = mulscale14(day-posy,zoom); - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) - { - col = 3; - if (spritecol2d[sprite[i].picnum][0]) + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; + if ((x1 >= 0) && (x2 < xdim) && (y1 >= 0) && (y2 < ydim16)) + { + col = 3; + if (spritecol2d[sprite[i].picnum][0]) col = spritecol2d[sprite[i].picnum][0]; - if ((sprite[i].cstat&1) > 0) - { - col = 5; - if (spritecol2d[sprite[i].picnum][1]) - col = spritecol2d[sprite[i].picnum][1]; - } + if ((sprite[i].cstat&1) > 0) + { + col = 5; + if (spritecol2d[sprite[i].picnum][1]) + col = spritecol2d[sprite[i].picnum][1]; + } - if ((i == pointhighlight-16384) && (totalclock & 32)) col += (2<<2); + if ((i == pointhighlight-16384) && (totalclock & 32)) col += (2<<2); - printext16(x1,y1,0,col,dabuffer,1); - } - } - j--; - } - i++; - } - } + printext16(x1,y1,0,col,dabuffer,1); + } + } + j--; + } + i++; + } + } - printcoords16(posx,posy,ang); + printcoords16(posx,posy,ang); - numwalls = templong; + numwalls = templong; - if (highlightsectorcnt > 0) - for(i=0;i 0) + for(i=0;i= 0) - drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,15); - else - drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,5); - enddrawing(); //}}} + //Draw the white pixel closest to mouse cursor on linehighlight + getclosestpointonwall(mousxplc,mousyplc,(long)linehighlight,&dax,&day); + x2 = mulscale14(dax-posx,zoom); + y2 = mulscale14(day-posy,zoom); + if (wall[linehighlight].nextsector >= 0) + drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,15); + else + drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,5); + enddrawing(); //}}} + + OSD_Draw(); - OSD_Draw(); - ExtCheckKeys(); // TX 20050101, it makes more sense to have this here so keys can be overwritten with new functions in bstub.c -// Flip/mirror sector Ed Coolidge + // Flip/mirror sector Ed Coolidge if (keystatus[0x2d] > 0) // X (2D) { if (highlightsectorcnt > 0) @@ -3051,8 +3051,8 @@ void overheadeditor(void) { dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); -// dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); -// day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); + // dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); + // day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); } for(i=0;i>1; for(w=1;w<=numtoswap;w++) { @@ -3100,7 +3100,7 @@ void overheadeditor(void) Bmemcpy(&wall[endofloop-w+1],&tempwall,sizeof(walltype)); } - //make point2 point to next wall in loop + //make point2 point to next wall in loop for(w=startofloop;w>grid))&(0xffffffff<<(11-grid))); day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); -// dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); -// day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); + // dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); + // day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); } for(i=0;i>1; for(w=1;w<=numtoswap;w++) { @@ -3216,7 +3216,7 @@ void overheadeditor(void) Bmemcpy(&wall[endofloop-w+1],&tempwall,sizeof(walltype)); } - //make point2 point to next wall in loop + //make point2 point to next wall in loop for(w=startofloop;w 0) //F12 - { - keystatus[88] = 0; - /* - j = ydim16; ydim16 = ydim; - clear2dscreen(); - draw2dgrid(posx,posy,ang,zoom,grid); - draw2dscreen(posx,posy,ang,zoom,grid); - */ - - screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); - - /* - ydim16 = j; - clear2dscreen(); - draw2dgrid(posx,posy,ang,zoom,grid); - draw2dscreen(posx,posy,ang,zoom,grid); - */ - showframe(1); - } - if (keystatus[0x30] > 0) // B (clip Blocking xor) (2D) - { - pointhighlight = getpointhighlight(mousxplc, mousyplc); - linehighlight = getlinehighlight(mousxplc, mousyplc); - - if ((pointhighlight&0xc000) == 16384) - { - sprite[pointhighlight&16383].cstat ^= 1; - sprite[pointhighlight&16383].cstat &= ~256; - sprite[pointhighlight&16383].cstat |= ((sprite[pointhighlight&16383].cstat&1)<<8); - asksave = 1; - } - else if (linehighlight >= 0) - { - wall[linehighlight].cstat ^= 1; - wall[linehighlight].cstat &= ~64; - if ((wall[linehighlight].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) - { - wall[wall[linehighlight].nextwall].cstat &= ~(1+64); - wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&1); - } - asksave = 1; - } - keystatus[0x30] = 0; - } - if (keystatus[0x21] > 0) //F (F alone does nothing in 2D right now) - { - keystatus[0x21] = 0; - if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT-F (relative alignmment flip) - { - linehighlight = getlinehighlight(mousxplc, mousyplc); - if (linehighlight >= 0) - { - setfirstwall(sectorofwall(linehighlight),linehighlight); - asksave = 1; - printmessage16("This wall now sector's first wall (sector[].wallptr)"); - } - } - } - - if (keystatus[0x18] > 0) // O (ornament onto wall) (2D) - { - keystatus[0x18] = 0; - if ((pointhighlight&0xc000) == 16384) - { - asksave = 1; - i = (pointhighlight&16383); - - hitscan(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum, - sintable[(sprite[i].ang+2560+1024)&2047], - sintable[(sprite[i].ang+2048+1024)&2047], - 0, - &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - - sprite[i].x = hitx; - sprite[i].y = hity; - sprite[i].z = hitz; - changespritesect(i,hitsect); - if (hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); - - //Make sure sprite's in right sector - if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) - { - j = wall[hitwall].point2; - sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); - sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); - } - } - } - - if (keystatus[0x33] > 0) // , (2D) - { - if (highlightsectorcnt > 0) - { - k = 0; - dax = 0; - day = 0; - for(i=0;i 0) - { - dax /= k; - day /= k; - } - - k = (keystatus[0x2a]|keystatus[0x36]); - - if (k == 0) - { - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - } - - for(i=0;i= 16384) - { - i = pointhighlight-16384; - if ((keystatus[0x2a]|keystatus[0x36]) > 0) - sprite[i].ang = ((sprite[i].ang+2048-1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048-128)&2047); - keystatus[0x33] = 0; - } - - clearmidstatbar16(); - showspritedata((short)pointhighlight-16384); - } - } - } - if (keystatus[0x34] > 0) // . (2D) - { - if (highlightsectorcnt > 0) - { - k = 0; - dax = 0; - day = 0; - for(i=0;i 0) - { - dax /= k; - day /= k; - } - - k = (keystatus[0x2a]|keystatus[0x36]); - - if (k == 0) - { - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - } - - for(i=0;i= 16384) - { - i = pointhighlight-16384; - if ((keystatus[0x2a]|keystatus[0x36]) > 0) - sprite[i].ang = ((sprite[i].ang+2048+1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048+128)&2047); - keystatus[0x34] = 0; - } - - clearmidstatbar16(); - showspritedata((short)pointhighlight-16384); - } - } - } - if (keystatus[0x46] > 0) //Scroll lock (set starting position) - { - startposx = posx; - startposy = posy; - startposz = posz; - startang = ang; - startsectnum = cursectnum; - keystatus[0x46] = 0; - asksave = 1; - } - - if (keystatus[0x3f] > 0) //F5 - { - keystatus[0x3f] = 0; - - for (i=0;i 0) //F6 - { - keystatus[0x40] = 0; - - if (pointhighlight >= 16384) - { - i = pointhighlight-16384; - - ydim16 = STATUS2DSIZ; - ExtShowSpriteData((short)i); - ydim16 = ydim-STATUS2DSIZ; - } - else if (linehighlight >= 0) - { - i = linehighlight; - - ydim16 = STATUS2DSIZ; - ExtShowWallData((short)i); - ydim16 = ydim-STATUS2DSIZ; - } - } - if (keystatus[0x41] > 0) //F7 - { - keystatus[0x41] = 0; - - for (i=0;i 0) //F8 - { - keystatus[0x42] = 0; - - if (pointhighlight >= 16384) - { - i = pointhighlight-16384; - - ydim16 = STATUS2DSIZ; - ExtEditSpriteData((short)i); - ydim16 = ydim-STATUS2DSIZ; - } - else if (linehighlight >= 0) - { - i = linehighlight; - - ydim16 = STATUS2DSIZ; - ExtEditWallData((short)i); - ydim16 = ydim-STATUS2DSIZ; - } - } - - if (keystatus[0x14] > 0) // T (tag) - { - keystatus[0x14] = 0; - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //Ctrl-T - { - showtags ^= 1; - if (showtags == 0) - printmessage16("Show tags OFF"); - else - printmessage16("Show tags ON"); - } - else if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT - { - if (pointhighlight >= 16384) - { - i = pointhighlight-16384; - Bsprintf(buffer,"Sprite (%ld) Lo-tag: ",i); - sprite[i].lotag = getnumber16(buffer,sprite[i].lotag,65536L,0); - clearmidstatbar16(); - showspritedata((short)i); - } - else if (linehighlight >= 0) - { - i = linehighlight; - Bsprintf(buffer,"Wall (%ld) Lo-tag: ",i); - wall[i].lotag = getnumber16(buffer,wall[i].lotag,65536L,0); - clearmidstatbar16(); - showwalldata((short)i); - } - printmessage16(""); - } - else - { - for (i=0;i 0) //H (Hi 16 bits of tag) - { - keystatus[0x23] = 0; - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //Ctrl-H - { - pointhighlight = getpointhighlight(mousxplc, mousyplc); - linehighlight = getlinehighlight(mousxplc, mousyplc); - - if ((pointhighlight&0xc000) == 16384) - { - sprite[pointhighlight&16383].cstat ^= 256; - asksave = 1; - } - else if (linehighlight >= 0) - { - wall[linehighlight].cstat ^= 64; - if ((wall[linehighlight].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) - { - wall[wall[linehighlight].nextwall].cstat &= ~64; - wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&64); - } - asksave = 1; - } - } - else if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT - { - if (pointhighlight >= 16384) - { - i = pointhighlight-16384; - Bsprintf(buffer,"Sprite (%ld) Hi-tag: ",i); - sprite[i].hitag = getnumber16(buffer,sprite[i].hitag,65536L,0); - clearmidstatbar16(); - showspritedata((short)i); - } - else if (linehighlight >= 0) - { - i = linehighlight; - Bsprintf(buffer,"Wall (%ld) Hi-tag: ",i); - wall[i].hitag = getnumber16(buffer,wall[i].hitag,65536L,0); - clearmidstatbar16(); - showwalldata((short)i); - } - } - else - { - for (i=0;i 0) // P (palookup #) - { - keystatus[0x19] = 0; - - for (i=0;i 0) // E (status list) - { - if (pointhighlight >= 16384) - { - i = pointhighlight-16384; - Bsprintf(buffer,"Sprite (%ld) Status list: ",i); - changespritestat(i,getnumber16(buffer,sprite[i].statnum,65536L,0)); - clearmidstatbar16(); - showspritedata((short)i); - } - - printmessage16(""); - - keystatus[0x12] = 0; - } - - if (keystatus[0x0f] > 0) //TAB - { - clearmidstatbar16(); - - if ((keystatus[0x38]|keystatus[0xb8]|keystatus[0x1d]|keystatus[0x9d]) > 0) //ALT or CTRL - { - if (pointhighlight >= 16384) - showspritedata((short)pointhighlight-16384); - else if (linehighlight >= 0) - showwalldata((short)linehighlight); - } - else - { - for (i=0;i 0) //Right shift (point highlighting) - { - if (highlightcnt == 0) - { - highlightx2 = searchx, highlighty2 = searchy; - ydim16 = ydim-STATUS2DSIZ; - drawline16(highlightx2,highlighty1,highlightx1,highlighty1,5); - drawline16(highlightx2,highlighty2,highlightx1,highlighty2,5); - drawline16(highlightx1,highlighty2,highlightx1,highlighty1,5); - drawline16(highlightx2,highlighty2,highlightx2,highlighty1,5); - } - if (highlightcnt != 0) - { - highlightx1 = searchx; - highlighty1 = searchy; - highlightx2 = searchx; - highlighty2 = searchx; - highlightcnt = 0; - - for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights - show2dwall[i] = 0; - for(i=0;i<(MAXSPRITES>>3);i++) - show2dsprite[i] = 0; - } - } - else - { - if (highlightcnt == 0) - { - getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); - getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); - if (highlightx1 > highlightx2) - { - templong = highlightx1; highlightx1 = highlightx2; highlightx2 = templong; - } - if (highlighty1 > highlighty2) - { - templong = highlighty1; highlighty1 = highlighty2; highlighty2 = templong; - } - - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) - { - if ((linehighlight >= 0) && (linehighlight < MAXWALLS)) - { - i = linehighlight; - do - { - highlight[highlightcnt++] = i; - show2dwall[i>>3] |= (1<<(i&7)); - - for(j=0;j>3] |= (1<<(j&7)); - } - - i = wall[i].point2; - } - while (i != linehighlight); - } - } - else - { - for(i=0;i= highlightx1) && (wall[i].x <= highlightx2)) - if ((wall[i].y >= highlighty1) && (wall[i].y <= highlighty2)) - { - highlight[highlightcnt++] = i; - show2dwall[i>>3] |= (1<<(i&7)); - } - for(i=0;i= highlightx1) && (sprite[i].x <= highlightx2)) - if ((sprite[i].y >= highlighty1) && (sprite[i].y <= highlighty2)) - { - highlight[highlightcnt++] = i+16384; - show2dsprite[i>>3] |= (1<<(i&7)); - } - } - - if (highlightcnt <= 0) - highlightcnt = -1; - } - } - } - if (highlightcnt < 0) - { - if (keystatus[0xb8] > 0) //Right alt (sector highlighting) - { - if (highlightsectorcnt == 0) - { - highlightx2 = searchx, highlighty2 = searchy; - ydim16 = ydim-STATUS2DSIZ; - begindrawing(); //{{{ - drawline16(highlightx2,highlighty1,highlightx1,highlighty1,10); - drawline16(highlightx2,highlighty2,highlightx1,highlighty2,10); - drawline16(highlightx1,highlighty2,highlightx1,highlighty1,10); - drawline16(highlightx2,highlighty2,highlightx2,highlighty1,10); - enddrawing(); //}}} - } - if (highlightsectorcnt != 0) - { - for(i=0;i= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,highlightsector[i]); - } - } - highlightx1 = searchx; - highlighty1 = searchy; - highlightx2 = searchx; - highlighty2 = searchx; - highlightsectorcnt = 0; - } - } - else - { - if (highlightsectorcnt == 0) - { - getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); - getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); - if (highlightx1 > highlightx2) - { - templong = highlightx1; highlightx1 = highlightx2; highlightx2 = templong; - } - if (highlighty1 > highlighty2) - { - templong = highlighty1; highlighty1 = highlighty2; highlighty2 = templong; - } - - for(i=0;i highlightx2) bad = 1; - if (wall[j].y < highlighty1) bad = 1; - if (wall[j].y > highlighty2) bad = 1; - if (bad == 1) break; - } - if (bad == 0) - highlightsector[highlightsectorcnt++] = i; - } - if (highlightsectorcnt <= 0) - highlightsectorcnt = -1; - - //White out all bordering lines of grab that are - //not highlighted on both sides - for(i=highlightsectorcnt-1;i>=0;i--) - { - startwall = sector[highlightsector[i]].wallptr; - endwall = startwall + sector[highlightsector[i]].wallnum; - for(j=startwall;j= 0) - { - for(k=highlightsectorcnt-1;k>=0;k--) - if (highlightsector[k] == wall[j].nextsector) - break; - if (k < 0) - { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - } - } - } - - } - } - } - - if (((bstatus&1) < (oldmousebstatus&1)) && (highlightsectorcnt < 0)) //after dragging - { - j = 1; - if (highlightcnt > 0) - for (i=0;i=0;i--) //delete points - { - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) - { - deletepoint((short)i); - printmessage16("Point deleted."); - asksave = 1; - } - } - for(i=0;i 0) //drag points - { - if (highlightsectorcnt > 0) - { - if ((bstatus&1) > (oldmousebstatus&1)) - { - newnumwalls = -1; - sectorhighlightstat = -1; - updatesector(mousxplc,mousyplc,&cursectorhighlight); - - if ((cursectorhighlight >= 0) && (cursectorhighlight < numsectors)) - { - for (i=0;i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - sectorhighlightx = dax; - sectorhighlighty = day; - break; - } - } - } - else if (sectorhighlightstat == 1) - { - dax = mousxplc; - day = mousyplc; - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - - dax -= sectorhighlightx; - day -= sectorhighlighty; - sectorhighlightx += dax; - sectorhighlighty += day; - - for(i=0;i=0;j=nextspritesect[j]) - { sprite[j].x += dax; sprite[j].y += day; } - } - - //for(i=0;i= 0) - // checksectorpointer(wall[j].nextwall,wall[j].nextsector); - // checksectorpointer((short)j,highlightsector[i]); - // } - //} - asksave = 1; - } - - } - else - { - if ((bstatus&1) > (oldmousebstatus&1)) - pointhighlight = getpointhighlight(mousxplc, mousyplc); - - if (pointhighlight >= 0) - { - dax = mousxplc; - day = mousyplc; - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - - j = 1; - if (highlightcnt > 0) - for (i=0;i= getceilzofslope(i,dax,day)) - if (sprite[pointhighlight&16383].z-daz <= getflorzofslope(i,dax,day)) - { - sprite[pointhighlight&16383].x = dax; - sprite[pointhighlight&16383].y = day; - if (sprite[pointhighlight&16383].sectnum != i) - changespritesect(pointhighlight&16383,(short)i); - break; - } - } - } - asksave = 1; - } - } - } - else - { - pointhighlight = getpointhighlight(mousxplc, mousyplc); - sectorhighlightstat = -1; - } - - if ((bstatus&6) > 0) - { - searchx = halfxdim16; - searchy = midydim16; - posx = mousxplc; - posy = mousyplc; - } - - if (((keystatus[buildkeys[8]] > 0) || (bstatus&16)) && (zoom < 16384)) zoom += synctics*(zoom>>4); - if (((keystatus[buildkeys[9]] > 0) || (bstatus&32)) && (zoom > 24)) zoom -= synctics*(zoom>>4); + // end edit for sector flip + + if (keystatus[88] > 0) //F12 + { + keystatus[88] = 0; + /* + j = ydim16; ydim16 = ydim; + clear2dscreen(); + draw2dgrid(posx,posy,ang,zoom,grid); + draw2dscreen(posx,posy,ang,zoom,grid); + */ + + screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); + + /* + ydim16 = j; + clear2dscreen(); + draw2dgrid(posx,posy,ang,zoom,grid); + draw2dscreen(posx,posy,ang,zoom,grid); + */ + showframe(1); + } + if (keystatus[0x30] > 0) // B (clip Blocking xor) (2D) + { + pointhighlight = getpointhighlight(mousxplc, mousyplc); + linehighlight = getlinehighlight(mousxplc, mousyplc); + + if ((pointhighlight&0xc000) == 16384) + { + sprite[pointhighlight&16383].cstat ^= 1; + sprite[pointhighlight&16383].cstat &= ~256; + sprite[pointhighlight&16383].cstat |= ((sprite[pointhighlight&16383].cstat&1)<<8); + asksave = 1; + } + else if (linehighlight >= 0) + { + wall[linehighlight].cstat ^= 1; + wall[linehighlight].cstat &= ~64; + if ((wall[linehighlight].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + { + wall[wall[linehighlight].nextwall].cstat &= ~(1+64); + wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&1); + } + asksave = 1; + } + keystatus[0x30] = 0; + } + if (keystatus[0x21] > 0) //F (F alone does nothing in 2D right now) + { + keystatus[0x21] = 0; + if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT-F (relative alignmment flip) + { + linehighlight = getlinehighlight(mousxplc, mousyplc); + if (linehighlight >= 0) + { + setfirstwall(sectorofwall(linehighlight),linehighlight); + asksave = 1; + printmessage16("This wall now sector's first wall (sector[].wallptr)"); + } + } + } + + if (keystatus[0x18] > 0) // O (ornament onto wall) (2D) + { + keystatus[0x18] = 0; + if ((pointhighlight&0xc000) == 16384) + { + asksave = 1; + i = (pointhighlight&16383); + + hitscan(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum, + sintable[(sprite[i].ang+2560+1024)&2047], + sintable[(sprite[i].ang+2048+1024)&2047], + 0, + &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + + sprite[i].x = hitx; + sprite[i].y = hity; + sprite[i].z = hitz; + changespritesect(i,hitsect); + if (hitwall >= 0) + sprite[i].ang = ((getangle(wall[wall[hitwall].point2].x-wall[hitwall].x,wall[wall[hitwall].point2].y-wall[hitwall].y)+512)&2047); + + //Make sure sprite's in right sector + if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) + { + j = wall[hitwall].point2; + sprite[i].x -= ksgn(wall[j].y-wall[hitwall].y); + sprite[i].y += ksgn(wall[j].x-wall[hitwall].x); + } + } + } + + if (keystatus[0x33] > 0) // , (2D) + { + if (highlightsectorcnt > 0) + { + k = 0; + dax = 0; + day = 0; + for(i=0;i 0) + { + dax /= k; + day /= k; + } + + k = (keystatus[0x2a]|keystatus[0x36]); + + if (k == 0) + { + if ((gridlock > 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + } + + for(i=0;i= 16384) + { + i = pointhighlight-16384; + if ((keystatus[0x2a]|keystatus[0x36]) > 0) + sprite[i].ang = ((sprite[i].ang+2048-1)&2047); + else + { + sprite[i].ang = ((sprite[i].ang+2048-128)&2047); + keystatus[0x33] = 0; + } + + clearmidstatbar16(); + showspritedata((short)pointhighlight-16384); + } + } + } + if (keystatus[0x34] > 0) // . (2D) + { + if (highlightsectorcnt > 0) + { + k = 0; + dax = 0; + day = 0; + for(i=0;i 0) + { + dax /= k; + day /= k; + } + + k = (keystatus[0x2a]|keystatus[0x36]); + + if (k == 0) + { + if ((gridlock > 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + } + + for(i=0;i= 16384) + { + i = pointhighlight-16384; + if ((keystatus[0x2a]|keystatus[0x36]) > 0) + sprite[i].ang = ((sprite[i].ang+2048+1)&2047); + else + { + sprite[i].ang = ((sprite[i].ang+2048+128)&2047); + keystatus[0x34] = 0; + } + + clearmidstatbar16(); + showspritedata((short)pointhighlight-16384); + } + } + } + if (keystatus[0x46] > 0) //Scroll lock (set starting position) + { + startposx = posx; + startposy = posy; + startposz = posz; + startang = ang; + startsectnum = cursectnum; + keystatus[0x46] = 0; + asksave = 1; + } + + if (keystatus[0x3f] > 0) //F5 + { + keystatus[0x3f] = 0; + + for (i=0;i 0) //F6 + { + keystatus[0x40] = 0; + + if (pointhighlight >= 16384) + { + i = pointhighlight-16384; + + ydim16 = STATUS2DSIZ; + ExtShowSpriteData((short)i); + ydim16 = ydim-STATUS2DSIZ; + } + else if (linehighlight >= 0) + { + i = linehighlight; + + ydim16 = STATUS2DSIZ; + ExtShowWallData((short)i); + ydim16 = ydim-STATUS2DSIZ; + } + } + if (keystatus[0x41] > 0) //F7 + { + keystatus[0x41] = 0; + + for (i=0;i 0) //F8 + { + keystatus[0x42] = 0; + + if (pointhighlight >= 16384) + { + i = pointhighlight-16384; + + ydim16 = STATUS2DSIZ; + ExtEditSpriteData((short)i); + ydim16 = ydim-STATUS2DSIZ; + } + else if (linehighlight >= 0) + { + i = linehighlight; + + ydim16 = STATUS2DSIZ; + ExtEditWallData((short)i); + ydim16 = ydim-STATUS2DSIZ; + } + } + + if (keystatus[0x14] > 0) // T (tag) + { + keystatus[0x14] = 0; + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //Ctrl-T + { + showtags ^= 1; + if (showtags == 0) + printmessage16("Show tags OFF"); + else + printmessage16("Show tags ON"); + } + else if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT + { + if (pointhighlight >= 16384) + { + i = pointhighlight-16384; + Bsprintf(buffer,"Sprite (%ld) Lo-tag: ",i); + sprite[i].lotag = getnumber16(buffer,sprite[i].lotag,65536L,0); + clearmidstatbar16(); + showspritedata((short)i); + } + else if (linehighlight >= 0) + { + i = linehighlight; + Bsprintf(buffer,"Wall (%ld) Lo-tag: ",i); + wall[i].lotag = getnumber16(buffer,wall[i].lotag,65536L,0); + clearmidstatbar16(); + showwalldata((short)i); + } + printmessage16(""); + } + else + { + for (i=0;i 0) //H (Hi 16 bits of tag) + { + keystatus[0x23] = 0; + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //Ctrl-H + { + pointhighlight = getpointhighlight(mousxplc, mousyplc); + linehighlight = getlinehighlight(mousxplc, mousyplc); + + if ((pointhighlight&0xc000) == 16384) + { + sprite[pointhighlight&16383].cstat ^= 256; + asksave = 1; + } + else if (linehighlight >= 0) + { + wall[linehighlight].cstat ^= 64; + if ((wall[linehighlight].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + { + wall[wall[linehighlight].nextwall].cstat &= ~64; + wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&64); + } + asksave = 1; + } + } + else if ((keystatus[0x38]|keystatus[0xb8]) > 0) //ALT + { + if (pointhighlight >= 16384) + { + i = pointhighlight-16384; + Bsprintf(buffer,"Sprite (%ld) Hi-tag: ",i); + sprite[i].hitag = getnumber16(buffer,sprite[i].hitag,65536L,0); + clearmidstatbar16(); + showspritedata((short)i); + } + else if (linehighlight >= 0) + { + i = linehighlight; + Bsprintf(buffer,"Wall (%ld) Hi-tag: ",i); + wall[i].hitag = getnumber16(buffer,wall[i].hitag,65536L,0); + clearmidstatbar16(); + showwalldata((short)i); + } + } + else + { + for (i=0;i 0) // P (palookup #) + { + keystatus[0x19] = 0; + + for (i=0;i 0) // E (status list) + { + if (pointhighlight >= 16384) + { + i = pointhighlight-16384; + Bsprintf(buffer,"Sprite (%ld) Status list: ",i); + changespritestat(i,getnumber16(buffer,sprite[i].statnum,65536L,0)); + clearmidstatbar16(); + showspritedata((short)i); + } + + printmessage16(""); + + keystatus[0x12] = 0; + } + + if (keystatus[0x0f] > 0) //TAB + { + clearmidstatbar16(); + + if ((keystatus[0x38]|keystatus[0xb8]|keystatus[0x1d]|keystatus[0x9d]) > 0) //ALT or CTRL + { + if (pointhighlight >= 16384) + showspritedata((short)pointhighlight-16384); + else if (linehighlight >= 0) + showwalldata((short)linehighlight); + } + else + { + for (i=0;i 0) //Right shift (point highlighting) + { + if (highlightcnt == 0) + { + highlightx2 = searchx, highlighty2 = searchy; + ydim16 = ydim-STATUS2DSIZ; + drawline16(highlightx2,highlighty1,highlightx1,highlighty1,5); + drawline16(highlightx2,highlighty2,highlightx1,highlighty2,5); + drawline16(highlightx1,highlighty2,highlightx1,highlighty1,5); + drawline16(highlightx2,highlighty2,highlightx2,highlighty1,5); + } + if (highlightcnt != 0) + { + highlightx1 = searchx; + highlighty1 = searchy; + highlightx2 = searchx; + highlighty2 = searchx; + highlightcnt = 0; + + for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights + show2dwall[i] = 0; + for(i=0;i<(MAXSPRITES>>3);i++) + show2dsprite[i] = 0; + } + } + else + { + if (highlightcnt == 0) + { + getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); + getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); + if (highlightx1 > highlightx2) + { + templong = highlightx1; highlightx1 = highlightx2; highlightx2 = templong; + } + if (highlighty1 > highlighty2) + { + templong = highlighty1; highlighty1 = highlighty2; highlighty2 = templong; + } + + if ((keystatus[0x1d]|keystatus[0x9d]) > 0) + { + if ((linehighlight >= 0) && (linehighlight < MAXWALLS)) + { + i = linehighlight; + do + { + highlight[highlightcnt++] = i; + show2dwall[i>>3] |= (1<<(i&7)); + + for(j=0;j>3] |= (1<<(j&7)); + } + + i = wall[i].point2; + } + while (i != linehighlight); + } + } + else + { + for(i=0;i= highlightx1) && (wall[i].x <= highlightx2)) + if ((wall[i].y >= highlighty1) && (wall[i].y <= highlighty2)) + { + highlight[highlightcnt++] = i; + show2dwall[i>>3] |= (1<<(i&7)); + } + for(i=0;i= highlightx1) && (sprite[i].x <= highlightx2)) + if ((sprite[i].y >= highlighty1) && (sprite[i].y <= highlighty2)) + { + highlight[highlightcnt++] = i+16384; + show2dsprite[i>>3] |= (1<<(i&7)); + } + } + + if (highlightcnt <= 0) + highlightcnt = -1; + } + } + } + if (highlightcnt < 0) + { + if (keystatus[0xb8] > 0) //Right alt (sector highlighting) + { + if (highlightsectorcnt == 0) + { + highlightx2 = searchx, highlighty2 = searchy; + ydim16 = ydim-STATUS2DSIZ; + begindrawing(); //{{{ + drawline16(highlightx2,highlighty1,highlightx1,highlighty1,10); + drawline16(highlightx2,highlighty2,highlightx1,highlighty2,10); + drawline16(highlightx1,highlighty2,highlightx1,highlighty1,10); + drawline16(highlightx2,highlighty2,highlightx2,highlighty1,10); + enddrawing(); //}}} + } + if (highlightsectorcnt != 0) + { + for(i=0;i= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,highlightsector[i]); + } + } + highlightx1 = searchx; + highlighty1 = searchy; + highlightx2 = searchx; + highlighty2 = searchx; + highlightsectorcnt = 0; + } + } + else + { + if (highlightsectorcnt == 0) + { + getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); + getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); + if (highlightx1 > highlightx2) + { + templong = highlightx1; highlightx1 = highlightx2; highlightx2 = templong; + } + if (highlighty1 > highlighty2) + { + templong = highlighty1; highlighty1 = highlighty2; highlighty2 = templong; + } + + for(i=0;i highlightx2) bad = 1; + if (wall[j].y < highlighty1) bad = 1; + if (wall[j].y > highlighty2) bad = 1; + if (bad == 1) break; + } + if (bad == 0) + highlightsector[highlightsectorcnt++] = i; + } + if (highlightsectorcnt <= 0) + highlightsectorcnt = -1; + + //White out all bordering lines of grab that are + //not highlighted on both sides + for(i=highlightsectorcnt-1;i>=0;i--) + { + startwall = sector[highlightsector[i]].wallptr; + endwall = startwall + sector[highlightsector[i]].wallnum; + for(j=startwall;j= 0) + { + for(k=highlightsectorcnt-1;k>=0;k--) + if (highlightsector[k] == wall[j].nextsector) + break; + if (k < 0) + { + wall[wall[j].nextwall].nextwall = -1; + wall[wall[j].nextwall].nextsector = -1; + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + } + } + } + + } + } + } + + if (((bstatus&1) < (oldmousebstatus&1)) && (highlightsectorcnt < 0)) //after dragging + { + j = 1; + if (highlightcnt > 0) + for (i=0;i=0;i--) //delete points + { + if (wall[i].x == wall[wall[i].point2].x) + if (wall[i].y == wall[wall[i].point2].y) + { + deletepoint((short)i); + printmessage16("Point deleted."); + asksave = 1; + } + } + for(i=0;i 0) //drag points + { + if (highlightsectorcnt > 0) + { + if ((bstatus&1) > (oldmousebstatus&1)) + { + newnumwalls = -1; + sectorhighlightstat = -1; + updatesector(mousxplc,mousyplc,&cursectorhighlight); + + if ((cursectorhighlight >= 0) && (cursectorhighlight < numsectors)) + { + for (i=0;i 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + sectorhighlightx = dax; + sectorhighlighty = day; + break; + } + } + } + else if (sectorhighlightstat == 1) + { + dax = mousxplc; + day = mousyplc; + if ((gridlock > 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + + dax -= sectorhighlightx; + day -= sectorhighlighty; + sectorhighlightx += dax; + sectorhighlighty += day; + + for(i=0;i=0;j=nextspritesect[j]) + { sprite[j].x += dax; sprite[j].y += day; } + } + + //for(i=0;i= 0) + // checksectorpointer(wall[j].nextwall,wall[j].nextsector); + // checksectorpointer((short)j,highlightsector[i]); + // } + //} + asksave = 1; + } + + } + else + { + if ((bstatus&1) > (oldmousebstatus&1)) + pointhighlight = getpointhighlight(mousxplc, mousyplc); + + if (pointhighlight >= 0) + { + dax = mousxplc; + day = mousyplc; + if ((gridlock > 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } + + j = 1; + if (highlightcnt > 0) + for (i=0;i= getceilzofslope(i,dax,day)) + if (sprite[pointhighlight&16383].z-daz <= getflorzofslope(i,dax,day)) + { + sprite[pointhighlight&16383].x = dax; + sprite[pointhighlight&16383].y = day; + if (sprite[pointhighlight&16383].sectnum != i) + changespritesect(pointhighlight&16383,(short)i); + break; + } + } + } + asksave = 1; + } + } + } + else + { + pointhighlight = getpointhighlight(mousxplc, mousyplc); + sectorhighlightstat = -1; + } + + if ((bstatus&6) > 0) + { + searchx = halfxdim16; + searchy = midydim16; + posx = mousxplc; + posy = mousyplc; + } + + if (((keystatus[buildkeys[8]] > 0) || (bstatus&16)) && (zoom < 16384)) zoom += synctics*(zoom>>4); + if (((keystatus[buildkeys[9]] > 0) || (bstatus&32)) && (zoom > 24)) zoom -= synctics*(zoom>>4); if (zoom < 24) zoom = 24; if (zoom > 16384) zoom = 16384; - if (keystatus[0x22] > 0) // G (grid on/off) - { - grid++; - if (grid == 7) grid = 0; - keystatus[0x22] = 0; - } - if (keystatus[0x26] > 0) // L (grid lock) - { - gridlock = 1-gridlock, keystatus[0x26] = 0; - if (gridlock == 0) - printmessage16("Grid locking OFF"); - else - printmessage16("Grid locking ON"); - } + if (keystatus[0x22] > 0) // G (grid on/off) + { + grid++; + if (grid == 7) grid = 0; + keystatus[0x22] = 0; + } + if (keystatus[0x26] > 0) // L (grid lock) + { + gridlock = 1-gridlock, keystatus[0x26] = 0; + if (gridlock == 0) + printmessage16("Grid locking OFF"); + else + printmessage16("Grid locking ON"); + } - if (keystatus[0x24] > 0) // J (join sectors) - { - if (joinsector[0] >= 0) - { - joinsector[1] = -1; - for(i=0;i= 0) && (joinsector[0] != joinsector[1])) - { - newnumwalls = numwalls; + if (keystatus[0x24] > 0) // J (join sectors) + { + if (joinsector[0] >= 0) + { + joinsector[1] = -1; + for(i=0;i= 0) && (joinsector[0] != joinsector[1])) + { + newnumwalls = numwalls; - for(k=0;k<2;k++) - { - startwall = sector[joinsector[k]].wallptr; - endwall = startwall + sector[joinsector[k]].wallnum - 1; - for(j=startwall;j<=endwall;j++) - { - if (wall[j].cstat == 255) - continue; - joinsectnum = k; - if (wall[j].nextsector == joinsector[1-joinsectnum]) - { - wall[j].cstat = 255; - continue; - } + for(k=0;k<2;k++) + { + startwall = sector[joinsector[k]].wallptr; + endwall = startwall + sector[joinsector[k]].wallnum - 1; + for(j=startwall;j<=endwall;j++) + { + if (wall[j].cstat == 255) + continue; + joinsectnum = k; + if (wall[j].nextsector == joinsector[1-joinsectnum]) + { + wall[j].cstat = 255; + continue; + } - i = j; - m = newnumwalls; - do - { - Bmemcpy(&wall[newnumwalls],&wall[i],sizeof(walltype)); - wall[newnumwalls].point2 = newnumwalls+1; - newnumwalls++; - wall[i].cstat = 255; + i = j; + m = newnumwalls; + do + { + Bmemcpy(&wall[newnumwalls],&wall[i],sizeof(walltype)); + wall[newnumwalls].point2 = newnumwalls+1; + newnumwalls++; + wall[i].cstat = 255; - i = wall[i].point2; - if (wall[i].nextsector == joinsector[1-joinsectnum]) - { - i = wall[wall[i].nextwall].point2; - joinsectnum = 1 - joinsectnum; - } - } - while ((wall[i].cstat != 255) && (wall[i].nextsector != joinsector[1-joinsectnum])); - wall[newnumwalls-1].point2 = m; - } - } + i = wall[i].point2; + if (wall[i].nextsector == joinsector[1-joinsectnum]) + { + i = wall[wall[i].nextwall].point2; + joinsectnum = 1 - joinsectnum; + } + } + while ((wall[i].cstat != 255) && (wall[i].nextsector != joinsector[1-joinsectnum])); + wall[newnumwalls-1].point2 = m; + } + } - if (newnumwalls > numwalls) - { - Bmemcpy(§or[numsectors],§or[joinsector[0]],sizeof(sectortype)); - sector[numsectors].wallptr = numwalls; - sector[numsectors].wallnum = newnumwalls-numwalls; + if (newnumwalls > numwalls) + { + Bmemcpy(§or[numsectors],§or[joinsector[0]],sizeof(sectortype)); + sector[numsectors].wallptr = numwalls; + sector[numsectors].wallnum = newnumwalls-numwalls; - //fix sprites - for(i=0;i<2;i++) - { - j = headspritesect[joinsector[i]]; - while (j != -1) - { - k = nextspritesect[j]; - changespritesect(j,numsectors); - j = k; - } - } + //fix sprites + for(i=0;i<2;i++) + { + j = headspritesect[joinsector[i]]; + while (j != -1) + { + k = nextspritesect[j]; + changespritesect(j,numsectors); + j = k; + } + } - numsectors++; + numsectors++; - for(i=numwalls;i= 0) - { - wall[wall[i].nextwall].nextwall = i; - wall[wall[i].nextwall].nextsector = numsectors-1; - } - } + for(i=numwalls;i= 0) + { + wall[wall[i].nextwall].nextwall = i; + wall[wall[i].nextwall].nextsector = numsectors-1; + } + } - numwalls = newnumwalls; - newnumwalls = -1; + numwalls = newnumwalls; + newnumwalls = -1; - for(k=0;k<2;k++) - { - startwall = sector[joinsector[k]].wallptr; - endwall = startwall + sector[joinsector[k]].wallnum - 1; - for(j=startwall;j<=endwall;j++) - { - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - } + for(k=0;k<2;k++) + { + startwall = sector[joinsector[k]].wallptr; + endwall = startwall + sector[joinsector[k]].wallnum - 1; + for(j=startwall;j<=endwall;j++) + { + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + } - deletesector((short)joinsector[0]); - if (joinsector[0] < joinsector[1]) - joinsector[1]--; - deletesector((short)joinsector[1]); - printmessage16("Sectors joined."); - } - } - joinsector[0] = -1; - } - else - { - joinsector[0] = -1; - for(i=0;i 0) //ALT-S - { - if ((linehighlight >= 0) && (wall[linehighlight].nextwall == -1)) - { - if ((newnumwalls = whitelinescan(linehighlight)) < numwalls) - { - printmessage16("Can't make a sector out there."); - } - else - { - for(i=numwalls;i 0) //S - { - sucksect = -1; - for(i=0;i 0) //ALT-S + { + if ((linehighlight >= 0) && (wall[linehighlight].nextwall == -1)) + { + if ((newnumwalls = whitelinescan(linehighlight)) < numwalls) + { + printmessage16("Can't make a sector out there."); + } + else + { + for(i=numwalls;i 0) //S + { + sucksect = -1; + for(i=0;i= 0) - { - dax = mousxplc; - day = mousyplc; - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (sucksect >= 0) + { + dax = mousxplc; + day = mousyplc; + if ((gridlock > 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } - i = insertsprite(sucksect,0); - sprite[i].x = dax, sprite[i].y = day; - sprite[i].cstat = defaultspritecstat; - sprite[i].shade = 0; - sprite[i].pal = 0; - sprite[i].xrepeat = 64, sprite[i].yrepeat = 64; - sprite[i].xoffset = 0, sprite[i].yoffset = 0; - sprite[i].ang = 1536; - sprite[i].xvel = 0; sprite[i].yvel = 0; sprite[i].zvel = 0; - sprite[i].owner = -1; - sprite[i].clipdist = 32; - sprite[i].lotag = 0; - sprite[i].hitag = 0; - sprite[i].extra = -1; + i = insertsprite(sucksect,0); + sprite[i].x = dax, sprite[i].y = day; + sprite[i].cstat = defaultspritecstat; + sprite[i].shade = 0; + sprite[i].pal = 0; + sprite[i].xrepeat = 64, sprite[i].yrepeat = 64; + sprite[i].xoffset = 0, sprite[i].yoffset = 0; + sprite[i].ang = 1536; + sprite[i].xvel = 0; sprite[i].yvel = 0; sprite[i].zvel = 0; + sprite[i].owner = -1; + sprite[i].clipdist = 32; + sprite[i].lotag = 0; + sprite[i].hitag = 0; + sprite[i].extra = -1; - sprite[i].z = getflorzofslope(sucksect,dax,day); - if ((sprite[i].cstat&128) != 0) - sprite[i].z -= ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + sprite[i].z = getflorzofslope(sucksect,dax,day); + if ((sprite[i].cstat&128) != 0) + sprite[i].z -= ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); - for(k=0;k localartfreq[j]) - j = k; - if (localartfreq[j] > 0) - sprite[i].picnum = j; - else - sprite[i].picnum = 0; + for(k=0;k localartfreq[j]) + j = k; + if (localartfreq[j] > 0) + sprite[i].picnum = j; + else + sprite[i].picnum = 0; - if (somethingintab == 3) - { - sprite[i].picnum = temppicnum; - if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) - { - j = 0; - for(k=0;k 0) && (tilesizy[k] > 0)) - { - j = k; - break; - } - sprite[i].picnum = j; - } - sprite[i].shade = tempshade; - sprite[i].pal = temppal; - sprite[i].xrepeat = tempxrepeat; - sprite[i].yrepeat = tempyrepeat; - if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; - if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; - sprite[i].cstat = tempcstat; - } + if (somethingintab == 3) + { + sprite[i].picnum = temppicnum; + if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) + { + j = 0; + for(k=0;k 0) && (tilesizy[k] > 0)) + { + j = k; + break; + } + sprite[i].picnum = j; + } + sprite[i].shade = tempshade; + sprite[i].pal = temppal; + sprite[i].xrepeat = tempxrepeat; + sprite[i].yrepeat = tempyrepeat; + if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; + if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; + sprite[i].cstat = tempcstat; + } - if (tilesizy[sprite[i].picnum] >= 32) - sprite[i].cstat |= 1; + if (tilesizy[sprite[i].picnum] >= 32) + sprite[i].cstat |= 1; - printmessage16("Sprite inserted."); - updatenumsprites(); - asksave = 1; - } + printmessage16("Sprite inserted."); + updatenumsprites(); + asksave = 1; + } - keystatus[0x1f] = 0; - } + keystatus[0x1f] = 0; + } - if (keystatus[0x2e] > 0) // C (make circle of points) - { + if (keystatus[0x2e] > 0) // C (make circle of points) + { if (highlightsectorcnt >= 0) { newnumsectors = numsectors; @@ -4490,7 +4490,7 @@ void overheadeditor(void) for(i=0;i= 0) - { - circlewall = -1; - } - else - { - if (linehighlight >= 0) - circlewall = linehighlight; - } - keystatus[0x2e] = 0; - } - if (keystatus[0x4a] > 0) // - - { - if (circlepoints > 1) - circlepoints--; - keystatus[0x4a] = 0; - } - if (keystatus[0x4e] > 0) // + - { - if (circlepoints < 63) - circlepoints++; - keystatus[0x4e] = 0; - } - - bad = (keystatus[0x39] > 0); //Gotta do this to save lots of 3 spaces! - - if (circlewall >= 0) - { - x1 = wall[circlewall].x; - y1 = wall[circlewall].y; - x2 = wall[wall[circlewall].point2].x; - y2 = wall[wall[circlewall].point2].y; - x3 = mousxplc; - y3 = mousyplc; - adjustmark(&x3,&y3,newnumwalls); - templong1 = dmulscale4(x3-x2,x1-x3,y1-y3,y3-y2); - templong2 = dmulscale4(y1-y2,x1-x3,y1-y3,x2-x1); - if (templong2 != 0) - { - centerx = (((x1+x2) + scale(y1-y2,templong1,templong2))>>1); - centery = (((y1+y2) + scale(x2-x1,templong1,templong2))>>1); - - dax = mulscale14(centerx-posx,zoom); - day = mulscale14(centery-posy,zoom); - drawline16(halfxdim16+dax-2,midydim16+day-2,halfxdim16+dax+2,midydim16+day+2,14); - drawline16(halfxdim16+dax-2,midydim16+day+2,halfxdim16+dax+2,midydim16+day-2,14); - - circleang1 = getangle(x1-centerx,y1-centery); - circleang2 = getangle(x2-centerx,y2-centery); - - circleangdir = 1; - k = ((circleang2-circleang1)&2047); - if (mulscale4(x3-x1,y2-y1) < mulscale4(x2-x1,y3-y1)) - { - circleangdir = -1; - k = -((circleang1-circleang2)&2047); - } - - circlerad = (ksqrt(dmulscale4(centerx-x1,centerx-x1,centery-y1,centery-y1))<<2); - - for(i=circlepoints;i>0;i--) - { - j = ((circleang1 + scale(i,k,circlepoints+1))&2047); - dax = centerx+mulscale14(sintable[(j+512)&2047],circlerad); - day = centery+mulscale14(sintable[j],circlerad); - - if (dax <= -editorgridextent) dax = -editorgridextent; - if (dax >= editorgridextent) dax = editorgridextent; - if (day <= -editorgridextent) day = -editorgridextent; - if (day >= editorgridextent) day = editorgridextent; - - if (bad > 0) - { - m = 0; - if (wall[circlewall].nextwall >= 0) - if (wall[circlewall].nextwall < circlewall) m = 1; - insertpoint(circlewall,dax,day); - circlewall += m; - } - dax = mulscale14(dax-posx,zoom); - day = mulscale14(day-posy,zoom); - drawline16(halfxdim16+dax-2,midydim16+day-2,halfxdim16+dax+2,midydim16+day-2,14); - drawline16(halfxdim16+dax+2,midydim16+day-2,halfxdim16+dax+2,midydim16+day+2,14); - drawline16(halfxdim16+dax+2,midydim16+day+2,halfxdim16+dax-2,midydim16+day+2,14); - drawline16(halfxdim16+dax-2,midydim16+day+2,halfxdim16+dax-2,midydim16+day-2,14); - } - if (bad > 0) - { - bad = 0; - keystatus[0x39] = 0; - asksave = 1; - printmessage16("Circle points inserted."); - circlewall = -1; - } - } - } - - if (bad > 0) //Space bar test - { - keystatus[0x39] = 0; - adjustmark(&mousxplc,&mousyplc,newnumwalls); - if (checkautoinsert(mousxplc,mousyplc,newnumwalls) == 1) - { - printmessage16("You must insert a point there first."); - bad = 0; - } - } - - if (bad > 0) //Space - { - if ((newnumwalls < numwalls) && (numwalls < MAXWALLS-1)) - { - firstx = mousxplc, firsty = mousyplc; //Make first point - newnumwalls = numwalls; - suckwall = -1; - split = 0; - - //clearbufbyte(&wall[newnumwalls],sizeof(walltype),0L); - memset(&wall[newnumwalls],0,sizeof(walltype)); - wall[newnumwalls].extra = -1; - - wall[newnumwalls].x = mousxplc; - wall[newnumwalls].y = mousyplc; - wall[newnumwalls].nextsector = -1; - wall[newnumwalls].nextwall = -1; - for(i=0;i>1); - day = ((wall[numwalls].y+mousyplc)>>1); - for(i=0;i= 0) - if ((wall[wall[k].point2].x != mousxplc) || (wall[wall[k].point2].y != mousyplc)) - if ((wall[lastwall((short)k)].x != mousxplc) || (wall[lastwall((short)k)].y != mousyplc)) - { - split = 1; - splitsect = i; - splitstartwall = m; - break; - } - } - } - - //make new point - - //make sure not drawing over old red line - bad = 0; - for(i=0;i= 0) - { - if ((wall[i].x == mousxplc) && (wall[i].y == mousyplc)) - if ((wall[wall[i].point2].x == wall[newnumwalls-1].x) && (wall[wall[i].point2].y == wall[newnumwalls-1].y)) - bad = 1; - if ((wall[i].x == wall[newnumwalls-1].x) && (wall[i].y == wall[newnumwalls-1].y)) - if ((wall[wall[i].point2].x == mousxplc) && (wall[wall[i].point2].y == mousyplc)) - bad = 1; - } - } - - if (bad == 0) - { - //clearbufbyte(&wall[newnumwalls],sizeof(walltype),0L); - memset(&wall[newnumwalls],0,sizeof(walltype)); - wall[newnumwalls].extra = -1; - - wall[newnumwalls].x = mousxplc; - wall[newnumwalls].y = mousyplc; - wall[newnumwalls].nextsector = -1; - wall[newnumwalls].nextwall = -1; - for(i=0;i= numwalls+3)) - { - wall[newnumwalls-1].point2 = numwalls; - - if (suckwall == -1) //if no connections to other sectors - { - k = -1; - for(i=0;i= suckwall) - wall[i].nextwall += j; - if (wall[i].point2 >= suckwall) - wall[i].point2 += j; - } - - for(i=newnumwalls-1;i>=suckwall;i--) - Bmemcpy(&wall[i+j],&wall[i],sizeof(walltype)); - for(i=0;inumwalls;j--) - { - Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); - wall[danumwalls].nextwall = -1; - wall[danumwalls].nextsector = -1; - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - } - m = splitstartwall; //copy rest of loop next - while (m != splitendwall) - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } - wall[danumwalls-1].point2 = secondstartwall; - - //Add other loops for 2nd sector - loopnum = loopnumofsector(splitsect,splitstartwall); - i = loopnum; - for(j=startwall;j<=endwall;j++) - { - k = loopnumofsector(splitsect,(short)j); - if ((k != i) && (k != loopnum)) - { - i = k; - if (loopinside(wall[j].x,wall[j].y,secondstartwall) == 1) - { - m = j; //copy loop - k = danumwalls; - do - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } - while (m != j); - wall[danumwalls-1].point2 = k; - } - } - } - - //fix all next pointers on old sector line - for(j=numwalls;j= 0) - { - wall[wall[j].nextwall].nextwall = j; - if (j < secondstartwall) - wall[wall[j].nextwall].nextsector = numsectors; - else - wall[wall[j].nextwall].nextsector = numsectors+1; - } - } - //set all next pointers on split - for(j=numwalls;j= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,sectorofwall((short)j)); - } - - //k now safe to use as temp - - for(m=numsectors-2;mnumwalls;j--) - { - Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); - wall[danumwalls].nextwall = -1; - wall[danumwalls].nextsector = -1; - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - } - - m = splitstartwall; //copy rest of loop next - do - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } while (m != splitstartwall); - wall[danumwalls-1].point2 = numwalls; - - //Add other loops to sector - loopnum = loopnumofsector(splitsect,splitstartwall); - i = loopnum; - for(j=startwall;j<=endwall;j++) - { - k = loopnumofsector(splitsect,(short)j); - if ((k != i) && (k != loopnumofsector(splitsect,splitstartwall)) && (k != loopnumofsector(splitsect,splitendwall))) - { - i = k; - m = j; k = danumwalls; //copy loop - do - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } while (m != j); - wall[danumwalls-1].point2 = k; - } - } - - //fix all next pointers on old sector line - for(j=numwalls;j= 0) - { - wall[wall[j].nextwall].nextwall = j; - wall[wall[j].nextwall].nextsector = numsectors; - } - } - - //copy sector attributes & fix wall pointers - Bmemcpy(§or[numsectors],§or[splitsect],sizeof(sectortype)); - sector[numsectors].wallptr = numwalls; - sector[numsectors].wallnum = danumwalls-numwalls; - - //fix sprites - j = headspritesect[splitsect]; - while (j != -1) - { - k = nextspritesect[j]; - changespritesect(j,numsectors); - j = k; - } - - numsectors++; - - //Back of number of walls of new sector for later - k = danumwalls-numwalls; - - //clear out old sector's next pointers for clean deletesector - numwalls = danumwalls; - for(j=startwall;j<=endwall;j++) - { - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - deletesector(splitsect); - - //Check pointers - for(j=numwalls-k;j= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,numsectors-1); - } - - newnumwalls = -1; - printmessage16("Loops joined."); - break; - } - } - } - } - } - - if (keystatus[0x1c] > 0) //Left Enter - { - keystatus[0x1c] = 0; - if (keystatus[0x2a]&keystatus[0x1d]) - { - printmessage16("CHECKING ALL POINTERS!"); - for(i=0;i=0;i--) - sector[i].wallnum = sector[i+1].wallptr-sector[i].wallptr; - sector[numsectors-1].wallnum = numwalls-sector[numsectors-1].wallptr; - - for(i=0;i= 0) - { - checksectorpointer(linehighlight,sectorofwall(linehighlight)); - printmessage16("Highlighted line pointers checked."); - asksave = 1; - } - } - } - - if ((keystatus[0x0e] > 0) && (newnumwalls >= numwalls)) //Backspace - { - if (newnumwalls > numwalls) - { - newnumwalls--; - asksave = 1; - keystatus[0x0e] = 0; - } - if (newnumwalls == numwalls) - { - newnumwalls = -1; - asksave = 1; - keystatus[0x0e] = 0; - } - } - - if ((keystatus[0xd3] > 0) && (keystatus[0x9d] > 0) && (numwalls >= 0)) - { //sector delete - keystatus[0xd3] = 0; - - sucksect = -1; - for(i=0;i= 0) - for(j=0;j=0;j--) - { - deletesector(highlightsector[j]); - for(k=j-1;k>=0;k--) - if (highlightsector[k] >= highlightsector[j]) - highlightsector[k]--; - } - printmessage16("Highlighted sectors deleted."); - newnumwalls = -1; - k = 1; - highlightsectorcnt = -1; - break; - } - if (k == 0) - { - deletesector((short)i); - highlightsectorcnt = -1; - printmessage16("Sector deleted."); - } - newnumwalls = -1; - asksave = 1; - break; - } - } - - if ((keystatus[0xd3] > 0) && (pointhighlight >= 0)) - { - if ((pointhighlight&0xc000) == 16384) //Sprite Delete - { - deletesprite(pointhighlight&16383); - printmessage16("Sprite deleted."); - updatenumsprites(); - asksave = 1; - } - keystatus[0xd3] = 0; - } - - if (keystatus[0xd2] > 0) //InsertPoint - { - if (highlightsectorcnt >= 0) - { - newnumsectors = numsectors; - newnumwalls = numwalls; - for(i=0;i= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,highlightsector[i]); - } - highlightsector[i] = numsectors+i; - } - numsectors = newnumsectors; - numwalls = newnumwalls; - - newnumwalls = -1; - newnumsectors = -1; - - updatenumsprites(); - printmessage16("Sectors duplicated and stamped."); - asksave = 1; - } - else if (highlightcnt >= 0) - { - for(i=0;i= 0) - { - getclosestpointonwall(mousxplc,mousyplc,(long)linehighlight,&dax,&day); - adjustmark(&dax,&day,newnumwalls); - insertpoint(linehighlight,dax,day); - printmessage16("Point inserted."); - - j = 0; - //Check to see if point was inserted over another point - for(i=numwalls-1;i>=0;i--) //delete points - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) - { - deletepoint((short)i); - j++; - } - for(i=0;i>1); - // day = ((wall[linehighlight].y + wall[wall[linehighlight].point2].y)>>1); - // if ((dax != wall[linehighlight].x) || (day != wall[linehighlight].y)) - // if ((dax != wall[wall[linehighlight].point2].x) || (day != wall[wall[linehighlight].point2].y)) - // { - // insertpoint(linehighlight,dax,day); - // printmessage16("Point inserted at midpoint."); - // } - //} - - asksave = 1; - } - keystatus[0xd2] = 0; - } - - /*j = 0; - for(i=22-1;i>=0;i--) updatecrc16(j,kensig[i]); - if ((j&0xffff) != 0xebf) - { - printf("Don't screw with my name.\n"); - exit(0); - }*/ - //printext16(9L,336+9L,4,-1,kensig,0); - //printext16(8L,336+8L,12,-1,kensig,0); - - showframe(1); - synctics = totalclock-lockclock; - lockclock += synctics; - - if (keystatus[buildkeys[14]] > 0) - { - updatesector(posx,posy,&cursectnum); - if (cursectnum >= 0) - keystatus[buildkeys[14]] = 2; - else - printmessage16("Arrow must be inside a sector before entering 3D mode."); - } - CANCEL: - if (keystatus[1] > 0) - { - keystatus[1] = 0; - printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (Q)uit"); - showframe(1); - bflushchars(); - bad = 1; - while (bad == 1) - { - if (handleevents()) { - if (quitevent) { - quitevent = 0; - } - } - - ch = bgetchar(); - - if (keystatus[1] > 0) - { - keystatus[1] = 0; - bad = 0; - printmessage16(""); - } - else if (ch == 'n' || ch == 'N') //N - { - bad = 0; - printmessage16("Are you sure you want to start a new board? (Y/N)"); - showframe(1); - bflushchars(); ch = 0; - while (keystatus[1] == 0) - { - if (handleevents()) { - if (quitevent) { - quitevent = 0; - } - } - - ch = bgetchar(); - - if (ch == 'Y' || ch == 'y') - { - highlightsectorcnt = -1; - highlightcnt = -1; - - for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights - show2dwall[i] = 0; - for(i=0;i<(MAXSPRITES>>3);i++) - show2dsprite[i] = 0; - - for(i=0;i= 0) + circlewall = linehighlight; + } + keystatus[0x2e] = 0; + } + if (keystatus[0x4a] > 0) // - + { + if (circlepoints > 1) + circlepoints--; + keystatus[0x4a] = 0; + } + if (keystatus[0x4e] > 0) // + + { + if (circlepoints < 63) + circlepoints++; + keystatus[0x4e] = 0; + } + + bad = (keystatus[0x39] > 0); //Gotta do this to save lots of 3 spaces! + + if (circlewall >= 0) + { + x1 = wall[circlewall].x; + y1 = wall[circlewall].y; + x2 = wall[wall[circlewall].point2].x; + y2 = wall[wall[circlewall].point2].y; + x3 = mousxplc; + y3 = mousyplc; + adjustmark(&x3,&y3,newnumwalls); + templong1 = dmulscale4(x3-x2,x1-x3,y1-y3,y3-y2); + templong2 = dmulscale4(y1-y2,x1-x3,y1-y3,x2-x1); + if (templong2 != 0) + { + centerx = (((x1+x2) + scale(y1-y2,templong1,templong2))>>1); + centery = (((y1+y2) + scale(x2-x1,templong1,templong2))>>1); + + dax = mulscale14(centerx-posx,zoom); + day = mulscale14(centery-posy,zoom); + drawline16(halfxdim16+dax-2,midydim16+day-2,halfxdim16+dax+2,midydim16+day+2,14); + drawline16(halfxdim16+dax-2,midydim16+day+2,halfxdim16+dax+2,midydim16+day-2,14); + + circleang1 = getangle(x1-centerx,y1-centery); + circleang2 = getangle(x2-centerx,y2-centery); + + circleangdir = 1; + k = ((circleang2-circleang1)&2047); + if (mulscale4(x3-x1,y2-y1) < mulscale4(x2-x1,y3-y1)) + { + circleangdir = -1; + k = -((circleang1-circleang2)&2047); + } + + circlerad = (ksqrt(dmulscale4(centerx-x1,centerx-x1,centery-y1,centery-y1))<<2); + + for(i=circlepoints;i>0;i--) + { + j = ((circleang1 + scale(i,k,circlepoints+1))&2047); + dax = centerx+mulscale14(sintable[(j+512)&2047],circlerad); + day = centery+mulscale14(sintable[j],circlerad); + + if (dax <= -editorgridextent) dax = -editorgridextent; + if (dax >= editorgridextent) dax = editorgridextent; + if (day <= -editorgridextent) day = -editorgridextent; + if (day >= editorgridextent) day = editorgridextent; + + if (bad > 0) + { + m = 0; + if (wall[circlewall].nextwall >= 0) + if (wall[circlewall].nextwall < circlewall) m = 1; + insertpoint(circlewall,dax,day); + circlewall += m; + } + dax = mulscale14(dax-posx,zoom); + day = mulscale14(day-posy,zoom); + drawline16(halfxdim16+dax-2,midydim16+day-2,halfxdim16+dax+2,midydim16+day-2,14); + drawline16(halfxdim16+dax+2,midydim16+day-2,halfxdim16+dax+2,midydim16+day+2,14); + drawline16(halfxdim16+dax+2,midydim16+day+2,halfxdim16+dax-2,midydim16+day+2,14); + drawline16(halfxdim16+dax-2,midydim16+day+2,halfxdim16+dax-2,midydim16+day-2,14); + } + if (bad > 0) + { + bad = 0; + keystatus[0x39] = 0; + asksave = 1; + printmessage16("Circle points inserted."); + circlewall = -1; + } + } + } + + if (bad > 0) //Space bar test + { + keystatus[0x39] = 0; + adjustmark(&mousxplc,&mousyplc,newnumwalls); + if (checkautoinsert(mousxplc,mousyplc,newnumwalls) == 1) + { + printmessage16("You must insert a point there first."); + bad = 0; + } + } + + if (bad > 0) //Space + { + if ((newnumwalls < numwalls) && (numwalls < MAXWALLS-1)) + { + firstx = mousxplc, firsty = mousyplc; //Make first point + newnumwalls = numwalls; + suckwall = -1; + split = 0; + + //clearbufbyte(&wall[newnumwalls],sizeof(walltype),0L); + memset(&wall[newnumwalls],0,sizeof(walltype)); + wall[newnumwalls].extra = -1; + + wall[newnumwalls].x = mousxplc; + wall[newnumwalls].y = mousyplc; + wall[newnumwalls].nextsector = -1; + wall[newnumwalls].nextwall = -1; + for(i=0;i>1); + day = ((wall[numwalls].y+mousyplc)>>1); + for(i=0;i= 0) + if ((wall[wall[k].point2].x != mousxplc) || (wall[wall[k].point2].y != mousyplc)) + if ((wall[lastwall((short)k)].x != mousxplc) || (wall[lastwall((short)k)].y != mousyplc)) + { + split = 1; + splitsect = i; + splitstartwall = m; + break; + } + } + } + + //make new point + + //make sure not drawing over old red line + bad = 0; + for(i=0;i= 0) + { + if ((wall[i].x == mousxplc) && (wall[i].y == mousyplc)) + if ((wall[wall[i].point2].x == wall[newnumwalls-1].x) && (wall[wall[i].point2].y == wall[newnumwalls-1].y)) + bad = 1; + if ((wall[i].x == wall[newnumwalls-1].x) && (wall[i].y == wall[newnumwalls-1].y)) + if ((wall[wall[i].point2].x == mousxplc) && (wall[wall[i].point2].y == mousyplc)) + bad = 1; + } + } + + if (bad == 0) + { + //clearbufbyte(&wall[newnumwalls],sizeof(walltype),0L); + memset(&wall[newnumwalls],0,sizeof(walltype)); + wall[newnumwalls].extra = -1; + + wall[newnumwalls].x = mousxplc; + wall[newnumwalls].y = mousyplc; + wall[newnumwalls].nextsector = -1; + wall[newnumwalls].nextwall = -1; + for(i=0;i= numwalls+3)) + { + wall[newnumwalls-1].point2 = numwalls; + + if (suckwall == -1) //if no connections to other sectors + { + k = -1; + for(i=0;i= suckwall) + wall[i].nextwall += j; + if (wall[i].point2 >= suckwall) + wall[i].point2 += j; + } + + for(i=newnumwalls-1;i>=suckwall;i--) + Bmemcpy(&wall[i+j],&wall[i],sizeof(walltype)); + for(i=0;inumwalls;j--) + { + Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); + wall[danumwalls].nextwall = -1; + wall[danumwalls].nextsector = -1; + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + } + m = splitstartwall; //copy rest of loop next + while (m != splitendwall) + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + wall[danumwalls-1].point2 = secondstartwall; + + //Add other loops for 2nd sector + loopnum = loopnumofsector(splitsect,splitstartwall); + i = loopnum; + for(j=startwall;j<=endwall;j++) + { + k = loopnumofsector(splitsect,(short)j); + if ((k != i) && (k != loopnum)) + { + i = k; + if (loopinside(wall[j].x,wall[j].y,secondstartwall) == 1) + { + m = j; //copy loop + k = danumwalls; + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + while (m != j); + wall[danumwalls-1].point2 = k; + } + } + } + + //fix all next pointers on old sector line + for(j=numwalls;j= 0) + { + wall[wall[j].nextwall].nextwall = j; + if (j < secondstartwall) + wall[wall[j].nextwall].nextsector = numsectors; + else + wall[wall[j].nextwall].nextsector = numsectors+1; + } + } + //set all next pointers on split + for(j=numwalls;j= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,sectorofwall((short)j)); + } + + //k now safe to use as temp + + for(m=numsectors-2;mnumwalls;j--) + { + Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); + wall[danumwalls].nextwall = -1; + wall[danumwalls].nextsector = -1; + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + } + + m = splitstartwall; //copy rest of loop next + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } while (m != splitstartwall); + wall[danumwalls-1].point2 = numwalls; + + //Add other loops to sector + loopnum = loopnumofsector(splitsect,splitstartwall); + i = loopnum; + for(j=startwall;j<=endwall;j++) + { + k = loopnumofsector(splitsect,(short)j); + if ((k != i) && (k != loopnumofsector(splitsect,splitstartwall)) && (k != loopnumofsector(splitsect,splitendwall))) + { + i = k; + m = j; k = danumwalls; //copy loop + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } while (m != j); + wall[danumwalls-1].point2 = k; + } + } + + //fix all next pointers on old sector line + for(j=numwalls;j= 0) + { + wall[wall[j].nextwall].nextwall = j; + wall[wall[j].nextwall].nextsector = numsectors; + } + } + + //copy sector attributes & fix wall pointers + Bmemcpy(§or[numsectors],§or[splitsect],sizeof(sectortype)); + sector[numsectors].wallptr = numwalls; + sector[numsectors].wallnum = danumwalls-numwalls; + + //fix sprites + j = headspritesect[splitsect]; + while (j != -1) + { + k = nextspritesect[j]; + changespritesect(j,numsectors); + j = k; + } + + numsectors++; + + //Back of number of walls of new sector for later + k = danumwalls-numwalls; + + //clear out old sector's next pointers for clean deletesector + numwalls = danumwalls; + for(j=startwall;j<=endwall;j++) + { + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + deletesector(splitsect); + + //Check pointers + for(j=numwalls-k;j= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,numsectors-1); + } + + newnumwalls = -1; + printmessage16("Loops joined."); + break; + } + } + } + } + } + + if (keystatus[0x1c] > 0) //Left Enter + { + keystatus[0x1c] = 0; + if (keystatus[0x2a]&keystatus[0x1d]) + { + printmessage16("CHECKING ALL POINTERS!"); + for(i=0;i=0;i--) + sector[i].wallnum = sector[i+1].wallptr-sector[i].wallptr; + sector[numsectors-1].wallnum = numwalls-sector[numsectors-1].wallptr; + + for(i=0;i= 0) + { + checksectorpointer(linehighlight,sectorofwall(linehighlight)); + printmessage16("Highlighted line pointers checked."); + asksave = 1; + } + } + } + + if ((keystatus[0x0e] > 0) && (newnumwalls >= numwalls)) //Backspace + { + if (newnumwalls > numwalls) + { + newnumwalls--; + asksave = 1; + keystatus[0x0e] = 0; + } + if (newnumwalls == numwalls) + { + newnumwalls = -1; + asksave = 1; + keystatus[0x0e] = 0; + } + } + + if ((keystatus[0xd3] > 0) && (keystatus[0x9d] > 0) && (numwalls >= 0)) + { //sector delete + keystatus[0xd3] = 0; + + sucksect = -1; + for(i=0;i= 0) + for(j=0;j=0;j--) + { + deletesector(highlightsector[j]); + for(k=j-1;k>=0;k--) + if (highlightsector[k] >= highlightsector[j]) + highlightsector[k]--; + } + printmessage16("Highlighted sectors deleted."); + newnumwalls = -1; + k = 1; + highlightsectorcnt = -1; + break; + } + if (k == 0) + { + deletesector((short)i); + highlightsectorcnt = -1; + printmessage16("Sector deleted."); + } + newnumwalls = -1; + asksave = 1; + break; + } + } + + if ((keystatus[0xd3] > 0) && (pointhighlight >= 0)) + { + if ((pointhighlight&0xc000) == 16384) //Sprite Delete + { + deletesprite(pointhighlight&16383); + printmessage16("Sprite deleted."); + updatenumsprites(); + asksave = 1; + } + keystatus[0xd3] = 0; + } + + if (keystatus[0xd2] > 0) //InsertPoint + { + if (highlightsectorcnt >= 0) + { + newnumsectors = numsectors; + newnumwalls = numwalls; + for(i=0;i= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,highlightsector[i]); + } + highlightsector[i] = numsectors+i; + } + numsectors = newnumsectors; + numwalls = newnumwalls; + + newnumwalls = -1; + newnumsectors = -1; + + updatenumsprites(); + printmessage16("Sectors duplicated and stamped."); + asksave = 1; + } + else if (highlightcnt >= 0) + { + for(i=0;i= 0) + { + getclosestpointonwall(mousxplc,mousyplc,(long)linehighlight,&dax,&day); + adjustmark(&dax,&day,newnumwalls); + insertpoint(linehighlight,dax,day); + printmessage16("Point inserted."); + + j = 0; + //Check to see if point was inserted over another point + for(i=numwalls-1;i>=0;i--) //delete points + if (wall[i].x == wall[wall[i].point2].x) + if (wall[i].y == wall[wall[i].point2].y) + { + deletepoint((short)i); + j++; + } + for(i=0;i>1); + // day = ((wall[linehighlight].y + wall[wall[linehighlight].point2].y)>>1); + // if ((dax != wall[linehighlight].x) || (day != wall[linehighlight].y)) + // if ((dax != wall[wall[linehighlight].point2].x) || (day != wall[wall[linehighlight].point2].y)) + // { + // insertpoint(linehighlight,dax,day); + // printmessage16("Point inserted at midpoint."); + // } + //} + + asksave = 1; + } + keystatus[0xd2] = 0; + } + + /*j = 0; + for(i=22-1;i>=0;i--) updatecrc16(j,kensig[i]); + if ((j&0xffff) != 0xebf) + { + printf("Don't screw with my name.\n"); + exit(0); + }*/ + //printext16(9L,336+9L,4,-1,kensig,0); + //printext16(8L,336+8L,12,-1,kensig,0); + + showframe(1); + synctics = totalclock-lockclock; + lockclock += synctics; + + if (keystatus[buildkeys[14]] > 0) + { + updatesector(posx,posy,&cursectnum); + if (cursectnum >= 0) + keystatus[buildkeys[14]] = 2; + else + printmessage16("Arrow must be inside a sector before entering 3D mode."); + } +CANCEL: + if (keystatus[1] > 0) + { + keystatus[1] = 0; + printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (Q)uit"); + showframe(1); + bflushchars(); + bad = 1; + while (bad == 1) + { + if (handleevents()) { + if (quitevent) { + quitevent = 0; + } + } + + ch = bgetchar(); + + if (keystatus[1] > 0) + { + keystatus[1] = 0; + bad = 0; + printmessage16(""); + } + else if (ch == 'n' || ch == 'N') //N + { + bad = 0; + printmessage16("Are you sure you want to start a new board? (Y/N)"); + showframe(1); + bflushchars(); ch = 0; + while (keystatus[1] == 0) + { + if (handleevents()) { + if (quitevent) { + quitevent = 0; + } + } + + ch = bgetchar(); + + if (ch == 'Y' || ch == 'y') + { + highlightsectorcnt = -1; + highlightcnt = -1; + + for(i=0;i<(MAXWALLS>>3);i++) //Clear all highlights + show2dwall[i] = 0; + for(i=0;i<(MAXSPRITES>>3);i++) + show2dsprite[i] = 0; + + for(i=0;i= 0) - { - j = 0; k = 0; - for(i=0;i= 0) + { + j = 0; k = 0; + for(i=0;i MAXSECTORS) || (numwalls+j > MAXWALLS) || (numsprites+k > MAXSPRITES)) - { - highlightsectorcnt = -1; - } - else - { - //Put sectors&walls to end of lists - j = MAXWALLS; - for(i=0;i MAXSECTORS) || (numwalls+j > MAXWALLS) || (numsprites+k > MAXSPRITES)) + { + highlightsectorcnt = -1; + } + else + { + //Put sectors&walls to end of lists + j = MAXWALLS; + for(i=0;i=0;i--) - if (sprite[i].statnum < MAXSTATUS) - { - k = sprite[i].sectnum; - for(j=0;j=0;i--) + if (sprite[i].statnum < MAXSTATUS) + { + k = sprite[i].sectnum; + for(j=0;j= 0) - { - if ((numsectors+highlightsectorcnt > MAXSECTORS) || (sector[MAXSECTORS-highlightsectorcnt].wallptr < numwalls)) - { - highlightsectorcnt = -1; - } - else - { - //Re-attach sectors&walls - for(i=0;i= 0) + { + if ((numsectors+highlightsectorcnt > MAXSECTORS) || (sector[MAXSECTORS-highlightsectorcnt].wallptr < numwalls)) + { + highlightsectorcnt = -1; + } + else + { + //Re-attach sectors&walls + for(i=0;i= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,highlightsector[i]); - } - } + for(i=0;i= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,highlightsector[i]); + } + } - } - } + } + } - if (mapversion < 7) printmessage16("Map loaded successfully and autoconverted to V7!"); - else printmessage16("Map loaded successfully."); - } - updatenumsprites(); - startposx = posx; //this is same - startposy = posy; - startposz = posz; - startang = ang; - startsectnum = cursectnum; - } - showframe(1); - keystatus[0x1c] = 0; - } - else if (ch == 'a' || ch == 'A') //A - { - bad = 0; + if (mapversion < 7) printmessage16("Map loaded successfully and autoconverted to V7!"); + else printmessage16("Map loaded successfully."); + } + updatenumsprites(); + startposx = posx; //this is same + startposy = posy; + startposz = posz; + startang = ang; + startsectnum = cursectnum; + } + showframe(1); + keystatus[0x1c] = 0; + } + else if (ch == 'a' || ch == 'A') //A + { + bad = 0; - Bstrcpy(selectedboardfilename, boardfilename); - if (Bstrrchr(boardfilename, '/')) - Bstrcpy(boardfilename, Bstrrchr(boardfilename, '/')+1); + Bstrcpy(selectedboardfilename, boardfilename); + if (Bstrrchr(boardfilename, '/')) + Bstrcpy(boardfilename, Bstrrchr(boardfilename, '/')+1); - i = 0; - while ((boardfilename[i] != 0) && (i < 64)) - i++; - if (boardfilename[i-4] == '.') - i -= 4; - boardfilename[i] = 0; + i = 0; + while ((boardfilename[i] != 0) && (i < 64)) + i++; + if (boardfilename[i-4] == '.') + i -= 4; + boardfilename[i] = 0; - bflushchars(); - while (bad == 0) - { - Bsprintf(buffer,"Save as: %s_", boardfilename); - printmessage16(buffer); - showframe(1); + bflushchars(); + while (bad == 0) + { + Bsprintf(buffer,"Save as: %s_", boardfilename); + printmessage16(buffer); + showframe(1); - if (handleevents()) { - if (quitevent) quitevent = 0; - } - - ch = bgetchar(); + if (handleevents()) { + if (quitevent) quitevent = 0; + } - if (keystatus[1] > 0) bad = 1; - else if (ch == 13) bad = 2; - else if (ch > 0) { - if (i > 0 && (ch == 8 || ch == 127)) { - i--; - boardfilename[i] = 0; - } - else if (i < 8 && ch > 32 && ch < 128) - { - boardfilename[i++] = ch; - boardfilename[i] = 0; - } - } - } - if (bad == 1) - { - Bstrcpy(boardfilename, selectedboardfilename); - keystatus[1] = 0; - printmessage16("Operation cancelled"); - showframe(1); - } - if (bad == 2) - { - char *f; - keystatus[0x1c] = 0; + ch = bgetchar(); - boardfilename[i] = '.'; - boardfilename[i+1] = 'm'; - boardfilename[i+2] = 'a'; - boardfilename[i+3] = 'p'; - boardfilename[i+4] = 0; + if (keystatus[1] > 0) bad = 1; + else if (ch == 13) bad = 2; + else if (ch > 0) { + if (i > 0 && (ch == 8 || ch == 127)) { + i--; + boardfilename[i] = 0; + } + else if (i < 8 && ch > 32 && ch < 128) + { + boardfilename[i++] = ch; + boardfilename[i] = 0; + } + } + } + if (bad == 1) + { + Bstrcpy(boardfilename, selectedboardfilename); + keystatus[1] = 0; + printmessage16("Operation cancelled"); + showframe(1); + } + if (bad == 2) + { + char *f; + keystatus[0x1c] = 0; - if (Bstrrchr(selectedboardfilename,'/')) - Bstrcpy(Bstrrchr(selectedboardfilename, '/')+1, boardfilename); - else - Bstrcpy(selectedboardfilename, boardfilename); - if (pathsearchmode) f = selectedboardfilename; - else { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = strrchr(selectedboardfilename, '/'); - if (!f) f = selectedboardfilename; else f++; - } - Bsprintf(buffer,"Saving to %s...",f); - printmessage16(buffer); - showframe(1); + boardfilename[i] = '.'; + boardfilename[i+1] = 'm'; + boardfilename[i+2] = 'a'; + boardfilename[i+3] = 'p'; + boardfilename[i+4] = 0; - fixspritesectors(); //Do this before saving! - updatesector(startposx,startposy,&startsectnum); - ExtPreSaveMap(); - saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); - ExtSaveMap(f); - printmessage16("Board saved."); - Bstrcpy(boardfilename, selectedboardfilename); - } - bad = 0; - } - else if (ch == 's' || ch == 'S') //S - { - char *f; - bad = 0; - printmessage16("Saving board..."); - showframe(1); - fixspritesectors(); //Do this before saving! - updatesector(startposx,startposy,&startsectnum); - if (pathsearchmode) f = boardfilename; - else { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = strrchr(boardfilename, '/'); - if (!f) f = boardfilename; else f++; - } - ExtPreSaveMap(); - saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); - ExtSaveMap(f); - printmessage16("Board saved."); - showframe(1); - } - else if (ch == 'q' || ch == 'Q') //Q - { - bad = 0; - printmessage16("Are you sure you want to quit?"); - showframe(1); - bflushchars(); + if (Bstrrchr(selectedboardfilename,'/')) + Bstrcpy(Bstrrchr(selectedboardfilename, '/')+1, boardfilename); + else + Bstrcpy(selectedboardfilename, boardfilename); + if (pathsearchmode) f = selectedboardfilename; + else { + // virtual filesystem mode can't save to directories so drop the file into + // the current directory + f = strrchr(selectedboardfilename, '/'); + if (!f) f = selectedboardfilename; else f++; + } + Bsprintf(buffer,"Saving to %s...",f); + printmessage16(buffer); + showframe(1); + + fixspritesectors(); //Do this before saving! + updatesector(startposx,startposy,&startsectnum); + ExtPreSaveMap(); + saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); + ExtSaveMap(f); + printmessage16("Board saved."); + Bstrcpy(boardfilename, selectedboardfilename); + } + bad = 0; + } + else if (ch == 's' || ch == 'S') //S + { + char *f; + bad = 0; + printmessage16("Saving board..."); + showframe(1); + fixspritesectors(); //Do this before saving! + updatesector(startposx,startposy,&startsectnum); + if (pathsearchmode) f = boardfilename; + else { + // virtual filesystem mode can't save to directories so drop the file into + // the current directory + f = strrchr(boardfilename, '/'); + if (!f) f = boardfilename; else f++; + } + ExtPreSaveMap(); + saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); + ExtSaveMap(f); + printmessage16("Board saved."); + showframe(1); + } + else if (ch == 'q' || ch == 'Q') //Q + { + bad = 0; + printmessage16("Are you sure you want to quit?"); + showframe(1); + bflushchars(); while ((keystatus[1]|keystatus[0x2e]) == 0) - { - if (handleevents()) { - if (quitevent) quitevent = 0; - } + { + if (handleevents()) { + if (quitevent) quitevent = 0; + } - ch = bgetchar(); + ch = bgetchar(); - if (ch == 'y' || ch == 'Y') - { - //QUIT! + if (ch == 'y' || ch == 'Y') + { + //QUIT! - printmessage16("Save changes?"); - showframe(1); + printmessage16("Save changes?"); + showframe(1); while ((keystatus[1]|keystatus[0x2e]) == 0) - { - if (handleevents()) { - if (quitevent) break; // like saying no - } + { + if (handleevents()) { + if (quitevent) break; // like saying no + } - ch = bgetchar(); + ch = bgetchar(); - if (ch == 'y' || ch == 'Y') - { - char *f; - fixspritesectors(); //Do this before saving! - updatesector(startposx,startposy,&startsectnum); - ExtPreSaveMap(); - if (pathsearchmode) f = boardfilename; - else { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = strrchr(boardfilename, '/'); - if (!f) f = boardfilename; else f++; - } - saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); - ExtSaveMap(f); - break; - } else if (ch == 'n' || ch == 'N' || ch == 13 || ch == ' ') { - break; - } - } + if (ch == 'y' || ch == 'Y') + { + char *f; + fixspritesectors(); //Do this before saving! + updatesector(startposx,startposy,&startsectnum); + ExtPreSaveMap(); + if (pathsearchmode) f = boardfilename; + else { + // virtual filesystem mode can't save to directories so drop the file into + // the current directory + f = strrchr(boardfilename, '/'); + if (!f) f = boardfilename; else f++; + } + saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); + ExtSaveMap(f); + break; + } else if (ch == 'n' || ch == 'N' || ch == 13 || ch == ' ') { + break; + } + } while(keystatus[1] || keystatus[0x2e]) { keystatus[1] = 0; @@ -5788,541 +5788,541 @@ void overheadeditor(void) showframe(1); goto CANCEL; } - clearfilenames(); - uninittimer(); - uninitinput(); - ExtUnInit(); - uninitengine(); - printf("Memory status: %ld(%ld) bytes\n",cachesize,artsize); - printf("%s\n",kensig); - exit(0); - } else if (ch == 'n' || ch == 'N' || ch == 13 || ch == ' ') { - break; - } - } - printmessage16(""); - showframe(1); - } - } - clearkeys(); - } + clearfilenames(); + uninittimer(); + uninitinput(); + ExtUnInit(); + uninitengine(); + printf("Memory status: %ld(%ld) bytes\n",cachesize,artsize); + printf("%s\n",kensig); + exit(0); + } else if (ch == 'n' || ch == 'N' || ch == 13 || ch == ' ') { + break; + } + } + printmessage16(""); + showframe(1); + } + } + clearkeys(); + } - //nextpage(); - } + //nextpage(); + } - for(i=0;i= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((short)j,highlightsector[i]); - } - } + for(i=0;i= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((short)j,highlightsector[i]); + } + } - fixspritesectors(); + fixspritesectors(); - if (setgamemode(fullscreen,xdimgame,ydimgame,bppgame) < 0) - { - ExtUnInit(); - uninitinput(); - uninittimer(); - uninitsystem(); - clearfilenames(); - printf("%ld * %ld not supported in this graphics mode\n",xdim,ydim); - exit(0); - } + if (setgamemode(fullscreen,xdimgame,ydimgame,bppgame) < 0) + { + ExtUnInit(); + uninitinput(); + uninittimer(); + uninitsystem(); + clearfilenames(); + printf("%ld * %ld not supported in this graphics mode\n",xdim,ydim); + exit(0); + } - posz = oposz; - searchx = scale(searchx,xdimgame,xdim2d); - searchy = scale(searchy,ydimgame,ydim2d-STATUS2DSIZ); + posz = oposz; + searchx = scale(searchx,xdimgame,xdim2d); + searchy = scale(searchy,ydimgame,ydim2d-STATUS2DSIZ); } void getpoint(long searchxe, long searchye, long *x, long *y) { - if (posx <= -editorgridextent) posx = -editorgridextent; - if (posx >= editorgridextent) posx = editorgridextent; - if (posy <= -editorgridextent) posy = -editorgridextent; - if (posy >= editorgridextent) posy = editorgridextent; + if (posx <= -editorgridextent) posx = -editorgridextent; + if (posx >= editorgridextent) posx = editorgridextent; + if (posy <= -editorgridextent) posy = -editorgridextent; + if (posy >= editorgridextent) posy = editorgridextent; - *x = posx + divscale14(searchxe-halfxdim16,zoom); - *y = posy + divscale14(searchye-midydim16,zoom); + *x = posx + divscale14(searchxe-halfxdim16,zoom); + *y = posy + divscale14(searchye-midydim16,zoom); - if (*x <= -editorgridextent) *x = -editorgridextent; - if (*x >= editorgridextent) *x = editorgridextent; - if (*y <= -editorgridextent) *y = -editorgridextent; - if (*y >= editorgridextent) *y = editorgridextent; + if (*x <= -editorgridextent) *x = -editorgridextent; + if (*x >= editorgridextent) *x = editorgridextent; + if (*y <= -editorgridextent) *y = -editorgridextent; + if (*y >= editorgridextent) *y = editorgridextent; } long getlinehighlight(long xplc, long yplc) { - long i, dst, dist, closest, x1, y1, x2, y2, nx, ny; + long i, dst, dist, closest, x1, y1, x2, y2, nx, ny; - if (numwalls == 0) - return(-1); + if (numwalls == 0) + return(-1); dist = 1024; - closest = numwalls-1; - for(i=0;i= 0) - { //if red line, allow highlighting of both sides - x1 = wall[closest].x; - y1 = wall[closest].y; - x2 = wall[wall[closest].point2].x; - y2 = wall[wall[closest].point2].y; - if (dmulscale32(xplc-x1,y2-y1,-(x2-x1),yplc-y1) >= 0) - closest = wall[closest].nextwall; - } - if ((pointhighlight&0xc000) == 16384) return (-1); - else return(closest); + if (wall[closest].nextwall >= 0) + { //if red line, allow highlighting of both sides + x1 = wall[closest].x; + y1 = wall[closest].y; + x2 = wall[wall[closest].point2].x; + y2 = wall[wall[closest].point2].y; + if (dmulscale32(xplc-x1,y2-y1,-(x2-x1),yplc-y1) >= 0) + closest = wall[closest].nextwall; + } + if ((pointhighlight&0xc000) == 16384) return (-1); + else return(closest); } long getpointhighlight(long xplc, long yplc) { - long i, dst, dist, closest; + long i, dst, dist, closest; - if (numwalls == 0) - return(-1); + if (numwalls == 0) + return(-1); - dist = 0; - if (grid > 0) - dist = 512; + dist = 0; + if (grid > 0) + dist = 512; - closest = -1; - for(i=0;i= 256) - for(i=0;i 0) && (gridlock > 0)) - pointlockdist = (128>>grid); + pointlockdist = 0; + if ((grid > 0) && (gridlock > 0)) + pointlockdist = (128>>grid); - dist = pointlockdist; - dax = *xplc; - day = *yplc; - for(i=0;i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + dist = pointlockdist; + dax = *xplc; + day = *yplc; + for(i=0;i 0) && (grid > 0)) + { + dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); + day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + } - *xplc = dax; - *yplc = day; - return(0); + *xplc = dax; + *yplc = day; + return(0); } long checkautoinsert(long dax, long day, short danumwalls) { - long i, x1, y1, x2, y2; + long i, x1, y1, x2, y2; - if (danumwalls < 0) - danumwalls = numwalls; - for(i=0;i= y2) && (y1 <= y0)) return(0); - if ((y1 >= y0) && (y1 <= y2)) return(1); + if ((y1 >= y2) && (y1 <= y0)) return(0); + if ((y1 >= y0) && (y1 <= y2)) return(1); - templong = (x0-x1)*(y2-y1) - (x2-x1)*(y0-y1); - if (templong < 0) - return(0); - else - return(1); + templong = (x0-x1)*(y2-y1) - (x2-x1)*(y0-y1); + if (templong < 0) + return(0); + else + return(1); } void flipwalls(short numwalls, short newnumwalls) { - long i, j, nume, templong; + long i, j, nume, templong; - nume = newnumwalls-numwalls; + nume = newnumwalls-numwalls; - for(i=numwalls;i>1);i++) - { - j = numwalls+newnumwalls-i-1; - templong = wall[i].x; wall[i].x = wall[j].x; wall[j].x = templong; - templong = wall[i].y; wall[i].y = wall[j].y; wall[j].y = templong; - } + for(i=numwalls;i>1);i++) + { + j = numwalls+newnumwalls-i-1; + templong = wall[i].x; wall[i].x = wall[j].x; wall[j].x = templong; + templong = wall[i].y; wall[i].y = wall[j].y; wall[j].y = templong; + } } void insertpoint(short linehighlight, long dax, long day) { - short sucksect; - long i, j, k; + short sucksect; + long i, j, k; - j = linehighlight; - sucksect = sectorofwall((short)j); + j = linehighlight; + sucksect = sectorofwall((short)j); - sector[sucksect].wallnum++; - for(i=sucksect+1;i= 0) - { - k = wall[j].nextwall; + if (wall[j].nextwall >= 0) + { + k = wall[j].nextwall; - sucksect = sectorofwall((short)k); + sucksect = sectorofwall((short)k); - sector[sucksect].wallnum++; - for(i=sucksect+1;i= 0) - { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; - } - if (wall[point].nextwall >= 0) - { - wall[wall[point].nextwall].nextwall = -1; - wall[wall[point].nextwall].nextsector = -1; - } - movewalls((long)point,-1L); + if (wall[j].nextwall >= 0) + { + wall[wall[j].nextwall].nextwall = -1; + wall[wall[j].nextwall].nextsector = -1; + } + if (wall[point].nextwall >= 0) + { + wall[wall[point].nextwall].nextwall = -1; + wall[wall[point].nextwall].nextsector = -1; + } + movewalls((long)point,-1L); - checksectorpointer((short)j,(short)sucksect); + checksectorpointer((short)j,(short)sucksect); } long deletesector(short sucksect) { - long i, j, k, nextk, startwall, endwall; + long i, j, k, nextk, startwall, endwall; - while (headspritesect[sucksect] >= 0) - deletesprite(headspritesect[sucksect]); - updatenumsprites(); + while (headspritesect[sucksect] >= 0) + deletesprite(headspritesect[sucksect]); + updatenumsprites(); - startwall = sector[sucksect].wallptr; - endwall = startwall + sector[sucksect].wallnum - 1; - j = sector[sucksect].wallnum; + startwall = sector[sucksect].wallptr; + endwall = startwall + sector[sucksect].wallnum - 1; + j = sector[sucksect].wallnum; - for(i=sucksect;i= startwall) - wall[i].nextsector--; - return(0); + j = endwall-startwall+1; + for (i=startwall;i<=endwall;i++) + if (wall[i].nextwall != -1) + { + wall[wall[i].nextwall].nextwall = -1; + wall[wall[i].nextwall].nextsector = -1; + } + movewalls(startwall,-j); + for(i=0;i= startwall) + wall[i].nextsector--; + return(0); } void fixspritesectors(void) { - long i, j, dax, day, daz; + long i, j, dax, day, daz; - for(i=numsectors-1;i>=0;i--) - if ((sector[i].wallnum <= 0) || (sector[i].wallptr >= numwalls)) - deletesector((short)i); + for(i=numsectors-1;i>=0;i--) + if ((sector[i].wallnum <= 0) || (sector[i].wallptr >= numwalls)) + deletesector((short)i); - for(i=0;i= getceilzofslope(j,dax,day)) - if (sprite[i].z-daz <= getflorzofslope(j,dax,day)) - { - changespritesect((short)i,(short)j); - break; - } - } - } + for(j=0;j= getceilzofslope(j,dax,day)) + if (sprite[i].z-daz <= getflorzofslope(j,dax,day)) + { + changespritesect((short)i,(short)j); + break; + } + } + } } long movewalls(long start, long offs) { - long i; + long i; - if (offs < 0) //Delete - { - for(i=start;i 0) //Insert - { - for(i=numwalls+offs-1;i>=start+offs;i--) - Bmemcpy(&wall[i],&wall[i-offs],sizeof(walltype)); - } - numwalls += offs; - for(i=0;i= start) wall[i].nextwall += offs; - if (wall[i].point2 >= start) wall[i].point2 += offs; - } - return(0); + if (offs < 0) //Delete + { + for(i=start;i 0) //Insert + { + for(i=numwalls+offs-1;i>=start+offs;i--) + Bmemcpy(&wall[i],&wall[i-offs],sizeof(walltype)); + } + numwalls += offs; + for(i=0;i= start) wall[i].nextwall += offs; + if (wall[i].point2 >= start) wall[i].point2 += offs; + } + return(0); } long checksectorpointer(short i, short sectnum) { - long j, k, startwall, endwall, x1, y1, x2, y2; + long j, k, startwall, endwall, x1, y1, x2, y2; - x1 = wall[i].x; - y1 = wall[i].y; - x2 = wall[wall[i].point2].x; - y2 = wall[wall[i].point2].y; + x1 = wall[i].x; + y1 = wall[i].y; + x2 = wall[wall[i].point2].x; + y2 = wall[wall[i].point2].y; - if (wall[i].nextwall >= 0) //Check for early exit - { - k = wall[i].nextwall; - if ((wall[k].x == x2) && (wall[k].y == y2)) - if ((wall[wall[k].point2].x == x1) && (wall[wall[k].point2].y == y1)) - return(0); - } + if (wall[i].nextwall >= 0) //Check for early exit + { + k = wall[i].nextwall; + if ((wall[k].x == x2) && (wall[k].y == y2)) + if ((wall[wall[k].point2].x == x1) && (wall[wall[k].point2].y == y1)) + return(0); + } - wall[i].nextsector = -1; - wall[i].nextwall = -1; - for(j=0;j> 2, 0x08080808l); + begindrawing(); + ydim16 = ydim; + // clearbuf((char *)(frameplace + (bytesperline*(ydim-STATUS2DSIZ+25L))),(bytesperline*(STATUS2DSIZ-1-(25<<1))) >> 2, 0x08080808l); clearbuf((char *)(frameplace + (bytesperline*(ydim-STATUS2DSIZ+25L))),(bytesperline*(STATUS2DSIZ+2-(25<<1))) >> 2, 0x00000000l); - drawline16(0,ydim-STATUS2DSIZ,0,ydim-1,7); - drawline16(xdim-1,ydim-STATUS2DSIZ,xdim-1,ydim-1,7); - ydim16 = ydim-STATUS2DSIZ; - enddrawing(); + drawline16(0,ydim-STATUS2DSIZ,0,ydim-1,7); + drawline16(xdim-1,ydim-STATUS2DSIZ,xdim-1,ydim-1,7); + ydim16 = ydim-STATUS2DSIZ; + enddrawing(); } short loopinside(long x, long y, short startwall) { - long x1, y1, x2, y2, templong; - short i, cnt; + long x1, y1, x2, y2, templong; + short i, cnt; - cnt = clockdir(startwall); - i = startwall; - do - { - x1 = wall[i].x; x2 = wall[wall[i].point2].x; - if ((x1 >= x) || (x2 >= x)) - { - y1 = wall[i].y; y2 = wall[wall[i].point2].y; - if (y1 > y2) - { - templong = x1, x1 = x2, x2 = templong; - templong = y1, y1 = y2, y2 = templong; - } - if ((y1 <= y) && (y2 > y)) - if (x1*(y-y2)+x2*(y1-y) <= x*(y1-y2)) - cnt ^= 1; - } - i = wall[i].point2; - } - while (i != startwall); - return(cnt); + cnt = clockdir(startwall); + i = startwall; + do + { + x1 = wall[i].x; x2 = wall[wall[i].point2].x; + if ((x1 >= x) || (x2 >= x)) + { + y1 = wall[i].y; y2 = wall[wall[i].point2].y; + if (y1 > y2) + { + templong = x1, x1 = x2, x2 = templong; + templong = y1, y1 = y2, y2 = templong; + } + if ((y1 <= y) && (y2 > y)) + if (x1*(y-y2)+x2*(y1-y) <= x*(y1-y2)) + cnt ^= 1; + } + i = wall[i].point2; + } + while (i != startwall); + return(cnt); } long numloopsofsector(short sectnum) { - long i, numloops, startwall, endwall; + long i, numloops, startwall, endwall; - numloops = 0; - startwall = sector[sectnum].wallptr; - endwall = startwall + sector[sectnum].wallnum; - for(i=startwall;i= '0' && ch <= '9') { - if (danum >= 0) + if (ch >= '0' && ch <= '9') { + if (danum >= 0) { - n = (danum*10)+(ch-'0'); + n = (danum*10)+(ch-'0'); if (n <= maxnumber) danum = n; } else if (sign) // this extra check isn't hurting anything @@ -6330,50 +6330,50 @@ long getnumber16(char namestart[80], long num, long maxnumber, char sign) n = (danum*10)-(ch-'0'); if (n >= -maxnumber) danum = n; } - } else if (ch == 8 || ch == 127) { // backspace - danum /= 10; - } else if (ch == 13) { - oldnum = danum; - asksave = 1; - break; - } else if (ch == '-' && sign) { // negate - danum = -danum; - } - } - clearkeys(); + } else if (ch == 8 || ch == 127) { // backspace + danum /= 10; + } else if (ch == 13) { + oldnum = danum; + asksave = 1; + break; + } else if (ch == '-' && sign) { // negate + danum = -danum; + } + } + clearkeys(); return(oldnum); } long getnumber256(char namestart[80], long num, long maxnumber, char sign) { - char buffer[80], ch; - long j, k, n, danum, oldnum; + char buffer[80], ch; + long j, k, n, danum, oldnum; danum = num; - oldnum = danum; - bflushchars(); - while (keystatus[0x1] == 0) - { - if (handleevents()) { - if (quitevent) quitevent = 0; - } + oldnum = danum; + bflushchars(); + while (keystatus[0x1] == 0) + { + if (handleevents()) { + if (quitevent) quitevent = 0; + } - drawrooms(posx,posy,posz,ang,horiz,cursectnum); + drawrooms(posx,posy,posz,ang,horiz,cursectnum); #ifdef SUPERBUILD - ExtAnalyzeSprites(); + ExtAnalyzeSprites(); #endif - drawmasks(); + drawmasks(); - ch = bgetchar(); + ch = bgetchar(); - Bsprintf(buffer,"%s%ld_ ",namestart,danum); - printmessage256(buffer); - showframe(1); + Bsprintf(buffer,"%s%ld_ ",namestart,danum); + printmessage256(buffer); + showframe(1); - if (ch >= '0' && ch <= '9') { - if (danum >= 0) + if (ch >= '0' && ch <= '9') { + if (danum >= 0) { - n = (danum*10)+(ch-'0'); + n = (danum*10)+(ch-'0'); if (n <= maxnumber) danum = n; } else if (sign) @@ -6381,141 +6381,141 @@ long getnumber256(char namestart[80], long num, long maxnumber, char sign) n = (danum*10)-(ch-'0'); if (n >= -maxnumber) danum = n; } - } else if (ch == 8 || ch == 127) { // backspace - danum /= 10; - } else if (ch == 13) { - oldnum = danum; - asksave = 1; - break; - } else if (ch == '-' && sign) { // negate - danum = -danum; - } - } - clearkeys(); + } else if (ch == 8 || ch == 127) { // backspace + danum /= 10; + } else if (ch == 13) { + oldnum = danum; + asksave = 1; + break; + } else if (ch == '-' && sign) { // negate + danum = -danum; + } + } + clearkeys(); - lockclock = totalclock; //Reset timing + lockclock = totalclock; //Reset timing return(oldnum); } void clearfilenames(void) { - klistfree(finddirs); - klistfree(findfiles); - finddirs = findfiles = NULL; - numfiles = numdirs = 0; + klistfree(finddirs); + klistfree(findfiles); + finddirs = findfiles = NULL; + numfiles = numdirs = 0; } long getfilenames(char *path, char kind[6]) { - CACHE1D_FIND_REC *r; + CACHE1D_FIND_REC *r; - clearfilenames(); - finddirs = klistpath(path,"*",CACHE1D_FIND_DIR|CACHE1D_FIND_DRIVE|(!pathsearchmode&&grponlymode?CACHE1D_OPT_NOSTACK:0)); - findfiles = klistpath(path,kind,CACHE1D_FIND_FILE|(!pathsearchmode&&grponlymode?CACHE1D_OPT_NOSTACK:0)); - for (r = finddirs; r; r=r->next) numdirs++; - for (r = findfiles; r; r=r->next) numfiles++; - - finddirshigh = finddirs; - findfileshigh = findfiles; - currentlist = 0; - if (findfileshigh) currentlist = 1; + clearfilenames(); + finddirs = klistpath(path,"*",CACHE1D_FIND_DIR|CACHE1D_FIND_DRIVE|(!pathsearchmode&&grponlymode?CACHE1D_OPT_NOSTACK:0)); + findfiles = klistpath(path,kind,CACHE1D_FIND_FILE|(!pathsearchmode&&grponlymode?CACHE1D_OPT_NOSTACK:0)); + for (r = finddirs; r; r=r->next) numdirs++; + for (r = findfiles; r; r=r->next) numfiles++; - return(0); + finddirshigh = finddirs; + findfileshigh = findfiles; + currentlist = 0; + if (findfileshigh) currentlist = 1; + + return(0); } long menuselect(void) { - int listsize; - long i, j, topplc; - char ch, buffer[78], *sb; - static char oldpath[BMAX_PATH]; - CACHE1D_FIND_REC *dir; - - int bakpathsearchmode = pathsearchmode; + int listsize; + long i, j, topplc; + char ch, buffer[78], *sb; + static char oldpath[BMAX_PATH]; + CACHE1D_FIND_REC *dir; - listsize = (ydim16-32)/8; + int bakpathsearchmode = pathsearchmode; - Bstrcpy(selectedboardfilename, oldpath); - if (pathsearchmode) - Bcanonicalisefilename(selectedboardfilename, 1); // clips off the last token and compresses relative path - else - Bcorrectfilename(selectedboardfilename, 1); + listsize = (ydim16-32)/8; - getfilenames(selectedboardfilename, "*.map"); + Bstrcpy(selectedboardfilename, oldpath); + if (pathsearchmode) + Bcanonicalisefilename(selectedboardfilename, 1); // clips off the last token and compresses relative path + else + Bcorrectfilename(selectedboardfilename, 1); - begindrawing(); - printmessage16("Select map file with arrow keys and enter."); - enddrawing(); - - do { - begindrawing(); - clearbuf((char *)frameplace, (bytesperline*ydim16) >> 2, 0l); - - if (pathsearchmode) { - strcpy(buffer,"Local filesystem mode; press F for game filesystem."); - } else { - sprintf(buffer,"Game filesystem %smode; press F for local filesystem or G for %s.", - grponlymode?"GRP-only ":"", grponlymode?"all files":"GRP contents only"); - } - printext16(halfxdim16-(8*strlen(buffer)/2), 4, 12,0,buffer,0); - - Bsnprintf(buffer,78,"(%d dirs, %d files) %s",numdirs,numfiles,selectedboardfilename); - buffer[sizeof(buffer)-1] = 0; - printext16(1,ydim16-8-1,8,0,buffer,0); + getfilenames(selectedboardfilename, "*.map"); - if (finddirshigh) { - dir = finddirshigh; - for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev; - for(i=0; inext) { - int c = dir->type == CACHE1D_FIND_DIR ? 4 : 3; - memset(buffer,0,sizeof(buffer)); - strncpy(buffer,dir->name,25); - if (strlen(buffer) == 25) - buffer[21] = buffer[22] = buffer[23] = '.', buffer[24] = 0; - if (dir == finddirshigh) { - if (currentlist == 0) printext16(8,16+8*i,c|8,0,"->",0); - printext16(32,16+8*i,c|8,0,buffer,0); - } else { - printext16(32,16+8*i,c,0,buffer,0); - } - } - } + begindrawing(); + printmessage16("Select map file with arrow keys and enter."); + enddrawing(); - if (findfileshigh) { - dir = findfileshigh; - for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev; - for(i=0; inext) { - if (dir == findfileshigh) { - if (currentlist == 1) printext16(240,16+8*i,7|8,0,"->",0); - printext16(240+24,16+8*i,7|8,0,dir->name,0); - } else { - printext16(240+24,16+8*i,7,0,dir->name,0); - } - } - } - enddrawing(); - showframe(1); + do { + begindrawing(); + clearbuf((char *)frameplace, (bytesperline*ydim16) >> 2, 0l); - keystatus[0xcb] = 0; - keystatus[0xcd] = 0; - keystatus[0xc8] = 0; - keystatus[0xd0] = 0; - keystatus[0x1c] = 0; //enter - keystatus[0xf] = 0; //tab - keystatus[1] = 0; //esc - ch = 0; //Interesting fakery of ch = getch() - while (ch == 0) - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } - ch = bgetchar(); - { // JBF 20040208: seek to first name matching pressed character - CACHE1D_FIND_REC *seeker = currentlist ? findfiles : finddirs; + if (pathsearchmode) { + strcpy(buffer,"Local filesystem mode; press F for game filesystem."); + } else { + sprintf(buffer,"Game filesystem %smode; press F for local filesystem or G for %s.", + grponlymode?"GRP-only ":"", grponlymode?"all files":"GRP contents only"); + } + printext16(halfxdim16-(8*strlen(buffer)/2), 4, 12,0,buffer,0); + + Bsnprintf(buffer,78,"(%d dirs, %d files) %s",numdirs,numfiles,selectedboardfilename); + buffer[sizeof(buffer)-1] = 0; + printext16(1,ydim16-8-1,8,0,buffer,0); + + if (finddirshigh) { + dir = finddirshigh; + for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev; + for(i=0; inext) { + int c = dir->type == CACHE1D_FIND_DIR ? 4 : 3; + memset(buffer,0,sizeof(buffer)); + strncpy(buffer,dir->name,25); + if (strlen(buffer) == 25) + buffer[21] = buffer[22] = buffer[23] = '.', buffer[24] = 0; + if (dir == finddirshigh) { + if (currentlist == 0) printext16(8,16+8*i,c|8,0,"->",0); + printext16(32,16+8*i,c|8,0,buffer,0); + } else { + printext16(32,16+8*i,c,0,buffer,0); + } + } + } + + if (findfileshigh) { + dir = findfileshigh; + for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev; + for(i=0; inext) { + if (dir == findfileshigh) { + if (currentlist == 1) printext16(240,16+8*i,7|8,0,"->",0); + printext16(240+24,16+8*i,7|8,0,dir->name,0); + } else { + printext16(240+24,16+8*i,7,0,dir->name,0); + } + } + } + enddrawing(); + showframe(1); + + keystatus[0xcb] = 0; + keystatus[0xcd] = 0; + keystatus[0xc8] = 0; + keystatus[0xd0] = 0; + keystatus[0x1c] = 0; //enter + keystatus[0xf] = 0; //tab + keystatus[1] = 0; //esc + ch = 0; //Interesting fakery of ch = getch() + while (ch == 0) + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } + ch = bgetchar(); + { // JBF 20040208: seek to first name matching pressed character + CACHE1D_FIND_REC *seeker = currentlist ? findfiles : finddirs; if((keystatus[0xc7]|keystatus[0xcf]) > 0) // home/end { while(keystatus[0xcf]?seeker->next:seeker->prev) @@ -6561,200 +6561,200 @@ long menuselect(void) } } } - } - if (keystatus[0xcb] > 0) ch = 9; // left arr - if (keystatus[0xcd] > 0) ch = 9; // right arr - if (keystatus[0xc8] > 0) ch = 72; // up arr - if (keystatus[0xd0] > 0) ch = 80; // down arr - } - if (ch == 'f' || ch == 'F') { - currentlist = 0; - pathsearchmode = 1-pathsearchmode; - if (pathsearchmode) { - strcpy(selectedboardfilename, ""); - Bcanonicalisefilename(selectedboardfilename, 0); - } else strcpy(selectedboardfilename, "/"); - getfilenames(selectedboardfilename, "*.map"); - Bstrcpy(oldpath,selectedboardfilename); - } else if (ch == 'g' || ch == 'G') { - if (!pathsearchmode) { - grponlymode = 1-grponlymode; - getfilenames(selectedboardfilename, "*.map"); - Bstrcpy(oldpath,selectedboardfilename); - } - } else if (ch == 9) { - if ((currentlist == 0 && findfiles) || (currentlist == 1 && finddirs)) - currentlist = 1-currentlist; - } else if ((ch == 75) || (ch == 72)) { - if (currentlist == 0) { - if (finddirshigh && finddirshigh->prev) finddirshigh = finddirshigh->prev; - } else { - if (findfileshigh && findfileshigh->prev) findfileshigh = findfileshigh->prev; - } - } else if ((ch == 77) || (ch == 80)) { - if (currentlist == 0) { - if (finddirshigh && finddirshigh->next) finddirshigh = finddirshigh->next; - } else { - if (findfileshigh && findfileshigh->next) findfileshigh = findfileshigh->next; - } - } else if ((ch == 13) && (currentlist == 0)) { - if (finddirshigh->type == CACHE1D_FIND_DRIVE) { - strcpy(selectedboardfilename, finddirshigh->name); - } else { - strcat(selectedboardfilename, finddirshigh->name); - } - strcat(selectedboardfilename, "/"); - if (pathsearchmode) - Bcanonicalisefilename(selectedboardfilename, 1); - else - Bcorrectfilename(selectedboardfilename, 1); + } + if (keystatus[0xcb] > 0) ch = 9; // left arr + if (keystatus[0xcd] > 0) ch = 9; // right arr + if (keystatus[0xc8] > 0) ch = 72; // up arr + if (keystatus[0xd0] > 0) ch = 80; // down arr + } + if (ch == 'f' || ch == 'F') { + currentlist = 0; + pathsearchmode = 1-pathsearchmode; + if (pathsearchmode) { + strcpy(selectedboardfilename, ""); + Bcanonicalisefilename(selectedboardfilename, 0); + } else strcpy(selectedboardfilename, "/"); + getfilenames(selectedboardfilename, "*.map"); + Bstrcpy(oldpath,selectedboardfilename); + } else if (ch == 'g' || ch == 'G') { + if (!pathsearchmode) { + grponlymode = 1-grponlymode; + getfilenames(selectedboardfilename, "*.map"); + Bstrcpy(oldpath,selectedboardfilename); + } + } else if (ch == 9) { + if ((currentlist == 0 && findfiles) || (currentlist == 1 && finddirs)) + currentlist = 1-currentlist; + } else if ((ch == 75) || (ch == 72)) { + if (currentlist == 0) { + if (finddirshigh && finddirshigh->prev) finddirshigh = finddirshigh->prev; + } else { + if (findfileshigh && findfileshigh->prev) findfileshigh = findfileshigh->prev; + } + } else if ((ch == 77) || (ch == 80)) { + if (currentlist == 0) { + if (finddirshigh && finddirshigh->next) finddirshigh = finddirshigh->next; + } else { + if (findfileshigh && findfileshigh->next) findfileshigh = findfileshigh->next; + } + } else if ((ch == 13) && (currentlist == 0)) { + if (finddirshigh->type == CACHE1D_FIND_DRIVE) { + strcpy(selectedboardfilename, finddirshigh->name); + } else { + strcat(selectedboardfilename, finddirshigh->name); + } + strcat(selectedboardfilename, "/"); + if (pathsearchmode) + Bcanonicalisefilename(selectedboardfilename, 1); + else + Bcorrectfilename(selectedboardfilename, 1); - Bstrcpy(oldpath,selectedboardfilename); - //printf("Changing directories to: %s\n", selectedboardfilename); + Bstrcpy(oldpath,selectedboardfilename); + //printf("Changing directories to: %s\n", selectedboardfilename); - getfilenames(selectedboardfilename, "*.map"); - ch = 0; + getfilenames(selectedboardfilename, "*.map"); + ch = 0; - begindrawing(); - clearbuf((char *)frameplace, (bytesperline*ydim16) >> 2, 0l); - enddrawing(); - showframe(1); - } - if (ch == 13 && !findfileshigh) ch = 0; - } - while ((ch != 13) && (ch != 27)); - if (ch == 13) - { - Bstrcat(selectedboardfilename, findfileshigh->name); - //printf("Selected file: %s\n", selectedboardfilename); + begindrawing(); + clearbuf((char *)frameplace, (bytesperline*ydim16) >> 2, 0l); + enddrawing(); + showframe(1); + } + if (ch == 13 && !findfileshigh) ch = 0; + } + while ((ch != 13) && (ch != 27)); + if (ch == 13) + { + Bstrcat(selectedboardfilename, findfileshigh->name); + //printf("Selected file: %s\n", selectedboardfilename); - return(0); - } - pathsearchmode = bakpathsearchmode; - return(-1); + return(0); + } + pathsearchmode = bakpathsearchmode; + return(-1); } long fillsector(short sectnum, char fillcolor) { - long x1, x2, y1, y2, sy, y, templong; - long lborder, rborder, uborder, dborder, miny, maxy, dax; - short z, zz, startwall, endwall, fillcnt; + long x1, x2, y1, y2, sy, y, templong; + long lborder, rborder, uborder, dborder, miny, maxy, dax; + short z, zz, startwall, endwall, fillcnt; - lborder = 0; rborder = xdim; - uborder = 0; dborder = ydim16; + lborder = 0; rborder = xdim; + uborder = 0; dborder = ydim16; - if (sectnum == -1) - return(0); - miny = dborder-1; - maxy = uborder; - startwall = sector[sectnum].wallptr; - endwall = startwall + sector[sectnum].wallnum - 1; - for(z=startwall;z<=endwall;z++) - { - y1 = (((wall[z].y-posy)*zoom)>>14)+midydim16; - y2 = (((wall[wall[z].point2].y-posy)*zoom)>>14)+midydim16; - if (y1 < miny) miny = y1; - if (y2 < miny) miny = y2; - if (y1 > maxy) maxy = y1; - if (y2 > maxy) maxy = y2; - } - if (miny < uborder) miny = uborder; - if (maxy >= dborder) maxy = dborder-1; + if (sectnum == -1) + return(0); + miny = dborder-1; + maxy = uborder; + startwall = sector[sectnum].wallptr; + endwall = startwall + sector[sectnum].wallnum - 1; + for(z=startwall;z<=endwall;z++) + { + y1 = (((wall[z].y-posy)*zoom)>>14)+midydim16; + y2 = (((wall[wall[z].point2].y-posy)*zoom)>>14)+midydim16; + if (y1 < miny) miny = y1; + if (y2 < miny) miny = y2; + if (y1 > maxy) maxy = y1; + if (y2 > maxy) maxy = y2; + } + if (miny < uborder) miny = uborder; + if (maxy >= dborder) maxy = dborder-1; - for(sy=miny+((totalclock>>2)&3);sy<=maxy;sy+=3) // JBF 20040116: numframes%3 -> (totalclock>>2)&3 - { - y = posy+(((sy-midydim16)<<14)/zoom); + for(sy=miny+((totalclock>>2)&3);sy<=maxy;sy+=3) // JBF 20040116: numframes%3 -> (totalclock>>2)&3 + { + y = posy+(((sy-midydim16)<<14)/zoom); - fillist[0] = lborder; fillcnt = 1; - for(z=startwall;z<=endwall;z++) - { - x1 = wall[z].x; x2 = wall[wall[z].point2].x; - y1 = wall[z].y; y2 = wall[wall[z].point2].y; - if (y1 > y2) - { - templong = x1; x1 = x2; x2 = templong; - templong = y1; y1 = y2; y2 = templong; - } - if ((y1 <= y) && (y2 > y)) - //if (x1*(y-y2) + x2*(y1-y) <= 0) - { - dax = x1+scale(y-y1,x2-x1,y2-y1); - dax = (((dax-posx)*zoom)>>14)+halfxdim16; - if (dax >= lborder) - fillist[fillcnt++] = dax; - } - } - if (fillcnt > 0) - { - for(z=1;z y2) + { + templong = x1; x1 = x2; x2 = templong; + templong = y1; y1 = y2; y2 = templong; + } + if ((y1 <= y) && (y2 > y)) + //if (x1*(y-y2) + x2*(y1-y) <= 0) + { + dax = x1+scale(y-y1,x2-x1,y2-y1); + dax = (((dax-posx)*zoom)>>14)+halfxdim16; + if (dax >= lborder) + fillist[fillcnt++] = dax; + } + } + if (fillcnt > 0) + { + for(z=1;z rborder) break; - if (fillist[z+1] > rborder) - fillist[z+1] = rborder; - drawline16(fillist[z],sy,fillist[z+1],sy,fillcolor); - } - } - } - return(0); + for (z=(fillcnt&1);z rborder) break; + if (fillist[z+1] > rborder) + fillist[z+1] = rborder; + drawline16(fillist[z],sy,fillist[z+1],sy,fillcolor); + } + } + } + return(0); } short whitelinescan(short dalinehighlight) { - long i, j, k; - short sucksect, newnumwalls; + long i, j, k; + short sucksect, newnumwalls; - sucksect = sectorofwall(dalinehighlight); + sucksect = sectorofwall(dalinehighlight); - Bmemcpy(§or[numsectors],§or[sucksect],sizeof(sectortype)); - sector[numsectors].wallptr = numwalls; - sector[numsectors].wallnum = 0; - i = dalinehighlight; - newnumwalls = numwalls; - do - { - j = lastwall((short)i); - if (wall[j].nextwall >= 0) - { - j = wall[j].point2; - for(k=0;k= 0) + { + j = wall[j].point2; + for(k=0;k= 1) { - if (a > 1) - if (buffer[a-2] == '\r') buffer[a-2] = 0; - if (buffer[a-1] == '\n') buffer[a-1] = 0; - } - - p = buffer; - line++; - while (*p == 32) p++; - if (*p == 0) continue; // blank line + while (Bfgets(buffer, 1024, fp)) { + a = Bstrlen(buffer); + if (a >= 1) { + if (a > 1) + if (buffer[a-2] == '\r') buffer[a-2] = 0; + if (buffer[a-1] == '\n') buffer[a-1] = 0; + } - if (*p == '#') { - p++; - while (*p == 32) p++; - if (*p == 0) continue; // null directive + p = buffer; + line++; + while (*p == 32) p++; + if (*p == 0) continue; // blank line - if (!Bstrncmp(p, "define ", 7)) { - // #define_... - p += 7; - while (*p == 32) p++; - if (*p == 0) { - printf("Error: Malformed #define at line %d\n", line-1); - continue; - } + if (*p == '#') { + p++; + while (*p == 32) p++; + if (*p == 0) continue; // null directive - name = p; - while (*p != 32 && *p != 0) p++; - if (*p == 32) { - *(p++) = 0; - while (*p == 32) p++; - if (*p == 0) { // #define_NAME with no number - printf("Error: No number given for name \"%s\" (line %d)\n", name, line-1); - continue; - } + if (!Bstrncmp(p, "define ", 7)) { + // #define_... + p += 7; + while (*p == 32) p++; + if (*p == 0) { + printf("Error: Malformed #define at line %d\n", line-1); + continue; + } - number = p; - while (*p != 0) p++; - if (*p != 0) *p = 0; + name = p; + while (*p != 32 && *p != 0) p++; + if (*p == 32) { + *(p++) = 0; + while (*p == 32) p++; + if (*p == 0) { // #define_NAME with no number + printf("Error: No number given for name \"%s\" (line %d)\n", name, line-1); + continue; + } - // add to list - num = Bstrtol(number, &endptr, 10); - if (*endptr != 0) { - p = endptr; - goto badline; - } - //printf("Grokked \"%s\" -> \"%d\"\n", name, num); - if (num < 0 || num >= MAXTILES) { - printf("Error: Constant %d for name \"%s\" out of range (line %d)\n", num, name, line-1); - continue; - } + number = p; + while (*p != 0) p++; + if (*p != 0) *p = 0; - if (Bstrlen(name) > 24) - printf("Warning: Name \"%s\" longer than 24 characters (line %d). Truncating.\n", name, line-1); + // add to list + num = Bstrtol(number, &endptr, 10); + if (*endptr != 0) { + p = endptr; + goto badline; + } + //printf("Grokked \"%s\" -> \"%d\"\n", name, num); + if (num < 0 || num >= MAXTILES) { + printf("Error: Constant %d for name \"%s\" out of range (line %d)\n", num, name, line-1); + continue; + } - Bstrncpy(names[num], name, 24); - names[num][24] = 0; + if (Bstrlen(name) > 24) + printf("Warning: Name \"%s\" longer than 24 characters (line %d). Truncating.\n", name, line-1); - syms++; + Bstrncpy(names[num], name, 24); + names[num][24] = 0; - continue; + syms++; - } else { // #define_NAME with no number - printf("Error: No number given for name \"%s\" (line %d)\n", name, line-1); - continue; - } - } else goto badline; - } else if (*p == '/') { - if (*(p+1) == '/') continue; // comment - } + continue; + + } else { // #define_NAME with no number + printf("Error: No number given for name \"%s\" (line %d)\n", name, line-1); + continue; + } + } else goto badline; + } else if (*p == '/') { + if (*(p+1) == '/') continue; // comment + } badline: - printf("Error: Invalid statement found at character %d on line %d\n", (p-buffer), line-1); - } - printf("Read %d lines, loaded %d names.\n", line, syms); + printf("Error: Invalid statement found at character %d on line %d\n", (p-buffer), line-1); + } + printf("Read %d lines, loaded %d names.\n", line, syms); - Bfclose(fp); - return 0; + Bfclose(fp); + return 0; } void printcoords16(long posxe, long posye, short ange) { - char snotbuf[80]; - long i,m; + char snotbuf[80]; + long i,m; - Bsprintf(snotbuf,"x=%ld y=%ld ang=%d",posxe,posye,ange); - i = 0; - while ((snotbuf[i] != 0) && (i < 30)) - i++; - while (i < 30) - { - snotbuf[i] = 32; - i++; - } - snotbuf[30] = 0; + Bsprintf(snotbuf,"x=%ld y=%ld ang=%d",posxe,posye,ange); + i = 0; + while ((snotbuf[i] != 0) && (i < 30)) + i++; + while (i < 30) + { + snotbuf[i] = 32; + i++; + } + snotbuf[30] = 0; - m = (numsectors > MAXSECTORSV7 || numwalls > MAXWALLSV7 || numsprites > MAXSPRITESV7); + m = (numsectors > MAXSECTORSV7 || numwalls > MAXWALLSV7 || numsprites > MAXSPRITESV7); printext16(8, ydim-STATUS2DSIZ+128+2, 9, 0, snotbuf,0); - Bsprintf(snotbuf,"%d/%d sect. %d/%d walls %ld/%d spri.", - numsectors,m?MAXSECTORSV8:MAXSECTORSV7, - numwalls,m?MAXWALLSV8:MAXWALLSV7, - numsprites,m?MAXSPRITESV8:MAXSPRITESV7); - i = 0; - while ((snotbuf[i] != 0) && (i < 46)) - i++; - while (i < 46) - { - snotbuf[i] = 32; - i++; - } - snotbuf[46] = 0; + Bsprintf(snotbuf,"%d/%d sect. %d/%d walls %ld/%d spri.", + numsectors,m?MAXSECTORSV8:MAXSECTORSV7, + numwalls,m?MAXWALLSV8:MAXWALLSV7, + numsprites,m?MAXSPRITESV8:MAXSPRITESV7); + i = 0; + while ((snotbuf[i] != 0) && (i < 46)) + i++; + while (i < 46) + { + snotbuf[i] = 32; + i++; + } + snotbuf[46] = 0; printext16(264, ydim-STATUS2DSIZ+128+2, 9+m, 0, snotbuf,0); } void updatenumsprites(void) { - long i; + long i; - numsprites = 0; - for(i=0;i= 0) - { - wall[newnumwalls].nextwall += deststartwall-startwall; - wall[newnumwalls].nextsector += destsector-soursector; - } - newnumwalls++; - } + //duplicate walls + startwall = sector[soursector].wallptr; + endwall = startwall + sector[soursector].wallnum; + for(j=startwall;j= 0) + { + wall[newnumwalls].nextwall += deststartwall-startwall; + wall[newnumwalls].nextsector += destsector-soursector; + } + newnumwalls++; + } - //for(j=deststartwall;j= 0) - // checksectorpointer(wall[j].nextwall,wall[j].nextsector); - // checksectorpointer((short)j,destsector); - //} + //for(j=deststartwall;j= 0) + // checksectorpointer(wall[j].nextwall,wall[j].nextsector); + // checksectorpointer((short)j,destsector); + //} - if (newnumwalls > deststartwall) - { - //duplicate sectors - Bmemcpy(§or[destsector],§or[soursector],sizeof(sectortype)); - sector[destsector].wallptr = deststartwall; - sector[destsector].wallnum = newnumwalls-deststartwall; + if (newnumwalls > deststartwall) + { + //duplicate sectors + Bmemcpy(§or[destsector],§or[soursector],sizeof(sectortype)); + sector[destsector].wallptr = deststartwall; + sector[destsector].wallnum = newnumwalls-deststartwall; - if (copystat == 1) - { - //duplicate sprites - j = headspritesect[soursector]; - while (j >= 0) - { - k = nextspritesect[j]; + if (copystat == 1) + { + //duplicate sprites + j = headspritesect[soursector]; + while (j >= 0) + { + k = nextspritesect[j]; - m = insertsprite(destsector,sprite[j].statnum); - Bmemcpy(&sprite[m],&sprite[j],sizeof(spritetype)); - sprite[m].sectnum = destsector; //Don't let memcpy overwrite sector! + m = insertsprite(destsector,sprite[j].statnum); + Bmemcpy(&sprite[m],&sprite[j],sizeof(spritetype)); + sprite[m].sectnum = destsector; //Don't let memcpy overwrite sector! - j = k; - } - } + j = k; + } + } - } + } } void showsectordata(short sectnum) { - char snotbuf[80]; + char snotbuf[80]; - Bsprintf(snotbuf,"Sector %d",sectnum); - printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Firstwall: %d",sector[sectnum].wallptr); - printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Numberofwalls: %d",sector[sectnum].wallnum); - printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Firstsprite: %d",headspritesect[sectnum]); - printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tags: %d, %d",sector[sectnum].hitag,sector[sectnum].lotag); - printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf," (0x%x), (0x%x)",sector[sectnum].hitag,sector[sectnum].lotag); - printext16(8,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Extra: %d",sector[sectnum].extra); - printext16(8,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Visibility: %d",sector[sectnum].visibility); - printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Pixel height: %ld",(sector[sectnum].floorz-sector[sectnum].ceilingz)>>8); - printext16(8,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Sector %d",sectnum); + printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Firstwall: %d",sector[sectnum].wallptr); + printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Numberofwalls: %d",sector[sectnum].wallnum); + printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Firstsprite: %d",headspritesect[sectnum]); + printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tags: %d, %d",sector[sectnum].hitag,sector[sectnum].lotag); + printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf," (0x%x), (0x%x)",sector[sectnum].hitag,sector[sectnum].lotag); + printext16(8,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Extra: %d",sector[sectnum].extra); + printext16(8,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Visibility: %d",sector[sectnum].visibility); + printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Pixel height: %ld",(sector[sectnum].floorz-sector[sectnum].ceilingz)>>8); + printext16(8,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); - printext16(200,ydim-STATUS2DSIZ+32,11,-1,"CEILINGS:",0); - Bsprintf(snotbuf,"Flags (hex): %x",sector[sectnum].ceilingstat); - printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)pan: %d, %d",sector[sectnum].ceilingxpanning,sector[sectnum].ceilingypanning); - printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Shade byte: %d",sector[sectnum].ceilingshade); - printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Z-coordinate: %ld",sector[sectnum].ceilingz); - printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tile number: %d",sector[sectnum].ceilingpicnum); - printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Ceiling heinum: %d",sector[sectnum].ceilingheinum); - printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Palookup number: %d",sector[sectnum].ceilingpal); - printext16(200,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + printext16(200,ydim-STATUS2DSIZ+32,11,-1,"CEILINGS:",0); + Bsprintf(snotbuf,"Flags (hex): %x",sector[sectnum].ceilingstat); + printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)pan: %d, %d",sector[sectnum].ceilingxpanning,sector[sectnum].ceilingypanning); + printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Shade byte: %d",sector[sectnum].ceilingshade); + printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Z-coordinate: %ld",sector[sectnum].ceilingz); + printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tile number: %d",sector[sectnum].ceilingpicnum); + printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Ceiling heinum: %d",sector[sectnum].ceilingheinum); + printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Palookup number: %d",sector[sectnum].ceilingpal); + printext16(200,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - printext16(400,ydim-STATUS2DSIZ+32,11,-1,"FLOORS:",0); - Bsprintf(snotbuf,"Flags (hex): %x",sector[sectnum].floorstat); - printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)pan: %d, %d",sector[sectnum].floorxpanning,sector[sectnum].floorypanning); - printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Shade byte: %d",sector[sectnum].floorshade); - printext16(400,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Z-coordinate: %ld",sector[sectnum].floorz); - printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tile number: %d",sector[sectnum].floorpicnum); - printext16(400,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Floor heinum: %d",sector[sectnum].floorheinum); - printext16(400,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Palookup number: %d",sector[sectnum].floorpal); - printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + printext16(400,ydim-STATUS2DSIZ+32,11,-1,"FLOORS:",0); + Bsprintf(snotbuf,"Flags (hex): %x",sector[sectnum].floorstat); + printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)pan: %d, %d",sector[sectnum].floorxpanning,sector[sectnum].floorypanning); + printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Shade byte: %d",sector[sectnum].floorshade); + printext16(400,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Z-coordinate: %ld",sector[sectnum].floorz); + printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tile number: %d",sector[sectnum].floorpicnum); + printext16(400,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Floor heinum: %d",sector[sectnum].floorheinum); + printext16(400,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Palookup number: %d",sector[sectnum].floorpal); + printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); } void showwalldata(short wallnum) { - long dax, day, dist; - char snotbuf[80]; + long dax, day, dist; + char snotbuf[80]; - Bsprintf(snotbuf,"Wall %d",wallnum); - printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); - Bsprintf(snotbuf,"X-coordinate: %ld",wall[wallnum].x); - printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Y-coordinate: %ld",wall[wallnum].y); - printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Point2: %d",wall[wallnum].point2); - printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Sector: %ld",sectorofwall(wallnum)); - printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Wall %d",wallnum); + printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); + Bsprintf(snotbuf,"X-coordinate: %ld",wall[wallnum].x); + printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Y-coordinate: %ld",wall[wallnum].y); + printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Point2: %d",wall[wallnum].point2); + printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Sector: %ld",sectorofwall(wallnum)); + printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tags: %d, %d",wall[wallnum].hitag,wall[wallnum].lotag); - printext16(8,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf," (0x%x), (0x%x)",wall[wallnum].hitag,wall[wallnum].lotag); - printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tags: %d, %d",wall[wallnum].hitag,wall[wallnum].lotag); + printext16(8,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf," (0x%x), (0x%x)",wall[wallnum].hitag,wall[wallnum].lotag); + printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - printext16(200,ydim-STATUS2DSIZ+32,11,-1,names[wall[wallnum].picnum],0); - Bsprintf(snotbuf,"Flags (hex): %x",wall[wallnum].cstat); - printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Shade: %d",wall[wallnum].shade); - printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Pal: %d",wall[wallnum].pal); - printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)repeat: %d, %d",wall[wallnum].xrepeat,wall[wallnum].yrepeat); - printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)pan: %d, %d",wall[wallnum].xpanning,wall[wallnum].ypanning); - printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tile number: %d",wall[wallnum].picnum); - printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"OverTile number: %d",wall[wallnum].overpicnum); - printext16(200,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + printext16(200,ydim-STATUS2DSIZ+32,11,-1,names[wall[wallnum].picnum],0); + Bsprintf(snotbuf,"Flags (hex): %x",wall[wallnum].cstat); + printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Shade: %d",wall[wallnum].shade); + printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Pal: %d",wall[wallnum].pal); + printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)repeat: %d, %d",wall[wallnum].xrepeat,wall[wallnum].yrepeat); + printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)pan: %d, %d",wall[wallnum].xpanning,wall[wallnum].ypanning); + printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tile number: %d",wall[wallnum].picnum); + printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf,"OverTile number: %d",wall[wallnum].overpicnum); + printext16(200,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - Bsprintf(snotbuf,"nextsector: %d",wall[wallnum].nextsector); - printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"nextwall: %d",wall[wallnum].nextwall); - printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"nextsector: %d",wall[wallnum].nextsector); + printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"nextwall: %d",wall[wallnum].nextwall); + printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Extra: %d",wall[wallnum].extra); - printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Extra: %d",wall[wallnum].extra); + printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - dax = wall[wallnum].x-wall[wall[wallnum].point2].x; - day = wall[wallnum].y-wall[wall[wallnum].point2].y; - dist = ksqrt(dax*dax+day*day); + dax = wall[wallnum].x-wall[wall[wallnum].point2].x; + day = wall[wallnum].y-wall[wall[wallnum].point2].y; + dist = ksqrt(dax*dax+day*day); -// TX 20050102 I'm not sure what unit dist<<4 is supposed to be, but dist itself is correct in terms of game coordinates as one would expect + // TX 20050102 I'm not sure what unit dist<<4 is supposed to be, but dist itself is correct in terms of game coordinates as one would expect - Bsprintf(snotbuf,"Wall length: %ld",dist); - printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Wall length: %ld",dist); + printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - dax = (long)sectorofwall(wallnum); - Bsprintf(snotbuf,"Pixel height: %ld",(sector[dax].floorz-sector[dax].ceilingz)>>8); - printext16(400,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); + dax = (long)sectorofwall(wallnum); + Bsprintf(snotbuf,"Pixel height: %ld",(sector[dax].floorz-sector[dax].ceilingz)>>8); + printext16(400,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); } void showspritedata(short spritenum) { - char snotbuf[80]; + char snotbuf[80]; - Bsprintf(snotbuf,"Sprite %d",spritenum); - printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); - Bsprintf(snotbuf,"X-coordinate: %ld",sprite[spritenum].x); - printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Y-coordinate: %ld",sprite[spritenum].y); - printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Z-coordinate: %ld",sprite[spritenum].z); - printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Sprite %d",spritenum); + printext16(8,ydim-STATUS2DSIZ+32,11,-1,snotbuf,0); + Bsprintf(snotbuf,"X-coordinate: %ld",sprite[spritenum].x); + printext16(8,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Y-coordinate: %ld",sprite[spritenum].y); + printext16(8,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Z-coordinate: %ld",sprite[spritenum].z); + printext16(8,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Sectnum: %d",sprite[spritenum].sectnum); - printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Statnum: %d",sprite[spritenum].statnum); - printext16(8,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Sectnum: %d",sprite[spritenum].sectnum); + printext16(8,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Statnum: %d",sprite[spritenum].statnum); + printext16(8,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tags: %d, %d",sprite[spritenum].hitag,sprite[spritenum].lotag); - printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); - Bsprintf(snotbuf," (0x%x), (0x%x)",sprite[spritenum].hitag,sprite[spritenum].lotag); - printext16(8,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tags: %d, %d",sprite[spritenum].hitag,sprite[spritenum].lotag); + printext16(8,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + Bsprintf(snotbuf," (0x%x), (0x%x)",sprite[spritenum].hitag,sprite[spritenum].lotag); + printext16(8,ydim-STATUS2DSIZ+104,11,-1,snotbuf,0); - printext16(200,ydim-STATUS2DSIZ+32,11,-1,names[sprite[spritenum].picnum],0); - Bsprintf(snotbuf,"Flags (hex): %x",sprite[spritenum].cstat); - printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Shade: %d",sprite[spritenum].shade); - printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Pal: %d",sprite[spritenum].pal); - printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)repeat: %d, %d",sprite[spritenum].xrepeat,sprite[spritenum].yrepeat); - printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"(X,Y)offset: %d, %d",sprite[spritenum].xoffset,sprite[spritenum].yoffset); - printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Tile number: %d",sprite[spritenum].picnum); - printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + printext16(200,ydim-STATUS2DSIZ+32,11,-1,names[sprite[spritenum].picnum],0); + Bsprintf(snotbuf,"Flags (hex): %x",sprite[spritenum].cstat); + printext16(200,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Shade: %d",sprite[spritenum].shade); + printext16(200,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Pal: %d",sprite[spritenum].pal); + printext16(200,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)repeat: %d, %d",sprite[spritenum].xrepeat,sprite[spritenum].yrepeat); + printext16(200,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"(X,Y)offset: %d, %d",sprite[spritenum].xoffset,sprite[spritenum].yoffset); + printext16(200,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Tile number: %d",sprite[spritenum].picnum); + printext16(200,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Angle (2048 degrees): %d",sprite[spritenum].ang); - printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); - Bsprintf(snotbuf,"X-Velocity: %d",sprite[spritenum].xvel); - printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Y-Velocity: %d",sprite[spritenum].yvel); - printext16(400,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Z-Velocity: %d",sprite[spritenum].zvel); - printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Owner: %d",sprite[spritenum].owner); - printext16(400,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Clipdist: %d",sprite[spritenum].clipdist); - printext16(400,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); - Bsprintf(snotbuf,"Extra: %d",sprite[spritenum].extra); - printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Angle (2048 degrees): %d",sprite[spritenum].ang); + printext16(400,ydim-STATUS2DSIZ+48,11,-1,snotbuf,0); + Bsprintf(snotbuf,"X-Velocity: %d",sprite[spritenum].xvel); + printext16(400,ydim-STATUS2DSIZ+56,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Y-Velocity: %d",sprite[spritenum].yvel); + printext16(400,ydim-STATUS2DSIZ+64,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Z-Velocity: %d",sprite[spritenum].zvel); + printext16(400,ydim-STATUS2DSIZ+72,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Owner: %d",sprite[spritenum].owner); + printext16(400,ydim-STATUS2DSIZ+80,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Clipdist: %d",sprite[spritenum].clipdist); + printext16(400,ydim-STATUS2DSIZ+88,11,-1,snotbuf,0); + Bsprintf(snotbuf,"Extra: %d",sprite[spritenum].extra); + printext16(400,ydim-STATUS2DSIZ+96,11,-1,snotbuf,0); } void keytimerstuff(void) { - static long ltotalclock=0; + static long ltotalclock=0; int i; - if (totalclock == ltotalclock) return; - ltotalclock=totalclock; - - if (keystatus[buildkeys[5]] == 0) - { - if (keystatus[buildkeys[2]] > 0) angvel = max(angvel-16,-128); - if (keystatus[buildkeys[3]] > 0) angvel = min(angvel+16,127); - } - else - { - if (keystatus[buildkeys[2]] > 0) svel = min(svel+8,127); - if (keystatus[buildkeys[3]] > 0) svel = max(svel-8,-128); - } - if (keystatus[buildkeys[0]] > 0) vel = min(vel+8,127); - if (keystatus[buildkeys[1]] > 0) vel = max(vel-8,-128); -/* if (keystatus[buildkeys[12]] > 0) svel = min(svel+8,127); - if (keystatus[buildkeys[13]] > 0) svel = max(svel-8,-128); */ + if (totalclock == ltotalclock) return; + ltotalclock=totalclock; - if (angvel < 0) angvel = min(angvel+12,0); - if (angvel > 0) angvel = max(angvel-12,0); - if (svel < 0) svel = min(svel+2,0); - if (svel > 0) svel = max(svel-2,0); - if (vel < 0) vel = min(vel+2,0); - if (vel > 0) vel = max(vel-2,0); + if (keystatus[buildkeys[5]] == 0) + { + if (keystatus[buildkeys[2]] > 0) angvel = max(angvel-16,-128); + if (keystatus[buildkeys[3]] > 0) angvel = min(angvel+16,127); + } + else + { + if (keystatus[buildkeys[2]] > 0) svel = min(svel+8,127); + if (keystatus[buildkeys[3]] > 0) svel = max(svel-8,-128); + } + if (keystatus[buildkeys[0]] > 0) vel = min(vel+8,127); + if (keystatus[buildkeys[1]] > 0) vel = max(vel-8,-128); + /* if (keystatus[buildkeys[12]] > 0) svel = min(svel+8,127); + if (keystatus[buildkeys[13]] > 0) svel = max(svel-8,-128); */ + + if (angvel < 0) angvel = min(angvel+12,0); + if (angvel > 0) angvel = max(angvel-12,0); + if (svel < 0) svel = min(svel+2,0); + if (svel > 0) svel = max(svel-2,0); + if (vel < 0) vel = min(vel+2,0); + if (vel > 0) vel = max(vel-2,0); if(mlook) posz -= (horiz-101)*(vel/40); } void _printmessage16(char name[82]) { - char snotbuf[60]; - long i; + char snotbuf[60]; + long i; - i = 0; - while ((name[i] != 0) && (i < 54)) - { - snotbuf[i] = name[i]; - i++; - } - while (i < 54) - { - snotbuf[i] = 32; - i++; - } - snotbuf[54] = 0; - begindrawing(); + i = 0; + while ((name[i] != 0) && (i < 54)) + { + snotbuf[i] = name[i]; + i++; + } + while (i < 54) + { + snotbuf[i] = 32; + i++; + } + snotbuf[54] = 0; + begindrawing(); printext16(200L, ydim-STATUS2DSIZ+8L, 9, 0, snotbuf, 0); - enddrawing(); + enddrawing(); } void printmessage16(char name[82]) @@ -7240,179 +7240,179 @@ void printmessage16(char name[82]) void printmessage256(char name[82]) { - char snotbuf[40]; - long i; + char snotbuf[40]; + long i; - i = 0; - while ((name[i] != 0) && (i < 38)) - { - snotbuf[i] = name[i]; - i++; - } - while (i < 38) - { - snotbuf[i] = 32; - i++; - } - snotbuf[38] = 0; + i = 0; + while ((name[i] != 0) && (i < 38)) + { + snotbuf[i] = name[i]; + i++; + } + while (i < 38) + { + snotbuf[i] = 32; + i++; + } + snotbuf[38] = 0; printext256(2L,2L,0,-1,snotbuf,0); printext256(0L,0L,whitecol,-1,snotbuf,0); } - //Find closest point (*dax, *day) on wall (dawall) to (x, y) +//Find closest point (*dax, *day) on wall (dawall) to (x, y) void getclosestpointonwall(long x, long y, long dawall, long *nx, long *ny) { - walltype *wal; - long i, j, dx, dy; + walltype *wal; + long i, j, dx, dy; - wal = &wall[dawall]; - dx = wall[wal->point2].x-wal->x; - dy = wall[wal->point2].y-wal->y; - i = dx*(x-wal->x) + dy*(y-wal->y); - if (i <= 0) { *nx = wal->x; *ny = wal->y; return; } - j = dx*dx+dy*dy; - if (i >= j) { *nx = wal->x+dx; *ny = wal->y+dy; return; } - i = divscale30(i,j); - *nx = wal->x + mulscale30(dx,i); - *ny = wal->y + mulscale30(dy,i); + wal = &wall[dawall]; + dx = wall[wal->point2].x-wal->x; + dy = wall[wal->point2].y-wal->y; + i = dx*(x-wal->x) + dy*(y-wal->y); + if (i <= 0) { *nx = wal->x; *ny = wal->y; return; } + j = dx*dx+dy*dy; + if (i >= j) { *nx = wal->x+dx; *ny = wal->y+dy; return; } + i = divscale30(i,j); + *nx = wal->x + mulscale30(dx,i); + *ny = wal->y + mulscale30(dy,i); } void initcrc(void) { - long i, j, k, a; + long i, j, k, a; - for(j=0;j<256;j++) //Calculate CRC table - { - k = (j<<8); a = 0; - for(i=7;i>=0;i--) - { - if (((k^a)&0x8000) > 0) - a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly - else - a = ((a<<1)&65535); - k = ((k<<1)&65535); - } - crctable[j] = (a&65535); - } + for(j=0;j<256;j++) //Calculate CRC table + { + k = (j<<8); a = 0; + for(i=7;i>=0;i--) + { + if (((k^a)&0x8000) > 0) + a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly + else + a = ((a<<1)&65535); + k = ((k<<1)&65535); + } + crctable[j] = (a&65535); + } } static char visited[MAXWALLS]; long GetWallZPeg(long nWall) { - long z=0, nSector, nNextSector; + long z=0, nSector, nNextSector; - nSector = sectorofwall((short)nWall); - nNextSector = wall[nWall].nextsector; - if (nNextSector == -1) - { - //1-sided wall - if (wall[nWall].cstat&4) z = sector[nSector].floorz; - else z = sector[nSector].ceilingz; - } - else - { - //2-sided wall - if (wall[nWall].cstat&4) - z = sector[nSector].ceilingz; - else - { - if (sector[nNextSector].ceilingz > sector[nSector].ceilingz) - z = sector[nNextSector].ceilingz; //top step - if (sector[nNextSector].floorz < sector[nSector].floorz) - z = sector[nNextSector].floorz; //bottom step - } - } - return(z); + nSector = sectorofwall((short)nWall); + nNextSector = wall[nWall].nextsector; + if (nNextSector == -1) + { + //1-sided wall + if (wall[nWall].cstat&4) z = sector[nSector].floorz; + else z = sector[nSector].ceilingz; + } + else + { + //2-sided wall + if (wall[nWall].cstat&4) + z = sector[nSector].ceilingz; + else + { + if (sector[nNextSector].ceilingz > sector[nSector].ceilingz) + z = sector[nNextSector].ceilingz; //top step + if (sector[nNextSector].floorz < sector[nSector].floorz) + z = sector[nNextSector].floorz; //bottom step + } + } + return(z); } void AlignWalls(long nWall0, long z0, long nWall1, long z1, long nTile) { - long n; + long n; - //do the x alignment - wall[nWall1].cstat &= ~0x0108; //Set to non-flip - wall[nWall1].xpanning = (char)((wall[nWall0].xpanning+(wall[nWall0].xrepeat<<3))%tilesizx[nTile]); + //do the x alignment + wall[nWall1].cstat &= ~0x0108; //Set to non-flip + wall[nWall1].xpanning = (char)((wall[nWall0].xpanning+(wall[nWall0].xrepeat<<3))%tilesizx[nTile]); - z1 = GetWallZPeg(nWall1); + z1 = GetWallZPeg(nWall1); - for(n=(picsiz[nTile]>>4);((1<>4);((1<>(n+3))); + wall[nWall1].yrepeat = wall[nWall0].yrepeat; + wall[nWall1].ypanning = (char)(wall[nWall0].ypanning+(((z1-z0)*wall[nWall0].yrepeat)>>(n+3))); } void AutoAlignWalls(long nWall0, long ply) { - long z0, z1, nTile, nWall1, branch, visible, nNextSector, nSector; + long z0, z1, nTile, nWall1, branch, visible, nNextSector, nSector; - nTile = wall[nWall0].picnum; - branch = 0; - if (ply == 0) - { - //clear visited bits - memset(visited,0,sizeof(visited)); - visited[nWall0] = 1; - } + nTile = wall[nWall0].picnum; + branch = 0; + if (ply == 0) + { + //clear visited bits + memset(visited,0,sizeof(visited)); + visited[nWall0] = 1; + } - z0 = GetWallZPeg(nWall0); + z0 = GetWallZPeg(nWall0); - nWall1 = wall[nWall0].point2; + nWall1 = wall[nWall0].point2; - //loop through walls at this vertex in CCW order - while (1) - { - //break if this wall would connect us in a loop - if (visited[nWall1]) break; + //loop through walls at this vertex in CCW order + while (1) + { + //break if this wall would connect us in a loop + if (visited[nWall1]) break; - visited[nWall1] = 1; + visited[nWall1] = 1; - //break if reached back of left wall - if (wall[nWall1].nextwall == nWall0) break; + //break if reached back of left wall + if (wall[nWall1].nextwall == nWall0) break; - if (wall[nWall1].picnum == nTile) - { - z1 = GetWallZPeg(nWall1); - visible = 0; + if (wall[nWall1].picnum == nTile) + { + z1 = GetWallZPeg(nWall1); + visible = 0; - nNextSector = wall[nWall1].nextsector; - if (nNextSector < 0) - visible = 1; - else - { - //ignore two sided walls that have no visible face - nSector = wall[wall[nWall1].nextwall].nextsector; - if (getceilzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) < - getceilzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y)) - visible = 1; + nNextSector = wall[nWall1].nextsector; + if (nNextSector < 0) + visible = 1; + else + { + //ignore two sided walls that have no visible face + nSector = wall[wall[nWall1].nextwall].nextsector; + if (getceilzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) < + getceilzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y)) + visible = 1; - if (getflorzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) > - getflorzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y)) - visible = 1; - } + if (getflorzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) > + getflorzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y)) + visible = 1; + } - if (visible) - { - branch++; - AlignWalls(nWall0,z0,nWall1,z1,nTile); + if (visible) + { + branch++; + AlignWalls(nWall0,z0,nWall1,z1,nTile); - //if wall was 1-sided, no need to recurse - if (wall[nWall1].nextwall < 0) - { - nWall0 = nWall1; - z0 = GetWallZPeg(nWall0); - nWall1 = wall[nWall0].point2; - branch = 0; - continue; - } - else - AutoAlignWalls(nWall1,ply+1); - } - } + //if wall was 1-sided, no need to recurse + if (wall[nWall1].nextwall < 0) + { + nWall0 = nWall1; + z0 = GetWallZPeg(nWall0); + nWall1 = wall[nWall0].point2; + branch = 0; + continue; + } + else + AutoAlignWalls(nWall1,ply+1); + } + } - if (wall[nWall1].nextwall < 0) break; - nWall1 = wall[wall[nWall1].nextwall].point2; - } + if (wall[nWall1].nextwall < 0) break; + nWall1 = wall[wall[nWall1].nextwall].point2; + } } diff --git a/polymer/build/src/buildstartwin.c b/polymer/build/src/buildstartwin.c index 3df25c7b6..1971ddd42 100644 --- a/polymer/build/src/buildstartwin.c +++ b/polymer/build/src/buildstartwin.c @@ -19,160 +19,160 @@ static void PopulateVideoModeLists(int fs, HWND list2d, HWND list3d) { - int i,j; - char buf[64]; + int i,j; + char buf[64]; - ComboBox_ResetContent(list2d); - ComboBox_ResetContent(list3d); - for (i=0; i 0) { - if (!IsWindow(hwndLaunch) || quitevent) break; - if (IsDialogMessage(hwndStart, &msg) /*|| IsDialogMessage(hwndLaunch, &msg)*/) continue; - - TranslateMessage(&msg); - DispatchMessage(&msg); - } + while (GetMessage(&msg, NULL, 0, 0) > 0) { + if (!IsWindow(hwndLaunch) || quitevent) break; + if (IsDialogMessage(hwndStart, &msg) /*|| IsDialogMessage(hwndLaunch, &msg)*/) continue; + + TranslateMessage(&msg); + DispatchMessage(&msg); + } #else - while (IsWindow(hwndLaunch) && !quitevent) { - x = win_getstartupcommand(); - if (x != 0) LaunchWindowProc(hwndLaunch, WM_COMMAND, x, 0); - handleevents(); - } + while (IsWindow(hwndLaunch) && !quitevent) { + x = win_getstartupcommand(); + if (x != 0) LaunchWindowProc(hwndLaunch, WM_COMMAND, x, 0); + handleevents(); + } #endif - EnableWindow(GetDlgItem(hwndStart,WIN_STARTWIN_ITEMLIST),TRUE); - } - if (quitevent) return 1; - return 0; + EnableWindow(GetDlgItem(hwndStart,WIN_STARTWIN_ITEMLIST),TRUE); + } + if (quitevent) return 1; + return 0; } diff --git a/polymer/build/src/cache1d.c b/polymer/build/src/cache1d.c index 8133a97e4..5891645fc 100644 --- a/polymer/build/src/cache1d.c +++ b/polymer/build/src/cache1d.c @@ -15,17 +15,17 @@ #ifdef WITHKPLIB #include "kplib.h" - //Insert '|' in front of filename - //Doing this tells kzopen to load the file only if inside a .ZIP file +//Insert '|' in front of filename +//Doing this tells kzopen to load the file only if inside a .ZIP file static long kzipopen(char *filnam) { - unsigned int i; - char newst[BMAX_PATH+4]; + unsigned int i; + char newst[BMAX_PATH+4]; - newst[0] = '|'; - for(i=0;filnam[i] && (i < sizeof(newst)-2);i++) newst[i+1] = filnam[i]; - newst[i+1] = 0; - return(kzopen(newst)); + newst[0] = '|'; + for(i=0;filnam[i] && (i < sizeof(newst)-2);i++) newst[i+1] = filnam[i]; + newst[i+1] = 0; + return(kzopen(newst)); } #endif @@ -81,169 +81,169 @@ extern char pow2char[8]; void initcache(long dacachestart, long dacachesize) { - long i; + long i; - for(i=1;i<200;i++) lockrecip[i] = (1<<28)/(200-i); + for(i=1;i<200;i++) lockrecip[i] = (1<<28)/(200-i); - cachestart = dacachestart; - cachesize = dacachesize; + cachestart = dacachestart; + cachesize = dacachesize; - cac[0].leng = cachesize; - cac[0].lock = &zerochar; - cacnum = 1; + cac[0].leng = cachesize; + cac[0].lock = &zerochar; + cacnum = 1; - initprintf("initcache(): Initialised with %d bytes\n", dacachesize); + initprintf("initcache(): Initialised with %d bytes\n", dacachesize); } void allocache(long *newhandle, long newbytes, char *newlockptr) { - long i, /*j,*/ z, zz, bestz=0, daval, bestval, besto=0, o1, o2, sucklen, suckz; + long i, /*j,*/ z, zz, bestz=0, daval, bestval, besto=0, o1, o2, sucklen, suckz; - newbytes = ((newbytes+15)&0xfffffff0); + newbytes = ((newbytes+15)&0xfffffff0); - if ((unsigned)newbytes > (unsigned)cachesize) - { - Bprintf("Cachesize: %ld\n",cachesize); - Bprintf("*Newhandle: 0x%lx, Newbytes: %ld, *Newlock: %d\n",(long)newhandle,newbytes,*newlockptr); - reportandexit("BUFFER TOO BIG TO FIT IN CACHE!"); - } + if ((unsigned)newbytes > (unsigned)cachesize) + { + Bprintf("Cachesize: %ld\n",cachesize); + Bprintf("*Newhandle: 0x%lx, Newbytes: %ld, *Newlock: %d\n",(long)newhandle,newbytes,*newlockptr); + reportandexit("BUFFER TOO BIG TO FIT IN CACHE!"); + } - if (*newlockptr == 0) - { - reportandexit("ALLOCACHE CALLED WITH LOCK OF 0!"); - } + if (*newlockptr == 0) + { + reportandexit("ALLOCACHE CALLED WITH LOCK OF 0!"); + } - //Find best place - bestval = 0x7fffffff; o1 = cachesize; - for(z=cacnum-1;z>=0;z--) - { - o1 -= cac[z].leng; - o2 = o1+newbytes; if (o2 > cachesize) continue; + //Find best place + bestval = 0x7fffffff; o1 = cachesize; + for(z=cacnum-1;z>=0;z--) + { + o1 -= cac[z].leng; + o2 = o1+newbytes; if (o2 > cachesize) continue; - daval = 0; - for(i=o1,zz=z;i= 200) { daval = 0x7fffffff; break; } - daval += mulscale32(cac[zz].leng+65536,lockrecip[*cac[zz].lock]); - if (daval >= bestval) break; - } - if (daval < bestval) - { - bestval = daval; besto = o1; bestz = z; - if (bestval == 0) break; - } - } + daval = 0; + for(i=o1,zz=z;i= 200) { daval = 0x7fffffff; break; } + daval += mulscale32(cac[zz].leng+65536,lockrecip[*cac[zz].lock]); + if (daval >= bestval) break; + } + if (daval < bestval) + { + bestval = daval; besto = o1; bestz = z; + if (bestval == 0) break; + } + } - //printf("%ld %ld %ld\n",besto,newbytes,*newlockptr); + //printf("%ld %ld %ld\n",besto,newbytes,*newlockptr); - if (bestval == 0x7fffffff) - reportandexit("CACHE SPACE ALL LOCKED UP!"); + if (bestval == 0x7fffffff) + reportandexit("CACHE SPACE ALL LOCKED UP!"); - //Suck things out - for(sucklen=-newbytes,suckz=bestz;sucklen<0;sucklen+=cac[suckz++].leng) - if (*cac[suckz].lock) *cac[suckz].hand = 0; + //Suck things out + for(sucklen=-newbytes,suckz=bestz;sucklen<0;sucklen+=cac[suckz++].leng) + if (*cac[suckz].lock) *cac[suckz].hand = 0; - //Remove all blocks except 1 - suckz -= (bestz+1); cacnum -= suckz; - copybufbyte(&cac[bestz+suckz],&cac[bestz],(cacnum-bestz)*sizeof(cactype)); - cac[bestz].hand = newhandle; *newhandle = cachestart+besto; - cac[bestz].leng = newbytes; - cac[bestz].lock = newlockptr; - cachecount++; + //Remove all blocks except 1 + suckz -= (bestz+1); cacnum -= suckz; + copybufbyte(&cac[bestz+suckz],&cac[bestz],(cacnum-bestz)*sizeof(cactype)); + cac[bestz].hand = newhandle; *newhandle = cachestart+besto; + cac[bestz].leng = newbytes; + cac[bestz].lock = newlockptr; + cachecount++; - //Add new empty block if necessary - if (sucklen <= 0) return; + //Add new empty block if necessary + if (sucklen <= 0) return; - bestz++; - if (bestz == cacnum) - { - cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); - cac[bestz].leng = sucklen; - cac[bestz].lock = &zerochar; - return; - } + bestz++; + if (bestz == cacnum) + { + cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); + cac[bestz].leng = sucklen; + cac[bestz].lock = &zerochar; + return; + } - if (*cac[bestz].lock == 0) { cac[bestz].leng += sucklen; return; } +if (*cac[bestz].lock == 0) { cac[bestz].leng += sucklen; return; } - cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); - for(z=cacnum-1;z>bestz;z--) cac[z] = cac[z-1]; - cac[bestz].leng = sucklen; - cac[bestz].lock = &zerochar; + cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); + for(z=cacnum-1;z>bestz;z--) cac[z] = cac[z-1]; + cac[bestz].leng = sucklen; + cac[bestz].lock = &zerochar; } void suckcache(long *suckptr) { - long i; + long i; - //Can't exit early, because invalid pointer might be same even though lock = 0 - for(i=0;i 0) && (*cac[i-1].lock == 0)) - { - cac[i-1].leng += cac[i].leng; - cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); - } - else if ((i < cacnum-1) && (*cac[i+1].lock == 0)) - { - cac[i+1].leng += cac[i].leng; - cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); - } - } + //Combine empty blocks + if ((i > 0) && (*cac[i-1].lock == 0)) + { + cac[i-1].leng += cac[i].leng; + cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); + } + else if ((i < cacnum-1) && (*cac[i+1].lock == 0)) + { + cac[i+1].leng += cac[i].leng; + cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); + } + } } void agecache(void) { - long cnt; - char ch; + long cnt; + char ch; - if (agecount >= cacnum) agecount = cacnum-1; - if (agecount < 0) return; - for(cnt=(cacnum>>4);cnt>=0;cnt--) - { - ch = (*cac[agecount].lock); - if (((ch-2)&255) < 198) - (*cac[agecount].lock) = ch-1; + if (agecount >= cacnum) agecount = cacnum-1; + if (agecount < 0) return; + for(cnt=(cacnum>>4);cnt>=0;cnt--) + { + ch = (*cac[agecount].lock); + if (((ch-2)&255) < 198) + (*cac[agecount].lock) = ch-1; - agecount--; if (agecount < 0) agecount = cacnum-1; - } + agecount--; if (agecount < 0) agecount = cacnum-1; + } } static void reportandexit(char *errormessage) { - long i, j; + long i, j; - //setvmode(0x3); - j = 0; - for(i=0;i typedef struct _searchpath { - struct _searchpath *next; - char *path; - size_t pathlen; // to save repeated calls to strlen() + struct _searchpath *next; + char *path; + size_t pathlen; // to save repeated calls to strlen() } searchpath_t; static searchpath_t *searchpathhead = NULL; static size_t maxsearchpathlen = 0; @@ -251,125 +251,125 @@ int pathsearchmode = 0; int addsearchpath(const char *p) { - struct stat st; - char *s; - searchpath_t *srch; - int i; + struct stat st; + char *s; + searchpath_t *srch; + int i; - if (Bstat(p, &st) < 0) { - if (errno == ENOENT) return -2; - return -1; - } - if (!(st.st_mode & BS_IFDIR)) return -1; + if (Bstat(p, &st) < 0) { + if (errno == ENOENT) return -2; + return -1; + } + if (!(st.st_mode & BS_IFDIR)) return -1; - srch = (searchpath_t*)malloc(sizeof(searchpath_t)); - if (!srch) return -1; + srch = (searchpath_t*)malloc(sizeof(searchpath_t)); + if (!srch) return -1; - srch->next = searchpathhead; - srch->pathlen = strlen(p)+1; - srch->path = (char*)malloc(srch->pathlen + 1); - if (!srch->path) { - free(srch); - return -1; - } - strcpy(srch->path, p); - for (s=srch->path; *s; s++) ; s--; if (spath || toupperlookup[*s] != '/') strcat(srch->path, "/"); + srch->next = searchpathhead; + srch->pathlen = strlen(p)+1; + srch->path = (char*)malloc(srch->pathlen + 1); + if (!srch->path) { + free(srch); + return -1; + } + strcpy(srch->path, p); + for (s=srch->path; *s; s++) ; s--; if (spath || toupperlookup[*s] != '/') strcat(srch->path, "/"); - searchpathhead = srch; - if (srch->pathlen > maxsearchpathlen) maxsearchpathlen = srch->pathlen; - initprintf("addsearchpath(): Added %s\n", srch->path); + searchpathhead = srch; + if (srch->pathlen > maxsearchpathlen) maxsearchpathlen = srch->pathlen; + initprintf("addsearchpath(): Added %s\n", srch->path); - return 0; + return 0; } int findfrompath(const char *fn, char **where) { - searchpath_t *sp; - char *pfn, *ffn; - int allocsiz; + searchpath_t *sp; + char *pfn, *ffn; + int allocsiz; - // pathsearchmode == 0: tests current dir and then the dirs of the path stack - // pathsearchmode == 1: tests fn without modification, then like for pathsearchmode == 0 - - if (pathsearchmode) { - // test unmolested filename first - if (access(fn, F_OK) >= 0) { - *where = strdup(fn); - return 0; - } - } + // pathsearchmode == 0: tests current dir and then the dirs of the path stack + // pathsearchmode == 1: tests fn without modification, then like for pathsearchmode == 0 - for (pfn = (char*)fn; toupperlookup[*pfn] == '/'; pfn++); - ffn = strdup(pfn); - if (!ffn) return -1; - Bcorrectfilename(ffn,0); // compress relative paths - - allocsiz = max(maxsearchpathlen, 2); // "./" (aka. curdir) - allocsiz += strlen(ffn); - allocsiz += 1; // a nul - - pfn = (char *)malloc(allocsiz); - if (!pfn) { free(ffn); return -1; } + if (pathsearchmode) { + // test unmolested filename first + if (access(fn, F_OK) >= 0) { + *where = strdup(fn); + return 0; + } + } - strcpy(pfn, "./"); - strcat(pfn, ffn); - if (access(pfn, F_OK) >= 0) { - *where = pfn; - free(ffn); - return 0; - } - - for (sp = searchpathhead; sp; sp = sp->next) { - strcpy(pfn, sp->path); - strcat(pfn, ffn); - //initprintf("Trying %s\n", pfn); - if (access(pfn, F_OK) >= 0) { - *where = pfn; - free(ffn); - return 0; - } - } - free(pfn); free(ffn); - return -1; + for (pfn = (char*)fn; toupperlookup[*pfn] == '/'; pfn++); + ffn = strdup(pfn); + if (!ffn) return -1; + Bcorrectfilename(ffn,0); // compress relative paths + + allocsiz = max(maxsearchpathlen, 2); // "./" (aka. curdir) + allocsiz += strlen(ffn); + allocsiz += 1; // a nul + + pfn = (char *)malloc(allocsiz); +if (!pfn) { free(ffn); return -1; } + + strcpy(pfn, "./"); + strcat(pfn, ffn); + if (access(pfn, F_OK) >= 0) { + *where = pfn; + free(ffn); + return 0; + } + + for (sp = searchpathhead; sp; sp = sp->next) { + strcpy(pfn, sp->path); + strcat(pfn, ffn); + //initprintf("Trying %s\n", pfn); + if (access(pfn, F_OK) >= 0) { + *where = pfn; + free(ffn); + return 0; + } + } + free(pfn); free(ffn); + return -1; } int openfrompath(const char *fn, int flags, int mode) { - char *pfn; - int h; + char *pfn; + int h; - if (findfrompath(fn, &pfn) < 0) return -1; - h = Bopen(pfn, flags, mode); - free(pfn); + if (findfrompath(fn, &pfn) < 0) return -1; + h = Bopen(pfn, flags, mode); + free(pfn); - return h; + return h; } BFILE* fopenfrompath(const char *fn, const char *mode) { - int fh; - BFILE *h; - int bmode = 0, smode = 0; - const char *c; + int fh; + BFILE *h; + int bmode = 0, smode = 0; + const char *c; - for (c=mode; c[0]; ) { - if (c[0] == 'r' && c[1] == '+') { bmode = BO_RDWR; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'r') { bmode = BO_RDONLY; smode = BS_IREAD; c+=1; } - else if (c[0] == 'w' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'w') { bmode = BO_WRONLY|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'a' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'a') { bmode = BO_WRONLY|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=1; } - else if (c[0] == 'b') { bmode |= BO_BINARY; c+=1; } - else if (c[1] == 't') { bmode |= BO_TEXT; c+=1; } - else c++; - } - fh = openfrompath(fn,bmode,smode); - if (fh < 0) return NULL; - - h = fdopen(fh,mode); - if (!h) close(fh); + for (c=mode; c[0]; ) { + if (c[0] == 'r' && c[1] == '+') { bmode = BO_RDWR; smode = BS_IREAD|BS_IWRITE; c+=2; } + else if (c[0] == 'r') { bmode = BO_RDONLY; smode = BS_IREAD; c+=1; } + else if (c[0] == 'w' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } + else if (c[0] == 'w') { bmode = BO_WRONLY|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } + else if (c[0] == 'a' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=2; } + else if (c[0] == 'a') { bmode = BO_WRONLY|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=1; } + else if (c[0] == 'b') { bmode |= BO_BINARY; c+=1; } + else if (c[1] == 't') { bmode |= BO_TEXT; c+=1; } + else c++; + } + fh = openfrompath(fn,bmode,smode); + if (fh < 0) return NULL; - return h; + h = fdopen(fh,mode); + if (!h) close(fh); + + return h; } @@ -377,24 +377,24 @@ BFILE* fopenfrompath(const char *fn, const char *mode) #define MAXOPENFILES 64 //Warning: Fix filehan if this is changed static char toupperlookup[256] = -{ - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, - 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, - 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, - 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, - 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, - 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, - 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff -}; + { + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, + 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, + 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, + 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, + 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, + 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, + 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, + 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, + 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, + 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, + 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, + 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff + }; static long numgroupfiles = 0; static long gnumfiles[MAXGROUPFILES]; @@ -406,12 +406,12 @@ static long *gfileoffs[MAXGROUPFILES]; static char filegrp[MAXOPENFILES]; static long filepos[MAXOPENFILES]; static long filehan[MAXOPENFILES] = -{ - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -}; + { + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + }; #ifdef WITHKPLIB static char filenamsav[MAXOPENFILES][260]; static long kzcurhand = -1; @@ -419,609 +419,609 @@ static long kzcurhand = -1; long initgroupfile(char *filename) { - char buf[16]; - long i, j, k; + char buf[16]; + long i, j, k; #ifdef WITHKPLIB - char *zfn; - searchpath_t *sp = NULL; + char *zfn; + searchpath_t *sp = NULL; #endif #ifdef _WIN32 - // on Windows, translate all backslashes (0x5c) to forward slashes (0x2f) - toupperlookup[0x5c] = 0x2f; + // on Windows, translate all backslashes (0x5c) to forward slashes (0x2f) + toupperlookup[0x5c] = 0x2f; #endif - + #ifdef WITHKPLIB - if (findfrompath(filename, &zfn) < 0) return -1; - - // check to see if the file passed is a ZIP and pass it on to kplib if it is - i = Bopen(zfn,BO_BINARY|BO_RDONLY,BS_IREAD); - if (i < 0) { free(zfn); return -1; } + if (findfrompath(filename, &zfn) < 0) return -1; - Bread(i, buf, 4); - if (buf[0] == 0x50 && buf[1] == 0x4B && buf[2] == 0x03 && buf[3] == 0x04) { - Bclose(i); - j = kzaddstack(zfn); - free(zfn); - return j; - } - free(zfn); + // check to see if the file passed is a ZIP and pass it on to kplib if it is + i = Bopen(zfn,BO_BINARY|BO_RDONLY,BS_IREAD); +if (i < 0) { free(zfn); return -1; } - if (numgroupfiles >= MAXGROUPFILES) return(-1); + Bread(i, buf, 4); + if (buf[0] == 0x50 && buf[1] == 0x4B && buf[2] == 0x03 && buf[3] == 0x04) { + Bclose(i); + j = kzaddstack(zfn); + free(zfn); + return j; + } + free(zfn); - Blseek(i,0,BSEEK_SET); - groupfil[numgroupfiles] = i; + if (numgroupfiles >= MAXGROUPFILES) return(-1); + + Blseek(i,0,BSEEK_SET); + groupfil[numgroupfiles] = i; #else - groupfil[numgroupfiles] = openfrompath(filename,BO_BINARY|BO_RDONLY,BS_IREAD); - if (groupfil[numgroupfiles] != -1) + groupfil[numgroupfiles] = openfrompath(filename,BO_BINARY|BO_RDONLY,BS_IREAD); + if (groupfil[numgroupfiles] != -1) #endif - { - groupfilpos[numgroupfiles] = 0; - Bread(groupfil[numgroupfiles],buf,16); - if ((buf[0] != 'K') || (buf[1] != 'e') || (buf[2] != 'n') || - (buf[3] != 'S') || (buf[4] != 'i') || (buf[5] != 'l') || - (buf[6] != 'v') || (buf[7] != 'e') || (buf[8] != 'r') || - (buf[9] != 'm') || (buf[10] != 'a') || (buf[11] != 'n')) - { - Bclose(groupfil[numgroupfiles]); - groupfil[numgroupfiles] = -1; - return(-1); - } - gnumfiles[numgroupfiles] = B_LITTLE32(*((long *)&buf[12])); + { + groupfilpos[numgroupfiles] = 0; + Bread(groupfil[numgroupfiles],buf,16); + if ((buf[0] != 'K') || (buf[1] != 'e') || (buf[2] != 'n') || + (buf[3] != 'S') || (buf[4] != 'i') || (buf[5] != 'l') || + (buf[6] != 'v') || (buf[7] != 'e') || (buf[8] != 'r') || + (buf[9] != 'm') || (buf[10] != 'a') || (buf[11] != 'n')) + { + Bclose(groupfil[numgroupfiles]); + groupfil[numgroupfiles] = -1; + return(-1); + } + gnumfiles[numgroupfiles] = B_LITTLE32(*((long *)&buf[12])); - if ((gfilelist[numgroupfiles] = (char *)kmalloc(gnumfiles[numgroupfiles]<<4)) == 0) - { Bprintf("Not enough memory for file grouping system\n"); exit(0); } - if ((gfileoffs[numgroupfiles] = (long *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0) - { Bprintf("Not enough memory for file grouping system\n"); exit(0); } + if ((gfilelist[numgroupfiles] = (char *)kmalloc(gnumfiles[numgroupfiles]<<4)) == 0) + { Bprintf("Not enough memory for file grouping system\n"); exit(0); } + if ((gfileoffs[numgroupfiles] = (long *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0) + { Bprintf("Not enough memory for file grouping system\n"); exit(0); } - Bread(groupfil[numgroupfiles],gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4); + Bread(groupfil[numgroupfiles],gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4); - j = 0; - for(i=0;i=0;i--) - if (groupfil[i] != -1 && groupfil[i] == grphandle) - { - kfree(gfilelist[i]); - kfree(gfileoffs[i]); - Bclose(groupfil[i]); - groupfil[i] = -1; - grpnum = i; - break; - } + for(i=numgroupfiles-1;i>=0;i--) + if (groupfil[i] != -1 && groupfil[i] == grphandle) + { + kfree(gfilelist[i]); + kfree(gfileoffs[i]); + Bclose(groupfil[i]); + groupfil[i] = -1; + grpnum = i; + break; + } - if (grpnum == -1) return; + if (grpnum == -1) return; - // JBF 20040111 - numgroupfiles--; + // JBF 20040111 + numgroupfiles--; - // move any group files following this one back - for (i=grpnum+1; i= 254) // external file (255) or ZIPped file (254) - continue; - else if (filegrp[i] == grpnum) // close file in group we closed - filehan[i] = -1; - else if (filegrp[i] > grpnum) // move back a file in a group after the one we closed - filegrp[i]--; - } + // fix up the open files that need attention + for(i=0;i= 254) // external file (255) or ZIPped file (254) + continue; + else if (filegrp[i] == grpnum) // close file in group we closed + filehan[i] = -1; + else if (filegrp[i] > grpnum) // move back a file in a group after the one we closed + filegrp[i]--; + } } void uninitgroupfile(void) { - long i; + long i; - for(i=numgroupfiles-1;i>=0;i--) - if (groupfil[i] != -1) - { - kfree(gfilelist[i]); - kfree(gfileoffs[i]); - Bclose(groupfil[i]); - groupfil[i] = -1; - } - numgroupfiles = 0; + for(i=numgroupfiles-1;i>=0;i--) + if (groupfil[i] != -1) + { + kfree(gfilelist[i]); + kfree(gfileoffs[i]); + Bclose(groupfil[i]); + groupfil[i] = -1; + } + numgroupfiles = 0; - // JBF 20040111: "close" any files open in groups - for(i=0;i= 0) - { - filegrp[newhandle] = 255; - filehan[newhandle] = fil; - filepos[newhandle] = 0; - return(newhandle); - } + if (searchfirst == 0) + if ((fil = openfrompath(filename,BO_BINARY|BO_RDONLY,S_IREAD)) >= 0) + { + filegrp[newhandle] = 255; + filehan[newhandle] = fil; + filepos[newhandle] = 0; + return(newhandle); + } + + for (; toupperlookup[*filename] == '/'; filename++); - for (; toupperlookup[*filename] == '/'; filename++); - #ifdef WITHKPLIB - if ((kzcurhand != newhandle) && (kztell() >= 0)) - { - if (kzcurhand >= 0) filepos[kzcurhand] = kztell(); - kzclose(); - } - if (searchfirst != 1 && (i = kzipopen(filename)) != 0) { - kzcurhand = newhandle; - filegrp[newhandle] = 254; - filehan[newhandle] = i; - filepos[newhandle] = 0; - strcpy(filenamsav[newhandle],filename); - return newhandle; - } + if ((kzcurhand != newhandle) && (kztell() >= 0)) + { + if (kzcurhand >= 0) filepos[kzcurhand] = kztell(); + kzclose(); + } + if (searchfirst != 1 && (i = kzipopen(filename)) != 0) { + kzcurhand = newhandle; + filegrp[newhandle] = 254; + filehan[newhandle] = i; + filepos[newhandle] = 0; + strcpy(filenamsav[newhandle],filename); + return newhandle; + } #endif - for(k=numgroupfiles-1;k>=0;k--) - { - if (searchfirst == 1) k = 0; - if (groupfil[k] >= 0) - { - for(i=gnumfiles[k]-1;i>=0;i--) - { - gfileptr = (char *)&gfilelist[k][i<<4]; + for(k=numgroupfiles-1;k>=0;k--) + { + if (searchfirst == 1) k = 0; + if (groupfil[k] >= 0) + { + for(i=gnumfiles[k]-1;i>=0;i--) + { + gfileptr = (char *)&gfilelist[k][i<<4]; - bad = 0; - for(j=0;j<13;j++) - { - if (!filename[j]) break; - if (toupperlookup[filename[j]] != toupperlookup[gfileptr[j]]) - { bad = 1; break; } - } - if (bad) continue; - if (j<13 && gfileptr[j]) continue; // JBF: because e1l1.map might exist before e1l1 - if (j==13 && filename[j]) continue; // JBF: long file name + bad = 0; + for(j=0;j<13;j++) + { + if (!filename[j]) break; + if (toupperlookup[filename[j]] != toupperlookup[gfileptr[j]]) + { bad = 1; break; } + } + if (bad) continue; + if (j<13 && gfileptr[j]) continue; // JBF: because e1l1.map might exist before e1l1 + if (j==13 && filename[j]) continue; // JBF: long file name - filegrp[newhandle] = k; - filehan[newhandle] = i; - filepos[newhandle] = 0; - return(newhandle); - } - } - } - return(-1); + filegrp[newhandle] = k; + filehan[newhandle] = i; + filepos[newhandle] = 0; + return(newhandle); + } + } + } + return(-1); } long kread(long handle, void *buffer, long leng) { - long i, filenum, groupnum; + long i, filenum, groupnum; - filenum = filehan[handle]; - groupnum = filegrp[handle]; - if (groupnum == 255) return(Bread(filenum,buffer,leng)); + filenum = filehan[handle]; + groupnum = filegrp[handle]; + if (groupnum == 255) return(Bread(filenum,buffer,leng)); #ifdef WITHKPLIB - else if (groupnum == 254) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(filepos[handle],SEEK_SET); - } - return(kzread(buffer,leng)); - } + else if (groupnum == 254) + { + if (kzcurhand != handle) + { + if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } + kzcurhand = handle; + kzipopen(filenamsav[handle]); + kzseek(filepos[handle],SEEK_SET); + } + return(kzread(buffer,leng)); + } #endif - if (groupfil[groupnum] != -1) - { - i = gfileoffs[groupnum][filenum]+filepos[handle]; - if (i != groupfilpos[groupnum]) - { - Blseek(groupfil[groupnum],i+((gnumfiles[groupnum]+1)<<4),BSEEK_SET); - groupfilpos[groupnum] = i; - } - leng = min(leng,(gfileoffs[groupnum][filenum+1]-gfileoffs[groupnum][filenum])-filepos[handle]); - leng = Bread(groupfil[groupnum],buffer,leng); - filepos[handle] += leng; - groupfilpos[groupnum] += leng; - return(leng); - } + if (groupfil[groupnum] != -1) + { + i = gfileoffs[groupnum][filenum]+filepos[handle]; + if (i != groupfilpos[groupnum]) + { + Blseek(groupfil[groupnum],i+((gnumfiles[groupnum]+1)<<4),BSEEK_SET); + groupfilpos[groupnum] = i; + } + leng = min(leng,(gfileoffs[groupnum][filenum+1]-gfileoffs[groupnum][filenum])-filepos[handle]); + leng = Bread(groupfil[groupnum],buffer,leng); + filepos[handle] += leng; + groupfilpos[groupnum] += leng; + return(leng); + } - return(0); + return(0); } long klseek(long handle, long offset, long whence) { - long i, groupnum; + long i, groupnum; - groupnum = filegrp[handle]; + groupnum = filegrp[handle]; - if (groupnum == 255) return(Blseek(filehan[handle],offset,whence)); + if (groupnum == 255) return(Blseek(filehan[handle],offset,whence)); #ifdef WITHKPLIB - else if (groupnum == 254) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(filepos[handle],SEEK_SET); - } - return(kzseek(offset,whence)); - } + else if (groupnum == 254) + { + if (kzcurhand != handle) + { + if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } + kzcurhand = handle; + kzipopen(filenamsav[handle]); + kzseek(filepos[handle],SEEK_SET); + } + return(kzseek(offset,whence)); + } #endif - if (groupfil[groupnum] != -1) - { - switch(whence) - { - case BSEEK_SET: filepos[handle] = offset; break; - case BSEEK_END: i = filehan[handle]; - filepos[handle] = (gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i])+offset; - break; - case BSEEK_CUR: filepos[handle] += offset; break; - } - return(filepos[handle]); - } - return(-1); + if (groupfil[groupnum] != -1) + { + switch(whence) + { + case BSEEK_SET: filepos[handle] = offset; break; + case BSEEK_END: i = filehan[handle]; + filepos[handle] = (gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i])+offset; + break; + case BSEEK_CUR: filepos[handle] += offset; break; + } + return(filepos[handle]); + } + return(-1); } long kfilelength(long handle) { - long i, groupnum; + long i, groupnum; - groupnum = filegrp[handle]; - if (groupnum == 255) { - // return(filelength(filehan[handle])) - return Bfilelength(filehan[handle]); - } + groupnum = filegrp[handle]; + if (groupnum == 255) { + // return(filelength(filehan[handle])) + return Bfilelength(filehan[handle]); + } #ifdef WITHKPLIB - else if (groupnum == 254) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(filepos[handle],SEEK_SET); - } - return kzfilelength(); - } + else if (groupnum == 254) + { + if (kzcurhand != handle) + { + if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } + kzcurhand = handle; + kzipopen(filenamsav[handle]); + kzseek(filepos[handle],SEEK_SET); + } + return kzfilelength(); + } #endif - i = filehan[handle]; - return(gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i]); + i = filehan[handle]; + return(gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i]); } long ktell(long handle) { - long i, groupnum; + long i, groupnum; - groupnum = filegrp[handle]; + groupnum = filegrp[handle]; - if (groupnum == 255) return(Blseek(filehan[handle],0,BSEEK_CUR)); + if (groupnum == 255) return(Blseek(filehan[handle],0,BSEEK_CUR)); #ifdef WITHKPLIB - else if (groupnum == 254) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(filepos[handle],SEEK_SET); - } - return kztell(); - } + else if (groupnum == 254) + { + if (kzcurhand != handle) + { + if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); } + kzcurhand = handle; + kzipopen(filenamsav[handle]); + kzseek(filepos[handle],SEEK_SET); + } + return kztell(); + } #endif - if (groupfil[groupnum] != -1) - return filepos[handle]; - return(-1); + if (groupfil[groupnum] != -1) + return filepos[handle]; + return(-1); } void kclose(long handle) { - if (handle < 0) return; - if (filegrp[handle] == 255) Bclose(filehan[handle]); + if (handle < 0) return; + if (filegrp[handle] == 255) Bclose(filehan[handle]); #ifdef WITHKPLIB - else if (filegrp[handle] == 254) - { - kzclose(); - kzcurhand = -1; - } + else if (filegrp[handle] == 254) + { + kzclose(); + kzcurhand = -1; + } #endif - filehan[handle] = -1; + filehan[handle] = -1; } static int klistaddentry(CACHE1D_FIND_REC **rec, char *name, int type, int source) { - CACHE1D_FIND_REC *r = NULL, *attach = NULL; + CACHE1D_FIND_REC *r = NULL, *attach = NULL; - if (*rec) { - int insensitive, v; - CACHE1D_FIND_REC *last = NULL; - - for (attach = *rec; attach; last = attach, attach = attach->next) { - if (type == CACHE1D_FIND_DRIVE) continue; // we just want to get to the end for drives + if (*rec) { + int insensitive, v; + CACHE1D_FIND_REC *last = NULL; + + for (attach = *rec; attach; last = attach, attach = attach->next) { + if (type == CACHE1D_FIND_DRIVE) continue; // we just want to get to the end for drives #ifdef _WIN32 - insensitive = 1; + insensitive = 1; #else - if (source == CACHE1D_SOURCE_GRP || attach->source == CACHE1D_SOURCE_GRP) - insensitive = 1; - else if (source == CACHE1D_SOURCE_ZIP || attach->source == CACHE1D_SOURCE_ZIP) - insensitive = 1; - else - insensitive = 0; + if (source == CACHE1D_SOURCE_GRP || attach->source == CACHE1D_SOURCE_GRP) + insensitive = 1; + else if (source == CACHE1D_SOURCE_ZIP || attach->source == CACHE1D_SOURCE_ZIP) + insensitive = 1; + else + insensitive = 0; #endif - if (insensitive) v = Bstrcasecmp(name, attach->name); - else v = Bstrcmp(name, attach->name); - - // sorted list - if (v > 0) continue; // item to add is bigger than the current one - // so look for something bigger than us - if (v < 0) { // item to add is smaller than the current one - attach = NULL; // so wedge it between the current item and the one before - break; - } - - // matched - if (source >= attach->source) return 1; // item to add is of lower priority - r = attach; - break; - } + if (insensitive) v = Bstrcasecmp(name, attach->name); + else v = Bstrcmp(name, attach->name); - // wasn't found in the list, so attach to the end - if (!attach) attach = last; - } + // sorted list + if (v > 0) continue; // item to add is bigger than the current one + // so look for something bigger than us + if (v < 0) { // item to add is smaller than the current one + attach = NULL; // so wedge it between the current item and the one before + break; + } - if (r) { - r->type = type; - r->source = source; - return 0; - } + // matched + if (source >= attach->source) return 1; // item to add is of lower priority + r = attach; + break; + } - r = (CACHE1D_FIND_REC *)malloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1); - if (!r) return -1; - r->name = (char*)r + sizeof(CACHE1D_FIND_REC); strcpy(r->name, name); - r->type = type; - r->source = source; - r->usera = r->userb = NULL; + // wasn't found in the list, so attach to the end + if (!attach) attach = last; + } - if (!attach) { // we are the first item - r->prev = NULL; - r->next = *rec; - if (*rec) (*rec)->prev = r; - *rec = r; - } else { - r->prev = attach; - r->next = attach->next; - if (attach->next) attach->next->prev = r; - attach->next = r; - } + if (r) { + r->type = type; + r->source = source; + return 0; + } - return 0; + r = (CACHE1D_FIND_REC *)malloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1); + if (!r) return -1; + r->name = (char*)r + sizeof(CACHE1D_FIND_REC); strcpy(r->name, name); + r->type = type; + r->source = source; + r->usera = r->userb = NULL; + + if (!attach) { // we are the first item + r->prev = NULL; + r->next = *rec; + if (*rec) (*rec)->prev = r; + *rec = r; + } else { + r->prev = attach; + r->next = attach->next; + if (attach->next) attach->next->prev = r; + attach->next = r; + } + + return 0; } void klistfree(CACHE1D_FIND_REC *rec) { - CACHE1D_FIND_REC *n; - - while (rec) { - n = rec->next; - free(rec); - rec = n; - } + CACHE1D_FIND_REC *n; + + while (rec) { + n = rec->next; + free(rec); + rec = n; + } } CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int type) { - CACHE1D_FIND_REC *rec = NULL; - char *path; - - // pathsearchmode == 0: enumerates a path in the virtual filesystem - // pathsearchmode == 1: enumerates the system filesystem path passed in - - path = strdup(_path); - if (!path) return NULL; + CACHE1D_FIND_REC *rec = NULL; + char *path; - // we don't need any leading dots and slashes or trailing slashes either - { - int i,j; - for (i=0; path[i] == '.' || toupperlookup[path[i]] == '/'; ) i++; - for (j=0; (path[j] = path[i]); j++,i++) ; - while (j>0 && toupperlookup[path[j-1]] == '/') j--; - path[j] = 0; - //initprintf("Cleaned up path = \"%s\"\n",path); - } - - if (*path && (type & CACHE1D_FIND_DIR)) { - if (klistaddentry(&rec, "..", CACHE1D_FIND_DIR, CACHE1D_SOURCE_CURDIR) < 0) goto failure; - } - - if (!(type & CACHE1D_OPT_NOSTACK)) { // current directory and paths in the search stack - searchpath_t *search = NULL; - BDIR *dir; - struct Bdirent *dirent; - const char *d = "."; - int stackdepth = CACHE1D_SOURCE_CURDIR; - char buf[BMAX_PATH]; + // pathsearchmode == 0: enumerates a path in the virtual filesystem + // pathsearchmode == 1: enumerates the system filesystem path passed in - if (pathsearchmode) d = _path; + path = strdup(_path); + if (!path) return NULL; - do { - if (!pathsearchmode) { - strcpy(buf, path); - if (*path) strcat(buf, "/"); - strcat(buf, d); - } else strcpy(buf, d); - dir = Bopendir(buf); - if (dir) { - while ((dirent = Breaddir(dir))) { - if ((dirent->name[0] == '.' && dirent->name[1] == 0) || - (dirent->name[0] == '.' && dirent->name[1] == '.' && dirent->name[2] == 0)) - continue; - if ((type & CACHE1D_FIND_DIR) && !(dirent->mode & BS_IFDIR)) continue; - if ((type & CACHE1D_FIND_FILE) && (dirent->mode & BS_IFDIR)) continue; - if (!Bwildmatch(dirent->name, mask)) continue; - switch (klistaddentry(&rec, dirent->name, - (dirent->mode & BS_IFDIR) ? CACHE1D_FIND_DIR : CACHE1D_FIND_FILE, - stackdepth)) { - case -1: goto failure; - //case 1: initprintf("%s:%s dropped for lower priority\n", d,dirent->name); break; - //case 0: initprintf("%s:%s accepted\n", d,dirent->name); break; - default: break; - } - } - Bclosedir(dir); - } - - if (pathsearchmode) break; + // we don't need any leading dots and slashes or trailing slashes either + { + int i,j; + for (i=0; path[i] == '.' || toupperlookup[path[i]] == '/'; ) i++; + for (j=0; (path[j] = path[i]); j++,i++) ; + while (j>0 && toupperlookup[path[j-1]] == '/') j--; + path[j] = 0; + //initprintf("Cleaned up path = \"%s\"\n",path); + } - if (!search) { - search = searchpathhead; - stackdepth = CACHE1D_SOURCE_PATH; - } else { - search = search->next; - stackdepth++; - } - if (search) d = search->path; - } while (search); - } + if (*path && (type & CACHE1D_FIND_DIR)) { + if (klistaddentry(&rec, "..", CACHE1D_FIND_DIR, CACHE1D_SOURCE_CURDIR) < 0) goto failure; + } - if (!pathsearchmode) { // next, zip files - char buf[BMAX_PATH], *p; - int i, j, ftype; - strcpy(buf,path); - if (*path) strcat(buf,"/"); - strcat(buf,mask); - for (kzfindfilestart(buf); kzfindfile(buf); ) { - if (buf[0] != '|') continue; // local files we don't need - - // scan for the end of the string and shift - // everything left a char in the process - for (i=1; (buf[i-1]=buf[i]); i++) ; i-=2; + if (!(type & CACHE1D_OPT_NOSTACK)) { // current directory and paths in the search stack + searchpath_t *search = NULL; + BDIR *dir; + struct Bdirent *dirent; + const char *d = "."; + int stackdepth = CACHE1D_SOURCE_CURDIR; + char buf[BMAX_PATH]; - // if there's a slash at the end, this is a directory entry - if (toupperlookup[buf[i]] == '/') { ftype = CACHE1D_FIND_DIR; buf[i] = 0; } - else ftype = CACHE1D_FIND_FILE; + if (pathsearchmode) d = _path; - // skip over the common characters at the beginning of the base path and the zip entry - for (j=0; buf[j] && path[j]; j++) { - if (toupperlookup[ path[j] ] == toupperlookup[ buf[j] ]) continue; - break; - } - // we've now hopefully skipped the common path component at the beginning. - // if that's true, we should be staring at a null byte in path and either any character in buf - // if j==0, or a slash if j>0 - if ((!path[0] && buf[j]) || (!path[j] && toupperlookup[ buf[j] ] == '/')) { - if (j>0) j++; - - // yep, so now we shift what follows back to the start of buf and while we do that, - // keep an eye out for any more slashes which would mean this entry has sub-entities - // and is useless to us. - for (i = 0; (buf[i] = buf[j]) && toupperlookup[buf[j]] != '/'; i++,j++) ; - if (toupperlookup[buf[j]] == '/') continue; // damn, try next entry - } else { - // if we're here it means we have a situation where: - // path = foo - // buf = foobar... - // or - // path = foobar - // buf = foo... - // which would mean the entry is higher up in the directory tree and is also useless - continue; - } + do { + if (!pathsearchmode) { + strcpy(buf, path); + if (*path) strcat(buf, "/"); + strcat(buf, d); + } else strcpy(buf, d); + dir = Bopendir(buf); + if (dir) { + while ((dirent = Breaddir(dir))) { + if ((dirent->name[0] == '.' && dirent->name[1] == 0) || + (dirent->name[0] == '.' && dirent->name[1] == '.' && dirent->name[2] == 0)) + continue; + if ((type & CACHE1D_FIND_DIR) && !(dirent->mode & BS_IFDIR)) continue; + if ((type & CACHE1D_FIND_FILE) && (dirent->mode & BS_IFDIR)) continue; + if (!Bwildmatch(dirent->name, mask)) continue; + switch (klistaddentry(&rec, dirent->name, + (dirent->mode & BS_IFDIR) ? CACHE1D_FIND_DIR : CACHE1D_FIND_FILE, + stackdepth)) { + case -1: goto failure; + //case 1: initprintf("%s:%s dropped for lower priority\n", d,dirent->name); break; + //case 0: initprintf("%s:%s accepted\n", d,dirent->name); break; + default: break; + } + } + Bclosedir(dir); + } - if ((type & CACHE1D_FIND_DIR) && ftype != CACHE1D_FIND_DIR) continue; - if ((type & CACHE1D_FIND_FILE) && ftype != CACHE1D_FIND_FILE) continue; - - // the entry is in the clear - switch (klistaddentry(&rec, buf, ftype, CACHE1D_SOURCE_ZIP)) { - case -1: goto failure; - //case 1: initprintf(":%s dropped for lower priority\n", buf); break; - //case 0: initprintf(":%s accepted\n", buf); break; - default: break; - } - } - } - - // then, grp files - if (!pathsearchmode && !*path && (type & CACHE1D_FIND_FILE)) { - char buf[13]; - int i,j; - buf[12] = 0; - for (i=0;i=0;j--) - { - Bmemcpy(buf,&gfilelist[i][j<<4],12); - if (!Bwildmatch(buf,mask)) continue; - switch (klistaddentry(&rec, buf, CACHE1D_FIND_FILE, CACHE1D_SOURCE_GRP)) { - case -1: goto failure; - //case 1: initprintf(":%s dropped for lower priority\n", workspace); break; - //case 0: initprintf(":%s accepted\n", workspace); break; - default: break; - } - } - } - } - - if (pathsearchmode && (type & CACHE1D_FIND_DRIVE)) { - char *drives, *drp; - drives = Bgetsystemdrives(); - if (drives) { - for (drp=drives; *drp; drp+=strlen(drp)+1) { - if (klistaddentry(&rec, drp, CACHE1D_FIND_DRIVE, CACHE1D_SOURCE_DRIVE) < 0) { - free(drives); - goto failure; - } - } - free(drives); - } - } - - free(path); - return rec; + if (pathsearchmode) break; + + if (!search) { + search = searchpathhead; + stackdepth = CACHE1D_SOURCE_PATH; + } else { + search = search->next; + stackdepth++; + } + if (search) d = search->path; + } while (search); + } + + if (!pathsearchmode) { // next, zip files + char buf[BMAX_PATH], *p; + int i, j, ftype; + strcpy(buf,path); + if (*path) strcat(buf,"/"); + strcat(buf,mask); + for (kzfindfilestart(buf); kzfindfile(buf); ) { + if (buf[0] != '|') continue; // local files we don't need + + // scan for the end of the string and shift + // everything left a char in the process + for (i=1; (buf[i-1]=buf[i]); i++) ; i-=2; + + // if there's a slash at the end, this is a directory entry + if (toupperlookup[buf[i]] == '/') { ftype = CACHE1D_FIND_DIR; buf[i] = 0; } + else ftype = CACHE1D_FIND_FILE; + + // skip over the common characters at the beginning of the base path and the zip entry + for (j=0; buf[j] && path[j]; j++) { + if (toupperlookup[ path[j] ] == toupperlookup[ buf[j] ]) continue; + break; + } + // we've now hopefully skipped the common path component at the beginning. + // if that's true, we should be staring at a null byte in path and either any character in buf + // if j==0, or a slash if j>0 + if ((!path[0] && buf[j]) || (!path[j] && toupperlookup[ buf[j] ] == '/')) { + if (j>0) j++; + + // yep, so now we shift what follows back to the start of buf and while we do that, + // keep an eye out for any more slashes which would mean this entry has sub-entities + // and is useless to us. + for (i = 0; (buf[i] = buf[j]) && toupperlookup[buf[j]] != '/'; i++,j++) ; + if (toupperlookup[buf[j]] == '/') continue; // damn, try next entry + } else { + // if we're here it means we have a situation where: + // path = foo + // buf = foobar... + // or + // path = foobar + // buf = foo... + // which would mean the entry is higher up in the directory tree and is also useless + continue; + } + + if ((type & CACHE1D_FIND_DIR) && ftype != CACHE1D_FIND_DIR) continue; + if ((type & CACHE1D_FIND_FILE) && ftype != CACHE1D_FIND_FILE) continue; + + // the entry is in the clear + switch (klistaddentry(&rec, buf, ftype, CACHE1D_SOURCE_ZIP)) { + case -1: goto failure; + //case 1: initprintf(":%s dropped for lower priority\n", buf); break; + //case 0: initprintf(":%s accepted\n", buf); break; + default: break; + } + } + } + + // then, grp files + if (!pathsearchmode && !*path && (type & CACHE1D_FIND_FILE)) { + char buf[13]; + int i,j; + buf[12] = 0; + for (i=0;i=0;j--) + { + Bmemcpy(buf,&gfilelist[i][j<<4],12); + if (!Bwildmatch(buf,mask)) continue; + switch (klistaddentry(&rec, buf, CACHE1D_FIND_FILE, CACHE1D_SOURCE_GRP)) { + case -1: goto failure; + //case 1: initprintf(":%s dropped for lower priority\n", workspace); break; + //case 0: initprintf(":%s accepted\n", workspace); break; + default: break; + } + } + } + } + + if (pathsearchmode && (type & CACHE1D_FIND_DRIVE)) { + char *drives, *drp; + drives = Bgetsystemdrives(); + if (drives) { + for (drp=drives; *drp; drp+=strlen(drp)+1) { + if (klistaddentry(&rec, drp, CACHE1D_FIND_DRIVE, CACHE1D_SOURCE_DRIVE) < 0) { + free(drives); + goto failure; + } + } + free(drives); + } + } + + free(path); + return rec; failure: - free(path); - klistfree(rec); - return NULL; + free(path); + klistfree(rec); + return NULL; } - //Internal LZW variables +//Internal LZW variables #define LZWSIZE 16384 //Watch out for shorts! static char *lzwbuf1, *lzwbuf4, *lzwbuf5, lzwbuflock[5]; static short *lzwbuf2, *lzwbuf3; @@ -1031,269 +1031,269 @@ static long lzwuncompress(char *lzwinbuf, long compleng, char *lzwoutbuf); int kdfread(void *buffer, bsize_t dasizeof, bsize_t count, long fil) { - unsigned long i, j, k, kgoal; - short leng; - char *ptr; + unsigned long i, j, k, kgoal; + short leng; + char *ptr; - lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; - if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); - if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); - if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); - if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); - if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; + if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); + if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); + if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); + if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); + if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); - if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } - ptr = (char *)buffer; +if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } + ptr = (char *)buffer; - if (kread(fil,&leng,2) != 2) return -1; leng = B_LITTLE16(leng); - if (kread(fil,lzwbuf5,(long)leng) != leng) return -1; - k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); + if (kread(fil,&leng,2) != 2) return -1; leng = B_LITTLE16(leng); + if (kread(fil,lzwbuf5,(long)leng) != leng) return -1; + k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); - copybufbyte(lzwbuf4,ptr,(long)dasizeof); - k += (long)dasizeof; + copybufbyte(lzwbuf4,ptr,(long)dasizeof); + k += (long)dasizeof; - for(i=1;i= kgoal) - { - if (kread(fil,&leng,2) != 2) return -1; leng = B_LITTLE16(leng); - if (kread(fil,lzwbuf5,(long)leng) != leng) return -1; - k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); - } - for(j=0;j= kgoal) + { + if (kread(fil,&leng,2) != 2) return -1; leng = B_LITTLE16(leng); + if (kread(fil,lzwbuf5,(long)leng) != leng) return -1; + k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); + } + for(j=0;j>4),&lzwbuflock[0]); - if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); - if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); - if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); - if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; + if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); + if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); + if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); + if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); + if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); - if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } - ptr = (char *)buffer; +if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } + ptr = (char *)buffer; - if (Bfread(&leng,2,1,fil) != 1) return -1; leng = B_LITTLE16(leng); - if (Bfread(lzwbuf5,(long)leng,1,fil) != 1) return -1; - k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); + if (Bfread(&leng,2,1,fil) != 1) return -1; leng = B_LITTLE16(leng); + if (Bfread(lzwbuf5,(long)leng,1,fil) != 1) return -1; + k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); - copybufbyte(lzwbuf4,ptr,(long)dasizeof); - k += (long)dasizeof; + copybufbyte(lzwbuf4,ptr,(long)dasizeof); + k += (long)dasizeof; - for(i=1;i= kgoal) - { - if (Bfread(&leng,2,1,fil) != 1) return -1; leng = B_LITTLE16(leng); - if (Bfread(lzwbuf5,(long)leng,1,fil) != 1) return -1; - k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); - } - for(j=0;j= kgoal) + { + if (Bfread(&leng,2,1,fil) != 1) return -1; leng = B_LITTLE16(leng); + if (Bfread(lzwbuf5,(long)leng,1,fil) != 1) return -1; + k = 0; kgoal = lzwuncompress(lzwbuf5,(long)leng,lzwbuf4); + } + for(j=0;j>4),&lzwbuflock[0]); - if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); - if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); - if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); - if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); - - if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } - ptr = (char *)buffer; - - copybufbyte(ptr,lzwbuf4,(long)dasizeof); - k = dasizeof; - - if (k > LZWSIZE-dasizeof) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); - Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); - } - - for(i=1;i LZWSIZE-dasizeof) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); - Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); - } - ptr += dasizeof; - } - if (k > 0) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); swleng = B_LITTLE16(leng); - Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); - } - lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1; + unsigned long i, j, k; + short leng, swleng; + char *ptr; + + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; + if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); + if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); + if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); + if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); + if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); + +if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } + ptr = (char *)buffer; + + copybufbyte(ptr,lzwbuf4,(long)dasizeof); + k = dasizeof; + + if (k > LZWSIZE-dasizeof) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); + Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); + } + + for(i=1;i LZWSIZE-dasizeof) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); + Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); + } + ptr += dasizeof; + } + if (k > 0) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); swleng = B_LITTLE16(leng); + Bwrite(fil,&swleng,2); Bwrite(fil,lzwbuf5,(long)leng); + } + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1; } void dfwrite(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil) { - unsigned long i, j, k; - short leng, swleng; - char *ptr; + unsigned long i, j, k; + short leng, swleng; + char *ptr; - lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; - if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); - if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); - if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); - if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); - if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200; + if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]); + if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]); + if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]); + if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]); + if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]); - if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } - ptr = (char *)buffer; +if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; } + ptr = (char *)buffer; - copybufbyte(ptr,lzwbuf4,(long)dasizeof); - k = dasizeof; + copybufbyte(ptr,lzwbuf4,(long)dasizeof); + k = dasizeof; - if (k > LZWSIZE-dasizeof) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); - Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); - } + if (k > LZWSIZE-dasizeof) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); + Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); + } - for(i=1;i LZWSIZE-dasizeof) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); - Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); - } - ptr += dasizeof; - } - if (k > 0) - { - leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); swleng = B_LITTLE16(leng); - Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); - } - lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1; + for(i=1;i LZWSIZE-dasizeof) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); k = 0; swleng = B_LITTLE16(leng); + Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); + } + ptr += dasizeof; + } + if (k > 0) + { + leng = (short)lzwcompress(lzwbuf4,k,lzwbuf5); swleng = B_LITTLE16(leng); + Bfwrite(&swleng,2,1,fil); Bfwrite(lzwbuf5,(long)leng,1,fil); + } + lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1; } static long lzwcompress(char *lzwinbuf, long uncompleng, char *lzwoutbuf) { - long i, addr, newaddr, addrcnt, zx, *intptr; - long bytecnt1, bitcnt, numbits, oneupnumbits; - short *shortptr; + long i, addr, newaddr, addrcnt, zx, *intptr; + long bytecnt1, bitcnt, numbits, oneupnumbits; + short *shortptr; - for(i=255;i>=0;i--) { lzwbuf1[i] = i; lzwbuf3[i] = (i+1)&255; } - clearbuf(lzwbuf2,256>>1,0xffffffff); - clearbuf(lzwoutbuf,((uncompleng+15)+3)>>2,0L); + for(i=255;i>=0;i--) { lzwbuf1[i] = i; lzwbuf3[i] = (i+1)&255; } + clearbuf(lzwbuf2,256>>1,0xffffffff); + clearbuf(lzwoutbuf,((uncompleng+15)+3)>>2,0L); - addrcnt = 256; bytecnt1 = 0; bitcnt = (4<<3); - numbits = 8; oneupnumbits = (1<<8); - do - { - addr = lzwinbuf[bytecnt1]; - do - { - bytecnt1++; - if (bytecnt1 == uncompleng) break; - if (lzwbuf2[addr] < 0) {lzwbuf2[addr] = addrcnt; break;} - newaddr = lzwbuf2[addr]; - while (lzwbuf1[newaddr] != lzwinbuf[bytecnt1]) - { - zx = lzwbuf3[newaddr]; - if (zx < 0) {lzwbuf3[newaddr] = addrcnt; break;} - newaddr = zx; - } - if (lzwbuf3[newaddr] == addrcnt) break; - addr = newaddr; - } while (addr >= 0); - lzwbuf1[addrcnt] = lzwinbuf[bytecnt1]; - lzwbuf2[addrcnt] = -1; - lzwbuf3[addrcnt] = -1; + addrcnt = 256; bytecnt1 = 0; bitcnt = (4<<3); + numbits = 8; oneupnumbits = (1<<8); + do + { + addr = lzwinbuf[bytecnt1]; + do + { + bytecnt1++; + if (bytecnt1 == uncompleng) break; + if (lzwbuf2[addr] < 0) {lzwbuf2[addr] = addrcnt; break;} + newaddr = lzwbuf2[addr]; + while (lzwbuf1[newaddr] != lzwinbuf[bytecnt1]) + { + zx = lzwbuf3[newaddr]; + if (zx < 0) {lzwbuf3[newaddr] = addrcnt; break;} + newaddr = zx; + } + if (lzwbuf3[newaddr] == addrcnt) break; + addr = newaddr; + } while (addr >= 0); + lzwbuf1[addrcnt] = lzwinbuf[bytecnt1]; + lzwbuf2[addrcnt] = -1; + lzwbuf3[addrcnt] = -1; - intptr = (long *)&lzwoutbuf[bitcnt>>3]; - intptr[0] |= B_LITTLE32(addr<<(bitcnt&7)); - bitcnt += numbits; - if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1))) - bitcnt--; + intptr = (long *)&lzwoutbuf[bitcnt>>3]; + intptr[0] |= B_LITTLE32(addr<<(bitcnt&7)); + bitcnt += numbits; + if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1))) + bitcnt--; - addrcnt++; - if (addrcnt > oneupnumbits) { numbits++; oneupnumbits <<= 1; } - } while ((bytecnt1 < uncompleng) && (bitcnt < (uncompleng<<3))); + addrcnt++; + if (addrcnt > oneupnumbits) { numbits++; oneupnumbits <<= 1; } + } while ((bytecnt1 < uncompleng) && (bitcnt < (uncompleng<<3))); - intptr = (long *)&lzwoutbuf[bitcnt>>3]; - intptr[0] |= B_LITTLE32(addr<<(bitcnt&7)); - bitcnt += numbits; - if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1))) - bitcnt--; + intptr = (long *)&lzwoutbuf[bitcnt>>3]; + intptr[0] |= B_LITTLE32(addr<<(bitcnt&7)); + bitcnt += numbits; + if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1))) + bitcnt--; - shortptr = (short *)lzwoutbuf; - shortptr[0] = B_LITTLE16((short)uncompleng); - if (((bitcnt+7)>>3) < uncompleng) - { - shortptr[1] = B_LITTLE16((short)addrcnt); - return((bitcnt+7)>>3); - } - shortptr[1] = (short)0; - for(i=0;i>3) < uncompleng) + { + shortptr[1] = B_LITTLE16((short)addrcnt); + return((bitcnt+7)>>3); + } + shortptr[1] = (short)0; + for(i=0;i>2); - return((long)B_LITTLE16(shortptr[0])); //uncompleng - } - for(i=255;i>=0;i--) { lzwbuf2[i] = i; lzwbuf3[i] = i; } - currstr = 256; bitcnt = (4<<3); outbytecnt = 0; - numbits = 8; oneupnumbits = (1<<8); - do - { - intptr = (long *)&lzwinbuf[bitcnt>>3]; - dat = ((B_LITTLE32(intptr[0])>>(bitcnt&7)) & (oneupnumbits-1)); - bitcnt += numbits; - if ((dat&((oneupnumbits>>1)-1)) > ((currstr-1)&((oneupnumbits>>1)-1))) - { dat &= ((oneupnumbits>>1)-1); bitcnt--; } + shortptr = (short *)lzwinbuf; + strtot = (long)B_LITTLE16(shortptr[1]); + if (strtot == 0) + { + copybuf(lzwinbuf+4,lzwoutbuf,((compleng-4)+3)>>2); + return((long)B_LITTLE16(shortptr[0])); //uncompleng + } + for(i=255;i>=0;i--) { lzwbuf2[i] = i; lzwbuf3[i] = i; } + currstr = 256; bitcnt = (4<<3); outbytecnt = 0; + numbits = 8; oneupnumbits = (1<<8); + do + { + intptr = (long *)&lzwinbuf[bitcnt>>3]; + dat = ((B_LITTLE32(intptr[0])>>(bitcnt&7)) & (oneupnumbits-1)); + bitcnt += numbits; + if ((dat&((oneupnumbits>>1)-1)) > ((currstr-1)&((oneupnumbits>>1)-1))) + { dat &= ((oneupnumbits>>1)-1); bitcnt--; } - lzwbuf3[currstr] = dat; + lzwbuf3[currstr] = dat; - for(leng=0;dat>=256;leng++,dat=lzwbuf3[dat]) - lzwbuf1[leng] = lzwbuf2[dat]; + for(leng=0;dat>=256;leng++,dat=lzwbuf3[dat]) + lzwbuf1[leng] = lzwbuf2[dat]; - lzwoutbuf[outbytecnt++] = dat; - for(i=leng-1;i>=0;i--) lzwoutbuf[outbytecnt++] = lzwbuf1[i]; + lzwoutbuf[outbytecnt++] = dat; + for(i=leng-1;i>=0;i--) lzwoutbuf[outbytecnt++] = lzwbuf1[i]; - lzwbuf2[currstr-1] = dat; lzwbuf2[currstr] = dat; - currstr++; - if (currstr > oneupnumbits) { numbits++; oneupnumbits <<= 1; } - } while (currstr < strtot); - return((long)B_LITTLE16(shortptr[0])); //uncompleng + lzwbuf2[currstr-1] = dat; lzwbuf2[currstr] = dat; + currstr++; + if (currstr > oneupnumbits) { numbits++; oneupnumbits <<= 1; } + } while (currstr < strtot); + return((long)B_LITTLE16(shortptr[0])); //uncompleng } /* diff --git a/polymer/build/src/compat.c b/polymer/build/src/compat.c index 5f8f5adf3..c45d7066b 100644 --- a/polymer/build/src/compat.c +++ b/polymer/build/src/compat.c @@ -41,278 +41,278 @@ int Brand(void) { - return rand(); + return rand(); } void *Bmalloc(bsize_t size) { - return malloc(size); + return malloc(size); } void Bfree(void *ptr) { - free(ptr); + free(ptr); } int Bopen(const char *pathname, int flags, unsigned mode) { - int n=0,o=0; - - if (flags&BO_BINARY) n|=O_BINARY; else n|=O_TEXT; - if ((flags&BO_RDWR)==BO_RDWR) n|=O_RDWR; - else if ((flags&BO_RDWR)==BO_WRONLY) n|=O_WRONLY; - else if ((flags&BO_RDWR)==BO_RDONLY) n|=O_RDONLY; - if (flags&BO_APPEND) n|=O_APPEND; - if (flags&BO_CREAT) n|=O_CREAT; - if (flags&BO_TRUNC) n|=O_TRUNC; - if (mode&BS_IREAD) o|=S_IREAD; - if (mode&BS_IWRITE) o|=S_IWRITE; - if (mode&BS_IEXEC) o|=S_IEXEC; - - return open(pathname,n,o); + int n=0,o=0; + + if (flags&BO_BINARY) n|=O_BINARY; else n|=O_TEXT; + if ((flags&BO_RDWR)==BO_RDWR) n|=O_RDWR; + else if ((flags&BO_RDWR)==BO_WRONLY) n|=O_WRONLY; + else if ((flags&BO_RDWR)==BO_RDONLY) n|=O_RDONLY; + if (flags&BO_APPEND) n|=O_APPEND; + if (flags&BO_CREAT) n|=O_CREAT; + if (flags&BO_TRUNC) n|=O_TRUNC; + if (mode&BS_IREAD) o|=S_IREAD; + if (mode&BS_IWRITE) o|=S_IWRITE; + if (mode&BS_IEXEC) o|=S_IEXEC; + + return open(pathname,n,o); } int Bclose(int fd) { - return close(fd); + return close(fd); } bssize_t Bwrite(int fd, const void *buf, bsize_t count) { - return write(fd,buf,count); + return write(fd,buf,count); } bssize_t Bread(int fd, void *buf, bsize_t count) { - return read(fd,buf,count); + return read(fd,buf,count); } int Blseek(int fildes, int offset, int whence) { - switch (whence) { - case BSEEK_SET: whence=SEEK_SET; break; - case BSEEK_CUR: whence=SEEK_CUR; break; - case BSEEK_END: whence=SEEK_END; break; - } - return lseek(fildes,offset,whence); + switch (whence) { + case BSEEK_SET: whence=SEEK_SET; break; + case BSEEK_CUR: whence=SEEK_CUR; break; + case BSEEK_END: whence=SEEK_END; break; + } + return lseek(fildes,offset,whence); } BFILE *Bfopen(const char *path, const char *mode) { - return (BFILE*)fopen(path,mode); + return (BFILE*)fopen(path,mode); } int Bfclose(BFILE *stream) { - return fclose((FILE*)stream); + return fclose((FILE*)stream); } void Brewind(BFILE *stream) { - rewind((FILE*)stream); + rewind((FILE*)stream); } int Bfgetc(BFILE *stream) { - return fgetc((FILE*)stream); + return fgetc((FILE*)stream); } char *Bfgets(char *s, int size, BFILE *stream) { - return fgets(s,size,(FILE*)stream); + return fgets(s,size,(FILE*)stream); } int Bfputc(int c, BFILE *stream) { - return fputc(c,(FILE*)stream); + return fputc(c,(FILE*)stream); } int Bfputs(const char *s, BFILE *stream) { - return fputs(s,(FILE*)stream); + return fputs(s,(FILE*)stream); } bsize_t Bfread(void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream) { - return fread(ptr,size,nmemb,(FILE*)stream); + return fread(ptr,size,nmemb,(FILE*)stream); } bsize_t Bfwrite(const void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream) { - return fwrite(ptr,size,nmemb,(FILE*)stream); + return fwrite(ptr,size,nmemb,(FILE*)stream); } char *Bstrdup(const char *s) { - return strdup(s); + return strdup(s); } char *Bstrcpy(char *dest, const char *src) { - return strcpy(dest,src); + return strcpy(dest,src); } char *Bstrncpy(char *dest, const char *src, bsize_t n) { - return strncpy(dest,src,n); + return strncpy(dest,src,n); } int Bstrcmp(const char *s1, const char *s2) { - return strcmp(s1,s2); + return strcmp(s1,s2); } int Bstrncmp(const char *s1, const char *s2, bsize_t n) { - return strncmp(s1,s2,n); + return strncmp(s1,s2,n); } int Bstrcasecmp(const char *s1, const char *s2) { #ifdef _MSC_VER - return stricmp(s1,s2); + return stricmp(s1,s2); #else - return strcasecmp(s1,s2); + return strcasecmp(s1,s2); #endif } int Bstrncasecmp(const char *s1, const char *s2, bsize_t n) { #ifdef _MSC_VER - return strnicmp(s1,s2,n); + return strnicmp(s1,s2,n); #else - return strncasecmp(s1,s2,n); + return strncasecmp(s1,s2,n); #endif } char *Bstrcat(char *dest, const char *src) { - return strcat(dest,src); + return strcat(dest,src); } char *Bstrncat(char *dest, const char *src, bsize_t n) { - return strncat(dest,src,n); + return strncat(dest,src,n); } bsize_t Bstrlen(const char *s) { - return strlen(s); + return strlen(s); } char *Bstrchr(const char *s, int c) { - return strchr(s,c); + return strchr(s,c); } char *Bstrrchr(const char *s, int c) { - return strrchr(s,c); + return strrchr(s,c); } int Batoi(const char *nptr) { - return atoi(nptr); + return atoi(nptr); } long Batol(const char *nptr) { - return atol(nptr); + return atol(nptr); } long int Bstrtol(const char *nptr, char **endptr, int base) { - return strtol(nptr,endptr,base); + return strtol(nptr,endptr,base); } unsigned long int Bstrtoul(const char *nptr, char **endptr, int base) { - return strtoul(nptr,endptr,base); + return strtoul(nptr,endptr,base); } void *Bmemcpy(void *dest, const void *src, bsize_t n) { - return memcpy(dest,src,n); + return memcpy(dest,src,n); } void *Bmemmove(void *dest, const void *src, bsize_t n) { - return memmove(dest,src,n); + return memmove(dest,src,n); } void *Bmemchr(const void *s, int c, bsize_t n) { - return memchr(s,c,n); + return memchr(s,c,n); } void *Bmemset(void *s, int c, bsize_t n) { - return memset(s,c,n); + return memset(s,c,n); } int Bprintf(const char *format, ...) { - va_list ap; - int r; + va_list ap; + int r; - va_start(ap,format); + va_start(ap,format); #ifdef _MSC_VER - r = _vprintf(format,ap); + r = _vprintf(format,ap); #else - r = vprintf(format,ap); + r = vprintf(format,ap); #endif - va_end(ap); - return r; + va_end(ap); + return r; } int Bsprintf(char *str, const char *format, ...) { - va_list ap; - int r; + va_list ap; + int r; - va_start(ap,format); + va_start(ap,format); #ifdef _MSC_VER - r = _vsprintf(str,format,ap); + r = _vsprintf(str,format,ap); #else - r = vsprintf(str,format,ap); + r = vsprintf(str,format,ap); #endif - va_end(ap); - return r; + va_end(ap); + return r; } int Bsnprintf(char *str, bsize_t size, const char *format, ...) { - va_list ap; - int r; + va_list ap; + int r; - va_start(ap,format); + va_start(ap,format); #ifdef _MSC_VER - r = _vsnprintf(str,size,format,ap); + r = _vsnprintf(str,size,format,ap); #else - r = vsnprintf(str,size,format,ap); + r = vsnprintf(str,size,format,ap); #endif - va_end(ap); - return r; + va_end(ap); + return r; } int Bvsnprintf(char *str, bsize_t size, const char *format, va_list ap) { #ifdef _MSC_VER - return _vsnprintf(str,size,format,ap); + return _vsnprintf(str,size,format,ap); #else - return vsnprintf(str,size,format,ap); + return vsnprintf(str,size,format,ap); #endif } char *Bgetenv(const char *name) { - return getenv(name); + return getenv(name); } char *Bgetcwd(char *buf, bsize_t size) { - return getcwd(buf,size); + return getcwd(buf,size); } #endif // __compat_h_macrodef__ @@ -325,359 +325,359 @@ char *Bgetcwd(char *buf, bsize_t size) char *Bgethomedir(void) { #ifdef _WIN32 - TCHAR appdata[MAX_PATH]; + TCHAR appdata[MAX_PATH]; -//# if defined SHGetFolderPath -// if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, appdata))) -//# if defined SHGetSpecialFolderPath - if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE))) -//# else -//# error Cannot find SHGetFolderPath or SHGetSpecialFolderPath. Perhaps your shlobj.h is ancient? -//# endif - return strdup(appdata); - return NULL; + //# if defined SHGetFolderPath + // if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, appdata))) + //# if defined SHGetSpecialFolderPath + if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE))) + //# else + //# error Cannot find SHGetFolderPath or SHGetSpecialFolderPath. Perhaps your shlobj.h is ancient? + //# endif + return strdup(appdata); + return NULL; #else - char *e = getenv("HOME"); - if (!e) return NULL; - return strdup(e); + char *e = getenv("HOME"); + if (!e) return NULL; + return strdup(e); #endif } int Bcorrectfilename(char *filename, int removefn) { - char *fn; - char *tokarr[64], *first, *next, *token; - int i, ntok = 0, leadslash = 0, trailslash = 0; - - fn = strdup(filename); - if (!fn) return -1; - - for (first=fn; *first; first++) { + char *fn; + char *tokarr[64], *first, *next, *token; + int i, ntok = 0, leadslash = 0, trailslash = 0; + + fn = strdup(filename); + if (!fn) return -1; + + for (first=fn; *first; first++) { #ifdef _WIN32 - if (*first == '\\') *first = '/'; + if (*first == '\\') *first = '/'; #endif - } - leadslash = (*fn == '/'); - trailslash = (first>fn && first[-1] == '/'); - - first = fn; - do { - token = Bstrtoken(first, "/", &next, 1); - first = NULL; - if (!token) break; - else if (token[0] == 0) continue; - else if (token[0] == '.' && token[1] == 0) continue; - else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1); - else tokarr[ntok++] = token; - } while (1); - - if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; } - if (ntok == 0 && trailslash && leadslash) trailslash = 0; - - first = filename; - if (leadslash) *(first++) = '/'; - for (i=0; i0) *(first++) = '/'; - for (token=tokarr[i]; *token; token++) - *(first++) = *token; - } - if (trailslash) *(first++) = '/'; - *(first++) = 0; + } + leadslash = (*fn == '/'); + trailslash = (first>fn && first[-1] == '/'); + + first = fn; + do { + token = Bstrtoken(first, "/", &next, 1); + first = NULL; + if (!token) break; + else if (token[0] == 0) continue; + else if (token[0] == '.' && token[1] == 0) continue; + else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1); + else tokarr[ntok++] = token; + } while (1); + +if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; } + if (ntok == 0 && trailslash && leadslash) trailslash = 0; + + first = filename; + if (leadslash) *(first++) = '/'; + for (i=0; i0) *(first++) = '/'; + for (token=tokarr[i]; *token; token++) + *(first++) = *token; + } + if (trailslash) *(first++) = '/'; + *(first++) = 0; Bfree(fn); - return 0; + return 0; } int Bcanonicalisefilename(char *filename, int removefn) { - char cwd[BMAX_PATH], fn[BMAX_PATH], *p; - char *fnp = filename; + char cwd[BMAX_PATH], fn[BMAX_PATH], *p; + char *fnp = filename; #ifdef _WIN32 - int drv = 0; + int drv = 0; #endif - + #ifdef _WIN32 - { - if (filename[0] && filename[1] == ':') { - // filename is prefixed with a drive - drv = toupper(filename[0])-'A' + 1; - fnp += 2; - } - if (!_getdcwd(drv, cwd, sizeof(cwd))) return -1; - for (p=cwd; *p; p++) if (*p == '\\') *p = '/'; - } + { + if (filename[0] && filename[1] == ':') { + // filename is prefixed with a drive + drv = toupper(filename[0])-'A' + 1; + fnp += 2; + } + if (!_getdcwd(drv, cwd, sizeof(cwd))) return -1; + for (p=cwd; *p; p++) if (*p == '\\') *p = '/'; + } #else - if (!getcwd(cwd,sizeof(cwd))) return -1; + if (!getcwd(cwd,sizeof(cwd))) return -1; #endif - p = strrchr(cwd,'/'); if (!p || p[1]) strcat(cwd, "/"); - - strcpy(fn, fnp); + p = strrchr(cwd,'/'); if (!p || p[1]) strcat(cwd, "/"); + + strcpy(fn, fnp); #ifdef _WIN32 - for (p=fn; *p; p++) if (*p == '\\') *p = '/'; + for (p=fn; *p; p++) if (*p == '\\') *p = '/'; #endif - - if (fn[0] != '/') { - // we are dealing with a path relative to the current directory - strcpy(filename, cwd); - strcat(filename, fn); - } else { + + if (fn[0] != '/') { + // we are dealing with a path relative to the current directory + strcpy(filename, cwd); + strcat(filename, fn); + } else { #ifdef _WIN32 - filename[0] = cwd[0]; - filename[1] = ':'; - filename[2] = 0; + filename[0] = cwd[0]; + filename[1] = ':'; + filename[2] = 0; #else - filename[0] = 0; + filename[0] = 0; #endif - strcat(filename, fn); - } - fnp = filename; + strcat(filename, fn); + } + fnp = filename; #ifdef _WIN32 - fnp += 2; // skip the drive + fnp += 2; // skip the drive #endif - - return Bcorrectfilename(fnp,1); + + return Bcorrectfilename(fnp,1); } char *Bgetsystemdrives(void) { #ifdef _WIN32 - char *str, *p; - DWORD drv, mask; - int number=0; - - drv = GetLogicalDrives(); - if (drv == 0) return NULL; + char *str, *p; + DWORD drv, mask; + int number=0; - for (mask=1; mask<0x8000000l; mask<<=1) { - if ((drv&mask) == 0) continue; - number++; - } + drv = GetLogicalDrives(); + if (drv == 0) return NULL; - str = p = (char *)malloc(1 + (3*number)); - if (!str) return NULL; + for (mask=1; mask<0x8000000l; mask<<=1) { + if ((drv&mask) == 0) continue; + number++; + } - number = 0; - for (mask=1; mask<0x8000000l; mask<<=1, number++) { - if ((drv&mask) == 0) continue; - *(p++) = 'A' + number; - *(p++) = ':'; - *(p++) = 0; - } - *(p++) = 0; + str = p = (char *)malloc(1 + (3*number)); + if (!str) return NULL; - return str; + number = 0; + for (mask=1; mask<0x8000000l; mask<<=1, number++) { + if ((drv&mask) == 0) continue; + *(p++) = 'A' + number; + *(p++) = ':'; + *(p++) = 0; + } + *(p++) = 0; + + return str; #else - // Perhaps have Unix OS's put /, /home/user, and /mnt/* in the "drives" list? - return NULL; + // Perhaps have Unix OS's put /, /home/user, and /mnt/* in the "drives" list? + return NULL; #endif } long Bfilelength(int fd) { - struct stat st; - if (fstat(fd, &st) < 0) return -1; - return(long)(st.st_size); + struct stat st; + if (fstat(fd, &st) < 0) return -1; + return(long)(st.st_size); } typedef struct { #ifdef _MSC_VER - long dir; - struct _finddata_t fid; + long dir; + struct _finddata_t fid; #else - DIR *dir; + DIR *dir; #endif - struct Bdirent info; - int status; - char name[1]; + struct Bdirent info; + int status; + char name[1]; } BDIR_real; BDIR* Bopendir(const char *name) { - BDIR_real *dirr; + BDIR_real *dirr; #ifdef _MSC_VER - char *t,*tt; - t = (char*)malloc(strlen(name)+1+4); - if (!t) return NULL; + char *t,*tt; + t = (char*)malloc(strlen(name)+1+4); + if (!t) return NULL; #endif - dirr = (BDIR_real*)malloc(sizeof(BDIR_real) + strlen(name)); - if (!dirr) { + dirr = (BDIR_real*)malloc(sizeof(BDIR_real) + strlen(name)); + if (!dirr) { #ifdef _MSC_VER - free(t); + free(t); #endif - return NULL; - } + return NULL; + } #ifdef _MSC_VER - strcpy(t,name); - tt = t+strlen(name)-1; - while (*tt == ' ' && tt>t) tt--; - if (*tt != '/' && *tt != '\\') *(++tt) = '/'; - *(++tt) = '*'; - *(++tt) = '.'; - *(++tt) = '*'; - *(++tt) = 0; - - dirr->dir = _findfirst(t,&dirr->fid); - free(t); - if (dirr->dir == -1) { - free(dirr); - return NULL; - } + strcpy(t,name); + tt = t+strlen(name)-1; + while (*tt == ' ' && tt>t) tt--; + if (*tt != '/' && *tt != '\\') *(++tt) = '/'; + *(++tt) = '*'; + *(++tt) = '.'; + *(++tt) = '*'; + *(++tt) = 0; + + dirr->dir = _findfirst(t,&dirr->fid); + free(t); + if (dirr->dir == -1) { + free(dirr); + return NULL; + } #else - dirr->dir = opendir(name); - if (dirr->dir == NULL) { - free(dirr); - return NULL; - } + dirr->dir = opendir(name); + if (dirr->dir == NULL) { + free(dirr); + return NULL; + } #endif - dirr->status = 0; - strcpy(dirr->name, name); - - return (BDIR*)dirr; + dirr->status = 0; + strcpy(dirr->name, name); + + return (BDIR*)dirr; } struct Bdirent* Breaddir(BDIR *dir) { - BDIR_real *dirr = (BDIR_real*)dir; - struct dirent *de; - struct stat st; - char *fn; + BDIR_real *dirr = (BDIR_real*)dir; + struct dirent *de; + struct stat st; + char *fn; #ifdef _MSC_VER - if (dirr->status > 0) { - if (_findnext(dirr->dir,&dirr->fid) != 0) { - dirr->status = -1; - return NULL; - } - } - dirr->info.namlen = strlen(dirr->fid.name); - dirr->info.name = dirr->fid.name; - dirr->status++; + if (dirr->status > 0) { + if (_findnext(dirr->dir,&dirr->fid) != 0) { + dirr->status = -1; + return NULL; + } + } + dirr->info.namlen = strlen(dirr->fid.name); + dirr->info.name = dirr->fid.name; + dirr->status++; #else - de = readdir(dirr->dir); - if (de == NULL) { - dirr->status = -1; - return NULL; - } else { - dirr->status++; - } -//# if defined(__WATCOMC__) || defined(__linux) || defined(__BEOS__) || defined(__QNX__) || defined(SKYOS) - dirr->info.namlen = strlen(de->d_name); -//# else -// dirr->info.namlen = de->d_namlen; -//# endif - dirr->info.name = de->d_name; + de = readdir(dirr->dir); + if (de == NULL) { + dirr->status = -1; + return NULL; + } else { + dirr->status++; + } + //# if defined(__WATCOMC__) || defined(__linux) || defined(__BEOS__) || defined(__QNX__) || defined(SKYOS) + dirr->info.namlen = strlen(de->d_name); + //# else + // dirr->info.namlen = de->d_namlen; + //# endif + dirr->info.name = de->d_name; #endif - dirr->info.mode = 0; - dirr->info.size = 0; - dirr->info.mtime = 0; + dirr->info.mode = 0; + dirr->info.size = 0; + dirr->info.mtime = 0; - fn = (char *)malloc(strlen(dirr->name) + 1 + dirr->info.namlen + 1); - if (fn) { - sprintf(fn,"%s/%s",dirr->name,dirr->info.name); - if (!stat(fn, &st)) { - dirr->info.mode = st.st_mode; - dirr->info.size = st.st_size; - dirr->info.mtime = st.st_mtime; - } - free(fn); - } + fn = (char *)malloc(strlen(dirr->name) + 1 + dirr->info.namlen + 1); + if (fn) { + sprintf(fn,"%s/%s",dirr->name,dirr->info.name); + if (!stat(fn, &st)) { + dirr->info.mode = st.st_mode; + dirr->info.size = st.st_size; + dirr->info.mtime = st.st_mtime; + } + free(fn); + } - return &dirr->info; + return &dirr->info; } int Bclosedir(BDIR *dir) { - BDIR_real *dirr = (BDIR_real*)dir; - -#ifdef _MSC_VER - _findclose(dirr->dir); -#else - closedir(dirr->dir); -#endif - free(dirr); + BDIR_real *dirr = (BDIR_real*)dir; - return 0; +#ifdef _MSC_VER + _findclose(dirr->dir); +#else + closedir(dirr->dir); +#endif + free(dirr); + + return 0; } char *Bstrtoken(char *s, char *delim, char **ptrptr, int chop) { - char *p, *start; + char *p, *start; - if (!ptrptr) return NULL; - - if (s) p = s; - else p = *ptrptr; + if (!ptrptr) return NULL; - if (!p) return NULL; + if (s) p = s; + else p = *ptrptr; - while (*p != 0 && strchr(delim, *p)) p++; - if (*p == 0) { - *ptrptr = NULL; - return NULL; - } - start = p; - while (*p != 0 && !strchr(delim, *p)) p++; - if (*p == 0) *ptrptr = NULL; - else { - if (chop) *(p++) = 0; - *ptrptr = p; - } + if (!p) return NULL; - return start; + while (*p != 0 && strchr(delim, *p)) p++; + if (*p == 0) { + *ptrptr = NULL; + return NULL; + } + start = p; + while (*p != 0 && !strchr(delim, *p)) p++; + if (*p == 0) *ptrptr = NULL; + else { + if (chop) *(p++) = 0; + *ptrptr = p; + } + + return start; } - //Brute-force case-insensitive, slash-insensitive, * and ? wildcard matcher - //Given: string i and string j. string j can have wildcards - //Returns: 1:matches, 0:doesn't match +//Brute-force case-insensitive, slash-insensitive, * and ? wildcard matcher +//Given: string i and string j. string j can have wildcards +//Returns: 1:matches, 0:doesn't match long Bwildmatch (const char *i, const char *j) { - const char *k; - char c0, c1; + const char *k; + char c0, c1; - if (!*j) return(1); - do - { - if (*j == '*') - { - for(k=i,j++;*k;k++) if (Bwildmatch(k,j)) return(1); - continue; - } - if (!*i) return(0); - if (*j == '?') { i++; j++; continue; } - c0 = *i; if ((c0 >= 'a') && (c0 <= 'z')) c0 -= 32; - c1 = *j; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32; + if (!*j) return(1); + do + { + if (*j == '*') + { + for(k=i,j++;*k;k++) if (Bwildmatch(k,j)) return(1); + continue; + } + if (!*i) return(0); + if (*j == '?') { i++; j++; continue; } + c0 = *i; if ((c0 >= 'a') && (c0 <= 'z')) c0 -= 32; + c1 = *j; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32; #ifdef _WIN32 - if (c0 == '/') c0 = '\\'; - if (c1 == '/') c1 = '\\'; + if (c0 == '/') c0 = '\\'; + if (c1 == '/') c1 = '\\'; #endif - if (c0 != c1) return(0); - i++; j++; - } while (*j); - return(!*i); + if (c0 != c1) return(0); + i++; j++; + } while (*j); + return(!*i); } #if !defined(_WIN32) char *Bstrlwr(char *s) { - char *t = s; - if (!s) return s; - while (*t) { *t = Btolower(*t); t++; } - return s; + char *t = s; + if (!s) return s; +while (*t) { *t = Btolower(*t); t++; } + return s; } char *Bstrupr(char *s) { - char *t = s; - if (!s) return s; - while (*t) { *t = Btoupper(*t); t++; } - return s; + char *t = s; + if (!s) return s; +while (*t) { *t = Btoupper(*t); t++; } + return s; } #endif @@ -688,28 +688,28 @@ char *Bstrupr(char *s) unsigned int Bgetsysmemsize(void) { #ifdef _WIN32 - MEMORYSTATUS memst; - GlobalMemoryStatus(&memst); - return (unsigned int)memst.dwTotalPhys; + MEMORYSTATUS memst; + GlobalMemoryStatus(&memst); + return (unsigned int)memst.dwTotalPhys; #elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES) - unsigned int siz = 0x7fffffff; - long scpagesiz, scphyspages; + unsigned int siz = 0x7fffffff; + long scpagesiz, scphyspages; #ifdef _SC_PAGE_SIZE - scpagesiz = sysconf(_SC_PAGE_SIZE); + scpagesiz = sysconf(_SC_PAGE_SIZE); #else - scpagesiz = sysconf(_SC_PAGESIZE); + scpagesiz = sysconf(_SC_PAGESIZE); #endif - scphyspages = sysconf(_SC_PHYS_PAGES); - if (scpagesiz >= 0 && scphyspages >= 0) - siz = (unsigned int)min(longlong(0x7fffffff), (int64)scpagesiz * (int64)scphyspages); + scphyspages = sysconf(_SC_PHYS_PAGES); + if (scpagesiz >= 0 && scphyspages >= 0) + siz = (unsigned int)min(longlong(0x7fffffff), (int64)scpagesiz * (int64)scphyspages); - //initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n", - // scphyspages, scpagesiz, siz); + //initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n", + // scphyspages, scpagesiz, siz); - return siz; + return siz; #else - return 0x7fffffff; + return 0x7fffffff; #endif } diff --git a/polymer/build/src/config.c b/polymer/build/src/config.c index a56d2898b..b5e727d1f 100644 --- a/polymer/build/src/config.c +++ b/polymer/build/src/config.c @@ -12,45 +12,45 @@ #include "baselayer.h" static long vesares[13][2] = {{320,200},{360,200},{320,240},{360,240},{320,400}, - {360,400},{640,350},{640,400},{640,480},{800,600}, - {1024,768},{1280,1024},{1600,1200}}; + {360,400},{640,350},{640,400},{640,480},{800,600}, + {1024,768},{1280,1024},{1600,1200}}; static int readconfig(BFILE *fp, const char *key, char *value, unsigned len) { - char buf[1000], *k, *v, *eq; - int x=0; + char buf[1000], *k, *v, *eq; + int x=0; - if (len < 1) return 0; + if (len < 1) return 0; - Brewind(fp); + Brewind(fp); - while (1) { - if (!Bfgets(buf, 1000, fp)) return 0; + while (1) { + if (!Bfgets(buf, 1000, fp)) return 0; - if (buf[0] == ';') continue; + if (buf[0] == ';') continue; - eq = Bstrchr(buf, '='); - if (!eq) continue; + eq = Bstrchr(buf, '='); + if (!eq) continue; - k = buf; - v = eq+1; + k = buf; + v = eq+1; - while (*k == ' ' || *k == '\t') k++; - *(eq--) = 0; - while ((*eq == ' ' || *eq == '\t') && eq>=k) *(eq--) = 0; + while (*k == ' ' || *k == '\t') k++; + *(eq--) = 0; + while ((*eq == ' ' || *eq == '\t') && eq>=k) *(eq--) = 0; - if (Bstrcasecmp(k, key)) continue; - - while (*v == ' ' || *k == '\t') v++; - eq = v + Bstrlen(v)-1; + if (Bstrcasecmp(k, key)) continue; - while ((*eq == ' ' || *eq == '\t' || *eq == '\r' || *eq == '\n') && eq>=v) *(eq--) = 0; + while (*v == ' ' || *k == '\t') v++; + eq = v + Bstrlen(v)-1; - value[--len] = 0; - do value[x] = v[x]; while (v[x++] != 0 && len-- > 0); + while ((*eq == ' ' || *eq == '\t' || *eq == '\r' || *eq == '\n') && eq>=v) *(eq--) = 0; - return x-1; - } + value[--len] = 0; + do value[x] = v[x]; while (v[x++] != 0 && len-- > 0); + + return x-1; + } } extern short brightness; @@ -99,35 +99,35 @@ extern double msens; int loadsetup(const char *fn) { - BFILE *fp; + BFILE *fp; #define VL 32 - char val[VL]; - int i; + char val[VL]; + int i; - if ((fp = Bfopen(fn, "rt")) == NULL) return -1; + if ((fp = Bfopen(fn, "rt")) == NULL) return -1; - if (readconfig(fp, "fullscreen", val, VL) > 0) { if (Batoi(val) != 0) fullscreen = 1; else fullscreen = 0; } - if (readconfig(fp, "resolution", val, VL) > 0) { - i = Batoi(val) & 0x0f; - if ((unsigned)i<13) { xdimgame = xdim2d = vesares[i][0]; ydimgame = ydim2d = vesares[i][1]; } - } - if (readconfig(fp, "2dresolution", val, VL) > 0) { - i = Batoi(val) & 0x0f; - if ((unsigned)i<13) { xdim2d = vesares[i][0]; ydim2d = vesares[i][1]; } - } - if (readconfig(fp, "xdim2d", val, VL) > 0) xdim2d = Batoi(val); - if (readconfig(fp, "ydim2d", val, VL) > 0) ydim2d = Batoi(val); - if (readconfig(fp, "xdim3d", val, VL) > 0) xdimgame = Batoi(val); - if (readconfig(fp, "ydim3d", val, VL) > 0) ydimgame = Batoi(val); - if (readconfig(fp, "samplerate", val, VL) > 0) option[7] = (Batoi(val) & 0x0f) << 4; - if (readconfig(fp, "music", val, VL) > 0) { if (Batoi(val) != 0) option[2] = 1; else option[2] = 0; } - if (readconfig(fp, "mouse", val, VL) > 0) { if (Batoi(val) != 0) option[3] = 1; else option[3] = 0; } - if (readconfig(fp, "bpp", val, VL) > 0) bppgame = Batoi(val); - if (readconfig(fp, "renderer", val, VL) > 0) { i = Batoi(val); setrendermode(i); } - if (readconfig(fp, "brightness", val, VL) > 0) brightness = min(max(Batoi(val),0),15); +if (readconfig(fp, "fullscreen", val, VL) > 0) { if (Batoi(val) != 0) fullscreen = 1; else fullscreen = 0; } + if (readconfig(fp, "resolution", val, VL) > 0) { + i = Batoi(val) & 0x0f; + if ((unsigned)i<13) { xdimgame = xdim2d = vesares[i][0]; ydimgame = ydim2d = vesares[i][1]; } + } + if (readconfig(fp, "2dresolution", val, VL) > 0) { + i = Batoi(val) & 0x0f; + if ((unsigned)i<13) { xdim2d = vesares[i][0]; ydim2d = vesares[i][1]; } + } + if (readconfig(fp, "xdim2d", val, VL) > 0) xdim2d = Batoi(val); + if (readconfig(fp, "ydim2d", val, VL) > 0) ydim2d = Batoi(val); + if (readconfig(fp, "xdim3d", val, VL) > 0) xdimgame = Batoi(val); + if (readconfig(fp, "ydim3d", val, VL) > 0) ydimgame = Batoi(val); + if (readconfig(fp, "samplerate", val, VL) > 0) option[7] = (Batoi(val) & 0x0f) << 4; +if (readconfig(fp, "music", val, VL) > 0) { if (Batoi(val) != 0) option[2] = 1; else option[2] = 0; } +if (readconfig(fp, "mouse", val, VL) > 0) { if (Batoi(val) != 0) option[3] = 1; else option[3] = 0; } + if (readconfig(fp, "bpp", val, VL) > 0) bppgame = Batoi(val); +if (readconfig(fp, "renderer", val, VL) > 0) { i = Batoi(val); setrendermode(i); } + if (readconfig(fp, "brightness", val, VL) > 0) brightness = min(max(Batoi(val),0),15); #ifdef RENDERTYPEWIN - if (readconfig(fp, "maxrefreshfreq", val, VL) > 0) maxrefreshfreq = Batoi(val); + if (readconfig(fp, "maxrefreshfreq", val, VL) > 0) maxrefreshfreq = Batoi(val); #endif glusetexcache = glusetexcachecompression = -1; if (readconfig(fp, "glusetexcache", val, VL) > 0) { @@ -142,166 +142,166 @@ int loadsetup(const char *fn) { i=wm_ynbox("Texture caching", "Would you like to enable the on-disk texture cache? " - "This feature may use up to 200 megabytes of disk " - "space if you have a great deal of high resolution " - "textures and skins, but textures will load exponentially " - "faster after the first time they are loaded."); + "This feature may use up to 200 megabytes of disk " + "space if you have a great deal of high resolution " + "textures and skins, but textures will load exponentially " + "faster after the first time they are loaded."); if (i) i = 'y'; if(i == 'y' || i == 'Y' ) glusetexcompr = glusetexcache = glusetexcachecompression = 1; else glusetexcache = glusetexcachecompression = 0; } - option[0] = 1; // vesa all the way... - option[1] = 1; // sound all the way... - option[4] = 0; // no multiplayer - option[5] = 0; + option[0] = 1; // vesa all the way... + option[1] = 1; // sound all the way... + option[4] = 0; // no multiplayer + option[5] = 0; - if (readconfig(fp, "keyforward", val, VL) > 0) keys[0] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keybackward", val, VL) > 0) keys[1] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyturnleft", val, VL) > 0) keys[2] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyturnright", val, VL) > 0) keys[3] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyrun", val, VL) > 0) keys[4] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keystrafe", val, VL) > 0) keys[5] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyfire", val, VL) > 0) keys[6] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyuse", val, VL) > 0) keys[7] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keystandhigh", val, VL) > 0) keys[8] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keystandlow", val, VL) > 0) keys[9] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keylookup", val, VL) > 0) keys[10] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keylookdown", val, VL) > 0) keys[11] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keystrafeleft", val, VL) > 0) keys[12] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keystraferight", val, VL) > 0) keys[13] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "key2dmode", val, VL) > 0) keys[14] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyviewcycle", val, VL) > 0) keys[15] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "key2dzoomin", val, VL) > 0) keys[16] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "key2dzoomout", val, VL) > 0) keys[17] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keychat", val, VL) > 0) keys[18] = Bstrtol(val, NULL, 16); - if (readconfig(fp, "keyconsole", val, VL) > 0) { keys[19] = Bstrtol(val, NULL, 16); OSD_CaptureKey(keys[19]); } + if (readconfig(fp, "keyforward", val, VL) > 0) keys[0] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keybackward", val, VL) > 0) keys[1] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyturnleft", val, VL) > 0) keys[2] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyturnright", val, VL) > 0) keys[3] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyrun", val, VL) > 0) keys[4] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keystrafe", val, VL) > 0) keys[5] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyfire", val, VL) > 0) keys[6] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyuse", val, VL) > 0) keys[7] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keystandhigh", val, VL) > 0) keys[8] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keystandlow", val, VL) > 0) keys[9] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keylookup", val, VL) > 0) keys[10] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keylookdown", val, VL) > 0) keys[11] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keystrafeleft", val, VL) > 0) keys[12] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keystraferight", val, VL) > 0) keys[13] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "key2dmode", val, VL) > 0) keys[14] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keyviewcycle", val, VL) > 0) keys[15] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "key2dzoomin", val, VL) > 0) keys[16] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "key2dzoomout", val, VL) > 0) keys[17] = Bstrtol(val, NULL, 16); + if (readconfig(fp, "keychat", val, VL) > 0) keys[18] = Bstrtol(val, NULL, 16); +if (readconfig(fp, "keyconsole", val, VL) > 0) { keys[19] = Bstrtol(val, NULL, 16); OSD_CaptureKey(keys[19]); } - if (readconfig(fp, "mousesensitivity", val, VL) > 0) msens = Bstrtod(val, NULL); + if (readconfig(fp, "mousesensitivity", val, VL) > 0) msens = Bstrtod(val, NULL); - Bfclose(fp); + Bfclose(fp); - return 0; + return 0; } int writesetup(const char *fn) { - BFILE *fp; + BFILE *fp; - fp = Bfopen(fn,"wt"); - if (!fp) return -1; - - Bfprintf(fp, - "; Video mode selection\n" - "; 0 - Windowed\n" - "; 1 - Fullscreen\n" - "fullscreen = %ld\n" - "\n" - "; Video resolution\n" - "xdim2d = %ld\n" - "ydim2d = %ld\n" - "xdim3d = %ld\n" - "ydim3d = %ld\n" - "\n" - "; 3D-mode colour depth\n" - "bpp = %ld\n" - "\n" - "; OpenGL mode options\n" - "glusetexcache = %ld\n" - "glusetexcachecompression = %ld\n" - "\n" + fp = Bfopen(fn,"wt"); + if (!fp) return -1; + + Bfprintf(fp, + "; Video mode selection\n" + "; 0 - Windowed\n" + "; 1 - Fullscreen\n" + "fullscreen = %ld\n" + "\n" + "; Video resolution\n" + "xdim2d = %ld\n" + "ydim2d = %ld\n" + "xdim3d = %ld\n" + "ydim3d = %ld\n" + "\n" + "; 3D-mode colour depth\n" + "bpp = %ld\n" + "\n" + "; OpenGL mode options\n" + "glusetexcache = %ld\n" + "glusetexcachecompression = %ld\n" + "\n" #ifdef RENDERTYPEWIN - "; Maximum OpenGL mode refresh rate (Windows only, in Hertz)\n" - "maxrefreshfreq = %d\n" - "\n" + "; Maximum OpenGL mode refresh rate (Windows only, in Hertz)\n" + "maxrefreshfreq = %d\n" + "\n" #endif - "; 3D mode brightness setting\n" - "; 0 - lowest\n" - "; 15 - highest\n" - "brightness = %d\n" - "\n" - "; Sound sample frequency\n" - "; 0 - 6 KHz\n" - "; 1 - 8 KHz\n" - "; 2 - 11.025 KHz\n" - "; 3 - 16 KHz\n" - "; 4 - 22.05 KHz\n" - "; 5 - 32 KHz\n" - "; 6 - 44.1 KHz\n" - "samplerate = %d\n" - "\n" - "; Music playback\n" - "; 0 - Off\n" - "; 1 - On\n" - "music = %d\n" - "\n" - "; Enable mouse\n" - "; 0 - No\n" - "; 1 - Yes\n" - "mouse = %d\n" - "\n" - "; Mouse sensitivity\n" - "mousesensitivity = %g\n" - "\n" - "; Key Settings\n" - "; Here's a map of all the keyboard scan codes: NOTE: values are listed in hex!\n" - "; +---------------------------------------------------------------------------------------------+\n" - "; | 01 3B 3C 3D 3E 3F 40 41 42 43 44 57 58 46 |\n" - "; |ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 SCROLL |\n" - "; | |\n" - "; |29 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E D2 C7 C9 45 B5 37 4A |\n" - "; | ` '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' - = BACK INS HOME PGUP NUMLK KP/ KP* KP- |\n" - "; | |\n" - "; | 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 2B D3 CF D1 47 48 49 4E |\n" - "; |TAB Q W E R T Y U I O P [ ] \\ DEL END PGDN KP7 KP8 KP9 KP+ |\n" - "; | |\n" - "; | 3A 1E 1F 20 21 22 23 24 25 26 27 28 1C 4B 4C 4D |\n" - "; |CAPS A S D F G H J K L ; ' ENTER KP4 KP5 KP6 9C |\n" - "; | KPENTER|\n" - "; | 2A 2C 2D 2E 2F 30 31 32 33 34 35 36 C8 4F 50 51 |\n" - "; |LSHIFT Z X C V B N M , . / RSHIFT UP KP1 KP2 KP3 |\n" - "; | |\n" - "; | 1D 38 39 B8 9D CB D0 CD 52 53 |\n" - "; |LCTRL LALT SPACE RALT RCTRL LEFT DOWN RIGHT KP0 KP. |\n" - "; +---------------------------------------------------------------------------------------------+\n" - "\n" - "keyforward = %X\n" - "keybackward = %X\n" - "keyturnleft = %X\n" - "keyturnright = %X\n" - "keyrun = %X\n" - "keystrafe = %X\n" - "keyfire = %X\n" - "keyuse = %X\n" - "keystandhigh = %X\n" - "keystandlow = %X\n" - "keylookup = %X\n" - "keylookdown = %X\n" - "keystrafeleft = %X\n" - "keystraferight = %X\n" - "key2dmode = %X\n" - "keyviewcycle = %X\n" - "key2dzoomin = %X\n" - "key2dzoomout = %X\n" - "keychat = %X\n" - "keyconsole = %X\n" - "\n", - - fullscreen, xdim2d, ydim2d, xdimgame, ydimgame, bppgame, - glusetexcache, glusetexcachecompression, + "; 3D mode brightness setting\n" + "; 0 - lowest\n" + "; 15 - highest\n" + "brightness = %d\n" + "\n" + "; Sound sample frequency\n" + "; 0 - 6 KHz\n" + "; 1 - 8 KHz\n" + "; 2 - 11.025 KHz\n" + "; 3 - 16 KHz\n" + "; 4 - 22.05 KHz\n" + "; 5 - 32 KHz\n" + "; 6 - 44.1 KHz\n" + "samplerate = %d\n" + "\n" + "; Music playback\n" + "; 0 - Off\n" + "; 1 - On\n" + "music = %d\n" + "\n" + "; Enable mouse\n" + "; 0 - No\n" + "; 1 - Yes\n" + "mouse = %d\n" + "\n" + "; Mouse sensitivity\n" + "mousesensitivity = %g\n" + "\n" + "; Key Settings\n" + "; Here's a map of all the keyboard scan codes: NOTE: values are listed in hex!\n" + "; +---------------------------------------------------------------------------------------------+\n" + "; | 01 3B 3C 3D 3E 3F 40 41 42 43 44 57 58 46 |\n" + "; |ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 SCROLL |\n" + "; | |\n" + "; |29 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E D2 C7 C9 45 B5 37 4A |\n" + "; | ` '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' - = BACK INS HOME PGUP NUMLK KP/ KP* KP- |\n" + "; | |\n" + "; | 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 2B D3 CF D1 47 48 49 4E |\n" + "; |TAB Q W E R T Y U I O P [ ] \\ DEL END PGDN KP7 KP8 KP9 KP+ |\n" + "; | |\n" + "; | 3A 1E 1F 20 21 22 23 24 25 26 27 28 1C 4B 4C 4D |\n" + "; |CAPS A S D F G H J K L ; ' ENTER KP4 KP5 KP6 9C |\n" + "; | KPENTER|\n" + "; | 2A 2C 2D 2E 2F 30 31 32 33 34 35 36 C8 4F 50 51 |\n" + "; |LSHIFT Z X C V B N M , . / RSHIFT UP KP1 KP2 KP3 |\n" + "; | |\n" + "; | 1D 38 39 B8 9D CB D0 CD 52 53 |\n" + "; |LCTRL LALT SPACE RALT RCTRL LEFT DOWN RIGHT KP0 KP. |\n" + "; +---------------------------------------------------------------------------------------------+\n" + "\n" + "keyforward = %X\n" + "keybackward = %X\n" + "keyturnleft = %X\n" + "keyturnright = %X\n" + "keyrun = %X\n" + "keystrafe = %X\n" + "keyfire = %X\n" + "keyuse = %X\n" + "keystandhigh = %X\n" + "keystandlow = %X\n" + "keylookup = %X\n" + "keylookdown = %X\n" + "keystrafeleft = %X\n" + "keystraferight = %X\n" + "key2dmode = %X\n" + "keyviewcycle = %X\n" + "key2dzoomin = %X\n" + "key2dzoomout = %X\n" + "keychat = %X\n" + "keyconsole = %X\n" + "\n", + + fullscreen, xdim2d, ydim2d, xdimgame, ydimgame, bppgame, + glusetexcache, glusetexcachecompression, #ifdef RENDERTYPEWIN - maxrefreshfreq, + maxrefreshfreq, #endif - brightness, option[7]>>4, option[2], - option[3], msens, - keys[0], keys[1], keys[2], keys[3], keys[4], keys[5], - keys[6], keys[7], keys[8], keys[9], keys[10], keys[11], - keys[12], keys[13], keys[14], keys[15], keys[16], keys[17], - keys[18], keys[19] - ); + brightness, option[7]>>4, option[2], + option[3], msens, + keys[0], keys[1], keys[2], keys[3], keys[4], keys[5], + keys[6], keys[7], keys[8], keys[9], keys[10], keys[11], + keys[12], keys[13], keys[14], keys[15], keys[16], keys[17], + keys[18], keys[19] + ); - Bfclose(fp); + Bfclose(fp); - return 0; + return 0; } diff --git a/polymer/build/src/crc32.c b/polymer/build/src/crc32.c index 6cfa1dfa4..85221d194 100644 --- a/polymer/build/src/crc32.c +++ b/polymer/build/src/crc32.c @@ -62,43 +62,43 @@ static unsigned long crc32table[256]; void initcrc32table(void) { - unsigned long i,j,k; - - // algorithm and polynomial same as that used by infozip's zip - for (i=0; i<256; i++) { - j = i; - for (k=8; k; k--) - j = (j&1) ? (0xedb88320L ^ (j>>1)) : (j>>1); - crc32table[i] = j; - } + unsigned long i,j,k; + + // algorithm and polynomial same as that used by infozip's zip + for (i=0; i<256; i++) { + j = i; + for (k=8; k; k--) + j = (j&1) ? (0xedb88320L ^ (j>>1)) : (j>>1); + crc32table[i] = j; + } } unsigned long crc32once(unsigned char *blk, unsigned long len) { - unsigned long crc; - - crc32init(&crc); - crc32block(&crc, blk, len); - return crc32finish(&crc); + unsigned long crc; + + crc32init(&crc); + crc32block(&crc, blk, len); + return crc32finish(&crc); } void crc32init(unsigned long *crcvar) { - if (!crcvar) return; - *crcvar = 0xffffffffl; + if (!crcvar) return; + *crcvar = 0xffffffffl; } void crc32block(unsigned long *crcvar, unsigned char *blk, unsigned long len) { - unsigned long crc = *crcvar; - while (len--) crc = crc32table[(crc ^ *(blk++)) & 0xffl] ^ (crc >> 8); - *crcvar = crc; + unsigned long crc = *crcvar; + while (len--) crc = crc32table[(crc ^ *(blk++)) & 0xffl] ^ (crc >> 8); + *crcvar = crc; } unsigned long crc32finish(unsigned long *crcvar) { - *crcvar = *crcvar ^ 0xffffffffl; - return *crcvar; + *crcvar = *crcvar ^ 0xffffffffl; + return *crcvar; } diff --git a/polymer/build/src/defs.c b/polymer/build/src/defs.c index bd17bac52..c916ef0ca 100644 --- a/polymer/build/src/defs.c +++ b/polymer/build/src/defs.c @@ -12,196 +12,196 @@ #include "cache1d.h" enum { - T_EOF = -2, - T_ERROR = -1, - T_INCLUDE = 0, - T_DEFINE, - T_DEFINETEXTURE, - T_DEFINESKYBOX, - T_DEFINETINT, - T_DEFINEMODEL, - T_DEFINEMODELFRAME, - T_DEFINEMODELANIM, - T_DEFINEMODELSKIN, - T_SELECTMODELSKIN, - T_DEFINEVOXEL, - T_DEFINEVOXELTILES, - T_MODEL, - T_FILE, - T_SCALE, - T_SHADE, - T_FRAME, - T_ANIM, - T_SKIN, - T_SURF, - T_TILE, - T_TILE0, - T_TILE1, - T_FRAME0, - T_FRAME1, - T_FPS, - T_FLAGS, - T_PAL, - T_HUD, - T_XADD, - T_YADD, - T_ZADD, - T_ANGADD, - T_FLIPPED, - T_HIDE, - T_NOBOB, - T_NODEPTH, - T_VOXEL, - T_SKYBOX, - T_FRONT,T_RIGHT,T_BACK,T_LEFT,T_TOP,T_BOTTOM, - T_TINT,T_RED,T_GREEN,T_BLUE, - T_TEXTURE,T_ALPHACUT,T_NOCOMPRESS, - T_UNDEFMODEL,T_UNDEFMODELRANGE,T_UNDEFMODELOF,T_UNDEFTEXTURE,T_UNDEFTEXTURERANGE, - T_ALPHAHACK,T_ALPHAHACKRANGE, - T_SPRITECOL,T_2DCOL, - T_FOGPAL, - T_LOADGRP, + T_EOF = -2, + T_ERROR = -1, + T_INCLUDE = 0, + T_DEFINE, + T_DEFINETEXTURE, + T_DEFINESKYBOX, + T_DEFINETINT, + T_DEFINEMODEL, + T_DEFINEMODELFRAME, + T_DEFINEMODELANIM, + T_DEFINEMODELSKIN, + T_SELECTMODELSKIN, + T_DEFINEVOXEL, + T_DEFINEVOXELTILES, + T_MODEL, + T_FILE, + T_SCALE, + T_SHADE, + T_FRAME, + T_ANIM, + T_SKIN, + T_SURF, + T_TILE, + T_TILE0, + T_TILE1, + T_FRAME0, + T_FRAME1, + T_FPS, + T_FLAGS, + T_PAL, + T_HUD, + T_XADD, + T_YADD, + T_ZADD, + T_ANGADD, + T_FLIPPED, + T_HIDE, + T_NOBOB, + T_NODEPTH, + T_VOXEL, + T_SKYBOX, + T_FRONT,T_RIGHT,T_BACK,T_LEFT,T_TOP,T_BOTTOM, + T_TINT,T_RED,T_GREEN,T_BLUE, + T_TEXTURE,T_ALPHACUT,T_NOCOMPRESS, + T_UNDEFMODEL,T_UNDEFMODELRANGE,T_UNDEFMODELOF,T_UNDEFTEXTURE,T_UNDEFTEXTURERANGE, + T_ALPHAHACK,T_ALPHAHACKRANGE, + T_SPRITECOL,T_2DCOL, + T_FOGPAL, + T_LOADGRP, }; typedef struct { char *text; int tokenid; } tokenlist; -static tokenlist basetokens[] = -{ - { "include", T_INCLUDE }, - { "#include", T_INCLUDE }, - { "define", T_DEFINE }, - { "#define", T_DEFINE }, +static tokenlist basetokens[] = + { + { "include", T_INCLUDE }, + { "#include", T_INCLUDE }, + { "define", T_DEFINE }, + { "#define", T_DEFINE }, - // deprecated style - { "definetexture", T_DEFINETEXTURE }, - { "defineskybox", T_DEFINESKYBOX }, - { "definetint", T_DEFINETINT }, - { "definemodel", T_DEFINEMODEL }, - { "definemodelframe",T_DEFINEMODELFRAME }, - { "definemodelanim", T_DEFINEMODELANIM }, - { "definemodelskin", T_DEFINEMODELSKIN }, - { "selectmodelskin", T_SELECTMODELSKIN }, - { "definevoxel", T_DEFINEVOXEL }, - { "definevoxeltiles",T_DEFINEVOXELTILES }, + // deprecated style + { "definetexture", T_DEFINETEXTURE }, + { "defineskybox", T_DEFINESKYBOX }, + { "definetint", T_DEFINETINT }, + { "definemodel", T_DEFINEMODEL }, + { "definemodelframe",T_DEFINEMODELFRAME }, + { "definemodelanim", T_DEFINEMODELANIM }, + { "definemodelskin", T_DEFINEMODELSKIN }, + { "selectmodelskin", T_SELECTMODELSKIN }, + { "definevoxel", T_DEFINEVOXEL }, + { "definevoxeltiles",T_DEFINEVOXELTILES }, - // new style + // new style - { "model", T_MODEL }, - { "voxel", T_VOXEL }, - { "skybox", T_SKYBOX }, - { "tint", T_TINT }, - { "texture", T_TEXTURE }, - { "tile", T_TEXTURE }, - - // other stuff - { "undefmodel", T_UNDEFMODEL }, - { "undefmodelrange", T_UNDEFMODELRANGE }, - { "undefmodelof", T_UNDEFMODELOF }, - { "undeftexture", T_UNDEFTEXTURE }, - { "undeftexturerange", T_UNDEFTEXTURERANGE }, - { "alphahack", T_ALPHAHACK }, - { "alphahackrange", T_ALPHAHACKRANGE }, - { "spritecol", T_SPRITECOL }, - { "2dcol", T_2DCOL }, - { "fogpal", T_FOGPAL }, - { "loadgrp", T_LOADGRP }, -}; + { "model", T_MODEL }, + { "voxel", T_VOXEL }, + { "skybox", T_SKYBOX }, + { "tint", T_TINT }, + { "texture", T_TEXTURE }, + { "tile", T_TEXTURE }, + + // other stuff + { "undefmodel", T_UNDEFMODEL }, + { "undefmodelrange", T_UNDEFMODELRANGE }, + { "undefmodelof", T_UNDEFMODELOF }, + { "undeftexture", T_UNDEFTEXTURE }, + { "undeftexturerange", T_UNDEFTEXTURERANGE }, + { "alphahack", T_ALPHAHACK }, + { "alphahackrange", T_ALPHAHACKRANGE }, + { "spritecol", T_SPRITECOL }, + { "2dcol", T_2DCOL }, + { "fogpal", T_FOGPAL }, + { "loadgrp", T_LOADGRP }, + }; static tokenlist modeltokens[] = { - { "scale", T_SCALE }, - { "shade", T_SHADE }, - { "zadd", T_ZADD }, - { "frame", T_FRAME }, - { "anim", T_ANIM }, - { "skin", T_SKIN }, - { "hud", T_HUD }, -}; + { "scale", T_SCALE }, + { "shade", T_SHADE }, + { "zadd", T_ZADD }, + { "frame", T_FRAME }, + { "anim", T_ANIM }, + { "skin", T_SKIN }, + { "hud", T_HUD }, + }; static tokenlist modelframetokens[] = { - { "frame", T_FRAME }, - { "name", T_FRAME }, - { "tile", T_TILE }, - { "tile0", T_TILE0 }, - { "tile1", T_TILE1 }, -}; + { "frame", T_FRAME }, + { "name", T_FRAME }, + { "tile", T_TILE }, + { "tile0", T_TILE0 }, + { "tile1", T_TILE1 }, + }; static tokenlist modelanimtokens[] = { - { "frame0", T_FRAME0 }, - { "frame1", T_FRAME1 }, - { "fps", T_FPS }, - { "flags", T_FLAGS }, -}; + { "frame0", T_FRAME0 }, + { "frame1", T_FRAME1 }, + { "fps", T_FPS }, + { "flags", T_FLAGS }, + }; static tokenlist modelskintokens[] = { - { "pal", T_PAL }, - { "file", T_FILE }, - { "surf", T_SURF }, - { "surface",T_SURF }, -}; + { "pal", T_PAL }, + { "file", T_FILE }, + { "surf", T_SURF }, + { "surface",T_SURF }, + }; static tokenlist modelhudtokens[] = { - { "tile", T_TILE }, - { "tile0", T_TILE0 }, - { "tile1", T_TILE1 }, - { "xadd", T_XADD }, - { "yadd", T_YADD }, - { "zadd", T_ZADD }, - { "angadd", T_ANGADD }, - { "hide", T_HIDE }, - { "nobob", T_NOBOB }, - { "flipped",T_FLIPPED}, - { "nodepth",T_NODEPTH}, -}; + { "tile", T_TILE }, + { "tile0", T_TILE0 }, + { "tile1", T_TILE1 }, + { "xadd", T_XADD }, + { "yadd", T_YADD }, + { "zadd", T_ZADD }, + { "angadd", T_ANGADD }, + { "hide", T_HIDE }, + { "nobob", T_NOBOB }, + { "flipped",T_FLIPPED}, + { "nodepth",T_NODEPTH}, + }; static tokenlist voxeltokens[] = { - { "tile", T_TILE }, - { "tile0", T_TILE0 }, - { "tile1", T_TILE1 }, - { "scale", T_SCALE }, -}; + { "tile", T_TILE }, + { "tile0", T_TILE0 }, + { "tile1", T_TILE1 }, + { "scale", T_SCALE }, + }; static tokenlist skyboxtokens[] = { - { "tile" ,T_TILE }, - { "pal" ,T_PAL }, - { "ft" ,T_FRONT },{ "front" ,T_FRONT },{ "forward",T_FRONT }, - { "rt" ,T_RIGHT },{ "right" ,T_RIGHT }, - { "bk" ,T_BACK },{ "back" ,T_BACK }, - { "lf" ,T_LEFT },{ "left" ,T_LEFT },{ "lt" ,T_LEFT }, - { "up" ,T_TOP },{ "top" ,T_TOP },{ "ceiling",T_TOP },{ "ceil" ,T_TOP }, - { "dn" ,T_BOTTOM },{ "bottom" ,T_BOTTOM },{ "floor" ,T_BOTTOM },{ "down" ,T_BOTTOM } -}; + { "tile" ,T_TILE }, + { "pal" ,T_PAL }, + { "ft" ,T_FRONT },{ "front" ,T_FRONT },{ "forward",T_FRONT }, + { "rt" ,T_RIGHT },{ "right" ,T_RIGHT }, + { "bk" ,T_BACK },{ "back" ,T_BACK }, + { "lf" ,T_LEFT },{ "left" ,T_LEFT },{ "lt" ,T_LEFT }, + { "up" ,T_TOP },{ "top" ,T_TOP },{ "ceiling",T_TOP },{ "ceil" ,T_TOP }, + { "dn" ,T_BOTTOM },{ "bottom" ,T_BOTTOM },{ "floor" ,T_BOTTOM },{ "down" ,T_BOTTOM } + }; static tokenlist tinttokens[] = { - { "pal", T_PAL }, - { "red", T_RED },{ "r", T_RED }, - { "green", T_GREEN },{ "g", T_GREEN }, - { "blue", T_BLUE },{ "b", T_BLUE }, - { "flags", T_FLAGS } -}; + { "pal", T_PAL }, + { "red", T_RED },{ "r", T_RED }, + { "green", T_GREEN },{ "g", T_GREEN }, + { "blue", T_BLUE },{ "b", T_BLUE }, + { "flags", T_FLAGS } + }; static tokenlist texturetokens[] = { - { "pal", T_PAL }, -}; + { "pal", T_PAL }, + }; static tokenlist texturetokens_pal[] = { - { "file", T_FILE },{ "name", T_FILE }, - { "alphacut", T_ALPHACUT }, - { "nocompress",T_NOCOMPRESS }, -}; + { "file", T_FILE },{ "name", T_FILE }, + { "alphacut", T_ALPHACUT }, + { "nocompress",T_NOCOMPRESS }, + }; static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens) { - char *tok; - int i; + char *tok; + int i; - if (!sf) return T_ERROR; - tok = scriptfile_gettoken(sf); - if (!tok) return T_EOF; + if (!sf) return T_ERROR; + tok = scriptfile_gettoken(sf); + if (!tok) return T_EOF; - for(i=0;iltextptr; - switch (tokn) { - case T_ERROR: - initprintf("Error on line %s:%d.\n", script->filename,scriptfile_getlinum(script,cmdtokptr)); - break; - case T_EOF: - return(0); - case T_INCLUDE: - { - char *fn; - if (!scriptfile_getstring(script,&fn)) { - scriptfile *included; + int tokn; + char *cmdtokptr; + while (1) { + tokn = getatoken(script,basetokens,sizeof(basetokens)/sizeof(tokenlist)); + cmdtokptr = script->ltextptr; + switch (tokn) { + case T_ERROR: + initprintf("Error on line %s:%d.\n", script->filename,scriptfile_getlinum(script,cmdtokptr)); + break; + case T_EOF: + return(0); + case T_INCLUDE: + { + char *fn; + if (!scriptfile_getstring(script,&fn)) { + scriptfile *included; - included = scriptfile_fromfile(fn); - if (!included) { - initprintf("Warning: Failed including %s on line %s:%d\n", - fn, script->filename,scriptfile_getlinum(script,cmdtokptr)); - } else { - defsparser(included); - scriptfile_close(included); - } - } - break; - } - case T_DEFINE: - { - char *name; - int number; + included = scriptfile_fromfile(fn); + if (!included) { + initprintf("Warning: Failed including %s on line %s:%d\n", + fn, script->filename,scriptfile_getlinum(script,cmdtokptr)); + } else { + defsparser(included); + scriptfile_close(included); + } + } + break; + } + case T_DEFINE: + { + char *name; + int number; - if (scriptfile_getstring(script,&name)) break; - if (scriptfile_getsymbol(script,&number)) break; + if (scriptfile_getstring(script,&name)) break; + if (scriptfile_getsymbol(script,&number)) break; - if (scriptfile_addsymbolvalue(name,number) < 0) - initprintf("Warning: Symbol %s was NOT redefined to %d on line %s:%d\n", - name,number,script->filename,scriptfile_getlinum(script,cmdtokptr)); - break; - } + if (scriptfile_addsymbolvalue(name,number) < 0) + initprintf("Warning: Symbol %s was NOT redefined to %d on line %s:%d\n", + name,number,script->filename,scriptfile_getlinum(script,cmdtokptr)); + break; + } - // OLD (DEPRECATED) DEFINITION SYNTAX - case T_DEFINETEXTURE: - { - int tile,pal,fnoo; - char *fn; + // OLD (DEPRECATED) DEFINITION SYNTAX + case T_DEFINETEXTURE: + { + int tile,pal,fnoo; + char *fn; - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getsymbol(script,&pal)) break; - if (scriptfile_getnumber(script,&fnoo)) break; //x-center - if (scriptfile_getnumber(script,&fnoo)) break; //y-center - if (scriptfile_getnumber(script,&fnoo)) break; //x-size - if (scriptfile_getnumber(script,&fnoo)) break; //y-size - if (scriptfile_getstring(script,&fn)) break; - hicsetsubsttex(tile,pal,fn,-1.0,0); - } - break; - case T_DEFINESKYBOX: - { - int tile,pal,i; - char *fn[6]; + if (scriptfile_getsymbol(script,&tile)) break; + if (scriptfile_getsymbol(script,&pal)) break; + if (scriptfile_getnumber(script,&fnoo)) break; //x-center + if (scriptfile_getnumber(script,&fnoo)) break; //y-center + if (scriptfile_getnumber(script,&fnoo)) break; //x-size + if (scriptfile_getnumber(script,&fnoo)) break; //y-size + if (scriptfile_getstring(script,&fn)) break; + hicsetsubsttex(tile,pal,fn,-1.0,0); + } + break; + case T_DEFINESKYBOX: + { + int tile,pal,i; + char *fn[6]; - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getsymbol(script,&pal)) break; - if (scriptfile_getsymbol(script,&i)) break; //future expansion - for (i=0;i<6;i++) if (scriptfile_getstring(script,&fn[i])) break; //grab the 6 faces - if (i < 6) break; - hicsetskybox(tile,pal,fn); - } - break; - case T_DEFINETINT: - { - int pal, r,g,b,f; + if (scriptfile_getsymbol(script,&tile)) break; + if (scriptfile_getsymbol(script,&pal)) break; + if (scriptfile_getsymbol(script,&i)) break; //future expansion + for (i=0;i<6;i++) if (scriptfile_getstring(script,&fn[i])) break; //grab the 6 faces + if (i < 6) break; + hicsetskybox(tile,pal,fn); + } + break; + case T_DEFINETINT: + { + int pal, r,g,b,f; - if (scriptfile_getsymbol(script,&pal)) break; - if (scriptfile_getnumber(script,&r)) break; - if (scriptfile_getnumber(script,&g)) break; - if (scriptfile_getnumber(script,&b)) break; - if (scriptfile_getnumber(script,&f)) break; //effects - hicsetpalettetint(pal,r,g,b,f); - } - break; - case T_ALPHAHACK: - { - int tile; - double alpha; + if (scriptfile_getsymbol(script,&pal)) break; + if (scriptfile_getnumber(script,&r)) break; + if (scriptfile_getnumber(script,&g)) break; + if (scriptfile_getnumber(script,&b)) break; + if (scriptfile_getnumber(script,&f)) break; //effects + hicsetpalettetint(pal,r,g,b,f); + } + break; + case T_ALPHAHACK: + { + int tile; + double alpha; - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getdouble(script,&alpha)) break; - if ((unsigned long)tile < MAXTILES) alphahackarray[tile] = alpha; - } - break; - case T_ALPHAHACKRANGE: - { - int tilenume1,tilenume2,i; - double alpha; + if (scriptfile_getsymbol(script,&tile)) break; + if (scriptfile_getdouble(script,&alpha)) break; + if ((unsigned long)tile < MAXTILES) alphahackarray[tile] = alpha; + } + break; + case T_ALPHAHACKRANGE: + { + int tilenume1,tilenume2,i; + double alpha; - if (scriptfile_getsymbol(script,&tilenume1)) break; - if (scriptfile_getsymbol(script,&tilenume2)) break; - if (scriptfile_getdouble(script,&alpha)) break; - if (tilenume2 < tilenume1) { - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - i = tilenume2; - tilenume2 = tilenume1; - tilenume1 = i; - } - if ((tilenume1 >= 0 && tilenume1 < MAXTILES) && (tilenume2 >= 0 && tilenume2 < MAXTILES)) - { - for (i=tilenume1;i<=tilenume2;i++) - { - if ((unsigned long)i < MAXTILES) - alphahackarray[i] = alpha; - } - } - } - break; - case T_SPRITECOL: - { - int tile,col,type; + if (scriptfile_getsymbol(script,&tilenume1)) break; + if (scriptfile_getsymbol(script,&tilenume2)) break; + if (scriptfile_getdouble(script,&alpha)) break; + if (tilenume2 < tilenume1) { + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + i = tilenume2; + tilenume2 = tilenume1; + tilenume1 = i; + } + if ((tilenume1 >= 0 && tilenume1 < MAXTILES) && (tilenume2 >= 0 && tilenume2 < MAXTILES)) + { + for (i=tilenume1;i<=tilenume2;i++) + { + if ((unsigned long)i < MAXTILES) + alphahackarray[i] = alpha; + } + } + } + break; + case T_SPRITECOL: + { + int tile,col,type; - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getnumber(script,&col)) break; - if (scriptfile_getnumber(script,&type)) break; - if ((unsigned long)tile < MAXTILES) spritecol2d[tile][type] = col; - } - break; - case T_2DCOL: - { - int col,b,g,r; + if (scriptfile_getsymbol(script,&tile)) break; + if (scriptfile_getnumber(script,&col)) break; + if (scriptfile_getnumber(script,&type)) break; + if ((unsigned long)tile < MAXTILES) spritecol2d[tile][type] = col; + } + break; + case T_2DCOL: + { + int col,b,g,r; - if (scriptfile_getnumber(script,&col)) break; - if (scriptfile_getnumber(script,&r)) break; - if (scriptfile_getnumber(script,&g)) break; - if (scriptfile_getnumber(script,&b)) break; + if (scriptfile_getnumber(script,&col)) break; + if (scriptfile_getnumber(script,&r)) break; + if (scriptfile_getnumber(script,&g)) break; + if (scriptfile_getnumber(script,&b)) break; - if (col < 256) { - vgapal16[col*4+0] = b; // blue - vgapal16[col*4+1] = g; // green - vgapal16[col*4+2] = r; // red - } - } - break; - case T_FOGPAL: - { - int p,r,g,b,j; - char tempbuf[256]; + if (col < 256) { + vgapal16[col*4+0] = b; // blue + vgapal16[col*4+1] = g; // green + vgapal16[col*4+2] = r; // red + } + } + break; + case T_FOGPAL: + { + int p,r,g,b,j; + char tempbuf[256]; - if (scriptfile_getnumber(script,&p)) break; - if (scriptfile_getnumber(script,&r)) break; - if (scriptfile_getnumber(script,&g)) break; - if (scriptfile_getnumber(script,&b)) break; + if (scriptfile_getnumber(script,&p)) break; + if (scriptfile_getnumber(script,&r)) break; + if (scriptfile_getnumber(script,&g)) break; + if (scriptfile_getnumber(script,&b)) break; - for (j = 0; j < 256; j++) - tempbuf[j] = j; - makepalookup(p, tempbuf, r, g, b, 1); - } - break; - case T_LOADGRP: - { - char *bs; - scriptfile_getstring(script,&bs); - } - break; - case T_DEFINEMODEL: - { - char *modelfn; - double scale; - int shadeoffs; + for (j = 0; j < 256; j++) + tempbuf[j] = j; + makepalookup(p, tempbuf, r, g, b, 1); + } + break; + case T_LOADGRP: + { + char *bs; + scriptfile_getstring(script,&bs); + } + break; + case T_DEFINEMODEL: + { + char *modelfn; + double scale; + int shadeoffs; - if (scriptfile_getstring(script,&modelfn)) break; - if (scriptfile_getdouble(script,&scale)) break; - if (scriptfile_getnumber(script,&shadeoffs)) break; + if (scriptfile_getstring(script,&modelfn)) break; + if (scriptfile_getdouble(script,&scale)) break; + if (scriptfile_getnumber(script,&shadeoffs)) break; #if defined(POLYMOST) && defined(USE_OPENGL) - lastmodelid = md_loadmodel(modelfn); - if (lastmodelid < 0) { - initprintf("Failure loading MD2/MD3 model \"%s\"\n", modelfn); - break; - } - md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0); + lastmodelid = md_loadmodel(modelfn); + if (lastmodelid < 0) { + initprintf("Failure loading MD2/MD3 model \"%s\"\n", modelfn); + break; + } + md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0); #endif - modelskin = lastmodelskin = 0; - seenframe = 0; - } - break; - case T_DEFINEMODELFRAME: - { - char *framename, happy=1; - int ftilenume, ltilenume, tilex; + modelskin = lastmodelskin = 0; + seenframe = 0; + } + break; + case T_DEFINEMODELFRAME: + { + char *framename, happy=1; + int ftilenume, ltilenume, tilex; - if (scriptfile_getstring(script,&framename)) break; - if (scriptfile_getnumber(script,&ftilenume)) break; //first tile number - if (scriptfile_getnumber(script,<ilenume)) break; //last tile number (inclusive) - if (ltilenume < ftilenume) { - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - tilex = ftilenume; - ftilenume = ltilenume; - ltilenume = tilex; - } + if (scriptfile_getstring(script,&framename)) break; + if (scriptfile_getnumber(script,&ftilenume)) break; //first tile number + if (scriptfile_getnumber(script,<ilenume)) break; //last tile number (inclusive) + if (ltilenume < ftilenume) { + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + tilex = ftilenume; + ftilenume = ltilenume; + ltilenume = tilex; + } - if (lastmodelid < 0) { - initprintf("Warning: Ignoring frame definition.\n"); - break; - } + if (lastmodelid < 0) { + initprintf("Warning: Ignoring frame definition.\n"); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { - switch (md_defineframe(lastmodelid, framename, tilex, max(0,modelskin))) { - case 0: break; - case -1: happy = 0; break; // invalid model id!? - case -2: initprintf("Invalid tile number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - happy = 0; - break; - case -3: initprintf("Invalid frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - happy = 0; - break; - } - } + for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { + switch (md_defineframe(lastmodelid, framename, tilex, max(0,modelskin))) { + case 0: break; + case -1: happy = 0; break; // invalid model id!? + case -2: initprintf("Invalid tile number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + happy = 0; + break; + case -3: initprintf("Invalid frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + happy = 0; + break; + } + } #endif - seenframe = 1; - } - break; - case T_DEFINEMODELANIM: - { - char *startframe, *endframe; - int flags; - double dfps; + seenframe = 1; + } + break; + case T_DEFINEMODELANIM: + { + char *startframe, *endframe; + int flags; + double dfps; - if (scriptfile_getstring(script,&startframe)) break; - if (scriptfile_getstring(script,&endframe)) break; - if (scriptfile_getdouble(script,&dfps)) break; //animation frame rate - if (scriptfile_getnumber(script,&flags)) break; + if (scriptfile_getstring(script,&startframe)) break; + if (scriptfile_getstring(script,&endframe)) break; + if (scriptfile_getdouble(script,&dfps)) break; //animation frame rate + if (scriptfile_getnumber(script,&flags)) break; - if (lastmodelid < 0) { - initprintf("Warning: Ignoring animation definition.\n"); - break; - } + if (lastmodelid < 0) { + initprintf("Warning: Ignoring animation definition.\n"); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - switch (md_defineanimation(lastmodelid, startframe, endframe, (int)(dfps*(65536.0*.001)), flags)) { - case 0: break; - case -1: break; // invalid model id!? - case -2: initprintf("Invalid starting frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - case -3: initprintf("Invalid ending frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - case -4: initprintf("Out of memory on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } + switch (md_defineanimation(lastmodelid, startframe, endframe, (int)(dfps*(65536.0*.001)), flags)) { + case 0: break; + case -1: break; // invalid model id!? + case -2: initprintf("Invalid starting frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + case -3: initprintf("Invalid ending frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + case -4: initprintf("Out of memory on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } #endif - } - break; - case T_DEFINEMODELSKIN: - { - int palnum, palnumer; - char *skinfn; - - if (scriptfile_getsymbol(script,&palnum)) break; - if (scriptfile_getstring(script,&skinfn)) break; //skin filename + } + break; + case T_DEFINEMODELSKIN: + { + int palnum, palnumer; + char *skinfn; - // if we see a sequence of definemodelskin, then a sequence of definemodelframe, - // and then a definemodelskin, we need to increment the skin counter. - // - // definemodel "mymodel.md2" 1 1 - // definemodelskin 0 "normal.png" // skin 0 - // definemodelskin 21 "normal21.png" - // definemodelframe "foo" 1000 1002 // these use skin 0 - // definemodelskin 0 "wounded.png" // skin 1 - // definemodelskin 21 "wounded21.png" - // definemodelframe "foo2" 1003 1004 // these use skin 1 - // selectmodelskin 0 // resets to skin 0 - // definemodelframe "foo3" 1005 1006 // these use skin 0 - if (seenframe) { modelskin = ++lastmodelskin; } - seenframe = 0; + if (scriptfile_getsymbol(script,&palnum)) break; + if (scriptfile_getstring(script,&skinfn)) break; //skin filename + + // if we see a sequence of definemodelskin, then a sequence of definemodelframe, + // and then a definemodelskin, we need to increment the skin counter. + // + // definemodel "mymodel.md2" 1 1 + // definemodelskin 0 "normal.png" // skin 0 + // definemodelskin 21 "normal21.png" + // definemodelframe "foo" 1000 1002 // these use skin 0 + // definemodelskin 0 "wounded.png" // skin 1 + // definemodelskin 21 "wounded21.png" + // definemodelframe "foo2" 1003 1004 // these use skin 1 + // selectmodelskin 0 // resets to skin 0 + // definemodelframe "foo3" 1005 1006 // these use skin 0 + if (seenframe) { modelskin = ++lastmodelskin; } + seenframe = 0; #if defined(POLYMOST) && defined(USE_OPENGL) - switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), 0)) { - case 0: break; - case -1: break; // invalid model id!? - case -2: initprintf("Invalid skin filename on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - case -3: initprintf("Invalid palette number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - case -4: initprintf("Out of memory on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } + switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), 0)) { + case 0: break; + case -1: break; // invalid model id!? + case -2: initprintf("Invalid skin filename on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + case -3: initprintf("Invalid palette number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + case -4: initprintf("Out of memory on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } #endif - } - break; - case T_SELECTMODELSKIN: - { - if (scriptfile_getsymbol(script,&modelskin)) break; - } - break; - case T_DEFINEVOXEL: - { - char *fn; + } + break; + case T_SELECTMODELSKIN: + { + if (scriptfile_getsymbol(script,&modelskin)) break; + } + break; + case T_DEFINEVOXEL: + { + char *fn; - if (scriptfile_getstring(script,&fn)) break; //voxel filename + if (scriptfile_getstring(script,&fn)) break; //voxel filename - if (nextvoxid == MAXVOXELS) { - initprintf("Maximum number of voxels already defined.\n"); - break; - } + if (nextvoxid == MAXVOXELS) { + initprintf("Maximum number of voxels already defined.\n"); + break; + } #ifdef SUPERBUILD - if (qloadkvx(nextvoxid, fn)) { - initprintf("Failure loading voxel file \"%s\"\n",fn); - break; - } + if (qloadkvx(nextvoxid, fn)) { + initprintf("Failure loading voxel file \"%s\"\n",fn); + break; + } - lastvoxid = nextvoxid++; + lastvoxid = nextvoxid++; #endif - } - break; - case T_DEFINEVOXELTILES: - { - int ftilenume, ltilenume, tilex; + } + break; + case T_DEFINEVOXELTILES: + { + int ftilenume, ltilenume, tilex; - if (scriptfile_getnumber(script,&ftilenume)) break; //1st tile # - if (scriptfile_getnumber(script,<ilenume)) break; //last tile # + if (scriptfile_getnumber(script,&ftilenume)) break; //1st tile # + if (scriptfile_getnumber(script,<ilenume)) break; //last tile # - if (ltilenume < ftilenume) { - initprintf("Warning: backwards tile range on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - tilex = ftilenume; - ftilenume = ltilenume; - ltilenume = tilex; - } - if (ltilenume < 0 || ftilenume >= MAXTILES) { - initprintf("Invalid tile range on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } + if (ltilenume < ftilenume) { + initprintf("Warning: backwards tile range on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + tilex = ftilenume; + ftilenume = ltilenume; + ltilenume = tilex; + } + if (ltilenume < 0 || ftilenume >= MAXTILES) { + initprintf("Invalid tile range on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } - if (lastvoxid < 0) { - initprintf("Warning: Ignoring voxel tiles definition.\n"); - break; - } + if (lastvoxid < 0) { + initprintf("Warning: Ignoring voxel tiles definition.\n"); + break; + } #ifdef SUPERBUILD - for (tilex = ftilenume; tilex <= ltilenume; tilex++) { - tiletovox[tilex] = lastvoxid; - } + for (tilex = ftilenume; tilex <= ltilenume; tilex++) { + tiletovox[tilex] = lastvoxid; + } #endif - } - break; + } + break; - // NEW (ENCOURAGED) DEFINITION SYNTAX - case T_MODEL: - { - char *modelend, *modelfn; - double scale=1.0, mzadd=0.0; - int shadeoffs=0; + // NEW (ENCOURAGED) DEFINITION SYNTAX + case T_MODEL: + { + char *modelend, *modelfn; + double scale=1.0, mzadd=0.0; + int shadeoffs=0; - modelskin = lastmodelskin = 0; - seenframe = 0; + modelskin = lastmodelskin = 0; + seenframe = 0; - if (scriptfile_getstring(script,&modelfn)) break; + if (scriptfile_getstring(script,&modelfn)) break; #if defined(POLYMOST) && defined(USE_OPENGL) - lastmodelid = md_loadmodel(modelfn); - if (lastmodelid < 0) { - initprintf("Failure loading MD2/MD3 model \"%s\"\n", modelfn); - break; - } + lastmodelid = md_loadmodel(modelfn); + if (lastmodelid < 0) { + initprintf("Failure loading MD2/MD3 model \"%s\"\n", modelfn); + break; + } #endif - if (scriptfile_getbraces(script,&modelend)) break; - while (script->textptr < modelend) { - switch (getatoken(script,modeltokens,sizeof(modeltokens)/sizeof(tokenlist))) { - //case T_ERROR: initprintf("Error on line %s:%d in model tokens\n", script->filename,script->linenum); break; - case T_SCALE: scriptfile_getdouble(script,&scale); break; - case T_SHADE: scriptfile_getnumber(script,&shadeoffs); break; - case T_ZADD: scriptfile_getdouble(script,&mzadd); break; - case T_FRAME: - { - char *frametokptr = script->ltextptr; - char *frameend, *framename = 0, happy=1; - int ftilenume = -1, ltilenume = -1, tilex = 0; + if (scriptfile_getbraces(script,&modelend)) break; + while (script->textptr < modelend) { + switch (getatoken(script,modeltokens,sizeof(modeltokens)/sizeof(tokenlist))) { + //case T_ERROR: initprintf("Error on line %s:%d in model tokens\n", script->filename,script->linenum); break; + case T_SCALE: scriptfile_getdouble(script,&scale); break; + case T_SHADE: scriptfile_getnumber(script,&shadeoffs); break; + case T_ZADD: scriptfile_getdouble(script,&mzadd); break; + case T_FRAME: + { + char *frametokptr = script->ltextptr; + char *frameend, *framename = 0, happy=1; + int ftilenume = -1, ltilenume = -1, tilex = 0; - if (scriptfile_getbraces(script,&frameend)) break; - while (script->textptr < frameend) { - switch(getatoken(script,modelframetokens,sizeof(modelframetokens)/sizeof(tokenlist))) { - case T_FRAME: scriptfile_getstring(script,&framename); break; - case T_TILE: scriptfile_getsymbol(script,&ftilenume); ltilenume = ftilenume; break; - case T_TILE0: scriptfile_getsymbol(script,&ftilenume); break; //first tile number - case T_TILE1: scriptfile_getsymbol(script,<ilenume); break; //last tile number (inclusive) - } - } + if (scriptfile_getbraces(script,&frameend)) break; + while (script->textptr < frameend) { + switch(getatoken(script,modelframetokens,sizeof(modelframetokens)/sizeof(tokenlist))) { + case T_FRAME: scriptfile_getstring(script,&framename); break; + case T_TILE: scriptfile_getsymbol(script,&ftilenume); ltilenume = ftilenume; break; + case T_TILE0: scriptfile_getsymbol(script,&ftilenume); break; //first tile number + case T_TILE1: scriptfile_getsymbol(script,<ilenume); break; //last tile number (inclusive) + } + } - if (ftilenume < 0) initprintf("Error: missing 'first tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; - if (ltilenume < 0) initprintf("Error: missing 'last tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; - if (!happy) break; + if (ftilenume < 0) initprintf("Error: missing 'first tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; + if (ltilenume < 0) initprintf("Error: missing 'last tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; + if (!happy) break; - if (ltilenume < ftilenume) { - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)); - tilex = ftilenume; - ftilenume = ltilenume; - ltilenume = tilex; - } + if (ltilenume < ftilenume) { + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)); + tilex = ftilenume; + ftilenume = ltilenume; + ltilenume = tilex; + } - if (lastmodelid < 0) { - initprintf("Warning: Ignoring frame definition.\n"); - break; - } + if (lastmodelid < 0) { + initprintf("Warning: Ignoring frame definition.\n"); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { - switch (md_defineframe(lastmodelid, framename, tilex, max(0,modelskin))) { - case 0: break; - case -1: happy = 0; break; // invalid model id!? - case -2: initprintf("Invalid tile number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,frametokptr)); - happy = 0; - break; - case -3: initprintf("Invalid frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,frametokptr)); - happy = 0; - break; - } - } + for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { + switch (md_defineframe(lastmodelid, framename, tilex, max(0,modelskin))) { + case 0: break; + case -1: happy = 0; break; // invalid model id!? + case -2: initprintf("Invalid tile number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,frametokptr)); + happy = 0; + break; + case -3: initprintf("Invalid frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,frametokptr)); + happy = 0; + break; + } + } #endif - seenframe = 1; - } - break; - case T_ANIM: - { - char *animtokptr = script->ltextptr; - char *animend, *startframe = 0, *endframe = 0, happy=1; - int flags = 0; - double dfps = 1.0; + seenframe = 1; + } + break; + case T_ANIM: + { + char *animtokptr = script->ltextptr; + char *animend, *startframe = 0, *endframe = 0, happy=1; + int flags = 0; + double dfps = 1.0; - if (scriptfile_getbraces(script,&animend)) break; - while (script->textptr < animend) { - switch(getatoken(script,modelanimtokens,sizeof(modelanimtokens)/sizeof(tokenlist))) { - case T_FRAME0: scriptfile_getstring(script,&startframe); break; - case T_FRAME1: scriptfile_getstring(script,&endframe); break; - case T_FPS: scriptfile_getdouble(script,&dfps); break; //animation frame rate - case T_FLAGS: scriptfile_getsymbol(script,&flags); break; - } - } + if (scriptfile_getbraces(script,&animend)) break; + while (script->textptr < animend) { + switch(getatoken(script,modelanimtokens,sizeof(modelanimtokens)/sizeof(tokenlist))) { + case T_FRAME0: scriptfile_getstring(script,&startframe); break; + case T_FRAME1: scriptfile_getstring(script,&endframe); break; + case T_FPS: scriptfile_getdouble(script,&dfps); break; //animation frame rate + case T_FLAGS: scriptfile_getsymbol(script,&flags); break; + } + } - if (!startframe) initprintf("Error: missing 'start frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; - if (!endframe) initprintf("Error: missing 'end frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; - if (!happy) break; - - if (lastmodelid < 0) { - initprintf("Warning: Ignoring animation definition.\n"); - break; - } + if (!startframe) initprintf("Error: missing 'start frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; + if (!endframe) initprintf("Error: missing 'end frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; + if (!happy) break; + + if (lastmodelid < 0) { + initprintf("Warning: Ignoring animation definition.\n"); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - switch (md_defineanimation(lastmodelid, startframe, endframe, (int)(dfps*(65536.0*.001)), flags)) { - case 0: break; - case -1: break; // invalid model id!? - case -2: initprintf("Invalid starting frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,animtokptr)); - break; - case -3: initprintf("Invalid ending frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,animtokptr)); - break; - case -4: initprintf("Out of memory on line %s:%d\n", - script->filename, scriptfile_getlinum(script,animtokptr)); - break; - } + switch (md_defineanimation(lastmodelid, startframe, endframe, (int)(dfps*(65536.0*.001)), flags)) { + case 0: break; + case -1: break; // invalid model id!? + case -2: initprintf("Invalid starting frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,animtokptr)); + break; + case -3: initprintf("Invalid ending frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,animtokptr)); + break; + case -4: initprintf("Out of memory on line %s:%d\n", + script->filename, scriptfile_getlinum(script,animtokptr)); + break; + } #endif - } break; - case T_SKIN: - { - char *skintokptr = script->ltextptr; - char *skinend, *skinfn = 0; - int palnum = 0, surfnum = 0; + } break; + case T_SKIN: + { + char *skintokptr = script->ltextptr; + char *skinend, *skinfn = 0; + int palnum = 0, surfnum = 0; - if (scriptfile_getbraces(script,&skinend)) break; - while (script->textptr < skinend) { - switch(getatoken(script,modelskintokens,sizeof(modelskintokens)/sizeof(tokenlist))) { - case T_PAL: scriptfile_getsymbol(script,&palnum); break; - case T_FILE: scriptfile_getstring(script,&skinfn); break; //skin filename - case T_SURF: scriptfile_getnumber(script,&surfnum); break; - } - } + if (scriptfile_getbraces(script,&skinend)) break; + while (script->textptr < skinend) { + switch(getatoken(script,modelskintokens,sizeof(modelskintokens)/sizeof(tokenlist))) { + case T_PAL: scriptfile_getsymbol(script,&palnum); break; + case T_FILE: scriptfile_getstring(script,&skinfn); break; //skin filename + case T_SURF: scriptfile_getnumber(script,&surfnum); break; + } + } - if (!skinfn) { - initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); - break; - } + if (!skinfn) { + initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); + break; + } - if (seenframe) { modelskin = ++lastmodelskin; } - seenframe = 0; + if (seenframe) { modelskin = ++lastmodelskin; } + seenframe = 0; #if defined(POLYMOST) && defined(USE_OPENGL) - switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), surfnum)) { - case 0: break; - case -1: break; // invalid model id!? - case -2: initprintf("Invalid skin filename on line %s:%d\n", - script->filename, scriptfile_getlinum(script,skintokptr)); - break; - case -3: initprintf("Invalid palette number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,skintokptr)); - break; - case -4: initprintf("Out of memory on line %s:%d\n", - script->filename, scriptfile_getlinum(script,skintokptr)); - break; - } + switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), surfnum)) { + case 0: break; + case -1: break; // invalid model id!? + case -2: initprintf("Invalid skin filename on line %s:%d\n", + script->filename, scriptfile_getlinum(script,skintokptr)); + break; + case -3: initprintf("Invalid palette number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,skintokptr)); + break; + case -4: initprintf("Out of memory on line %s:%d\n", + script->filename, scriptfile_getlinum(script,skintokptr)); + break; + } #endif - } break; - case T_HUD: - { - char *hudtokptr = script->ltextptr; - char happy=1, *frameend; - int ftilenume = -1, ltilenume = -1, tilex = 0, flags = 0; - double xadd = 0.0, yadd = 0.0, zadd = 0.0, angadd = 0.0; + } break; + case T_HUD: + { + char *hudtokptr = script->ltextptr; + char happy=1, *frameend; + int ftilenume = -1, ltilenume = -1, tilex = 0, flags = 0; + double xadd = 0.0, yadd = 0.0, zadd = 0.0, angadd = 0.0; - if (scriptfile_getbraces(script,&frameend)) break; - while (script->textptr < frameend) { - switch(getatoken(script,modelhudtokens,sizeof(modelhudtokens)/sizeof(tokenlist))) { - case T_TILE: scriptfile_getsymbol(script,&ftilenume); ltilenume = ftilenume; break; - case T_TILE0: scriptfile_getsymbol(script,&ftilenume); break; //first tile number - case T_TILE1: scriptfile_getsymbol(script,<ilenume); break; //last tile number (inclusive) - case T_XADD: scriptfile_getdouble(script,&xadd); break; - case T_YADD: scriptfile_getdouble(script,&yadd); break; - case T_ZADD: scriptfile_getdouble(script,&zadd); break; - case T_ANGADD:scriptfile_getdouble(script,&angadd); break; - case T_HIDE: flags |= 1; break; - case T_NOBOB: flags |= 2; break; - case T_FLIPPED: flags |= 4; break; - case T_NODEPTH: flags |= 8; break; - } - } + if (scriptfile_getbraces(script,&frameend)) break; + while (script->textptr < frameend) { + switch(getatoken(script,modelhudtokens,sizeof(modelhudtokens)/sizeof(tokenlist))) { + case T_TILE: scriptfile_getsymbol(script,&ftilenume); ltilenume = ftilenume; break; + case T_TILE0: scriptfile_getsymbol(script,&ftilenume); break; //first tile number + case T_TILE1: scriptfile_getsymbol(script,<ilenume); break; //last tile number (inclusive) + case T_XADD: scriptfile_getdouble(script,&xadd); break; + case T_YADD: scriptfile_getdouble(script,&yadd); break; + case T_ZADD: scriptfile_getdouble(script,&zadd); break; + case T_ANGADD:scriptfile_getdouble(script,&angadd); break; + case T_HIDE: flags |= 1; break; + case T_NOBOB: flags |= 2; break; + case T_FLIPPED: flags |= 4; break; + case T_NODEPTH: flags |= 8; break; + } + } - if (ftilenume < 0) initprintf("Error: missing 'first tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; - if (ltilenume < 0) initprintf("Error: missing 'last tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; - if (!happy) break; + if (ftilenume < 0) initprintf("Error: missing 'first tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; + if (ltilenume < 0) initprintf("Error: missing 'last tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; + if (!happy) break; - if (ltilenume < ftilenume) { - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)); - tilex = ftilenume; - ftilenume = ltilenume; - ltilenume = tilex; - } + if (ltilenume < ftilenume) { + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)); + tilex = ftilenume; + ftilenume = ltilenume; + ltilenume = tilex; + } - if (lastmodelid < 0) { - initprintf("Warning: Ignoring frame definition.\n"); - break; - } + if (lastmodelid < 0) { + initprintf("Warning: Ignoring frame definition.\n"); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { - switch (md_definehud(lastmodelid, tilex, xadd, yadd, zadd, angadd, flags)) { - case 0: break; - case -1: happy = 0; break; // invalid model id!? - case -2: initprintf("Invalid tile number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,hudtokptr)); - happy = 0; - break; - case -3: initprintf("Invalid frame name on line %s:%d\n", - script->filename, scriptfile_getlinum(script,hudtokptr)); - happy = 0; - break; - } - } + for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) { + switch (md_definehud(lastmodelid, tilex, xadd, yadd, zadd, angadd, flags)) { + case 0: break; + case -1: happy = 0; break; // invalid model id!? + case -2: initprintf("Invalid tile number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,hudtokptr)); + happy = 0; + break; + case -3: initprintf("Invalid frame name on line %s:%d\n", + script->filename, scriptfile_getlinum(script,hudtokptr)); + happy = 0; + break; + } + } #endif - } break; - } - } + } break; + } + } #if defined(POLYMOST) && defined(USE_OPENGL) - md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd); + md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd); #endif - modelskin = lastmodelskin = 0; - seenframe = 0; + modelskin = lastmodelskin = 0; + seenframe = 0; - } - break; - case T_VOXEL: - { - char *voxeltokptr = script->ltextptr; - char *fn, *modelend; - int tile0 = MAXTILES, tile1 = -1, tilex = -1; + } + break; + case T_VOXEL: + { + char *voxeltokptr = script->ltextptr; + char *fn, *modelend; + int tile0 = MAXTILES, tile1 = -1, tilex = -1; - if (scriptfile_getstring(script,&fn)) break; //voxel filename - if (nextvoxid == MAXVOXELS) { initprintf("Maximum number of voxels already defined.\n"); break; } + if (scriptfile_getstring(script,&fn)) break; //voxel filename + if (nextvoxid == MAXVOXELS) { initprintf("Maximum number of voxels already defined.\n"); break; } #ifdef SUPERBUILD - if (qloadkvx(nextvoxid, fn)) { initprintf("Failure loading voxel file \"%s\"\n",fn); break; } - lastvoxid = nextvoxid++; + if (qloadkvx(nextvoxid, fn)) { initprintf("Failure loading voxel file \"%s\"\n",fn); break; } + lastvoxid = nextvoxid++; #endif - if (scriptfile_getbraces(script,&modelend)) break; - while (script->textptr < modelend) { - switch (getatoken(script,voxeltokens,sizeof(voxeltokens)/sizeof(tokenlist))) { - //case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break; - case T_TILE: - scriptfile_getsymbol(script,&tilex); + if (scriptfile_getbraces(script,&modelend)) break; + while (script->textptr < modelend) { + switch (getatoken(script,voxeltokens,sizeof(voxeltokens)/sizeof(tokenlist))) { + //case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break; + case T_TILE: + scriptfile_getsymbol(script,&tilex); #ifdef SUPERBUILD - if ((unsigned long)tilex < MAXTILES) tiletovox[tilex] = lastvoxid; - else initprintf("Invalid tile number on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); + if ((unsigned long)tilex < MAXTILES) tiletovox[tilex] = lastvoxid; + else initprintf("Invalid tile number on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); #endif - break; - case T_TILE0: - scriptfile_getsymbol(script,&tile0); break; //1st tile # - case T_TILE1: - scriptfile_getsymbol(script,&tile1); - if (tile0 > tile1) - { - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,voxeltokptr)); - tilex = tile0; tile0 = tile1; tile1 = tilex; - } - if ((tile1 < 0) || (tile0 >= MAXTILES)) - { initprintf("Invalid tile range on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); break; } + break; + case T_TILE0: + scriptfile_getsymbol(script,&tile0); break; //1st tile # + case T_TILE1: + scriptfile_getsymbol(script,&tile1); + if (tile0 > tile1) + { + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,voxeltokptr)); + tilex = tile0; tile0 = tile1; tile1 = tilex; + } + if ((tile1 < 0) || (tile0 >= MAXTILES)) + { initprintf("Invalid tile range on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); break; } #ifdef SUPERBUILD - for(tilex=tile0;tilex<=tile1;tilex++) tiletovox[tilex] = lastvoxid; + for(tilex=tile0;tilex<=tile1;tilex++) tiletovox[tilex] = lastvoxid; #endif - break; //last tile number (inclusive) - case T_SCALE: { - double scale=1.0; - scriptfile_getdouble(script,&scale); + break; //last tile number (inclusive) + case T_SCALE: { + double scale=1.0; + scriptfile_getdouble(script,&scale); #ifdef SUPERBUILD - voxscale[lastvoxid] = 65536*scale; + voxscale[lastvoxid] = 65536*scale; #endif - break; - } - } - } - lastvoxid = -1; - } - break; - case T_SKYBOX: - { - char *skyboxtokptr = script->ltextptr; - char *fn[6] = {0,0,0,0,0,0}, *modelend, happy=1; - int i, tile = -1, pal = 0; + break; + } + } + } + lastvoxid = -1; + } + break; + case T_SKYBOX: + { + char *skyboxtokptr = script->ltextptr; + char *fn[6] = {0,0,0,0,0,0}, *modelend, happy=1; + int i, tile = -1, pal = 0; - if (scriptfile_getbraces(script,&modelend)) break; - while (script->textptr < modelend) { - switch (getatoken(script,skyboxtokens,sizeof(skyboxtokens)/sizeof(tokenlist))) { - //case T_ERROR: initprintf("Error on line %s:%d in skybox tokens\n",script->filename,linenum); break; - case T_TILE: scriptfile_getsymbol(script,&tile ); break; - case T_PAL: scriptfile_getsymbol(script,&pal ); break; - case T_FRONT: scriptfile_getstring(script,&fn[0]); break; - case T_RIGHT: scriptfile_getstring(script,&fn[1]); break; - case T_BACK: scriptfile_getstring(script,&fn[2]); break; - case T_LEFT: scriptfile_getstring(script,&fn[3]); break; - case T_TOP: scriptfile_getstring(script,&fn[4]); break; - case T_BOTTOM:scriptfile_getstring(script,&fn[5]); break; - } - } + if (scriptfile_getbraces(script,&modelend)) break; + while (script->textptr < modelend) { + switch (getatoken(script,skyboxtokens,sizeof(skyboxtokens)/sizeof(tokenlist))) { + //case T_ERROR: initprintf("Error on line %s:%d in skybox tokens\n",script->filename,linenum); break; + case T_TILE: scriptfile_getsymbol(script,&tile ); break; + case T_PAL: scriptfile_getsymbol(script,&pal ); break; + case T_FRONT: scriptfile_getstring(script,&fn[0]); break; + case T_RIGHT: scriptfile_getstring(script,&fn[1]); break; + case T_BACK: scriptfile_getstring(script,&fn[2]); break; + case T_LEFT: scriptfile_getstring(script,&fn[3]); break; + case T_TOP: scriptfile_getstring(script,&fn[4]); break; + case T_BOTTOM:scriptfile_getstring(script,&fn[5]); break; + } + } - if (tile < 0) initprintf("Error: missing 'tile number' for skybox definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0; - for (i=0;i<6;i++) { - if (!fn[i]) initprintf("Error: missing '%s filename' for skybox definition near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0; - } + if (tile < 0) initprintf("Error: missing 'tile number' for skybox definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0; + for (i=0;i<6;i++) { + if (!fn[i]) initprintf("Error: missing '%s filename' for skybox definition near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0; + } - if (!happy) break; - - hicsetskybox(tile,pal,fn); - } - break; - case T_TINT: - { - char *tinttokptr = script->ltextptr; - int red=255, green=255, blue=255, pal=-1, flags=0; - char *tintend; + if (!happy) break; - if (scriptfile_getbraces(script,&tintend)) break; - while (script->textptr < tintend) { - switch (getatoken(script,tinttokens,sizeof(tinttokens)/sizeof(tokenlist))) { - case T_PAL: scriptfile_getsymbol(script,&pal); break; - case T_RED: scriptfile_getnumber(script,&red); red = min(255,max(0,red)); break; - case T_GREEN: scriptfile_getnumber(script,&green); green = min(255,max(0,green)); break; - case T_BLUE: scriptfile_getnumber(script,&blue); blue = min(255,max(0,blue)); break; - case T_FLAGS: scriptfile_getsymbol(script,&flags); break; - } - } + hicsetskybox(tile,pal,fn); + } + break; + case T_TINT: + { + char *tinttokptr = script->ltextptr; + int red=255, green=255, blue=255, pal=-1, flags=0; + char *tintend; - if (pal < 0) { - initprintf("Error: missing 'palette number' for tint definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); - break; - } + if (scriptfile_getbraces(script,&tintend)) break; + while (script->textptr < tintend) { + switch (getatoken(script,tinttokens,sizeof(tinttokens)/sizeof(tokenlist))) { + case T_PAL: scriptfile_getsymbol(script,&pal); break; + case T_RED: scriptfile_getnumber(script,&red); red = min(255,max(0,red)); break; + case T_GREEN: scriptfile_getnumber(script,&green); green = min(255,max(0,green)); break; + case T_BLUE: scriptfile_getnumber(script,&blue); blue = min(255,max(0,blue)); break; + case T_FLAGS: scriptfile_getsymbol(script,&flags); break; + } + } - hicsetpalettetint(pal,red,green,blue,flags); - } - break; - case T_TEXTURE: - { - char *texturetokptr = script->ltextptr, *textureend; - int tile=-1; + if (pal < 0) { + initprintf("Error: missing 'palette number' for tint definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); + break; + } - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getbraces(script,&textureend)) break; - while (script->textptr < textureend) { - switch (getatoken(script,texturetokens,sizeof(texturetokens)/sizeof(tokenlist))) { - case T_PAL: { - char *paltokptr = script->ltextptr, *palend; - int pal=-1; - char *fn = NULL; - double alphacut = -1.0; - char flags = 0; + hicsetpalettetint(pal,red,green,blue,flags); + } + break; + case T_TEXTURE: + { + char *texturetokptr = script->ltextptr, *textureend; + int tile=-1; - if (scriptfile_getsymbol(script,&pal)) break; - if (scriptfile_getbraces(script,&palend)) break; - while (script->textptr < palend) { - switch (getatoken(script,texturetokens_pal,sizeof(texturetokens_pal)/sizeof(tokenlist))) { - case T_FILE: scriptfile_getstring(script,&fn); break; - case T_ALPHACUT: scriptfile_getdouble(script,&alphacut); break; - case T_NOCOMPRESS: flags |= 1; break; - default: break; - } - } + if (scriptfile_getsymbol(script,&tile)) break; + if (scriptfile_getbraces(script,&textureend)) break; + while (script->textptr < textureend) { + switch (getatoken(script,texturetokens,sizeof(texturetokens)/sizeof(tokenlist))) { + case T_PAL: { + char *paltokptr = script->ltextptr, *palend; + int pal=-1; + char *fn = NULL; + double alphacut = -1.0; + char flags = 0; - if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later - if ((unsigned)pal > (unsigned)MAXPALOOKUPS) { - initprintf("Error: missing or invalid 'palette number' for texture definition near " - "line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr)); - break; - } - if (!fn) { - initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", - script->filename, scriptfile_getlinum(script,paltokptr)); - break; - } - hicsetsubsttex(tile,pal,fn,alphacut,flags); - } break; - default: break; - } - } - - if ((unsigned)tile >= (unsigned)MAXTILES) { - initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n", - script->filename, scriptfile_getlinum(script,texturetokptr)); - break; - } - } - break; + if (scriptfile_getsymbol(script,&pal)) break; + if (scriptfile_getbraces(script,&palend)) break; + while (script->textptr < palend) { + switch (getatoken(script,texturetokens_pal,sizeof(texturetokens_pal)/sizeof(tokenlist))) { + case T_FILE: scriptfile_getstring(script,&fn); break; + case T_ALPHACUT: scriptfile_getdouble(script,&alphacut); break; + case T_NOCOMPRESS: flags |= 1; break; + default: break; + } + } - case T_UNDEFMODEL: - case T_UNDEFMODELRANGE: - { - int r0,r1; - - if (scriptfile_getsymbol(script,&r0)) break; - if (tokn == T_UNDEFMODELRANGE) { - if (scriptfile_getsymbol(script,&r1)) break; - if (r1 < r0) { - int t = r1; - r1 = r0; - r0 = t; - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - } - if (r0 < 0 || r1 >= MAXTILES) { - initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - } else { - r1 = r0; - if ((unsigned)r0 >= (unsigned)MAXTILES) { - initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - } + if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later + if ((unsigned)pal > (unsigned)MAXPALOOKUPS) { + initprintf("Error: missing or invalid 'palette number' for texture definition near " + "line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr)); + break; + } + if (!fn) { + initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", + script->filename, scriptfile_getlinum(script,paltokptr)); + break; + } + hicsetsubsttex(tile,pal,fn,alphacut,flags); + } break; + default: break; + } + } + + if ((unsigned)tile >= (unsigned)MAXTILES) { + initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n", + script->filename, scriptfile_getlinum(script,texturetokptr)); + break; + } + } + break; + + case T_UNDEFMODEL: + case T_UNDEFMODELRANGE: + { + int r0,r1; + + if (scriptfile_getsymbol(script,&r0)) break; + if (tokn == T_UNDEFMODELRANGE) { + if (scriptfile_getsymbol(script,&r1)) break; + if (r1 < r0) { + int t = r1; + r1 = r0; + r0 = t; + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + } + if (r0 < 0 || r1 >= MAXTILES) { + initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } + } else { + r1 = r0; + if ((unsigned)r0 >= (unsigned)MAXTILES) { + initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } + } #if defined(POLYMOST) && defined(USE_OPENGL) - for (; r0 <= r1; r0++) md_undefinetile(r0); + for (; r0 <= r1; r0++) md_undefinetile(r0); #endif - } - break; + } + break; - case T_UNDEFMODELOF: - { - int mid,r0; + case T_UNDEFMODELOF: + { + int mid,r0; - if (scriptfile_getsymbol(script,&r0)) break; - if ((unsigned)r0 >= (unsigned)MAXTILES) { - initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } + if (scriptfile_getsymbol(script,&r0)) break; + if ((unsigned)r0 >= (unsigned)MAXTILES) { + initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } #if defined(POLYMOST) && defined(USE_OPENGL) - mid = md_tilehasmodel(r0); - if (mid < 0) break; + mid = md_tilehasmodel(r0); + if (mid < 0) break; - md_undefinemodel(mid); + md_undefinemodel(mid); #endif - } - break; + } + break; - case T_UNDEFTEXTURE: - case T_UNDEFTEXTURERANGE: - { - int r0,r1,i; + case T_UNDEFTEXTURE: + case T_UNDEFTEXTURERANGE: + { + int r0,r1,i; - if (scriptfile_getsymbol(script,&r0)) break; - if (tokn == T_UNDEFTEXTURERANGE) { - if (scriptfile_getsymbol(script,&r1)) break; - if (r1 < r0) { - int t = r1; - r1 = r0; - r0 = t; - initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - } - if (r0 < 0 || r1 >= MAXTILES) { - initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - } else { - r1 = r0; - if ((unsigned)r0 >= (unsigned)MAXTILES) { - initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - } + if (scriptfile_getsymbol(script,&r0)) break; + if (tokn == T_UNDEFTEXTURERANGE) { + if (scriptfile_getsymbol(script,&r1)) break; + if (r1 < r0) { + int t = r1; + r1 = r0; + r0 = t; + initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + } + if (r0 < 0 || r1 >= MAXTILES) { + initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } + } else { + r1 = r0; + if ((unsigned)r0 >= (unsigned)MAXTILES) { + initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); + break; + } + } - for (; r0 <= r1; r0++) - for (i=MAXPALOOKUPS-1; i>=0; i--) - hicclearsubst(r0,i); - } - break; - - default: - initprintf("Unknown token.\n"); break; - } - } - return 0; + for (; r0 <= r1; r0++) + for (i=MAXPALOOKUPS-1; i>=0; i--) + hicclearsubst(r0,i); + } + break; + + default: + initprintf("Unknown token.\n"); break; + } + } + return 0; } int loaddefinitionsfile(char *fn) { - scriptfile *script; + scriptfile *script; - script = scriptfile_fromfile(fn); - if (!script) return -1; + script = scriptfile_fromfile(fn); + if (!script) return -1; - defsparser(script); + defsparser(script); - scriptfile_close(script); - scriptfile_clearsymbols(); + scriptfile_close(script); + scriptfile_clearsymbols(); - return 0; + return 0; } static int defsparserpassone(scriptfile *script) { - int tokn; - char *cmdtokptr; - while (1) { - tokn = getatoken(script,basetokens,sizeof(basetokens)/sizeof(tokenlist)); - cmdtokptr = script->ltextptr; - switch (tokn) { - case T_LOADGRP: - { - char *fn; - if (!scriptfile_getstring(script,&fn)) - { - int j = initgroupfile(fn); + int tokn; + char *cmdtokptr; + while (1) { + tokn = getatoken(script,basetokens,sizeof(basetokens)/sizeof(tokenlist)); + cmdtokptr = script->ltextptr; + switch (tokn) { + case T_LOADGRP: + { + char *fn; + if (!scriptfile_getstring(script,&fn)) + { + int j = initgroupfile(fn); - if( j == -1 ) - initprintf("Could not find GRP file %s.\n",fn); - else - initprintf("Using GRP file %s.\n",fn); - } - } - break; - case T_EOF: - return(0); - default: - break; - } - } - return 0; + if( j == -1 ) + initprintf("Could not find GRP file %s.\n",fn); + else + initprintf("Using GRP file %s.\n",fn); + } + } + break; + case T_EOF: + return(0); + default: + break; + } + } + return 0; } int loadgroupfiles(char *fn) { - scriptfile *script; + scriptfile *script; - script = scriptfile_fromfile(fn); - if (!script) return -1; + script = scriptfile_fromfile(fn); + if (!script) return -1; - defsparserpassone(script); + defsparserpassone(script); - scriptfile_close(script); - scriptfile_clearsymbols(); + scriptfile_close(script); + scriptfile_clearsymbols(); - return 0; + return 0; } // vim:ts=4: diff --git a/polymer/build/src/engine.c b/polymer/build/src/engine.c index 756fd13d5..57a01c381 100644 --- a/polymer/build/src/engine.c +++ b/polymer/build/src/engine.c @@ -56,7 +56,7 @@ long usevoxels = 1; long novoxmips = 0; long editorgridextent = 131072; - //These variables need to be copied into BUILD +//These variables need to be copied into BUILD #define MAXXSIZ 256 #define MAXYSIZ 256 #define MAXZSIZ 255 @@ -77,7 +77,7 @@ static long oxdimen = -1, oviewingrange = -1, oxyaspect = -1; long curbrightness = 0, gammabrightness = 0; - //Textured Map variables +//Textured Map variables static char globalpolytype; static short *dotp1[MAXYDIM], *dotp2[MAXYDIM]; @@ -102,16 +102,16 @@ static short radarang[1280], radarang2[MAXXDIM]; static unsigned short sqrtable[4096], shlookup[4096+256]; char pow2char[8] = {1,2,4,8,16,32,64,128}; long pow2long[32] = -{ - 1L,2L,4L,8L, - 16L,32L,64L,128L, - 256L,512L,1024L,2048L, - 4096L,8192L,16384L,32768L, - 65536L,131072L,262144L,524288L, - 1048576L,2097152L,4194304L,8388608L, - 16777216L,33554432L,67108864L,134217728L, - 268435456L,536870912L,1073741824L,2147483647L -}; + { + 1L,2L,4L,8L, + 16L,32L,64L,128L, + 256L,512L,1024L,2048L, + 4096L,8192L,16384L,32768L, + 65536L,131072L,262144L,524288L, + 1048576L,2097152L,4194304L,8388608L, + 16777216L,33554432L,67108864L,134217728L, + 268435456L,536870912L,1073741824L,2147483647L + }; long reciptable[2048], fpuasm; char britable[16][256]; // JBF 20040207: full 8bit precision @@ -132,18 +132,18 @@ static inline unsigned long nsqrtasm(unsigned long a) if (a & 0xff000000) { // test eax, 0xff000000 / jnz short over24 c = shlookup[(a >> 24) + 4096]; // mov ebx, eax - // over24: shr ebx, 24 - // mov cx, word ptr shlookup[ebx*2+8192] + // over24: shr ebx, 24 + // mov cx, word ptr shlookup[ebx*2+8192] } else { c = shlookup[a >> 12]; // mov ebx, eax - // shr ebx, 12 - // mov cx, word ptr shlookup[ebx*2] - // jmp short under24 + // shr ebx, 12 + // mov cx, word ptr shlookup[ebx*2] + // jmp short under24 } a >>= c&0xff; // under24: shr eax, cl a = (a&0xffff0000)|(sqrtable[a]); // mov ax, word ptr sqrtable[eax*2] a >>= ((c&0xff00) >> 8); // mov cl, ch - // shr eax, cl + // shr eax, cl return a; } @@ -234,7 +234,7 @@ unsigned long nsqrtasm(unsigned long); modify exact [eax ebx ecx] long msqrtasm(unsigned long); - //0x007ff000 is (11<<13), 0x3f800000 is (127<<23) +//0x007ff000 is (11<<13), 0x3f800000 is (127<<23) #pragma aux krecipasm =\ "mov fpuasm, eax",\ "fild dword ptr fpuasm",\ @@ -350,7 +350,7 @@ static inline long msqrtasm(long c) } } - //0x007ff000 is (11<<13), 0x3f800000 is (127<<23) +//0x007ff000 is (11<<13), 0x3f800000 is (127<<23) static inline long krecipasm(long a) { _asm { @@ -359,20 +359,20 @@ static inline long krecipasm(long a) mov fpuasm, eax fild dword ptr fpuasm add eax, eax - fstp dword ptr fpuasm - sbb ebx, ebx - mov eax, fpuasm - mov ecx, eax - and eax, 0x007ff000 - shr eax, 10 - sub ecx, 0x3f800000 - shr ecx, 23 - mov eax, dword ptr reciptable[eax] - sar eax, cl - xor eax, ebx - pop ebx + fstp dword ptr fpuasm + sbb ebx, ebx + mov eax, fpuasm + mov ecx, eax + and eax, 0x007ff000 + shr eax, 10 + sub ecx, 0x3f800000 + shr ecx, 23 + mov eax, dword ptr reciptable[eax] + sar eax, cl + xor eax, ebx + pop ebx + } } -} static inline void setgotpic(long a) { @@ -404,18 +404,18 @@ static inline long getclipmask(long a, long b, long c, long d) mov edx, d sar eax, 31 add ebx, ebx - adc eax, eax - add ecx, ecx - adc eax, eax - add edx, edx - adc eax, eax - mov ebx, eax - shl ebx, 4 - or al, 0xf0 - xor eax, ebx - pop ebx - } -} + adc eax, eax + add ecx, ecx + adc eax, eax + add edx, edx + adc eax, eax + mov ebx, eax + shl ebx, 4 + or al, 0xf0 + xor eax, ebx + pop ebx + } + } static inline long getkensmessagecrc(void *b) { @@ -460,7 +460,7 @@ static inline long getkensmessagecrc(void *b) : "=a" (__r) : "a" (__a) : "ebx", "ecx", "cc"); \ __r; }) - // edx is blown by this code somehow?! +// edx is blown by this code somehow?! #define msqrtasm(c) \ ({ long __r, __c=(c); \ __asm__ __volatile__ ( \ @@ -642,12 +642,12 @@ short numscans, numhits, numbunches; static short posfil, capturecount = 0, hitcnt; char vgapal16[4*256] = -{ - 00,00,00,00, 42,00,00,00, 00,42,00,00, 42,42,00,00, 00,00,42,00, - 42,00,42,00, 00,21,42,00, 42,42,42,00, 21,21,21,00, 63,21,21,00, - 21,63,21,00, 63,63,21,00, 21,21,63,00, 63,21,63,00, 21,63,63,00, - 63,63,63,00 -}; + { + 00,00,00,00, 42,00,00,00, 00,42,00,00, 42,42,00,00, 00,00,42,00, + 42,00,42,00, 00,21,42,00, 42,42,42,00, 21,21,21,00, 63,21,21,00, + 21,63,21,00, 63,63,21,00, 21,21,63,00, 63,21,63,00, 21,63,63,00, + 63,63,63,00 + }; short editstatus = 0; short searchit; @@ -734,8 +734,8 @@ static void scansector(short sectnum) { spr = &sprite[z]; if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) && - (spr->xrepeat > 0) && (spr->yrepeat > 0) && - (spritesortcnt < MAXSPRITESONSCREEN)) + (spr->xrepeat > 0) && (spr->yrepeat > 0) && + (spritesortcnt < MAXSPRITESONSCREEN)) { xs = spr->x-globalposx; ys = spr->y-globalposy; if ((spr->cstat&48) || (xs*cosglobalang+ys*singlobalang > 0)) @@ -785,7 +785,7 @@ static void scansector(short sectnum) yp2 = dmulscale6(x2,cosviewingrangeglobalang,y2,sinviewingrangeglobalang); if ((yp1 < 256) && (yp2 < 256)) goto skipitaddwall; - //If wall's NOT facing you + //If wall's NOT facing you if (dmulscale32(xp1,yp2,-xp2,yp1) >= 0) goto skipitaddwall; if (xp1 >= -yp1) @@ -824,7 +824,7 @@ static void scansector(short sectnum) } if ((yb2[numscans] < 256) || (xb1[numscans] > xb2[numscans])) goto skipitaddwall; - //Made it all the way! + //Made it all the way! thesector[numscans] = sectnum; thewall[numscans] = z; rx1[numscans] = xp1; ry1[numscans] = yp1; rx2[numscans] = xp2; ry2[numscans] = yp2; @@ -894,7 +894,7 @@ static void maskwallscan(long x1, long x2, short *uwal, short *dwal, long *swal, palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -969,7 +969,7 @@ static void maskwallscan(long x1, long x2, short *uwal, short *dwal, long *swal, palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -990,7 +990,7 @@ static void maskwallscan(long x1, long x2, short *uwal, short *dwal, long *swal, palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -1078,7 +1078,7 @@ static long spriteobstructswall(spritetype *s, long w) a1 = 1e+37; // not infinite, but almost ;) b1 = -1; c1 = (y1 - (a1 * x1)); - + // player to sprite line equation if ((s->x - globalposx) != 0) a2 = (float)(s->y - globalposy)/(s->x - globalposx); @@ -1086,7 +1086,7 @@ static long spriteobstructswall(spritetype *s, long w) a2 = 1e+37; b2 = -1; c2 = 0; - + // intersection point d1 = (float)(1) / (a1*b2 - a2*b1); x = ((b1*c2 - b2*c1) * d1); @@ -1096,10 +1096,10 @@ static long spriteobstructswall(spritetype *s, long w) a1 = s->x - globalposx; b1 = s->y - globalposy; d1 = (a1 * a1 + b1 * b1); - + // distance between the intersection point and the player d2 = (x * x + y * y); - + // check if the sprite obstructs the wall if ((d1 < d2) && (min(x1, x2) <= x) && (x <= max(x1, x2)) && (min(y1, y2) <= y) && (y <= max(y1, y2))) return (1); @@ -1143,7 +1143,7 @@ static void hline(long xr, long yp) s = ((long)getpalookup((long)mulscale16(r,globvis),globalshade)<<8); hlineasm4(xr-xl,0L,s,globalx2*r+globalypanning,globaly1*r+globalxpanning, - ylookup[yp]+xr+frameoffset); + ylookup[yp]+xr+frameoffset); } @@ -1163,11 +1163,11 @@ static void slowhline(long xr, long yp) if (!(globalorientation&256)) { mhline(globalbufplc,globaly1*r+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L, - globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); + globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); return; } thline(globalbufplc,globaly1*r+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L, - globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); + globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); } @@ -1180,7 +1180,7 @@ static void prepwall(long z, walltype *wal) walxrepeat = (wal->xrepeat<<3); - //lwall calculation + //lwall calculation i = xb1[z]-halfxdimen; topinc = -(ry1[z]>>2); botinc = ((ry2[z]-ry1[z])>>8); @@ -1265,18 +1265,18 @@ static long animateoffs(short tilenum, short fakevar) { switch(picanm[tilenum]&192) { - case 64: - k = (i%((picanm[tilenum]&63)<<1)); - if (k < (picanm[tilenum]&63)) - offs = k; - else - offs = (((picanm[tilenum]&63)<<1)-k); - break; - case 128: - offs = (i%((picanm[tilenum]&63)+1)); - break; - case 192: - offs = -(i%((picanm[tilenum]&63)+1)); + case 64: + k = (i%((picanm[tilenum]&63)<<1)); + if (k < (picanm[tilenum]&63)) + offs = k; + else + offs = (((picanm[tilenum]&63)<<1)-k); + break; + case 128: + offs = (i%((picanm[tilenum]&63)+1)); + break; + case 192: + offs = -(i%((picanm[tilenum]&63)+1)); } } return(offs); @@ -1399,9 +1399,9 @@ static long wallmost(short *mostbuf, long w, long sectnum, char dastat) dasqr = krecipasm(nsqrtasm(dx*dx+dy*dy)); if (xb1[w] == 0) - { xv = cosglobalang+sinviewingrangeglobalang; yv = singlobalang-cosviewingrangeglobalang; } + { xv = cosglobalang+sinviewingrangeglobalang; yv = singlobalang-cosviewingrangeglobalang; } else - { xv = x1-globalposx; yv = y1-globalposy; } + { xv = x1-globalposx; yv = y1-globalposy; } i = xv*(y1-globalposy)-yv*(x1-globalposx); j = yv*x2-xv*y2; if (klabs(j) > klabs(i>>3)) i = divscale28(i,j); if (dastat == 0) @@ -1415,13 +1415,13 @@ static long wallmost(short *mostbuf, long w, long sectnum, char dastat) z1 = sector[sectnum].floorz; } z1 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8), - -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z1-globalposz)<<7); + -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z1-globalposz)<<7); if (xb2[w] == xdimen-1) - { xv = cosglobalang-sinviewingrangeglobalang; yv = singlobalang+cosviewingrangeglobalang; } + { xv = cosglobalang-sinviewingrangeglobalang; yv = singlobalang+cosviewingrangeglobalang; } else - { xv = (x2+x1)-globalposx; yv = (y2+y1)-globalposy; } + { xv = (x2+x1)-globalposx; yv = (y2+y1)-globalposy; } i = xv*(y1-globalposy)-yv*(x1-globalposx); j = yv*x2-xv*y2; if (klabs(j) > klabs(i>>3)) i = divscale28(i,j); if (dastat == 0) @@ -1435,7 +1435,7 @@ static long wallmost(short *mostbuf, long w, long sectnum, char dastat) z2 = sector[sectnum].floorz; } z2 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8), - -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z2-globalposz)<<7); + -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z2-globalposz)<<7); s1 = mulscale20(globaluclip,yb1[w]); s2 = mulscale20(globaluclip,yb2[w]); @@ -1462,7 +1462,7 @@ static long wallmost(short *mostbuf, long w, long sectnum, char dastat) if (bad&3) { - //inty = intz / (globaluclip>>16) + //inty = intz / (globaluclip>>16) t = divscale30(oz1-s1,s2-s1+oz1-oz2); inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); intz = oz1 + mulscale30(oz2-oz1,t); @@ -1488,7 +1488,7 @@ static long wallmost(short *mostbuf, long w, long sectnum, char dastat) if (bad&12) { - //inty = intz / (globaldclip>>16) + //inty = intz / (globaldclip>>16) t = divscale30(oz1-s3,s4-s3+oz1-oz2); inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); intz = oz1 + mulscale30(oz2-oz1,t); @@ -1587,7 +1587,7 @@ static void ceilscan(long x1, long x2, long sectnum) globaly1 = mulscale16(globaly1,viewingrangerecip); globalxshift = (8-(picsiz[globalpicnum]&15)); globalyshift = (8-(picsiz[globalpicnum]>>4)); - if (globalorientation&8) { globalxshift++; globalyshift++; } +if (globalorientation&8) { globalxshift++; globalyshift++; } if ((globalorientation&0x4) > 0) { @@ -1639,7 +1639,7 @@ static void ceilscan(long x1, long x2, long sectnum) else { while (y1 < y2-1) hline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } + if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } y1 = umost[x+1]; y2 = y1; } globalx2 += globaly2; globaly1 += globalx1; @@ -1651,17 +1651,17 @@ static void ceilscan(long x1, long x2, long sectnum) switch(globalorientation&0x180) { - case 128: - msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 256: - settransnormal(); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 384: - settransreverse(); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; + case 128: + msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; + case 256: + settransnormal(); + tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; + case 384: + settransreverse(); + tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; } y1 = umost[x1]; y2 = y1; @@ -1686,7 +1686,7 @@ static void ceilscan(long x1, long x2, long sectnum) else { while (y1 < y2-1) slowhline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } + if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } y1 = umost[x+1]; y2 = y1; } globalx2 += globaly2; globaly1 += globalx1; @@ -1758,7 +1758,7 @@ static void florscan(long x1, long x2, long sectnum) globaly1 = mulscale16(globaly1,viewingrangerecip); globalxshift = (8-(picsiz[globalpicnum]&15)); globalyshift = (8-(picsiz[globalpicnum]>>4)); - if (globalorientation&8) { globalxshift++; globalyshift++; } +if (globalorientation&8) { globalxshift++; globalyshift++; } if ((globalorientation&0x4) > 0) { @@ -1810,7 +1810,7 @@ static void florscan(long x1, long x2, long sectnum) else { while (y1 < y2-1) hline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } + if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } y1 = max(dplc[x+1],umost[x+1]); y2 = y1; } globalx2 += globaly2; globaly1 += globalx1; @@ -1822,17 +1822,17 @@ static void florscan(long x1, long x2, long sectnum) switch(globalorientation&0x180) { - case 128: - msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 256: - settransnormal(); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 384: - settransreverse(); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; + case 128: + msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; + case 256: + settransnormal(); + tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; + case 384: + settransreverse(); + tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); + break; } y1 = max(dplc[x1],umost[x1]); y2 = y1; @@ -1857,7 +1857,7 @@ static void florscan(long x1, long x2, long sectnum) else { while (y1 < y2-1) slowhline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } + if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } y1 = max(dplc[x+1],umost[x+1]); y2 = y1; } globalx2 += globaly2; globaly1 += globalx1; @@ -1908,7 +1908,7 @@ static void wallscan(long x1, long x2, short *uwal, short *dwal, long *swal, lon palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -1983,7 +1983,7 @@ static void wallscan(long x1, long x2, short *uwal, short *dwal, long *swal, lon palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -2003,7 +2003,7 @@ static void wallscan(long x1, long x2, short *uwal, short *dwal, long *swal, lon palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8); bufplce[0] = lwal[x] + globalxpanning; - if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } + if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; } if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy; vince[0] = swal[x]*globalyscale; @@ -2011,7 +2011,7 @@ static void wallscan(long x1, long x2, short *uwal, short *dwal, long *swal, lon vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],x+frameoffset+ylookup[y1ve[0]]); } - + #endif faketimerhandler(); @@ -2058,7 +2058,7 @@ static void transmaskvline2(long x) short y1ve[2], y2ve[2]; if ((x < 0) || (x >= xdimen)) return; - if (x == xdimen-1) { transmaskvline(x); return; } +if (x == xdimen-1) { transmaskvline(x); return; } x2 = x+1; @@ -2153,9 +2153,9 @@ static void ceilspritehline(long x2, long y) { long x1, v, bx, by; - //x = x1 + (x2-x1)t + (y1-y2)u ~ x = 160v - //y = y1 + (y2-y1)t + (x2-x1)u ~ y = (scrx-160)v - //z = z1 = z2 ~ z = posz + (scry-horiz)v + //x = x1 + (x2-x1)t + (y1-y2)u ~ x = 160v + //y = y1 + (y2-y1)t + (x2-x1)u ~ y = (scrx-160)v + //z = z1 = z2 ~ z = posz + (scry-horiz)v x1 = lastx[y]; if (x2 < x1) return; @@ -2338,7 +2338,7 @@ static void grouscan(long dax1, long dax2, long sectnum, char dastat) if (shinc > 0) shoffs = (4<<15); else shoffs = ((16380-ydimen)<<15); // JBF: was 2044 if (dastat == 0) y1 = umost[dax1]; else y1 = max(umost[dax1],dplc[dax1]); m1 = mulscale16(y1,globalzd) + (globalzx>>6); - //Avoid visibility overflow by crossing horizon + //Avoid visibility overflow by crossing horizon if (globalzd > 0) m1 += (globalzd>>16); else m1 -= (globalzd>>16); m2 = m1+l; mptr1 = (long *)&slopalookup[y1+(shoffs>>15)]; mptr2 = mptr1+1; @@ -2433,7 +2433,7 @@ static void parascan(long dax1, long dax2, long sectnum, char dastat, long bunch wallnum = thewall[z]; nextsectnum = wall[wallnum].nextsector; if (dastat == 0) j = sector[nextsectnum].ceilingstat; - else j = sector[nextsectnum].floorstat; + else j = sector[nextsectnum].floorstat; if ((nextsectnum < 0) || (wall[wallnum].cstat&32) || ((j&1) == 0)) { @@ -2560,7 +2560,7 @@ static void drawalls(long bunch) parascan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1,bunch); } - //DRAW WALLS SECTION! + //DRAW WALLS SECTION! for(z=bunchfirst[bunch];z>=0;z=p2[z]) { x1 = xb1[z]; x2 = xb2[z]; @@ -2657,7 +2657,7 @@ static void drawalls(long bunch) globalzd += (globalypanning<<24); if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd; - if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } + if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } wallscan(x1,x2,uplc,dwall,swall,lwall); if ((cz[2] >= cz[0]) && (cz[3] >= cz[1])) @@ -2763,7 +2763,7 @@ static void drawalls(long bunch) globalzd += (globalypanning<<24); if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd; - if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } + if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } wallscan(x1,x2,uwall,dplc,swall,lwall); if ((fz[2] <= fz[0]) && (fz[3] <= fz[1])) @@ -2813,10 +2813,10 @@ static void drawalls(long bunch) { for(x=x1;xcstat; if (nextsectnum < 0) globalpicnum = wal->picnum; - else globalpicnum = wal->overpicnum; + else globalpicnum = wal->overpicnum; if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0; globalxpanning = (long)wal->xpanning; globalypanning = (long)wal->ypanning; @@ -2849,22 +2849,22 @@ static void drawalls(long bunch) if (nextsectnum >= 0) { if ((globalorientation&4) == 0) globalzd = globalposz-nextsec->ceilingz; - else globalzd = globalposz-sec->ceilingz; + else globalzd = globalposz-sec->ceilingz; } else { if ((globalorientation&4) == 0) globalzd = globalposz-sec->ceilingz; - else globalzd = globalposz-sec->floorz; + else globalzd = globalposz-sec->floorz; } globalzd = ((globalzd*globalyscale)<<8) + (globalypanning<<24); if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd; - if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } + if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } wallscan(x1,x2,uplc,dplc,swall,lwall); for(x=x1;x<=x2;x++) if (umost[x] <= dmost[x]) - { umost[x] = 1; dmost[x] = 0; numhits--; } + { umost[x] = 1; dmost[x] = 0; numhits--; } smostwall[smostwallcnt] = z; smostwalltype[smostwallcnt] = 0; smostwallcnt++; @@ -2884,8 +2884,8 @@ static void drawalls(long bunch) // #ifdef SUPERBUILD static void drawvox(long dasprx, long daspry, long dasprz, long dasprang, - long daxscale, long dayscale, char daindex, - signed char dashade, char dapal, long *daumost, long *dadmost) + long daxscale, long dayscale, char daindex, + signed char dashade, char dapal, long *daumost, long *dadmost) { long i, j, k, x, y, syoff, ggxstart, ggystart, nxoff; long cosang, sinang, sprcosang, sprsinang, backx, backy, gxinc, gyinc; @@ -2916,11 +2916,11 @@ static void drawvox(long dasprx, long daspry, long dasprz, long dasprang, if (novoxmips) i = 0; davoxptr = (char *)voxoff[daindex][i]; - if (!davoxptr && i > 0) { davoxptr = (char *)voxoff[daindex][0]; i = 0; } +if (!davoxptr && i > 0) { davoxptr = (char *)voxoff[daindex][0]; i = 0; } if (!davoxptr) return; if (voxscale[daindex] == 65536) - { daxscale <<= (i+8); dayscale <<= (i+8); } + { daxscale <<= (i+8); dayscale <<= (i+8); } else { daxscale = mulscale8(daxscale< 0) { dagxinc = gxinc; dagyinc = mulscale16(gyinc,viewingrangerecip); } + if (yi > 0) { dagxinc = gxinc; dagyinc = mulscale16(gyinc,viewingrangerecip); } else { dagxinc = -gxinc; dagyinc = -mulscale16(gyinc,viewingrangerecip); } - //Fix for non 90 degree viewing ranges + //Fix for non 90 degree viewing ranges nxoff = mulscale16(x2-x1,viewingrangerecip); x1 = mulscale16(x1,viewingrangerecip); @@ -3092,7 +3092,7 @@ static void drawvox(long dasprx, long daspry, long dasprz, long dasprang, { if (z2-z1 >= 1024) yinc = divscale16(voxptr[1],z2-z1); else if (z2 > z1) yinc = (lowrecip[z2-z1]*voxptr[1]>>8); - if (z1 < daumost[lx]) { yplc = yinc*(daumost[lx]-z1); z1 = daumost[lx]; } else yplc = 0; + if (z1 < daumost[lx]) { yplc = yinc*(daumost[lx]-z1); z1 = daumost[lx]; } else yplc = 0; } if (z2 > dadmost[lx]) z2 = dadmost[lx]; z2 -= z1; if (z2 <= 0) continue; @@ -3143,9 +3143,9 @@ static void drawsprite(long snum) if ((cstat&48)==48) vtilenum = tilenum; // if the game wants voxels, it gets voxels else if ((cstat&48)!=48 && (usevoxels) && (tiletovox[tilenum] != -1) #if defined(POLYMOST) && defined(USE_OPENGL) - && (!(spriteext[tspr->owner].flags&SPREXT_NOTMD)) + && (!(spriteext[tspr->owner].flags&SPREXT_NOTMD)) #endif - ) { + ) { vtilenum = tiletovox[tilenum]; cstat |= 48; } @@ -3260,26 +3260,26 @@ static void drawsprite(long snum) switch(smostwalltype[i]) { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (k=dalx2; k<=darx2; k++) dwall[k] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - if ((dalx2 == lx) && (darx2 == rx)) daclip |= 1; - break; - case 2: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - if ((dalx2 == lx) && (darx2 == rx)) daclip |= 2; - break; + case 0: + if (dalx2 <= darx2) + { + if ((dalx2 == lx) && (darx2 == rx)) return; + //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); + for (k=dalx2; k<=darx2; k++) dwall[k] = 0; + } + break; + case 1: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; + if ((dalx2 == lx) && (darx2 == rx)) daclip |= 1; + break; + case 2: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; + if ((dalx2 == lx) && (darx2 == rx)) daclip |= 2; + break; } } @@ -3290,7 +3290,7 @@ static void drawsprite(long snum) if (x == rx) return; } - //sprite + //sprite if ((searchit >= 1) && (searchx >= lx) && (searchx <= rx)) if ((searchy >= uwall[searchx]) && (searchy < dwall[searchx])) { @@ -3475,7 +3475,7 @@ static void drawsprite(long snum) owallmost(uwall,(long)(MAXWALLSB-1),z1-globalposz); owallmost(dwall,(long)(MAXWALLSB-1),z2-globalposz); for(i=xb1[MAXWALLSB-1];i<=xb2[MAXWALLSB-1];i++) - { swall[i] = (krecipasm(hplc)<<2); hplc += hinc; } + { swall[i] = (krecipasm(hplc)<<2); hplc += hinc; } for(i=smostwallcnt-1;i>=0;i--) { @@ -3529,9 +3529,9 @@ static void drawsprite(long snum) if (xp1 >= 0) x++; //Fix for SIGNED divide if (z1 < 0) - { if (dalx2 < x) dalx2 = x; } + { if (dalx2 < x) dalx2 = x; } else - { if (darx2 > x) darx2 = x; } + { if (darx2 > x) darx2 = x; } x = 0x80000001; } else @@ -3546,30 +3546,30 @@ static void drawsprite(long snum) if (darx2 > xb2[MAXWALLSB-1]) darx2 = xb2[MAXWALLSB-1]; switch(smostwalltype[i]) { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == xb1[MAXWALLSB-1]) && (darx2 == xb2[MAXWALLSB-1])) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (k=dalx2; k<=darx2; k++) dwall[k] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; + case 0: + if (dalx2 <= darx2) + { + if ((dalx2 == xb1[MAXWALLSB-1]) && (darx2 == xb2[MAXWALLSB-1])) return; + //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); + for (k=dalx2; k<=darx2; k++) dwall[k] = 0; + } + break; + case 1: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; + break; + case 2: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; + break; } } } } - //sprite + //sprite if ((searchit >= 1) && (searchx >= xb1[MAXWALLSB-1]) && (searchx <= xb2[MAXWALLSB-1])) if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx])) { @@ -3594,13 +3594,13 @@ static void drawsprite(long snum) xspan = tilesizx[tilenum]; yspan = tilesizy[tilenum]; - //Rotate center point + //Rotate center point dax = tspr->x-globalposx; day = tspr->y-globalposy; rzi[0] = dmulscale10(cosglobalang,dax,singlobalang,day); rxi[0] = dmulscale10(cosglobalang,day,-singlobalang,dax); - //Get top-left corner + //Get top-left corner i = ((tspr->ang+2048-globalang)&2047); cosang = sintable[(i+512)&2047]; sinang = sintable[i]; dax = ((xspan>>1)+xoff)*tspr->xrepeat; @@ -3608,7 +3608,7 @@ static void drawsprite(long snum) rzi[0] += dmulscale12(sinang,dax,cosang,day); rxi[0] += dmulscale12(sinang,day,-cosang,dax); - //Get other 3 corners + //Get other 3 corners dax = xspan*tspr->xrepeat; day = yspan*tspr->yrepeat; rzi[1] = rzi[0]-mulscale12(sinang,dax); @@ -3618,15 +3618,15 @@ static void drawsprite(long snum) rzi[2] = rzi[1]+dax; rxi[2] = rxi[1]+day; rzi[3] = rzi[0]+dax; rxi[3] = rxi[0]+day; - //Put all points on same z + //Put all points on same z ryi[0] = scale((tspr->z-globalposz),yxaspect,320<<8); if (ryi[0] == 0) return; ryi[1] = ryi[2] = ryi[3] = ryi[0]; if ((cstat&4) == 0) - { z = 0; z1 = 1; z2 = 3; } + { z = 0; z1 = 1; z2 = 3; } else - { z = 1; z1 = 0; z2 = 2; } + { z = 1; z1 = 0; z2 = 2; } dax = rzi[z1]-rzi[z]; day = rxi[z1]-rxi[z]; bot = dmulscale8(dax,dax,day,day); @@ -3640,7 +3640,7 @@ static void drawsprite(long snum) globaly1 = divscale18(dax,bot); globaly2 = divscale18(day,bot); - //Calculate globals for hline texture mapping function + //Calculate globals for hline texture mapping function globalxpanning = (rxi[z]<<12); globalypanning = (rzi[z]<<12); globalzd = (ryi[z]<<12); @@ -3657,10 +3657,10 @@ static void drawsprite(long snum) } - //Clip polygon in 3-space + //Clip polygon in 3-space npoints = 4; - //Clip edge 1 + //Clip edge 1 npoints2 = 0; zzsgn = rxi[0]+rzi[0]; for(z=0;z rmax) rmax = xsi[z], rpoint = z; } - //Get uwall arrays + //Get uwall arrays for(z=lpoint;z!=rpoint;z=zz) { zz = z+1; if (zz == npoints) zz = 0; @@ -3786,7 +3786,7 @@ static void drawsprite(long snum) } } - //Get dwall arrays + //Get dwall arrays for(;z!=lpoint;z=zz) { zz = z+1; if (zz == npoints) zz = 0; @@ -3810,14 +3810,14 @@ static void drawsprite(long snum) dwall[x] = min(dwall[x],startdmost[x+windowx1]-windowy1); } - //Additional uwall/dwall clipping goes here + //Additional uwall/dwall clipping goes here for(i=smostwallcnt-1;i>=0;i--) { j = smostwall[i]; if ((xb1[j] > rx) || (xb2[j] < lx)) continue; if ((yp <= yb1[j]) && (yp <= yb2[j])) continue; - //if (spritewallfront(tspr,thewall[j]) == 0) + //if (spritewallfront(tspr,thewall[j]) == 0) x = thewall[j]; xp1 = wall[x].x; yp1 = wall[x].y; x = wall[x].point2; xp2 = wall[x].x; yp2 = wall[x].y; x = (xp2-xp1)*(tspr->y-yp1)-(tspr->x-xp1)*(yp2-yp1); @@ -3828,28 +3828,28 @@ static void drawsprite(long snum) switch(smostwalltype[i]) { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (x=dalx2; x<=darx2; x++) dwall[x] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; + case 0: + if (dalx2 <= darx2) + { + if ((dalx2 == lx) && (darx2 == rx)) return; + //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); + for (x=dalx2; x<=darx2; x++) dwall[x] = 0; + } + break; + case 1: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; + break; + case 2: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; + break; } } - //sprite + //sprite if ((searchit >= 1) && (searchx >= lx) && (searchx <= rx)) if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx])) { @@ -3893,7 +3893,7 @@ static void drawsprite(long snum) else tsethlineshift(x,y); - //Draw it! + //Draw it! ceilspritescan(lx,rx-1); } #ifdef SUPERBUILD @@ -3918,24 +3918,24 @@ static void drawsprite(long snum) switch(smostwalltype[i]) { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&swall[dalx2],(darx2-dalx2+1)*sizeof(swall[0]),0L); - for (x=dalx2; x<=darx2; x++) swall[x] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] > lwall[x]) lwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - for(x=dalx2;x<=darx2;x++) - if (smost[k+x] < swall[x]) swall[x] = smost[k+x]; - break; + case 0: + if (dalx2 <= darx2) + { + if ((dalx2 == lx) && (darx2 == rx)) return; + //clearbufbyte(&swall[dalx2],(darx2-dalx2+1)*sizeof(swall[0]),0L); + for (x=dalx2; x<=darx2; x++) swall[x] = 0; + } + break; + case 1: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] > lwall[x]) lwall[x] = smost[k+x]; + break; + case 2: + k = smoststart[i] - xb1[j]; + for(x=dalx2;x<=darx2;x++) + if (smost[k+x] < swall[x]) swall[x] = smost[k+x]; + break; } } @@ -3984,7 +3984,7 @@ static void drawsprite(long snum) xsiz = mulscale30(siz,xv*xspan); ysiz = mulscale30(siz,nyrepeat*yspan); - //Watch out for divscale overflow + //Watch out for divscale overflow if (((xspan>>11) < xsiz) && (yspan < (ysiz>>1))) { x1 = xb-(xsiz>>1); @@ -4011,7 +4011,7 @@ static void drawsprite(long snum) else startdm = 0x7fffffff; - //sprite + //sprite if ((searchy >= max(startum,(y1>>8))) && (searchy < min(startdm,(y2>>8)))) { searchsector = sectnum; searchwall = spritenum; @@ -4093,28 +4093,28 @@ static void drawmaskwall(short damaskwallcnt) switch(smostwalltype[i]) { - case 0: - if (lx <= rx) - { - if ((lx == xb1[z]) && (rx == xb2[z])) return; - //clearbufbyte(&dwall[lx],(rx-lx+1)*sizeof(dwall[0]),0L); - for (x=lx; x<=rx; x++) dwall[x] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for(x=lx;x<=rx;x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - for(x=lx;x<=rx;x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; + case 0: + if (lx <= rx) + { + if ((lx == xb1[z]) && (rx == xb2[z])) return; + //clearbufbyte(&dwall[lx],(rx-lx+1)*sizeof(dwall[0]),0L); + for (x=lx; x<=rx; x++) dwall[x] = 0; + } + break; + case 1: + k = smoststart[i] - xb1[j]; + for(x=lx;x<=rx;x++) + if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; + break; + case 2: + k = smoststart[i] - xb1[j]; + for(x=lx;x<=rx;x++) + if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; + break; } } - //maskwall + //maskwall if ((searchit >= 1) && (searchx >= xb1[z]) && (searchx <= xb2[z])) if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx])) { @@ -4150,7 +4150,7 @@ static void fillpolygon(long npoints) miny = 0x7fffffff; maxy = 0x80000000; for(z=npoints-1;z>=0;z--) - { y = ry1[z]; miny = min(miny,y); maxy = max(maxy,y); } + { y = ry1[z]; miny = min(miny,y); maxy = max(maxy,y); } miny = (miny>>12); maxy = (maxy>>12); if (miny < 0) miny = 0; if (maxy >= ydim) maxy = ydim-1; @@ -4210,7 +4210,7 @@ static void fillpolygon(long npoints) if (globalpolytype < 1) { - //maphline + //maphline ox = x2+1-(xdim>>1); bx = ox*asm1 + globalposx; by = ox*asm2 - globalposy; @@ -4220,7 +4220,7 @@ static void fillpolygon(long npoints) } else { - //maphline + //maphline ox = x1+1-(xdim>>1); bx = ox*asm1 + globalposx; by = ox*asm2 - globalposy; @@ -4301,7 +4301,7 @@ static long clippoly(long npoints, long clipstat) s2 = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]); s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]); if (s2 < s1) - { t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; } + { t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; } } @@ -4348,7 +4348,7 @@ static long clippoly(long npoints, long clipstat) s2 = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]); s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]); if (s2 < s1) - { t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; } + { t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; } } } if (clipstat&0x5) //Need to clip bottom or right @@ -4396,7 +4396,7 @@ static long clippoly(long npoints, long clipstat) s2 = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]); s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]); if (s2 < s1) - { t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; } + { t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; } } @@ -4443,7 +4443,7 @@ static long clippoly(long npoints, long clipstat) s2 = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]); s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]); if (s2 < s1) - { t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; } + { t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; } } } return(npoints); @@ -4453,8 +4453,8 @@ static long clippoly(long npoints, long clipstat) // // clippoly4 (internal) // - //Assume npoints=4 with polygon on &nrx1,&nry1 - //JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function +//Assume npoints=4 with polygon on &nrx1,&nry1 +//JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function static long clippoly4(long cx1, long cy1, long cx2, long cy2) { long n, nn, z, zz, x, x1, x2, y, y1, y2, t; @@ -4510,7 +4510,7 @@ static long clippoly4(long cx1, long cy1, long cx2, long cy2) // // dorotatesprite (internal) // - //JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function +//JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function static void dorotatesprite(long sx, long sy, long z, short a, short picnum, signed char dashade, char dapalnum, char dastat, long cx1, long cy1, long cx2, long cy2, long uniqid) { long cosang, sinang, v, nextv, dax1, dax2, oy, bx, by, ny1, ny2; @@ -4524,14 +4524,14 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign if (rendmode) { polymost_dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2,uniqid); return; } #endif //============================================================================= //POLYMOST ENDS - + if (cx1 < 0) cx1 = 0; if (cy1 < 0) cy1 = 0; if (cx2 > xres-1) cx2 = xres-1; if (cy2 > yres-1) cy2 = yres-1; xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum]; - if (dastat&16) { xoff = 0; yoff = 0; } +if (dastat&16) { xoff = 0; yoff = 0; } else { xoff = (long)((signed char)((picanm[picnum]>>8)&255))+(xsiz>>1); @@ -4552,8 +4552,8 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign } else { - //If not clipping to startmosts, & auto-scaling on, as a - //hard-coded bonus, scale to full screen instead + //If not clipping to startmosts, & auto-scaling on, as a + //hard-coded bonus, scale to full screen instead x = scale(xdim,yxaspect,320); sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); @@ -4646,17 +4646,17 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign by = dmulscale16(x,yv2,y,yv); if (dastat&4) { yv = -yv; yv2 = -yv2; by = (ysiz<<16)-1-by; } -/* if (origbuffermode == 0) - { - if (dastat&128) + /* if (origbuffermode == 0) { - obuffermode = buffermode; - buffermode = 0; - setactivepage(activepage); + if (dastat&128) + { + obuffermode = buffermode; + buffermode = 0; + setactivepage(activepage); + } } - } - else if (dastat&8) - permanentupdate = 1; */ + else if (dastat&8) + permanentupdate = 1; */ #ifndef ENGINE_USING_A_C @@ -4789,7 +4789,7 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign { y1++; if ((y1&31) == 0) faketimerhandler(); - //x,y1 + //x,y1 bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; if (dastat&64) { if (qlinemode) qrhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L ,by<<16,ylookup[y1]+x+frameplace); @@ -4804,7 +4804,7 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign { y1++; if ((y1&31) == 0) faketimerhandler(); - //x,y1 + //x,y1 bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; if (dastat&64) { if (qlinemode) qrhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L ,by<<16,ylookup[y1]+x+frameplace); @@ -4817,7 +4817,7 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign { y2--; if ((y2&31) == 0) faketimerhandler(); - //x,y2 + //x,y2 bx += xv*(y2-oy); by += yv*(y2-oy); oy = y2; if (dastat&64) { if (qlinemode) qrhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L ,by<<16,ylookup[y2]+x+frameplace); @@ -4832,14 +4832,14 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign { y1++; if ((y1&31) == 0) faketimerhandler(); - //x,y1 + //x,y1 bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; if (dastat&64) { if (qlinemode) qrhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L ,by<<16,ylookup[y1]+x+frameplace); else rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace); } else rmhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace); } - if (x == x2-1) { bx += xv2; by += yv2; break; } + if (x == x2-1) { bx += xv2; by += yv2; break; } y1 = uplc[x+1]; if (((dastat&8) == 0) && (startumost[x+1] > y1)) y1 = startumost[x+1]; y2 = y1; @@ -4850,7 +4850,7 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign { y1++; if ((y1&31) == 0) faketimerhandler(); - //x2,y1 + //x2,y1 bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; if (dastat&64) { if (qlinemode) qrhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L,by<<16,ylookup[y1]+x2+frameplace); @@ -4887,10 +4887,10 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign switch(y1-oy) { - case -1: bx -= xv; by -= yv; oy = y1; break; - case 0: break; - case 1: bx += xv; by += yv; oy = y1; break; - default: bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; break; + case -1: bx -= xv; by -= yv; oy = y1; break; + case 0: break; + case 1: bx += xv; by += yv; oy = y1; break; + default: bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; break; } p = ylookup[y1]+x+frameplace; @@ -4938,10 +4938,10 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign switch(y1-oy) { - case -1: bx -= xv; by -= yv; oy = y1; break; - case 0: break; - case 1: bx += xv; by += yv; oy = y1; break; - default: bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; break; + case -1: bx -= xv; by -= yv; oy = y1; break; + case 0: break; + case 1: bx += xv; by += yv; oy = y1; break; + default: bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1; break; } p = ylookup[y1]+x+frameplace; @@ -4963,11 +4963,11 @@ static void dorotatesprite(long sx, long sy, long z, short a, short picnum, sign #endif -/* if ((dastat&128) && (origbuffermode == 0)) - { - buffermode = obuffermode; - setactivepage(activepage); - }*/ + /* if ((dastat&128) && (origbuffermode == 0)) + { + buffermode = obuffermode; + setactivepage(activepage); + }*/ } @@ -5310,7 +5310,7 @@ static long deletespritestat(short deleteme) // lintersect (internal) // static long lintersect(long x1, long y1, long z1, long x2, long y2, long z2, long x3, - long y3, long x4, long y4, long *intx, long *inty, long *intz) + long y3, long x4, long y4, long *intx, long *inty, long *intz) { //p1 to p2 is a line segment long x21, y21, x34, y34, x31, y31, bot, topt, topu, t; @@ -5342,7 +5342,7 @@ static long lintersect(long x1, long y1, long z1, long x2, long y2, long z2, lon // rintersect (internal) // static long rintersect(long x1, long y1, long z1, long vx, long vy, long vz, long x3, - long y3, long x4, long y4, long *intx, long *inty, long *intz) + long y3, long x4, long y4, long *intx, long *inty, long *intz) { //p1 towards p2 is a ray long x34, y34, x31, y31, bot, topt, topu, t; @@ -5421,7 +5421,7 @@ static long raytrace(long x3, long y3, long *x4, long *y4) } while (x21*(ninty-y1) <= (nintx-x1)*y21); if (klabs(x3-nintx)+klabs(y3-ninty) < klabs(x3-*x4)+klabs(y3-*y4)) - { *x4 = nintx; *y4 = ninty; hitwall = z; } + { *x4 = nintx; *y4 = ninty; hitwall = z; } } return(hitwall); } @@ -5436,25 +5436,25 @@ static long raytrace(long x3, long y3, long *x4, long *y4) #include static void sighandler(int sig, const siginfo_t *info, void *ctx) { - const char *s; - switch (sig) { - case SIGFPE: - switch (info->si_code) { - case FPE_INTDIV: s = "FPE_INTDIV (integer divide by zero)"; break; - case FPE_INTOVF: s = "FPE_INTOVF (integer overflow)"; break; - case FPE_FLTDIV: s = "FPE_FLTDIV (floating-point divide by zero)"; break; - case FPE_FLTOVF: s = "FPE_FLTOVF (floating-point overflow)"; break; - case FPE_FLTUND: s = "FPE_FLTUND (floating-point underflow)"; break; - case FPE_FLTRES: s = "FPE_FLTRES (floating-point inexact result)"; break; - case FPE_FLTINV: s = "FPE_FLTINV (floating-point invalid operation)"; break; - case FPE_FLTSUB: s = "FPE_FLTSUB (floating-point subscript out of range)"; break; - default: s = "?! (unknown)"; break; - } - fprintf(stderr, "Caught SIGFPE at address %p, code %s. Aborting.\n", info->si_addr, s); - break; - default: break; - } - abort(); + const char *s; + switch (sig) { + case SIGFPE: + switch (info->si_code) { + case FPE_INTDIV: s = "FPE_INTDIV (integer divide by zero)"; break; + case FPE_INTOVF: s = "FPE_INTOVF (integer overflow)"; break; + case FPE_FLTDIV: s = "FPE_FLTDIV (floating-point divide by zero)"; break; + case FPE_FLTOVF: s = "FPE_FLTOVF (floating-point overflow)"; break; + case FPE_FLTUND: s = "FPE_FLTUND (floating-point underflow)"; break; + case FPE_FLTRES: s = "FPE_FLTRES (floating-point inexact result)"; break; + case FPE_FLTINV: s = "FPE_FLTINV (floating-point invalid operation)"; break; + case FPE_FLTSUB: s = "FPE_FLTSUB (floating-point subscript out of range)"; break; + default: s = "?! (unknown)"; break; + } + fprintf(stderr, "Caught SIGFPE at address %p, code %s. Aborting.\n", info->si_addr, s); + break; + default: break; + } + abort(); } #endif @@ -5467,14 +5467,14 @@ int initengine(void) char *e; #if !defined _WIN32 && defined DEBUGGINGAIDS - struct sigaction sigact, oldact; - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_sigaction = sighandler; - sigact.sa_flags = SA_SIGINFO; - sigaction(SIGFPE, &sigact, &oldact); + struct sigaction sigact, oldact; + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_sigaction = sighandler; + sigact.sa_flags = SA_SIGINFO; + sigaction(SIGFPE, &sigact, &oldact); #endif - if (initsystem()) exit(1); + if (initsystem()) exit(1); if ((e = Bgetenv("BUILD_NOP6")) != NULL) if (!Bstrcasecmp(e, "TRUE")) { @@ -5541,9 +5541,9 @@ int initengine(void) if (!mdinited) mdinit(); #endif - initcrc32table(); + initcrc32table(); - return 0; + return 0; } @@ -5553,7 +5553,7 @@ int initengine(void) void uninitengine(void) { long i; - + //OSD_Printf("cacheresets = %d, cacheinvalidates = %d\n", cacheresets, cacheinvalidates); #if defined(POLYMOST) && defined(USE_OPENGL) @@ -5565,7 +5565,7 @@ void uninitengine(void) uninitsystem(); if (artfil != -1) kclose(artfil); - if (transluc != NULL) { kkfree(transluc); transluc = NULL; } +if (transluc != NULL) { kkfree(transluc); transluc = NULL; } if (pic != NULL) { kkfree(pic); pic = NULL; } if (lookups != NULL) { @@ -5574,7 +5574,7 @@ void uninitengine(void) lookups = NULL; } for(i=0;i=0;i--) tspriteptr[i] = &tsprite[i]; - for(i=spritesortcnt-1;i>=0;i--) - { - xs = tspriteptr[i]->x-globalposx; ys = tspriteptr[i]->y-globalposy; - yp = dmulscale6(xs,cosviewingrangeglobalang,ys,sinviewingrangeglobalang); - if (yp > (4<<8)) - { - xp = dmulscale6(ys,cosglobalang,-xs,singlobalang); - if (mulscale24(labs(xp+yp),xdimen) >= yp) goto killsprite; - spritesx[i] = scale(xp+yp,xdimen<<7,yp); - } - else if ((tspriteptr[i]->cstat&48) == 0) - { + for(i=spritesortcnt-1;i>=0;i--) tspriteptr[i] = &tsprite[i]; + for(i=spritesortcnt-1;i>=0;i--) + { + xs = tspriteptr[i]->x-globalposx; ys = tspriteptr[i]->y-globalposy; + yp = dmulscale6(xs,cosviewingrangeglobalang,ys,sinviewingrangeglobalang); + if (yp > (4<<8)) + { + xp = dmulscale6(ys,cosglobalang,-xs,singlobalang); + if (mulscale24(labs(xp+yp),xdimen) >= yp) goto killsprite; + spritesx[i] = scale(xp+yp,xdimen<<7,yp); + } + else if ((tspriteptr[i]->cstat&48) == 0) + { killsprite: - spritesortcnt--; //Delete face sprite if on wrong side! - if (i != spritesortcnt) - { - tspriteptr[i] = tspriteptr[spritesortcnt]; - spritesx[i] = spritesx[spritesortcnt]; - spritesy[i] = spritesy[spritesortcnt]; - } - continue; - } - spritesy[i] = yp; - } + spritesortcnt--; //Delete face sprite if on wrong side! + if (i != spritesortcnt) + { + tspriteptr[i] = tspriteptr[spritesortcnt]; + spritesx[i] = spritesx[spritesortcnt]; + spritesy[i] = spritesy[spritesortcnt]; + } + continue; + } + spritesy[i] = yp; + } gap = 1; while (gap < spritesortcnt) gap = (gap<<1)+1; for(gap>>=1;gap>0;gap>>=1) //Sort sprite list @@ -5858,7 +5858,7 @@ killsprite: } begindrawing(); //{{{ - + /*for(i=spritesortcnt-1;i>=0;i--) { xs = tspriteptr[i].x-globalposx; @@ -5880,94 +5880,94 @@ killsprite: #if 0 { // Removing previous sorting code #ifdef POLYMOST - //Hack to make it draw all opaque quads first. This should reduce the chances of - //bad sorting causing transparent quads knocking out opaque quads behind it. - // - //Need to store alpha flag with all textures before this works right! - if (rendmode == 3) - { - for(i=spritesortcnt-1;i>=0;i--) - if ((!(tspriteptr[i]->cstat&2)) -#ifdef USE_OPENGL - && (!gltexmayhavealpha(tspriteptr[i]->picnum,tspriteptr[i]->pal)) -#endif - ) - { drawsprite(i); tspriteptr[i] = 0; } //draw only if it is fully opaque - for(i=j=0;i=0;i--) - { - k = thewall[maskwall[i]]; - if ((!(wall[k].cstat&128)) -#ifdef USE_OPENGL - && (!gltexmayhavealpha(wall[k].overpicnum,wall[k].pal)) -#endif - ) - { drawmaskwall(i); maskwall[i] = -1; } //draw only if it is fully opaque - } - for(i=j=0;i 0) && (maskwallcnt > 0)) //While BOTH > 0 - { - j = maskwall[maskwallcnt-1]; - if (spritewallfront(tspriteptr[spritesortcnt-1],(long)thewall[j]) == 0) - drawsprite(--spritesortcnt); - else + //Hack to make it draw all opaque quads first. This should reduce the chances of + //bad sorting causing transparent quads knocking out opaque quads behind it. + // + //Need to store alpha flag with all textures before this works right! + if (rendmode == 3) { - //Check to see if any sprites behind the masked wall... - k = -1; - gap = 0; - for(i=spritesortcnt-2;i>=0;i--) - if ((xb1[j] <= (spritesx[i]>>8)) && ((spritesx[i]>>8) <= xb2[j])) - if (spritewallfront(tspriteptr[i],(long)thewall[j]) == 0) - { - drawsprite(i); - tspriteptr[i]->owner = -1; - k = i; - gap++; - } - if (k >= 0) //remove holes in sprite list + for(i=spritesortcnt-1;i>=0;i--) + if ((!(tspriteptr[i]->cstat&2)) +#ifdef USE_OPENGL + && (!gltexmayhavealpha(tspriteptr[i]->picnum,tspriteptr[i]->pal)) +#endif + ) + { drawsprite(i); tspriteptr[i] = 0; } //draw only if it is fully opaque + for(i=j=0;iowner >= 0) - { - if (i > k) - { - tspriteptr[k] = tspriteptr[i]; - spritesx[k] = spritesx[i]; - spritesy[k] = spritesy[i]; - } - k++; - } - spritesortcnt -= gap; + if (!tspriteptr[i]) continue; + tspriteptr[j] = tspriteptr[i]; + spritesx[j] = spritesx[i]; + spritesy[j] = spritesy[i]; j++; } + spritesortcnt = j; + + for(i=maskwallcnt-1;i>=0;i--) + { + k = thewall[maskwall[i]]; + if ((!(wall[k].cstat&128)) +#ifdef USE_OPENGL + && (!gltexmayhavealpha(wall[k].overpicnum,wall[k].pal)) +#endif + ) + { drawmaskwall(i); maskwall[i] = -1; } //draw only if it is fully opaque + } + for(i=j=0;i 0) && (maskwallcnt > 0)) //While BOTH > 0 + { + j = maskwall[maskwallcnt-1]; + if (spritewallfront(tspriteptr[spritesortcnt-1],(long)thewall[j]) == 0) + drawsprite(--spritesortcnt); + else + { + //Check to see if any sprites behind the masked wall... + k = -1; + gap = 0; + for(i=spritesortcnt-2;i>=0;i--) + if ((xb1[j] <= (spritesx[i]>>8)) && ((spritesx[i]>>8) <= xb2[j])) + if (spritewallfront(tspriteptr[i],(long)thewall[j]) == 0) + { + drawsprite(i); + tspriteptr[i]->owner = -1; + k = i; + gap++; + } + if (k >= 0) //remove holes in sprite list + { + for(i=k;iowner >= 0) + { + if (i > k) + { + tspriteptr[k] = tspriteptr[i]; + spritesx[k] = spritesx[i]; + spritesy[k] = spritesy[i]; + } + k++; + } + spritesortcnt -= gap; + } //finally safe to draw the masked wall - drawmaskwall(--maskwallcnt); + drawmaskwall(--maskwallcnt); + } } - } - while (spritesortcnt > 0) drawsprite(--spritesortcnt); - while (maskwallcnt > 0) drawmaskwall(--maskwallcnt); + while (spritesortcnt > 0) drawsprite(--spritesortcnt); + while (maskwallcnt > 0) drawmaskwall(--maskwallcnt); } #else - // PLAG : The heart of good transparency -> sorted rendering on all layers. - // that's why this code interleaves the drawing of all possible transparent entities - // bubblesort is used, shouldn't cause any problems cpu-wise since the lists are small - + // PLAG : The heart of good transparency -> sorted rendering on all layers. + // that's why this code interleaves the drawing of all possible transparent entities + // bubblesort is used, shouldn't cause any problems cpu-wise since the lists are small + // SPRITES PREPROCESSING l = spritesortcnt; indexes = malloc(l * sizeof(long)); @@ -5982,7 +5982,7 @@ killsprite: depths[i] = (tspriteptr[spritesortcnt]->x - globalposx) * (tspriteptr[spritesortcnt]->x - globalposx) + (tspriteptr[spritesortcnt]->y - globalposy) * (tspriteptr[spritesortcnt]->y - globalposy); } - + // second pass (and possibly more) to z-sort j = 0; while (j == 0) @@ -5998,7 +5998,7 @@ killsprite: } } } - + // MASKS PREPROCESSING k = maskwallcnt; wallindexes = malloc(k * sizeof(long)); @@ -6010,12 +6010,12 @@ killsprite: { i--; wallindexes[i] = --maskwallcnt; - + xs = wall[thewall[maskwall[wallindexes[i]]]].x; ys = wall[thewall[maskwall[wallindexes[i]]]].y; xp = wall[wall[thewall[maskwall[wallindexes[i]]]].point2].x; yp = wall[wall[thewall[maskwall[wallindexes[i]]]].point2].y; - + x = ((xs + xp) / 2) - globalposx; y = ((ys + yp) / 2) - globalposy; walldepths[i] = (x * x) + (y * y); @@ -6040,10 +6040,10 @@ killsprite: // DRAWING // in this code all sprites are drawn, and masks are inserted when needed i = l - 1; - while (i >= 0) + while (i >= 0) { j = k; - while (j > 0) + while (j > 0) { j--; // if a mask is farther than the sprite which is about to be drawn, we draw it before then discard it from the stack @@ -6114,7 +6114,7 @@ void drawmapview(long dax, long day, long zoome, short ang) sortnum = 0; begindrawing(); //{{{ - + for(s=0,sec=§or[s];s>3]&pow2char[s&7]) { @@ -6138,8 +6138,8 @@ void drawmapview(long dax, long day, long zoome, short ang) { k = lastwall(j); if ((k > j) && (npoints > 0)) { xb1[npoints-1] = l; l = npoints; } //overwrite point2 - //wall[k].x wal->x wall[wal->point2].x - //wall[k].y wal->y wall[wal->point2].y + //wall[k].x wal->x wall[wal->point2].x + //wall[k].y wal->y wall[wal->point2].y if (!dmulscale1(wal->x-wall[k].x,wall[wal->point2].y-wal->y,-(wal->y-wall[k].y),wall[wal->point2].x-wal->x)) continue; ox = wal->x - dax; oy = wal->y - day; x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11); @@ -6160,7 +6160,7 @@ void drawmapview(long dax, long day, long zoome, short ang) if (npoints < 3) continue; } - //Collect floor sprites to draw + //Collect floor sprites to draw for(i=headspritesect[s];i>=0;i=nextspritesect[i]) if ((sprite[i].cstat&48) == 32) { @@ -6219,7 +6219,7 @@ void drawmapview(long dax, long day, long zoome, short ang) } globalxshift = (8-(picsiz[globalpicnum]&15)); globalyshift = (8-(picsiz[globalpicnum]>>4)); - if (globalorientation&8) {globalxshift++; globalyshift++; } + if (globalorientation&8) {globalxshift++; globalyshift++; } sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc); @@ -6241,7 +6241,7 @@ void drawmapview(long dax, long day, long zoome, short ang) fillpolygon(npoints); } - //Sort sprite list + //Sort sprite list gap = 1; while (gap < sortnum) gap = (gap<<1)+1; for(gap>>=1;gap>0;gap>>=1) for(i=0;ivisibility != 0) globvis = mulscale4(globvis,(long)((unsigned char)(sec->visibility+16))); globalpolytype = ((spr->cstat&2)>>1)+1; - //relative alignment stuff + //relative alignment stuff ox = x2-x1; oy = y2-y1; i = ox*ox+oy*oy; if (i == 0) continue; i = (65536*16384)/i; globalx1 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i); @@ -6378,14 +6378,14 @@ void drawmapview(long dax, long day, long zoome, short ang) // loadboard // long loadboard(char *filename, char fromwhere, long *daposx, long *daposy, long *daposz, - short *daang, short *dacursectnum) + short *daang, short *dacursectnum) { short fil, i, numsprites; i = strlen(filename)-1; if (filename[i] == 255) { filename[i] = 0; fromwhere = 1; } // JBF 20040119: "compatibility" if ((fil = kopen4load(filename,fromwhere)) == -1) - { mapversion = 7L; return(-1); } + { mapversion = 7L; return(-1); } kread(fil,&mapversion,4); mapversion = B_LITTLE32(mapversion); if (mapversion != 7L && mapversion != 8L) { kclose(fil); return(-2); } @@ -6475,7 +6475,7 @@ long loadboard(char *filename, char fromwhere, long *daposx, long *daposy, long insertsprite(sprite[i].sectnum,sprite[i].statnum); } - //Must be after loading sectors, etc! + //Must be after loading sectors, etc! updatesector(*daposx,*daposy,dacursectnum); kclose(fil); @@ -6775,7 +6775,7 @@ static void convertv6sprv7(struct spritetypev6 *from, spritetype *to) // Powerslave uses v6 // Witchaven 1 and TekWar use v5 long loadoldboard(char *filename, char fromwhere, long *daposx, long *daposy, long *daposz, - short *daang, short *dacursectnum) + short *daang, short *dacursectnum) { short fil, i, numsprites; struct sectortypev5 v5sect; @@ -6788,7 +6788,7 @@ long loadoldboard(char *filename, char fromwhere, long *daposx, long *daposy, lo i = strlen(filename)-1; if (filename[i] == 255) { filename[i] = 0; fromwhere = 1; } // JBF 20040119: "compatibility" if ((fil = kopen4load(filename,fromwhere)) == -1) - { mapversion = 5L; return(-1); } + { mapversion = 5L; return(-1); } kread(fil,&mapversion,4); mapversion = B_LITTLE32(mapversion); if (mapversion != 5L && mapversion != 6L) { kclose(fil); return(-2); } @@ -6809,119 +6809,119 @@ long loadoldboard(char *filename, char fromwhere, long *daposx, long *daposy, lo if (numsectors > MAXSECTORS) { kclose(fil); return(-1); } for (i=0; i MAXWALLS) { kclose(fil); return(-1); } +if (numwalls > MAXWALLS) { kclose(fil); return(-1); } for (i=0; i MAXSPRITES) { kclose(fil); return(-1); } +if (numsprites > MAXSPRITES) { kclose(fil); return(-1); } for (i=0; iltextptr; switch (legaltokens[i].tokenid) { - case 0: // sprite - if (scriptfile_getnumber(script, &whichsprite)) break; + case 0: // sprite + if (scriptfile_getnumber(script, &whichsprite)) break; - if ((unsigned)whichsprite >= (unsigned)MAXSPRITES) { - // sprite number out of range - initprintf("Sprite number out of range 0-%d on line %s:%d\n", - MAXSPRITES-1,script->filename, scriptfile_getlinum(script,cmdtokptr)); - whichsprite = -1; - break; - } - + if ((unsigned)whichsprite >= (unsigned)MAXSPRITES) { + // sprite number out of range + initprintf("Sprite number out of range 0-%d on line %s:%d\n", + MAXSPRITES-1,script->filename, scriptfile_getlinum(script,cmdtokptr)); + whichsprite = -1; break; - case 1: // angoff - { - int ang; - if (scriptfile_getnumber(script, &ang)) break; + } + + break; + case 1: // angoff + { + int ang; + if (scriptfile_getnumber(script, &ang)) break; - if (whichsprite < 0) { - // no sprite directive preceeding - initprintf("Ignoring angle offset directive because of absent/invalid sprite number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - spriteext[whichsprite].angoff = (short)ang; - } - break; - case 2: // notmd if (whichsprite < 0) { // no sprite directive preceeding - initprintf("Ignoring not-MD2/MD3 directive because of absent/invalid sprite number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); + initprintf("Ignoring angle offset directive because of absent/invalid sprite number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); break; } - spriteext[whichsprite].flags |= SPREXT_NOTMD; + spriteext[whichsprite].angoff = (short)ang; + } + break; + case 2: // notmd + if (whichsprite < 0) { + // no sprite directive preceeding + initprintf("Ignoring not-MD2/MD3 directive because of absent/invalid sprite number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); break; - case 3: // nomdanim - if (whichsprite < 0) { - // no sprite directive preceeding - initprintf("Ignoring no-MD2/MD3-anim directive because of absent/invalid sprite number on line %s:%d\n", - script->filename, scriptfile_getlinum(script,cmdtokptr)); - break; - } - spriteext[whichsprite].flags |= SPREXT_NOMDANIM; - break; - default: - // unrecognised token + } + spriteext[whichsprite].flags |= SPREXT_NOTMD; + break; + case 3: // nomdanim + if (whichsprite < 0) { + // no sprite directive preceeding + initprintf("Ignoring no-MD2/MD3-anim directive because of absent/invalid sprite number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,cmdtokptr)); break; + } + spriteext[whichsprite].flags |= SPREXT_NOMDANIM; + break; + default: + // unrecognised token + break; } } @@ -7042,7 +7042,7 @@ long loadmaphack(char *filename) { return -1; } // saveboard // long saveboard(char *filename, long *daposx, long *daposy, long *daposz, - short *daang, short *dacursectnum) + short *daang, short *dacursectnum) { short fil, i, j, numsprites, ts; long tl; @@ -7050,8 +7050,8 @@ long saveboard(char *filename, long *daposx, long *daposy, long *daposz, walltype twall; spritetype tspri; - if ((fil = Bopen(filename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1) - return(-1); + if ((fil = Bopen(filename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1) + return(-1); numsprites = 0; for(j=0;j>1); } +if (searchx < 0) { searchx = halfxdimen; searchy = (ydimen>>1); } #if defined(POLYMOST) && defined(USE_OPENGL) if (rendmode == 3) { @@ -7241,45 +7241,45 @@ void nextpage(void) switch(qsetmode) { - case 200: - begindrawing(); //{{{ - for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1))) - { - per = &permfifo[i]; - if ((per->pagesleft > 0) && (per->pagesleft <= numpages)) - dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum, - per->dashade,per->dapalnum,per->dastat, - per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid); - } - enddrawing(); //}}} + case 200: + begindrawing(); //{{{ + for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1))) + { + per = &permfifo[i]; + if ((per->pagesleft > 0) && (per->pagesleft <= numpages)) + dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum, + per->dashade,per->dapalnum,per->dastat, + per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid); + } + enddrawing(); //}}} - OSD_Draw(); - showframe(0); + OSD_Draw(); + showframe(0); - begindrawing(); //{{{ - for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1))) - { - per = &permfifo[i]; - if (per->pagesleft >= 130) - dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum, - per->dashade,per->dapalnum,per->dastat, - per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid); + begindrawing(); //{{{ + for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1))) + { + per = &permfifo[i]; + if (per->pagesleft >= 130) + dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum, + per->dashade,per->dapalnum,per->dastat, + per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid); - if (per->pagesleft&127) per->pagesleft--; - if (((per->pagesleft&127) == 0) && (i == permtail)) - permtail = ((permtail+1)&(MAXPERMS-1)); - } - enddrawing(); //}}} - break; + if (per->pagesleft&127) per->pagesleft--; + if (((per->pagesleft&127) == 0) && (i == permtail)) + permtail = ((permtail+1)&(MAXPERMS-1)); + } + enddrawing(); //}}} + break; - case 350: - case 480: - break; + case 350: + case 480: + break; } faketimerhandler(); if ((totalclock >= lastageclock+8) || (totalclock < lastageclock)) - { lastageclock = totalclock; agecache(); } + { lastageclock = totalclock; agecache(); } #ifdef USE_OPENGL omdtims = mdtims; mdtims = getticks(); @@ -7357,11 +7357,11 @@ long loadpics(char *filename, long askedsize) //try dpmi_DETERMINEMAXREALALLOC! - //cachesize = min((long)((Bgetsysmemsize()/100)*60),max(artsize,askedsize)); - if (Bgetsysmemsize() <= (unsigned long)askedsize) - cachesize = (Bgetsysmemsize()/100)*60; - else - cachesize = askedsize; + //cachesize = min((long)((Bgetsysmemsize()/100)*60),max(artsize,askedsize)); + if (Bgetsysmemsize() <= (unsigned long)askedsize) + cachesize = (Bgetsysmemsize()/100)*60; + else + cachesize = askedsize; while ((pic = kkmalloc(cachesize)) == NULL) { cachesize -= 65536L; @@ -7466,7 +7466,7 @@ long allocatepermanenttile(short tilenume, long xsiz, long ysiz) // copytilepiece // void copytilepiece(long tilenume1, long sx1, long sy1, long xsiz, long ysiz, - long tilenume2, long sx2, long sy2) + long tilenume2, long sx2, long sy2) { char *ptr1, *ptr2, dat; long xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2; @@ -7520,7 +7520,7 @@ long qloadkvx(long voxindex, char *filename) for(i=0;ix; y1 = spr->y; z1 = spr->z; switch(cstat&48) { - case 0: - topt = vx*(x1-xs) + vy*(y1-ys); if (topt <= 0) continue; - bot = vx*vx + vy*vy; if (bot == 0) continue; + case 0: + topt = vx*(x1-xs) + vy*(y1-ys); if (topt <= 0) continue; + bot = vx*vx + vy*vy; if (bot == 0) continue; - intz = zs+scale(vz,topt,bot); + intz = zs+scale(vz,topt,bot); - i = (tilesizy[spr->picnum]*spr->yrepeat<<2); - if (cstat&128) z1 += (i>>1); - if (picanm[spr->picnum]&0x00ff0000) z1 -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - if ((intz > z1) || (intz < z1-i)) continue; - topu = vx*(y1-ys) - vy*(x1-xs); + i = (tilesizy[spr->picnum]*spr->yrepeat<<2); + if (cstat&128) z1 += (i>>1); + if (picanm[spr->picnum]&0x00ff0000) z1 -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); + if ((intz > z1) || (intz < z1-i)) continue; + topu = vx*(y1-ys) - vy*(x1-xs); - offx = scale(vx,topu,bot); - offy = scale(vy,topu,bot); - dist = offx*offx + offy*offy; - i = tilesizx[spr->picnum]*spr->xrepeat; i *= i; - if (dist > (i>>7)) continue; - intx = xs + scale(vx,topt,bot); - inty = ys + scale(vy,topt,bot); + offx = scale(vx,topu,bot); + offy = scale(vy,topu,bot); + dist = offx*offx + offy*offy; + i = tilesizx[spr->picnum]*spr->xrepeat; i *= i; + if (dist > (i>>7)) continue; + intx = xs + scale(vx,topt,bot); + inty = ys + scale(vy,topt,bot); - if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; + if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; + *hitsect = dasector; *hitwall = -1; *hitsprite = z; + *hitx = intx; *hity = inty; *hitz = intz; + break; + case 16: + //These lines get the 2 points of the rotated sprite + //Given: (x1, y1) starts out as the center point + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + if ((cstat&4) > 0) xoff = -xoff; + k = spr->ang; l = spr->xrepeat; + dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; + l = tilesizx[tilenum]; k = (l>>1)+xoff; + x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); + y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + + if ((cstat&64) != 0) //back side of 1-way sprite + if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue; + + if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue; + + if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; + + k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2); + if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z; + if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); + if ((intz < daz) && (intz > daz-k)) + { *hitsect = dasector; *hitwall = -1; *hitsprite = z; *hitx = intx; *hity = inty; *hitz = intz; - break; - case 16: - //These lines get the 2 points of the rotated sprite - //Given: (x1, y1) starts out as the center point - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - if ((cstat&4) > 0) xoff = -xoff; - k = spr->ang; l = spr->xrepeat; - dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; - l = tilesizx[tilenum]; k = (l>>1)+xoff; - x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); - y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + } + break; + case 32: + if (vz == 0) continue; + intz = z1; + if (((intz-zs)^vz) < 0) continue; + if ((cstat&64) != 0) + if ((zs > intz) == ((cstat&8)==0)) continue; - if ((cstat&64) != 0) //back side of 1-way sprite - if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue; + intx = xs+scale(intz-zs,vx,vz); + inty = ys+scale(intz-zs,vy,vz); - if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue; + if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; - if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); + if ((cstat&4) > 0) xoff = -xoff; + if ((cstat&8) > 0) yoff = -yoff; - k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2); - if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z; - if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - if ((intz < daz) && (intz > daz-k)) - { - *hitsect = dasector; *hitwall = -1; *hitsprite = z; - *hitx = intx; *hity = inty; *hitz = intz; - } - break; - case 32: - if (vz == 0) continue; - intz = z1; - if (((intz-zs)^vz) < 0) continue; - if ((cstat&64) != 0) - if ((zs > intz) == ((cstat&8)==0)) continue; + ang = spr->ang; + cosang = sintable[(ang+512)&2047]; sinang = sintable[ang]; + xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; + yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - intx = xs+scale(intz-zs,vx,vz); - inty = ys+scale(intz-zs,vy,vz); + dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; + x1 += dmulscale16(sinang,dax,cosang,day)-intx; + y1 += dmulscale16(sinang,day,-cosang,dax)-inty; + l = xspan*xrepeat; + x2 = x1 - mulscale16(sinang,l); + y2 = y1 + mulscale16(cosang,l); + l = yspan*yrepeat; + k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; + k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; - if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue; + clipyou = 0; + if ((y1^y2) < 0) + { + if ((x1^x2) < 0) clipyou ^= (x1*y2= 0) clipyou ^= 1; + } + if ((y2^y3) < 0) + { + if ((x2^x3) < 0) clipyou ^= (x2*y3= 0) clipyou ^= 1; + } + if ((y3^y4) < 0) + { + if ((x3^x4) < 0) clipyou ^= (x3*y4= 0) clipyou ^= 1; + } + if ((y4^y1) < 0) + { + if ((x4^x1) < 0) clipyou ^= (x4*y1= 0) clipyou ^= 1; + } - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); - if ((cstat&4) > 0) xoff = -xoff; - if ((cstat&8) > 0) yoff = -yoff; - - ang = spr->ang; - cosang = sintable[(ang+512)&2047]; sinang = sintable[ang]; - xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; - yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - - dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; - x1 += dmulscale16(sinang,dax,cosang,day)-intx; - y1 += dmulscale16(sinang,day,-cosang,dax)-inty; - l = xspan*xrepeat; - x2 = x1 - mulscale16(sinang,l); - y2 = y1 + mulscale16(cosang,l); - l = yspan*yrepeat; - k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; - k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; - - clipyou = 0; - if ((y1^y2) < 0) - { - if ((x1^x2) < 0) clipyou ^= (x1*y2= 0) clipyou ^= 1; - } - if ((y2^y3) < 0) - { - if ((x2^x3) < 0) clipyou ^= (x2*y3= 0) clipyou ^= 1; - } - if ((y3^y4) < 0) - { - if ((x3^x4) < 0) clipyou ^= (x3*y4= 0) clipyou ^= 1; - } - if ((y4^y1) < 0) - { - if ((x4^x1) < 0) clipyou ^= (x4*y1= 0) clipyou ^= 1; - } - - if (clipyou != 0) - { - *hitsect = dasector; *hitwall = -1; *hitsprite = z; - *hitx = intx; *hity = inty; *hitz = intz; - } - break; + if (clipyou != 0) + { + *hitsect = dasector; *hitwall = -1; *hitsprite = z; + *hitx = intx; *hity = inty; *hitz = intz; + } + break; } } tempshortcnt++; @@ -8338,8 +8338,8 @@ long clipmoveboxtracenum = 3; // clipmove // long clipmove (long *x, long *y, long *z, short *sectnum, - long xvect, long yvect, - long walldist, long ceildist, long flordist, unsigned long cliptype) + long xvect, long yvect, + long walldist, long ceildist, long flordist, unsigned long cliptype) { walltype *wal, *wal2; spritetype *spr; @@ -8366,7 +8366,7 @@ long clipmove (long *x, long *y, long *z, short *sectnum, cx = (((*x)+goalx)>>1); cy = (((*y)+goaly)>>1); - //Extra walldist for sprites on sector lines + //Extra walldist for sprites on sector lines gx = goalx-(*x); gy = goaly-(*y); rad = nsqrtasm(gx*gx + gy*gy) + MAXCLIPDIST+walldist + 8; xmin = cx-rad; ymin = cy-rad; @@ -8424,7 +8424,7 @@ long clipmove (long *x, long *y, long *z, short *sectnum, if (clipyou) { - //Add 2 boxes at endpoints + //Add 2 boxes at endpoints bsz = walldist; if (gx < 0) bsz = -bsz; addclipline(x1-bsz,y1-bsz,x1-bsz,y1+bsz,(short)j+32768); addclipline(x2-bsz,y2-bsz,x2-bsz,y2+bsz,(short)j+32768); @@ -8452,117 +8452,117 @@ long clipmove (long *x, long *y, long *z, short *sectnum, x1 = spr->x; y1 = spr->y; switch(cstat&48) { - case 0: - if ((x1 >= xmin) && (x1 <= xmax) && (y1 >= ymin) && (y1 <= ymax)) - { - k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2); - if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z; - if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - if (((*z) < daz+ceildist) && ((*z) > daz-k-flordist)) - { - bsz = (spr->clipdist<<2)+walldist; if (gx < 0) bsz = -bsz; - addclipline(x1-bsz,y1-bsz,x1-bsz,y1+bsz,(short)j+49152); - bsz = (spr->clipdist<<2)+walldist; if (gy < 0) bsz = -bsz; - addclipline(x1+bsz,y1-bsz,x1-bsz,y1-bsz,(short)j+49152); - } - } - break; - case 16: + case 0: + if ((x1 >= xmin) && (x1 <= xmax) && (y1 >= ymin) && (y1 <= ymax)) + { k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2); if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z; if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - daz2 = daz-k; - daz += ceildist; daz2 -= flordist; - if (((*z) < daz) && ((*z) > daz2)) + if (((*z) < daz+ceildist) && ((*z) > daz-k-flordist)) { - //These lines get the 2 points of the rotated sprite - //Given: (x1, y1) starts out as the center point - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - if ((cstat&4) > 0) xoff = -xoff; - k = spr->ang; l = spr->xrepeat; - dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; - l = tilesizx[tilenum]; k = (l>>1)+xoff; - x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); - y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); - if (clipinsideboxline(cx,cy,x1,y1,x2,y2,rad) != 0) - { - dax = mulscale14(sintable[(spr->ang+256+512)&2047],walldist); - day = mulscale14(sintable[(spr->ang+256)&2047],walldist); - - if ((x1-(*x))*(y2-(*y)) >= (x2-(*x))*(y1-(*y))) //Front - { - addclipline(x1+dax,y1+day,x2+day,y2-dax,(short)j+49152); - } - else - { - if ((cstat&64) != 0) continue; - addclipline(x2-dax,y2-day,x1-day,y1+dax,(short)j+49152); - } - - //Side blocker - if ((x2-x1)*((*x)-x1) + (y2-y1)*((*y)-y1) < 0) - { addclipline(x1-day,y1+dax,x1+dax,y1+day,(short)j+49152); } - else if ((x1-x2)*((*x)-x2) + (y1-y2)*((*y)-y2) < 0) - { addclipline(x2+day,y2-dax,x2-dax,y2-day,(short)j+49152); } - } + bsz = (spr->clipdist<<2)+walldist; if (gx < 0) bsz = -bsz; + addclipline(x1-bsz,y1-bsz,x1-bsz,y1+bsz,(short)j+49152); + bsz = (spr->clipdist<<2)+walldist; if (gy < 0) bsz = -bsz; + addclipline(x1+bsz,y1-bsz,x1-bsz,y1-bsz,(short)j+49152); } - break; - case 32: - daz = spr->z+ceildist; - daz2 = spr->z-flordist; - if (((*z) < daz) && ((*z) > daz2)) + } + break; + case 16: + k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2); + if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z; + if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); + daz2 = daz-k; + daz += ceildist; daz2 -= flordist; + if (((*z) < daz) && ((*z) > daz2)) + { + //These lines get the 2 points of the rotated sprite + //Given: (x1, y1) starts out as the center point + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + if ((cstat&4) > 0) xoff = -xoff; + k = spr->ang; l = spr->xrepeat; + dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; + l = tilesizx[tilenum]; k = (l>>1)+xoff; + x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); + y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + if (clipinsideboxline(cx,cy,x1,y1,x2,y2,rad) != 0) { - if ((cstat&64) != 0) - if (((*z) > spr->z) == ((cstat&8)==0)) continue; + dax = mulscale14(sintable[(spr->ang+256+512)&2047],walldist); + day = mulscale14(sintable[(spr->ang+256)&2047],walldist); - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); - if ((cstat&4) > 0) xoff = -xoff; - if ((cstat&8) > 0) yoff = -yoff; - - k = spr->ang; - cosang = sintable[(k+512)&2047]; sinang = sintable[k]; - xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; - yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - - dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; - rxi[0] = x1 + dmulscale16(sinang,dax,cosang,day); - ryi[0] = y1 + dmulscale16(sinang,day,-cosang,dax); - l = xspan*xrepeat; - rxi[1] = rxi[0] - mulscale16(sinang,l); - ryi[1] = ryi[0] + mulscale16(cosang,l); - l = yspan*yrepeat; - k = -mulscale16(cosang,l); rxi[2] = rxi[1]+k; rxi[3] = rxi[0]+k; - k = -mulscale16(sinang,l); ryi[2] = ryi[1]+k; ryi[3] = ryi[0]+k; - - dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist); - day = mulscale14(sintable[(spr->ang-256)&2047],walldist); - - if ((rxi[0]-(*x))*(ryi[1]-(*y)) < (rxi[1]-(*x))*(ryi[0]-(*y))) + if ((x1-(*x))*(y2-(*y)) >= (x2-(*x))*(y1-(*y))) //Front { - if (clipinsideboxline(cx,cy,rxi[1],ryi[1],rxi[0],ryi[0],rad) != 0) - addclipline(rxi[1]-day,ryi[1]+dax,rxi[0]+dax,ryi[0]+day,(short)j+49152); + addclipline(x1+dax,y1+day,x2+day,y2-dax,(short)j+49152); } - else if ((rxi[2]-(*x))*(ryi[3]-(*y)) < (rxi[3]-(*x))*(ryi[2]-(*y))) + else { - if (clipinsideboxline(cx,cy,rxi[3],ryi[3],rxi[2],ryi[2],rad) != 0) - addclipline(rxi[3]+day,ryi[3]-dax,rxi[2]-dax,ryi[2]-day,(short)j+49152); + if ((cstat&64) != 0) continue; + addclipline(x2-dax,y2-day,x1-day,y1+dax,(short)j+49152); } - if ((rxi[1]-(*x))*(ryi[2]-(*y)) < (rxi[2]-(*x))*(ryi[1]-(*y))) - { - if (clipinsideboxline(cx,cy,rxi[2],ryi[2],rxi[1],ryi[1],rad) != 0) - addclipline(rxi[2]-dax,ryi[2]-day,rxi[1]-day,ryi[1]+dax,(short)j+49152); - } - else if ((rxi[3]-(*x))*(ryi[0]-(*y)) < (rxi[0]-(*x))*(ryi[3]-(*y))) - { - if (clipinsideboxline(cx,cy,rxi[0],ryi[0],rxi[3],ryi[3],rad) != 0) - addclipline(rxi[0]+dax,ryi[0]+day,rxi[3]+day,ryi[3]-dax,(short)j+49152); - } + //Side blocker + if ((x2-x1)*((*x)-x1) + (y2-y1)*((*y)-y1) < 0) + { addclipline(x1-day,y1+dax,x1+dax,y1+day,(short)j+49152); } + else if ((x1-x2)*((*x)-x2) + (y1-y2)*((*y)-y2) < 0) + { addclipline(x2+day,y2-dax,x2-dax,y2-day,(short)j+49152); } } - break; + } + break; + case 32: + daz = spr->z+ceildist; + daz2 = spr->z-flordist; + if (((*z) < daz) && ((*z) > daz2)) + { + if ((cstat&64) != 0) + if (((*z) > spr->z) == ((cstat&8)==0)) continue; + + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); + if ((cstat&4) > 0) xoff = -xoff; + if ((cstat&8) > 0) yoff = -yoff; + + k = spr->ang; + cosang = sintable[(k+512)&2047]; sinang = sintable[k]; + xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; + yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; + + dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; + rxi[0] = x1 + dmulscale16(sinang,dax,cosang,day); + ryi[0] = y1 + dmulscale16(sinang,day,-cosang,dax); + l = xspan*xrepeat; + rxi[1] = rxi[0] - mulscale16(sinang,l); + ryi[1] = ryi[0] + mulscale16(cosang,l); + l = yspan*yrepeat; + k = -mulscale16(cosang,l); rxi[2] = rxi[1]+k; rxi[3] = rxi[0]+k; + k = -mulscale16(sinang,l); ryi[2] = ryi[1]+k; ryi[3] = ryi[0]+k; + + dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist); + day = mulscale14(sintable[(spr->ang-256)&2047],walldist); + + if ((rxi[0]-(*x))*(ryi[1]-(*y)) < (rxi[1]-(*x))*(ryi[0]-(*y))) + { + if (clipinsideboxline(cx,cy,rxi[1],ryi[1],rxi[0],ryi[0],rad) != 0) + addclipline(rxi[1]-day,ryi[1]+dax,rxi[0]+dax,ryi[0]+day,(short)j+49152); + } + else if ((rxi[2]-(*x))*(ryi[3]-(*y)) < (rxi[3]-(*x))*(ryi[2]-(*y))) + { + if (clipinsideboxline(cx,cy,rxi[3],ryi[3],rxi[2],ryi[2],rad) != 0) + addclipline(rxi[3]+day,ryi[3]-dax,rxi[2]-dax,ryi[2]-day,(short)j+49152); + } + + if ((rxi[1]-(*x))*(ryi[2]-(*y)) < (rxi[2]-(*x))*(ryi[1]-(*y))) + { + if (clipinsideboxline(cx,cy,rxi[2],ryi[2],rxi[1],ryi[1],rad) != 0) + addclipline(rxi[2]-dax,ryi[2]-day,rxi[1]-day,ryi[1]+dax,(short)j+49152); + } + else if ((rxi[3]-(*x))*(ryi[0]-(*y)) < (rxi[0]-(*x))*(ryi[3]-(*y))) + { + if (clipinsideboxline(cx,cy,rxi[0],ryi[0],rxi[3],ryi[3],rad) != 0) + addclipline(rxi[0]+dax,ryi[0]+day,rxi[3]+day,ryi[3]-dax,(short)j+49152); + } + } + break; } } } while (clipsectcnt < clipsectnum); @@ -8634,7 +8634,7 @@ long clipmove (long *x, long *y, long *z, short *sectnum, if (templong2 > 0) { if (templong2 < templong1) - { *sectnum = j; templong1 = templong2; } + { *sectnum = j; templong1 = templong2; } } else { @@ -8649,7 +8649,7 @@ long clipmove (long *x, long *y, long *z, short *sectnum, return(retval); } if (templong2 < templong1) - { *sectnum = j; templong1 = templong2; } + { *sectnum = j; templong1 = templong2; } } } @@ -8661,7 +8661,7 @@ long clipmove (long *x, long *y, long *z, short *sectnum, // pushmove // long pushmove (long *x, long *y, long *z, short *sectnum, - long walldist, long ceildist, long flordist, unsigned long cliptype) + long walldist, long ceildist, long flordist, unsigned long cliptype) { sectortype *sec, *sec2; walltype *wal, *wal2; @@ -8737,7 +8737,7 @@ long pushmove (long *x, long *y, long *z, short *sectnum, sec2 = §or[wal->nextsector]; - //Find closest point on wall (dax, day) to (*x, *y) + //Find closest point on wall (dax, day) to (*x, *y) dax = wall[wal->point2].x-wal->x; day = wall[wal->point2].y-wal->y; daz = dax*((*x)-wal->x) + day*((*y)-wal->y); @@ -8853,7 +8853,7 @@ void updatesectorz(long x, long y, long z, short *sectnum) getzsofslope(i, x, y, &cz, &fz); if ((z >= cz) && (z <= fz)) if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } + { *sectnum = i; return; } } wal++; j--; } while (j != 0); @@ -8864,7 +8864,7 @@ void updatesectorz(long x, long y, long z, short *sectnum) getzsofslope(i, x, y, &cz, &fz); if ((z >= cz) && (z <= fz)) if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } + { *sectnum = i; return; } } *sectnum = -1; @@ -8912,8 +8912,8 @@ long krand(void) // getzrange // void getzrange(long x, long y, long z, short sectnum, - long *ceilz, long *ceilhit, long *florz, long *florhit, - long walldist, unsigned long cliptype) + long *ceilz, long *ceilhit, long *florz, long *florhit, + long walldist, unsigned long cliptype) { sectortype *sec; walltype *wal, *wal2; @@ -8932,7 +8932,7 @@ void getzrange(long x, long y, long z, short sectnum, return; } - //Extra walldist for sprites on sector lines + //Extra walldist for sprites on sector lines i = walldist+MAXCLIPDIST+1; xmin = x-i; ymin = y-i; xmax = x+i; ymax = y+i; @@ -8988,9 +8988,9 @@ void getzrange(long x, long y, long z, short sectnum, if (dy > 0) day -= dy*MAXCLIPDIST; else day += dy*MAXCLIPDIST; if (dax >= day) continue; - //It actually got here, through all the continue's!!! + //It actually got here, through all the continue's!!! getzsofslope((short)k,x,y,&daz,&daz2); - if (daz > *ceilz) { *ceilz = daz; *ceilhit = k+16384; } + if (daz > *ceilz) { *ceilz = daz; *ceilhit = k+16384; } if (daz2 < *florz) { *florz = daz2; *florhit = k+16384; } } } @@ -9010,89 +9010,89 @@ void getzrange(long x, long y, long z, short sectnum, clipyou = 0; switch(cstat&48) { - case 0: - k = walldist+(spr->clipdist<<2)+1; - if ((klabs(x1-x) <= k) && (klabs(y1-y) <= k)) - { - daz = spr->z; - k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1); - if (cstat&128) daz += k; - if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - daz2 = daz - (k<<1); - clipyou = 1; - } - break; - case 16: - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - if ((cstat&4) > 0) xoff = -xoff; - k = spr->ang; l = spr->xrepeat; - dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; - l = tilesizx[tilenum]; k = (l>>1)+xoff; - x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); - y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); - if (clipinsideboxline(x,y,x1,y1,x2,y2,walldist+1) != 0) - { - daz = spr->z; k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1); - if (cstat&128) daz += k; - if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); - daz2 = daz-(k<<1); - clipyou = 1; - } - break; - case 32: - daz = spr->z; daz2 = daz; + case 0: + k = walldist+(spr->clipdist<<2)+1; + if ((klabs(x1-x) <= k) && (klabs(y1-y) <= k)) + { + daz = spr->z; + k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1); + if (cstat&128) daz += k; + if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); + daz2 = daz - (k<<1); + clipyou = 1; + } + break; + case 16: + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + if ((cstat&4) > 0) xoff = -xoff; + k = spr->ang; l = spr->xrepeat; + dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; + l = tilesizx[tilenum]; k = (l>>1)+xoff; + x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); + y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + if (clipinsideboxline(x,y,x1,y1,x2,y2,walldist+1) != 0) + { + daz = spr->z; k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1); + if (cstat&128) daz += k; + if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2); + daz2 = daz-(k<<1); + clipyou = 1; + } + break; + case 32: + daz = spr->z; daz2 = daz; - if ((cstat&64) != 0) - if ((z > daz) == ((cstat&8)==0)) continue; + if ((cstat&64) != 0) + if ((z > daz) == ((cstat&8)==0)) continue; - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); - if ((cstat&4) > 0) xoff = -xoff; - if ((cstat&8) > 0) yoff = -yoff; + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); + if ((cstat&4) > 0) xoff = -xoff; + if ((cstat&8) > 0) yoff = -yoff; - ang = spr->ang; - cosang = sintable[(ang+512)&2047]; sinang = sintable[ang]; - xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; - yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; + ang = spr->ang; + cosang = sintable[(ang+512)&2047]; sinang = sintable[ang]; + xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; + yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; - x1 += dmulscale16(sinang,dax,cosang,day)-x; - y1 += dmulscale16(sinang,day,-cosang,dax)-y; - l = xspan*xrepeat; - x2 = x1 - mulscale16(sinang,l); - y2 = y1 + mulscale16(cosang,l); - l = yspan*yrepeat; - k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; - k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; + dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; + x1 += dmulscale16(sinang,dax,cosang,day)-x; + y1 += dmulscale16(sinang,day,-cosang,dax)-y; + l = xspan*xrepeat; + x2 = x1 - mulscale16(sinang,l); + y2 = y1 + mulscale16(cosang,l); + l = yspan*yrepeat; + k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; + k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; - dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist+4); - day = mulscale14(sintable[(spr->ang-256)&2047],walldist+4); - x1 += dax; x2 -= day; x3 -= dax; x4 += day; - y1 += day; y2 += dax; y3 -= day; y4 -= dax; + dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist+4); + day = mulscale14(sintable[(spr->ang-256)&2047],walldist+4); + x1 += dax; x2 -= day; x3 -= dax; x4 += day; + y1 += day; y2 += dax; y3 -= day; y4 -= dax; - if ((y1^y2) < 0) - { - if ((x1^x2) < 0) clipyou ^= (x1*y2= 0) clipyou ^= 1; - } - if ((y2^y3) < 0) - { - if ((x2^x3) < 0) clipyou ^= (x2*y3= 0) clipyou ^= 1; - } - if ((y3^y4) < 0) - { - if ((x3^x4) < 0) clipyou ^= (x3*y4= 0) clipyou ^= 1; - } - if ((y4^y1) < 0) - { - if ((x4^x1) < 0) clipyou ^= (x4*y1= 0) clipyou ^= 1; - } - break; + if ((y1^y2) < 0) + { + if ((x1^x2) < 0) clipyou ^= (x1*y2= 0) clipyou ^= 1; + } + if ((y2^y3) < 0) + { + if ((x2^x3) < 0) clipyou ^= (x2*y3= 0) clipyou ^= 1; + } + if ((y3^y4) < 0) + { + if ((x3^x4) < 0) clipyou ^= (x3*y4= 0) clipyou ^= 1; + } + if ((y4^y1) < 0) + { + if ((x4^x1) < 0) clipyou ^= (x4*y1= 0) clipyou ^= 1; + } + break; } if (clipyou != 0) @@ -9126,7 +9126,7 @@ void setview(long x1, long y1, long x2, long y2) for(i=0;i= xdim-1) && (cy2 >= ydim-1) && - (sx == (160<<16)) && (sy == (100<<16)) && (z == 65536L) && (a == 0) && ((dastat&1) == 0)) + (sx == (160<<16)) && (sy == (100<<16)) && (z == 65536L) && (a == 0) && ((dastat&1) == 0)) permhead = permtail = 0; if ((dastat&128) == 0) return; @@ -9196,7 +9196,7 @@ void rotatesprite(long sx, long sy, long z, short a, short picnum, signed char d per->cx1 = cx1; per->cy1 = cy1; per->cx2 = cx2; per->cy2 = cy2; per->uniqid = guniqhudid; //JF extension - //Would be better to optimize out true bounding boxes + //Would be better to optimize out true bounding boxes if (dastat&64) //If non-masking write, checking for overlapping cases { for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1))) @@ -9251,7 +9251,7 @@ void makepalookup(long palnum, char *remapbuf, signed char r, signed char g, sig if (palookup[palnum] == NULL) { - //Allocate palookup buffer + //Allocate palookup buffer if ((palookup[palnum] = (char *)kkmalloc(numpalookups<<8)) == NULL) allocache((long*)&palookup[palnum],numpalookups<<8,&permanentlock); } @@ -9266,7 +9266,7 @@ void makepalookup(long palnum, char *remapbuf, signed char r, signed char g, sig ptr = (char *)(FP_OFF(palookup[0])+remapbuf[i]); ptr2 = (char *)(FP_OFF(palookup[palnum])+i); for(j=0;j> 6 ) ) >> 2; - tempbuf[k++] = - (curpalettefaded[i].g = - p.g + ( ( ( (long)palfadergb.g - (long)p.g ) * (long)offset ) >> 6 ) ) >> 2; - tempbuf[k++] = - (curpalettefaded[i].r = - p.r + ( ( ( (long)palfadergb.r - (long)p.r ) * (long)offset ) >> 6 ) ) >> 2; - tempbuf[k++] = curpalettefaded[i].f = 0; - } + palfadergb.r = min(63,r) << 2; + palfadergb.g = min(63,g) << 2; + palfadergb.b = min(63,b) << 2; + palfadedelta = min(63,offset) << 2; + + k = 0; + for (i=0;i<256;i++) { + if (gammabrightness) p = curpalette[i]; + else { + p.b = britable[curbrightness][ curpalette[i].b ]; + p.g = britable[curbrightness][ curpalette[i].g ]; + p.r = britable[curbrightness][ curpalette[i].r ]; + } + + tempbuf[k++] = + (curpalettefaded[i].b = + p.b + ( ( ( (long)palfadergb.b - (long)p.b ) * (long)offset ) >> 6 ) ) >> 2; + tempbuf[k++] = + (curpalettefaded[i].g = + p.g + ( ( ( (long)palfadergb.g - (long)p.g ) * (long)offset ) >> 6 ) ) >> 2; + tempbuf[k++] = + (curpalettefaded[i].r = + p.r + ( ( ( (long)palfadergb.r - (long)p.r ) * (long)offset ) >> 6 ) ) >> 2; + tempbuf[k++] = curpalettefaded[i].f = 0; + } setpalette(0,256,(char*)tempbuf); } @@ -9410,21 +9410,21 @@ void clearview(long dacol) if (qsetmode != 200) return; #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { - palette_t p; - if (gammabrightness) p = curpalette[dacol]; - else { - p.r = britable[curbrightness][ curpalette[dacol].r ]; - p.g = britable[curbrightness][ curpalette[dacol].g ]; - p.b = britable[curbrightness][ curpalette[dacol].b ]; - } - bglClearColor(((float)p.r)/255.0, - ((float)p.g)/255.0, - ((float)p.b)/255.0, - 0); - bglClear(GL_COLOR_BUFFER_BIT); - return; - } + if (rendmode == 3) { + palette_t p; + if (gammabrightness) p = curpalette[dacol]; + else { + p.r = britable[curbrightness][ curpalette[dacol].r ]; + p.g = britable[curbrightness][ curpalette[dacol].g ]; + p.b = britable[curbrightness][ curpalette[dacol].b ]; + } + bglClearColor(((float)p.r)/255.0, + ((float)p.g)/255.0, + ((float)p.b)/255.0, + 0); + bglClear(GL_COLOR_BUFFER_BIT); + return; + } #endif begindrawing(); //{{{ @@ -9451,22 +9451,22 @@ void clearallviews(long dacol) //dacol += (dacol<<8); dacol += (dacol<<16); #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { - palette_t p; - if (gammabrightness) p = curpalette[dacol]; - else { - p.r = britable[curbrightness][ curpalette[dacol].r ]; - p.g = britable[curbrightness][ curpalette[dacol].g ]; - p.b = britable[curbrightness][ curpalette[dacol].b ]; - } - bglViewport(0,0,xdim,ydim); glox1 = -1; - bglClearColor(((float)p.r)/255.0, - ((float)p.g)/255.0, - ((float)p.b)/255.0, - 0); - bglClear(GL_COLOR_BUFFER_BIT); - return; - } + if (rendmode == 3) { + palette_t p; + if (gammabrightness) p = curpalette[dacol]; + else { + p.r = britable[curbrightness][ curpalette[dacol].r ]; + p.g = britable[curbrightness][ curpalette[dacol].g ]; + p.b = britable[curbrightness][ curpalette[dacol].b ]; + } + bglViewport(0,0,xdim,ydim); glox1 = -1; + bglClearColor(((float)p.r)/255.0, + ((float)p.g)/255.0, + ((float)p.b)/255.0, + 0); + bglClear(GL_COLOR_BUFFER_BIT); + return; + } #endif begindrawing(); //{{{ @@ -9485,21 +9485,21 @@ void clearallviews(long dacol) void plotpixel(long x, long y, char col) { #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3 && qsetmode == 200) { - palette_t p; - if (gammabrightness) p = curpalette[col]; - else { - p.r = britable[curbrightness][ curpalette[col].r ]; - p.g = britable[curbrightness][ curpalette[col].g ]; - p.b = britable[curbrightness][ curpalette[col].b ]; - } + if (rendmode == 3 && qsetmode == 200) { + palette_t p; + if (gammabrightness) p = curpalette[col]; + else { + p.r = britable[curbrightness][ curpalette[col].r ]; + p.g = britable[curbrightness][ curpalette[col].g ]; + p.b = britable[curbrightness][ curpalette[col].b ]; + } - setpolymost2dview(); // JBF 20040205: more efficient setup + setpolymost2dview(); // JBF 20040205: more efficient setup - bglBegin(GL_POINTS); - bglColor4ub(p.r,p.g,p.b,255); - bglVertex2i(x,y); - bglEnd(); + bglBegin(GL_POINTS); + bglColor4ub(p.r,p.g,p.b,255); + bglVertex2i(x,y); + bglEnd(); return; } @@ -9529,7 +9529,7 @@ char getpixel(long x, long y) } - //MUST USE RESTOREFORDRAWROOMS AFTER DRAWING +//MUST USE RESTOREFORDRAWROOMS AFTER DRAWING // // setviewtotile @@ -9538,7 +9538,7 @@ void setviewtotile(short tilenume, long xsiz, long ysiz) { long i, j; - //DRAWROOMS TO TILE BACKUP&SET CODE + //DRAWROOMS TO TILE BACKUP&SET CODE tilesizx[tilenume] = xsiz; tilesizy[tilenume] = ysiz; bakxsiz[setviewcnt] = xsiz; bakysiz[setviewcnt] = ysiz; bakframeplace[setviewcnt] = frameplace; frameplace = waloff[tilenume]; @@ -9583,7 +9583,7 @@ void setviewback(void) #endif setview(bakwindowx1[setviewcnt],bakwindowy1[setviewcnt], - bakwindowx2[setviewcnt],bakwindowy2[setviewcnt]); + bakwindowx2[setviewcnt],bakwindowy2[setviewcnt]); copybufbyte(&bakumost[windowx1],&startumost[windowx1],(windowx2-windowx1+1)*sizeof(startumost[0])); copybufbyte(&bakdmost[windowx1],&startdmost[windowx1],(windowx2-windowx1+1)*sizeof(startdmost[0])); frameplace = bakframeplace[setviewcnt]; @@ -9607,7 +9607,7 @@ void squarerotatetile(short tilenume) xsiz = tilesizx[tilenume]; ysiz = tilesizy[tilenume]; - //supports square tiles only for rotation part + //supports square tiles only for rotation part if (xsiz == ysiz) { k = (xsiz<<1); @@ -9616,7 +9616,7 @@ void squarerotatetile(short tilenume) ptr1 = (char *)(waloff[tilenume]+i*(xsiz+1)); ptr2 = ptr1; if ((i&1) != 0) { ptr1--; ptr2 -= xsiz; swapchar(ptr1,ptr2); } for(j=(i>>1)-1;j>=0;j--) - { ptr1 -= 2; ptr2 -= k; swapchar2(ptr1,ptr2,xsiz); } + { ptr1 -= 2; ptr2 -= k; swapchar2(ptr1,ptr2,xsiz); } } } } @@ -9652,24 +9652,24 @@ void completemirror(void) if (rendmode) return; #endif - //Can't reverse with uninitialized data - if (inpreparemirror) { inpreparemirror = 0; return; } + //Can't reverse with uninitialized data +if (inpreparemirror) { inpreparemirror = 0; return; } if (mirrorsx1 > 0) mirrorsx1--; if (mirrorsx2 < windowx2-windowx1-1) mirrorsx2++; if (mirrorsx2 < mirrorsx1) return; - begindrawing(); - p = frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1; - i = windowx2-windowx1-mirrorsx2-mirrorsx1; mirrorsx2 -= mirrorsx1; - for(dy=mirrorsy2-mirrorsy1-1;dy>=0;dy--) - { - copybufbyte((void*)(p+1),tempbuf,mirrorsx2+1); - tempbuf[mirrorsx2] = tempbuf[mirrorsx2-1]; - copybufreverse(&tempbuf[mirrorsx2],(void*)(p+i),mirrorsx2+1); - p += ylookup[1]; - faketimerhandler(); - } - enddrawing(); + begindrawing(); + p = frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1; + i = windowx2-windowx1-mirrorsx2-mirrorsx1; mirrorsx2 -= mirrorsx1; + for(dy=mirrorsy2-mirrorsy1-1;dy>=0;dy--) + { + copybufbyte((void*)(p+1),tempbuf,mirrorsx2+1); + tempbuf[mirrorsx2] = tempbuf[mirrorsx2-1]; + copybufreverse(&tempbuf[mirrorsx2],(void*)(p+i),mirrorsx2+1); + p += ylookup[1]; + faketimerhandler(); + } + enddrawing(); } @@ -9766,7 +9766,7 @@ void alignceilslope(short dasect, long x, long y, long z) i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return; sector[dasect].ceilingheinum = scale((z-sector[dasect].ceilingz)<<8, - nsqrtasm(dax*dax+day*day),i); + nsqrtasm(dax*dax+day*day),i); if (sector[dasect].ceilingheinum == 0) sector[dasect].ceilingstat &= ~2; else sector[dasect].ceilingstat |= 2; @@ -9787,7 +9787,7 @@ void alignflorslope(short dasect, long x, long y, long z) i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return; sector[dasect].floorheinum = scale((z-sector[dasect].floorz)<<8, - nsqrtasm(dax*dax+day*day),i); + nsqrtasm(dax*dax+day*day),i); if (sector[dasect].floorheinum == 0) sector[dasect].floorstat &= ~2; else sector[dasect].floorstat |= 2; @@ -9836,7 +9836,7 @@ void setfirstwall(short sectnum, short newfirstwall) i = wall[i].point2; } while (i != newfirstwall); - //Put correct loop at beginning + //Put correct loop at beginning dagoalloop = loopnumofsector(sectnum,newfirstwall); if (dagoalloop > 0) { @@ -9885,26 +9885,26 @@ void drawline256(long x1, long y1, long x2, long y2, char col) col = palookup[0][col]; #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) - { - palette_t p; - if (gammabrightness) p = curpalette[col]; - else { - p.r = britable[curbrightness][ curpalette[col].r ]; - p.g = britable[curbrightness][ curpalette[col].g ]; - p.b = britable[curbrightness][ curpalette[col].b ]; - } + if (rendmode == 3) + { + palette_t p; + if (gammabrightness) p = curpalette[col]; + else { + p.r = britable[curbrightness][ curpalette[col].r ]; + p.g = britable[curbrightness][ curpalette[col].g ]; + p.b = britable[curbrightness][ curpalette[col].b ]; + } - setpolymost2dview(); // JBF 20040205: more efficient setup + setpolymost2dview(); // JBF 20040205: more efficient setup - bglBegin(GL_LINES); - bglColor4ub(p.r,p.g,p.b,255); - bglVertex2f((float)x1/4096.0,(float)y1/4096.0); - bglVertex2f((float)x2/4096.0,(float)y2/4096.0); - bglEnd(); + bglBegin(GL_LINES); + bglColor4ub(p.r,p.g,p.b,255); + bglVertex2f((float)x1/4096.0,(float)y1/4096.0); + bglVertex2f((float)x2/4096.0,(float)y2/4096.0); + bglEnd(); - return; - } + return; + } #endif dx = x2-x1; dy = y2-y1; @@ -9997,26 +9997,26 @@ void drawline16(long x1, long y1, long x2, long y2, char col) if (dx >= 0) { if ((x1 >= xres) || (x2 < 0)) return; - if (x1 < 0) { if (dy) y1 += scale(0-x1,dy,dx); x1 = 0; } - if (x2 >= xres) { if (dy) y2 += scale(xres-1-x2,dy,dx); x2 = xres-1; } + if (x1 < 0) { if (dy) y1 += scale(0-x1,dy,dx); x1 = 0; } + if (x2 >= xres) { if (dy) y2 += scale(xres-1-x2,dy,dx); x2 = xres-1; } } else { if ((x2 >= xres) || (x1 < 0)) return; - if (x2 < 0) { if (dy) y2 += scale(0-x2,dy,dx); x2 = 0; } - if (x1 >= xres) { if (dy) y1 += scale(xres-1-x1,dy,dx); x1 = xres-1; } + if (x2 < 0) { if (dy) y2 += scale(0-x2,dy,dx); x2 = 0; } + if (x1 >= xres) { if (dy) y1 += scale(xres-1-x1,dy,dx); x1 = xres-1; } } if (dy >= 0) { if ((y1 >= ydim16) || (y2 < 0)) return; - if (y1 < 0) { if (dx) x1 += scale(0-y1,dx,dy); y1 = 0; if (x1 < 0) x1 = 0; } - if (y2 >= ydim16) { if (dx) x2 += scale(ydim16-1-y2,dx,dy); y2 = ydim16-1; if (x2 < 0) x2 = 0; } + if (y1 < 0) { if (dx) x1 += scale(0-y1,dx,dy); y1 = 0; if (x1 < 0) x1 = 0; } + if (y2 >= ydim16) { if (dx) x2 += scale(ydim16-1-y2,dx,dy); y2 = ydim16-1; if (x2 < 0) x2 = 0; } } else { if ((y2 >= ydim16) || (y1 < 0)) return; - if (y2 < 0) { if (dx) x2 += scale(0-y2,dx,dy); y2 = 0; if (x2 < 0) x2 = 0; } - if (y1 >= ydim16) { if (dx) x1 += scale(ydim16-1-y1,dx,dy); y1 = ydim16-1; if (x1 < 0) x1 = 0; } + if (y2 < 0) { if (dx) x2 += scale(0-y2,dx,dy); y2 = 0; if (x2 < 0) x2 = 0; } + if (y1 >= ydim16) { if (dx) x1 += scale(ydim16-1-y1,dx,dy); y1 = ydim16-1; if (x1 < 0) x1 = 0; } } dx = klabs(x2-x1)+1; dy = klabs(y2-y1)+1; @@ -10029,21 +10029,21 @@ void drawline16(long x1, long y1, long x2, long y2, char col) } d = 0; if (y2 > y1) pinc = bytesperline; else pinc = -bytesperline; - + begindrawing(); //{{{ p = (y1*bytesperline)+x1+frameplace; if (dy == 0 && drawlinepat == 0xffffffff) { i = ((long)col<<24)|((long)col<<16)|((long)col<<8)|col; clearbufbyte((void *)p, dx, i); } else - for(i=dx;i>0;i--) - { - if (drawlinepat & pow2long[(patc++)&31]) - drawpixel((char *)p, col); - d += dy; + for(i=dx;i>0;i--) + { + if (drawlinepat & pow2long[(patc++)&31]) + drawpixel((char *)p, col); + d += dy; if (d >= dx) { d -= dx; p += pinc; } - p++; - } + p++; + } enddrawing(); //}}} return; } @@ -10063,7 +10063,7 @@ void drawline16(long x1, long y1, long x2, long y2, char col) if (drawlinepat & pow2long[(patc++)&31]) drawpixel((char *)p, col); d += dx; - if (d >= dy) { d -= dy; p += pinc; } + if (d >= dy) { d -= dy; p += pinc; } p += bytesperline; } enddrawing(); //}}} @@ -10095,7 +10095,7 @@ void drawcircle16(long x1, long y1, long r, char col) d = 1 - r; de = 2; dse = 5 - (r << 1); - + begindrawing(); p = (y1*bytesperline)+x1+frameplace; @@ -10188,7 +10188,7 @@ void qsetmode640350(void) ydim16 = 350; halfxdim16 = 320; midydim16 = 146; - + begindrawing(); //{{{ clearbuf((char *)frameplace, (bytesperline*350L) >> 2, 0); enddrawing(); //}}} @@ -10218,7 +10218,7 @@ void qsetmode640480(void) ydim16 = 336; halfxdim16 = 320; midydim16 = 200; - + begindrawing(); //{{{ clearbuf((char *)(frameplace + (336l*bytesperline)), (bytesperline*144L) >> 2, 0x08080808l); clearbuf((char *)frameplace, (bytesperline*336L) >> 2, 0L); @@ -10249,13 +10249,13 @@ void qsetmodeany(long daxdim, long daydim) ydim16 = yres - STATUS2DSIZ; halfxdim16 = xres >> 1; midydim16 = scale(200,yres,480); - + begindrawing(); //{{{ clearbuf((char *)(frameplace + (ydim16*bytesperline)), (bytesperline*STATUS2DSIZ) >> 2, 0x08080808l); clearbuf((char *)frameplace, (ydim16*bytesperline) >> 2, 0L); enddrawing(); //}}} } - + qsetmode = ((daxdim<<16)|(daydim&0xffff)); } @@ -10266,7 +10266,7 @@ void qsetmodeany(long daxdim, long daydim) void clear2dscreen(void) { int clearsz; - + begindrawing(); //{{{ if (qsetmode == 350) clearsz = 350; else { @@ -10285,53 +10285,53 @@ void draw2dgrid(long posxe, long posye, short ange, long zoome, short gride) { long i, xp1, yp1, xp2=0, yp2, tempy; - if (gride > 0) - { - begindrawing(); //{{{ - - yp1 = midydim16-mulscale14(posye+editorgridextent,zoome); - if (yp1 < 0) yp1 = 0; - yp2 = midydim16-mulscale14(posye-editorgridextent,zoome); - if (yp2 >= ydim16) yp2 = ydim16-1; + if (gride > 0) + { + begindrawing(); //{{{ - if ((yp1 < ydim16) && (yp2 >= 0) && (yp2 >= yp1)) - { - xp1 = halfxdim16-mulscale14(posxe+editorgridextent,zoome); - for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride)) - { - xp2 = xp1; - xp1 = halfxdim16-mulscale14(posxe-i,zoome); - if (xp1 >= xdim) break; - if (xp1 >= 0) - { - if (xp1 != xp2) - { - drawline16(xp1,yp1,xp1,yp2,8); - } - } - } - if ((i >= editorgridextent) && (xp1 < xdim)) - xp2 = xp1; - if ((xp2 >= 0) && (xp2 < xdim)) - { - drawline16(xp2,yp1,xp2,yp2,8); - } - } - xp1 = mulscale14(posxe+editorgridextent,zoome); - xp2 = mulscale14(posxe-editorgridextent,zoome); - tempy = 0x80000000l; - for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride)) - { - yp1 = (((posye-i)*zoome)>>14); - if (yp1 != tempy) - { - if ((yp1 > midydim16-ydim16) && (yp1 <= midydim16)) - { - drawline16(halfxdim16-xp1,midydim16-yp1,halfxdim16-xp2,midydim16-yp1,8); - tempy = yp1; - } - } - } + yp1 = midydim16-mulscale14(posye+editorgridextent,zoome); + if (yp1 < 0) yp1 = 0; + yp2 = midydim16-mulscale14(posye-editorgridextent,zoome); + if (yp2 >= ydim16) yp2 = ydim16-1; + + if ((yp1 < ydim16) && (yp2 >= 0) && (yp2 >= yp1)) + { + xp1 = halfxdim16-mulscale14(posxe+editorgridextent,zoome); + for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride)) + { + xp2 = xp1; + xp1 = halfxdim16-mulscale14(posxe-i,zoome); + if (xp1 >= xdim) break; + if (xp1 >= 0) + { + if (xp1 != xp2) + { + drawline16(xp1,yp1,xp1,yp2,8); + } + } + } + if ((i >= editorgridextent) && (xp1 < xdim)) + xp2 = xp1; + if ((xp2 >= 0) && (xp2 < xdim)) + { + drawline16(xp2,yp1,xp2,yp2,8); + } + } + xp1 = mulscale14(posxe+editorgridextent,zoome); + xp2 = mulscale14(posxe-editorgridextent,zoome); + tempy = 0x80000000l; + for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride)) + { + yp1 = (((posye-i)*zoome)>>14); + if (yp1 != tempy) + { + if ((yp1 > midydim16-ydim16) && (yp1 <= midydim16)) + { + drawline16(halfxdim16-xp1,midydim16-yp1,halfxdim16-xp2,midydim16-yp1,8); + tempy = yp1; + } + } + } enddrawing(); //}}} } } @@ -10692,7 +10692,7 @@ void draw2dscreen(long posxe, long posye, short ange, long zoome, short gride) co[ii][1] = s; } - drawlinepat = 0xcfcfcfcf; + drawlinepat = 0xcfcfcfcf; for (ii=0;ii<4;ii++) { drawline16(halfxdim16 + xp1 + co[ii][0], midydim16 + yp1 - co[ii][1], halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1], @@ -10772,48 +10772,48 @@ void printext256(long xpos, long ypos, short col, short backcol, char *name, cha if (rendmode == 3) { long xx, yy; int lc=-1; - palette_t p,b; + palette_t p,b; - if (gammabrightness) { - p = curpalette[col]; - b = curpalette[backcol]; - } else { - p.r = britable[curbrightness][ curpalette[col].r ]; - p.g = britable[curbrightness][ curpalette[col].g ]; - p.b = britable[curbrightness][ curpalette[col].b ]; - b.r = britable[curbrightness][ curpalette[backcol].r ]; - b.g = britable[curbrightness][ curpalette[backcol].g ]; - b.b = britable[curbrightness][ curpalette[backcol].b ]; - } - - setpolymost2dview(); - bglDisable(GL_ALPHA_TEST); - bglDepthMask(GL_FALSE); // disable writing to the z-buffer + if (gammabrightness) { + p = curpalette[col]; + b = curpalette[backcol]; + } else { + p.r = britable[curbrightness][ curpalette[col].r ]; + p.g = britable[curbrightness][ curpalette[col].g ]; + p.b = britable[curbrightness][ curpalette[col].b ]; + b.r = britable[curbrightness][ curpalette[backcol].r ]; + b.g = britable[curbrightness][ curpalette[backcol].g ]; + b.b = britable[curbrightness][ curpalette[backcol].b ]; + } - bglBegin(GL_POINTS); - - for(i=0;name[i];i++) { - letptr = &fontptr[name[i]<<3]; - xx = stx-fontsize; - yy = ypos+7 + 2; //+1 is hack! - for(y=7;y>=0;y--) { - for(x=charxsiz-1;x>=0;x--) { - if (letptr[y]&pow2char[7-fontsize-x]) { - if (lc!=col) - bglColor4ub(p.r,p.g,p.b,255); - lc = col; - bglVertex2i(xx+x,yy); - } else if (backcol >= 0) { - if (lc!=backcol) - bglColor4ub(b.r,b.g,b.b,255); - lc = backcol; - bglVertex2i(xx+x,yy); - } - } - yy--; - } - stx += charxsiz; - } + setpolymost2dview(); + bglDisable(GL_ALPHA_TEST); + bglDepthMask(GL_FALSE); // disable writing to the z-buffer + + bglBegin(GL_POINTS); + + for(i=0;name[i];i++) { + letptr = &fontptr[name[i]<<3]; + xx = stx-fontsize; + yy = ypos+7 + 2; //+1 is hack! + for(y=7;y>=0;y--) { + for(x=charxsiz-1;x>=0;x--) { + if (letptr[y]&pow2char[7-fontsize-x]) { + if (lc!=col) + bglColor4ub(p.r,p.g,p.b,255); + lc = col; + bglVertex2i(xx+x,yy); + } else if (backcol >= 0) { + if (lc!=backcol) + bglColor4ub(b.r,b.g,b.b,255); + lc = backcol; + bglVertex2i(xx+x,yy); + } + } + yy--; + } + stx += charxsiz; + } bglEnd(); bglDepthMask(GL_TRUE); // re-enable writing to the z-buffer @@ -10821,7 +10821,7 @@ void printext256(long xpos, long ypos, short col, short backcol, char *name, cha return; } #endif - + begindrawing(); //{{{ for(i=0;name[i];i++) { @@ -10867,7 +10867,7 @@ long screencapture_tga(char *filename, char inverseit) fn[i++] = 't'; fn[i++] = 'g'; fn[i++] = 'a'; - + if ((fil = Bfopen(fn,"rb")) == NULL) break; Bfclose(fil); capturecount++; @@ -10952,7 +10952,7 @@ long screencapture_tga(char *filename, char inverseit) } enddrawing(); //}}} - + Bfclose(fil); OSD_Printf("Saved screenshot to %s\n", fn); Bfree(fn); @@ -10990,16 +10990,16 @@ static void writepcxline(char *buf, long bytes, long step, BFILE *fp) runCount++; if (runCount == 63) { writepcxbyte(last, runCount, fp); - runCount = 0; - } - } else { + runCount = 0; + } + } else { if (runCount) writepcxbyte(last, runCount, fp); - last = ths; + last = ths; runCount = 1; - } } - + } + if (runCount) writepcxbyte(last, runCount, fp); if (bytes&1) writepcxbyte(0, 1, fp); } @@ -11024,7 +11024,7 @@ long screencapture_pcx(char *filename, char inverseit) fn[i++] = 'p'; fn[i++] = 'c'; fn[i++] = 'x'; - + if ((fil = Bfopen(fn,"rb")) == NULL) break; Bfclose(fil); capturecount++; @@ -11044,7 +11044,7 @@ long screencapture_pcx(char *filename, char inverseit) head[14] = 72; head[15] = 0; head[65] = 1; // 8-bit head[68] = 1; - + #if defined(POLYMOST) && defined(USE_OPENGL) if (rendmode >= 3 && qsetmode == 200) { head[65] = 3; // 24-bit @@ -11197,7 +11197,7 @@ void invalidatetile(short tilenume, long pal, long how) #if defined(POLYMOST) && defined(USE_OPENGL) int numpal, firstpal, np; int hp; - + if (rendmode < 3) return; if (pal < 0) { @@ -11227,7 +11227,7 @@ void setpolymost2dview(void) { #if defined(POLYMOST) && defined(USE_OPENGL) if (rendmode < 3) return; - + if (gloy1 != -1) { bglViewport(0,0,xres,yres); bglMatrixMode(GL_PROJECTION); @@ -11238,7 +11238,7 @@ void setpolymost2dview(void) } gloy1 = -1; - + bglDisable(GL_DEPTH_TEST); bglDisable(GL_TEXTURE_2D); bglDisable(GL_BLEND); diff --git a/polymer/build/src/game.c b/polymer/build/src/game.c index a8c4747c1..8651ca75c 100644 --- a/polymer/build/src/game.c +++ b/polymer/build/src/game.c @@ -106,13 +106,13 @@ KEN'S STATUS DEFINITIONS: (Please define your own statuses for your games) typedef struct { - long x, y, z; + long x, y, z; } point3d; typedef struct { - signed char fvel, svel, avel; - short bits; + signed char fvel, svel, avel; + short bits; } input; static long screentilt = 0, oscreentilt = 0; @@ -125,11 +125,11 @@ static long fvel2, svel2, avel2; #define NUMKEYS 19 char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0}; char keys[NUMKEYS] = -{ - 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, - 0x1e,0x2c,0xd1,0xc9,0x33,0x34, - 0x9c,0x1c,0xd,0xc,0xf -}; + { + 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, + 0x1e,0x2c,0xd1,0xc9,0x33,0x34, + 0x9c,0x1c,0xd,0xc,0xf + }; long xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480; // JBF 20050318: config.c expects to find these static long digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000}; @@ -146,7 +146,7 @@ static long lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS]; static long lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS]; static long lavaradx[24][96], lavarady[24][96], lavaradcnt[32]; - //Shared player variables +//Shared player variables static long posx[MAXPLAYERS], posy[MAXPLAYERS], posz[MAXPLAYERS]; static long horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS]; static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS]; @@ -162,7 +162,7 @@ static char revolvedoorstat[MAXPLAYERS]; static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS]; static long revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS]; - //ENGINE CONTROLLED MULTIPLAYER VARIABLES: +//ENGINE CONTROLLED MULTIPLAYER VARIABLES: extern long numplayers, myconnectindex; extern long connecthead, connectpoint2[MAXPLAYERS]; //Player linked list variables (indeces, not connection numbers) @@ -173,15 +173,15 @@ static long nummoves; #define NUMSTATS 13 static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1}; - //Input structures +//Input structures static char networkmode; //0 is 2(n-1) mode, 1 is n(n-1) mode static long locselectedgun, locselectedgun2; static input loc, oloc, loc2; static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS]; - //Input faketimerhandler -> movethings fifo +//Input faketimerhandler -> movethings fifo static long movefifoplc, movefifoend[MAXPLAYERS]; static input baksync[MOVEFIFOSIZ][MAXPLAYERS]; - //Game recording variables +//Game recording variables static long reccnt, recstat = 1; static input recsync[16384][2]; @@ -197,9 +197,9 @@ static long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ]; static long myhorizbak[MOVEFIFOSIZ]; static short myangbak[MOVEFIFOSIZ]; - //MULTI.OBJ sync state variables +//MULTI.OBJ sync state variables extern char syncstate; - //GAME.C sync state variables +//GAME.C sync state variables static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ]; static long syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail; @@ -221,7 +221,7 @@ extern long cachecount; static char playerreadyflag[MAXPLAYERS]; - //Miscellaneous variables +//Miscellaneous variables static char packbuf[MAXXDIM]; static char tempbuf[MAXXDIM], boardfilename[80]; static short tempshort[MAXSECTORS]; @@ -233,10 +233,10 @@ static long lockclock, neartagdist, neartaghitdist; extern long pageoffset, ydim16; static long globhiz, globloz, globhihit, globlohit; - //Over the shoulder mode variables +//Over the shoulder mode variables static long cameradist = -1, cameraang = 0, cameraclock = 0; - //Board animation variables +//Board animation variables #define MAXMIRRORS 64 static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt; static short floormirrorsector[64], floormirrorcnt; @@ -262,7 +262,7 @@ static long subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4]; static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS]; static short slimesoundcnt[MAXPLAYERS]; - //Variables that let you type messages to other player +//Variables that let you type messages to other player static char getmessage[162], getmessageleng; static long getmessagetimeoff; static char typemessage[162], typemessageleng = 0, typemode = 0; @@ -291,15 +291,15 @@ static char scantoascwithshift[128] = }; */ - //These variables are for animating x, y, or z-coordinates of sectors, - //walls, or sprites (They are NOT to be used for changing the [].picnum's) - //See the setanimation(), and getanimategoal() functions for more details. +//These variables are for animating x, y, or z-coordinates of sectors, +//walls, or sprites (They are NOT to be used for changing the [].picnum's) +//See the setanimation(), and getanimategoal() functions for more details. #define MAXANIMATES 512 static long *animateptr[MAXANIMATES], animategoal[MAXANIMATES]; static long animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0; #if defined(POLYMOST) && defined(USE_OPENGL) - //These parameters are in exact order of sprite structure in BUILD.H +//These parameters are in exact order of sprite structure in BUILD.H #define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \ clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \ xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \ @@ -350,41 +350,41 @@ int nextvoxid = 0; static int osdcmd_restartvid(const osdfuncparm_t *parm) { - resetvideomode(); - if (setgamemode(fullscreen,xdim,ydim,bpp)) - OSD_Printf("restartvid: Reset failed...\n"); + resetvideomode(); + if (setgamemode(fullscreen,xdim,ydim,bpp)) + OSD_Printf("restartvid: Reset failed...\n"); - return OSDCMD_OK; + return OSDCMD_OK; } static int osdcmd_vidmode(const osdfuncparm_t *parm) { - long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; + long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; - if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; + if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; - switch (parm->numparms) { - case 1: // bpp switch - newbpp = Batol(parm->parms[0]); - break; - case 2: // res switch - newx = Batol(parm->parms[0]); - newy = Batol(parm->parms[1]); - break; - case 3: // res & bpp switch - case 4: - newx = Batol(parm->parms[0]); - newy = Batol(parm->parms[1]); - newbpp = Batol(parm->parms[2]); - if (parm->numparms == 4) - newfullscreen = (Batol(parm->parms[3]) != 0); - break; - } + switch (parm->numparms) { + case 1: // bpp switch + newbpp = Batol(parm->parms[0]); + break; + case 2: // res switch + newx = Batol(parm->parms[0]); + newy = Batol(parm->parms[1]); + break; + case 3: // res & bpp switch + case 4: + newx = Batol(parm->parms[0]); + newy = Batol(parm->parms[1]); + newbpp = Batol(parm->parms[2]); + if (parm->numparms == 4) + newfullscreen = (Batol(parm->parms[3]) != 0); + break; + } - if (setgamemode(newfullscreen,newx,newy,newbpp)) - OSD_Printf("vidmode: Mode change failed!\n"); - screensize = xdim+1; - return OSDCMD_OK; + if (setgamemode(newfullscreen,newx,newy,newbpp)) + OSD_Printf("vidmode: Mode change failed!\n"); + screensize = xdim+1; + return OSDCMD_OK; } #ifdef RENDERTYPEWIN @@ -395,4523 +395,4523 @@ char *startwin_labeltext = "Starting KenBuild..."; long app_main(long argc, char *argv[]) { - long i, j, k, l, fil, waitplayers, x1, y1, x2, y2; - long other, packleng, netparm; + long i, j, k, l, fil, waitplayers, x1, y1, x2, y2; + long other, packleng, netparm; #ifdef USE_OPENGL - OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); - OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); + OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); + OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); #endif - - wm_setapptitle("KenBuild by Ken Silverman"); - Bstrcpy(boardfilename, "nukeland.map"); - j = 0; netparm = argc; - for (i=1;i= 2); + //initmultiplayers(argc-netparm,&argv[netparm],option[4],option[5],0); + if (initmultiplayersparms(argc-netparm,&argv[netparm])) { + initprintf("Waiting for players...\n"); + while (initmultiplayerscycle()) { + handleevents(); + if (quitevent) { + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + return 0; + } + } + } + option[4] = (numplayers >= 2); - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; - loadpics("tiles000.art",1048576); //Load artwork + loadpics("tiles000.art",1048576); //Load artwork #ifdef SUPERBUILD - if (!qloadkvx(nextvoxid,"voxel000.kvx")) - tiletovox[PLAYER] = nextvoxid++; - if (!qloadkvx(nextvoxid,"voxel001.kvx")) - tiletovox[BROWNMONSTER] = nextvoxid++; + if (!qloadkvx(nextvoxid,"voxel000.kvx")) + tiletovox[PLAYER] = nextvoxid++; + if (!qloadkvx(nextvoxid,"voxel001.kvx")) + tiletovox[BROWNMONSTER] = nextvoxid++; #endif - if (!loaddefinitionsfile("kenbuild.def")) initprintf("Definitions file loaded.\n"); + if (!loaddefinitionsfile("kenbuild.def")) initprintf("Definitions file loaded.\n"); - //Here's an example of TRUE ornamented walls - //The allocatepermanenttile should be called right after loadpics - //Since it resets the tile cache for each call. - if (allocatepermanenttile(SLIME,128,128) == 0) //If enough memory - { - printf("Not enough memory for slime!\n"); - exit(0); - } - if (allocatepermanenttile(MAXTILES-1,64,64) != 0) //If enough memory - { - //My face with an explosion written over it - copytilepiece(KENPICTURE,0,0,64,64,MAXTILES-1,0,0); - copytilepiece(EXPLOSION,0,0,64,64,MAXTILES-1,0,0); - } + //Here's an example of TRUE ornamented walls + //The allocatepermanenttile should be called right after loadpics + //Since it resets the tile cache for each call. + if (allocatepermanenttile(SLIME,128,128) == 0) //If enough memory + { + printf("Not enough memory for slime!\n"); + exit(0); + } + if (allocatepermanenttile(MAXTILES-1,64,64) != 0) //If enough memory + { + //My face with an explosion written over it + copytilepiece(KENPICTURE,0,0,64,64,MAXTILES-1,0,0); + copytilepiece(EXPLOSION,0,0,64,64,MAXTILES-1,0,0); + } - initlava(); + initlava(); - for(j=0;j<256;j++) - tempbuf[j] = ((j+32)&255); //remap colors for screwy palette sectors - makepalookup(16,tempbuf,0,0,0,1); + for(j=0;j<256;j++) + tempbuf[j] = ((j+32)&255); //remap colors for screwy palette sectors + makepalookup(16,tempbuf,0,0,0,1); - for(j=0;j<256;j++) tempbuf[j] = j; - makepalookup(17,tempbuf,24,24,24,1); + for(j=0;j<256;j++) tempbuf[j] = j; + makepalookup(17,tempbuf,24,24,24,1); - for(j=0;j<256;j++) tempbuf[j] = j; //(j&31)+32; - makepalookup(18,tempbuf,8,8,48,1); + for(j=0;j<256;j++) tempbuf[j] = j; //(j&31)+32; + makepalookup(18,tempbuf,8,8,48,1); - prepareboard(boardfilename); //Load board + prepareboard(boardfilename); //Load board - initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1); - //if (Bstrcmp(boardfilename,"klab.map") == 0) - // loadsong("klabsong.kdm"); - //else - loadsong("neatsong.ogg"); - musicon(); + initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1); + //if (Bstrcmp(boardfilename,"klab.map") == 0) + // loadsong("klabsong.kdm"); + //else + loadsong("neatsong.ogg"); + musicon(); - /* - if (option[4] > 0) - { - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; + /* + if (option[4] > 0) + { + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; - drawtilebackground(0L,0L,BACKGROUND,8,x1,y1,x2,y2,0); + drawtilebackground(0L,0L,BACKGROUND,8,x1,y1,x2,y2,0); - sendlogon(); + sendlogon(); - if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3; - while (numplayers < waitplayers) - { - sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers); - printext256(68L,84L,31,0,tempbuf,0); - nextpage(); + if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3; + while (numplayers < waitplayers) + { + sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers); + printext256(68L,84L,31,0,tempbuf,0); + nextpage(); - if (getpacket(&other,packbuf) > 0) - if (packbuf[0] == 255) - keystatus[1] = 1; + if (getpacket(&other,packbuf) > 0) + if (packbuf[0] == 255) + keystatus[1] = 1; - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } - if (keystatus[1]) - { - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } - } - screenpeek = myconnectindex; + if (keystatus[1]) + { + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } + } + screenpeek = myconnectindex; - if (numplayers <= 3) - networkmode = 1; - else - networkmode = 0; + if (numplayers <= 3) + networkmode = 1; + else + networkmode = 0; - j = 1; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (myconnectindex == i) break; - j++; - } - sprintf(getmessage,"Player %ld",j); - if (networkmode == 0) - { - if (j == 1) Bstrcat(getmessage," (Master)"); - else Bstrcat(getmessage," (Slave)"); - } else - Bstrcat(getmessage," (Even)"); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+120; - } - */ - screenpeek = myconnectindex; - reccnt = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + j = 1; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (myconnectindex == i) break; + j++; + } + sprintf(getmessage,"Player %ld",j); + if (networkmode == 0) + { + if (j == 1) Bstrcat(getmessage," (Master)"); + else Bstrcat(getmessage," (Slave)"); + } else + Bstrcat(getmessage," (Even)"); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+120; + } + */ + screenpeek = myconnectindex; + reccnt = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - waitforeverybody(); - totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0; + waitforeverybody(); + totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0; - ready2send = 1; - drawscreen(screenpeek,65536L); + ready2send = 1; + drawscreen(screenpeek,65536L); - while (!keystatus[1]) //Main loop starts here - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } + while (!keystatus[1]) //Main loop starts here + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } - refreshaudio(); - OSD_DispatchQueued(); + refreshaudio(); + OSD_DispatchQueued(); - // backslash (useful only with KDM) -// if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); } + // backslash (useful only with KDM) + // if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); } - if ((networkmode == 1) || (myconnectindex != connecthead)) - while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); + if ((networkmode == 1) || (myconnectindex != connecthead)) + while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); - getpackets(); + getpackets(); - if (typemode == 0) //if normal game keys active - { - if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0) //Sh.Sh.R (replay) - { - keystatus[0x13] = 0; - playback(); - } + if (typemode == 0) //if normal game keys active + { + if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0) //Sh.Sh.R (replay) + { + keystatus[0x13] = 0; + playback(); + } - if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game - { - keystatus[0x26] = 0; - loadgame(); - drawstatusbar(screenpeek); // Andy did this - } + if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game + { + keystatus[0x26] = 0; + loadgame(); + drawstatusbar(screenpeek); // Andy did this + } - if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game - { - keystatus[0x1f] = 0; - savegame(); - } - } + if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game + { + keystatus[0x1f] = 0; + savegame(); + } + } - if ((networkmode == 0) || (option[4] == 0)) - { - while (movefifoplc != movefifoend[0]) domovethings(); - } - else - { - j = connecthead; - if (j == myconnectindex) j = connectpoint2[j]; - averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3); - j = max(averagelag[j]>>9,1); - while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j) - { - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (movefifoplc == movefifoend[i]) break; - if (i >= 0) break; - if (myconnectindex != connecthead) - { - k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255); - if (k > 128+1) ototalclock++; - if (k < 128-1) ototalclock--; - } - domovethings(); - } - } - i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND)); + if ((networkmode == 0) || (option[4] == 0)) + { + while (movefifoplc != movefifoend[0]) domovethings(); + } + else + { + j = connecthead; + if (j == myconnectindex) j = connectpoint2[j]; + averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3); + j = max(averagelag[j]>>9,1); + while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j) + { + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (movefifoplc == movefifoend[i]) break; + if (i >= 0) break; + if (myconnectindex != connecthead) + { + k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255); + if (k > 128+1) ototalclock++; + if (k < 128-1) ototalclock--; + } + domovethings(); + } + } + i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND)); - drawscreen(screenpeek,i); - } + drawscreen(screenpeek,i); + } - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); - return(0); + return(0); } void operatesector(short dasector) { //Door code - long i, j, k, s, nexti, good, cnt, datag; - long dax, day, daz, dax2, day2, daz2, centx, centy; - short startwall, endwall, wallfind[2]; + long i, j, k, s, nexti, good, cnt, datag; + long dax, day, daz, dax2, day2, daz2, centx, centy; + short startwall, endwall, wallfind[2]; - datag = sector[dasector].lotag; + datag = sector[dasector].lotag; - startwall = sector[dasector].wallptr; - endwall = startwall + sector[dasector].wallnum; - centx = 0L, centy = 0L; - for(i=startwall;i= 0) //If door already moving, reverse its direction - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].floorz; + //Simple door that moves up (tag 8 is a combination of tags 6 & 7) + if ((datag == 6) || (datag == 8)) //If the sector in front is a door + { + i = getanimationgoal((long)§or[dasector].ceilingz); + if (i >= 0) //If door already moving, reverse its direction + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].floorz; - if (animategoal[i] == daz) - animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; - else - animategoal[i] = daz; - animatevel[i] = 0; - } - else //else insert the door's ceiling on the animation list - { - if (sector[dasector].ceilingz == sector[dasector].floorz) - daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; - else - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].floorz; - } - if ((j = setanimation(§or[dasector].ceilingz,daz,6L,6L)) >= 0) - wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); - } - } - //Simple door that moves down - if ((datag == 7) || (datag == 8)) //If the sector in front's elevator - { - i = getanimationgoal((long)§or[dasector].floorz); - if (i >= 0) //If elevator already moving, reverse its direction - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].ceilingz; + if (animategoal[i] == daz) + animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; + else + animategoal[i] = daz; + animatevel[i] = 0; + } + else //else insert the door's ceiling on the animation list + { + if (sector[dasector].ceilingz == sector[dasector].floorz) + daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; + else + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].floorz; + } + if ((j = setanimation(§or[dasector].ceilingz,daz,6L,6L)) >= 0) + wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); + } + } + //Simple door that moves down + if ((datag == 7) || (datag == 8)) //If the sector in front's elevator + { + i = getanimationgoal((long)§or[dasector].floorz); + if (i >= 0) //If elevator already moving, reverse its direction + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].ceilingz; - if (animategoal[i] == daz) - animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; - else - animategoal[i] = daz; - animatevel[i] = 0; - } - else //else insert the elevator's ceiling on the animation list - { - if (sector[dasector].floorz == sector[dasector].ceilingz) - daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; - else - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].ceilingz; - } - if ((j = setanimation(§or[dasector].floorz,daz,6L,6L)) >= 0) - wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); - } - } + if (animategoal[i] == daz) + animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; + else + animategoal[i] = daz; + animatevel[i] = 0; + } + else //else insert the elevator's ceiling on the animation list + { + if (sector[dasector].floorz == sector[dasector].ceilingz) + daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; + else + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].ceilingz; + } + if ((j = setanimation(§or[dasector].floorz,daz,6L,6L)) >= 0) + wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); + } + } - if (datag == 9) //Smooshy-wall sideways double-door - { - //find any points with either same x or same y coordinate - // as center (centx, centy) - should be 2 points found. - wallfind[0] = -1; - wallfind[1] = -1; - for(i=startwall;i>1)-wall[wallfind[j]].x; - day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; - if (dax2 != 0) - { - dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; - dax2 -= wall[wall[wallfind[j]].point2].x; - setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); - setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); - } - else if (day2 != 0) - { - day2 = wall[wall[wall[wallfind[j]].point2].point2].y; - day2 -= wall[wall[wallfind[j]].point2].y; - setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); - setanimation(&wall[i].y,wall[i].y+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); - } - } - else - { - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x; - day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; - if (dax2 != 0) - { - setanimation(&wall[wallfind[j]].x,centx,4L,0L); - setanimation(&wall[i].x,centx+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L); - } - else if (day2 != 0) - { - setanimation(&wall[wallfind[j]].y,centy,4L,0L); - setanimation(&wall[i].y,centy+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L); - } - } - } - wsayfollow("updowndr.wav",4096L-256L,256L,¢x,¢y,0); - wsayfollow("updowndr.wav",4096L+256L,256L,¢x,¢y,0); - } + for(j=0;j<2;j++) + { + if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy)) + { + //find what direction door should open by averaging the + // 2 neighboring points of wallfind[0] & wallfind[1]. + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x; + day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; + if (dax2 != 0) + { + dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; + dax2 -= wall[wall[wallfind[j]].point2].x; + setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); + setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); + } + else if (day2 != 0) + { + day2 = wall[wall[wall[wallfind[j]].point2].point2].y; + day2 -= wall[wall[wallfind[j]].point2].y; + setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); + setanimation(&wall[i].y,wall[i].y+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); + } + } + else + { + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x; + day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; + if (dax2 != 0) + { + setanimation(&wall[wallfind[j]].x,centx,4L,0L); + setanimation(&wall[i].x,centx+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L); + } + else if (day2 != 0) + { + setanimation(&wall[wallfind[j]].y,centy,4L,0L); + setanimation(&wall[i].y,centy+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L); + } + } + } + wsayfollow("updowndr.wav",4096L-256L,256L,¢x,¢y,0); + wsayfollow("updowndr.wav",4096L+256L,256L,¢x,¢y,0); + } - if (datag == 13) //Swinging door - { - for(i=0;i>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy)) - { //door was closed - //find what direction door should open - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = wall[i].x-wall[wallfind[j]].x; - day2 = wall[i].y-wall[wallfind[j]].y; - if (dax2 != 0) - { - dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x; - dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x; - setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); - setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L); - } - else if (day2 != 0) - { - day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y; - day2 -= wall[wall[wall[wallfind[j]].point2].point2].y; - setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); - setanimation(&wall[i].y,wall[i].y+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L); - } - } - else - { //door was not closed - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = wall[i].x-wall[wallfind[j]].x; - day2 = wall[i].y-wall[wallfind[j]].y; - if (dax2 != 0) - { - setanimation(&wall[wallfind[j]].x,centx,4L,0L); - setanimation(&wall[i].x,centx+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L); - } - else if (day2 != 0) - { - setanimation(&wall[wallfind[j]].y,centy,4L,0L); - setanimation(&wall[i].y,centy+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L); - } - } - } - wsayfollow("updowndr.wav",4096L-64L,256L,¢x,¢y,0); - wsayfollow("updowndr.wav",4096L+64L,256L,¢x,¢y,0); - } + for(j=0;j<2;j++) + { + if ((((wall[wallfind[j]].x+wall[wall[wallfind[j]].point2].x)>>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy)) + { //door was closed + //find what direction door should open + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = wall[i].x-wall[wallfind[j]].x; + day2 = wall[i].y-wall[wallfind[j]].y; + if (dax2 != 0) + { + dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x; + dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x; + setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); + setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L); + } + else if (day2 != 0) + { + day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y; + day2 -= wall[wall[wall[wallfind[j]].point2].point2].y; + setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); + setanimation(&wall[i].y,wall[i].y+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L); + } + } + else + { //door was not closed + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = wall[i].x-wall[wallfind[j]].x; + day2 = wall[i].y-wall[wallfind[j]].y; + if (dax2 != 0) + { + setanimation(&wall[wallfind[j]].x,centx,4L,0L); + setanimation(&wall[i].x,centx+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L); + } + else if (day2 != 0) + { + setanimation(&wall[wallfind[j]].y,centy,4L,0L); + setanimation(&wall[i].y,centy+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L); + } + } + } + wsayfollow("updowndr.wav",4096L-64L,256L,¢x,¢y,0); + wsayfollow("updowndr.wav",4096L+64L,256L,¢x,¢y,0); + } } void operatesprite(short dasprite) { - long datag; + long datag; - datag = sprite[dasprite].lotag; + datag = sprite[dasprite].lotag; - if (datag == 2) //A sprite that shoots a bomb - { - shootgun(dasprite, - sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z, - sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2); - } + if (datag == 2) //A sprite that shoots a bomb + { + shootgun(dasprite, + sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z, + sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2); + } } long changehealth(short snum, short deltahealth) { - long dax, day; - short good, k, startwall, endwall, s; + long dax, day; + short good, k, startwall, endwall, s; - if (health[snum] > 0) - { - health[snum] += deltahealth; - if (health[snum] > 999) health[snum] = 999; + if (health[snum] > 0) + { + health[snum] += deltahealth; + if (health[snum] > 999) health[snum] = 999; - if (health[snum] <= 0) - { - health[snum] = -1; - wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - sprite[playersprite[snum]].picnum = SKELETON; - } + if (health[snum] <= 0) + { + health[snum] = -1; + wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + sprite[playersprite[snum]].picnum = SKELETON; + } - if ((snum == screenpeek) && (screensize <= xdim)) - { - if (health[snum] > 0) - sprintf(tempbuf,"Health:%3ld",health[snum]); - else - sprintf(tempbuf,"YOU STINK!"); + if ((snum == screenpeek) && (screensize <= xdim)) + { + if (health[snum] > 0) + sprintf(tempbuf,"Health:%3ld",health[snum]); + else + sprintf(tempbuf,"YOU STINK!"); - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); - } - } - return(health[snum] <= 0); //You were just injured + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); + } + } + return(health[snum] <= 0); //You were just injured } void changenumbombs(short snum, short deltanumbombs) { // Andy did this - numbombs[snum] += deltanumbombs; - if (numbombs[snum] > 999) numbombs[snum] = 999; - if (numbombs[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - numbombs[snum] = 0; - } + numbombs[snum] += deltanumbombs; + if (numbombs[snum] > 999) numbombs[snum] = 999; + if (numbombs[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + numbombs[snum] = 0; + } - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"B:%3d",numbombs[snum]); - printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); - } + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"B:%3d",numbombs[snum]); + printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); + } } void changenummissiles(short snum, short deltanummissiles) { // Andy did this - nummissiles[snum] += deltanummissiles; - if (nummissiles[snum] > 999) nummissiles[snum] = 999; - if (nummissiles[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - nummissiles[snum] = 0; - } + nummissiles[snum] += deltanummissiles; + if (nummissiles[snum] > 999) nummissiles[snum] = 999; + if (nummissiles[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + nummissiles[snum] = 0; + } - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"M:%3d",nummissiles[snum]); - printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); - } + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"M:%3d",nummissiles[snum]); + printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); + } } void changenumgrabbers(short snum, short deltanumgrabbers) { // Andy did this - numgrabbers[snum] += deltanumgrabbers; - if (numgrabbers[snum] > 999) numgrabbers[snum] = 999; - if (numgrabbers[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - numgrabbers[snum] = 0; - } + numgrabbers[snum] += deltanumgrabbers; + if (numgrabbers[snum] > 999) numgrabbers[snum] = 999; + if (numgrabbers[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + numgrabbers[snum] = 0; + } - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"G:%3d",numgrabbers[snum]); - printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); - } + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"G:%3d",numgrabbers[snum]); + printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); + } } static long ostatusflytime = 0x80000000; void drawstatusflytime(short snum) { // Andy did this - long nstatusflytime; + long nstatusflytime; - if ((snum == screenpeek) && (screensize <= xdim)) { - nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); - if (nstatusflytime > 1000) nstatusflytime = 1000; - else if (nstatusflytime < 0) nstatusflytime = 0; - if (nstatusflytime != ostatusflytime) { - if (nstatusflytime > 999) sprintf(tempbuf,"FT:BIG"); - else sprintf(tempbuf,"FT:%3ld",nstatusflytime); - printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); - ostatusflytime = nstatusflytime; - } - } + if ((snum == screenpeek) && (screensize <= xdim)) { + nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); + if (nstatusflytime > 1000) nstatusflytime = 1000; + else if (nstatusflytime < 0) nstatusflytime = 0; + if (nstatusflytime != ostatusflytime) { + if (nstatusflytime > 999) sprintf(tempbuf,"FT:BIG"); + else sprintf(tempbuf,"FT:%3ld",nstatusflytime); + printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); + ostatusflytime = nstatusflytime; + } + } } void drawstatusbar(short snum) { // Andy did this - long nstatusflytime; + long nstatusflytime; - if ((snum == screenpeek) && (screensize <= xdim)) { - Bsprintf(tempbuf,"Deaths:%d",deaths[snum]); - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-16,tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"Health:%3ld",health[snum]); - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); + if ((snum == screenpeek) && (screensize <= xdim)) { + Bsprintf(tempbuf,"Deaths:%d",deaths[snum]); + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-16,tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"Health:%3ld",health[snum]); + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"B:%3d",numbombs[snum]); - printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"M:%3d",nummissiles[snum]); - printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"G:%3d",numgrabbers[snum]); - printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"B:%3d",numbombs[snum]); + printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"M:%3d",nummissiles[snum]); + printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"G:%3d",numgrabbers[snum]); + printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); - nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); - if (nstatusflytime < 0) { - Bsprintf(tempbuf,"FT: 0"); - ostatusflytime = 0; - } - else if (nstatusflytime > 999) { - Bsprintf(tempbuf,"FT:BIG"); - ostatusflytime = 999; - } - else { - Bsprintf(tempbuf,"FT:%3ld",nstatusflytime); - ostatusflytime = nstatusflytime; - } - printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); - } + nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); + if (nstatusflytime < 0) { + Bsprintf(tempbuf,"FT: 0"); + ostatusflytime = 0; + } + else if (nstatusflytime > 999) { + Bsprintf(tempbuf,"FT:BIG"); + ostatusflytime = 999; + } + else { + Bsprintf(tempbuf,"FT:%3ld",nstatusflytime); + ostatusflytime = nstatusflytime; + } + printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); + } } void prepareboard(char *daboardfilename) { - short startwall, endwall, dasector; - long i, j, k=0, s, dax, day, daz, dax2, day2; + short startwall, endwall, dasector; + long i, j, k=0, s, dax, day, daz, dax2, day2; - getmessageleng = 0; - typemessageleng = 0; + getmessageleng = 0; + typemessageleng = 0; - randomseed = 17L; + randomseed = 17L; - //Clear (do)animation's list - animatecnt = 0; - typemode = 0; - locselectedgun = 0; - locselectedgun2 = 0; + //Clear (do)animation's list + animatecnt = 0; + typemode = 0; + locselectedgun = 0; + locselectedgun2 = 0; - if (loadboard(daboardfilename,0,&posx[0],&posy[0],&posz[0],&ang[0],&cursectnum[0]) == -1) - { - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - printf("Board not found\n"); - exit(0); - } else { - char *fp; + if (loadboard(daboardfilename,0,&posx[0],&posy[0],&posz[0],&ang[0],&cursectnum[0]) == -1) + { + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + printf("Board not found\n"); + exit(0); + } else { + char *fp; - strcpy(tempbuf, daboardfilename); - fp = strrchr(tempbuf,'.'); - if (fp) *fp = 0; - strcat(tempbuf,".mhk"); + strcpy(tempbuf, daboardfilename); + fp = strrchr(tempbuf,'.'); + if (fp) *fp = 0; + strcat(tempbuf,".mhk"); - loadmaphack(tempbuf); - } + loadmaphack(tempbuf); + } - setup3dscreen(); + setup3dscreen(); - for(i=0;i dax2) dax2 = wall[j].x; - if (wall[j].y > day2) day2 = wall[j].y; - if (wall[j].lotag == 3) k = j; - } - if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16; - if (wall[k].y == day) dragydir[dragsectorcnt] = -16; - if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16; - if (wall[k].y == day2) dragydir[dragsectorcnt] = 16; + for(i=0;i dax2) dax2 = wall[j].x; + if (wall[j].y > day2) day2 = wall[j].y; + if (wall[j].lotag == 3) k = j; + } + if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16; + if (wall[k].y == day) dragydir[dragsectorcnt] = -16; + if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16; + if (wall[k].y == day2) dragydir[dragsectorcnt] = 16; - dasector = wall[startwall].nextsector; - dragx1[dragsectorcnt] = 0x7fffffff; - dragy1[dragsectorcnt] = 0x7fffffff; - dragx2[dragsectorcnt] = 0x80000000; - dragy2[dragsectorcnt] = 0x80000000; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(j=startwall;j dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x; - if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y; + dasector = wall[startwall].nextsector; + dragx1[dragsectorcnt] = 0x7fffffff; + dragy1[dragsectorcnt] = 0x7fffffff; + dragx2[dragsectorcnt] = 0x80000000; + dragy2[dragsectorcnt] = 0x80000000; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(j=startwall;j dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x; + if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y; - setinterpolation(§or[dasector].floorz); - setinterpolation(&wall[j].x); - setinterpolation(&wall[j].y); - setinterpolation(&wall[wall[j].nextwall].x); - setinterpolation(&wall[wall[j].nextwall].y); - } + setinterpolation(§or[dasector].floorz); + setinterpolation(&wall[j].x); + setinterpolation(&wall[j].y); + setinterpolation(&wall[wall[j].nextwall].x); + setinterpolation(&wall[wall[j].nextwall].y); + } - dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax); - dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day); - dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x); - dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y); + dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax); + dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day); + dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x); + dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y); - dragfloorz[dragsectorcnt] = sector[i].floorz; + dragfloorz[dragsectorcnt] = sector[i].floorz; - dragsectorlist[dragsectorcnt++] = i; - break; - case 13: - startwall = sector[i].wallptr; - endwall = startwall+sector[i].wallnum; - for(j=startwall;j dax2) dax2 = wall[j].x; - if (wall[j].y > day2) day2 = wall[j].y; - } - for(j=startwall;j dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2)) - { - subwayx[subwaytrackcnt] = wall[j].x; - } - else - { - subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x; - subwaystopcnt[subwaytrackcnt]++; - } - } - } + subwaystopcnt[subwaytrackcnt] = 0; + dax = 0x7fffffff; + day = 0x7fffffff; + dax2 = 0x80000000; + day2 = 0x80000000; + startwall = sector[i].wallptr; + endwall = startwall+sector[i].wallnum; + for(j=startwall;j dax2) dax2 = wall[j].x; + if (wall[j].y > day2) day2 = wall[j].y; + } + for(j=startwall;j dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2)) + { + subwayx[subwaytrackcnt] = wall[j].x; + } + else + { + subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x; + subwaystopcnt[subwaytrackcnt]++; + } + } + } - for(j=1;j subwaytrackx1[subwaytrackcnt]) - if (wall[startwall].y > subwaytracky1[subwaytrackcnt]) - if (wall[startwall].x < subwaytrackx2[subwaytrackcnt]) - if (wall[startwall].y < subwaytracky2[subwaytrackcnt]) - { - if (sector[j].floorz != sector[i].floorz) - { - sector[j].ceilingstat |= 64; - sector[j].floorstat |= 64; - } - subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j; - subwaynumsectors[subwaytrackcnt]++; - } - } + subwaynumsectors[subwaytrackcnt] = 1; + for(j=0;j subwaytrackx1[subwaytrackcnt]) + if (wall[startwall].y > subwaytracky1[subwaytrackcnt]) + if (wall[startwall].x < subwaytrackx2[subwaytrackcnt]) + if (wall[startwall].y < subwaytracky2[subwaytrackcnt]) + { + if (sector[j].floorz != sector[i].floorz) + { + sector[j].ceilingstat |= 64; + sector[j].floorstat |= 64; + } + subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j; + subwaynumsectors[subwaytrackcnt]++; + } + } - subwayvel[subwaytrackcnt] = 64; - subwaypausetime[subwaytrackcnt] = 720; + subwayvel[subwaytrackcnt] = 64; + subwaypausetime[subwaytrackcnt] = 720; - startwall = sector[i].wallptr; - endwall = startwall+sector[i].wallnum; - for(k=startwall;k subwaytrackx1[subwaytrackcnt]) - if (wall[k].y > subwaytracky1[subwaytrackcnt]) - if (wall[k].x < subwaytrackx2[subwaytrackcnt]) - if (wall[k].y < subwaytracky2[subwaytrackcnt]) - setinterpolation(&wall[k].x); + startwall = sector[i].wallptr; + endwall = startwall+sector[i].wallnum; + for(k=startwall;k subwaytrackx1[subwaytrackcnt]) + if (wall[k].y > subwaytracky1[subwaytrackcnt]) + if (wall[k].x < subwaytrackx2[subwaytrackcnt]) + if (wall[k].y < subwaytracky2[subwaytrackcnt]) + setinterpolation(&wall[k].x); - for(j=1;j=0;k=nextspritesect[k]) - if (statrate[sprite[k].statnum] < 0) - setinterpolation(&sprite[k].x); - } + for(k=headspritesect[dasector];k>=0;k=nextspritesect[k]) + if (statrate[sprite[k].statnum] < 0) + setinterpolation(&sprite[k].x); + } - subwaytrackcnt++; - break; - } - if (sector[i].floorpicnum == FLOORMIRROR) - floormirrorsector[mirrorcnt++] = i; - //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS - } + subwaytrackcnt++; + break; + } + if (sector[i].floorpicnum == FLOORMIRROR) + floormirrorsector[mirrorcnt++] = i; + //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS + } - //Scan wall tags + //Scan wall tags - mirrorcnt = 0; - tilesizx[MIRROR] = 0; - tilesizy[MIRROR] = 0; - for(i=0;i= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32)) - { - if ((sector[s].floorstat&1) == 0) - { - wall[i].overpicnum = MIRRORLABEL+mirrorcnt; - sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt; - sector[s].floorpicnum = MIRRORLABEL+mirrorcnt; - sector[s].floorstat |= 1; - mirrorwall[mirrorcnt] = i; - mirrorsector[mirrorcnt] = s; - mirrorcnt++; - } - else - wall[i].overpicnum = sector[s].ceilingpicnum; - } - } + ypanningwallcnt = 0; + for(i=0;i= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32)) + { + if ((sector[s].floorstat&1) == 0) + { + wall[i].overpicnum = MIRRORLABEL+mirrorcnt; + sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt; + sector[s].floorpicnum = MIRRORLABEL+mirrorcnt; + sector[s].floorstat |= 1; + mirrorwall[mirrorcnt] = i; + mirrorsector[mirrorcnt] = s; + mirrorcnt++; + } + else + wall[i].overpicnum = sector[s].ceilingpicnum; + } + } - //Invalidate textures in sector behind mirror - for(i=0;i=0;i--) copybuf(&sprite[i].x,&osprite[i].x,3); + for(i=MAXSPRITES-1;i>=0;i--) copybuf(&sprite[i].x,&osprite[i].x,3); - searchmap(cursectnum[connecthead]); + searchmap(cursectnum[connecthead]); - lockclock = 0; - ototalclock = 0; - gotlastpacketclock = 0; + lockclock = 0; + ototalclock = 0; + gotlastpacketclock = 0; - screensize = xdim; - dax = ((xdim-screensize)>>1); - dax2 = dax+screensize-1; - day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - day2 = day + scale(screensize,ydim-32,xdim)-1; - setview(dax,day,dax2,day2); + screensize = xdim; + dax = ((xdim-screensize)>>1); + dax2 = dax+screensize-1; + day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + day2 = day + scale(screensize,ydim-32,xdim)-1; + setview(dax,day,dax2,day2); - startofdynamicinterpolations = numinterpolations; + startofdynamicinterpolations = numinterpolations; - /* - for(i=connecthead;i>=0;i=connectpoint2[i]) myminlag[i] = 0; - otherminlag = mymaxlag = 0; - */ + /* + for(i=connecthead;i>=0;i=connectpoint2[i]) myminlag[i] = 0; + otherminlag = mymaxlag = 0; + */ } void checktouchsprite(short snum, short sectnum) { - long i, nexti; + long i, nexti; - if ((sectnum < 0) || (sectnum >= numsectors)) return; + if ((sectnum < 0) || (sectnum >= numsectors)) return; - for(i=headspritesect[sectnum];i>=0;i=nexti) - { - nexti = nextspritesect[i]; - if (sprite[i].cstat&0x8000) continue; - if ((klabs(posx[snum]-sprite[i].x)+klabs(posy[snum]-sprite[i].y) < 512) && (klabs((posz[snum]>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) - { - switch(sprite[i].picnum) - { - case COIN: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,5); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*60; - changespritestat((short)i,11); - } - break; - case DIAMONDS: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,15); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*120; - changespritestat((short)i,11); - } - break; - case COINSTACK: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,25); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*180; - changespritestat((short)i,11); - } - break; - case GIFTBOX: - wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case CANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[4] = 1; - changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case LAUNCHER: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[5] = 1; - changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case GRABCANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[6] = 1; - changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case AIRPLANE: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (flytime[snum] < lockclock) flytime[snum] = lockclock; - flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); - drawstatusflytime(snum); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - } - } - } + for(i=headspritesect[sectnum];i>=0;i=nexti) + { + nexti = nextspritesect[i]; + if (sprite[i].cstat&0x8000) continue; + if ((klabs(posx[snum]-sprite[i].x)+klabs(posy[snum]-sprite[i].y) < 512) && (klabs((posz[snum]>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) + { + switch(sprite[i].picnum) + { + case COIN: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,5); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*60; + changespritestat((short)i,11); + } + break; + case DIAMONDS: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,15); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*120; + changespritestat((short)i,11); + } + break; + case COINSTACK: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,25); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*180; + changespritestat((short)i,11); + } + break; + case GIFTBOX: + wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case CANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[4] = 1; + changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case LAUNCHER: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[5] = 1; + changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case GRABCANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[6] = 1; + changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case AIRPLANE: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (flytime[snum] < lockclock) flytime[snum] = lockclock; + flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); + drawstatusflytime(snum); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + } + } + } } void checkgrabbertouchsprite(short snum, short sectnum) // Andy did this { - long i, nexti; - short onum; + long i, nexti; + short onum; - if ((sectnum < 0) || (sectnum >= numsectors)) return; - onum = (sprite[snum].owner & (MAXSPRITES - 1)); + if ((sectnum < 0) || (sectnum >= numsectors)) return; + onum = (sprite[snum].owner & (MAXSPRITES - 1)); - for(i=headspritesect[sectnum];i>=0;i=nexti) - { - nexti = nextspritesect[i]; - if (sprite[i].cstat&0x8000) continue; - if ((klabs(sprite[snum].x-sprite[i].x)+klabs(sprite[snum].y-sprite[i].y) < 512) && (klabs((sprite[snum].z>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) - { - switch(sprite[i].picnum) - { - case COIN: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,5); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*60; - changespritestat((short)i,11); - } - break; - case DIAMONDS: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,15); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*120; - changespritestat((short)i,11); - } - break; - case COINSTACK: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,25); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*180; - changespritestat((short)i,11); - } - break; - case GIFTBOX: - wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case CANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[4] = 1; - changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case LAUNCHER: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[5] = 1; - changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case GRABCANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[6] = 1; - changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case AIRPLANE: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (flytime[snum] < lockclock) flytime[snum] = lockclock; - flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); - drawstatusflytime(onum); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - } - } - } + for(i=headspritesect[sectnum];i>=0;i=nexti) + { + nexti = nextspritesect[i]; + if (sprite[i].cstat&0x8000) continue; + if ((klabs(sprite[snum].x-sprite[i].x)+klabs(sprite[snum].y-sprite[i].y) < 512) && (klabs((sprite[snum].z>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) + { + switch(sprite[i].picnum) + { + case COIN: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,5); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*60; + changespritestat((short)i,11); + } + break; + case DIAMONDS: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,15); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*120; + changespritestat((short)i,11); + } + break; + case COINSTACK: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,25); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*180; + changespritestat((short)i,11); + } + break; + case GIFTBOX: + wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case CANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[4] = 1; + changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case LAUNCHER: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[5] = 1; + changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case GRABCANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[6] = 1; + changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case AIRPLANE: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (flytime[snum] < lockclock) flytime[snum] = lockclock; + flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); + drawstatusflytime(onum); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + } + } + } } void shootgun(short snum, long x, long y, long z, - short daang, long dahoriz, short dasectnum, char guntype) + short daang, long dahoriz, short dasectnum, char guntype) { - short hitsect, hitwall, hitsprite, daang2; - long i, j, daz2, hitx, hity, hitz; + short hitsect, hitwall, hitsprite, daang2; + long i, j, daz2, hitx, hity, hitz; - switch(guntype) - { - case 0: //Shoot chain gun - daang2 = ((daang + (krand()&31)-16)&2047); - daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1); + switch(guntype) + { + case 0: //Shoot chain gun + daang2 = ((daang + (krand()&31)-16)&2047); + daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1); - hitscan(x,y,z,dasectnum, //Start position - sintable[(daang2+512)&2047], //X vector of 3D ang - sintable[daang2&2047], //Y vector of 3D ang - daz2, //Z vector of 3D ang - &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + hitscan(x,y,z,dasectnum, //Start position + sintable[(daang2+512)&2047], //X vector of 3D ang + sintable[daang2&2047], //Y vector of 3D ang + daz2, //Z vector of 3D ang + &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - if (wall[hitwall].picnum == KENPICTURE) - { - if (waloff[MAXTILES-1] != 0) wall[hitwall].picnum = MAXTILES-1; - wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitwall].x,&wall[hitwall].y,0); - } - else if (((hitwall < 0) && (hitsprite < 0) && (hitz >= z) && ((sector[hitsect].floorpicnum == SLIME) || (sector[hitsect].floorpicnum == FLOORMIRROR))) || ((hitwall >= 0) && (wall[hitwall].picnum == SLIME))) - { //If you shoot slime, make a splash - wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); - spawnsprite(j,hitx,hity,hitz,2,0,0,32,64,64,0,0,SPLASH,daang, - 0,0,0,snum+4096,hitsect,4,63,0,0); //63=time left for splash - } - else - { - wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + if (wall[hitwall].picnum == KENPICTURE) + { + if (waloff[MAXTILES-1] != 0) wall[hitwall].picnum = MAXTILES-1; + wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitwall].x,&wall[hitwall].y,0); + } + else if (((hitwall < 0) && (hitsprite < 0) && (hitz >= z) && ((sector[hitsect].floorpicnum == SLIME) || (sector[hitsect].floorpicnum == FLOORMIRROR))) || ((hitwall >= 0) && (wall[hitwall].picnum == SLIME))) + { //If you shoot slime, make a splash + wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); + spawnsprite(j,hitx,hity,hitz,2,0,0,32,64,64,0,0,SPLASH,daang, + 0,0,0,snum+4096,hitsect,4,63,0,0); //63=time left for splash + } + else + { + wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - if ((hitsprite >= 0) && (sprite[hitsprite].statnum < MAXSTATUS)) - switch(sprite[hitsprite].picnum) - { - case BROWNMONSTER: - if (sprite[hitsprite].lotag > 0) sprite[hitsprite].lotag -= 10; - if (sprite[hitsprite].lotag > 0) - { - wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); - if (sprite[hitsprite].lotag <= 25) - sprite[hitsprite].cstat |= 2; - } - else - { - wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - sprite[hitsprite].z += ((tilesizy[sprite[hitsprite].picnum]*sprite[hitsprite].yrepeat)<<1); - sprite[hitsprite].picnum = GIFTBOX; - sprite[hitsprite].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(hitsprite,12); + if ((hitsprite >= 0) && (sprite[hitsprite].statnum < MAXSTATUS)) + switch(sprite[hitsprite].picnum) + { + case BROWNMONSTER: + if (sprite[hitsprite].lotag > 0) sprite[hitsprite].lotag -= 10; + if (sprite[hitsprite].lotag > 0) + { + wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); + if (sprite[hitsprite].lotag <= 25) + sprite[hitsprite].cstat |= 2; + } + else + { + wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + sprite[hitsprite].z += ((tilesizy[sprite[hitsprite].picnum]*sprite[hitsprite].yrepeat)<<1); + sprite[hitsprite].picnum = GIFTBOX; + sprite[hitsprite].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(hitsprite,12); - spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64, - 0,0,EXPLOSION,daang,0,0,0,snum+4096, - hitsect,5,31,0,0); - } - break; - case EVILAL: - wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - sprite[hitsprite].picnum = EVILALGRAVE; - sprite[hitsprite].cstat = 0; - sprite[hitsprite].xvel = (krand()&255)-128; - sprite[hitsprite].yvel = (krand()&255)-128; - sprite[hitsprite].zvel = (krand()&4095)-3072; - changespritestat(hitsprite,9); + spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64, + 0,0,EXPLOSION,daang,0,0,0,snum+4096, + hitsect,5,31,0,0); + } + break; + case EVILAL: + wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + sprite[hitsprite].picnum = EVILALGRAVE; + sprite[hitsprite].cstat = 0; + sprite[hitsprite].xvel = (krand()&255)-128; + sprite[hitsprite].yvel = (krand()&255)-128; + sprite[hitsprite].zvel = (krand()&4095)-3072; + changespritestat(hitsprite,9); - spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64,0, - 0,EXPLOSION,daang,0,0,0,snum+4096,hitsect,5,31,0,0); - //31=time left for explosion + spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64,0, + 0,EXPLOSION,daang,0,0,0,snum+4096,hitsect,5,31,0,0); + //31=time left for explosion - break; - case PLAYER: - for(j=connecthead;j>=0;j=connectpoint2[j]) - if (playersprite[j] == hitsprite) - { - wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - changehealth(j,-10); - break; - } - break; - } + break; + case PLAYER: + for(j=connecthead;j>=0;j=connectpoint2[j]) + if (playersprite[j] == hitsprite) + { + wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + changehealth(j,-10); + break; + } + break; + } - spawnsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0, - EXPLOSION,daang,0,0,0,snum+4096,hitsect,3,63,0,0); + spawnsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0, + EXPLOSION,daang,0,0,0,snum+4096,hitsect,3,63,0,0); - //Sprite starts out with center exactly on wall. - //This moves it back enough to see it at all angles. - movesprite((short)j,-(((long)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((long)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1); - } - break; - case 1: //Shoot silver sphere bullet - spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,BULLET,daang, - sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, - (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); - break; - case 2: //Shoot bomb - spawnsprite(j,x,y,z,128,0,0,12,16,16,0,0,BOMB,daang, - sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8, - (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); - break; - case 3: //Shoot missile (Andy did this) - spawnsprite(j,x,y,z,1+128,0,0,16,32,32,0,0,MISSILE,daang, - sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4, - (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); - break; - case 4: //Shoot grabber (Andy did this) - spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,GRABBER,daang, - sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, - (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); - break; - } + //Sprite starts out with center exactly on wall. + //This moves it back enough to see it at all angles. + movesprite((short)j,-(((long)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((long)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1); + } + break; + case 1: //Shoot silver sphere bullet + spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,BULLET,daang, + sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, + (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); + break; + case 2: //Shoot bomb + spawnsprite(j,x,y,z,128,0,0,12,16,16,0,0,BOMB,daang, + sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8, + (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); + break; + case 3: //Shoot missile (Andy did this) + spawnsprite(j,x,y,z,1+128,0,0,16,32,32,0,0,MISSILE,daang, + sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4, + (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); + break; + case 4: //Shoot grabber (Andy did this) + spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,GRABBER,daang, + sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, + (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); + break; + } } #define MAXVOXMIPS 5 extern char *voxoff[][MAXVOXMIPS]; void analyzesprites(long dax, long day) { - long i, j=0, k, *intptr; - point3d *ospr; - spritetype *tspr; + long i, j=0, k, *intptr; + point3d *ospr; + spritetype *tspr; - //This function is called between drawrooms() and drawmasks() - //It has a list of possible sprites that may be drawn on this frame + //This function is called between drawrooms() and drawmasks() + //It has a list of possible sprites that may be drawn on this frame - for(i=0,tspr=&tsprite[0];ipicnum] >= 0) - switch(tspr->picnum) - { - case PLAYER: - // //Get which of the 8 angles of the sprite to draw (0-7) - // //k ranges from 0-7 - //k = getangle(tspr->x-dax,tspr->y-day); - //k = (((tspr->ang+3072+128-k)&2047)>>8)&7; - // //This guy has only 5 pictures for 8 angles (3 are x-flipped) - //if (k <= 4) - //{ - // tspr->picnum += (k<<2); - // tspr->cstat &= ~4; //clear x-flipping bit - //} - //else - //{ - // tspr->picnum += ((8-k)<<2); - // tspr->cstat |= 4; //set x-flipping bit - //} + if (usevoxels && tiletovox[tspr->picnum] >= 0) + switch(tspr->picnum) + { + case PLAYER: + // //Get which of the 8 angles of the sprite to draw (0-7) + // //k ranges from 0-7 + //k = getangle(tspr->x-dax,tspr->y-day); + //k = (((tspr->ang+3072+128-k)&2047)>>8)&7; + // //This guy has only 5 pictures for 8 angles (3 are x-flipped) + //if (k <= 4) + //{ + // tspr->picnum += (k<<2); + // tspr->cstat &= ~4; //clear x-flipping bit + //} + //else + //{ + // tspr->picnum += ((8-k)<<2); + // tspr->cstat |= 4; //set x-flipping bit + //} - if ((tspr->cstat&2) == 0) - { - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - intptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; - tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]); - tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]); - tspr->shade -= 6; - } - break; - case BROWNMONSTER: - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - break; - } + if ((tspr->cstat&2) == 0) + { + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + intptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; + tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]); + tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]); + tspr->shade -= 6; + } + break; + case BROWNMONSTER: + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + break; + } #endif - k = statrate[tspr->statnum]; - if (k >= 0) //Interpolate moving sprite - { - ospr = &osprite[tspr->owner]; - switch(k) - { - case 0: j = smoothratio; break; - case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break; - case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break; - case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break; - case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break; - } - k = tspr->x-ospr->x; tspr->x = ospr->x; - if (k != 0) tspr->x += mulscale16(k,j); - k = tspr->y-ospr->y; tspr->y = ospr->y; - if (k != 0) tspr->y += mulscale16(k,j); - k = tspr->z-ospr->z; tspr->z = ospr->z; - if (k != 0) tspr->z += mulscale16(k,j); - } + k = statrate[tspr->statnum]; + if (k >= 0) //Interpolate moving sprite + { + ospr = &osprite[tspr->owner]; + switch(k) + { + case 0: j = smoothratio; break; + case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break; + case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break; + case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break; + case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break; + } + k = tspr->x-ospr->x; tspr->x = ospr->x; + if (k != 0) tspr->x += mulscale16(k,j); + k = tspr->y-ospr->y; tspr->y = ospr->y; + if (k != 0) tspr->y += mulscale16(k,j); + k = tspr->z-ospr->z; tspr->z = ospr->z; + if (k != 0) tspr->z += mulscale16(k,j); + } - //Don't allow close explosion sprites to be transluscent - k = tspr->statnum; - if ((k == 3) || (k == 4) || (k == 5) || (k == 7)) - if (klabs(dax-tspr->x) < 256) - if (klabs(day-tspr->y) < 256) - tspr->cstat &= ~2; + //Don't allow close explosion sprites to be transluscent + k = tspr->statnum; + if ((k == 3) || (k == 4) || (k == 5) || (k == 7)) + if (klabs(dax-tspr->x) < 256) + if (klabs(day-tspr->y) < 256) + tspr->cstat &= ~2; - tspr->shade += 6; - if (sector[tspr->sectnum].ceilingstat&1) - tspr->shade += sector[tspr->sectnum].ceilingshade; - else - tspr->shade += sector[tspr->sectnum].floorshade; - } + tspr->shade += 6; + if (sector[tspr->sectnum].ceilingstat&1) + tspr->shade += sector[tspr->sectnum].ceilingshade; + else + tspr->shade += sector[tspr->sectnum].floorshade; + } } void tagcode(void) { - long i, nexti, j, k, l, s, dax, day, daz, dax2, day2, cnt, good; - short startwall, endwall, dasector, p, oldang; + long i, nexti, j, k, l, s, dax, day, daz, dax2, day2, cnt, good; + short startwall, endwall, dasector, p, oldang; - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - if (sector[cursectnum[p]].lotag == 1) - { - activatehitag(sector[cursectnum[p]].hitag); - sector[cursectnum[p]].lotag = 0; - sector[cursectnum[p]].hitag = 0; - } - if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p])) - activatehitag(sector[cursectnum[p]].hitag); - } + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + if (sector[cursectnum[p]].lotag == 1) + { + activatehitag(sector[cursectnum[p]].hitag); + sector[cursectnum[p]].lotag = 0; + sector[cursectnum[p]].hitag = 0; + } + if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p])) + activatehitag(sector[cursectnum[p]].hitag); + } - for(i=0;i>2); - if (j >= 16) j = 31-j; - { - sector[dasector].ceilingshade = j; - sector[dasector].floorshade = j; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(s=startwall;s>2); + if (j >= 16) j = 31-j; + { + sector[dasector].ceilingshade = j; + sector[dasector].floorshade = j; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(s=startwall;s=0;p=connectpoint2[p]) - if (sector[cursectnum[p]].lotag == 10) //warp sector - { - if (cursectnum[p] != ocursectnum[p]) - { - warpsprite(playersprite[p]); - posx[p] = sprite[playersprite[p]].x; - posy[p] = sprite[playersprite[p]].y; - posz[p] = sprite[playersprite[p]].z; - ang[p] = sprite[playersprite[p]].ang; - cursectnum[p] = sprite[playersprite[p]].sectnum; + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (sector[cursectnum[p]].lotag == 10) //warp sector + { + if (cursectnum[p] != ocursectnum[p]) + { + warpsprite(playersprite[p]); + posx[p] = sprite[playersprite[p]].x; + posy[p] = sprite[playersprite[p]].y; + posz[p] = sprite[playersprite[p]].z; + ang[p] = sprite[playersprite[p]].ang; + cursectnum[p] = sprite[playersprite[p]].sectnum; - sprite[playersprite[p]].z += EYEHEIGHT; + sprite[playersprite[p]].z += EYEHEIGHT; - //warp(&posx[p],&posy[p],&posz[p],&ang[p],&cursectnum[p]); - //Update sprite representation of player - //setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - //sprite[playersprite[p]].ang = ang[p]; - } - } + //warp(&posx[p],&posy[p],&posz[p],&ang[p],&cursectnum[p]); + //Update sprite representation of player + //setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + //sprite[playersprite[p]].ang = ang[p]; + } + } - for(i=0;i>2)&255); - } + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(s=startwall;s>2)&255); + } - for(i=0;i>2)&255); - sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255); - } + for(i=0;i>2)&255); + sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255); + } - for(i=0;i dragx2[i]) dragxdir[i] = -16; - if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16; + if (wall[startwall].x+dragxdir[i] < dragx1[i]) dragxdir[i] = 16; + if (wall[startwall].y+dragydir[i] < dragy1[i]) dragydir[i] = 16; + if (wall[startwall].x+dragxdir[i] > dragx2[i]) dragxdir[i] = -16; + if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16; - for(j=startwall;j>3); + for(j=startwall;j>3); - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (cursectnum[p] == dasector) - { - posx[p] += dragxdir[i]; - posy[p] += dragydir[i]; - if (p == myconnectindex) - { myx += dragxdir[i]; myy += dragydir[i]; } - //posz[p] += (sector[dasector].floorz-j); + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (cursectnum[p] == dasector) + { + posx[p] += dragxdir[i]; + posy[p] += dragydir[i]; + if (p == myconnectindex) + { myx += dragxdir[i]; myy += dragydir[i]; } + //posz[p] += (sector[dasector].floorz-j); - //Update sprite representation of player - setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - sprite[playersprite[p]].ang = ang[p]; - } - } + //Update sprite representation of player + setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + sprite[playersprite[p]].ang = ang[p]; + } + } - for(i=0;i=0;p=connectpoint2[p]) - if ((cursectnum[p] == swingsector[i]) || (testneighborsectors(cursectnum[p],swingsector[i]) == 1)) - { - cnt = 256; - do - { - good = 1; + if (swinganginc[i] != 0) + { + for(p=connecthead;p>=0;p=connectpoint2[p]) + if ((cursectnum[p] == swingsector[i]) || (testneighborsectors(cursectnum[p],swingsector[i]) == 1)) + { + cnt = 256; + do + { + good = 1; - //swingangopendir is -1 if forwards, 1 is backwards - l = (swingangopendir[i] > 0); - for(k=l+3;k>=l;k--) - if (clipinsidebox(posx[p],posy[p],swingwall[i][k],128L) != 0) - { - good = 0; - break; - } - if (good == 0) - { - if (cnt == 256) - { - swinganginc[i] = -swinganginc[i]; - swingang[i] = oldang; - } - else - { - swingang[i] = ((swingang[i]-swinganginc[i])&2047); - } - for(k=1;k<=3;k++) - rotatepoint(swingx[i][0],swingy[i][0],swingx[i][k],swingy[i][k],swingang[i],&wall[swingwall[i][k]].x,&wall[swingwall[i][k]].y); - if (swingang[i] == swingangclosed[i]) - { - wsayfollow("closdoor.wav",4096L+(krand()&511)-256,256L,&swingx[i][0],&swingy[i][0],0); - swinganginc[i] = 0; - break; - } - if (swingang[i] == swingangopen[i]) - { - swinganginc[i] = 0; - break; - } - cnt--; - } - } while ((good == 0) && (cnt > 0)); - } - } - } - if (swinganginc[i] == 0) - for(j=1;j<=3;j++) - { - stopinterpolation(&wall[swingwall[i][j]].x); - stopinterpolation(&wall[swingwall[i][j]].y); - } - } + //swingangopendir is -1 if forwards, 1 is backwards + l = (swingangopendir[i] > 0); + for(k=l+3;k>=l;k--) + if (clipinsidebox(posx[p],posy[p],swingwall[i][k],128L) != 0) + { + good = 0; + break; + } + if (good == 0) + { + if (cnt == 256) + { + swinganginc[i] = -swinganginc[i]; + swingang[i] = oldang; + } + else + { + swingang[i] = ((swingang[i]-swinganginc[i])&2047); + } + for(k=1;k<=3;k++) + rotatepoint(swingx[i][0],swingy[i][0],swingx[i][k],swingy[i][k],swingang[i],&wall[swingwall[i][k]].x,&wall[swingwall[i][k]].y); + if (swingang[i] == swingangclosed[i]) + { + wsayfollow("closdoor.wav",4096L+(krand()&511)-256,256L,&swingx[i][0],&swingy[i][0],0); + swinganginc[i] = 0; + break; + } + if (swingang[i] == swingangopen[i]) + { + swinganginc[i] = 0; + break; + } + cnt--; + } + } while ((good == 0) && (cnt > 0)); + } + } + } + if (swinganginc[i] == 0) + for(j=1;j<=3;j++) + { + stopinterpolation(&wall[swingwall[i][j]].x); + stopinterpolation(&wall[swingwall[i][j]].y); + } + } - for(i=0;i 2)) - { - dasector = subwaytracksector[i][0]; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(k=startwall;k subwaytrackx1[i]) - if (wall[k].y > subwaytracky1[i]) - if (wall[k].x < subwaytrackx2[i]) - if (wall[k].y < subwaytracky2[i]) - wall[k].x += subwayvel[i]; + for(i=0;i 2)) + { + dasector = subwaytracksector[i][0]; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(k=startwall;k subwaytrackx1[i]) + if (wall[k].y > subwaytracky1[i]) + if (wall[k].x < subwaytrackx2[i]) + if (wall[k].y < subwaytracky2[i]) + wall[k].x += subwayvel[i]; - for(j=1;j=0;s=nextspritesect[s]) - sprite[s].x += subwayvel[i]; - } + for(s=headspritesect[dasector];s>=0;s=nextspritesect[s]) + sprite[s].x += subwayvel[i]; + } - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (cursectnum[p] != subwaytracksector[i][0]) - if (sector[cursectnum[p]].floorz != sector[subwaytracksector[i][0]].floorz) - if (posx[p] > subwaytrackx1[i]) - if (posy[p] > subwaytracky1[i]) - if (posx[p] < subwaytrackx2[i]) - if (posy[p] < subwaytracky2[i]) - { - posx[p] += subwayvel[i]; - if (p == myconnectindex) - { myx += subwayvel[i]; } + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (cursectnum[p] != subwaytracksector[i][0]) + if (sector[cursectnum[p]].floorz != sector[subwaytracksector[i][0]].floorz) + if (posx[p] > subwaytrackx1[i]) + if (posy[p] > subwaytracky1[i]) + if (posx[p] < subwaytrackx2[i]) + if (posy[p] < subwaytracky2[i]) + { + posx[p] += subwayvel[i]; + if (p == myconnectindex) + { myx += subwayvel[i]; } - //Update sprite representation of player - setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - sprite[playersprite[p]].ang = ang[p]; - } + //Update sprite representation of player + setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + sprite[playersprite[p]].ang = ang[p]; + } - subwayx[i] += subwayvel[i]; - } + subwayx[i] += subwayvel[i]; + } - j = subwayvel[i]; - k = subwaystop[i][subwaygoalstop[i]] - subwayx[i]; - if (k > 0) - { - if (k > 4096) - { - if (subwayvel[i] < 256) subwayvel[i]++; - } - else - subwayvel[i] = (k>>4)+1; - } - else if (k < 0) - { - if (k < -4096) - { - if (subwayvel[i] > -256) subwayvel[i]--; - } - else - subwayvel[i] = (k>>4)-1; - } - if ((j < 0) && (subwayvel[i] >= 0)) subwayvel[i] = -1; - if ((j > 0) && (subwayvel[i] <= 0)) subwayvel[i] = 1; + j = subwayvel[i]; + k = subwaystop[i][subwaygoalstop[i]] - subwayx[i]; + if (k > 0) + { + if (k > 4096) + { + if (subwayvel[i] < 256) subwayvel[i]++; + } + else + subwayvel[i] = (k>>4)+1; + } + else if (k < 0) + { + if (k < -4096) + { + if (subwayvel[i] > -256) subwayvel[i]--; + } + else + subwayvel[i] = (k>>4)-1; + } + if ((j < 0) && (subwayvel[i] >= 0)) subwayvel[i] = -1; + if ((j > 0) && (subwayvel[i] <= 0)) subwayvel[i] = 1; - if ((subwayvel[i] <= 2) && (subwayvel[i] >= -2) && (klabs(k) < 2048)) - { - //Open / close doors - if ((subwaypausetime[i] == 720) || ((subwaypausetime[i] >= 120) && (subwaypausetime[i]-TICSPERFRAME < 120))) - activatehitag(sector[subwaytracksector[i][0]].hitag); + if ((subwayvel[i] <= 2) && (subwayvel[i] >= -2) && (klabs(k) < 2048)) + { + //Open / close doors + if ((subwaypausetime[i] == 720) || ((subwaypausetime[i] >= 120) && (subwaypausetime[i]-TICSPERFRAME < 120))) + activatehitag(sector[subwaytracksector[i][0]].hitag); - subwaypausetime[i] -= TICSPERFRAME; - if (subwaypausetime[i] < 0) - { - subwaypausetime[i] = 720; - if (subwayvel[i] < 0) - { - subwaygoalstop[i]--; - if (subwaygoalstop[i] < 0) - { - subwaygoalstop[i] = 1; - subwayvel[i] = 1; - } - } - else if (subwayvel[i] > 0) - { - subwaygoalstop[i]++; - if (subwaygoalstop[i] >= subwaystopcnt[i]) - { - subwaygoalstop[i] = subwaystopcnt[i]-2; - subwayvel[i] = -1; - } - } - } - } - } + subwaypausetime[i] -= TICSPERFRAME; + if (subwaypausetime[i] < 0) + { + subwaypausetime[i] = 720; + if (subwayvel[i] < 0) + { + subwaygoalstop[i]--; + if (subwaygoalstop[i] < 0) + { + subwaygoalstop[i] = 1; + subwayvel[i] = 1; + } + } + else if (subwayvel[i] > 0) + { + subwaygoalstop[i]++; + if (subwaygoalstop[i] >= subwaystopcnt[i]) + { + subwaygoalstop[i] = subwaystopcnt[i]-2; + subwayvel[i] = -1; + } + } + } + } + } } void statuslistcode(void) { - short p, target, hitobject, daang, osectnum, movestat; - long i, nexti, j, nextj, k, l, dax, day, daz, dist, ox, oy, mindist; - long doubvel, xvect, yvect; + short p, target, hitobject, daang, osectnum, movestat; + long i, nexti, j, nextj, k, l, dax, day, daz, dist, ox, oy, mindist; + long doubvel, xvect, yvect; - //Go through active BROWNMONSTER list - for(i=headspritestat[1];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through active BROWNMONSTER list + for(i=headspritestat[1];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - k = krand(); + k = krand(); - //Choose a target player - mindist = 0x7fffffff; target = connecthead; - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); - if (dist < mindist) mindist = dist, target = p; - } + //Choose a target player + mindist = 0x7fffffff; target = connecthead; + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); + if (dist < mindist) mindist = dist, target = p; + } - //brown monster decides to shoot bullet - if ((k&63) == 23) - { - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 0) - { - if ((k&0xf00) == 0xb00) changespritestat(i,2); - } - else - { - wsayfollow("monshoot.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + //brown monster decides to shoot bullet + if ((k&63) == 23) + { + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 0) + { + if ((k&0xf00) == 0xb00) changespritestat(i,2); + } + else + { + wsayfollow("monshoot.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - doubvel = (TICSPERFRAME<<((ssync[target].bits&256)>0)); - xvect = 0, yvect = 0; - if (ssync[target].fvel != 0) - { - xvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[(ang[target]+512)&2047])>>3); - yvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[ang[target]&2047])>>3); - } - if (ssync[target].svel != 0) - { - xvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[ang[target]&2047])>>3); - yvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[(ang[target]+1536)&2047])>>3); - } + doubvel = (TICSPERFRAME<<((ssync[target].bits&256)>0)); + xvect = 0, yvect = 0; + if (ssync[target].fvel != 0) + { + xvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[(ang[target]+512)&2047])>>3); + yvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[ang[target]&2047])>>3); + } + if (ssync[target].svel != 0) + { + xvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[ang[target]&2047])>>3); + yvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[(ang[target]+1536)&2047])>>3); + } - ox = posx[target]; oy = posy[target]; + ox = posx[target]; oy = posy[target]; - //distance is j - j = ksqrt((ox-sprite[i].x)*(ox-sprite[i].x)+(oy-sprite[i].y)*(oy-sprite[i].y)); + //distance is j + j = ksqrt((ox-sprite[i].x)*(ox-sprite[i].x)+(oy-sprite[i].y)*(oy-sprite[i].y)); - switch((sprite[i].extra>>11)&3) - { - case 1: j = -(j>>1); break; - case 3: j = 0; break; - case 0: case 2: break; - } - sprite[i].extra += 2048; + switch((sprite[i].extra>>11)&3) + { + case 1: j = -(j>>1); break; + case 3: j = 0; break; + case 0: case 2: break; + } + sprite[i].extra += 2048; - //rate is (TICSPERFRAME<<19) - xvect = scale(xvect,j,TICSPERFRAME<<19); - yvect = scale(yvect,j,TICSPERFRAME<<19); - clipmove(&ox,&oy,&posz[target],&cursectnum[target],xvect<<14,yvect<<14,128L,4<<8,4<<8,CLIPMASK0); - ox -= sprite[i].x; - oy -= sprite[i].y; + //rate is (TICSPERFRAME<<19) + xvect = scale(xvect,j,TICSPERFRAME<<19); + yvect = scale(yvect,j,TICSPERFRAME<<19); + clipmove(&ox,&oy,&posz[target],&cursectnum[target],xvect<<14,yvect<<14,128L,4<<8,4<<8,CLIPMASK0); + ox -= sprite[i].x; + oy -= sprite[i].y; - daang = ((getangle(ox,oy)+(krand()&7)-4)&2047); + daang = ((getangle(ox,oy)+(krand()&7)-4)&2047); - dax = (sintable[(daang+512)&2047]>>6); - day = (sintable[daang&2047]>>6); - daz = 0; - if (ox != 0) - daz = scale(dax,posz[target]+(8<<8)-sprite[i].z,ox); - else if (oy != 0) - daz = scale(day,posz[target]+(8<<8)-sprite[i].z,oy); + dax = (sintable[(daang+512)&2047]>>6); + day = (sintable[daang&2047]>>6); + daz = 0; + if (ox != 0) + daz = scale(dax,posz[target]+(8<<8)-sprite[i].z,ox); + else if (oy != 0) + daz = scale(day,posz[target]+(8<<8)-sprite[i].z,oy); - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,128,0,0, - 16,sprite[i].xrepeat,sprite[i].yrepeat,0,0,BULLET,daang,dax,day,daz,i,sprite[i].sectnum,6,0,0,0); + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,128,0,0, + 16,sprite[i].xrepeat,sprite[i].yrepeat,0,0,BULLET,daang,dax,day,daz,i,sprite[i].sectnum,6,0,0,0); - sprite[i].extra &= (~2047); - } - } + sprite[i].extra &= (~2047); + } + } - //Move brown monster - dax = sprite[i].x; //Back up old x&y if stepping off cliff - day = sprite[i].y; + //Move brown monster + dax = sprite[i].x; //Back up old x&y if stepping off cliff + day = sprite[i].y; - doubvel = max(mulscale7(sprite[i].xrepeat,sprite[i].yrepeat),4); + doubvel = max(mulscale7(sprite[i].xrepeat,sprite[i].yrepeat),4); - osectnum = sprite[i].sectnum; - movestat = movesprite((short)i,(long)sintable[(sprite[i].ang+512)&2047]*doubvel,(long)sintable[sprite[i].ang]*doubvel,0L,4L<<8,4L<<8,CLIPMASK0); - if (globloz > sprite[i].z+(48<<8)) - { sprite[i].x = dax; sprite[i].y = day; movestat = 1; } - else - sprite[i].z = globloz-((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + osectnum = sprite[i].sectnum; + movestat = movesprite((short)i,(long)sintable[(sprite[i].ang+512)&2047]*doubvel,(long)sintable[sprite[i].ang]*doubvel,0L,4L<<8,4L<<8,CLIPMASK0); + if (globloz > sprite[i].z+(48<<8)) + { sprite[i].x = dax; sprite[i].y = day; movestat = 1; } + else + sprite[i].z = globloz-((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { warpsprite((short)i); movestat = 0; } + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { warpsprite((short)i); movestat = 0; } - if ((movestat != 0) || ((k&63) == 1)) - { - if (sprite[i].ang == (sprite[i].extra&2047)) - { - daang = (getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y)&2047); - daang = ((daang+(krand()&1023)-512)&2047); - sprite[i].extra = ((sprite[i].extra&(~2047))|daang); - } - if ((sprite[i].extra-sprite[i].ang)&1024) - { - sprite[i].ang = ((sprite[i].ang-32)&2047); - if (!((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); - } - else - { - sprite[i].ang = ((sprite[i].ang+32)&2047); - if (((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); - } - } - } + if ((movestat != 0) || ((k&63) == 1)) + { + if (sprite[i].ang == (sprite[i].extra&2047)) + { + daang = (getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y)&2047); + daang = ((daang+(krand()&1023)-512)&2047); + sprite[i].extra = ((sprite[i].extra&(~2047))|daang); + } + if ((sprite[i].extra-sprite[i].ang)&1024) + { + sprite[i].ang = ((sprite[i].ang-32)&2047); + if (!((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); + } + else + { + sprite[i].ang = ((sprite[i].ang+32)&2047); + if (((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); + } + } + } - for(i=headspritestat[10];i>=0;i=nexti) //EVILAL list - { - nexti = nextspritestat[i]; + for(i=headspritestat[10];i>=0;i=nexti) //EVILAL list + { + nexti = nextspritestat[i]; - if (sprite[i].yrepeat < 38) continue; - if (sprite[i].yrepeat < 64) - { - sprite[i].xrepeat++; - sprite[i].yrepeat++; - continue; - } + if (sprite[i].yrepeat < 38) continue; + if (sprite[i].yrepeat < 64) + { + sprite[i].xrepeat++; + sprite[i].yrepeat++; + continue; + } - if ((nummoves-i)&statrate[10]) continue; + if ((nummoves-i)&statrate[10]) continue; - //Choose a target player - mindist = 0x7fffffff; target = connecthead; - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); - if (dist < mindist) mindist = dist, target = p; - } + //Choose a target player + mindist = 0x7fffffff; target = connecthead; + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); + if (dist < mindist) mindist = dist, target = p; + } - k = (krand()&255); + k = (krand()&255); - if ((sprite[i].lotag&32) && (k < 48)) //Al decides to reproduce - { - l = 0; - if ((sprite[i].lotag&64) && (k < 2)) //Give him a chance to reproduce without seeing you - l = 1; - else if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) - l = 1; - if (l != 0) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].cstat,sprite[i].shade,sprite[i].pal, - sprite[i].clipdist,38,38,sprite[i].xoffset,sprite[i].yoffset,sprite[i].picnum,krand()&2047,0,0,0,i, - sprite[i].sectnum,10,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); - switch(krand()&31) //Mutations! - { - case 0: sprite[i].cstat ^= 2; break; - case 1: sprite[i].cstat ^= 512; break; - case 2: sprite[i].shade++; break; - case 3: sprite[i].shade--; break; - case 4: sprite[i].pal ^= 16; break; - case 5: case 6: case 7: sprite[i].lotag ^= (1<<(krand()&7)); break; - case 8: sprite[i].lotag = (krand()&255); break; - } - } - } - if (k >= 208+((sprite[i].lotag&128)>>2)) //Al decides to shoot bullet - { - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) - { - wsayfollow("zipguns.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + if ((sprite[i].lotag&32) && (k < 48)) //Al decides to reproduce + { + l = 0; + if ((sprite[i].lotag&64) && (k < 2)) //Give him a chance to reproduce without seeing you + l = 1; + else if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) + l = 1; + if (l != 0) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].cstat,sprite[i].shade,sprite[i].pal, + sprite[i].clipdist,38,38,sprite[i].xoffset,sprite[i].yoffset,sprite[i].picnum,krand()&2047,0,0,0,i, + sprite[i].sectnum,10,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); + switch(krand()&31) //Mutations! + { + case 0: sprite[i].cstat ^= 2; break; + case 1: sprite[i].cstat ^= 512; break; + case 2: sprite[i].shade++; break; + case 3: sprite[i].shade--; break; + case 4: sprite[i].pal ^= 16; break; + case 5: case 6: case 7: sprite[i].lotag ^= (1<<(krand()&7)); break; + case 8: sprite[i].lotag = (krand()&255); break; + } + } + } + if (k >= 208+((sprite[i].lotag&128)>>2)) //Al decides to shoot bullet + { + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) + { + wsayfollow("zipguns.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - spawnsprite(j,sprite[i].x,sprite[i].y, - sector[sprite[i].sectnum].floorz-(24<<8), - 0,0,0,16,32,32,0,0,BULLET, - (getangle(posx[target]-sprite[j].x, - posy[target]-sprite[j].y)+(krand()&15)-8)&2047, - sintable[(sprite[j].ang+512)&2047]>>6, - sintable[sprite[j].ang&2047]>>6, - ((posz[target]+(8<<8)-sprite[j].z)<<8) / - (ksqrt((posx[target]-sprite[j].x) * - (posx[target]-sprite[j].x) + - (posy[target]-sprite[j].y) * - (posy[target]-sprite[j].y))+1), - i,sprite[i].sectnum,6,0,0,0); - } - } + spawnsprite(j,sprite[i].x,sprite[i].y, + sector[sprite[i].sectnum].floorz-(24<<8), + 0,0,0,16,32,32,0,0,BULLET, + (getangle(posx[target]-sprite[j].x, + posy[target]-sprite[j].y)+(krand()&15)-8)&2047, + sintable[(sprite[j].ang+512)&2047]>>6, + sintable[sprite[j].ang&2047]>>6, + ((posz[target]+(8<<8)-sprite[j].z)<<8) / + (ksqrt((posx[target]-sprite[j].x) * + (posx[target]-sprite[j].x) + + (posy[target]-sprite[j].y) * + (posy[target]-sprite[j].y))+1), + i,sprite[i].sectnum,6,0,0,0); + } + } - //Move Al - l = (((sprite[i].lotag&3)+2)<<8); - if (sprite[i].lotag&4) l = -l; - dax = sintable[(sprite[i].ang+512)&2047]*l; - day = sintable[sprite[i].ang]*l; + //Move Al + l = (((sprite[i].lotag&3)+2)<<8); + if (sprite[i].lotag&4) l = -l; + dax = sintable[(sprite[i].ang+512)&2047]*l; + day = sintable[sprite[i].ang]*l; - osectnum = sprite[i].sectnum; - movestat = movesprite((short)i,dax,day,0L,-8L<<8,-8L<<8,CLIPMASK0); - sprite[i].z = globloz; - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { - warpsprite((short)i); - movestat = 0; - } + osectnum = sprite[i].sectnum; + movestat = movesprite((short)i,dax,day,0L,-8L<<8,-8L<<8,CLIPMASK0); + sprite[i].z = globloz; + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { + warpsprite((short)i); + movestat = 0; + } - if (sprite[i].lotag&16) - { - if (((k&124) >= 120) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) - sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); - else - sprite[i].ang = (krand()&2047); - } + if (sprite[i].lotag&16) + { + if (((k&124) >= 120) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) + sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); + else + sprite[i].ang = (krand()&2047); + } - if (movestat != 0) - { - if ((k&2) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) - sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); - else - sprite[i].ang = (krand()&2047); + if (movestat != 0) + { + if ((k&2) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) + sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); + else + sprite[i].ang = (krand()&2047); - if ((movestat&49152) == 49152) - if (sprite[movestat&16383].picnum == EVILAL) - if ((k&31) >= 30) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } + if ((movestat&49152) == 49152) + if (sprite[movestat&16383].picnum == EVILAL) + if ((k&31) >= 30) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } - if (sprite[i].lotag&8) - if ((k&31) >= 30) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } + if (sprite[i].lotag&8) + if ((k&31) >= 30) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } - if (movestat == -1) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } - } - } + if (movestat == -1) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } + } + } - //Go through travelling bullet sprites - for(i=headspritestat[6];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through travelling bullet sprites + for(i=headspritestat[6];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - if ((nummoves-i)&statrate[6]) continue; + if ((nummoves-i)&statrate[6]) continue; - //If the sprite is a bullet then... - if ((sprite[i].picnum == BULLET) || (sprite[i].picnum == GRABBER) || (sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) - { - dax = ((((long)sprite[i].xvel)*TICSPERFRAME)<<12); - day = ((((long)sprite[i].yvel)*TICSPERFRAME)<<12); - daz = ((((long)sprite[i].zvel)*TICSPERFRAME)>>2); - if (sprite[i].picnum == BOMB) daz = 0; + //If the sprite is a bullet then... + if ((sprite[i].picnum == BULLET) || (sprite[i].picnum == GRABBER) || (sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) + { + dax = ((((long)sprite[i].xvel)*TICSPERFRAME)<<12); + day = ((((long)sprite[i].yvel)*TICSPERFRAME)<<12); + daz = ((((long)sprite[i].zvel)*TICSPERFRAME)>>2); + if (sprite[i].picnum == BOMB) daz = 0; - osectnum = sprite[i].sectnum; - hitobject = movesprite((short)i,dax,day,daz,4L<<8,4L<<8,CLIPMASK1); - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { - warpsprite((short)i); - hitobject = 0; - } + osectnum = sprite[i].sectnum; + hitobject = movesprite((short)i,dax,day,daz,4L<<8,4L<<8,CLIPMASK1); + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { + warpsprite((short)i); + hitobject = 0; + } - if (sprite[i].picnum == GRABBER) { // Andy did this (& Ken) !Homing! - checkgrabbertouchsprite(i,sprite[i].sectnum); - l = 0x7fffffff; - for (j = connecthead; j >= 0; j = connectpoint2[j]) // Players - if (j != (sprite[i].owner & (MAXSPRITES - 1))) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j])) { - k = ksqrt(sqr(posx[j] - sprite[i].x) + sqr(posy[j] - sprite[i].y) + (sqr(posz[j] - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (posx[j] - sprite[i].x); - day = (posy[j] - sprite[i].y); - daz = (posz[j] - sprite[i].z); - } - } - for(j = headspritestat[1]; j >= 0; j = nextj) { // Active monsters - nextj = nextspritestat[j]; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { - k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (sprite[j].x - sprite[i].x); - day = (sprite[j].y - sprite[i].y); - daz = (sprite[j].z - sprite[i].z); - } - } - } - for(j = headspritestat[2]; j >= 0; j = nextj) { // Inactive monsters - nextj = nextspritestat[j]; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { - k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (sprite[j].x - sprite[i].x); - day = (sprite[j].y - sprite[i].y); - daz = (sprite[j].z - sprite[i].z); - } - } - } - if (l != 0x7fffffff) { - sprite[i].xvel = (divscale7(dax,l) + sprite[i].xvel); // 1/5 of velocity is homing, 4/5 is momentum - sprite[i].yvel = (divscale7(day,l) + sprite[i].yvel); // 1/5 of velocity is homing, 4/5 is momentum - sprite[i].zvel = (divscale7(daz,l) + sprite[i].zvel); // 1/5 of velocity is homing, 4/5 is momentum - l = ksqrt((sprite[i].xvel * sprite[i].xvel) + (sprite[i].yvel * sprite[i].yvel) + ((sprite[i].zvel * sprite[i].zvel) >> 8)); - sprite[i].xvel = divscale9(sprite[i].xvel,l); - sprite[i].yvel = divscale9(sprite[i].yvel,l); - sprite[i].zvel = divscale9(sprite[i].zvel,l); - sprite[i].ang = getangle(sprite[i].xvel,sprite[i].yvel); - } - } + if (sprite[i].picnum == GRABBER) { // Andy did this (& Ken) !Homing! + checkgrabbertouchsprite(i,sprite[i].sectnum); + l = 0x7fffffff; + for (j = connecthead; j >= 0; j = connectpoint2[j]) // Players + if (j != (sprite[i].owner & (MAXSPRITES - 1))) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j])) { + k = ksqrt(sqr(posx[j] - sprite[i].x) + sqr(posy[j] - sprite[i].y) + (sqr(posz[j] - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (posx[j] - sprite[i].x); + day = (posy[j] - sprite[i].y); + daz = (posz[j] - sprite[i].z); + } + } + for(j = headspritestat[1]; j >= 0; j = nextj) { // Active monsters + nextj = nextspritestat[j]; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { + k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (sprite[j].x - sprite[i].x); + day = (sprite[j].y - sprite[i].y); + daz = (sprite[j].z - sprite[i].z); + } + } + } + for(j = headspritestat[2]; j >= 0; j = nextj) { // Inactive monsters + nextj = nextspritestat[j]; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { + k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (sprite[j].x - sprite[i].x); + day = (sprite[j].y - sprite[i].y); + daz = (sprite[j].z - sprite[i].z); + } + } + } + if (l != 0x7fffffff) { + sprite[i].xvel = (divscale7(dax,l) + sprite[i].xvel); // 1/5 of velocity is homing, 4/5 is momentum + sprite[i].yvel = (divscale7(day,l) + sprite[i].yvel); // 1/5 of velocity is homing, 4/5 is momentum + sprite[i].zvel = (divscale7(daz,l) + sprite[i].zvel); // 1/5 of velocity is homing, 4/5 is momentum + l = ksqrt((sprite[i].xvel * sprite[i].xvel) + (sprite[i].yvel * sprite[i].yvel) + ((sprite[i].zvel * sprite[i].zvel) >> 8)); + sprite[i].xvel = divscale9(sprite[i].xvel,l); + sprite[i].yvel = divscale9(sprite[i].yvel,l); + sprite[i].zvel = divscale9(sprite[i].zvel,l); + sprite[i].ang = getangle(sprite[i].xvel,sprite[i].yvel); + } + } - if (sprite[i].picnum == BOMB) - { - j = sprite[i].sectnum; - if ((sector[j].floorstat&2) && (sprite[i].z > globloz-(8<<8))) - { - k = sector[j].wallptr; - daang = getangle(wall[wall[k].point2].x-wall[k].x,wall[wall[k].point2].y-wall[k].y); - sprite[i].xvel += mulscale22(sintable[(daang+1024)&2047],sector[j].floorheinum); - sprite[i].yvel += mulscale22(sintable[(daang+512)&2047],sector[j].floorheinum); - } - } + if (sprite[i].picnum == BOMB) + { + j = sprite[i].sectnum; + if ((sector[j].floorstat&2) && (sprite[i].z > globloz-(8<<8))) + { + k = sector[j].wallptr; + daang = getangle(wall[wall[k].point2].x-wall[k].x,wall[wall[k].point2].y-wall[k].y); + sprite[i].xvel += mulscale22(sintable[(daang+1024)&2047],sector[j].floorheinum); + sprite[i].yvel += mulscale22(sintable[(daang+512)&2047],sector[j].floorheinum); + } + } - if (sprite[i].picnum == BOMB) - { - sprite[i].z += sprite[i].zvel; - sprite[i].zvel += (TICSPERFRAME<<7); - if (sprite[i].z < globhiz+(tilesizy[BOMB]<<6)) - { - sprite[i].z = globhiz+(tilesizy[BOMB]<<6); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > globloz-(tilesizy[BOMB]<<6)) - { - sprite[i].z = globloz-(tilesizy[BOMB]<<6); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - dax = sprite[i].xvel; day = sprite[i].yvel; - dist = dax*dax+day*day; - if (dist < 512) - { - bombexplode(i); - goto bulletisdeletedskip; - } - if (dist < 4096) - { - sprite[i].xrepeat = ((4096+2048)*16) / (dist+2048); - sprite[i].yrepeat = sprite[i].xrepeat; - sprite[i].xoffset = (krand()&15)-8; - sprite[i].yoffset = (krand()&15)-8; - } - if (mulscale30(krand(),dist) == 0) - { - sprite[i].xvel -= ksgn(sprite[i].xvel); - sprite[i].yvel -= ksgn(sprite[i].yvel); - sprite[i].zvel -= ksgn(sprite[i].zvel); - } - } + if (sprite[i].picnum == BOMB) + { + sprite[i].z += sprite[i].zvel; + sprite[i].zvel += (TICSPERFRAME<<7); + if (sprite[i].z < globhiz+(tilesizy[BOMB]<<6)) + { + sprite[i].z = globhiz+(tilesizy[BOMB]<<6); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > globloz-(tilesizy[BOMB]<<6)) + { + sprite[i].z = globloz-(tilesizy[BOMB]<<6); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + dax = sprite[i].xvel; day = sprite[i].yvel; + dist = dax*dax+day*day; + if (dist < 512) + { + bombexplode(i); + goto bulletisdeletedskip; + } + if (dist < 4096) + { + sprite[i].xrepeat = ((4096+2048)*16) / (dist+2048); + sprite[i].yrepeat = sprite[i].xrepeat; + sprite[i].xoffset = (krand()&15)-8; + sprite[i].yoffset = (krand()&15)-8; + } + if (mulscale30(krand(),dist) == 0) + { + sprite[i].xvel -= ksgn(sprite[i].xvel); + sprite[i].yvel -= ksgn(sprite[i].yvel); + sprite[i].zvel -= ksgn(sprite[i].zvel); + } + } - //Check for bouncy objects before killing bullet - if ((hitobject&0xc000) == 16384) //Bullet hit a ceiling/floor - { - k = sector[hitobject&(MAXSECTORS-1)].wallptr; l = wall[k].point2; - daang = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y); + //Check for bouncy objects before killing bullet + if ((hitobject&0xc000) == 16384) //Bullet hit a ceiling/floor + { + k = sector[hitobject&(MAXSECTORS-1)].wallptr; l = wall[k].point2; + daang = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y); - getzsofslope(hitobject&(MAXSECTORS-1),sprite[i].x,sprite[i].y,&k,&l); - if (sprite[i].z < ((k+l)>>1)) k = sector[hitobject&(MAXSECTORS-1)].ceilingheinum; - else k = sector[hitobject&(MAXSECTORS-1)].floorheinum; + getzsofslope(hitobject&(MAXSECTORS-1),sprite[i].x,sprite[i].y,&k,&l); + if (sprite[i].z < ((k+l)>>1)) k = sector[hitobject&(MAXSECTORS-1)].ceilingheinum; + else k = sector[hitobject&(MAXSECTORS-1)].floorheinum; - dax = mulscale14(k,sintable[(daang)&2047]); - day = mulscale14(k,sintable[(daang+1536)&2047]); - daz = 4096; + dax = mulscale14(k,sintable[(daang)&2047]); + day = mulscale14(k,sintable[(daang+1536)&2047]); + daz = 4096; - k = sprite[i].xvel*dax+sprite[i].yvel*day+mulscale4(sprite[i].zvel,daz); - l = dax*dax+day*day+daz*daz; - if ((klabs(k)>>14) < l) - { - k = divscale17(k,l); - sprite[i].xvel -= mulscale16(dax,k); - sprite[i].yvel -= mulscale16(day,k); - sprite[i].zvel -= mulscale12(daz,k); - } - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,255,&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - sprite[i].owner = -1; //Bullet turns evil! - } - else if ((hitobject&0xc000) == 32768) //Bullet hit a wall - { - if (wall[hitobject&4095].lotag == 8) - { - dax = sprite[i].xvel; day = sprite[i].yvel; - if ((sprite[i].picnum != BOMB) || (dax*dax+day*day >= 512)) - { - k = (hitobject&4095); l = wall[k].point2; - j = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y)+512; + k = sprite[i].xvel*dax+sprite[i].yvel*day+mulscale4(sprite[i].zvel,daz); + l = dax*dax+day*day+daz*daz; + if ((klabs(k)>>14) < l) + { + k = divscale17(k,l); + sprite[i].xvel -= mulscale16(dax,k); + sprite[i].yvel -= mulscale16(day,k); + sprite[i].zvel -= mulscale12(daz,k); + } + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,255,&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + sprite[i].owner = -1; //Bullet turns evil! + } + else if ((hitobject&0xc000) == 32768) //Bullet hit a wall + { + if (wall[hitobject&4095].lotag == 8) + { + dax = sprite[i].xvel; day = sprite[i].yvel; + if ((sprite[i].picnum != BOMB) || (dax*dax+day*day >= 512)) + { + k = (hitobject&4095); l = wall[k].point2; + j = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y)+512; - //k = cos(ang) * sin(ang) * 2 - k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); - //l = cos(ang * 2) - l = sintable[((j<<1)+512)&2047]; + //k = cos(ang) * sin(ang) * 2 + k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); + //l = cos(ang * 2) + l = sintable[((j<<1)+512)&2047]; - ox = sprite[i].xvel; oy = sprite[i].yvel; - dax = -ox; day = -oy; - sprite[i].xvel = dmulscale14(day,k,dax,l); - sprite[i].yvel = dmulscale14(dax,k,-day,l); + ox = sprite[i].xvel; oy = sprite[i].yvel; + dax = -ox; day = -oy; + sprite[i].xvel = dmulscale14(day,k,dax,l); + sprite[i].yvel = dmulscale14(dax,k,-day,l); - if (sprite[i].picnum == BOMB) - { - sprite[i].xvel -= (sprite[i].xvel>>3); - sprite[i].yvel -= (sprite[i].yvel>>3); - sprite[i].zvel -= (sprite[i].zvel>>3); - } - ox -= sprite[i].xvel; oy -= sprite[i].yvel; - dist = ((ox*ox+oy*oy)>>8); - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - sprite[i].owner = -1; //Bullet turns evil! - } - } - } - else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite - { - if (sprite[hitobject&4095].picnum == BOUNCYMAT) - { - if ((sprite[hitobject&4095].cstat&48) == 0) - { - sprite[i].xvel = -sprite[i].xvel; - sprite[i].yvel = -sprite[i].yvel; - sprite[i].zvel = -sprite[i].zvel; - dist = 255; - } - else if ((sprite[hitobject&4095].cstat&48) == 16) - { - j = sprite[hitobject&4095].ang; + if (sprite[i].picnum == BOMB) + { + sprite[i].xvel -= (sprite[i].xvel>>3); + sprite[i].yvel -= (sprite[i].yvel>>3); + sprite[i].zvel -= (sprite[i].zvel>>3); + } + ox -= sprite[i].xvel; oy -= sprite[i].yvel; + dist = ((ox*ox+oy*oy)>>8); + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + sprite[i].owner = -1; //Bullet turns evil! + } + } + } + else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite + { + if (sprite[hitobject&4095].picnum == BOUNCYMAT) + { + if ((sprite[hitobject&4095].cstat&48) == 0) + { + sprite[i].xvel = -sprite[i].xvel; + sprite[i].yvel = -sprite[i].yvel; + sprite[i].zvel = -sprite[i].zvel; + dist = 255; + } + else if ((sprite[hitobject&4095].cstat&48) == 16) + { + j = sprite[hitobject&4095].ang; - //k = cos(ang) * sin(ang) * 2 - k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); - //l = cos(ang * 2) - l = sintable[((j<<1)+512)&2047]; + //k = cos(ang) * sin(ang) * 2 + k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); + //l = cos(ang * 2) + l = sintable[((j<<1)+512)&2047]; - ox = sprite[i].xvel; oy = sprite[i].yvel; - dax = -ox; day = -oy; - sprite[i].xvel = dmulscale14(day,k,dax,l); - sprite[i].yvel = dmulscale14(dax,k,-day,l); + ox = sprite[i].xvel; oy = sprite[i].yvel; + dax = -ox; day = -oy; + sprite[i].xvel = dmulscale14(day,k,dax,l); + sprite[i].yvel = dmulscale14(dax,k,-day,l); - ox -= sprite[i].xvel; oy -= sprite[i].yvel; - dist = ((ox*ox+oy*oy)>>8); - } - sprite[i].owner = -1; //Bullet turns evil! - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - } - } + ox -= sprite[i].xvel; oy -= sprite[i].yvel; + dist = ((ox*ox+oy*oy)>>8); + } + sprite[i].owner = -1; //Bullet turns evil! + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + } + } - if (hitobject != 0) - { - if ((sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) - { - if ((hitobject&0xc000) == 49152) - if (sprite[hitobject&4095].lotag == 5) //Basketball hoop - { - wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } + if (hitobject != 0) + { + if ((sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) + { + if ((hitobject&0xc000) == 49152) + if (sprite[hitobject&4095].lotag == 5) //Basketball hoop + { + wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } - bombexplode(i); - goto bulletisdeletedskip; - } + bombexplode(i); + goto bulletisdeletedskip; + } - if ((hitobject&0xc000) == 16384) //Hits a ceiling / floor - { - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - else if ((hitobject&0xc000) == 32768) //Bullet hit a wall - { - if (wall[hitobject&4095].picnum == KENPICTURE) - { - if (waloff[MAXTILES-1] != 0) - wall[hitobject&4095].picnum = MAXTILES-1; - wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); //Ken says, "Hello... how are you today!" - } - else - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if ((hitobject&0xc000) == 16384) //Hits a ceiling / floor + { + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } + else if ((hitobject&0xc000) == 32768) //Bullet hit a wall + { + if (wall[hitobject&4095].picnum == KENPICTURE) + { + if (waloff[MAXTILES-1] != 0) + wall[hitobject&4095].picnum = MAXTILES-1; + wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); //Ken says, "Hello... how are you today!" + } + else + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite - { - if ((sprite[hitobject&4095].lotag == 5) && (sprite[i].picnum == GRABBER)) { // Basketball hoop (Andy's addition) - wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - switch (krand() & 63) { - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: - sprite[i].picnum = COIN; break; - case 10: case 11: case 12: case 13: case 14: case 15: case 16: - sprite[i].picnum = DIAMONDS; break; - case 17: case 18: case 19: - sprite[i].picnum = COINSTACK; break; - case 20: case 21: case 22: case 23: - sprite[i].picnum = GIFTBOX; break; - case 24: case 25: - sprite[i].picnum = GRABCANNON; break; - case 26: case 27: - sprite[i].picnum = LAUNCHER; break; - case 28: case 29: case 30: - sprite[i].picnum = CANNON; break; - case 31: - sprite[i].picnum = AIRPLANE; break; - default: - deletesprite((short)i); - goto bulletisdeletedskip; - } - sprite[i].xvel = sprite[i].yvel = sprite[i].zvel = 0; - sprite[i].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(i,12); - goto bulletisdeletedskip; - } + deletesprite((short)i); + goto bulletisdeletedskip; + } + else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite + { + if ((sprite[hitobject&4095].lotag == 5) && (sprite[i].picnum == GRABBER)) { // Basketball hoop (Andy's addition) + wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + switch (krand() & 63) { +case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: + sprite[i].picnum = COIN; break; +case 10: case 11: case 12: case 13: case 14: case 15: case 16: + sprite[i].picnum = DIAMONDS; break; + case 17: case 18: case 19: + sprite[i].picnum = COINSTACK; break; + case 20: case 21: case 22: case 23: + sprite[i].picnum = GIFTBOX; break; + case 24: case 25: + sprite[i].picnum = GRABCANNON; break; + case 26: case 27: + sprite[i].picnum = LAUNCHER; break; + case 28: case 29: case 30: + sprite[i].picnum = CANNON; break; + case 31: + sprite[i].picnum = AIRPLANE; break; + default: + deletesprite((short)i); + goto bulletisdeletedskip; + } + sprite[i].xvel = sprite[i].yvel = sprite[i].zvel = 0; + sprite[i].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(i,12); + goto bulletisdeletedskip; + } - //Check if bullet hit a player & find which player it was... - if (sprite[hitobject&4095].picnum == PLAYER) - for(j=connecthead;j>=0;j=connectpoint2[j]) - if (sprite[i].owner != j+4096) - if (playersprite[j] == (hitobject&4095)) - { - wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (sprite[i].picnum == GRABBER) { // Andy did this - k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; - changehealth((sprite[i].owner - 4096),k); - changehealth(j,-k); - } - else changehealth(j,-mulscale8(sprite[i].xrepeat,sprite[i].yrepeat)); - deletesprite((short)i); - goto bulletisdeletedskip; - } + //Check if bullet hit a player & find which player it was... + if (sprite[hitobject&4095].picnum == PLAYER) + for(j=connecthead;j>=0;j=connectpoint2[j]) + if (sprite[i].owner != j+4096) + if (playersprite[j] == (hitobject&4095)) + { + wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (sprite[i].picnum == GRABBER) { // Andy did this + k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; + changehealth((sprite[i].owner - 4096),k); + changehealth(j,-k); + } + else changehealth(j,-mulscale8(sprite[i].xrepeat,sprite[i].yrepeat)); + deletesprite((short)i); + goto bulletisdeletedskip; + } - //Check if bullet hit any monsters... - j = (hitobject&4095); //j is the spritenum that the bullet (spritenum i) hit - if (sprite[i].owner != j) - { - switch(sprite[j].picnum) - { - case BROWNMONSTER: - if (sprite[j].lotag > 0) { - if (sprite[i].picnum == GRABBER) { // Andy did this - k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; - changehealth((sprite[i].owner - 4096),k); - sprite[j].lotag -= k; - } - sprite[j].lotag -= mulscale8(sprite[i].xrepeat,sprite[i].yrepeat); - } - if (sprite[j].lotag > 0) - { - if (sprite[j].lotag <= 25) sprite[j].cstat |= 2; - wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&sprite[i].x,&sprite[i].y,1); - } - else - { - wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); - sprite[j].picnum = GIFTBOX; - sprite[j].cstat &= ~0x83; //Should not clip, foot-z + //Check if bullet hit any monsters... + j = (hitobject&4095); //j is the spritenum that the bullet (spritenum i) hit + if (sprite[i].owner != j) + { + switch(sprite[j].picnum) + { + case BROWNMONSTER: + if (sprite[j].lotag > 0) { + if (sprite[i].picnum == GRABBER) { // Andy did this + k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; + changehealth((sprite[i].owner - 4096),k); + sprite[j].lotag -= k; + } + sprite[j].lotag -= mulscale8(sprite[i].xrepeat,sprite[i].yrepeat); + } + if (sprite[j].lotag > 0) + { + if (sprite[j].lotag <= 25) sprite[j].cstat |= 2; + wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&sprite[i].x,&sprite[i].y,1); + } + else + { + wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); + sprite[j].picnum = GIFTBOX; + sprite[j].cstat &= ~0x83; //Should not clip, foot-z - spawnsprite(k,sprite[j].x,sprite[j].y,sprite[j].z, - 0,-4,0,32,64,64,0,0,EXPLOSION,sprite[j].ang, - 0,0,0,j,sprite[j].sectnum,5,31,0,0); - //31=Time left for explosion to stay + spawnsprite(k,sprite[j].x,sprite[j].y,sprite[j].z, + 0,-4,0,32,64,64,0,0,EXPLOSION,sprite[j].ang, + 0,0,0,j,sprite[j].sectnum,5,31,0,0); + //31=Time left for explosion to stay - changespritestat(j,12); - } - deletesprite((short)i); - goto bulletisdeletedskip; - case EVILAL: - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].picnum = EVILALGRAVE; - sprite[j].cstat = 0; - sprite[j].xvel = (krand()&255)-128; - sprite[j].yvel = (krand()&255)-128; - sprite[j].zvel = (krand()&4095)-3072; - changespritestat(j,9); + changespritestat(j,12); + } + deletesprite((short)i); + goto bulletisdeletedskip; + case EVILAL: + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].picnum = EVILALGRAVE; + sprite[j].cstat = 0; + sprite[j].xvel = (krand()&255)-128; + sprite[j].yvel = (krand()&255)-128; + sprite[j].zvel = (krand()&4095)-3072; + changespritestat(j,9); - deletesprite((short)i); - goto bulletisdeletedskip; - case AL: - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].xrepeat += 2; - sprite[j].yrepeat += 2; - if (sprite[j].yrepeat >= 38) - { - sprite[j].picnum = EVILAL; - //sprite[j].cstat |= 2; //Make him transluscent - changespritestat(j,10); - } - deletesprite((short)i); - goto bulletisdeletedskip; - default: - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - } - } - } - } + deletesprite((short)i); + goto bulletisdeletedskip; + case AL: + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].xrepeat += 2; + sprite[j].yrepeat += 2; + if (sprite[j].yrepeat >= 38) + { + sprite[j].picnum = EVILAL; + //sprite[j].cstat |= 2; //Make him transluscent + changespritestat(j,10); + } + deletesprite((short)i); + goto bulletisdeletedskip; + default: + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } + } + } + } + } bulletisdeletedskip: continue; - } + } - //Go through monster waiting for you list - for(i=headspritestat[2];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through monster waiting for you list + for(i=headspritestat[2];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - if ((nummoves-i)&15) continue; + if ((nummoves-i)&15) continue; - //Use dot product to see if monster's angle is towards a player - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (sintable[(sprite[i].ang+512)&2047]*(posx[p]-sprite[i].x) + sintable[sprite[i].ang&2047]*(posy[p]-sprite[i].y) >= 0) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[p],posy[p],posz[p],cursectnum[p]) == 1) - { - changespritestat(i,1); - //if (sprite[i].lotag == 100) - //{ - wsayfollow("iseeyou.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - // sprite[i].lotag = 99; - //} - } - } + //Use dot product to see if monster's angle is towards a player + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (sintable[(sprite[i].ang+512)&2047]*(posx[p]-sprite[i].x) + sintable[sprite[i].ang&2047]*(posy[p]-sprite[i].y) >= 0) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[p],posy[p],posz[p],cursectnum[p]) == 1) + { + changespritestat(i,1); + //if (sprite[i].lotag == 100) + //{ + wsayfollow("iseeyou.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + // sprite[i].lotag = 99; + //} + } + } - //Go through smoke sprites - for(i=headspritestat[3];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through smoke sprites + for(i=headspritestat[3];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].z -= (TICSPERFRAME<<6); - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) deletesprite(i); - } + sprite[i].z -= (TICSPERFRAME<<6); + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) deletesprite(i); + } - //Go through splash sprites - for(i=headspritestat[4];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through splash sprites + for(i=headspritestat[4];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].lotag -= TICSPERFRAME; - sprite[i].picnum = SPLASH + ((63-sprite[i].lotag)>>4); - if (sprite[i].lotag < 0) deletesprite(i); - } + sprite[i].lotag -= TICSPERFRAME; + sprite[i].picnum = SPLASH + ((63-sprite[i].lotag)>>4); + if (sprite[i].lotag < 0) deletesprite(i); + } - //Go through explosion sprites - for(i=headspritestat[5];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through explosion sprites + for(i=headspritestat[5];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) deletesprite(i); - } + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) deletesprite(i); + } - //Go through bomb spriral-explosion sprites - for(i=headspritestat[7];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Go through bomb spriral-explosion sprites + for(i=headspritestat[7];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].xrepeat = (sprite[i].lotag>>2); - sprite[i].yrepeat = (sprite[i].lotag>>2); - sprite[i].lotag -= (TICSPERFRAME<<2); - if (sprite[i].lotag < 0) { deletesprite(i); continue; } + sprite[i].xrepeat = (sprite[i].lotag>>2); + sprite[i].yrepeat = (sprite[i].lotag>>2); + sprite[i].lotag -= (TICSPERFRAME<<2); + if (sprite[i].lotag < 0) { deletesprite(i); continue; } - if ((nummoves-i)&statrate[7]) continue; + if ((nummoves-i)&statrate[7]) continue; - sprite[i].x += ((sprite[i].xvel*TICSPERFRAME)>>2); - sprite[i].y += ((sprite[i].yvel*TICSPERFRAME)>>2); - sprite[i].z += ((sprite[i].zvel*TICSPERFRAME)>>2); + sprite[i].x += ((sprite[i].xvel*TICSPERFRAME)>>2); + sprite[i].y += ((sprite[i].yvel*TICSPERFRAME)>>2); + sprite[i].z += ((sprite[i].zvel*TICSPERFRAME)>>2); - sprite[i].zvel += (TICSPERFRAME<<9); - if (sprite[i].z < sector[sprite[i].sectnum].ceilingz+(4<<8)) - { - sprite[i].z = sector[sprite[i].sectnum].ceilingz+(4<<8); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > sector[sprite[i].sectnum].floorz-(4<<8)) - { - sprite[i].z = sector[sprite[i].sectnum].floorz-(4<<8); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - } + sprite[i].zvel += (TICSPERFRAME<<9); + if (sprite[i].z < sector[sprite[i].sectnum].ceilingz+(4<<8)) + { + sprite[i].z = sector[sprite[i].sectnum].ceilingz+(4<<8); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > sector[sprite[i].sectnum].floorz-(4<<8)) + { + sprite[i].z = sector[sprite[i].sectnum].floorz-(4<<8); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + } - //EVILALGRAVE shrinking list - for(i=headspritestat[9];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //EVILALGRAVE shrinking list + for(i=headspritestat[9];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].xrepeat = (sprite[i].lotag>>2); - sprite[i].yrepeat = (sprite[i].lotag>>2); - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) { deletesprite(i); continue; } + sprite[i].xrepeat = (sprite[i].lotag>>2); + sprite[i].yrepeat = (sprite[i].lotag>>2); + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) { deletesprite(i); continue; } - if ((nummoves-i)&statrate[9]) continue; + if ((nummoves-i)&statrate[9]) continue; - sprite[i].x += (sprite[i].xvel*TICSPERFRAME); - sprite[i].y += (sprite[i].yvel*TICSPERFRAME); - sprite[i].z += (sprite[i].zvel*TICSPERFRAME); + sprite[i].x += (sprite[i].xvel*TICSPERFRAME); + sprite[i].y += (sprite[i].yvel*TICSPERFRAME); + sprite[i].z += (sprite[i].zvel*TICSPERFRAME); - sprite[i].zvel += (TICSPERFRAME<<8); - if (sprite[i].z < sector[sprite[i].sectnum].ceilingz) - { - sprite[i].z = sector[sprite[i].sectnum].ceilingz; - sprite[i].xvel -= (sprite[i].xvel>>2); - sprite[i].yvel -= (sprite[i].yvel>>2); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > sector[sprite[i].sectnum].floorz) - { - sprite[i].z = sector[sprite[i].sectnum].floorz; - sprite[i].xvel -= (sprite[i].xvel>>2); - sprite[i].yvel -= (sprite[i].yvel>>2); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - } + sprite[i].zvel += (TICSPERFRAME<<8); + if (sprite[i].z < sector[sprite[i].sectnum].ceilingz) + { + sprite[i].z = sector[sprite[i].sectnum].ceilingz; + sprite[i].xvel -= (sprite[i].xvel>>2); + sprite[i].yvel -= (sprite[i].yvel>>2); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > sector[sprite[i].sectnum].floorz) + { + sprite[i].z = sector[sprite[i].sectnum].floorz; + sprite[i].xvel -= (sprite[i].xvel>>2); + sprite[i].yvel -= (sprite[i].yvel>>2); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + } - //Re-spawning sprite list - for(i=headspritestat[11];i>=0;i=nexti) - { - nexti = nextspritestat[i]; + //Re-spawning sprite list + for(i=headspritestat[11];i>=0;i=nexti) + { + nexti = nextspritestat[i]; - sprite[i].extra -= TICSPERFRAME; - if (sprite[i].extra < 0) - { - wsayfollow("warp.wav",6144L+(krand()&127)-64,128L,&sprite[i].x,&sprite[i].y,0); - sprite[i].cstat &= ~0x8000; - sprite[i].extra = -1; - changespritestat((short)i,0); - } - } + sprite[i].extra -= TICSPERFRAME; + if (sprite[i].extra < 0) + { + wsayfollow("warp.wav",6144L+(krand()&127)-64,128L,&sprite[i].x,&sprite[i].y,0); + sprite[i].cstat &= ~0x8000; + sprite[i].extra = -1; + changespritestat((short)i,0); + } + } } void activatehitag(short dahitag) { - long i, nexti; + long i, nexti; - for(i=0;i=0;i=nexti) - { - nexti = nextspritestat[i]; - if (sprite[i].hitag == dahitag) operatesprite(i); - } + for(i=headspritestat[0];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + if (sprite[i].hitag == dahitag) operatesprite(i); + } } void bombexplode(long i) { - long j, nextj, k, daang, dax, day, dist; + long j, nextj, k, daang, dax, day, dist; - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,0,-4,0, - 32,64,64,0,0,EXPLOSION,sprite[i].ang, - 0,0,0,sprite[i].owner,sprite[i].sectnum,5,31,0,0); - //31=Time left for explosion to stay + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,0,-4,0, + 32,64,64,0,0,EXPLOSION,sprite[i].ang, + 0,0,0,sprite[i].owner,sprite[i].sectnum,5,31,0,0); + //31=Time left for explosion to stay - for(k=0;k<12;k++) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, - 32,24,24,0,0,EXPLOSION,sprite[i].ang, - (krand()>>7)-256,(krand()>>7)-256,(krand()>>2)-8192, - sprite[i].owner,sprite[i].sectnum,7,96,0,0); - //96=Time left for smoke to be alive - } + for(k=0;k<12;k++) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, + 32,24,24,0,0,EXPLOSION,sprite[i].ang, + (krand()>>7)-256,(krand()>>7)-256,(krand()>>2)-8192, + sprite[i].owner,sprite[i].sectnum,7,96,0,0); + //96=Time left for smoke to be alive + } - for(j=connecthead;j>=0;j=connectpoint2[j]) - { - dist = (posx[j]-sprite[i].x)*(posx[j]-sprite[i].x); - dist += (posy[j]-sprite[i].y)*(posy[j]-sprite[i].y); - dist += ((posz[j]-sprite[i].z)>>4)*((posz[j]-sprite[i].z)>>4); - if (dist < 4194304) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j]) == 1) - { - k = ((32768/((dist>>16)+4))>>5); - if (j == myconnectindex) - { - daang = getangle(posx[j]-sprite[i].x,posy[j]-sprite[i].y); - dax = ((k*sintable[(daang+512)&2047])>>14); - day = ((k*sintable[daang&2047])>>14); - fvel += ((dax*sintable[(ang[j]+512)&2047]+day*sintable[ang[j]&2047])>>14); - svel += ((day*sintable[(ang[j]+512)&2047]-dax*sintable[ang[j]&2047])>>14); - } - changehealth(j,-k); //if changehealth returns 1, you're dead - } - } + for(j=connecthead;j>=0;j=connectpoint2[j]) + { + dist = (posx[j]-sprite[i].x)*(posx[j]-sprite[i].x); + dist += (posy[j]-sprite[i].y)*(posy[j]-sprite[i].y); + dist += ((posz[j]-sprite[i].z)>>4)*((posz[j]-sprite[i].z)>>4); + if (dist < 4194304) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j]) == 1) + { + k = ((32768/((dist>>16)+4))>>5); + if (j == myconnectindex) + { + daang = getangle(posx[j]-sprite[i].x,posy[j]-sprite[i].y); + dax = ((k*sintable[(daang+512)&2047])>>14); + day = ((k*sintable[daang&2047])>>14); + fvel += ((dax*sintable[(ang[j]+512)&2047]+day*sintable[ang[j]&2047])>>14); + svel += ((day*sintable[(ang[j]+512)&2047]-dax*sintable[ang[j]&2047])>>14); + } + changehealth(j,-k); //if changehealth returns 1, you're dead + } + } - for(k=1;k<=2;k++) //Check for hurting monsters - { - for(j=headspritestat[k];j>=0;j=nextj) - { - nextj = nextspritestat[j]; + for(k=1;k<=2;k++) //Check for hurting monsters + { + for(j=headspritestat[k];j>=0;j=nextj) + { + nextj = nextspritestat[j]; - dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); - dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); - dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); - if (dist >= 4194304) continue; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) - continue; - if (sprite[j].picnum == BROWNMONSTER) - { - sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); - sprite[j].picnum = GIFTBOX; - sprite[j].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(j,12); - } - } - } + dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); + dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); + dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); + if (dist >= 4194304) continue; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) + continue; + if (sprite[j].picnum == BROWNMONSTER) + { + sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); + sprite[j].picnum = GIFTBOX; + sprite[j].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(j,12); + } + } + } - for(j=headspritestat[10];j>=0;j=nextj) //Check for EVILAL's - { - nextj = nextspritestat[j]; + for(j=headspritestat[10];j>=0;j=nextj) //Check for EVILAL's + { + nextj = nextspritestat[j]; - dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); - dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); - dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); - if (dist >= 4194304) continue; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) - continue; + dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); + dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); + dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); + if (dist >= 4194304) continue; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) + continue; - sprite[j].picnum = EVILALGRAVE; - sprite[j].cstat = 0; - sprite[j].xvel = (krand()&255)-128; - sprite[j].yvel = (krand()&255)-128; - sprite[j].zvel = (krand()&4095)-3072; - changespritestat(j,9); - } + sprite[j].picnum = EVILALGRAVE; + sprite[j].cstat = 0; + sprite[j].xvel = (krand()&255)-128; + sprite[j].yvel = (krand()&255)-128; + sprite[j].zvel = (krand()&4095)-3072; + changespritestat(j,9); + } - wsayfollow("blowup.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); + wsayfollow("blowup.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); } void processinput(short snum) { - long oldposx, oldposy, nexti; - long i, j, k, doubvel, xvect, yvect, goalz; - long dax, day, dax2, day2, odax, oday, odax2, oday2; - short startwall, endwall; - char *ptr; + long oldposx, oldposy, nexti; + long i, j, k, doubvel, xvect, yvect, goalz; + long dax, day, dax2, day2, odax, oday, odax2, oday2; + short startwall, endwall; + char *ptr; - //SHARED KEYS: - //Movement code - if ((ssync[snum].fvel|ssync[snum].svel) != 0) - { - doubvel = (TICSPERFRAME<<((ssync[snum].bits&256)>0)); + //SHARED KEYS: + //Movement code + if ((ssync[snum].fvel|ssync[snum].svel) != 0) + { + doubvel = (TICSPERFRAME<<((ssync[snum].bits&256)>0)); - xvect = 0, yvect = 0; - if (ssync[snum].fvel != 0) - { - xvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[(ang[snum]+512)&2047])>>3); - yvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[ang[snum]&2047])>>3); - } - if (ssync[snum].svel != 0) - { - xvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[ang[snum]&2047])>>3); - yvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[(ang[snum]+1536)&2047])>>3); - } - if (flytime[snum] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed - clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); - revolvedoorstat[snum] = 1; - } - else - { - revolvedoorstat[snum] = 0; - } + xvect = 0, yvect = 0; + if (ssync[snum].fvel != 0) + { + xvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[(ang[snum]+512)&2047])>>3); + yvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[ang[snum]&2047])>>3); + } + if (ssync[snum].svel != 0) + { + xvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[ang[snum]&2047])>>3); + yvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[(ang[snum]+1536)&2047])>>3); + } + if (flytime[snum] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed + clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); + revolvedoorstat[snum] = 1; + } + else + { + revolvedoorstat[snum] = 0; + } - sprite[playersprite[snum]].cstat &= ~1; - //Push player away from walls if clipmove doesn't work - if (pushmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],128L,4<<8,4<<8,CLIPMASK0) < 0) - changehealth(snum,-1000); //If this screws up, then instant death!!! + sprite[playersprite[snum]].cstat &= ~1; + //Push player away from walls if clipmove doesn't work + if (pushmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],128L,4<<8,4<<8,CLIPMASK0) < 0) + changehealth(snum,-1000); //If this screws up, then instant death!!! - // Getzrange returns the highest and lowest z's for an entire box, - // NOT just a point. This prevents you from falling off cliffs - // when you step only slightly over the cliff. - getzrange(posx[snum],posy[snum],posz[snum],cursectnum[snum],&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); - sprite[playersprite[snum]].cstat |= 1; + // Getzrange returns the highest and lowest z's for an entire box, + // NOT just a point. This prevents you from falling off cliffs + // when you step only slightly over the cliff. + getzrange(posx[snum],posy[snum],posz[snum],cursectnum[snum],&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); + sprite[playersprite[snum]].cstat |= 1; - if (ssync[snum].avel != 0) //ang += avel * constant - { //ENGINE calculates avel for you - doubvel = TICSPERFRAME; - if ((ssync[snum].bits&256) > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (TICSPERFRAME>>1); - ang[snum] += ((((long)ssync[snum].avel)*doubvel)>>4); - ang[snum] &= 2047; - } + if (ssync[snum].avel != 0) //ang += avel * constant + { //ENGINE calculates avel for you + doubvel = TICSPERFRAME; + if ((ssync[snum].bits&256) > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (TICSPERFRAME>>1); + ang[snum] += ((((long)ssync[snum].avel)*doubvel)>>4); + ang[snum] &= 2047; + } - if (health[snum] < 0) - { - health[snum] -= TICSPERFRAME; - if (health[snum] <= -160) - { - hvel[snum] = 0; - if (snum == myconnectindex) - fvel = 0, svel = 0, avel = 0, keystatus[3] = 1; + if (health[snum] < 0) + { + health[snum] -= TICSPERFRAME; + if (health[snum] <= -160) + { + hvel[snum] = 0; + if (snum == myconnectindex) + fvel = 0, svel = 0, avel = 0, keystatus[3] = 1; - deaths[snum]++; - health[snum] = 100; - numbombs[snum] = 0; - numgrabbers[snum] = 0; - nummissiles[snum] = 0; - flytime[snum] = 0; + deaths[snum]++; + health[snum] = 100; + numbombs[snum] = 0; + numgrabbers[snum] = 0; + nummissiles[snum] = 0; + flytime[snum] = 0; - findrandomspot(&posx[snum],&posy[snum],&cursectnum[snum]); - posz[snum] = getflorzofslope(cursectnum[snum],posx[snum],posy[snum])-(1<<8); - horiz[snum] = 100; - ang[snum] = (krand()&2047); + findrandomspot(&posx[snum],&posy[snum],&cursectnum[snum]); + posz[snum] = getflorzofslope(cursectnum[snum],posx[snum],posy[snum])-(1<<8); + horiz[snum] = 100; + ang[snum] = (krand()&2047); - sprite[playersprite[snum]].x = posx[snum]; - sprite[playersprite[snum]].y = posy[snum]; - sprite[playersprite[snum]].z = posz[snum]+EYEHEIGHT; - sprite[playersprite[snum]].picnum = PLAYER; - sprite[playersprite[snum]].ang = ang[snum]; - sprite[playersprite[snum]].xrepeat = 64; - sprite[playersprite[snum]].yrepeat = 64; - changespritesect(playersprite[snum],cursectnum[snum]); + sprite[playersprite[snum]].x = posx[snum]; + sprite[playersprite[snum]].y = posy[snum]; + sprite[playersprite[snum]].z = posz[snum]+EYEHEIGHT; + sprite[playersprite[snum]].picnum = PLAYER; + sprite[playersprite[snum]].ang = ang[snum]; + sprite[playersprite[snum]].xrepeat = 64; + sprite[playersprite[snum]].yrepeat = 64; + changespritesect(playersprite[snum],cursectnum[snum]); - drawstatusbar(snum); // Andy did this + drawstatusbar(snum); // Andy did this - i = playersprite[snum]; - wsayfollow("zipguns.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - for(k=0;k<16;k++) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, - 32,24,24,0,0,EXPLOSION,sprite[i].ang, - (krand()&511)-256,(krand()&511)-256,(krand()&16384)-8192, - sprite[i].owner,sprite[i].sectnum,7,96,0,0); - //96=Time left for smoke to be alive - } - } - else - { - sprite[playersprite[snum]].xrepeat = max(((128+health[snum])>>1),0); - sprite[playersprite[snum]].yrepeat = max(((128+health[snum])>>1),0); + i = playersprite[snum]; + wsayfollow("zipguns.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + for(k=0;k<16;k++) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, + 32,24,24,0,0,EXPLOSION,sprite[i].ang, + (krand()&511)-256,(krand()&511)-256,(krand()&16384)-8192, + sprite[i].owner,sprite[i].sectnum,7,96,0,0); + //96=Time left for smoke to be alive + } + } + else + { + sprite[playersprite[snum]].xrepeat = max(((128+health[snum])>>1),0); + sprite[playersprite[snum]].yrepeat = max(((128+health[snum])>>1),0); - hvel[snum] += (TICSPERFRAME<<2); - horiz[snum] = max(horiz[snum]-4,0); - posz[snum] += hvel[snum]; - if (posz[snum] > globloz-(4<<8)) - { - posz[snum] = globloz-(4<<8); - horiz[snum] = min(horiz[snum]+5,200); - hvel[snum] = 0; - } - } - } + hvel[snum] += (TICSPERFRAME<<2); + horiz[snum] = max(horiz[snum]-4,0); + posz[snum] += hvel[snum]; + if (posz[snum] > globloz-(4<<8)) + { + posz[snum] = globloz-(4<<8); + horiz[snum] = min(horiz[snum]+5,200); + hvel[snum] = 0; + } + } + } - if (((ssync[snum].bits&8) > 0) && (horiz[snum] > 100-(200>>1))) horiz[snum] -= 4; //- - if (((ssync[snum].bits&4) > 0) && (horiz[snum] < 100+(200>>1))) horiz[snum] += 4; //+ + if (((ssync[snum].bits&8) > 0) && (horiz[snum] > 100-(200>>1))) horiz[snum] -= 4; //- + if (((ssync[snum].bits&4) > 0) && (horiz[snum] < 100+(200>>1))) horiz[snum] += 4; //+ - goalz = globloz-EYEHEIGHT; - if (sector[cursectnum[snum]].lotag == 4) //slime sector - if ((globlohit&0xc000) != 49152) //You're not on a sprite - { - goalz = globloz-(8<<8); - if (posz[snum] >= goalz-(2<<8)) - { - clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); + goalz = globloz-EYEHEIGHT; + if (sector[cursectnum[snum]].lotag == 4) //slime sector + if ((globlohit&0xc000) != 49152) //You're not on a sprite + { + goalz = globloz-(8<<8); + if (posz[snum] >= goalz-(2<<8)) + { + clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); - if (slimesoundcnt[snum] >= 0) - { - slimesoundcnt[snum] -= TICSPERFRAME; - while (slimesoundcnt[snum] < 0) - { - slimesoundcnt[snum] += 120; - wsayfollow("slime.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - } - } - } - } - if (goalz < globhiz+(16<<8)) //ceiling&floor too close - goalz = ((globloz+globhiz)>>1); - //goalz += mousz; - if (health[snum] >= 0) - { - if ((ssync[snum].bits&1) > 0) //A (stand high) - { - if (flytime[snum] <= lockclock) - { - if (posz[snum] >= globloz-(32<<8)) - { - goalz -= (16<<8); - if (ssync[snum].bits&256) goalz -= (24<<8); - } - } - else - { - hvel[snum] -= 192; - if (ssync[snum].bits&256) hvel[snum] -= 192; - } - } - if ((ssync[snum].bits&2) > 0) //Z (stand low) - { - if (flytime[snum] <= lockclock) - { - goalz += (12<<8); - if (ssync[snum].bits&256) goalz += (12<<8); - } - else - { - hvel[snum] += 192; - if (ssync[snum].bits&256) hvel[snum] += 192; - } - } - } + if (slimesoundcnt[snum] >= 0) + { + slimesoundcnt[snum] -= TICSPERFRAME; + while (slimesoundcnt[snum] < 0) + { + slimesoundcnt[snum] += 120; + wsayfollow("slime.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + } + } + } + } + if (goalz < globhiz+(16<<8)) //ceiling&floor too close + goalz = ((globloz+globhiz)>>1); + //goalz += mousz; + if (health[snum] >= 0) + { + if ((ssync[snum].bits&1) > 0) //A (stand high) + { + if (flytime[snum] <= lockclock) + { + if (posz[snum] >= globloz-(32<<8)) + { + goalz -= (16<<8); + if (ssync[snum].bits&256) goalz -= (24<<8); + } + } + else + { + hvel[snum] -= 192; + if (ssync[snum].bits&256) hvel[snum] -= 192; + } + } + if ((ssync[snum].bits&2) > 0) //Z (stand low) + { + if (flytime[snum] <= lockclock) + { + goalz += (12<<8); + if (ssync[snum].bits&256) goalz += (12<<8); + } + else + { + hvel[snum] += 192; + if (ssync[snum].bits&256) hvel[snum] += 192; + } + } + } - if (flytime[snum] <= lockclock) - { - if (posz[snum] < goalz) - hvel[snum] += (TICSPERFRAME<<4); - else - hvel[snum] = (((goalz-posz[snum])*TICSPERFRAME)>>5); - } - else - { - hvel[snum] -= (hvel[snum]>>2); - hvel[snum] -= ksgn(hvel[snum]); - } + if (flytime[snum] <= lockclock) + { + if (posz[snum] < goalz) + hvel[snum] += (TICSPERFRAME<<4); + else + hvel[snum] = (((goalz-posz[snum])*TICSPERFRAME)>>5); + } + else + { + hvel[snum] -= (hvel[snum]>>2); + hvel[snum] -= ksgn(hvel[snum]); + } - posz[snum] += hvel[snum]; - if (posz[snum] > globloz-(4<<8)) posz[snum] = globloz-(4<<8), hvel[snum] = 0; - if (posz[snum] < globhiz+(4<<8)) posz[snum] = globhiz+(4<<8), hvel[snum] = 0; + posz[snum] += hvel[snum]; + if (posz[snum] > globloz-(4<<8)) posz[snum] = globloz-(4<<8), hvel[snum] = 0; + if (posz[snum] < globhiz+(4<<8)) posz[snum] = globhiz+(4<<8), hvel[snum] = 0; - if (dimensionmode[snum] != 3) - { - if (((ssync[snum].bits&32) > 0) && (zoom[snum] > 48)) zoom[snum] -= (zoom[snum]>>4); - if (((ssync[snum].bits&16) > 0) && (zoom[snum] < 4096)) zoom[snum] += (zoom[snum]>>4); - } + if (dimensionmode[snum] != 3) + { + if (((ssync[snum].bits&32) > 0) && (zoom[snum] > 48)) zoom[snum] -= (zoom[snum]>>4); + if (((ssync[snum].bits&16) > 0) && (zoom[snum] < 4096)) zoom[snum] += (zoom[snum]>>4); + } - //Update sprite representation of player - // -should be after movement, but before shooting code - setsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT); - sprite[playersprite[snum]].ang = ang[snum]; + //Update sprite representation of player + // -should be after movement, but before shooting code + setsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT); + sprite[playersprite[snum]].ang = ang[snum]; - if (health[snum] >= 0) - { - if ((cursectnum[snum] < 0) || (cursectnum[snum] >= numsectors)) - { //How did you get in the wrong sector? - wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); - changehealth(snum,-TICSPERFRAME); - } - else if (globhiz+(8<<8) > globloz) - { //Ceiling and floor are smooshing you! - wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); - changehealth(snum,-TICSPERFRAME); - } - } + if (health[snum] >= 0) + { + if ((cursectnum[snum] < 0) || (cursectnum[snum] >= numsectors)) + { //How did you get in the wrong sector? + wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); + changehealth(snum,-TICSPERFRAME); + } + else if (globhiz+(8<<8) > globloz) + { //Ceiling and floor are smooshing you! + wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); + changehealth(snum,-TICSPERFRAME); + } + } - if ((waterfountainwall[snum] >= 0) && (health[snum] >= 0)) - if ((wall[neartagwall].lotag != 7) || ((ssync[snum].bits&1024) == 0)) - { - i = waterfountainwall[snum]; - if (wall[i].overpicnum == USEWATERFOUNTAIN) - wall[i].overpicnum = WATERFOUNTAIN; - else if (wall[i].picnum == USEWATERFOUNTAIN) - wall[i].picnum = WATERFOUNTAIN; + if ((waterfountainwall[snum] >= 0) && (health[snum] >= 0)) + if ((wall[neartagwall].lotag != 7) || ((ssync[snum].bits&1024) == 0)) + { + i = waterfountainwall[snum]; + if (wall[i].overpicnum == USEWATERFOUNTAIN) + wall[i].overpicnum = WATERFOUNTAIN; + else if (wall[i].picnum == USEWATERFOUNTAIN) + wall[i].picnum = WATERFOUNTAIN; - waterfountainwall[snum] = -1; - } + waterfountainwall[snum] = -1; + } - if ((ssync[snum].bits&1024) > 0) //Space bar - { - //Continuous triggers... + if ((ssync[snum].bits&1024) > 0) //Space bar + { + //Continuous triggers... - neartag(posx[snum],posy[snum],posz[snum],cursectnum[snum],ang[snum],&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,1024L,3); - if (neartagsector == -1) - { - i = cursectnum[snum]; - if ((sector[i].lotag|sector[i].hitag) != 0) - neartagsector = i; - } + neartag(posx[snum],posy[snum],posz[snum],cursectnum[snum],ang[snum],&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,1024L,3); + if (neartagsector == -1) + { + i = cursectnum[snum]; + if ((sector[i].lotag|sector[i].hitag) != 0) + neartagsector = i; + } - if (wall[neartagwall].lotag == 7) //Water fountain - { - if (wall[neartagwall].overpicnum == WATERFOUNTAIN) - { - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - wall[neartagwall].overpicnum = USEWATERFOUNTAIN; - waterfountainwall[snum] = neartagwall; - } - else if (wall[neartagwall].picnum == WATERFOUNTAIN) - { - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - wall[neartagwall].picnum = USEWATERFOUNTAIN; - waterfountainwall[snum] = neartagwall; - } + if (wall[neartagwall].lotag == 7) //Water fountain + { + if (wall[neartagwall].overpicnum == WATERFOUNTAIN) + { + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + wall[neartagwall].overpicnum = USEWATERFOUNTAIN; + waterfountainwall[snum] = neartagwall; + } + else if (wall[neartagwall].picnum == WATERFOUNTAIN) + { + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + wall[neartagwall].picnum = USEWATERFOUNTAIN; + waterfountainwall[snum] = neartagwall; + } - if (waterfountainwall[snum] >= 0) - { - waterfountaincnt[snum] -= TICSPERFRAME; - while (waterfountaincnt[snum] < 0) - { - waterfountaincnt[snum] += 120; - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - changehealth(snum,2); - } - } - } + if (waterfountainwall[snum] >= 0) + { + waterfountaincnt[snum] -= TICSPERFRAME; + while (waterfountaincnt[snum] < 0) + { + waterfountaincnt[snum] += 120; + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + changehealth(snum,2); + } + } + } - //1-time triggers... - if ((oflags[snum]&1024) == 0) - { - if (neartagsector >= 0) - if (sector[neartagsector].hitag == 0) - operatesector(neartagsector); + //1-time triggers... + if ((oflags[snum]&1024) == 0) + { + if (neartagsector >= 0) + if (sector[neartagsector].hitag == 0) + operatesector(neartagsector); - if (neartagwall >= 0) - if (wall[neartagwall].lotag == 2) //Switch - { - activatehitag(wall[neartagwall].hitag); + if (neartagwall >= 0) + if (wall[neartagwall].lotag == 2) //Switch + { + activatehitag(wall[neartagwall].hitag); - j = wall[neartagwall].overpicnum; - if (j == SWITCH1ON) //1-time switch - { - wall[neartagwall].overpicnum = GIFTBOX; - wall[neartagwall].lotag = 0; - wall[neartagwall].hitag = 0; - } - if (j == GIFTBOX) //1-time switch - { - wall[neartagwall].overpicnum = SWITCH1ON; - wall[neartagwall].lotag = 0; - wall[neartagwall].hitag = 0; - } - if (j == SWITCH2ON) wall[neartagwall].overpicnum = SWITCH2OFF; - if (j == SWITCH2OFF) wall[neartagwall].overpicnum = SWITCH2ON; - if (j == SWITCH3ON) wall[neartagwall].overpicnum = SWITCH3OFF; - if (j == SWITCH3OFF) wall[neartagwall].overpicnum = SWITCH3ON; + j = wall[neartagwall].overpicnum; + if (j == SWITCH1ON) //1-time switch + { + wall[neartagwall].overpicnum = GIFTBOX; + wall[neartagwall].lotag = 0; + wall[neartagwall].hitag = 0; + } + if (j == GIFTBOX) //1-time switch + { + wall[neartagwall].overpicnum = SWITCH1ON; + wall[neartagwall].lotag = 0; + wall[neartagwall].hitag = 0; + } + if (j == SWITCH2ON) wall[neartagwall].overpicnum = SWITCH2OFF; + if (j == SWITCH2OFF) wall[neartagwall].overpicnum = SWITCH2ON; + if (j == SWITCH3ON) wall[neartagwall].overpicnum = SWITCH3OFF; + if (j == SWITCH3OFF) wall[neartagwall].overpicnum = SWITCH3ON; - i = wall[neartagwall].point2; - dax = ((wall[neartagwall].x+wall[i].x)>>1); - day = ((wall[neartagwall].y+wall[i].y)>>1); - wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); - } + i = wall[neartagwall].point2; + dax = ((wall[neartagwall].x+wall[i].x)>>1); + day = ((wall[neartagwall].y+wall[i].y)>>1); + wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); + } - if (neartagsprite >= 0) - { - if (sprite[neartagsprite].lotag == 1) - { //if you're shoving innocent little AL around, he gets mad! - if (sprite[neartagsprite].picnum == AL) - { - sprite[neartagsprite].picnum = EVILAL; - sprite[neartagsprite].cstat |= 2; //Make him transluscent - sprite[neartagsprite].xrepeat = 38; - sprite[neartagsprite].yrepeat = 38; - changespritestat(neartagsprite,10); - } - } - if (sprite[neartagsprite].lotag == 4) - { - activatehitag(sprite[neartagsprite].hitag); + if (neartagsprite >= 0) + { + if (sprite[neartagsprite].lotag == 1) + { //if you're shoving innocent little AL around, he gets mad! + if (sprite[neartagsprite].picnum == AL) + { + sprite[neartagsprite].picnum = EVILAL; + sprite[neartagsprite].cstat |= 2; //Make him transluscent + sprite[neartagsprite].xrepeat = 38; + sprite[neartagsprite].yrepeat = 38; + changespritestat(neartagsprite,10); + } + } + if (sprite[neartagsprite].lotag == 4) + { + activatehitag(sprite[neartagsprite].hitag); - j = sprite[neartagsprite].picnum; - if (j == SWITCH1ON) //1-time switch - { - sprite[neartagsprite].picnum = GIFTBOX; - sprite[neartagsprite].lotag = 0; - sprite[neartagsprite].hitag = 0; - } - if (j == GIFTBOX) //1-time switch - { - sprite[neartagsprite].picnum = SWITCH1ON; - sprite[neartagsprite].lotag = 0; - sprite[neartagsprite].hitag = 0; - } - if (j == SWITCH2ON) sprite[neartagsprite].picnum = SWITCH2OFF; - if (j == SWITCH2OFF) sprite[neartagsprite].picnum = SWITCH2ON; - if (j == SWITCH3ON) sprite[neartagsprite].picnum = SWITCH3OFF; - if (j == SWITCH3OFF) sprite[neartagsprite].picnum = SWITCH3ON; + j = sprite[neartagsprite].picnum; + if (j == SWITCH1ON) //1-time switch + { + sprite[neartagsprite].picnum = GIFTBOX; + sprite[neartagsprite].lotag = 0; + sprite[neartagsprite].hitag = 0; + } + if (j == GIFTBOX) //1-time switch + { + sprite[neartagsprite].picnum = SWITCH1ON; + sprite[neartagsprite].lotag = 0; + sprite[neartagsprite].hitag = 0; + } + if (j == SWITCH2ON) sprite[neartagsprite].picnum = SWITCH2OFF; + if (j == SWITCH2OFF) sprite[neartagsprite].picnum = SWITCH2ON; + if (j == SWITCH3ON) sprite[neartagsprite].picnum = SWITCH3OFF; + if (j == SWITCH3OFF) sprite[neartagsprite].picnum = SWITCH3ON; - dax = sprite[neartagsprite].x; - day = sprite[neartagsprite].y; - wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); - } - } - } - } + dax = sprite[neartagsprite].x; + day = sprite[neartagsprite].y; + wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); + } + } + } + } - if ((ssync[snum].bits & 2048) > 0) { // Shoot a bullet - if ((numbombs[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 2) && (myconnectindex == snum)) - locselectedgun = 0; - if ((nummissiles[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 3) && (myconnectindex == snum)) - locselectedgun = 1; - if ((numgrabbers[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 4) && (myconnectindex == snum)) - locselectedgun = 1; + if ((ssync[snum].bits & 2048) > 0) { // Shoot a bullet + if ((numbombs[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 2) && (myconnectindex == snum)) + locselectedgun = 0; + if ((nummissiles[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 3) && (myconnectindex == snum)) + locselectedgun = 1; + if ((numgrabbers[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 4) && (myconnectindex == snum)) + locselectedgun = 1; - if ((health[snum] >= 0) || ((krand() & 127) > -health[snum])) - switch((ssync[snum].bits >> 13) & 7) { - case 0: - if (lockclock > lastchaingun[snum]+8) { - lastchaingun[snum] = lockclock; - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],0); - } - break; - case 1: - if ((oflags[snum] & 2048) == 0) - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],1); - break; - case 2: - if ((oflags[snum] & 2048) == 0) - if (numbombs[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],2); - changenumbombs(snum,-1); - } - break; - case 3: - if ((oflags[snum] & 2048) == 0) - if (nummissiles[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],3); - changenummissiles(snum,-1); - } - break; - case 4: - if ((oflags[snum] & 2048) == 0) - if (numgrabbers[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],4); - changenumgrabbers(snum,-1); - } - break; - } - } + if ((health[snum] >= 0) || ((krand() & 127) > -health[snum])) + switch((ssync[snum].bits >> 13) & 7) { + case 0: + if (lockclock > lastchaingun[snum]+8) { + lastchaingun[snum] = lockclock; + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],0); + } + break; + case 1: + if ((oflags[snum] & 2048) == 0) + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],1); + break; + case 2: + if ((oflags[snum] & 2048) == 0) + if (numbombs[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],2); + changenumbombs(snum,-1); + } + break; + case 3: + if ((oflags[snum] & 2048) == 0) + if (nummissiles[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],3); + changenummissiles(snum,-1); + } + break; + case 4: + if ((oflags[snum] & 2048) == 0) + if (numgrabbers[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],4); + changenumgrabbers(snum,-1); + } + break; + } + } - if ((ssync[snum].bits&4096) > (oflags[snum]&4096)) //Keypad enter - { - dimensionmode[snum]++; - if (dimensionmode[snum] > 3) dimensionmode[snum] = 1; - } + if ((ssync[snum].bits&4096) > (oflags[snum]&4096)) //Keypad enter + { + dimensionmode[snum]++; + if (dimensionmode[snum] > 3) dimensionmode[snum] = 1; + } - oflags[snum] = ssync[snum].bits; + oflags[snum] = ssync[snum].bits; } void view(short snum, long *vx, long *vy, long *vz, short *vsectnum, short ang, long horiz) { - spritetype *sp; - long i, nx, ny, nz, hx, hy, hz, hitx, hity, hitz; - short bakcstat, hitsect, hitwall, hitsprite, daang; + spritetype *sp; + long i, nx, ny, nz, hx, hy, hz, hitx, hity, hitz; + short bakcstat, hitsect, hitwall, hitsprite, daang; - nx = (sintable[(ang+1536)&2047]>>4); - ny = (sintable[(ang+1024)&2047]>>4); - nz = (horiz-100)*128; + nx = (sintable[(ang+1536)&2047]>>4); + ny = (sintable[(ang+1024)&2047]>>4); + nz = (horiz-100)*128; - sp = &sprite[snum]; + sp = &sprite[snum]; - bakcstat = sp->cstat; - sp->cstat &= (short)~0x101; + bakcstat = sp->cstat; + sp->cstat &= (short)~0x101; - updatesectorz(*vx,*vy,*vz,vsectnum); - hitscan(*vx,*vy,*vz,*vsectnum,nx,ny,nz,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - hx = hitx-(*vx); hy = hity-(*vy); - if (klabs(nx)+klabs(ny) > klabs(hx)+klabs(hy)) - { - *vsectnum = hitsect; - if (hitwall >= 0) - { - daang = getangle(wall[wall[hitwall].point2].x-wall[hitwall].x, - wall[wall[hitwall].point2].y-wall[hitwall].y); + updatesectorz(*vx,*vy,*vz,vsectnum); + hitscan(*vx,*vy,*vz,*vsectnum,nx,ny,nz,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + hx = hitx-(*vx); hy = hity-(*vy); + if (klabs(nx)+klabs(ny) > klabs(hx)+klabs(hy)) + { + *vsectnum = hitsect; + if (hitwall >= 0) + { + daang = getangle(wall[wall[hitwall].point2].x-wall[hitwall].x, + wall[wall[hitwall].point2].y-wall[hitwall].y); - i = nx*sintable[daang]+ny*sintable[(daang+1536)&2047]; - if (klabs(nx) > klabs(ny)) hx -= mulscale28(nx,i); - else hy -= mulscale28(ny,i); - } - else if (hitsprite < 0) - { - if (klabs(nx) > klabs(ny)) hx -= (nx>>5); - else hy -= (ny>>5); - } - if (klabs(nx) > klabs(ny)) i = divscale16(hx,nx); - else i = divscale16(hy,ny); - if (i < cameradist) cameradist = i; - } - *vx = (*vx)+mulscale16(nx,cameradist); - *vy = (*vy)+mulscale16(ny,cameradist); - *vz = (*vz)+mulscale16(nz,cameradist); + i = nx*sintable[daang]+ny*sintable[(daang+1536)&2047]; + if (klabs(nx) > klabs(ny)) hx -= mulscale28(nx,i); + else hy -= mulscale28(ny,i); + } + else if (hitsprite < 0) + { + if (klabs(nx) > klabs(ny)) hx -= (nx>>5); + else hy -= (ny>>5); + } + if (klabs(nx) > klabs(ny)) i = divscale16(hx,nx); + else i = divscale16(hy,ny); + if (i < cameradist) cameradist = i; + } + *vx = (*vx)+mulscale16(nx,cameradist); + *vy = (*vy)+mulscale16(ny,cameradist); + *vz = (*vz)+mulscale16(nz,cameradist); - updatesectorz(*vx,*vy,*vz,vsectnum); + updatesectorz(*vx,*vy,*vz,vsectnum); - sp->cstat = bakcstat; + sp->cstat = bakcstat; } #if 0 // JBF: now in the engine void updatesectorz(long x, long y, long z, short *sectnum) { - walltype *wal; - long i, j, cz, fz; + walltype *wal; + long i, j, cz, fz; - getzsofslope(*sectnum,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,*sectnum) != 0) return; + getzsofslope(*sectnum,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,*sectnum) != 0) return; - if ((*sectnum >= 0) && (*sectnum < numsectors)) - { - wal = &wall[sector[*sectnum].wallptr]; - j = sector[*sectnum].wallnum; - do - { - i = wal->nextsector; - if (i >= 0) - { - getzsofslope(i,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } - } - wal++; j--; - } while (j != 0); - } + if ((*sectnum >= 0) && (*sectnum < numsectors)) + { + wal = &wall[sector[*sectnum].wallptr]; + j = sector[*sectnum].wallnum; + do + { + i = wal->nextsector; + if (i >= 0) + { + getzsofslope(i,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,(short)i) == 1) + { *sectnum = i; return; } + } + wal++; j--; + } while (j != 0); + } - for(i=numsectors-1;i>=0;i--) - { - getzsofslope(i,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } - } + for(i=numsectors-1;i>=0;i--) + { + getzsofslope(i,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,(short)i) == 1) + { *sectnum = i; return; } + } - *sectnum = -1; + *sectnum = -1; } #endif void drawscreen(short snum, long dasmoothratio) { - long i, j, k=0, l, charsperline, tempint; - long x1, y1, x2, y2, ox1, oy1, ox2, oy2, dist, maxdist; - long cposx, cposy, cposz, choriz, czoom, tposx, tposy; - long tiltlock, *intptr, ovisibility, oparallaxvisibility; - short cang, tang, csect; - char ch, *ptr, *ptr2, *ptr3, *ptr4; - spritetype *tspr; - - smoothratio = max(min(dasmoothratio,65536),0); - - dointerpolations(); - - if ((snum == myconnectindex) && ((networkmode == 1) || (myconnectindex != connecthead))) - { - cposx = omyx+mulscale16(myx-omyx,smoothratio); - cposy = omyy+mulscale16(myy-omyy,smoothratio); - cposz = omyz+mulscale16(myz-omyz,smoothratio); - choriz = omyhoriz+mulscale16(myhoriz-omyhoriz,smoothratio); - cang = omyang+mulscale16((long)(((myang+1024-omyang)&2047)-1024),smoothratio); - } - else - { - cposx = oposx[snum]+mulscale16(posx[snum]-oposx[snum],smoothratio); - cposy = oposy[snum]+mulscale16(posy[snum]-oposy[snum],smoothratio); - cposz = oposz[snum]+mulscale16(posz[snum]-oposz[snum],smoothratio); - choriz = ohoriz[snum]+mulscale16(horiz[snum]-ohoriz[snum],smoothratio); - cang = oang[snum]+mulscale16(((ang[snum]+1024-oang[snum])&2047)-1024,smoothratio); - } - czoom = ozoom[snum]+mulscale16(zoom[snum]-ozoom[snum],smoothratio); - - setears(cposx,cposy,(long)sintable[(cang+512)&2047]<<14,(long)sintable[cang&2047]<<14); - - if (dimensionmode[myconnectindex] == 3) - { - tempint = screensize; - - if (((loc.bits&32) > (screensizeflag&32)) && (screensize > 64)) - { - ox1 = ((xdim-screensize)>>1); - ox2 = ox1+screensize-1; - oy1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - oy2 = oy1 + scale(screensize,ydim-32,xdim)-1; - screensize -= (screensize>>3); - - if (tempint > xdim) - { - screensize = xdim; - - flushperms(); - - rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1); - while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1)+320; - while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; - if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; - - drawstatusbar(screenpeek); // Andy did this - } - - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; - setview(x1,y1,x2,y2); - - // (ox1,oy1)ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ - // ³ (x1,y1) ³ - // ³ ÚÄÄÄÄÄ¿ ³ - // ³ ³ ³ ³ - // ³ ÀÄÄÄÄÄÙ ³ - // ³ (x2,y2) ³ - // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ(ox2,oy2) - - drawtilebackground(0L,0L,BACKGROUND,8,ox1,oy1,x1-1,oy2,0); - drawtilebackground(0L,0L,BACKGROUND,8,x2+1,oy1,ox2,oy2,0); - drawtilebackground(0L,0L,BACKGROUND,8,x1,oy1,x2,y1-1,0); - drawtilebackground(0L,0L,BACKGROUND,8,x1,y2+1,x2,oy2,0); - } - if (((loc.bits&16) > (screensizeflag&16)) && (screensize <= xdim)) - { - screensize += (screensize>>3); - if ((screensize > xdim) && (tempint == xdim)) - { - screensize = xdim+1; - x1 = 0; y1 = 0; - x2 = xdim-1; y2 = ydim-1; - } - else - { - if (screensize > xdim) screensize = xdim; - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; - } - setview(x1,y1,x2,y2); - } - screensizeflag = loc.bits; - } - - if (dimensionmode[snum] != 2) - { - if ((numplayers > 1) && (option[4] == 0)) - { - //Do not draw other views constantly if they're staying still - //It's a shame this trick will only work in screen-buffer mode - //At least screen-buffer mode covers all the HI hi-res modes - //if (vidoption == 2) - //{ - for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 0; - frame2draw[snum] = 1; - - //2-1,3-1,4-2 - //5-2,6-2,7-2,8-3,9-3,10-3,11-3,12-4,13-4,14-4,15-4,16-5 - x1 = posx[snum]; y1 = posy[snum]; - for(j=(numplayers>>2)+1;j>0;j--) - { - maxdist = 0x80000000; - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (frame2draw[i] == 0) - { - x2 = posx[i]-x1; y2 = posy[i]-y1; - dist = dmulscale12(x2,x2,y2,y2); - - if (dist < 64) dist = 16384; - else if (dist > 16384) dist = 64; - else dist = 1048576 / dist; - - dist *= frameskipcnt[i]; - - //Increase frame rate if screen is moving - if ((posx[i] != oposx[i]) || (posy[i] != oposy[i]) || - (posz[i] != oposz[i]) || (ang[i] != oang[i]) || - (horiz[i] != ohoriz[i])) dist += dist; - - if (dist > maxdist) maxdist = dist, k = i; - } - - for(i=connecthead;i>=0;i=connectpoint2[i]) - frameskipcnt[i] += (frameskipcnt[i]>>3)+1; - frameskipcnt[k] = 0; - - frame2draw[k] = 1; - } - //} - //else - //{ - // for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 1; - //} - - for(i=connecthead,j=0;i>=0;i=connectpoint2[i],j++) - if (frame2draw[i] != 0) - { - if (numplayers <= 4) - { - switch(j) - { - case 0: setview(0,0,(xdim>>1)-1,(ydim>>1)-1); break; - case 1: setview((xdim>>1),0,xdim-1,(ydim>>1)-1); break; - case 2: setview(0,(ydim>>1),(xdim>>1)-1,ydim-1); break; - case 3: setview((xdim>>1),(ydim>>1),xdim-1,ydim-1); break; - } - } - else - { - switch(j) - { - case 0: setview(0,0,(xdim>>2)-1,(ydim>>2)-1); break; - case 1: setview(xdim>>2,0,(xdim>>1)-1,(ydim>>2)-1); break; - case 2: setview(xdim>>1,0,xdim-(xdim>>2)-1,(ydim>>2)-1); break; - case 3: setview(xdim-(xdim>>2),0,xdim-1,(ydim>>2)-1); break; - case 4: setview(0,ydim>>2,(xdim>>2)-1,(ydim>>1)-1); break; - case 5: setview(xdim>>2,ydim>>2,(xdim>>1)-1,(ydim>>1)-1); break; - case 6: setview(xdim>>1,ydim>>2,xdim-(xdim>>2)-1,(ydim>>1)-1); break; - case 7: setview(xdim-(xdim>>2),ydim>>2,xdim-1,(ydim>>1)-1); break; - case 8: setview(0,ydim>>1,(xdim>>2)-1,ydim-(ydim>>2)-1); break; - case 9: setview(xdim>>2,ydim>>1,(xdim>>1)-1,ydim-(ydim>>2)-1); break; - case 10: setview(xdim>>1,ydim>>1,xdim-(xdim>>2)-1,ydim-(ydim>>2)-1); break; - case 11: setview(xdim-(xdim>>2),ydim>>1,xdim-1,ydim-(ydim>>2)-1); break; - case 12: setview(0,ydim-(ydim>>2),(xdim>>2)-1,ydim-1); break; - case 13: setview(xdim>>2,ydim-(ydim>>2),(xdim>>1)-1,ydim-1); break; - case 14: setview(xdim>>1,ydim-(ydim>>2),xdim-(xdim>>2)-1,ydim-1); break; - case 15: setview(xdim-(xdim>>2),ydim-(ydim>>2),xdim-1,ydim-1); break; - } - } - - if (i == snum) - { - sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,cposz,cang,choriz,cursectnum[i]); - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - } - else - { - sprite[playersprite[i]].cstat |= 0x8000; - drawrooms(posx[i],posy[i],posz[i],ang[i],horiz[i],cursectnum[i]); - sprite[playersprite[i]].cstat &= ~0x8000; - analyzesprites(posx[i],posy[i]); - } - drawmasks(); - if ((numgrabbers[i] > 0) || (nummissiles[i] > 0) || (numbombs[i] > 0)) - rotatesprite(160<<16,184L<<16,65536,0,GUNONBOTTOM,sector[cursectnum[i]].floorshade,0,2,windowx1,windowy1,windowx2,windowy2); - - if (lockclock < 384) - { - if (lockclock < 128) - rotatesprite(320<<15,200<<15,lockclock<<9,lockclock<<4,DEMOSIGN,(128-lockclock)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - else if (lockclock < 256) - rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); - else - rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - } - - if (health[i] <= 0) - rotatesprite(320<<15,200<<15,(-health[i])<<11,(-health[i])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); - } - } - else - { - //Init for screen rotation - if (getrendermode() == 0) { // JBF 20031220 - tiltlock = screentilt; - if ((tiltlock) || (detailmode)) - { - walock[MAXTILES-2] = 255; - if (waloff[MAXTILES-2] == 0) - allocache(&waloff[MAXTILES-2],320L*320L,&walock[MAXTILES-2]); - if ((tiltlock&1023) == 0) - setviewtotile(MAXTILES-2,200L>>detailmode,320L>>detailmode); - else - setviewtotile(MAXTILES-2,320L>>detailmode,320L>>detailmode); - if ((tiltlock&1023) == 512) - { //Block off unscreen section of 90ø tilted screen - j = ((320-60)>>detailmode); - for(i=(60>>detailmode)-1;i>=0;i--) - { - startumost[i] = 1; startumost[i+j] = 1; - startdmost[i] = 0; startdmost[i+j] = 0; - } - } - - i = (tiltlock&511); if (i > 256) i = 512-i; - i = sintable[i+512]*8 + sintable[i]*5L; - setaspect(i>>1,yxaspect); - } - } else { - tiltlock = screentilt; - // Ken loves to interpolate - setrollangle(oscreentilt + mulscale16(((screentilt-oscreentilt+1024)&2047)-1024,smoothratio)); - } - - if ((gotpic[FLOORMIRROR>>3]&(1<<(FLOORMIRROR&7))) > 0) - { - dist = 0x7fffffff; i = 0; - for(k=floormirrorcnt-1;k>=0;k--) - { - j = klabs(wall[sector[floormirrorsector[k]].wallptr].x-cposx); - j += klabs(wall[sector[floormirrorsector[k]].wallptr].y-cposy); - if (j < dist) dist = j, i = k; - } - - //if (cposz > sector[floormirrorsector[i]].ceilingz) i = 1-i; //SOS - - j = floormirrorsector[i]; - - if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,(sector[j].floorz<<1)-cposz,cang,201-choriz,j); //SOS - //drawrooms(cposx,cposy,cposz,cang,choriz,j+MAXSECTORS); //SOS - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - drawmasks(); - - //Temp horizon - if (getrendermode() == 0) { - l = scale(choriz-100,windowx2-windowx1,320)+((windowy1+windowy2)>>1); - begindrawing(); //{{{ - for(y1=windowy1,y2=windowy2;y1>2,31)<<8); - ptr4 = palookup[18]; - ptr4 += (min(klabs(y2-l)>>2,31)<<8); - - j = sintable[((y2+totalclock)<<6)&2047]; - j += sintable[((y2-totalclock)<<7)&2047]; - j >>= 14; - - //ptr2 += j; - - //for(x1=windowx1;x1<=windowx2;x1++) - // { ch = ptr[x1]; ptr[x1] = ptr3[ptr2[x1]]; ptr2[x1] = ptr4[ch]; } - - ox1 = windowx1-min(j,0); - ox2 = windowx2-max(j,0); - - for(x1=windowx1;x1>3] &= ~(1<<(FLOORMIRROR&7)); - } - - if (gotpic[DAYSKY>>3]&(1<<(DAYSKY&7))) - { - gotpic[DAYSKY>>3] &= ~(1<<(DAYSKY&7)); - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; - } - else if (gotpic[NIGHTSKY>>3]&(1<<(NIGHTSKY&7))) - { - gotpic[NIGHTSKY>>3] &= ~(1<<(NIGHTSKY&7)); - pskyoff[0] = 0; pskyoff[1] = 0; pskyoff[2] = 0; pskyoff[3] = 0; - pskyoff[4] = 0; pskyoff[5] = 0; pskyoff[6] = 0; pskyoff[7] = 0; - pskybits = 3; - } - - - //Over the shoulder mode - csect = cursectnum[snum]; - if (cameradist >= 0) - { - cang += cameraang; - view(playersprite[snum],&cposx,&cposy,&cposz,&csect,cang,choriz); - } - - //WARNING! Assuming (MIRRORLABEL&31) = 0 and MAXMIRRORS = 64 - intptr = (long *)&gotpic[MIRRORLABEL>>3]; // CHECK! - if (intptr[0]|intptr[1]) - for(i=MAXMIRRORS-1;i>=0;i--) - if (gotpic[(i+MIRRORLABEL)>>3]&(1<<(i&7))) - { - gotpic[(i+MIRRORLABEL)>>3] &= ~(1<<(i&7)); - - //Prepare drawrooms for drawing mirror and calculate reflected - //position into tposx, tposy, and tang (tposz == cposz) - //Must call preparemirror before drawrooms and - // completemirror after drawrooms - preparemirror(cposx,cposy,cposz,cang,choriz, - mirrorwall[i],mirrorsector[i],&tposx,&tposy,&tang); - - ovisibility = visibility; - oparallaxvisibility = parallaxvisibility; - visibility <<= 1; - parallaxvisibility <<= 1; - ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; - - drawrooms(tposx,tposy,cposz,tang,choriz,mirrorsector[i]|MAXSECTORS); - for(j=0,tspr=&tsprite[0];jcstat&48) == 0) tspr->cstat |= 4; - analyzesprites(tposx,tposy); - drawmasks(); - - ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; - visibility = ovisibility; - parallaxvisibility = oparallaxvisibility; - - completemirror(); //Reverse screen x-wise in this function - - break; - } - - if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,cposz,cang,choriz,csect); - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - drawmasks(); - - //Finish for screen rotation - if (getrendermode() == 0) { // JBF 20031220 - if ((tiltlock) || (detailmode)) - { - setviewback(); - i = (tiltlock&511); if (i > 256) i = 512-i; - i = sintable[i+512]*8 + sintable[i]*5L; - if (detailmode == 0) i >>= 1; - rotatesprite(320<<15,200<<15,i,tiltlock+512,MAXTILES-2,0,0,2+4+64,windowx1,windowy1,windowx2,windowy2); - walock[MAXTILES-2] = 1; - } - } - - if (((numgrabbers[screenpeek] > 0) || (nummissiles[screenpeek] > 0) || (numbombs[screenpeek] > 0)) && (cameradist < 0)) - { - //Reset startdmost to bottom of screen - if ((windowx1 == 0) && (windowx2 == 319) && (yxaspect == 65536) && (tiltlock == 0)) - { - x1 = 160L-(tilesizx[GUNONBOTTOM]>>1); y1 = windowy2+1; - for(i=0;i>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - else if (lockclock < 256) - rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); - else - rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - } - - if (health[screenpeek] <= 0) - rotatesprite(320<<15,200<<15,(-health[screenpeek])<<11,(-health[screenpeek])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); - } - } - - //Only animate lava if its picnum is on screen - //gotpic is a bit array where the tile number's bit is set - //whenever it is drawn (ceilings, walls, sprites, etc.) - if ((gotpic[SLIME>>3]&(1<<(SLIME&7))) > 0) - { - gotpic[SLIME>>3] &= ~(1<<(SLIME&7)); - if (waloff[SLIME] != 0) { - movelava((char *)waloff[SLIME]); - invalidatetile(SLIME,0,1); // JBF 20031228 - } - } - - if ((show2dsector[cursectnum[snum]>>3]&(1<<(cursectnum[snum]&7))) == 0) - searchmap(cursectnum[snum]); - - if (dimensionmode[snum] != 3) - { - //Move back pivot point - i = scale(czoom,screensize,320); - if (dimensionmode[snum] == 2) - { - clearview(0L); //Clear screen to specified color - drawmapview(cposx,cposy,i,cang); - } - drawoverheadmap(cposx,cposy,i,cang); - } - - if (typemode != 0) - { - charsperline = 40; - //if (dimensionmode[snum] == 2) charsperline = 80; - - for(i=0;i<=typemessageleng;i+=charsperline) - { - for(j=0;j 0) - { - charsperline = 40; - //if (dimensionmode[snum] == 2) charsperline = 80; - - for(i=0;i<=getmessageleng;i+=charsperline) - { - for(j=0;j getmessagetimeoff) - getmessageleng = 0; - } - if ((numplayers >= 2) && (screenpeek != myconnectindex)) - { - j = 1; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (i == screenpeek) break; - j++; - } - Bsprintf(tempbuf,"(Player %ld's view)",j); - printext256((xdim>>1)-(Bstrlen(tempbuf)<<2),0,24,-1,tempbuf,0); - } - - if (syncstat != 0) printext256(68L,84L,31,0,"OUT OF SYNC!",0); - if (syncstate != 0) printext256(68L,92L,31,0,"Missed Network packet!",0); - -// //Uncomment this to test cache locks -//extern long cacnum; -//typedef struct { long *hand, leng; char *lock; } cactype; -//extern cactype cac[]; -// -// j = 0; -// for(i=0;i= 200) -// { -// Bsprintf(tempbuf,"Locked- %ld: Leng:%ld, Lock:%ld",i,cac[i].leng,*cac[i].lock); -// printext256(0L,j,31,-1,tempbuf,1); j += 6; -// } - - nextpage(); // send completed frame to display - - while (totalclock >= ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) - faketimerhandler(); - - if (keystatus[0x3f]) //F5 - { - keystatus[0x3f] = 0; - detailmode ^= 1; - //setrendermode(3); - } - if (keystatus[0x58]) //F12 - { - keystatus[0x58] = 0; - screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); - } - if (keystatus[0x3e]) //F4 - screen re-size - { - keystatus[0x3e] = 0; - - if (keystatus[0x2a]|keystatus[0x36]) { - setgamemode(!fullscreen, xdim, ydim, bpp); - } else { - - //cycle through all modes - j=-1; - - // work out a mask to select the mode - for (i=0; i 8) brightness = 0; - setbrightness(brightness,(char *)&palette[0],0); - } - - if (option[4] == 0) //Single player only keys - { - if (keystatus[0xd2]) //Insert - Insert player - { - keystatus[0xd2] = 0; - if (numplayers < MAXPLAYERS) - { - connectpoint2[numplayers-1] = numplayers; - connectpoint2[numplayers] = -1; - - movefifoend[numplayers] = movefifoend[0]; //HACK 01/05/2000 - - initplayersprite(numplayers); - - clearallviews(0L); //Clear screen to specified color - - numplayers++; - } - } - if (keystatus[0xd3]) //Delete - Delete player - { - keystatus[0xd3] = 0; - if (numplayers > 1) - { - numplayers--; - connectpoint2[numplayers-1] = -1; - - deletesprite(playersprite[numplayers]); - playersprite[numplayers] = -1; - - if (myconnectindex >= numplayers) myconnectindex = 0; - if (screenpeek >= numplayers) screenpeek = 0; - - if (numplayers < 2) - setup3dscreen(); - else - clearallviews(0L); //Clear screen to specified color - } - } - if (keystatus[0x46]) //Scroll Lock - { - keystatus[0x46] = 0; - - myconnectindex = connectpoint2[myconnectindex]; - if (myconnectindex < 0) myconnectindex = connecthead; - screenpeek = myconnectindex; - } - } - - restoreinterpolations(); + long i, j, k=0, l, charsperline, tempint; + long x1, y1, x2, y2, ox1, oy1, ox2, oy2, dist, maxdist; + long cposx, cposy, cposz, choriz, czoom, tposx, tposy; + long tiltlock, *intptr, ovisibility, oparallaxvisibility; + short cang, tang, csect; + char ch, *ptr, *ptr2, *ptr3, *ptr4; + spritetype *tspr; + + smoothratio = max(min(dasmoothratio,65536),0); + + dointerpolations(); + + if ((snum == myconnectindex) && ((networkmode == 1) || (myconnectindex != connecthead))) + { + cposx = omyx+mulscale16(myx-omyx,smoothratio); + cposy = omyy+mulscale16(myy-omyy,smoothratio); + cposz = omyz+mulscale16(myz-omyz,smoothratio); + choriz = omyhoriz+mulscale16(myhoriz-omyhoriz,smoothratio); + cang = omyang+mulscale16((long)(((myang+1024-omyang)&2047)-1024),smoothratio); + } + else + { + cposx = oposx[snum]+mulscale16(posx[snum]-oposx[snum],smoothratio); + cposy = oposy[snum]+mulscale16(posy[snum]-oposy[snum],smoothratio); + cposz = oposz[snum]+mulscale16(posz[snum]-oposz[snum],smoothratio); + choriz = ohoriz[snum]+mulscale16(horiz[snum]-ohoriz[snum],smoothratio); + cang = oang[snum]+mulscale16(((ang[snum]+1024-oang[snum])&2047)-1024,smoothratio); + } + czoom = ozoom[snum]+mulscale16(zoom[snum]-ozoom[snum],smoothratio); + + setears(cposx,cposy,(long)sintable[(cang+512)&2047]<<14,(long)sintable[cang&2047]<<14); + + if (dimensionmode[myconnectindex] == 3) + { + tempint = screensize; + + if (((loc.bits&32) > (screensizeflag&32)) && (screensize > 64)) + { + ox1 = ((xdim-screensize)>>1); + ox2 = ox1+screensize-1; + oy1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + oy2 = oy1 + scale(screensize,ydim-32,xdim)-1; + screensize -= (screensize>>3); + + if (tempint > xdim) + { + screensize = xdim; + + flushperms(); + + rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1); + while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1)+320; + while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; + if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; + + drawstatusbar(screenpeek); // Andy did this + } + + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; + setview(x1,y1,x2,y2); + + // (ox1,oy1)ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ + // ³ (x1,y1) ³ + // ³ ÚÄÄÄÄÄ¿ ³ + // ³ ³ ³ ³ + // ³ ÀÄÄÄÄÄÙ ³ + // ³ (x2,y2) ³ + // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ(ox2,oy2) + + drawtilebackground(0L,0L,BACKGROUND,8,ox1,oy1,x1-1,oy2,0); + drawtilebackground(0L,0L,BACKGROUND,8,x2+1,oy1,ox2,oy2,0); + drawtilebackground(0L,0L,BACKGROUND,8,x1,oy1,x2,y1-1,0); + drawtilebackground(0L,0L,BACKGROUND,8,x1,y2+1,x2,oy2,0); + } + if (((loc.bits&16) > (screensizeflag&16)) && (screensize <= xdim)) + { + screensize += (screensize>>3); + if ((screensize > xdim) && (tempint == xdim)) + { + screensize = xdim+1; + x1 = 0; y1 = 0; + x2 = xdim-1; y2 = ydim-1; + } + else + { + if (screensize > xdim) screensize = xdim; + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; + } + setview(x1,y1,x2,y2); + } + screensizeflag = loc.bits; + } + + if (dimensionmode[snum] != 2) + { + if ((numplayers > 1) && (option[4] == 0)) + { + //Do not draw other views constantly if they're staying still + //It's a shame this trick will only work in screen-buffer mode + //At least screen-buffer mode covers all the HI hi-res modes + //if (vidoption == 2) + //{ + for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 0; + frame2draw[snum] = 1; + + //2-1,3-1,4-2 + //5-2,6-2,7-2,8-3,9-3,10-3,11-3,12-4,13-4,14-4,15-4,16-5 + x1 = posx[snum]; y1 = posy[snum]; + for(j=(numplayers>>2)+1;j>0;j--) + { + maxdist = 0x80000000; + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (frame2draw[i] == 0) + { + x2 = posx[i]-x1; y2 = posy[i]-y1; + dist = dmulscale12(x2,x2,y2,y2); + + if (dist < 64) dist = 16384; + else if (dist > 16384) dist = 64; + else dist = 1048576 / dist; + + dist *= frameskipcnt[i]; + + //Increase frame rate if screen is moving + if ((posx[i] != oposx[i]) || (posy[i] != oposy[i]) || + (posz[i] != oposz[i]) || (ang[i] != oang[i]) || + (horiz[i] != ohoriz[i])) dist += dist; + + if (dist > maxdist) maxdist = dist, k = i; + } + + for(i=connecthead;i>=0;i=connectpoint2[i]) + frameskipcnt[i] += (frameskipcnt[i]>>3)+1; + frameskipcnt[k] = 0; + + frame2draw[k] = 1; + } + //} + //else + //{ + // for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 1; + //} + + for(i=connecthead,j=0;i>=0;i=connectpoint2[i],j++) + if (frame2draw[i] != 0) + { + if (numplayers <= 4) + { + switch(j) + { + case 0: setview(0,0,(xdim>>1)-1,(ydim>>1)-1); break; + case 1: setview((xdim>>1),0,xdim-1,(ydim>>1)-1); break; + case 2: setview(0,(ydim>>1),(xdim>>1)-1,ydim-1); break; + case 3: setview((xdim>>1),(ydim>>1),xdim-1,ydim-1); break; + } + } + else + { + switch(j) + { + case 0: setview(0,0,(xdim>>2)-1,(ydim>>2)-1); break; + case 1: setview(xdim>>2,0,(xdim>>1)-1,(ydim>>2)-1); break; + case 2: setview(xdim>>1,0,xdim-(xdim>>2)-1,(ydim>>2)-1); break; + case 3: setview(xdim-(xdim>>2),0,xdim-1,(ydim>>2)-1); break; + case 4: setview(0,ydim>>2,(xdim>>2)-1,(ydim>>1)-1); break; + case 5: setview(xdim>>2,ydim>>2,(xdim>>1)-1,(ydim>>1)-1); break; + case 6: setview(xdim>>1,ydim>>2,xdim-(xdim>>2)-1,(ydim>>1)-1); break; + case 7: setview(xdim-(xdim>>2),ydim>>2,xdim-1,(ydim>>1)-1); break; + case 8: setview(0,ydim>>1,(xdim>>2)-1,ydim-(ydim>>2)-1); break; + case 9: setview(xdim>>2,ydim>>1,(xdim>>1)-1,ydim-(ydim>>2)-1); break; + case 10: setview(xdim>>1,ydim>>1,xdim-(xdim>>2)-1,ydim-(ydim>>2)-1); break; + case 11: setview(xdim-(xdim>>2),ydim>>1,xdim-1,ydim-(ydim>>2)-1); break; + case 12: setview(0,ydim-(ydim>>2),(xdim>>2)-1,ydim-1); break; + case 13: setview(xdim>>2,ydim-(ydim>>2),(xdim>>1)-1,ydim-1); break; + case 14: setview(xdim>>1,ydim-(ydim>>2),xdim-(xdim>>2)-1,ydim-1); break; + case 15: setview(xdim-(xdim>>2),ydim-(ydim>>2),xdim-1,ydim-1); break; + } + } + + if (i == snum) + { + sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,cposz,cang,choriz,cursectnum[i]); + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + } + else + { + sprite[playersprite[i]].cstat |= 0x8000; + drawrooms(posx[i],posy[i],posz[i],ang[i],horiz[i],cursectnum[i]); + sprite[playersprite[i]].cstat &= ~0x8000; + analyzesprites(posx[i],posy[i]); + } + drawmasks(); + if ((numgrabbers[i] > 0) || (nummissiles[i] > 0) || (numbombs[i] > 0)) + rotatesprite(160<<16,184L<<16,65536,0,GUNONBOTTOM,sector[cursectnum[i]].floorshade,0,2,windowx1,windowy1,windowx2,windowy2); + + if (lockclock < 384) + { + if (lockclock < 128) + rotatesprite(320<<15,200<<15,lockclock<<9,lockclock<<4,DEMOSIGN,(128-lockclock)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + else if (lockclock < 256) + rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); + else + rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + } + + if (health[i] <= 0) + rotatesprite(320<<15,200<<15,(-health[i])<<11,(-health[i])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); + } + } + else + { + //Init for screen rotation + if (getrendermode() == 0) { // JBF 20031220 + tiltlock = screentilt; + if ((tiltlock) || (detailmode)) + { + walock[MAXTILES-2] = 255; + if (waloff[MAXTILES-2] == 0) + allocache(&waloff[MAXTILES-2],320L*320L,&walock[MAXTILES-2]); + if ((tiltlock&1023) == 0) + setviewtotile(MAXTILES-2,200L>>detailmode,320L>>detailmode); + else + setviewtotile(MAXTILES-2,320L>>detailmode,320L>>detailmode); + if ((tiltlock&1023) == 512) + { //Block off unscreen section of 90ø tilted screen + j = ((320-60)>>detailmode); + for(i=(60>>detailmode)-1;i>=0;i--) + { + startumost[i] = 1; startumost[i+j] = 1; + startdmost[i] = 0; startdmost[i+j] = 0; + } + } + + i = (tiltlock&511); if (i > 256) i = 512-i; + i = sintable[i+512]*8 + sintable[i]*5L; + setaspect(i>>1,yxaspect); + } + } else { + tiltlock = screentilt; + // Ken loves to interpolate + setrollangle(oscreentilt + mulscale16(((screentilt-oscreentilt+1024)&2047)-1024,smoothratio)); + } + + if ((gotpic[FLOORMIRROR>>3]&(1<<(FLOORMIRROR&7))) > 0) + { + dist = 0x7fffffff; i = 0; + for(k=floormirrorcnt-1;k>=0;k--) + { + j = klabs(wall[sector[floormirrorsector[k]].wallptr].x-cposx); + j += klabs(wall[sector[floormirrorsector[k]].wallptr].y-cposy); + if (j < dist) dist = j, i = k; + } + + //if (cposz > sector[floormirrorsector[i]].ceilingz) i = 1-i; //SOS + + j = floormirrorsector[i]; + + if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,(sector[j].floorz<<1)-cposz,cang,201-choriz,j); //SOS + //drawrooms(cposx,cposy,cposz,cang,choriz,j+MAXSECTORS); //SOS + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + drawmasks(); + + //Temp horizon + if (getrendermode() == 0) { + l = scale(choriz-100,windowx2-windowx1,320)+((windowy1+windowy2)>>1); + begindrawing(); //{{{ + for(y1=windowy1,y2=windowy2;y1>2,31)<<8); + ptr4 = palookup[18]; + ptr4 += (min(klabs(y2-l)>>2,31)<<8); + + j = sintable[((y2+totalclock)<<6)&2047]; + j += sintable[((y2-totalclock)<<7)&2047]; + j >>= 14; + + //ptr2 += j; + + //for(x1=windowx1;x1<=windowx2;x1++) + // { ch = ptr[x1]; ptr[x1] = ptr3[ptr2[x1]]; ptr2[x1] = ptr4[ch]; } + + ox1 = windowx1-min(j,0); + ox2 = windowx2-max(j,0); + + for(x1=windowx1;x1>3] &= ~(1<<(FLOORMIRROR&7)); + } + + if (gotpic[DAYSKY>>3]&(1<<(DAYSKY&7))) + { + gotpic[DAYSKY>>3] &= ~(1<<(DAYSKY&7)); + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + } + else if (gotpic[NIGHTSKY>>3]&(1<<(NIGHTSKY&7))) + { + gotpic[NIGHTSKY>>3] &= ~(1<<(NIGHTSKY&7)); + pskyoff[0] = 0; pskyoff[1] = 0; pskyoff[2] = 0; pskyoff[3] = 0; + pskyoff[4] = 0; pskyoff[5] = 0; pskyoff[6] = 0; pskyoff[7] = 0; + pskybits = 3; + } + + + //Over the shoulder mode + csect = cursectnum[snum]; + if (cameradist >= 0) + { + cang += cameraang; + view(playersprite[snum],&cposx,&cposy,&cposz,&csect,cang,choriz); + } + + //WARNING! Assuming (MIRRORLABEL&31) = 0 and MAXMIRRORS = 64 + intptr = (long *)&gotpic[MIRRORLABEL>>3]; // CHECK! + if (intptr[0]|intptr[1]) + for(i=MAXMIRRORS-1;i>=0;i--) + if (gotpic[(i+MIRRORLABEL)>>3]&(1<<(i&7))) + { + gotpic[(i+MIRRORLABEL)>>3] &= ~(1<<(i&7)); + + //Prepare drawrooms for drawing mirror and calculate reflected + //position into tposx, tposy, and tang (tposz == cposz) + //Must call preparemirror before drawrooms and + // completemirror after drawrooms + preparemirror(cposx,cposy,cposz,cang,choriz, + mirrorwall[i],mirrorsector[i],&tposx,&tposy,&tang); + + ovisibility = visibility; + oparallaxvisibility = parallaxvisibility; + visibility <<= 1; + parallaxvisibility <<= 1; + ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; + + drawrooms(tposx,tposy,cposz,tang,choriz,mirrorsector[i]|MAXSECTORS); + for(j=0,tspr=&tsprite[0];jcstat&48) == 0) tspr->cstat |= 4; + analyzesprites(tposx,tposy); + drawmasks(); + + ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; + visibility = ovisibility; + parallaxvisibility = oparallaxvisibility; + + completemirror(); //Reverse screen x-wise in this function + + break; + } + + if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,cposz,cang,choriz,csect); + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + drawmasks(); + + //Finish for screen rotation + if (getrendermode() == 0) { // JBF 20031220 + if ((tiltlock) || (detailmode)) + { + setviewback(); + i = (tiltlock&511); if (i > 256) i = 512-i; + i = sintable[i+512]*8 + sintable[i]*5L; + if (detailmode == 0) i >>= 1; + rotatesprite(320<<15,200<<15,i,tiltlock+512,MAXTILES-2,0,0,2+4+64,windowx1,windowy1,windowx2,windowy2); + walock[MAXTILES-2] = 1; + } + } + + if (((numgrabbers[screenpeek] > 0) || (nummissiles[screenpeek] > 0) || (numbombs[screenpeek] > 0)) && (cameradist < 0)) + { + //Reset startdmost to bottom of screen + if ((windowx1 == 0) && (windowx2 == 319) && (yxaspect == 65536) && (tiltlock == 0)) + { + x1 = 160L-(tilesizx[GUNONBOTTOM]>>1); y1 = windowy2+1; + for(i=0;i>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + else if (lockclock < 256) + rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); + else + rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + } + + if (health[screenpeek] <= 0) + rotatesprite(320<<15,200<<15,(-health[screenpeek])<<11,(-health[screenpeek])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); + } + } + + //Only animate lava if its picnum is on screen + //gotpic is a bit array where the tile number's bit is set + //whenever it is drawn (ceilings, walls, sprites, etc.) + if ((gotpic[SLIME>>3]&(1<<(SLIME&7))) > 0) + { + gotpic[SLIME>>3] &= ~(1<<(SLIME&7)); + if (waloff[SLIME] != 0) { + movelava((char *)waloff[SLIME]); + invalidatetile(SLIME,0,1); // JBF 20031228 + } + } + + if ((show2dsector[cursectnum[snum]>>3]&(1<<(cursectnum[snum]&7))) == 0) + searchmap(cursectnum[snum]); + + if (dimensionmode[snum] != 3) + { + //Move back pivot point + i = scale(czoom,screensize,320); + if (dimensionmode[snum] == 2) + { + clearview(0L); //Clear screen to specified color + drawmapview(cposx,cposy,i,cang); + } + drawoverheadmap(cposx,cposy,i,cang); + } + + if (typemode != 0) + { + charsperline = 40; + //if (dimensionmode[snum] == 2) charsperline = 80; + + for(i=0;i<=typemessageleng;i+=charsperline) + { + for(j=0;j 0) + { + charsperline = 40; + //if (dimensionmode[snum] == 2) charsperline = 80; + + for(i=0;i<=getmessageleng;i+=charsperline) + { + for(j=0;j getmessagetimeoff) + getmessageleng = 0; + } + if ((numplayers >= 2) && (screenpeek != myconnectindex)) + { + j = 1; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i == screenpeek) break; + j++; + } + Bsprintf(tempbuf,"(Player %ld's view)",j); + printext256((xdim>>1)-(Bstrlen(tempbuf)<<2),0,24,-1,tempbuf,0); + } + + if (syncstat != 0) printext256(68L,84L,31,0,"OUT OF SYNC!",0); + if (syncstate != 0) printext256(68L,92L,31,0,"Missed Network packet!",0); + + // //Uncomment this to test cache locks + //extern long cacnum; + //typedef struct { long *hand, leng; char *lock; } cactype; + //extern cactype cac[]; + // + // j = 0; + // for(i=0;i= 200) + // { + // Bsprintf(tempbuf,"Locked- %ld: Leng:%ld, Lock:%ld",i,cac[i].leng,*cac[i].lock); + // printext256(0L,j,31,-1,tempbuf,1); j += 6; + // } + + nextpage(); // send completed frame to display + + while (totalclock >= ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) + faketimerhandler(); + + if (keystatus[0x3f]) //F5 + { + keystatus[0x3f] = 0; + detailmode ^= 1; + //setrendermode(3); + } + if (keystatus[0x58]) //F12 + { + keystatus[0x58] = 0; + screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); + } + if (keystatus[0x3e]) //F4 - screen re-size + { + keystatus[0x3e] = 0; + + if (keystatus[0x2a]|keystatus[0x36]) { + setgamemode(!fullscreen, xdim, ydim, bpp); + } else { + + //cycle through all modes + j=-1; + + // work out a mask to select the mode + for (i=0; i 8) brightness = 0; + setbrightness(brightness,(char *)&palette[0],0); + } + + if (option[4] == 0) //Single player only keys + { + if (keystatus[0xd2]) //Insert - Insert player + { + keystatus[0xd2] = 0; + if (numplayers < MAXPLAYERS) + { + connectpoint2[numplayers-1] = numplayers; + connectpoint2[numplayers] = -1; + + movefifoend[numplayers] = movefifoend[0]; //HACK 01/05/2000 + + initplayersprite(numplayers); + + clearallviews(0L); //Clear screen to specified color + + numplayers++; + } + } + if (keystatus[0xd3]) //Delete - Delete player + { + keystatus[0xd3] = 0; + if (numplayers > 1) + { + numplayers--; + connectpoint2[numplayers-1] = -1; + + deletesprite(playersprite[numplayers]); + playersprite[numplayers] = -1; + + if (myconnectindex >= numplayers) myconnectindex = 0; + if (screenpeek >= numplayers) screenpeek = 0; + + if (numplayers < 2) + setup3dscreen(); + else + clearallviews(0L); //Clear screen to specified color + } + } + if (keystatus[0x46]) //Scroll Lock + { + keystatus[0x46] = 0; + + myconnectindex = connectpoint2[myconnectindex]; + if (myconnectindex < 0) myconnectindex = connecthead; + screenpeek = myconnectindex; + } + } + + restoreinterpolations(); } void movethings(void) { - long i; + long i; - gotlastpacketclock = totalclock; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - copybufbyte(&ffsync[i],&baksync[movefifoend[i]][i],sizeof(input)); - movefifoend[i] = ((movefifoend[i]+1)&(MOVEFIFOSIZ-1)); - } + gotlastpacketclock = totalclock; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + copybufbyte(&ffsync[i],&baksync[movefifoend[i]][i],sizeof(input)); + movefifoend[i] = ((movefifoend[i]+1)&(MOVEFIFOSIZ-1)); + } } void fakedomovethings(void) { - input *syn; - long i, j, k, doubvel, xvect, yvect, goalz; - short bakcstat; + input *syn; + long i, j, k, doubvel, xvect, yvect, goalz; + short bakcstat; - syn = (input *)&baksync[fakemovefifoplc][myconnectindex]; + syn = (input *)&baksync[fakemovefifoplc][myconnectindex]; - omyx = myx; - omyy = myy; - omyz = myz; - omyang = myang; - omyhoriz = myhoriz; + omyx = myx; + omyy = myy; + omyz = myz; + omyang = myang; + omyhoriz = myhoriz; - bakcstat = sprite[playersprite[myconnectindex]].cstat; - sprite[playersprite[myconnectindex]].cstat &= ~0x101; + bakcstat = sprite[playersprite[myconnectindex]].cstat; + sprite[playersprite[myconnectindex]].cstat &= ~0x101; - if ((syn->fvel|syn->svel) != 0) - { - doubvel = (TICSPERFRAME<<((syn->bits&256)>0)); + if ((syn->fvel|syn->svel) != 0) + { + doubvel = (TICSPERFRAME<<((syn->bits&256)>0)); - xvect = 0, yvect = 0; - if (syn->fvel != 0) - { - xvect += ((((long)syn->fvel)*doubvel*(long)sintable[(myang+512)&2047])>>3); - yvect += ((((long)syn->fvel)*doubvel*(long)sintable[myang&2047])>>3); - } - if (syn->svel != 0) - { - xvect += ((((long)syn->svel)*doubvel*(long)sintable[myang&2047])>>3); - yvect += ((((long)syn->svel)*doubvel*(long)sintable[(myang+1536)&2047])>>3); - } - if (flytime[myconnectindex] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed - clipmove(&myx,&myy,&myz,&mycursectnum,xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); - } + xvect = 0, yvect = 0; + if (syn->fvel != 0) + { + xvect += ((((long)syn->fvel)*doubvel*(long)sintable[(myang+512)&2047])>>3); + yvect += ((((long)syn->fvel)*doubvel*(long)sintable[myang&2047])>>3); + } + if (syn->svel != 0) + { + xvect += ((((long)syn->svel)*doubvel*(long)sintable[myang&2047])>>3); + yvect += ((((long)syn->svel)*doubvel*(long)sintable[(myang+1536)&2047])>>3); + } + if (flytime[myconnectindex] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed + clipmove(&myx,&myy,&myz,&mycursectnum,xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); + } - pushmove(&myx,&myy,&myz,&mycursectnum,128L,4<<8,4<<8,CLIPMASK0); - getzrange(myx,myy,myz,mycursectnum,&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); + pushmove(&myx,&myy,&myz,&mycursectnum,128L,4<<8,4<<8,CLIPMASK0); + getzrange(myx,myy,myz,mycursectnum,&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); - if (syn->avel != 0) //ang += avel * constant - { //ENGINE calculates avel for you - doubvel = TICSPERFRAME; - if ((syn->bits&256) > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (TICSPERFRAME>>1); - myang += ((((long)syn->avel)*doubvel)>>4); - myang &= 2047; - } + if (syn->avel != 0) //ang += avel * constant + { //ENGINE calculates avel for you + doubvel = TICSPERFRAME; + if ((syn->bits&256) > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (TICSPERFRAME>>1); + myang += ((((long)syn->avel)*doubvel)>>4); + myang &= 2047; + } - if (((syn->bits&8) > 0) && (myhoriz > 100-(200>>1))) myhoriz -= 4; //- - if (((syn->bits&4) > 0) && (myhoriz < 100+(200>>1))) myhoriz += 4; //+ + if (((syn->bits&8) > 0) && (myhoriz > 100-(200>>1))) myhoriz -= 4; //- + if (((syn->bits&4) > 0) && (myhoriz < 100+(200>>1))) myhoriz += 4; //+ - goalz = globloz-EYEHEIGHT; - if (sector[mycursectnum].lotag == 4) //slime sector - if ((globlohit&0xc000) != 49152) //You're not on a sprite - { - goalz = globloz-(8<<8); - if (myz >= goalz-(2<<8)) - clipmove(&myx,&myy,&myz,&mycursectnum,-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); - } - if (goalz < globhiz+(16<<8)) //ceiling&floor too close - goalz = ((globloz+globhiz)>>1); + goalz = globloz-EYEHEIGHT; + if (sector[mycursectnum].lotag == 4) //slime sector + if ((globlohit&0xc000) != 49152) //You're not on a sprite + { + goalz = globloz-(8<<8); + if (myz >= goalz-(2<<8)) + clipmove(&myx,&myy,&myz,&mycursectnum,-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); + } + if (goalz < globhiz+(16<<8)) //ceiling&floor too close + goalz = ((globloz+globhiz)>>1); - if (health[myconnectindex] >= 0) - { - if ((syn->bits&1) > 0) //A (stand high) - { - if (flytime[myconnectindex] <= lockclock) - { - if (myz >= globloz-(32<<8)) - { - goalz -= (16<<8); - if (syn->bits&256) goalz -= (24<<8); - } - } - else - { - myzvel -= 192; - if (syn->bits&256) myzvel -= 192; - } - } - if ((syn->bits&2) > 0) //Z (stand low) - { - if (flytime[myconnectindex] <= lockclock) - { - goalz += (12<<8); - if (syn->bits&256) goalz += (12<<8); - } - else - { - myzvel += 192; - if (syn->bits&256) myzvel += 192; - } - } - } + if (health[myconnectindex] >= 0) + { + if ((syn->bits&1) > 0) //A (stand high) + { + if (flytime[myconnectindex] <= lockclock) + { + if (myz >= globloz-(32<<8)) + { + goalz -= (16<<8); + if (syn->bits&256) goalz -= (24<<8); + } + } + else + { + myzvel -= 192; + if (syn->bits&256) myzvel -= 192; + } + } + if ((syn->bits&2) > 0) //Z (stand low) + { + if (flytime[myconnectindex] <= lockclock) + { + goalz += (12<<8); + if (syn->bits&256) goalz += (12<<8); + } + else + { + myzvel += 192; + if (syn->bits&256) myzvel += 192; + } + } + } - if (flytime[myconnectindex] <= lockclock) - { - if (myz < goalz) - myzvel += (TICSPERFRAME<<4); - else - myzvel = (((goalz-myz)*TICSPERFRAME)>>5); - } - else - { - myzvel -= (myzvel>>2); - myzvel -= ksgn(myzvel); - } + if (flytime[myconnectindex] <= lockclock) + { + if (myz < goalz) + myzvel += (TICSPERFRAME<<4); + else + myzvel = (((goalz-myz)*TICSPERFRAME)>>5); + } + else + { + myzvel -= (myzvel>>2); + myzvel -= ksgn(myzvel); + } - myz += myzvel; - if (myz > globloz-(4<<8)) myz = globloz-(4<<8), myzvel = 0; - if (myz < globhiz+(4<<8)) myz = globhiz+(4<<8), myzvel = 0; + myz += myzvel; + if (myz > globloz-(4<<8)) myz = globloz-(4<<8), myzvel = 0; + if (myz < globhiz+(4<<8)) myz = globhiz+(4<<8), myzvel = 0; - sprite[playersprite[myconnectindex]].cstat = bakcstat; + sprite[playersprite[myconnectindex]].cstat = bakcstat; - myxbak[fakemovefifoplc] = myx; - myybak[fakemovefifoplc] = myy; - myzbak[fakemovefifoplc] = myz; - myangbak[fakemovefifoplc] = myang; - myhorizbak[fakemovefifoplc] = myhoriz; - fakemovefifoplc = (fakemovefifoplc+1)&(MOVEFIFOSIZ-1); + myxbak[fakemovefifoplc] = myx; + myybak[fakemovefifoplc] = myy; + myzbak[fakemovefifoplc] = myz; + myangbak[fakemovefifoplc] = myang; + myhorizbak[fakemovefifoplc] = myhoriz; + fakemovefifoplc = (fakemovefifoplc+1)&(MOVEFIFOSIZ-1); } - //Prediction correction +//Prediction correction void fakedomovethingscorrect(void) { - long i; + long i; - if ((networkmode == 0) && (myconnectindex == connecthead)) return; + if ((networkmode == 0) && (myconnectindex == connecthead)) return; - i = ((movefifoplc-1)&(MOVEFIFOSIZ-1)); + i = ((movefifoplc-1)&(MOVEFIFOSIZ-1)); - if ((posx[myconnectindex] == myxbak[i]) && - (posy[myconnectindex] == myybak[i]) && - (posz[myconnectindex] == myzbak[i]) && - (horiz[myconnectindex] == myhorizbak[i]) && - (ang[myconnectindex] == myangbak[i])) - return; + if ((posx[myconnectindex] == myxbak[i]) && + (posy[myconnectindex] == myybak[i]) && + (posz[myconnectindex] == myzbak[i]) && + (horiz[myconnectindex] == myhorizbak[i]) && + (ang[myconnectindex] == myangbak[i])) + return; - //Re-start fakedomovethings back to place of error - myx = omyx = posx[myconnectindex]; - myy = omyy = posy[myconnectindex]; - myz = omyz = posz[myconnectindex]; myzvel = hvel[myconnectindex]; - myang = omyang = ang[myconnectindex]; - mycursectnum = mycursectnum; - myhoriz = omyhoriz = horiz[myconnectindex]; + //Re-start fakedomovethings back to place of error + myx = omyx = posx[myconnectindex]; + myy = omyy = posy[myconnectindex]; + myz = omyz = posz[myconnectindex]; myzvel = hvel[myconnectindex]; + myang = omyang = ang[myconnectindex]; + mycursectnum = mycursectnum; + myhoriz = omyhoriz = horiz[myconnectindex]; - fakemovefifoplc = movefifoplc; - while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); + fakemovefifoplc = movefifoplc; + while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); } void domovethings(void) { - short i, j, startwall, endwall; - spritetype *spr; - walltype *wal; - point3d *ospr; + short i, j, startwall, endwall; + spritetype *spr; + walltype *wal; + point3d *ospr; - nummoves++; + nummoves++; - for(i=connecthead;i>=0;i=connectpoint2[i]) - copybufbyte(&baksync[movefifoplc][i],&ssync[i],sizeof(input)); - movefifoplc = ((movefifoplc+1)&(MOVEFIFOSIZ-1)); + for(i=connecthead;i>=0;i=connectpoint2[i]) + copybufbyte(&baksync[movefifoplc][i],&ssync[i],sizeof(input)); + movefifoplc = ((movefifoplc+1)&(MOVEFIFOSIZ-1)); - if (option[4] != 0) - { - syncval[syncvalhead] = (char)(randomseed&255); - syncvalhead = ((syncvalhead+1)&(MOVEFIFOSIZ-1)); - } + if (option[4] != 0) + { + syncval[syncvalhead] = (char)(randomseed&255); + syncvalhead = ((syncvalhead+1)&(MOVEFIFOSIZ-1)); + } - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - oposx[i] = posx[i]; - oposy[i] = posy[i]; - oposz[i] = posz[i]; - ohoriz[i] = horiz[i]; - ozoom[i] = zoom[i]; - oang[i] = ang[i]; - } + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + oposx[i] = posx[i]; + oposy[i] = posy[i]; + oposz[i] = posz[i]; + ohoriz[i] = horiz[i]; + ozoom[i] = zoom[i]; + oang[i] = ang[i]; + } - for(i=NUMSTATS-1;i>=0;i--) - if (statrate[i] >= 0) - for(j=headspritestat[i];j>=0;j=nextspritestat[j]) - if (((nummoves-j)&statrate[i]) == 0) - copybuf(&sprite[j].x,&osprite[j].x,3); + for(i=NUMSTATS-1;i>=0;i--) + if (statrate[i] >= 0) + for(j=headspritestat[i];j>=0;j=nextspritestat[j]) + if (((nummoves-j)&statrate[i]) == 0) + copybuf(&sprite[j].x,&osprite[j].x,3); - for(i=connecthead;i>=0;i=connectpoint2[i]) - ocursectnum[i] = cursectnum[i]; + for(i=connecthead;i>=0;i=connectpoint2[i]) + ocursectnum[i] = cursectnum[i]; - updateinterpolations(); + updateinterpolations(); - if ((numplayers <= 2) && (recstat == 1)) - { - j = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - copybufbyte(&ssync[i],&recsync[reccnt][j],sizeof(input)); - j++; - } - reccnt++; if (reccnt > 16383) reccnt = 16383; - } + if ((numplayers <= 2) && (recstat == 1)) + { + j = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + copybufbyte(&ssync[i],&recsync[reccnt][j],sizeof(input)); + j++; + } + reccnt++; if (reccnt > 16383) reccnt = 16383; + } - lockclock += TICSPERFRAME; - drawstatusflytime(screenpeek); // Andy did this + lockclock += TICSPERFRAME; + drawstatusflytime(screenpeek); // Andy did this - if (cameradist >= 0) - { - cameradist = min(cameradist+((totalclock-cameraclock)<<10),65536); - if (keystatus[0x52]) //0 - cameraang -= ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); - if (keystatus[0x53]) //. - cameraang += ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); - cameraclock = totalclock; - } + if (cameradist >= 0) + { + cameradist = min(cameradist+((totalclock-cameraclock)<<10),65536); + if (keystatus[0x52]) //0 + cameraang -= ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); + if (keystatus[0x53]) //. + cameraang += ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); + cameraclock = totalclock; + } - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - processinput(i); //Move player + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + processinput(i); //Move player - checktouchsprite(i,cursectnum[i]); //Pick up coins - startwall = sector[cursectnum[i]].wallptr; - endwall = startwall + sector[cursectnum[i]].wallnum; - for(j=startwall,wal=&wall[j];jnextsector >= 0) checktouchsprite(i,wal->nextsector); - } + checktouchsprite(i,cursectnum[i]); //Pick up coins + startwall = sector[cursectnum[i]].wallptr; + endwall = startwall + sector[cursectnum[i]].wallnum; + for(j=startwall,wal=&wall[j];jnextsector >= 0) checktouchsprite(i,wal->nextsector); + } - doanimations(); - tagcode(); //Door code, moving sector code, other stuff - statuslistcode(); //Monster / bullet code / explosions + doanimations(); + tagcode(); //Door code, moving sector code, other stuff + statuslistcode(); //Monster / bullet code / explosions - fakedomovethingscorrect(); + fakedomovethingscorrect(); - checkmasterslaveswitch(); + checkmasterslaveswitch(); } void getinput(void) { - char ch, keystate, *ptr; - long i, j, k; - long mousx, mousy, bstatus; + char ch, keystate, *ptr; + long i, j, k; + long mousx, mousy, bstatus; - if (typemode == 0) //if normal game keys active - { - if (keystatus[keys[15]]) - { - keystatus[keys[15]] = 0; + if (typemode == 0) //if normal game keys active + { + if (keystatus[keys[15]]) + { + keystatus[keys[15]] = 0; - screenpeek = connectpoint2[screenpeek]; - if (screenpeek < 0) screenpeek = connecthead; - drawstatusbar(screenpeek); // Andy did this - } + screenpeek = connectpoint2[screenpeek]; + if (screenpeek < 0) screenpeek = connecthead; + drawstatusbar(screenpeek); // Andy did this + } - for(i=7;i>=0;i--) - if (keystatus[i+2]) - { keystatus[i+2] = 0; locselectedgun = i; break; } - } + for(i=7;i>=0;i--) + if (keystatus[i+2]) + { keystatus[i+2] = 0; locselectedgun = i; break; } + } - //KEYTIMERSTUFF - if (!keystatus[keys[5]]) - { - if (keystatus[keys[2]]) avel = max(avel-16*TICSPERFRAME,-128); - if (keystatus[keys[3]]) avel = min(avel+16*TICSPERFRAME,127); - } - else - { - if (keystatus[keys[2]]) svel = min(svel+8*TICSPERFRAME,127); - if (keystatus[keys[3]]) svel = max(svel-8*TICSPERFRAME,-128); - } - if (keystatus[keys[0]]) fvel = min(fvel+8*TICSPERFRAME,127); - if (keystatus[keys[1]]) fvel = max(fvel-8*TICSPERFRAME,-128); - if (keystatus[keys[12]]) svel = min(svel+8*TICSPERFRAME,127); - if (keystatus[keys[13]]) svel = max(svel-8*TICSPERFRAME,-128); + //KEYTIMERSTUFF + if (!keystatus[keys[5]]) + { + if (keystatus[keys[2]]) avel = max(avel-16*TICSPERFRAME,-128); + if (keystatus[keys[3]]) avel = min(avel+16*TICSPERFRAME,127); + } + else + { + if (keystatus[keys[2]]) svel = min(svel+8*TICSPERFRAME,127); + if (keystatus[keys[3]]) svel = max(svel-8*TICSPERFRAME,-128); + } + if (keystatus[keys[0]]) fvel = min(fvel+8*TICSPERFRAME,127); + if (keystatus[keys[1]]) fvel = max(fvel-8*TICSPERFRAME,-128); + if (keystatus[keys[12]]) svel = min(svel+8*TICSPERFRAME,127); + if (keystatus[keys[13]]) svel = max(svel-8*TICSPERFRAME,-128); - if (avel < 0) avel = min(avel+12*TICSPERFRAME,0); - if (avel > 0) avel = max(avel-12*TICSPERFRAME,0); - if (svel < 0) svel = min(svel+2*TICSPERFRAME,0); - if (svel > 0) svel = max(svel-2*TICSPERFRAME,0); - if (fvel < 0) fvel = min(fvel+2*TICSPERFRAME,0); - if (fvel > 0) fvel = max(fvel-2*TICSPERFRAME,0); + if (avel < 0) avel = min(avel+12*TICSPERFRAME,0); + if (avel > 0) avel = max(avel-12*TICSPERFRAME,0); + if (svel < 0) svel = min(svel+2*TICSPERFRAME,0); + if (svel > 0) svel = max(svel-2*TICSPERFRAME,0); + if (fvel < 0) fvel = min(fvel+2*TICSPERFRAME,0); + if (fvel > 0) fvel = max(fvel-2*TICSPERFRAME,0); - if ((option[4] == 0) && (numplayers >= 2)) - { - if (!keystatus[0x4f]) - { - if (keystatus[0x4b]) avel2 = max(avel2-16*TICSPERFRAME,-128); - if (keystatus[0x4d]) avel2 = min(avel2+16*TICSPERFRAME,127); - } - else - { - if (keystatus[0x4b]) svel2 = min(svel2+8*TICSPERFRAME,127); - if (keystatus[0x4d]) svel2 = max(svel2-8*TICSPERFRAME,-128); - } - if (keystatus[0x48]) fvel2 = min(fvel2+8*TICSPERFRAME,127); - if (keystatus[0x4c]) fvel2 = max(fvel2-8*TICSPERFRAME,-128); + if ((option[4] == 0) && (numplayers >= 2)) + { + if (!keystatus[0x4f]) + { + if (keystatus[0x4b]) avel2 = max(avel2-16*TICSPERFRAME,-128); + if (keystatus[0x4d]) avel2 = min(avel2+16*TICSPERFRAME,127); + } + else + { + if (keystatus[0x4b]) svel2 = min(svel2+8*TICSPERFRAME,127); + if (keystatus[0x4d]) svel2 = max(svel2-8*TICSPERFRAME,-128); + } + if (keystatus[0x48]) fvel2 = min(fvel2+8*TICSPERFRAME,127); + if (keystatus[0x4c]) fvel2 = max(fvel2-8*TICSPERFRAME,-128); - if (avel2 < 0) avel2 = min(avel2+12*TICSPERFRAME,0); - if (avel2 > 0) avel2 = max(avel2-12*TICSPERFRAME,0); - if (svel2 < 0) svel2 = min(svel2+2*TICSPERFRAME,0); - if (svel2 > 0) svel2 = max(svel2-2*TICSPERFRAME,0); - if (fvel2 < 0) fvel2 = min(fvel2+2*TICSPERFRAME,0); - if (fvel2 > 0) fvel2 = max(fvel2-2*TICSPERFRAME,0); - } + if (avel2 < 0) avel2 = min(avel2+12*TICSPERFRAME,0); + if (avel2 > 0) avel2 = max(avel2-12*TICSPERFRAME,0); + if (svel2 < 0) svel2 = min(svel2+2*TICSPERFRAME,0); + if (svel2 > 0) svel2 = max(svel2-2*TICSPERFRAME,0); + if (fvel2 < 0) fvel2 = min(fvel2+2*TICSPERFRAME,0); + if (fvel2 > 0) fvel2 = max(fvel2-2*TICSPERFRAME,0); + } - oscreentilt = screentilt; - if (keystatus[0x1a]) screentilt += ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); - if (keystatus[0x1b]) screentilt -= ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); + oscreentilt = screentilt; + if (keystatus[0x1a]) screentilt += ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); + if (keystatus[0x1b]) screentilt -= ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); - i = (TICSPERFRAME<<1); - while ((screentilt != 0) && (i > 0)) - { screentilt = ((screentilt+ksgn(screentilt-1024))&2047); i--; } - if (keystatus[0x28]) screentilt = 1536; + i = (TICSPERFRAME<<1); + while ((screentilt != 0) && (i > 0)) + { screentilt = ((screentilt+ksgn(screentilt-1024))&2047); i--; } + if (keystatus[0x28]) screentilt = 1536; - loc.fvel = min(max(fvel,-128+8),127-8); - loc.svel = min(max(svel,-128+8),127-8); - loc.avel = min(max(avel,-128+16),127-16); + loc.fvel = min(max(fvel,-128+8),127-8); + loc.svel = min(max(svel,-128+8),127-8); + loc.avel = min(max(avel,-128+16),127-16); - getmousevalues(&mousx,&mousy,&bstatus); - loc.avel = min(max(loc.avel+(mousx<<3),-128),127); - loc.fvel = min(max(loc.fvel-(mousy<<3),-128),127); + getmousevalues(&mousx,&mousy,&bstatus); + loc.avel = min(max(loc.avel+(mousx<<3),-128),127); + loc.fvel = min(max(loc.fvel-(mousy<<3),-128),127); - loc.bits = (locselectedgun<<13); - if (typemode == 0) //if normal game keys active - { - loc.bits |= (keystatus[0x32]<<9); //M (be master) - loc.bits |= ((keystatus[keys[14]]==1)<<12); //Map mode - } - loc.bits |= keystatus[keys[8]]; //Stand high - loc.bits |= (keystatus[keys[9]]<<1); //Stand low - loc.bits |= (keystatus[keys[16]]<<4); //Zoom in - loc.bits |= (keystatus[keys[17]]<<5); //Zoom out - loc.bits |= (keystatus[keys[4]]<<8); //Run - loc.bits |= (keystatus[keys[10]]<<2); //Look up - loc.bits |= (keystatus[keys[11]]<<3); //Look down - loc.bits |= ((keystatus[keys[7]]==1)<<10); //Space - loc.bits |= ((keystatus[keys[6]]==1)<<11); //Shoot - loc.bits |= (((bstatus&6)>(oldmousebstatus&6))<<10); //Space - loc.bits |= (((bstatus&1)>(oldmousebstatus&1))<<11); //Shoot + loc.bits = (locselectedgun<<13); + if (typemode == 0) //if normal game keys active + { + loc.bits |= (keystatus[0x32]<<9); //M (be master) + loc.bits |= ((keystatus[keys[14]]==1)<<12); //Map mode + } + loc.bits |= keystatus[keys[8]]; //Stand high + loc.bits |= (keystatus[keys[9]]<<1); //Stand low + loc.bits |= (keystatus[keys[16]]<<4); //Zoom in + loc.bits |= (keystatus[keys[17]]<<5); //Zoom out + loc.bits |= (keystatus[keys[4]]<<8); //Run + loc.bits |= (keystatus[keys[10]]<<2); //Look up + loc.bits |= (keystatus[keys[11]]<<3); //Look down + loc.bits |= ((keystatus[keys[7]]==1)<<10); //Space + loc.bits |= ((keystatus[keys[6]]==1)<<11); //Shoot + loc.bits |= (((bstatus&6)>(oldmousebstatus&6))<<10); //Space + loc.bits |= (((bstatus&1)>(oldmousebstatus&1))<<11); //Shoot - oldmousebstatus = bstatus; - if (((loc.bits&2048) > 0) && (locselectedgun == 0)) - oldmousebstatus &= ~1; //Allow continous fire with mouse for chain gun + oldmousebstatus = bstatus; + if (((loc.bits&2048) > 0) && (locselectedgun == 0)) + oldmousebstatus &= ~1; //Allow continous fire with mouse for chain gun - //PRIVATE KEYS: -/* if (keystatus[0xb7]) //Printscreen - { - keystatus[0xb7] = 0; - printscreeninterrupt(); - } -*/ - if (keystatus[0x2f]) //V - { - keystatus[0x2f] = 0; - if (cameradist < 0) cameradist = 0; else cameradist = -1; - cameraang = 0; - } + //PRIVATE KEYS: + /* if (keystatus[0xb7]) //Printscreen + { + keystatus[0xb7] = 0; + printscreeninterrupt(); + } + */ + if (keystatus[0x2f]) //V + { + keystatus[0x2f] = 0; + if (cameradist < 0) cameradist = 0; else cameradist = -1; + cameraang = 0; + } - if (typemode == 0) //if normal game keys active - { - if (keystatus[0x19]) //P - { - keystatus[0x19] = 0; - parallaxtype++; - if (parallaxtype > 2) parallaxtype = 0; - } - if (keystatus[0x38]|keystatus[0xb8]) //ALT - { - if (keystatus[0x4a]) // Keypad - - visibility = min(visibility+(visibility>>3),16384); - if (keystatus[0x4e]) // Keypad + - visibility = max(visibility-(visibility>>3),128); - } + if (typemode == 0) //if normal game keys active + { + if (keystatus[0x19]) //P + { + keystatus[0x19] = 0; + parallaxtype++; + if (parallaxtype > 2) parallaxtype = 0; + } + if (keystatus[0x38]|keystatus[0xb8]) //ALT + { + if (keystatus[0x4a]) // Keypad - + visibility = min(visibility+(visibility>>3),16384); + if (keystatus[0x4e]) // Keypad + + visibility = max(visibility-(visibility>>3),128); + } - if (keystatus[keys[18]]) //Typing mode - { - keystatus[keys[18]] = 0; - typemode = 1; - bflushchars(); - keyfifoplc = keyfifoend; //Reset keyboard fifo - } - } - else - { - while ((ch = bgetchar())) - { - if (ch == 8) //Backspace - { - if (typemessageleng == 0) { typemode = 0; break; } - typemessageleng--; - } - else if (ch == 9) // tab - { - keystatus[0xf] = 0; - typemode = 0; - break; - } - else if (ch == 13) //Either ENTER - { - keystatus[0x1c] = 0; keystatus[0x9c] = 0; - if (typemessageleng > 0) - { - packbuf[0] = 2; //Sending text is message type 4 - for(j=typemessageleng-1;j>=0;j--) - packbuf[j+1] = typemessage[j]; + if (keystatus[keys[18]]) //Typing mode + { + keystatus[keys[18]] = 0; + typemode = 1; + bflushchars(); + keyfifoplc = keyfifoend; //Reset keyboard fifo + } + } + else + { + while ((ch = bgetchar())) + { + if (ch == 8) //Backspace + { + if (typemessageleng == 0) { typemode = 0; break; } + typemessageleng--; + } + else if (ch == 9) // tab + { + keystatus[0xf] = 0; + typemode = 0; + break; + } + else if (ch == 13) //Either ENTER + { + keystatus[0x1c] = 0; keystatus[0x9c] = 0; + if (typemessageleng > 0) + { + packbuf[0] = 2; //Sending text is message type 4 + for(j=typemessageleng-1;j>=0;j--) + packbuf[j+1] = typemessage[j]; - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - sendpacket(i,packbuf,typemessageleng+1); + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + sendpacket(i,packbuf,typemessageleng+1); - typemessageleng = 0; - } - typemode = 0; - break; - } - else if ((typemessageleng < 159) && (ch >= 32) && (ch < 128)) - { - typemessage[typemessageleng++] = ch; - } - } - } + typemessageleng = 0; + } + typemode = 0; + break; + } + else if ((typemessageleng < 159) && (ch >= 32) && (ch < 128)) + { + typemessage[typemessageleng++] = ch; + } + } + } } void initplayersprite(short snum) { - long i; + long i; - if (playersprite[snum] >= 0) return; + if (playersprite[snum] >= 0) return; - spawnsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT, - 1+256,0,snum,32,64,64,0,0,PLAYER,ang[snum],0,0,0,snum+4096, - cursectnum[snum],8,0,0,0); + spawnsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT, + 1+256,0,snum,32,64,64,0,0,PLAYER,ang[snum],0,0,0,snum+4096, + cursectnum[snum],8,0,0,0); - switch(snum) - { - case 1: for(i=0;i<32;i++) tempbuf[i+192] = i+128; break; //green->red - case 2: for(i=0;i<32;i++) tempbuf[i+192] = i+32; break; //green->blue - case 3: for(i=0;i<32;i++) tempbuf[i+192] = i+224; break; //green->pink - case 4: for(i=0;i<32;i++) tempbuf[i+192] = i+64; break; //green->brown - case 5: for(i=0;i<32;i++) tempbuf[i+192] = i+96; break; - case 6: for(i=0;i<32;i++) tempbuf[i+192] = i+160; break; - case 7: for(i=0;i<32;i++) tempbuf[i+192] = i+192; break; - default: for(i=0;i<256;i++) tempbuf[i] = i; break; - } - makepalookup(snum,tempbuf,0,0,0,1); + switch(snum) + { + case 1: for(i=0;i<32;i++) tempbuf[i+192] = i+128; break; //green->red + case 2: for(i=0;i<32;i++) tempbuf[i+192] = i+32; break; //green->blue + case 3: for(i=0;i<32;i++) tempbuf[i+192] = i+224; break; //green->pink + case 4: for(i=0;i<32;i++) tempbuf[i+192] = i+64; break; //green->brown + case 5: for(i=0;i<32;i++) tempbuf[i+192] = i+96; break; + case 6: for(i=0;i<32;i++) tempbuf[i+192] = i+160; break; + case 7: for(i=0;i<32;i++) tempbuf[i+192] = i+192; break; + default: for(i=0;i<256;i++) tempbuf[i] = i; break; + } + makepalookup(snum,tempbuf,0,0,0,1); } void playback(void) { - long i, j, k; + long i, j, k; - ready2send = 0; - recstat = 0; i = reccnt; - while (!keystatus[1]) - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } + ready2send = 0; + recstat = 0; i = reccnt; + while (!keystatus[1]) + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } - refreshaudio(); + refreshaudio(); - while (totalclock >= lockclock+TICSPERFRAME) - { - sampletimer(); - if (i >= reccnt) - { - prepareboard(boardfilename); - for(i=connecthead;i>=0;i=connectpoint2[i]) - initplayersprite((short)i); - totalclock = 0; - i = 0; - } + while (totalclock >= lockclock+TICSPERFRAME) + { + sampletimer(); + if (i >= reccnt) + { + prepareboard(boardfilename); + for(i=connecthead;i>=0;i=connectpoint2[i]) + initplayersprite((short)i); + totalclock = 0; + i = 0; + } - k = 0; - for(j=connecthead;j>=0;j=connectpoint2[j]) - { - copybufbyte(&recsync[i][k],&ffsync[j],sizeof(input)); - k++; - } - movethings(); domovethings(); - i++; - } - drawscreen(screenpeek,(totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND))); + k = 0; + for(j=connecthead;j>=0;j=connectpoint2[j]) + { + copybufbyte(&recsync[i][k],&ffsync[j],sizeof(input)); + k++; + } + movethings(); domovethings(); + i++; + } + drawscreen(screenpeek,(totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND))); - if (keystatus[keys[15]]) - { - keystatus[keys[15]] = 0; - screenpeek = connectpoint2[screenpeek]; - if (screenpeek < 0) screenpeek = connecthead; - drawstatusbar(screenpeek); // Andy did this - } - if (keystatus[keys[14]]) - { - keystatus[keys[14]] = 0; - dimensionmode[screenpeek]++; - if (dimensionmode[screenpeek] > 3) dimensionmode[screenpeek] = 1; - } - } + if (keystatus[keys[15]]) + { + keystatus[keys[15]] = 0; + screenpeek = connectpoint2[screenpeek]; + if (screenpeek < 0) screenpeek = connecthead; + drawstatusbar(screenpeek); // Andy did this + } + if (keystatus[keys[14]]) + { + keystatus[keys[14]] = 0; + dimensionmode[screenpeek]++; + if (dimensionmode[screenpeek] > 3) dimensionmode[screenpeek] = 1; + } + } - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); } void setup3dscreen(void) { - long i, dax, day, dax2, day2; + long i, dax, day, dax2, day2; - i = setgamemode(fullscreen,xdimgame,ydimgame,bppgame); - if (i < 0) - { - printf("Error setting video mode.\n"); - sendlogoff(); - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } + i = setgamemode(fullscreen,xdimgame,ydimgame,bppgame); + if (i < 0) + { + printf("Error setting video mode.\n"); + sendlogoff(); + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } - //Make that ugly pink into black in case it ever shows up! - i = 0L; - setpalette(255,1,(char *)&i); - //outp(0x3c8,255); outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); + //Make that ugly pink into black in case it ever shows up! + i = 0L; + setpalette(255,1,(char *)&i); + //outp(0x3c8,255); outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); - screensize = xdim; - if (screensize > xdim) - { - dax = 0; day = 0; - dax2 = xdim-1; day2 = ydim-1; - } - else - { - dax = ((xdim-screensize)>>1); - dax2 = dax+screensize-1; - day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - day2 = day + scale(screensize,ydim-32,xdim)-1; - setview(dax,day,dax2,day2); - } + screensize = xdim; + if (screensize > xdim) + { + dax = 0; day = 0; + dax2 = xdim-1; day2 = ydim-1; + } + else + { + dax = ((xdim-screensize)>>1); + dax2 = dax+screensize-1; + day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + day2 = day + scale(screensize,ydim-32,xdim)-1; + setview(dax,day,dax2,day2); + } - flushperms(); + flushperms(); - if (screensize < xdim) - drawtilebackground(0L,0L,BACKGROUND,8,0L,0L,xdim-1L,ydim-1L,0); //Draw background + if (screensize < xdim) + drawtilebackground(0L,0L,BACKGROUND,8,0L,0L,xdim-1L,ydim-1L,0); //Draw background - if (screensize <= xdim) - { - rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1); - while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1)+320; - while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; - if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; + if (screensize <= xdim) + { + rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1); + while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1)+320; + while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; + if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; - drawstatusbar(screenpeek); // Andy did this - } + drawstatusbar(screenpeek); // Andy did this + } } void findrandomspot(long *x, long *y, short *sectnum) { - short startwall, endwall, s, dasector; - long dax, day, daz, minx, maxx, miny, maxy, cnt; + short startwall, endwall, s, dasector; + long dax, day, daz, minx, maxx, miny, maxy, cnt; - for(cnt=256;cnt>=0;cnt--) - { - do - { - dasector = mulscale16(krand(),numsectors); - } while ((sector[dasector].ceilingz+(8<<8) >= sector[dasector].floorz) || ((sector[dasector].lotag|sector[dasector].hitag) != 0) || ((sector[dasector].floorstat&1) != 0)); + for(cnt=256;cnt>=0;cnt--) + { + do + { + dasector = mulscale16(krand(),numsectors); + } while ((sector[dasector].ceilingz+(8<<8) >= sector[dasector].floorz) || ((sector[dasector].lotag|sector[dasector].hitag) != 0) || ((sector[dasector].floorstat&1) != 0)); - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - if (endwall <= startwall) continue; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + if (endwall <= startwall) continue; - dax = 0L; - day = 0L; - minx = 0x7fffffff; maxx = 0x80000000; - miny = 0x7fffffff; maxy = 0x80000000; + dax = 0L; + day = 0L; + minx = 0x7fffffff; maxx = 0x80000000; + miny = 0x7fffffff; maxy = 0x80000000; - for(s=startwall;s maxx) maxx = wall[s].x; - if (wall[s].y < miny) miny = wall[s].y; - if (wall[s].y > maxy) maxy = wall[s].y; - } + for(s=startwall;s maxx) maxx = wall[s].x; + if (wall[s].y < miny) miny = wall[s].y; + if (wall[s].y > maxy) maxy = wall[s].y; + } - if ((maxx-minx <= 256) || (maxy-miny <= 256)) continue; + if ((maxx-minx <= 256) || (maxy-miny <= 256)) continue; - dax /= (endwall-startwall); - day /= (endwall-startwall); + dax /= (endwall-startwall); + day /= (endwall-startwall); - if (inside(dax,day,dasector) == 0) continue; + if (inside(dax,day,dasector) == 0) continue; - daz = sector[dasector].floorz-(32<<8); - if (pushmove(&dax,&day,&daz,&dasector,128L,4<<8,4<<8,CLIPMASK0) < 0) continue; + daz = sector[dasector].floorz-(32<<8); + if (pushmove(&dax,&day,&daz,&dasector,128L,4<<8,4<<8,CLIPMASK0) < 0) continue; - *x = dax; *y = day; *sectnum = dasector; - return; - } + *x = dax; *y = day; *sectnum = dasector; + return; + } } void warp(long *x, long *y, long *z, short *daang, short *dasector) { - short startwall, endwall, s; - long i, j, dax, day, ox, oy; + short startwall, endwall, s; + long i, j, dax, day, ox, oy; - ox = *x; oy = *y; + ox = *x; oy = *y; - for(i=0;i= warpsectorcnt) i = 0; - } while (sector[warpsectorlist[i]].hitag != j); - *dasector = warpsectorlist[i]; - break; - } + for(i=0;i= warpsectorcnt) i = 0; + } while (sector[warpsectorlist[i]].hitag != j); + *dasector = warpsectorlist[i]; + break; + } - //Find center of sector - startwall = sector[*dasector].wallptr; - endwall = startwall+sector[*dasector].wallnum; - dax = 0L, day = 0L; - for(s=startwall;s= 0) - i = s; - } - *x = dax / (endwall-startwall); - *y = day / (endwall-startwall); - *z = sector[*dasector].floorz-(32<<8); - updatesector(*x,*y,dasector); - dax = ((wall[i].x+wall[wall[i].point2].x)>>1); - day = ((wall[i].y+wall[wall[i].point2].y)>>1); - *daang = getangle(dax-*x,day-*y); + //Find center of sector + startwall = sector[*dasector].wallptr; + endwall = startwall+sector[*dasector].wallnum; + dax = 0L, day = 0L; + for(s=startwall;s= 0) + i = s; + } + *x = dax / (endwall-startwall); + *y = day / (endwall-startwall); + *z = sector[*dasector].floorz-(32<<8); + updatesector(*x,*y,dasector); + dax = ((wall[i].x+wall[wall[i].point2].x)>>1); + day = ((wall[i].y+wall[wall[i].point2].y)>>1); + *daang = getangle(dax-*x,day-*y); - wsayfollow("warp.wav",3072L+(krand()&127)-64,192L,&ox,&oy,0); - wsayfollow("warp.wav",4096L+(krand()&127)-64,256L,x,y,0); + wsayfollow("warp.wav",3072L+(krand()&127)-64,192L,&ox,&oy,0); + wsayfollow("warp.wav",4096L+(krand()&127)-64,256L,x,y,0); } void warpsprite(short spritenum) { - short dasectnum; + short dasectnum; - dasectnum = sprite[spritenum].sectnum; - warp(&sprite[spritenum].x,&sprite[spritenum].y,&sprite[spritenum].z, - &sprite[spritenum].ang,&dasectnum); + dasectnum = sprite[spritenum].sectnum; + warp(&sprite[spritenum].x,&sprite[spritenum].y,&sprite[spritenum].z, + &sprite[spritenum].ang,&dasectnum); - copybuf(&sprite[spritenum].x,&osprite[spritenum].x,3); - changespritesect(spritenum,dasectnum); + copybuf(&sprite[spritenum].x,&osprite[spritenum].x,3); + changespritesect(spritenum,dasectnum); - show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); - if (show2dsector[dasectnum>>3]&(1<<(dasectnum&7))) - show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); + show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); + if (show2dsector[dasectnum>>3]&(1<<(dasectnum&7))) + show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); } void initlava(void) { - long x, y, z, r; + long x, y, z, r; - for(z=0;z<32;z++) lavaradcnt[z] = 0; - for(x=-16;x<=16;x++) - for(y=-16;y<=16;y++) - { - r = ksqrt(x*x + y*y); - lavaradx[r][lavaradcnt[r]] = x; - lavarady[r][lavaradcnt[r]] = y; - lavaradcnt[r]++; - } + for(z=0;z<32;z++) lavaradcnt[z] = 0; + for(x=-16;x<=16;x++) + for(y=-16;y<=16;y++) + { + r = ksqrt(x*x + y*y); + lavaradx[r][lavaradcnt[r]] = x; + lavarady[r][lavaradcnt[r]] = y; + lavaradcnt[r]++; + } - for(z=0;z<16;z++) - lavadropsizlookup[z] = 8 / (ksqrt(z)+1); + for(z=0;z<16;z++) + lavadropsizlookup[z] = 8 / (ksqrt(z)+1); - for(z=0;z>4)&7)-4)+12; + for(z=0;z>4)&7)-4)+12; - lavanumdrops = 0; - lavanumframes = 0; + lavanumdrops = 0; + lavanumframes = 0; } #if defined(NOASM) inline long addlava(long bx) { - char *b = (char *)bx; - return b[-133] + b[-132] + b[-131] + b[1] + b[-1] + b[131] + b[132]; + char *b = (char *)bx; + return b[-133] + b[-132] + b[-131] + b[1] + b[-1] + b[131] + b[132]; } #elif defined(__WATCOMC__) #pragma aux addlava =\ @@ -4929,35 +4929,35 @@ long addlava(long); #elif defined(_MSC_VER) inline long addlava(long b) { - _asm { - mov ebx, b - mov al, byte ptr [ebx-133] - mov dl, byte ptr [ebx-1] - add al, byte ptr [ebx-132] - add dl, byte ptr [ebx+131] - add al, byte ptr [ebx-131] - add dl, byte ptr [ebx+132] - add al, byte ptr [ebx+1] - add al, dl - } -} + _asm { + mov ebx, b + mov al, byte ptr [ebx-133] + mov dl, byte ptr [ebx-1] + add al, byte ptr [ebx-132] + add dl, byte ptr [ebx+131] + add al, byte ptr [ebx-131] + add dl, byte ptr [ebx+132] + add al, byte ptr [ebx+1] + add al, dl + } + } #elif defined(__GNUC__) && defined(__i386__) inline long addlava(long b) { - long r; - __asm__ __volatile__ ( - "movb -133(%%ebx), %%al\n\t" - "movb -1(%%ebx), %%dl\n\t" - "addb -132(%%ebx), %%al\n\t" - "addb 131(%%ebx), %%dl\n\t" - "addb -131(%%ebx), %%al\n\t" - "addb 132(%%ebx), %%dl\n\t" - "addb 1(%%ebx), %%al\n\t" - "addb %%dl, %%al" - : "=a" (r) : "b" (b) - : "dx" - ); - return r; + long r; + __asm__ __volatile__ ( + "movb -133(%%ebx), %%al\n\t" + "movb -1(%%ebx), %%dl\n\t" + "addb -132(%%ebx), %%al\n\t" + "addb 131(%%ebx), %%dl\n\t" + "addb -131(%%ebx), %%al\n\t" + "addb 132(%%ebx), %%dl\n\t" + "addb 1(%%ebx), %%al\n\t" + "addb %%dl, %%al" + : "=a" (r) : "b" (b) + : "dx" + ); + return r; } #else #error Unsupported compiler or architecture @@ -4965,1330 +4965,1330 @@ inline long addlava(long b) void movelava(char *dapic) { - long i, j, x, y, z, zz, dalavadropsiz, dadropsizlookup; - long dalavax, dalavay, *ptr, *ptr2; + long i, j, x, y, z, zz, dalavadropsiz, dadropsizlookup; + long dalavax, dalavay, *ptr, *ptr2; - for(z=min(LAVAMAXDROPS-lavanumdrops-1,3);z>=0;z--) - { - lavadropx[lavanumdrops] = (Brand()&(LAVASIZ-1)); - lavadropy[lavanumdrops] = (Brand()&(LAVASIZ-1)); - lavadropsiz[lavanumdrops] = 1; - lavanumdrops++; - } + for(z=min(LAVAMAXDROPS-lavanumdrops-1,3);z>=0;z--) + { + lavadropx[lavanumdrops] = (Brand()&(LAVASIZ-1)); + lavadropy[lavanumdrops] = (Brand()&(LAVASIZ-1)); + lavadropsiz[lavanumdrops] = 1; + lavanumdrops++; + } - for(z=lavanumdrops-1;z>=0;z--) - { - dadropsizlookup = lavadropsizlookup[lavadropsiz[z]]*(((z&1)<<1)-1); - dalavadropsiz = lavadropsiz[z]; - dalavax = lavadropx[z]; dalavay = lavadropy[z]; - for(zz=lavaradcnt[lavadropsiz[z]]-1;zz>=0;zz--) - { - i = (((lavaradx[dalavadropsiz][zz]+dalavax)&(LAVASIZ-1))<=0;z--) + { + dadropsizlookup = lavadropsizlookup[lavadropsiz[z]]*(((z&1)<<1)-1); + dalavadropsiz = lavadropsiz[z]; + dalavax = lavadropx[z]; dalavay = lavadropy[z]; + for(zz=lavaradcnt[lavadropsiz[z]]-1;zz>=0;zz--) + { + i = (((lavaradx[dalavadropsiz][zz]+dalavax)&(LAVASIZ-1))< 10) - { - lavanumdrops--; - lavadropx[z] = lavadropx[lavanumdrops]; - lavadropy[z] = lavadropy[lavanumdrops]; - lavadropsiz[z] = lavadropsiz[lavanumdrops]; - } - } + lavadropsiz[z]++; + if (lavadropsiz[z] > 10) + { + lavanumdrops--; + lavadropx[z] = lavadropx[lavanumdrops]; + lavadropy[z] = lavadropy[lavanumdrops]; + lavadropsiz[z] = lavadropsiz[lavanumdrops]; + } + } - //Back up dapic with 1 pixel extra on each boundary - //(to prevent anding for wrap-around) - ptr = (long *)dapic; - ptr2 = (long *)((LAVASIZ+4)+1+((long)lavabakpic)); - for(x=0;x>2);y>0;y--) *ptr2++ = ((*ptr++)&0x1f1f1f1f); - ptr2++; - } - for(y=0;y>2);y>0;y--) *ptr2++ = ((*ptr++)&0x1f1f1f1f); + ptr2++; + } + for(y=0;y>3)+ - ((addlava(y+1)&0xf8)<<5)+ - ((addlava(y+2)&0xf8)<<13)+ - ((addlava(y+3)&0xf8)<<21)+ - 0xc2c2c2c2; - } - } + ptr = (long *)dapic; + for(x=0;x>3)+ + ((addlava(y+1)&0xf8)<<5)+ + ((addlava(y+2)&0xf8)<<13)+ + ((addlava(y+3)&0xf8)<<21)+ + 0xc2c2c2c2; + } + } - lavanumframes++; + lavanumframes++; } void doanimations(void) { - long i, j; + long i, j; - for(i=animatecnt-1;i>=0;i--) - { - j = *animateptr[i]; + for(i=animatecnt-1;i>=0;i--) + { + j = *animateptr[i]; - if (j < animategoal[i]) - j = min(j+animatevel[i]*TICSPERFRAME,animategoal[i]); - else - j = max(j-animatevel[i]*TICSPERFRAME,animategoal[i]); - animatevel[i] += animateacc[i]; + if (j < animategoal[i]) + j = min(j+animatevel[i]*TICSPERFRAME,animategoal[i]); + else + j = max(j-animatevel[i]*TICSPERFRAME,animategoal[i]); + animatevel[i] += animateacc[i]; - *animateptr[i] = j; + *animateptr[i] = j; - if (j == animategoal[i]) - { - animatecnt--; - if (i != animatecnt) - { - stopinterpolation(animateptr[i]); - animateptr[i] = animateptr[animatecnt]; - animategoal[i] = animategoal[animatecnt]; - animatevel[i] = animatevel[animatecnt]; - animateacc[i] = animateacc[animatecnt]; - } - } - } + if (j == animategoal[i]) + { + animatecnt--; + if (i != animatecnt) + { + stopinterpolation(animateptr[i]); + animateptr[i] = animateptr[animatecnt]; + animategoal[i] = animategoal[animatecnt]; + animatevel[i] = animatevel[animatecnt]; + animateacc[i] = animateacc[animatecnt]; + } + } + } } long getanimationgoal(long animptr) { - long i; + long i; - for(i=animatecnt-1;i>=0;i--) - if ((long *)animptr == animateptr[i]) return(i); - return(-1); + for(i=animatecnt-1;i>=0;i--) + if ((long *)animptr == animateptr[i]) return(i); + return(-1); } long setanimation(long *animptr, long thegoal, long thevel, long theacc) { - long i, j; + long i, j; - if (animatecnt >= MAXANIMATES) return(-1); + if (animatecnt >= MAXANIMATES) return(-1); - j = animatecnt; - for(i=animatecnt-1;i>=0;i--) - if (animptr == animateptr[i]) - { j = i; break; } + j = animatecnt; + for(i=animatecnt-1;i>=0;i--) + if (animptr == animateptr[i]) + { j = i; break; } - setinterpolation(animptr); + setinterpolation(animptr); - animateptr[j] = animptr; - animategoal[j] = thegoal; - animatevel[j] = thevel; - animateacc[j] = theacc; - if (j == animatecnt) animatecnt++; - return(j); + animateptr[j] = animptr; + animategoal[j] = thegoal; + animatevel[j] = thevel; + animateacc[j] = theacc; + if (j == animatecnt) animatecnt++; + return(j); } void checkmasterslaveswitch(void) { - long i, j; + long i, j; - if (option[4] == 0) return; + if (option[4] == 0) return; - j = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (ssync[i].bits&512) j++; - if (j != 1) return; + j = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (ssync[i].bits&512) j++; + if (j != 1) return; - i = connecthead; - for(j=connectpoint2[i];j>=0;j=connectpoint2[j]) - { - if (ssync[j].bits&512) - { - connectpoint2[i] = connectpoint2[j]; - connectpoint2[j] = connecthead; - connecthead = (short)j; + i = connecthead; + for(j=connectpoint2[i];j>=0;j=connectpoint2[j]) + { + if (ssync[j].bits&512) + { + connectpoint2[i] = connectpoint2[j]; + connectpoint2[j] = connecthead; + connecthead = (short)j; - oloc.fvel = loc.fvel+1; - oloc.svel = loc.svel+1; - oloc.avel = loc.avel+1; - oloc.bits = loc.bits+1; - for(i=0;i=0;i=connectpoint2[i]) - { - if (myconnectindex == i) break; - j++; - } - if (j == 1) - Bstrcpy(getmessage,"Player 1 (Master)"); - else - Bsprintf(getmessage,"Player %ld (Slave)",j); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+120; + j = 1; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (myconnectindex == i) break; + j++; + } + if (j == 1) + Bstrcpy(getmessage,"Player 1 (Master)"); + else + Bsprintf(getmessage,"Player %ld (Slave)",j); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+120; - return; - } - i = j; - } + return; + } + i = j; + } } long testneighborsectors(short sect1, short sect2) { - short i, startwall, num1, num2; + short i, startwall, num1, num2; - num1 = sector[sect1].wallnum; - num2 = sector[sect2].wallnum; - if (num1 < num2) //Traverse walls of sector with fewest walls (for speed) - { - startwall = sector[sect1].wallptr; - for(i=num1-1;i>=0;i--) - if (wall[i+startwall].nextsector == sect2) - return(1); - } - else - { - startwall = sector[sect2].wallptr; - for(i=num2-1;i>=0;i--) - if (wall[i+startwall].nextsector == sect1) - return(1); - } - return(0); + num1 = sector[sect1].wallnum; + num2 = sector[sect2].wallnum; + if (num1 < num2) //Traverse walls of sector with fewest walls (for speed) + { + startwall = sector[sect1].wallptr; + for(i=num1-1;i>=0;i--) + if (wall[i+startwall].nextsector == sect2) + return(1); + } + else + { + startwall = sector[sect2].wallptr; + for(i=num2-1;i>=0;i--) + if (wall[i+startwall].nextsector == sect1) + return(1); + } + return(0); } long loadgame(void) { - long i; - long fil; + long i; + long fil; - if ((fil = kopen4load("save0000.gam",0)) == -1) return(-1); + if ((fil = kopen4load("save0000.gam",0)) == -1) return(-1); - kdfread(&numplayers,4,1,fil); - kdfread(&myconnectindex,4,1,fil); - kdfread(&connecthead,4,1,fil); - kdfread(connectpoint2,4,MAXPLAYERS,fil); + kdfread(&numplayers,4,1,fil); + kdfread(&myconnectindex,4,1,fil); + kdfread(&connecthead,4,1,fil); + kdfread(connectpoint2,4,MAXPLAYERS,fil); - //Make sure palookups get set, sprites will get overwritten later - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + //Make sure palookups get set, sprites will get overwritten later + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - kdfread(posx,4,MAXPLAYERS,fil); - kdfread(posy,4,MAXPLAYERS,fil); - kdfread(posz,4,MAXPLAYERS,fil); - kdfread(horiz,4,MAXPLAYERS,fil); - kdfread(zoom,4,MAXPLAYERS,fil); - kdfread(hvel,4,MAXPLAYERS,fil); - kdfread(ang,2,MAXPLAYERS,fil); - kdfread(cursectnum,2,MAXPLAYERS,fil); - kdfread(ocursectnum,2,MAXPLAYERS,fil); - kdfread(playersprite,2,MAXPLAYERS,fil); - kdfread(deaths,2,MAXPLAYERS,fil); - kdfread(lastchaingun,4,MAXPLAYERS,fil); - kdfread(health,4,MAXPLAYERS,fil); - kdfread(numgrabbers,2,MAXPLAYERS,fil); - kdfread(nummissiles,2,MAXPLAYERS,fil); - kdfread(numbombs,2,MAXPLAYERS,fil); - kdfread(flytime,4,MAXPLAYERS,fil); - kdfread(oflags,2,MAXPLAYERS,fil); - kdfread(dimensionmode,1,MAXPLAYERS,fil); - kdfread(revolvedoorstat,1,MAXPLAYERS,fil); - kdfread(revolvedoorang,2,MAXPLAYERS,fil); - kdfread(revolvedoorrotang,2,MAXPLAYERS,fil); - kdfread(revolvedoorx,4,MAXPLAYERS,fil); - kdfread(revolvedoory,4,MAXPLAYERS,fil); + kdfread(posx,4,MAXPLAYERS,fil); + kdfread(posy,4,MAXPLAYERS,fil); + kdfread(posz,4,MAXPLAYERS,fil); + kdfread(horiz,4,MAXPLAYERS,fil); + kdfread(zoom,4,MAXPLAYERS,fil); + kdfread(hvel,4,MAXPLAYERS,fil); + kdfread(ang,2,MAXPLAYERS,fil); + kdfread(cursectnum,2,MAXPLAYERS,fil); + kdfread(ocursectnum,2,MAXPLAYERS,fil); + kdfread(playersprite,2,MAXPLAYERS,fil); + kdfread(deaths,2,MAXPLAYERS,fil); + kdfread(lastchaingun,4,MAXPLAYERS,fil); + kdfread(health,4,MAXPLAYERS,fil); + kdfread(numgrabbers,2,MAXPLAYERS,fil); + kdfread(nummissiles,2,MAXPLAYERS,fil); + kdfread(numbombs,2,MAXPLAYERS,fil); + kdfread(flytime,4,MAXPLAYERS,fil); + kdfread(oflags,2,MAXPLAYERS,fil); + kdfread(dimensionmode,1,MAXPLAYERS,fil); + kdfread(revolvedoorstat,1,MAXPLAYERS,fil); + kdfread(revolvedoorang,2,MAXPLAYERS,fil); + kdfread(revolvedoorrotang,2,MAXPLAYERS,fil); + kdfread(revolvedoorx,4,MAXPLAYERS,fil); + kdfread(revolvedoory,4,MAXPLAYERS,fil); - kdfread(&numsectors,2,1,fil); - kdfread(sector,sizeof(sectortype),numsectors,fil); - kdfread(&numwalls,2,1,fil); - kdfread(wall,sizeof(walltype),numwalls,fil); - //Store all sprites (even holes) to preserve indeces - kdfread(sprite,sizeof(spritetype),MAXSPRITES,fil); - kdfread(headspritesect,2,MAXSECTORS+1,fil); - kdfread(prevspritesect,2,MAXSPRITES,fil); - kdfread(nextspritesect,2,MAXSPRITES,fil); - kdfread(headspritestat,2,MAXSTATUS+1,fil); - kdfread(prevspritestat,2,MAXSPRITES,fil); - kdfread(nextspritestat,2,MAXSPRITES,fil); + kdfread(&numsectors,2,1,fil); + kdfread(sector,sizeof(sectortype),numsectors,fil); + kdfread(&numwalls,2,1,fil); + kdfread(wall,sizeof(walltype),numwalls,fil); + //Store all sprites (even holes) to preserve indeces + kdfread(sprite,sizeof(spritetype),MAXSPRITES,fil); + kdfread(headspritesect,2,MAXSECTORS+1,fil); + kdfread(prevspritesect,2,MAXSPRITES,fil); + kdfread(nextspritesect,2,MAXSPRITES,fil); + kdfread(headspritestat,2,MAXSTATUS+1,fil); + kdfread(prevspritestat,2,MAXSPRITES,fil); + kdfread(nextspritestat,2,MAXSPRITES,fil); - kdfread(&fvel,4,1,fil); - kdfread(&svel,4,1,fil); - kdfread(&avel,4,1,fil); + kdfread(&fvel,4,1,fil); + kdfread(&svel,4,1,fil); + kdfread(&avel,4,1,fil); - kdfread(&locselectedgun,4,1,fil); - kdfread(&loc.fvel,1,1,fil); - kdfread(&oloc.fvel,1,1,fil); - kdfread(&loc.svel,1,1,fil); - kdfread(&oloc.svel,1,1,fil); - kdfread(&loc.avel,1,1,fil); - kdfread(&oloc.avel,1,1,fil); - kdfread(&loc.bits,2,1,fil); - kdfread(&oloc.bits,2,1,fil); + kdfread(&locselectedgun,4,1,fil); + kdfread(&loc.fvel,1,1,fil); + kdfread(&oloc.fvel,1,1,fil); + kdfread(&loc.svel,1,1,fil); + kdfread(&oloc.svel,1,1,fil); + kdfread(&loc.avel,1,1,fil); + kdfread(&oloc.avel,1,1,fil); + kdfread(&loc.bits,2,1,fil); + kdfread(&oloc.bits,2,1,fil); - kdfread(&locselectedgun2,4,1,fil); - kdfread(&loc2.fvel,sizeof(input),1,fil); + kdfread(&locselectedgun2,4,1,fil); + kdfread(&loc2.fvel,sizeof(input),1,fil); - kdfread(ssync,sizeof(input),MAXPLAYERS,fil); - kdfread(osync,sizeof(input),MAXPLAYERS,fil); + kdfread(ssync,sizeof(input),MAXPLAYERS,fil); + kdfread(osync,sizeof(input),MAXPLAYERS,fil); - kdfread(boardfilename,1,80,fil); - kdfread(&screenpeek,2,1,fil); - kdfread(&oldmousebstatus,2,1,fil); - kdfread(&brightness,2,1,fil); - kdfread(&neartagsector,2,1,fil); - kdfread(&neartagwall,2,1,fil); - kdfread(&neartagsprite,2,1,fil); - kdfread(&lockclock,4,1,fil); - kdfread(&neartagdist,4,1,fil); - kdfread(&neartaghitdist,4,1,fil); + kdfread(boardfilename,1,80,fil); + kdfread(&screenpeek,2,1,fil); + kdfread(&oldmousebstatus,2,1,fil); + kdfread(&brightness,2,1,fil); + kdfread(&neartagsector,2,1,fil); + kdfread(&neartagwall,2,1,fil); + kdfread(&neartagsprite,2,1,fil); + kdfread(&lockclock,4,1,fil); + kdfread(&neartagdist,4,1,fil); + kdfread(&neartaghitdist,4,1,fil); - kdfread(turnspritelist,2,16,fil); - kdfread(&turnspritecnt,2,1,fil); - kdfread(warpsectorlist,2,16,fil); - kdfread(&warpsectorcnt,2,1,fil); - kdfread(xpanningsectorlist,2,16,fil); - kdfread(&xpanningsectorcnt,2,1,fil); - kdfread(ypanningwalllist,2,64,fil); - kdfread(&ypanningwallcnt,2,1,fil); - kdfread(floorpanninglist,2,64,fil); - kdfread(&floorpanningcnt,2,1,fil); - kdfread(dragsectorlist,2,16,fil); - kdfread(dragxdir,2,16,fil); - kdfread(dragydir,2,16,fil); - kdfread(&dragsectorcnt,2,1,fil); - kdfread(dragx1,4,16,fil); - kdfread(dragy1,4,16,fil); - kdfread(dragx2,4,16,fil); - kdfread(dragy2,4,16,fil); - kdfread(dragfloorz,4,16,fil); - kdfread(&swingcnt,2,1,fil); - kdfread(swingwall,2,32*5,fil); - kdfread(swingsector,2,32,fil); - kdfread(swingangopen,2,32,fil); - kdfread(swingangclosed,2,32,fil); - kdfread(swingangopendir,2,32,fil); - kdfread(swingang,2,32,fil); - kdfread(swinganginc,2,32,fil); - kdfread(swingx,4,32*8,fil); - kdfread(swingy,4,32*8,fil); - kdfread(revolvesector,2,4,fil); - kdfread(revolveang,2,4,fil); - kdfread(&revolvecnt,2,1,fil); - kdfread(revolvex,4,4*16,fil); - kdfread(revolvey,4,4*16,fil); - kdfread(revolvepivotx,4,4,fil); - kdfread(revolvepivoty,4,4,fil); - kdfread(subwaytracksector,2,4*128,fil); - kdfread(subwaynumsectors,2,4,fil); - kdfread(&subwaytrackcnt,2,1,fil); - kdfread(subwaystop,4,4*8,fil); - kdfread(subwaystopcnt,4,4,fil); - kdfread(subwaytrackx1,4,4,fil); - kdfread(subwaytracky1,4,4,fil); - kdfread(subwaytrackx2,4,4,fil); - kdfread(subwaytracky2,4,4,fil); - kdfread(subwayx,4,4,fil); - kdfread(subwaygoalstop,4,4,fil); - kdfread(subwayvel,4,4,fil); - kdfread(subwaypausetime,4,4,fil); - kdfread(waterfountainwall,2,MAXPLAYERS,fil); - kdfread(waterfountaincnt,2,MAXPLAYERS,fil); - kdfread(slimesoundcnt,2,MAXPLAYERS,fil); + kdfread(turnspritelist,2,16,fil); + kdfread(&turnspritecnt,2,1,fil); + kdfread(warpsectorlist,2,16,fil); + kdfread(&warpsectorcnt,2,1,fil); + kdfread(xpanningsectorlist,2,16,fil); + kdfread(&xpanningsectorcnt,2,1,fil); + kdfread(ypanningwalllist,2,64,fil); + kdfread(&ypanningwallcnt,2,1,fil); + kdfread(floorpanninglist,2,64,fil); + kdfread(&floorpanningcnt,2,1,fil); + kdfread(dragsectorlist,2,16,fil); + kdfread(dragxdir,2,16,fil); + kdfread(dragydir,2,16,fil); + kdfread(&dragsectorcnt,2,1,fil); + kdfread(dragx1,4,16,fil); + kdfread(dragy1,4,16,fil); + kdfread(dragx2,4,16,fil); + kdfread(dragy2,4,16,fil); + kdfread(dragfloorz,4,16,fil); + kdfread(&swingcnt,2,1,fil); + kdfread(swingwall,2,32*5,fil); + kdfread(swingsector,2,32,fil); + kdfread(swingangopen,2,32,fil); + kdfread(swingangclosed,2,32,fil); + kdfread(swingangopendir,2,32,fil); + kdfread(swingang,2,32,fil); + kdfread(swinganginc,2,32,fil); + kdfread(swingx,4,32*8,fil); + kdfread(swingy,4,32*8,fil); + kdfread(revolvesector,2,4,fil); + kdfread(revolveang,2,4,fil); + kdfread(&revolvecnt,2,1,fil); + kdfread(revolvex,4,4*16,fil); + kdfread(revolvey,4,4*16,fil); + kdfread(revolvepivotx,4,4,fil); + kdfread(revolvepivoty,4,4,fil); + kdfread(subwaytracksector,2,4*128,fil); + kdfread(subwaynumsectors,2,4,fil); + kdfread(&subwaytrackcnt,2,1,fil); + kdfread(subwaystop,4,4*8,fil); + kdfread(subwaystopcnt,4,4,fil); + kdfread(subwaytrackx1,4,4,fil); + kdfread(subwaytracky1,4,4,fil); + kdfread(subwaytrackx2,4,4,fil); + kdfread(subwaytracky2,4,4,fil); + kdfread(subwayx,4,4,fil); + kdfread(subwaygoalstop,4,4,fil); + kdfread(subwayvel,4,4,fil); + kdfread(subwaypausetime,4,4,fil); + kdfread(waterfountainwall,2,MAXPLAYERS,fil); + kdfread(waterfountaincnt,2,MAXPLAYERS,fil); + kdfread(slimesoundcnt,2,MAXPLAYERS,fil); - //Warning: only works if all pointers are in sector structures! - kdfread(animateptr,4,MAXANIMATES,fil); - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]+((long)sector)); + //Warning: only works if all pointers are in sector structures! + kdfread(animateptr,4,MAXANIMATES,fil); + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]+((long)sector)); - kdfread(animategoal,4,MAXANIMATES,fil); - kdfread(animatevel,4,MAXANIMATES,fil); - kdfread(animateacc,4,MAXANIMATES,fil); - kdfread(&animatecnt,4,1,fil); + kdfread(animategoal,4,MAXANIMATES,fil); + kdfread(animatevel,4,MAXANIMATES,fil); + kdfread(animateacc,4,MAXANIMATES,fil); + kdfread(&animatecnt,4,1,fil); - kdfread(&totalclock,4,1,fil); - kdfread(&numframes,4,1,fil); - kdfread(&randomseed,4,1,fil); - kdfread(&numpalookups,2,1,fil); + kdfread(&totalclock,4,1,fil); + kdfread(&numframes,4,1,fil); + kdfread(&randomseed,4,1,fil); + kdfread(&numpalookups,2,1,fil); - kdfread(&visibility,4,1,fil); - kdfread(¶llaxvisibility,4,1,fil); - kdfread(¶llaxtype,1,1,fil); - kdfread(¶llaxyoffs,4,1,fil); - kdfread(pskyoff,2,MAXPSKYTILES,fil); - kdfread(&pskybits,2,1,fil); + kdfread(&visibility,4,1,fil); + kdfread(¶llaxvisibility,4,1,fil); + kdfread(¶llaxtype,1,1,fil); + kdfread(¶llaxyoffs,4,1,fil); + kdfread(pskyoff,2,MAXPSKYTILES,fil); + kdfread(&pskybits,2,1,fil); - kdfread(&mirrorcnt,2,1,fil); - kdfread(mirrorwall,2,mirrorcnt,fil); - kdfread(mirrorsector,2,mirrorcnt,fil); + kdfread(&mirrorcnt,2,1,fil); + kdfread(mirrorwall,2,mirrorcnt,fil); + kdfread(mirrorsector,2,mirrorcnt,fil); - //I should save off interpolation list, but they're pointers :( - numinterpolations = 0; - startofdynamicinterpolations = 0; + //I should save off interpolation list, but they're pointers :( + numinterpolations = 0; + startofdynamicinterpolations = 0; - kclose(fil); + kclose(fil); - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - totalclock = lockclock; - ototalclock = lockclock; + totalclock = lockclock; + ototalclock = lockclock; - Bstrcpy(getmessage,"Game loaded."); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - return(0); + Bstrcpy(getmessage,"Game loaded."); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + return(0); } long savegame(void) { - long i; - BFILE *fil; + long i; + BFILE *fil; - if ((fil = Bfopen("save0000.gam","wb")) == 0) return(-1); + if ((fil = Bfopen("save0000.gam","wb")) == 0) return(-1); - dfwrite(&numplayers,4,1,fil); - dfwrite(&myconnectindex,4,1,fil); - dfwrite(&connecthead,4,1,fil); - dfwrite(connectpoint2,4,MAXPLAYERS,fil); + dfwrite(&numplayers,4,1,fil); + dfwrite(&myconnectindex,4,1,fil); + dfwrite(&connecthead,4,1,fil); + dfwrite(connectpoint2,4,MAXPLAYERS,fil); - dfwrite(posx,4,MAXPLAYERS,fil); - dfwrite(posy,4,MAXPLAYERS,fil); - dfwrite(posz,4,MAXPLAYERS,fil); - dfwrite(horiz,4,MAXPLAYERS,fil); - dfwrite(zoom,4,MAXPLAYERS,fil); - dfwrite(hvel,4,MAXPLAYERS,fil); - dfwrite(ang,2,MAXPLAYERS,fil); - dfwrite(cursectnum,2,MAXPLAYERS,fil); - dfwrite(ocursectnum,2,MAXPLAYERS,fil); - dfwrite(playersprite,2,MAXPLAYERS,fil); - dfwrite(deaths,2,MAXPLAYERS,fil); - dfwrite(lastchaingun,4,MAXPLAYERS,fil); - dfwrite(health,4,MAXPLAYERS,fil); - dfwrite(numgrabbers,2,MAXPLAYERS,fil); - dfwrite(nummissiles,2,MAXPLAYERS,fil); - dfwrite(numbombs,2,MAXPLAYERS,fil); - dfwrite(flytime,4,MAXPLAYERS,fil); - dfwrite(oflags,2,MAXPLAYERS,fil); - dfwrite(dimensionmode,1,MAXPLAYERS,fil); - dfwrite(revolvedoorstat,1,MAXPLAYERS,fil); - dfwrite(revolvedoorang,2,MAXPLAYERS,fil); - dfwrite(revolvedoorrotang,2,MAXPLAYERS,fil); - dfwrite(revolvedoorx,4,MAXPLAYERS,fil); - dfwrite(revolvedoory,4,MAXPLAYERS,fil); + dfwrite(posx,4,MAXPLAYERS,fil); + dfwrite(posy,4,MAXPLAYERS,fil); + dfwrite(posz,4,MAXPLAYERS,fil); + dfwrite(horiz,4,MAXPLAYERS,fil); + dfwrite(zoom,4,MAXPLAYERS,fil); + dfwrite(hvel,4,MAXPLAYERS,fil); + dfwrite(ang,2,MAXPLAYERS,fil); + dfwrite(cursectnum,2,MAXPLAYERS,fil); + dfwrite(ocursectnum,2,MAXPLAYERS,fil); + dfwrite(playersprite,2,MAXPLAYERS,fil); + dfwrite(deaths,2,MAXPLAYERS,fil); + dfwrite(lastchaingun,4,MAXPLAYERS,fil); + dfwrite(health,4,MAXPLAYERS,fil); + dfwrite(numgrabbers,2,MAXPLAYERS,fil); + dfwrite(nummissiles,2,MAXPLAYERS,fil); + dfwrite(numbombs,2,MAXPLAYERS,fil); + dfwrite(flytime,4,MAXPLAYERS,fil); + dfwrite(oflags,2,MAXPLAYERS,fil); + dfwrite(dimensionmode,1,MAXPLAYERS,fil); + dfwrite(revolvedoorstat,1,MAXPLAYERS,fil); + dfwrite(revolvedoorang,2,MAXPLAYERS,fil); + dfwrite(revolvedoorrotang,2,MAXPLAYERS,fil); + dfwrite(revolvedoorx,4,MAXPLAYERS,fil); + dfwrite(revolvedoory,4,MAXPLAYERS,fil); - dfwrite(&numsectors,2,1,fil); - dfwrite(sector,sizeof(sectortype),numsectors,fil); - dfwrite(&numwalls,2,1,fil); - dfwrite(wall,sizeof(walltype),numwalls,fil); - //Store all sprites (even holes) to preserve indeces - dfwrite(sprite,sizeof(spritetype),MAXSPRITES,fil); - dfwrite(headspritesect,2,MAXSECTORS+1,fil); - dfwrite(prevspritesect,2,MAXSPRITES,fil); - dfwrite(nextspritesect,2,MAXSPRITES,fil); - dfwrite(headspritestat,2,MAXSTATUS+1,fil); - dfwrite(prevspritestat,2,MAXSPRITES,fil); - dfwrite(nextspritestat,2,MAXSPRITES,fil); + dfwrite(&numsectors,2,1,fil); + dfwrite(sector,sizeof(sectortype),numsectors,fil); + dfwrite(&numwalls,2,1,fil); + dfwrite(wall,sizeof(walltype),numwalls,fil); + //Store all sprites (even holes) to preserve indeces + dfwrite(sprite,sizeof(spritetype),MAXSPRITES,fil); + dfwrite(headspritesect,2,MAXSECTORS+1,fil); + dfwrite(prevspritesect,2,MAXSPRITES,fil); + dfwrite(nextspritesect,2,MAXSPRITES,fil); + dfwrite(headspritestat,2,MAXSTATUS+1,fil); + dfwrite(prevspritestat,2,MAXSPRITES,fil); + dfwrite(nextspritestat,2,MAXSPRITES,fil); - dfwrite(&fvel,4,1,fil); - dfwrite(&svel,4,1,fil); - dfwrite(&avel,4,1,fil); + dfwrite(&fvel,4,1,fil); + dfwrite(&svel,4,1,fil); + dfwrite(&avel,4,1,fil); - dfwrite(&locselectedgun,4,1,fil); - dfwrite(&loc.fvel,1,1,fil); - dfwrite(&oloc.fvel,1,1,fil); - dfwrite(&loc.svel,1,1,fil); - dfwrite(&oloc.svel,1,1,fil); - dfwrite(&loc.avel,1,1,fil); - dfwrite(&oloc.avel,1,1,fil); - dfwrite(&loc.bits,2,1,fil); - dfwrite(&oloc.bits,2,1,fil); + dfwrite(&locselectedgun,4,1,fil); + dfwrite(&loc.fvel,1,1,fil); + dfwrite(&oloc.fvel,1,1,fil); + dfwrite(&loc.svel,1,1,fil); + dfwrite(&oloc.svel,1,1,fil); + dfwrite(&loc.avel,1,1,fil); + dfwrite(&oloc.avel,1,1,fil); + dfwrite(&loc.bits,2,1,fil); + dfwrite(&oloc.bits,2,1,fil); - dfwrite(&locselectedgun2,4,1,fil); - dfwrite(&loc2.fvel,sizeof(input),1,fil); + dfwrite(&locselectedgun2,4,1,fil); + dfwrite(&loc2.fvel,sizeof(input),1,fil); - dfwrite(ssync,sizeof(input),MAXPLAYERS,fil); - dfwrite(osync,sizeof(input),MAXPLAYERS,fil); + dfwrite(ssync,sizeof(input),MAXPLAYERS,fil); + dfwrite(osync,sizeof(input),MAXPLAYERS,fil); - dfwrite(boardfilename,1,80,fil); - dfwrite(&screenpeek,2,1,fil); - dfwrite(&oldmousebstatus,2,1,fil); - dfwrite(&brightness,2,1,fil); - dfwrite(&neartagsector,2,1,fil); - dfwrite(&neartagwall,2,1,fil); - dfwrite(&neartagsprite,2,1,fil); - dfwrite(&lockclock,4,1,fil); - dfwrite(&neartagdist,4,1,fil); - dfwrite(&neartaghitdist,4,1,fil); + dfwrite(boardfilename,1,80,fil); + dfwrite(&screenpeek,2,1,fil); + dfwrite(&oldmousebstatus,2,1,fil); + dfwrite(&brightness,2,1,fil); + dfwrite(&neartagsector,2,1,fil); + dfwrite(&neartagwall,2,1,fil); + dfwrite(&neartagsprite,2,1,fil); + dfwrite(&lockclock,4,1,fil); + dfwrite(&neartagdist,4,1,fil); + dfwrite(&neartaghitdist,4,1,fil); - dfwrite(turnspritelist,2,16,fil); - dfwrite(&turnspritecnt,2,1,fil); - dfwrite(warpsectorlist,2,16,fil); - dfwrite(&warpsectorcnt,2,1,fil); - dfwrite(xpanningsectorlist,2,16,fil); - dfwrite(&xpanningsectorcnt,2,1,fil); - dfwrite(ypanningwalllist,2,64,fil); - dfwrite(&ypanningwallcnt,2,1,fil); - dfwrite(floorpanninglist,2,64,fil); - dfwrite(&floorpanningcnt,2,1,fil); - dfwrite(dragsectorlist,2,16,fil); - dfwrite(dragxdir,2,16,fil); - dfwrite(dragydir,2,16,fil); - dfwrite(&dragsectorcnt,2,1,fil); - dfwrite(dragx1,4,16,fil); - dfwrite(dragy1,4,16,fil); - dfwrite(dragx2,4,16,fil); - dfwrite(dragy2,4,16,fil); - dfwrite(dragfloorz,4,16,fil); - dfwrite(&swingcnt,2,1,fil); - dfwrite(swingwall,2,32*5,fil); - dfwrite(swingsector,2,32,fil); - dfwrite(swingangopen,2,32,fil); - dfwrite(swingangclosed,2,32,fil); - dfwrite(swingangopendir,2,32,fil); - dfwrite(swingang,2,32,fil); - dfwrite(swinganginc,2,32,fil); - dfwrite(swingx,4,32*8,fil); - dfwrite(swingy,4,32*8,fil); - dfwrite(revolvesector,2,4,fil); - dfwrite(revolveang,2,4,fil); - dfwrite(&revolvecnt,2,1,fil); - dfwrite(revolvex,4,4*16,fil); - dfwrite(revolvey,4,4*16,fil); - dfwrite(revolvepivotx,4,4,fil); - dfwrite(revolvepivoty,4,4,fil); - dfwrite(subwaytracksector,2,4*128,fil); - dfwrite(subwaynumsectors,2,4,fil); - dfwrite(&subwaytrackcnt,2,1,fil); - dfwrite(subwaystop,4,4*8,fil); - dfwrite(subwaystopcnt,4,4,fil); - dfwrite(subwaytrackx1,4,4,fil); - dfwrite(subwaytracky1,4,4,fil); - dfwrite(subwaytrackx2,4,4,fil); - dfwrite(subwaytracky2,4,4,fil); - dfwrite(subwayx,4,4,fil); - dfwrite(subwaygoalstop,4,4,fil); - dfwrite(subwayvel,4,4,fil); - dfwrite(subwaypausetime,4,4,fil); - dfwrite(waterfountainwall,2,MAXPLAYERS,fil); - dfwrite(waterfountaincnt,2,MAXPLAYERS,fil); - dfwrite(slimesoundcnt,2,MAXPLAYERS,fil); + dfwrite(turnspritelist,2,16,fil); + dfwrite(&turnspritecnt,2,1,fil); + dfwrite(warpsectorlist,2,16,fil); + dfwrite(&warpsectorcnt,2,1,fil); + dfwrite(xpanningsectorlist,2,16,fil); + dfwrite(&xpanningsectorcnt,2,1,fil); + dfwrite(ypanningwalllist,2,64,fil); + dfwrite(&ypanningwallcnt,2,1,fil); + dfwrite(floorpanninglist,2,64,fil); + dfwrite(&floorpanningcnt,2,1,fil); + dfwrite(dragsectorlist,2,16,fil); + dfwrite(dragxdir,2,16,fil); + dfwrite(dragydir,2,16,fil); + dfwrite(&dragsectorcnt,2,1,fil); + dfwrite(dragx1,4,16,fil); + dfwrite(dragy1,4,16,fil); + dfwrite(dragx2,4,16,fil); + dfwrite(dragy2,4,16,fil); + dfwrite(dragfloorz,4,16,fil); + dfwrite(&swingcnt,2,1,fil); + dfwrite(swingwall,2,32*5,fil); + dfwrite(swingsector,2,32,fil); + dfwrite(swingangopen,2,32,fil); + dfwrite(swingangclosed,2,32,fil); + dfwrite(swingangopendir,2,32,fil); + dfwrite(swingang,2,32,fil); + dfwrite(swinganginc,2,32,fil); + dfwrite(swingx,4,32*8,fil); + dfwrite(swingy,4,32*8,fil); + dfwrite(revolvesector,2,4,fil); + dfwrite(revolveang,2,4,fil); + dfwrite(&revolvecnt,2,1,fil); + dfwrite(revolvex,4,4*16,fil); + dfwrite(revolvey,4,4*16,fil); + dfwrite(revolvepivotx,4,4,fil); + dfwrite(revolvepivoty,4,4,fil); + dfwrite(subwaytracksector,2,4*128,fil); + dfwrite(subwaynumsectors,2,4,fil); + dfwrite(&subwaytrackcnt,2,1,fil); + dfwrite(subwaystop,4,4*8,fil); + dfwrite(subwaystopcnt,4,4,fil); + dfwrite(subwaytrackx1,4,4,fil); + dfwrite(subwaytracky1,4,4,fil); + dfwrite(subwaytrackx2,4,4,fil); + dfwrite(subwaytracky2,4,4,fil); + dfwrite(subwayx,4,4,fil); + dfwrite(subwaygoalstop,4,4,fil); + dfwrite(subwayvel,4,4,fil); + dfwrite(subwaypausetime,4,4,fil); + dfwrite(waterfountainwall,2,MAXPLAYERS,fil); + dfwrite(waterfountaincnt,2,MAXPLAYERS,fil); + dfwrite(slimesoundcnt,2,MAXPLAYERS,fil); - //Warning: only works if all pointers are in sector structures! - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]-((long)sector)); - dfwrite(animateptr,4,MAXANIMATES,fil); - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]+((long)sector)); + //Warning: only works if all pointers are in sector structures! + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]-((long)sector)); + dfwrite(animateptr,4,MAXANIMATES,fil); + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]+((long)sector)); - dfwrite(animategoal,4,MAXANIMATES,fil); - dfwrite(animatevel,4,MAXANIMATES,fil); - dfwrite(animateacc,4,MAXANIMATES,fil); - dfwrite(&animatecnt,4,1,fil); + dfwrite(animategoal,4,MAXANIMATES,fil); + dfwrite(animatevel,4,MAXANIMATES,fil); + dfwrite(animateacc,4,MAXANIMATES,fil); + dfwrite(&animatecnt,4,1,fil); - dfwrite(&totalclock,4,1,fil); - dfwrite(&numframes,4,1,fil); - dfwrite(&randomseed,4,1,fil); - dfwrite(&numpalookups,2,1,fil); + dfwrite(&totalclock,4,1,fil); + dfwrite(&numframes,4,1,fil); + dfwrite(&randomseed,4,1,fil); + dfwrite(&numpalookups,2,1,fil); - dfwrite(&visibility,4,1,fil); - dfwrite(¶llaxvisibility,4,1,fil); - dfwrite(¶llaxtype,1,1,fil); - dfwrite(¶llaxyoffs,4,1,fil); - dfwrite(pskyoff,2,MAXPSKYTILES,fil); - dfwrite(&pskybits,2,1,fil); + dfwrite(&visibility,4,1,fil); + dfwrite(¶llaxvisibility,4,1,fil); + dfwrite(¶llaxtype,1,1,fil); + dfwrite(¶llaxyoffs,4,1,fil); + dfwrite(pskyoff,2,MAXPSKYTILES,fil); + dfwrite(&pskybits,2,1,fil); - dfwrite(&mirrorcnt,2,1,fil); - dfwrite(mirrorwall,2,mirrorcnt,fil); - dfwrite(mirrorsector,2,mirrorcnt,fil); + dfwrite(&mirrorcnt,2,1,fil); + dfwrite(mirrorwall,2,mirrorcnt,fil); + dfwrite(mirrorsector,2,mirrorcnt,fil); - Bfclose(fil); + Bfclose(fil); - Bstrcpy(getmessage,"Game saved."); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - return(0); + Bstrcpy(getmessage,"Game saved."); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + return(0); } void faketimerhandler(void) { - short other, packbufleng; - long i, j, k, l; + short other, packbufleng; + long i, j, k, l; - sampletimer(); - if ((totalclock < ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) || (ready2send == 0)) return; - ototalclock += (TIMERINTSPERSECOND/MOVESPERSECOND); + sampletimer(); + if ((totalclock < ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) || (ready2send == 0)) return; + ototalclock += (TIMERINTSPERSECOND/MOVESPERSECOND); - getpackets(); - if (getoutputcirclesize() >= 16) return; - getinput(); + getpackets(); + if (getoutputcirclesize() >= 16) return; + getinput(); - /* - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - { - k = (movefifoend[myconnectindex]-1)-movefifoend[i]; - myminlag[i] = min(myminlag[i],k); - mymaxlag = max(mymaxlag,k); - } + /* + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + { + k = (movefifoend[myconnectindex]-1)-movefifoend[i]; + myminlag[i] = min(myminlag[i],k); + mymaxlag = max(mymaxlag,k); + } - if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0) - { - i = mymaxlag-bufferjitter; mymaxlag = 0; - if (i > 0) bufferjitter += ((2+i)>>2); - else if (i < 0) bufferjitter -= ((2-i)>>2); - } - */ + if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0) + { + i = mymaxlag-bufferjitter; mymaxlag = 0; + if (i > 0) bufferjitter += ((2+i)>>2); + else if (i < 0) bufferjitter -= ((2-i)>>2); + } + */ - if (networkmode == 1) - { - packbuf[2] = 0; j = 3; - if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[2] |= 1; - if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[2] |= 2; - if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[2] |= 4; - if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[2] |= 8; - if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[2] |= 16; - copybufbyte(&loc,&oloc,sizeof(input)); + if (networkmode == 1) + { + packbuf[2] = 0; j = 3; + if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[2] |= 1; + if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[2] |= 2; + if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[2] |= 4; + if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[2] |= 8; + if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[2] |= 16; + copybufbyte(&loc,&oloc,sizeof(input)); - copybufbyte(&loc,&baksync[movefifoend[myconnectindex]][myconnectindex],sizeof(input)); - movefifoend[myconnectindex] = ((movefifoend[myconnectindex]+1)&(MOVEFIFOSIZ-1)); + copybufbyte(&loc,&baksync[movefifoend[myconnectindex]][myconnectindex],sizeof(input)); + movefifoend[myconnectindex] = ((movefifoend[myconnectindex]+1)&(MOVEFIFOSIZ-1)); - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - { - packbuf[0] = 17; - packbuf[1] = (char)((movefifoend[myconnectindex]-movefifoend[i])&(MOVEFIFOSIZ-1)); + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + { + packbuf[0] = 17; + packbuf[1] = (char)((movefifoend[myconnectindex]-movefifoend[i])&(MOVEFIFOSIZ-1)); - k = j; - if ((myconnectindex == connecthead) || ((i == connecthead) && (myconnectindex == connectpoint2[connecthead]))) - { - while (syncvalhead != syncvaltail) - { - packbuf[j++] = syncval[syncvaltail]; - syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); - } - } - sendpacket(i,packbuf,j); - j = k; - } + k = j; + if ((myconnectindex == connecthead) || ((i == connecthead) && (myconnectindex == connectpoint2[connecthead]))) + { + while (syncvalhead != syncvaltail) + { + packbuf[j++] = syncval[syncvaltail]; + syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); + } + } + sendpacket(i,packbuf,j); + j = k; + } - gotlastpacketclock = totalclock; - return; - } + gotlastpacketclock = totalclock; + return; + } - //MASTER (or 1 player game) - if ((myconnectindex == connecthead) || (option[4] == 0)) - { - copybufbyte(&loc,&ffsync[myconnectindex],sizeof(input)); + //MASTER (or 1 player game) + if ((myconnectindex == connecthead) || (option[4] == 0)) + { + copybufbyte(&loc,&ffsync[myconnectindex],sizeof(input)); - if (option[4] != 0) - { - packbuf[0] = 0; - j = ((numplayers+1)>>1)+1; - for(k=1;k=0;i=connectpoint2[i]) - { - l = 0; - if (ffsync[i].fvel != osync[i].fvel) packbuf[j++] = ffsync[i].fvel, l |= 1; - if (ffsync[i].svel != osync[i].svel) packbuf[j++] = ffsync[i].svel, l |= 2; - if (ffsync[i].avel != osync[i].avel) packbuf[j++] = ffsync[i].avel, l |= 4; - if (ffsync[i].bits != osync[i].bits) - { - packbuf[j++] = (ffsync[i].bits&255); - packbuf[j++] = ((ffsync[i].bits>>8)&255); - l |= 8; - } - packbuf[k>>3] |= (l<<(k&7)); - k += 4; + if (option[4] != 0) + { + packbuf[0] = 0; + j = ((numplayers+1)>>1)+1; + for(k=1;k=0;i=connectpoint2[i]) + { + l = 0; + if (ffsync[i].fvel != osync[i].fvel) packbuf[j++] = ffsync[i].fvel, l |= 1; + if (ffsync[i].svel != osync[i].svel) packbuf[j++] = ffsync[i].svel, l |= 2; + if (ffsync[i].avel != osync[i].avel) packbuf[j++] = ffsync[i].avel, l |= 4; + if (ffsync[i].bits != osync[i].bits) + { + packbuf[j++] = (ffsync[i].bits&255); + packbuf[j++] = ((ffsync[i].bits>>8)&255); + l |= 8; + } + packbuf[k>>3] |= (l<<(k&7)); + k += 4; - copybufbyte(&ffsync[i],&osync[i],sizeof(input)); - } + copybufbyte(&ffsync[i],&osync[i],sizeof(input)); + } - while (syncvalhead != syncvaltail) - { - packbuf[j++] = syncval[syncvaltail]; - syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); - } + while (syncvalhead != syncvaltail) + { + packbuf[j++] = syncval[syncvaltail]; + syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); + } - for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - sendpacket(i,packbuf,j); - } - else if (numplayers >= 2) - { - if (keystatus[0xb5]) - { - keystatus[0xb5] = 0; - locselectedgun2++; if (locselectedgun2 >= 3) locselectedgun2 = 0; - } + for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) + sendpacket(i,packbuf,j); + } + else if (numplayers >= 2) + { + if (keystatus[0xb5]) + { + keystatus[0xb5] = 0; + locselectedgun2++; if (locselectedgun2 >= 3) locselectedgun2 = 0; + } - //Second player on 1 computer mode - loc2.fvel = min(max(fvel2,-128+8),127-8); - loc2.svel = min(max(svel2,-128+8),127-8); - loc2.avel = min(max(avel2,-128+16),127-16); - loc2.bits = (locselectedgun2<<13); - loc2.bits |= keystatus[0x45]; //Stand high - loc2.bits |= (keystatus[0x47]<<1); //Stand low - loc2.bits |= (1<<8); //Run - loc2.bits |= (keystatus[0x49]<<2); //Look up - loc2.bits |= (keystatus[0x37]<<3); //Look down - loc2.bits |= (keystatus[0x50]<<10); //Space - loc2.bits |= (keystatus[0x52]<<11); //Shoot + //Second player on 1 computer mode + loc2.fvel = min(max(fvel2,-128+8),127-8); + loc2.svel = min(max(svel2,-128+8),127-8); + loc2.avel = min(max(avel2,-128+16),127-16); + loc2.bits = (locselectedgun2<<13); + loc2.bits |= keystatus[0x45]; //Stand high + loc2.bits |= (keystatus[0x47]<<1); //Stand low + loc2.bits |= (1<<8); //Run + loc2.bits |= (keystatus[0x49]<<2); //Look up + loc2.bits |= (keystatus[0x37]<<3); //Look down + loc2.bits |= (keystatus[0x50]<<10); //Space + loc2.bits |= (keystatus[0x52]<<11); //Shoot - other = connectpoint2[myconnectindex]; - if (other < 0) other = connecthead; + other = connectpoint2[myconnectindex]; + if (other < 0) other = connecthead; - copybufbyte(&loc2,&ffsync[other],sizeof(input)); - } - movethings(); //Move EVERYTHING (you too!) - } - else //I am a SLAVE - { - packbuf[0] = 1; packbuf[1] = 0; j = 2; - if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[1] |= 1; - if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[1] |= 2; - if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[1] |= 4; - if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[1] |= 8; - if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[1] |= 16; - copybufbyte(&loc,&oloc,sizeof(input)); - sendpacket(connecthead,packbuf,j); - } + copybufbyte(&loc2,&ffsync[other],sizeof(input)); + } + movethings(); //Move EVERYTHING (you too!) + } + else //I am a SLAVE + { + packbuf[0] = 1; packbuf[1] = 0; j = 2; + if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[1] |= 1; + if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[1] |= 2; + if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[1] |= 4; + if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[1] |= 8; + if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[1] |= 16; + copybufbyte(&loc,&oloc,sizeof(input)); + sendpacket(connecthead,packbuf,j); + } } void getpackets(void) { - long i, j, k, l; - long other, packbufleng, movecnt; + long i, j, k, l; + long other, packbufleng, movecnt; - if (option[4] == 0) return; + if (option[4] == 0) return; - movecnt = 0; - while ((packbufleng = getpacket(&other,packbuf)) > 0) - { - switch(packbuf[0]) - { - case 0: //[0] (receive master sync buffer) - j = ((numplayers+1)>>1)+1; k = (1<<3); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - l = (packbuf[k>>3]>>(k&7)); - if (l&1) ffsync[i].fvel = packbuf[j++]; - if (l&2) ffsync[i].svel = packbuf[j++]; - if (l&4) ffsync[i].avel = packbuf[j++]; - if (l&8) - { - ffsync[i].bits = ((short)packbuf[j])+(((short)packbuf[j+1])<<8); - j += 2; - } - k += 4; - } + movecnt = 0; + while ((packbufleng = getpacket(&other,packbuf)) > 0) + { + switch(packbuf[0]) + { + case 0: //[0] (receive master sync buffer) + j = ((numplayers+1)>>1)+1; k = (1<<3); + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + l = (packbuf[k>>3]>>(k&7)); + if (l&1) ffsync[i].fvel = packbuf[j++]; + if (l&2) ffsync[i].svel = packbuf[j++]; + if (l&4) ffsync[i].avel = packbuf[j++]; + if (l&8) + { + ffsync[i].bits = ((short)packbuf[j])+(((short)packbuf[j+1])<<8); + j += 2; + } + k += 4; + } - while (j != packbufleng) - { - othersyncval[othersyncvalhead] = packbuf[j++]; - othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); - } - if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) - { - syncstat = 0; - do - { - syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); - syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); - } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); - } + while (j != packbufleng) + { + othersyncval[othersyncvalhead] = packbuf[j++]; + othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); + } + if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) + { + syncstat = 0; + do + { + syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); + syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); + } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); + } - movethings(); //Move all players and sprites - movecnt++; - break; - case 1: //[1] (receive slave sync buffer) - j = 2; k = packbuf[1]; - if (k&1) ffsync[other].fvel = packbuf[j++]; - if (k&2) ffsync[other].svel = packbuf[j++]; - if (k&4) ffsync[other].avel = packbuf[j++]; - if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); - if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); - break; - case 2: - getmessageleng = packbufleng-1; - for(j=getmessageleng-1;j>=0;j--) getmessage[j] = packbuf[j+1]; - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - wsay("getstuff.wav",8192L,63L,63L); //Added 12/2004 - break; - case 3: - wsay("getstuff.wav",4096L,63L,63L); - break; - /* - case 5: - playerreadyflag[other] = packbuf[1]; - if ((other == connecthead) && (packbuf[1] == 2)) - sendpacket(connecthead,packbuf,2); - break; - */ - case 250: - playerreadyflag[other]++; - break; - case 17: - j = 3; k = packbuf[2]; - if (k&1) ffsync[other].fvel = packbuf[j++]; - if (k&2) ffsync[other].svel = packbuf[j++]; - if (k&4) ffsync[other].avel = packbuf[j++]; - if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); - if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); - otherlag[other] = packbuf[1]; + movethings(); //Move all players and sprites + movecnt++; + break; + case 1: //[1] (receive slave sync buffer) + j = 2; k = packbuf[1]; + if (k&1) ffsync[other].fvel = packbuf[j++]; + if (k&2) ffsync[other].svel = packbuf[j++]; + if (k&4) ffsync[other].avel = packbuf[j++]; + if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); + if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); + break; + case 2: + getmessageleng = packbufleng-1; + for(j=getmessageleng-1;j>=0;j--) getmessage[j] = packbuf[j+1]; + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + wsay("getstuff.wav",8192L,63L,63L); //Added 12/2004 + break; + case 3: + wsay("getstuff.wav",4096L,63L,63L); + break; + /* + case 5: + playerreadyflag[other] = packbuf[1]; + if ((other == connecthead) && (packbuf[1] == 2)) + sendpacket(connecthead,packbuf,2); + break; + */ + case 250: + playerreadyflag[other]++; + break; + case 17: + j = 3; k = packbuf[2]; + if (k&1) ffsync[other].fvel = packbuf[j++]; + if (k&2) ffsync[other].svel = packbuf[j++]; + if (k&4) ffsync[other].avel = packbuf[j++]; + if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); + if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); + otherlag[other] = packbuf[1]; - copybufbyte(&ffsync[other],&baksync[movefifoend[other]][other],sizeof(input)); - movefifoend[other] = ((movefifoend[other]+1)&(MOVEFIFOSIZ-1)); + copybufbyte(&ffsync[other],&baksync[movefifoend[other]][other],sizeof(input)); + movefifoend[other] = ((movefifoend[other]+1)&(MOVEFIFOSIZ-1)); - while (j != packbufleng) - { - othersyncval[othersyncvalhead] = packbuf[j++]; - othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); - } - if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) - { - syncstat = 0; - do - { - syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); - syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); - } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); - } + while (j != packbufleng) + { + othersyncval[othersyncvalhead] = packbuf[j++]; + othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); + } + if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) + { + syncstat = 0; + do + { + syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); + syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); + } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); + } - break; - case 255: //[255] (logout) - keystatus[1] = 1; - break; - } - } - if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0)) - { - if (rand()&1) ototalclock += (TICSPERFRAME>>1); - else ototalclock -= (TICSPERFRAME>>1); - } + break; + case 255: //[255] (logout) + keystatus[1] = 1; + break; + } + } + if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0)) + { + if (rand()&1) ototalclock += (TICSPERFRAME>>1); + else ototalclock -= (TICSPERFRAME>>1); + } } void drawoverheadmap(long cposx, long cposy, long czoom, short cang) { - long i, j, k, l=0, x1, y1, x2=0, y2=0, x3, y3, x4, y4, ox, oy, xoff, yoff; - long dax, day, cosang, sinang, xspan, yspan, sprx, spry; - long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; - long xvect, yvect, xvect2, yvect2; - char col; - walltype *wal, *wal2; - spritetype *spr; + long i, j, k, l=0, x1, y1, x2=0, y2=0, x3, y3, x4, y4, ox, oy, xoff, yoff; + long dax, day, cosang, sinang, xspan, yspan, sprx, spry; + long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; + long xvect, yvect, xvect2, yvect2; + char col; + walltype *wal, *wal2; + spritetype *spr; - xvect = sintable[(-cang)&2047] * czoom; - yvect = sintable[(1536-cang)&2047] * czoom; - xvect2 = mulscale16(xvect,yxaspect); - yvect2 = mulscale16(yvect,yxaspect); + xvect = sintable[(-cang)&2047] * czoom; + yvect = sintable[(1536-cang)&2047] * czoom; + xvect2 = mulscale16(xvect,yxaspect); + yvect2 = mulscale16(yvect,yxaspect); - //Draw red lines - for(i=0;inextwall; if (k < 0) continue; + for(j=startwall,wal=&wall[startwall];jnextwall; if (k < 0) continue; - if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; - if ((k > j) && ((show2dwall[k>>3]&(1<<(k&7))) > 0)) continue; + if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; + if ((k > j) && ((show2dwall[k>>3]&(1<<(k&7))) > 0)) continue; - if (sector[wal->nextsector].ceilingz == z1) - if (sector[wal->nextsector].floorz == z2) - if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; + if (sector[wal->nextsector].ceilingz == z1) + if (sector[wal->nextsector].floorz == z2) + if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; - col = 152; + col = 152; - if (dimensionmode[screenpeek] == 2) - { - if (sector[i].floorz != sector[i].ceilingz) - if (sector[wal->nextsector].floorz != sector[wal->nextsector].ceilingz) - if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) - if (sector[i].floorz == sector[wal->nextsector].floorz) continue; - if (sector[i].floorpicnum != sector[wal->nextsector].floorpicnum) continue; - if (sector[i].floorshade != sector[wal->nextsector].floorshade) continue; - col = 12; - } + if (dimensionmode[screenpeek] == 2) + { + if (sector[i].floorz != sector[i].ceilingz) + if (sector[wal->nextsector].floorz != sector[wal->nextsector].ceilingz) + if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) + if (sector[i].floorz == sector[wal->nextsector].floorz) continue; + if (sector[i].floorpicnum != sector[wal->nextsector].floorpicnum) continue; + if (sector[i].floorshade != sector[wal->nextsector].floorshade) continue; + col = 12; + } - ox = wal->x-cposx; oy = wal->y-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + ox = wal->x-cposx; oy = wal->y-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - wal2 = &wall[wal->point2]; - ox = wal2->x-cposx; oy = wal2->y-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + wal2 = &wall[wal->point2]; + ox = wal2->x-cposx; oy = wal2->y-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - drawline256(x1,y1,x2,y2,col); - } - } + drawline256(x1,y1,x2,y2,col); + } + } - //Draw sprites - k = playersprite[screenpeek]; - for(i=0;i=0;j=nextspritesect[j]) - if ((show2dsprite[j>>3]&(1<<(j&7))) > 0) - { - spr = &sprite[j]; if (spr->cstat&0x8000) continue; - col = 56; - if (spr->cstat&1) col = 248; - if (j == k) col = 31; + //Draw sprites + k = playersprite[screenpeek]; + for(i=0;i=0;j=nextspritesect[j]) + if ((show2dsprite[j>>3]&(1<<(j&7))) > 0) + { + spr = &sprite[j]; if (spr->cstat&0x8000) continue; + col = 56; + if (spr->cstat&1) col = 248; + if (j == k) col = 31; - k = statrate[spr->statnum]; - sprx = spr->x; - spry = spr->y; - if (k >= 0) - { - switch(k) - { - case 0: l = smoothratio; break; - case 1: l = (smoothratio>>1)+(((nummoves-j)&1)<<15); break; - case 3: l = (smoothratio>>2)+(((nummoves-j)&3)<<14); break; - case 7: l = (smoothratio>>3)+(((nummoves-j)&7)<<13); break; - case 15: l = (smoothratio>>4)+(((nummoves-j)&15)<<12); break; - } - sprx = osprite[j].x+mulscale16(sprx-osprite[j].x,l); - spry = osprite[j].y+mulscale16(spry-osprite[j].y,l); - } + k = statrate[spr->statnum]; + sprx = spr->x; + spry = spr->y; + if (k >= 0) + { + switch(k) + { + case 0: l = smoothratio; break; + case 1: l = (smoothratio>>1)+(((nummoves-j)&1)<<15); break; + case 3: l = (smoothratio>>2)+(((nummoves-j)&3)<<14); break; + case 7: l = (smoothratio>>3)+(((nummoves-j)&7)<<13); break; + case 15: l = (smoothratio>>4)+(((nummoves-j)&15)<<12); break; + } + sprx = osprite[j].x+mulscale16(sprx-osprite[j].x,l); + spry = osprite[j].y+mulscale16(spry-osprite[j].y,l); + } - switch (spr->cstat&48) - { - case 0: - ox = sprx-cposx; oy = spry-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); + switch (spr->cstat&48) + { + case 0: + ox = sprx-cposx; oy = spry-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); - if (dimensionmode[screenpeek] == 1) - { - ox = (sintable[(spr->ang+512)&2047]>>7); - oy = (sintable[(spr->ang)&2047]>>7); - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect,ox,yvect); + if (dimensionmode[screenpeek] == 1) + { + ox = (sintable[(spr->ang+512)&2047]>>7); + oy = (sintable[(spr->ang)&2047]>>7); + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect,ox,yvect); - if (j == playersprite[screenpeek]) - { - x2 = 0L; - y2 = -(czoom<<5); - } + if (j == playersprite[screenpeek]) + { + x2 = 0L; + y2 = -(czoom<<5); + } - x3 = mulscale16(x2,yxaspect); - y3 = mulscale16(y2,yxaspect); + x3 = mulscale16(x2,yxaspect); + y3 = mulscale16(y2,yxaspect); - drawline256(x1-x2+(xdim<<11),y1-y3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - drawline256(x1-y2+(xdim<<11),y1+x3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - drawline256(x1+y2+(xdim<<11),y1-x3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - } - else - { - if (((gotsector[i>>3]&(1<<(i&7))) > 0) && (czoom > 96)) - { - daang = (spr->ang-cang)&2047; - if (j == playersprite[screenpeek]) { x1 = 0; y1 = 0; daang = 0; } - rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),mulscale16(czoom*spr->yrepeat,yxaspect),daang,spr->picnum,spr->shade,spr->pal,(spr->cstat&2)>>1,windowx1,windowy1,windowx2,windowy2); - } - } - break; - case 16: - x1 = sprx; y1 = spry; - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - if ((spr->cstat&4) > 0) xoff = -xoff; - k = spr->ang; l = spr->xrepeat; - dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; - l = tilesizx[tilenum]; k = (l>>1)+xoff; - x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); - y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + drawline256(x1-x2+(xdim<<11),y1-y3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + drawline256(x1-y2+(xdim<<11),y1+x3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + drawline256(x1+y2+(xdim<<11),y1-x3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + } + else + { + if (((gotsector[i>>3]&(1<<(i&7))) > 0) && (czoom > 96)) + { + daang = (spr->ang-cang)&2047; + if (j == playersprite[screenpeek]) { x1 = 0; y1 = 0; daang = 0; } + rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),mulscale16(czoom*spr->yrepeat,yxaspect),daang,spr->picnum,spr->shade,spr->pal,(spr->cstat&2)>>1,windowx1,windowy1,windowx2,windowy2); + } + } + break; + case 16: + x1 = sprx; y1 = spry; + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + if ((spr->cstat&4) > 0) xoff = -xoff; + k = spr->ang; l = spr->xrepeat; + dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; + l = tilesizx[tilenum]; k = (l>>1)+xoff; + x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); + y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); - ox = x1-cposx; oy = y1-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x1-cposx; oy = y1-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); - ox = x2-cposx; oy = y2-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x2-cposx; oy = y2-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect2,ox,yvect2); - drawline256(x1+(xdim<<11),y1+(ydim<<11), - x2+(xdim<<11),y2+(ydim<<11),col); + drawline256(x1+(xdim<<11),y1+(ydim<<11), + x2+(xdim<<11),y2+(ydim<<11),col); - break; - case 32: - if (dimensionmode[screenpeek] == 1) - { - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); - if ((spr->cstat&4) > 0) xoff = -xoff; - if ((spr->cstat&8) > 0) yoff = -yoff; + break; + case 32: + if (dimensionmode[screenpeek] == 1) + { + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); + if ((spr->cstat&4) > 0) xoff = -xoff; + if ((spr->cstat&8) > 0) yoff = -yoff; - k = spr->ang; - cosang = sintable[(k+512)&2047]; sinang = sintable[k]; - xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; - yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; + k = spr->ang; + cosang = sintable[(k+512)&2047]; sinang = sintable[k]; + xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; + yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; - x1 = sprx + dmulscale16(sinang,dax,cosang,day); - y1 = spry + dmulscale16(sinang,day,-cosang,dax); - l = xspan*xrepeat; - x2 = x1 - mulscale16(sinang,l); - y2 = y1 + mulscale16(cosang,l); - l = yspan*yrepeat; - k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; - k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; + dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; + x1 = sprx + dmulscale16(sinang,dax,cosang,day); + y1 = spry + dmulscale16(sinang,day,-cosang,dax); + l = xspan*xrepeat; + x2 = x1 - mulscale16(sinang,l); + y2 = y1 + mulscale16(cosang,l); + l = yspan*yrepeat; + k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; + k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; - ox = x1-cposx; oy = y1-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x1-cposx; oy = y1-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); - ox = x2-cposx; oy = y2-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x2-cposx; oy = y2-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect2,ox,yvect2); - ox = x3-cposx; oy = y3-cposy; - x3 = dmulscale16(ox,xvect,-oy,yvect); - y3 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x3-cposx; oy = y3-cposy; + x3 = dmulscale16(ox,xvect,-oy,yvect); + y3 = dmulscale16(oy,xvect2,ox,yvect2); - ox = x4-cposx; oy = y4-cposy; - x4 = dmulscale16(ox,xvect,-oy,yvect); - y4 = dmulscale16(oy,xvect2,ox,yvect2); + ox = x4-cposx; oy = y4-cposy; + x4 = dmulscale16(ox,xvect,-oy,yvect); + y4 = dmulscale16(oy,xvect2,ox,yvect2); - drawline256(x1+(xdim<<11),y1+(ydim<<11), - x2+(xdim<<11),y2+(ydim<<11),col); + drawline256(x1+(xdim<<11),y1+(ydim<<11), + x2+(xdim<<11),y2+(ydim<<11),col); - drawline256(x2+(xdim<<11),y2+(ydim<<11), - x3+(xdim<<11),y3+(ydim<<11),col); + drawline256(x2+(xdim<<11),y2+(ydim<<11), + x3+(xdim<<11),y3+(ydim<<11),col); - drawline256(x3+(xdim<<11),y3+(ydim<<11), - x4+(xdim<<11),y4+(ydim<<11),col); + drawline256(x3+(xdim<<11),y3+(ydim<<11), + x4+(xdim<<11),y4+(ydim<<11),col); - drawline256(x4+(xdim<<11),y4+(ydim<<11), - x1+(xdim<<11),y1+(ydim<<11),col); + drawline256(x4+(xdim<<11),y4+(ydim<<11), + x1+(xdim<<11),y1+(ydim<<11),col); - } - break; - } - } + } + break; + } + } - //Draw white lines - for(i=0;inextwall >= 0) continue; + k = -1; + for(j=startwall,wal=&wall[startwall];jnextwall >= 0) continue; - if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; + if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; - if (tilesizx[wal->picnum] == 0) continue; - if (tilesizy[wal->picnum] == 0) continue; + if (tilesizx[wal->picnum] == 0) continue; + if (tilesizy[wal->picnum] == 0) continue; - if (j == k) - { x1 = x2; y1 = y2; } - else - { - ox = wal->x-cposx; oy = wal->y-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - } + if (j == k) + { x1 = x2; y1 = y2; } + else + { + ox = wal->x-cposx; oy = wal->y-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + } - k = wal->point2; wal2 = &wall[k]; - ox = wal2->x-cposx; oy = wal2->y-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + k = wal->point2; wal2 = &wall[k]; + ox = wal2->x-cposx; oy = wal2->y-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - drawline256(x1,y1,x2,y2,24); - } - } + drawline256(x1,y1,x2,y2,24); + } + } } - //New movesprite using getzrange. Note that I made the getzrange - //parameters global (&globhiz,&globhihit,&globloz,&globlohit) so they - //don't need to be passed everywhere. Also this should make this - //movesprite function compatible with the older movesprite functions. +//New movesprite using getzrange. Note that I made the getzrange +//parameters global (&globhiz,&globhihit,&globloz,&globlohit) so they +//don't need to be passed everywhere. Also this should make this +//movesprite function compatible with the older movesprite functions. long movesprite(short spritenum, long dx, long dy, long dz, long ceildist, long flordist, long clipmask) { - long daz, zoffs, tempint; - short retval, dasectnum, datempshort; - spritetype *spr; + long daz, zoffs, tempint; + short retval, dasectnum, datempshort; + spritetype *spr; - spr = &sprite[spritenum]; + spr = &sprite[spritenum]; - if ((spr->cstat&128) == 0) - zoffs = -((tilesizy[spr->picnum]*spr->yrepeat)<<1); - else - zoffs = 0; + if ((spr->cstat&128) == 0) + zoffs = -((tilesizy[spr->picnum]*spr->yrepeat)<<1); + else + zoffs = 0; - dasectnum = spr->sectnum; //Can't modify sprite sectors directly becuase of linked lists - daz = spr->z+zoffs; //Must do this if not using the new centered centering (of course) - retval = clipmove(&spr->x,&spr->y,&daz,&dasectnum,dx,dy, - ((long)spr->clipdist)<<2,ceildist,flordist,clipmask); + dasectnum = spr->sectnum; //Can't modify sprite sectors directly becuase of linked lists + daz = spr->z+zoffs; //Must do this if not using the new centered centering (of course) + retval = clipmove(&spr->x,&spr->y,&daz,&dasectnum,dx,dy, + ((long)spr->clipdist)<<2,ceildist,flordist,clipmask); - if (dasectnum < 0) retval = -1; + if (dasectnum < 0) retval = -1; - if ((dasectnum != spr->sectnum) && (dasectnum >= 0)) - changespritesect(spritenum,dasectnum); + if ((dasectnum != spr->sectnum) && (dasectnum >= 0)) + changespritesect(spritenum,dasectnum); - //Set the blocking bit to 0 temporarly so getzrange doesn't pick up - //its own sprite - datempshort = spr->cstat; spr->cstat &= ~1; - getzrange(spr->x,spr->y,spr->z-1,spr->sectnum, - &globhiz,&globhihit,&globloz,&globlohit, - ((long)spr->clipdist)<<2,clipmask); - spr->cstat = datempshort; + //Set the blocking bit to 0 temporarly so getzrange doesn't pick up + //its own sprite + datempshort = spr->cstat; spr->cstat &= ~1; + getzrange(spr->x,spr->y,spr->z-1,spr->sectnum, + &globhiz,&globhihit,&globloz,&globlohit, + ((long)spr->clipdist)<<2,clipmask); + spr->cstat = datempshort; - daz = spr->z+zoffs + dz; - if ((daz <= globhiz) || (daz > globloz)) - { - if (retval != 0) return(retval); - return(16384+dasectnum); - } - spr->z = daz-zoffs; - return(retval); + daz = spr->z+zoffs + dz; + if ((daz <= globhiz) || (daz > globloz)) + { + if (retval != 0) return(retval); + return(16384+dasectnum); + } + spr->z = daz-zoffs; + return(retval); } void waitforeverybody () { - long i; - if (numplayers < 2) return; - packbuf[0] = 250; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (i != myconnectindex) sendpacket(i,packbuf,1); - if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master - } - playerreadyflag[myconnectindex]++; - while (1) - { - handleevents(); - refreshaudio(); + long i; + if (numplayers < 2) return; + packbuf[0] = 250; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,packbuf,1); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + playerreadyflag[myconnectindex]++; + while (1) + { + handleevents(); + refreshaudio(); - drawrooms(posx[myconnectindex],posy[myconnectindex],posz[myconnectindex],ang[myconnectindex],horiz[myconnectindex],cursectnum[myconnectindex]); - if (!networkmode) Bsprintf(tempbuf,"Master/slave mode"); - else Bsprintf(tempbuf,"Peer-peer mode"); - printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-24,31,0,tempbuf,0); - Bsprintf(tempbuf,"Waiting for players"); - printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-16,31,0,tempbuf,0); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (playerreadyflag[i] < playerreadyflag[myconnectindex]) - { - //slaves in M/S mode only wait for master - if ((!networkmode) && (myconnectindex != connecthead) && (i != connecthead)) - { - Bsprintf(tempbuf,"Player %ld",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,15,0,tempbuf,0); - } - else - { - Bsprintf(tempbuf,"Player %ld NOT ready",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,127,0,tempbuf,0); - } - } - else - { - Bsprintf(tempbuf,"Player %ld ready",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,31,0,tempbuf,0); - } - if (i == myconnectindex) - { - Bsprintf(tempbuf,"You->"); - printext256((xdim>>1)-(26<<2),(ydim>>1)+i*8,95,0,tempbuf,0); - } - } - nextpage(); + drawrooms(posx[myconnectindex],posy[myconnectindex],posz[myconnectindex],ang[myconnectindex],horiz[myconnectindex],cursectnum[myconnectindex]); + if (!networkmode) Bsprintf(tempbuf,"Master/slave mode"); + else Bsprintf(tempbuf,"Peer-peer mode"); + printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-24,31,0,tempbuf,0); + Bsprintf(tempbuf,"Waiting for players"); + printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-16,31,0,tempbuf,0); + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (playerreadyflag[i] < playerreadyflag[myconnectindex]) + { + //slaves in M/S mode only wait for master + if ((!networkmode) && (myconnectindex != connecthead) && (i != connecthead)) + { + Bsprintf(tempbuf,"Player %ld",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,15,0,tempbuf,0); + } + else + { + Bsprintf(tempbuf,"Player %ld NOT ready",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,127,0,tempbuf,0); + } + } + else + { + Bsprintf(tempbuf,"Player %ld ready",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,31,0,tempbuf,0); + } + if (i == myconnectindex) + { + Bsprintf(tempbuf,"You->"); + printext256((xdim>>1)-(26<<2),(ydim>>1)+i*8,95,0,tempbuf,0); + } + } + nextpage(); - if (quitevent || keystatus[1]) { - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } + if (quitevent || keystatus[1]) { + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } - getpackets(); + getpackets(); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (playerreadyflag[i] < playerreadyflag[myconnectindex]) break; - if ((!networkmode) && (myconnectindex != connecthead)) { i = -1; break; } //slaves in M/S mode only wait for master - } - if (i < 0) return; - } + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (playerreadyflag[i] < playerreadyflag[myconnectindex]) break; + if ((!networkmode) && (myconnectindex != connecthead)) { i = -1; break; } //slaves in M/S mode only wait for master + } + if (i < 0) return; + } } void searchmap(short startsector) { - long i, j, dasect, splc, send, startwall, endwall; - short dapic; - walltype *wal; + long i, j, dasect, splc, send, startwall, endwall; + short dapic; + walltype *wal; - if ((startsector < 0) || (startsector >= numsectors)) return; - for(i=0;i<(MAXSECTORS>>3);i++) show2dsector[i] = 0; - for(i=0;i<(MAXWALLS>>3);i++) show2dwall[i] = 0; - for(i=0;i<(MAXSPRITES>>3);i++) show2dsprite[i] = 0; + if ((startsector < 0) || (startsector >= numsectors)) return; + for(i=0;i<(MAXSECTORS>>3);i++) show2dsector[i] = 0; + for(i=0;i<(MAXWALLS>>3);i++) show2dwall[i] = 0; + for(i=0;i<(MAXSPRITES>>3);i++) show2dsprite[i] = 0; - automapping = 0; + automapping = 0; - //Search your area recursively & set all show2dsector/show2dwalls - tempshort[0] = startsector; - show2dsector[startsector>>3] |= (1<<(startsector&7)); - dapic = sector[startsector].ceilingpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = sector[startsector].floorpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - for(splc=0,send=1;splc>3] |= (1<<(i&7)); - dapic = wall[i].picnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = wall[i].overpicnum; - if (((dapic&0xfffff000) == 0) && (waloff[dapic] == 0)) loadtile(dapic); + //Search your area recursively & set all show2dsector/show2dwalls + tempshort[0] = startsector; + show2dsector[startsector>>3] |= (1<<(startsector&7)); + dapic = sector[startsector].ceilingpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = sector[startsector].floorpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + for(splc=0,send=1;splc>3] |= (1<<(i&7)); + dapic = wall[i].picnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = wall[i].overpicnum; + if (((dapic&0xfffff000) == 0) && (waloff[dapic] == 0)) loadtile(dapic); - j = wal->nextsector; - if ((j >= 0) && ((show2dsector[j>>3]&(1<<(j&7))) == 0)) - { - show2dsector[j>>3] |= (1<<(j&7)); + j = wal->nextsector; + if ((j >= 0) && ((show2dsector[j>>3]&(1<<(j&7))) == 0)) + { + show2dsector[j>>3] |= (1<<(j&7)); - dapic = sector[j].ceilingpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = sector[j].floorpicnum; - if (waloff[dapic] == 0) loadtile(dapic); + dapic = sector[j].ceilingpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = sector[j].floorpicnum; + if (waloff[dapic] == 0) loadtile(dapic); - tempshort[send++] = (short)j; - } - } + tempshort[send++] = (short)j; + } + } - for(i=headspritesect[dasect];i>=0;i=nextspritesect[i]) - { - show2dsprite[i>>3] |= (1<<(i&7)); - dapic = sprite[i].picnum; - if (waloff[dapic] == 0) loadtile(dapic); - } - } + for(i=headspritesect[dasect];i>=0;i=nextspritesect[i]) + { + show2dsprite[i>>3] |= (1<<(i&7)); + dapic = sprite[i].picnum; + if (waloff[dapic] == 0) loadtile(dapic); + } + } } void setinterpolation(long *posptr) { - long i; + long i; - if (numinterpolations >= MAXINTERPOLATIONS) return; - for(i=numinterpolations-1;i>=0;i--) - if (curipos[i] == posptr) return; - curipos[numinterpolations] = posptr; - oldipos[numinterpolations] = *posptr; - numinterpolations++; + if (numinterpolations >= MAXINTERPOLATIONS) return; + for(i=numinterpolations-1;i>=0;i--) + if (curipos[i] == posptr) return; + curipos[numinterpolations] = posptr; + oldipos[numinterpolations] = *posptr; + numinterpolations++; } void stopinterpolation(long *posptr) { - long i; + long i; - for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--) - if (curipos[i] == posptr) - { - numinterpolations--; - oldipos[i] = oldipos[numinterpolations]; - bakipos[i] = bakipos[numinterpolations]; - curipos[i] = curipos[numinterpolations]; - } + for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--) + if (curipos[i] == posptr) + { + numinterpolations--; + oldipos[i] = oldipos[numinterpolations]; + bakipos[i] = bakipos[numinterpolations]; + curipos[i] = curipos[numinterpolations]; + } } void updateinterpolations(void) //Stick at beginning of domovethings { - long i; + long i; - for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i]; + for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i]; } void dointerpolations(void) //Stick at beginning of drawscreen { - long i, j, odelta, ndelta; + long i, j, odelta, ndelta; - ndelta = 0; j = 0; - for(i=numinterpolations-1;i>=0;i--) - { - bakipos[i] = *curipos[i]; - odelta = ndelta; ndelta = (*curipos[i])-oldipos[i]; - if (odelta != ndelta) j = mulscale16(ndelta,smoothratio); - *curipos[i] = oldipos[i]+j; - } + ndelta = 0; j = 0; + for(i=numinterpolations-1;i>=0;i--) + { + bakipos[i] = *curipos[i]; + odelta = ndelta; ndelta = (*curipos[i])-oldipos[i]; + if (odelta != ndelta) j = mulscale16(ndelta,smoothratio); + *curipos[i] = oldipos[i]+j; + } } void restoreinterpolations(void) //Stick at end of drawscreen { - long i; + long i; - for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i]; + for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i]; } void printext(long x, long y, char *buffer, short tilenum, char invisiblecol) { - long i; - char ch; + long i; + char ch; - for(i=0;buffer[i]!=0;i++) - { - ch = buffer[i]; - rotatesprite((x-((8&15)<<3))<<16,(y-((8>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+64+128,x,y,x+7,y+7); - rotatesprite((x-((ch&15)<<3))<<16,(y-((ch>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+128,x,y,x+7,y+7); - x += 8; - } + for(i=0;buffer[i]!=0;i++) + { + ch = buffer[i]; + rotatesprite((x-((8&15)<<3))<<16,(y-((8>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+64+128,x,y,x+7,y+7); + rotatesprite((x-((ch&15)<<3))<<16,(y-((ch>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+128,x,y,x+7,y+7); + x += 8; + } } void drawtilebackground (long thex, long they, short tilenum, - signed char shade, long cx1, long cy1, - long cx2, long cy2, char dapalnum) + signed char shade, long cx1, long cy1, + long cx2, long cy2, char dapalnum) { - long x, y, xsiz, ysiz, tx1, ty1, tx2, ty2; + long x, y, xsiz, ysiz, tx1, ty1, tx2, ty2; - xsiz = tilesizx[tilenum]; tx1 = cx1/xsiz; tx2 = cx2/xsiz; - ysiz = tilesizy[tilenum]; ty1 = cy1/ysiz; ty2 = cy2/ysiz; + xsiz = tilesizx[tilenum]; tx1 = cx1/xsiz; tx2 = cx2/xsiz; + ysiz = tilesizy[tilenum]; ty1 = cy1/ysiz; ty2 = cy2/ysiz; - for(x=tx1;x<=tx2;x++) - for(y=ty1;y<=ty2;y++) - rotatesprite(x*xsiz<<16,y*ysiz<<16,65536L,0,tilenum,shade,dapalnum,8+16+64+128,cx1,cy1,cx2,cy2); + for(x=tx1;x<=tx2;x++) + for(y=ty1;y<=ty2;y++) + rotatesprite(x*xsiz<<16,y*ysiz<<16,65536L,0,tilenum,shade,dapalnum,8+16+64+128,cx1,cy1,cx2,cy2); } diff --git a/polymer/build/src/gamestartwin.c b/polymer/build/src/gamestartwin.c index f210933fd..a65b0dcb5 100644 --- a/polymer/build/src/gamestartwin.c +++ b/polymer/build/src/gamestartwin.c @@ -18,127 +18,127 @@ static void PopulateVideoModeLists(int fs, HWND list3d) { - int i,j; - char buf[64]; + int i,j; + char buf[64]; - ComboBox_ResetContent(list3d); - for (i=0; i 0) { - if (!IsWindow(hwndLaunch) || quitevent) break; - if (IsDialogMessage(hwndStart, &msg) /*|| IsDialogMessage(hwndLaunch, &msg)*/) continue; - - TranslateMessage(&msg); - DispatchMessage(&msg); - } - EnableWindow(GetDlgItem(hwndStart,WIN_STARTWIN_ITEMLIST),TRUE); - } - if (quitevent) return 1; - return 0; + hwndLaunch = CreateDialogParam((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(2000), hwndStart, LaunchWindowProc, (LPARAM)saferect); + if (hwndLaunch) { + EnableWindow(GetDlgItem(hwndStart,WIN_STARTWIN_ITEMLIST),FALSE); + while (GetMessage(&msg, NULL, 0, 0) > 0) { + if (!IsWindow(hwndLaunch) || quitevent) break; + if (IsDialogMessage(hwndStart, &msg) /*|| IsDialogMessage(hwndLaunch, &msg)*/) continue; + + TranslateMessage(&msg); + DispatchMessage(&msg); + } + EnableWindow(GetDlgItem(hwndStart,WIN_STARTWIN_ITEMLIST),TRUE); + } + if (quitevent) return 1; + return 0; } diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index e5ad09eb0..fc516ea48 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -79,7 +79,7 @@ void (APIENTRY * bglGetCompressedTexImageARB)(GLenum, GLint, GLvoid *); void (APIENTRY * bglFogf)( GLenum pname, GLfloat param ); void (APIENTRY * bglFogi)( GLenum pname, GLint param ); void (APIENTRY * bglFogfv)( GLenum pname, const GLfloat *params ); - + #ifdef RENDERTYPEWIN // Windows HGLRC (WINAPI * bwglCreateContext)(HDC); @@ -101,20 +101,20 @@ char *gldriver = NULL; static void * getproc_(const char *s, int *err, int fatal, int extension) { - void *t; + void *t; #if defined RENDERTYPESDL - t = (void*)SDL_GL_GetProcAddress(s); + t = (void*)SDL_GL_GetProcAddress(s); #elif defined _WIN32 - if (extension) t = (void*)bwglGetProcAddress(s); - else t = (void*)GetProcAddress(hGLDLL,s); + if (extension) t = (void*)bwglGetProcAddress(s); + else t = (void*)GetProcAddress(hGLDLL,s); #else #error Need a dynamic loader for this platform... #endif - if (!t && fatal) { - initprintf("Failed to find %s in %s\n", s, gldriver); - *err = 1; - } - return t; + if (!t && fatal) { + initprintf("Failed to find %s in %s\n", s, gldriver); + *err = 1; + } + return t; } #define GETPROC(s) getproc_(s,&err,1,0) #define GETPROCSOFT(s) getproc_(s,&err,0,0) @@ -123,229 +123,229 @@ static void * getproc_(const char *s, int *err, int fatal, int extension) int loadgldriver(const char *driver) { - void *t; - int err=0; - + void *t; + int err=0; + #ifdef RENDERTYPEWIN - if (hGLDLL) return 0; + if (hGLDLL) return 0; #endif - if (!driver) { + if (!driver) { #ifdef _WIN32 - driver = "OPENGL32.DLL"; + driver = "OPENGL32.DLL"; #else - driver = "libGL.so"; + driver = "libGL.so"; #endif - } + } - initprintf("Loading %s\n",driver); + initprintf("Loading %s\n",driver); #if defined RENDERTYPESDL - if (SDL_GL_LoadLibrary(driver)) return -1; + if (SDL_GL_LoadLibrary(driver)) return -1; #elif defined _WIN32 - hGLDLL = LoadLibrary(driver); - if (!hGLDLL) return -1; + hGLDLL = LoadLibrary(driver); + if (!hGLDLL) return -1; #endif - gldriver = strdup(driver); + gldriver = strdup(driver); #ifdef RENDERTYPEWIN - bwglCreateContext = GETPROC("wglCreateContext"); - bwglDeleteContext = GETPROC("wglDeleteContext"); - bwglGetProcAddress = GETPROC("wglGetProcAddress"); - bwglMakeCurrent = GETPROC("wglMakeCurrent"); + bwglCreateContext = GETPROC("wglCreateContext"); + bwglDeleteContext = GETPROC("wglDeleteContext"); + bwglGetProcAddress = GETPROC("wglGetProcAddress"); + bwglMakeCurrent = GETPROC("wglMakeCurrent"); - bwglSwapBuffers = GETPROC("wglSwapBuffers"); - bwglChoosePixelFormat = GETPROC("wglChoosePixelFormat"); - bwglDescribePixelFormat = GETPROC("wglDescribePixelFormat"); - bwglGetPixelFormat = GETPROC("wglGetPixelFormat"); - bwglSetPixelFormat = GETPROC("wglSetPixelFormat"); + bwglSwapBuffers = GETPROC("wglSwapBuffers"); + bwglChoosePixelFormat = GETPROC("wglChoosePixelFormat"); + bwglDescribePixelFormat = GETPROC("wglDescribePixelFormat"); + bwglGetPixelFormat = GETPROC("wglGetPixelFormat"); + bwglSetPixelFormat = GETPROC("wglSetPixelFormat"); #endif - bglClearColor = GETPROC("glClearColor"); - bglClear = GETPROC("glClear"); - bglColorMask = GETPROC("glColorMask"); - bglAlphaFunc = GETPROC("glAlphaFunc"); - bglBlendFunc = GETPROC("glBlendFunc"); - bglCullFace = GETPROC("glCullFace"); - bglFrontFace = GETPROC("glFrontFace"); - bglPolygonOffset = GETPROC("glPolygonOffset"); - bglPolygonMode = GETPROC("glPolygonMode"); - bglEnable = GETPROC("glEnable"); - bglDisable = GETPROC("glDisable"); - bglGetFloatv = GETPROC("glGetFloatv"); - bglGetIntegerv = GETPROC("glGetIntegerv"); - bglPushAttrib = GETPROC("glPushAttrib"); - bglPopAttrib = GETPROC("glPopAttrib"); - bglGetError = GETPROC("glGetError"); - bglGetString = GETPROC("glGetString"); - bglHint = GETPROC("glHint"); + bglClearColor = GETPROC("glClearColor"); + bglClear = GETPROC("glClear"); + bglColorMask = GETPROC("glColorMask"); + bglAlphaFunc = GETPROC("glAlphaFunc"); + bglBlendFunc = GETPROC("glBlendFunc"); + bglCullFace = GETPROC("glCullFace"); + bglFrontFace = GETPROC("glFrontFace"); + bglPolygonOffset = GETPROC("glPolygonOffset"); + bglPolygonMode = GETPROC("glPolygonMode"); + bglEnable = GETPROC("glEnable"); + bglDisable = GETPROC("glDisable"); + bglGetFloatv = GETPROC("glGetFloatv"); + bglGetIntegerv = GETPROC("glGetIntegerv"); + bglPushAttrib = GETPROC("glPushAttrib"); + bglPopAttrib = GETPROC("glPopAttrib"); + bglGetError = GETPROC("glGetError"); + bglGetString = GETPROC("glGetString"); + bglHint = GETPROC("glHint"); - // Depth - bglDepthFunc = GETPROC("glDepthFunc"); - bglDepthMask = GETPROC("glDepthMask"); - bglDepthRange = GETPROC("glDepthRange"); + // Depth + bglDepthFunc = GETPROC("glDepthFunc"); + bglDepthMask = GETPROC("glDepthMask"); + bglDepthRange = GETPROC("glDepthRange"); - // Matrix - bglMatrixMode = GETPROC("glMatrixMode"); - bglOrtho = GETPROC("glOrtho"); - bglFrustum = GETPROC("glFrustum"); - bglViewport = GETPROC("glViewport"); - bglPushMatrix = GETPROC("glPushMatrix"); - bglPopMatrix = GETPROC("glPopMatrix"); - bglLoadIdentity = GETPROC("glLoadIdentity"); - bglLoadMatrixf = GETPROC("glLoadMatrixf"); + // Matrix + bglMatrixMode = GETPROC("glMatrixMode"); + bglOrtho = GETPROC("glOrtho"); + bglFrustum = GETPROC("glFrustum"); + bglViewport = GETPROC("glViewport"); + bglPushMatrix = GETPROC("glPushMatrix"); + bglPopMatrix = GETPROC("glPopMatrix"); + bglLoadIdentity = GETPROC("glLoadIdentity"); + bglLoadMatrixf = GETPROC("glLoadMatrixf"); - // Drawing - bglBegin = GETPROC("glBegin"); - bglEnd = GETPROC("glEnd"); - bglVertex2f = GETPROC("glVertex2f"); - bglVertex2i = GETPROC("glVertex2i"); - bglVertex3d = GETPROC("glVertex3d"); - bglVertex3fv = GETPROC("glVertex3fv"); - bglColor4f = GETPROC("glColor4f"); - bglColor4ub = GETPROC("glColor4ub"); - bglTexCoord2d = GETPROC("glTexCoord2d"); - bglTexCoord2f = GETPROC("glTexCoord2f"); + // Drawing + bglBegin = GETPROC("glBegin"); + bglEnd = GETPROC("glEnd"); + bglVertex2f = GETPROC("glVertex2f"); + bglVertex2i = GETPROC("glVertex2i"); + bglVertex3d = GETPROC("glVertex3d"); + bglVertex3fv = GETPROC("glVertex3fv"); + bglColor4f = GETPROC("glColor4f"); + bglColor4ub = GETPROC("glColor4ub"); + bglTexCoord2d = GETPROC("glTexCoord2d"); + bglTexCoord2f = GETPROC("glTexCoord2f"); - // Lighting - bglShadeModel = GETPROC("glShadeModel"); + // Lighting + bglShadeModel = GETPROC("glShadeModel"); - // Raster funcs - bglReadPixels = GETPROC("glReadPixels"); + // Raster funcs + bglReadPixels = GETPROC("glReadPixels"); - // Texture mapping - bglTexEnvf = GETPROC("glTexEnvf"); - bglGenTextures = GETPROC("glGenTextures"); - bglDeleteTextures = GETPROC("glDeleteTextures"); - bglBindTexture = GETPROC("glBindTexture"); - bglTexImage2D = GETPROC("glTexImage2D"); - bglTexSubImage2D = GETPROC("glTexSubImage2D"); - bglTexParameterf = GETPROC("glTexParameterf"); - bglTexParameteri = GETPROC("glTexParameteri"); - bglGetTexLevelParameteriv = GETPROC("glGetTexLevelParameteriv"); + // Texture mapping + bglTexEnvf = GETPROC("glTexEnvf"); + bglGenTextures = GETPROC("glGenTextures"); + bglDeleteTextures = GETPROC("glDeleteTextures"); + bglBindTexture = GETPROC("glBindTexture"); + bglTexImage2D = GETPROC("glTexImage2D"); + bglTexSubImage2D = GETPROC("glTexSubImage2D"); + bglTexParameterf = GETPROC("glTexParameterf"); + bglTexParameteri = GETPROC("glTexParameteri"); + bglGetTexLevelParameteriv = GETPROC("glGetTexLevelParameteriv"); - // Fog - bglFogf = GETPROC("glFogf"); - bglFogi = GETPROC("glFogi"); - bglFogfv = GETPROC("glFogfv"); + // Fog + bglFogf = GETPROC("glFogf"); + bglFogi = GETPROC("glFogi"); + bglFogfv = GETPROC("glFogfv"); - loadglextensions(); + loadglextensions(); - if (err) unloadgldriver(); - return err; + if (err) unloadgldriver(); + return err; } int loadglextensions(void) { - int err = 0; + int err = 0; #ifdef RENDERTYPEWIN - if (!hGLDLL) return 0; + if (!hGLDLL) return 0; #endif - bglCompressedTexImage2DARB = GETPROCEXTSOFT("glCompressedTexImage2DARB"); - bglGetCompressedTexImageARB = GETPROCEXTSOFT("glGetCompressedTexImageARB"); + bglCompressedTexImage2DARB = GETPROCEXTSOFT("glCompressedTexImage2DARB"); + bglGetCompressedTexImageARB = GETPROCEXTSOFT("glGetCompressedTexImageARB"); - return err; + return err; } int unloadgldriver(void) { #ifdef RENDERTYPEWIN - if (!hGLDLL) return 0; + if (!hGLDLL) return 0; #endif - free(gldriver); - gldriver = NULL; - + free(gldriver); + gldriver = NULL; + #ifdef RENDERTYPEWIN - FreeLibrary(hGLDLL); - hGLDLL = NULL; + FreeLibrary(hGLDLL); + hGLDLL = NULL; #endif - - bglClearColor = NULL; - bglClear = NULL; - bglColorMask = NULL; - bglAlphaFunc = NULL; - bglBlendFunc = NULL; - bglCullFace = NULL; - bglFrontFace = NULL; - bglPolygonOffset = NULL; - bglPolygonMode = NULL; - bglEnable = NULL; - bglDisable = NULL; - bglGetFloatv = NULL; - bglGetIntegerv = NULL; - bglPushAttrib = NULL; - bglPopAttrib = NULL; - bglGetError = NULL; - bglGetString = NULL; - bglHint = NULL; - // Depth - bglDepthFunc = NULL; - bglDepthMask = NULL; - bglDepthRange = NULL; + bglClearColor = NULL; + bglClear = NULL; + bglColorMask = NULL; + bglAlphaFunc = NULL; + bglBlendFunc = NULL; + bglCullFace = NULL; + bglFrontFace = NULL; + bglPolygonOffset = NULL; + bglPolygonMode = NULL; + bglEnable = NULL; + bglDisable = NULL; + bglGetFloatv = NULL; + bglGetIntegerv = NULL; + bglPushAttrib = NULL; + bglPopAttrib = NULL; + bglGetError = NULL; + bglGetString = NULL; + bglHint = NULL; - // Matrix - bglMatrixMode = NULL; - bglOrtho = NULL; - bglFrustum = NULL; - bglViewport = NULL; - bglPushMatrix = NULL; - bglPopMatrix = NULL; - bglLoadIdentity = NULL; - bglLoadMatrixf = NULL; + // Depth + bglDepthFunc = NULL; + bglDepthMask = NULL; + bglDepthRange = NULL; - // Drawing - bglBegin = NULL; - bglEnd = NULL; - bglVertex2f = NULL; - bglVertex2i = NULL; - bglVertex3d = NULL; - bglVertex3fv = NULL; - bglColor4f = NULL; - bglColor4ub = NULL; - bglTexCoord2d = NULL; - bglTexCoord2f = NULL; + // Matrix + bglMatrixMode = NULL; + bglOrtho = NULL; + bglFrustum = NULL; + bglViewport = NULL; + bglPushMatrix = NULL; + bglPopMatrix = NULL; + bglLoadIdentity = NULL; + bglLoadMatrixf = NULL; - // Lighting - bglShadeModel = NULL; + // Drawing + bglBegin = NULL; + bglEnd = NULL; + bglVertex2f = NULL; + bglVertex2i = NULL; + bglVertex3d = NULL; + bglVertex3fv = NULL; + bglColor4f = NULL; + bglColor4ub = NULL; + bglTexCoord2d = NULL; + bglTexCoord2f = NULL; - // Raster funcs - bglReadPixels = NULL; + // Lighting + bglShadeModel = NULL; - // Texture mapping - bglTexEnvf = NULL; - bglGenTextures = NULL; - bglDeleteTextures = NULL; - bglBindTexture = NULL; - bglTexImage2D = NULL; - bglTexSubImage2D = NULL; - bglTexParameterf = NULL; - bglTexParameteri = NULL; - bglGetTexLevelParameteriv = NULL; - bglCompressedTexImage2DARB = NULL; - bglGetCompressedTexImageARB = NULL; + // Raster funcs + bglReadPixels = NULL; + + // Texture mapping + bglTexEnvf = NULL; + bglGenTextures = NULL; + bglDeleteTextures = NULL; + bglBindTexture = NULL; + bglTexImage2D = NULL; + bglTexSubImage2D = NULL; + bglTexParameterf = NULL; + bglTexParameteri = NULL; + bglGetTexLevelParameteriv = NULL; + bglCompressedTexImage2DARB = NULL; + bglGetCompressedTexImageARB = NULL; + + // Fog + bglFogf = NULL; + bglFogi = NULL; + bglFogfv = NULL; - // Fog - bglFogf = NULL; - bglFogi = NULL; - bglFogfv = NULL; - #ifdef RENDERTYPEWIN - bwglCreateContext = NULL; - bwglDeleteContext = NULL; - bwglGetProcAddress = NULL; - bwglMakeCurrent = NULL; + bwglCreateContext = NULL; + bwglDeleteContext = NULL; + bwglGetProcAddress = NULL; + bwglMakeCurrent = NULL; - bwglSwapBuffers = NULL; - bwglChoosePixelFormat = NULL; - bwglDescribePixelFormat = NULL; - bwglGetPixelFormat = NULL; - bwglSetPixelFormat = NULL; + bwglSwapBuffers = NULL; + bwglChoosePixelFormat = NULL; + bwglDescribePixelFormat = NULL; + bwglGetPixelFormat = NULL; + bwglSetPixelFormat = NULL; #endif - return 0; + return 0; } #else diff --git a/polymer/build/src/gtkbits.c b/polymer/build/src/gtkbits.c index 8c359ecad..83866e5fa 100644 --- a/polymer/build/src/gtkbits.c +++ b/polymer/build/src/gtkbits.c @@ -31,182 +31,182 @@ static GdkPixbuf *appicon = NULL; static gboolean on_startwin_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) { - quitevent++; - return TRUE; // FALSE would let the event go through. we want the game to decide when to close + quitevent++; + return TRUE; // FALSE would let the event go through. we want the game to decide when to close } void gtkbuild_create_startwin(void) { - GtkWidget *banner, *label, *content, *scroll; - GtkWidget *hbox1, *fixed1; - GdkPixbuf *startbanner_pixbuf; + GtkWidget *banner, *label, *content, *scroll; + GtkWidget *hbox1, *fixed1; + GdkPixbuf *startbanner_pixbuf; - if (!gtkenabled) return; + if (!gtkenabled) return; - startwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (startwin), apptitle); - gtk_window_set_position (GTK_WINDOW (startwin), GTK_WIN_POS_CENTER); - gtk_window_set_resizable (GTK_WINDOW (startwin), FALSE); - gtk_window_set_type_hint (GTK_WINDOW (startwin), GDK_WINDOW_TYPE_HINT_DIALOG); + startwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (startwin), apptitle); + gtk_window_set_position (GTK_WINDOW (startwin), GTK_WIN_POS_CENTER); + gtk_window_set_resizable (GTK_WINDOW (startwin), FALSE); + gtk_window_set_type_hint (GTK_WINDOW (startwin), GDK_WINDOW_TYPE_HINT_DIALOG); - hbox1 = gtk_hbox_new (FALSE, 0); - gtk_widget_show (hbox1); - gtk_container_add (GTK_CONTAINER (startwin), hbox1); + hbox1 = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox1); + gtk_container_add (GTK_CONTAINER (startwin), hbox1); - startbanner_pixbuf = gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); - banner = gtk_image_new_from_pixbuf(startbanner_pixbuf); - g_object_unref((gpointer)startbanner_pixbuf); - gtk_widget_show (banner); - gtk_box_pack_start (GTK_BOX (hbox1), banner, FALSE, FALSE, 0); + startbanner_pixbuf = gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); + banner = gtk_image_new_from_pixbuf(startbanner_pixbuf); + g_object_unref((gpointer)startbanner_pixbuf); + gtk_widget_show (banner); + gtk_box_pack_start (GTK_BOX (hbox1), banner, FALSE, FALSE, 0); - fixed1 = gtk_fixed_new (); - gtk_widget_show (fixed1); - gtk_box_pack_start (GTK_BOX (hbox1), fixed1, TRUE, TRUE, 0); - gtk_widget_set_size_request (fixed1, 390, -1); + fixed1 = gtk_fixed_new (); + gtk_widget_show (fixed1); + gtk_box_pack_start (GTK_BOX (hbox1), fixed1, TRUE, TRUE, 0); + gtk_widget_set_size_request (fixed1, 390, -1); - label = gtk_label_new (startwin_labeltext); - gtk_widget_show (label); - gtk_fixed_put (GTK_FIXED (fixed1), label, 6, 6); - gtk_widget_set_size_request (label, 378, 16); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER); + label = gtk_label_new (startwin_labeltext); + gtk_widget_show (label); + gtk_fixed_put (GTK_FIXED (fixed1), label, 6, 6); + gtk_widget_set_size_request (label, 378, 16); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER); - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scroll); - gtk_fixed_put (GTK_FIXED (fixed1), scroll, 6, 28); - gtk_widget_set_size_request (scroll, 378, 248); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scroll); + gtk_fixed_put (GTK_FIXED (fixed1), scroll, 6, 28); + gtk_widget_set_size_request (scroll, 378, 248); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); - content = gtk_text_view_new (); - gtk_widget_show (content); - gtk_container_add (GTK_CONTAINER(scroll), content); - //gtk_fixed_put (GTK_FIXED (fixed1), content, 6, 28); - gtk_widget_set_size_request (content, 378, 248); - gtk_text_view_set_editable (GTK_TEXT_VIEW (content), FALSE); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (content), GTK_WRAP_WORD); - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (content), FALSE); + content = gtk_text_view_new (); + gtk_widget_show (content); + gtk_container_add (GTK_CONTAINER(scroll), content); + //gtk_fixed_put (GTK_FIXED (fixed1), content, 6, 28); + gtk_widget_set_size_request (content, 378, 248); + gtk_text_view_set_editable (GTK_TEXT_VIEW (content), FALSE); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (content), GTK_WRAP_WORD); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (content), FALSE); - g_signal_connect ((gpointer) startwin, "delete_event", - G_CALLBACK (on_startwin_delete_event), - NULL); + g_signal_connect ((gpointer) startwin, "delete_event", + G_CALLBACK (on_startwin_delete_event), + NULL); - /* Store pointers to all widgets, for use by lookup_widget(). */ - GLADE_HOOKUP_OBJECT_NO_REF (startwin, startwin, "startwin"); - GLADE_HOOKUP_OBJECT (startwin, banner, "banner"); - GLADE_HOOKUP_OBJECT (startwin, label, "label"); - GLADE_HOOKUP_OBJECT (startwin, scroll, "scroll"); - GLADE_HOOKUP_OBJECT (startwin, content, "content"); + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF (startwin, startwin, "startwin"); + GLADE_HOOKUP_OBJECT (startwin, banner, "banner"); + GLADE_HOOKUP_OBJECT (startwin, label, "label"); + GLADE_HOOKUP_OBJECT (startwin, scroll, "scroll"); + GLADE_HOOKUP_OBJECT (startwin, content, "content"); - g_signal_connect((gpointer)startwin, "destroy", G_CALLBACK(gtk_widget_destroyed), (gpointer)&startwin); - gtk_widget_show (startwin); - gtk_main_iteration_do (FALSE); + g_signal_connect((gpointer)startwin, "destroy", G_CALLBACK(gtk_widget_destroyed), (gpointer)&startwin); + gtk_widget_show (startwin); + gtk_main_iteration_do (FALSE); } void gtkbuild_settitle_startwin(const char *title) { - if (!gtkenabled || !startwin) return; - gtk_window_set_title (GTK_WINDOW (startwin), title); + if (!gtkenabled || !startwin) return; + gtk_window_set_title (GTK_WINDOW (startwin), title); } void gtkbuild_puts_startwin(const char *str) { - GtkWidget *textview; - GtkTextBuffer *textbuffer; - GtkTextIter enditer; - GtkTextMark *mark; - const char *aptr, *bptr; + GtkWidget *textview; + GtkTextBuffer *textbuffer; + GtkTextIter enditer; + GtkTextMark *mark; + const char *aptr, *bptr; - if (!gtkenabled || !startwin || !str) return; - if (!(textview = lookup_widget(startwin, "content"))) return; - textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); + if (!gtkenabled || !startwin || !str) return; + if (!(textview = lookup_widget(startwin, "content"))) return; + textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); - gtk_text_buffer_get_end_iter(textbuffer, &enditer); - for (aptr = bptr = str; *aptr != 0; ) { - switch (*bptr) { - case '\b': - if (bptr > aptr) - gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); + gtk_text_buffer_get_end_iter(textbuffer, &enditer); + for (aptr = bptr = str; *aptr != 0; ) { + switch (*bptr) { + case '\b': + if (bptr > aptr) + gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); #if GTK_CHECK_VERSION(2,6,0) - gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); + gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); #else - { - GtkTextIter iter2 = enditer; - gtk_text_iter_backward_cursor_position(&iter2); - //FIXME: this seems be deleting one too many chars somewhere! - if (!gtk_text_iter_equal(&iter2, &enditer)) - gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); - } + { + GtkTextIter iter2 = enditer; + gtk_text_iter_backward_cursor_position(&iter2); + //FIXME: this seems be deleting one too many chars somewhere! + if (!gtk_text_iter_equal(&iter2, &enditer)) + gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); + } #endif - aptr = ++bptr; - break; - case 0: - if (bptr > aptr) - gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); - aptr = bptr; - break; - case '\r': // FIXME - default: - bptr++; - break; - } - } + aptr = ++bptr; + break; + case 0: + if (bptr > aptr) + gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); + aptr = bptr; + break; + case '\r': // FIXME + default: + bptr++; + break; + } + } - mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); - gtk_text_buffer_delete_mark(textbuffer, mark); + mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); + gtk_text_buffer_delete_mark(textbuffer, mark); } void gtkbuild_close_startwin(void) { - if (!gtkenabled) return; - if (startwin) { - gtk_widget_destroy (startwin); - startwin = NULL; - } + if (!gtkenabled) return; + if (startwin) { + gtk_widget_destroy (startwin); + startwin = NULL; + } } void gtkbuild_update_startwin(void) { - if (!gtkenabled) return; - gtk_main_iteration_do (FALSE); + if (!gtkenabled) return; + gtk_main_iteration_do (FALSE); } int gtkbuild_msgbox(char *name, char *msg) { - GtkWidget *dialog; + GtkWidget *dialog; - if (!gtkenabled) return -1; + if (!gtkenabled) return -1; - dialog = gtk_message_dialog_new(NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - msg); - gtk_window_set_title(GTK_WINDOW(dialog), name); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + msg); + gtk_window_set_title(GTK_WINDOW(dialog), name); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); - return 1; + return 1; } int gtkbuild_ynbox(char *name, char *msg) { - int r; - GtkWidget *dialog; + int r; + GtkWidget *dialog; - if (!gtkenabled) return -1; + if (!gtkenabled) return -1; - dialog = gtk_message_dialog_new(NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_YES_NO, - msg); - gtk_window_set_title(GTK_WINDOW(dialog), name); - r = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_YES_NO, + msg); + gtk_window_set_title(GTK_WINDOW(dialog), name); + r = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); - if (r == GTK_RESPONSE_YES) return 1; - return 0; + if (r == GTK_RESPONSE_YES) return 1; + return 0; } #ifdef RENDERTYPESDL @@ -215,24 +215,24 @@ extern struct sdlappicon sdlappicon; #endif void gtkbuild_init(int argc, char **argv) { - gtkenabled = gtk_init_check(argc, argv); - if (!gtkenabled) return; + gtkenabled = gtk_init_check(argc, argv); + if (!gtkenabled) return; #ifdef RENDERTYPESDL - appicon = gdk_pixbuf_new_from_data((const guchar *)sdlappicon.pixels, - GDK_COLORSPACE_RGB, TRUE, 8, sdlappicon.width, sdlappicon.height, - sdlappicon.width*4, NULL, NULL); + appicon = gdk_pixbuf_new_from_data((const guchar *)sdlappicon.pixels, + GDK_COLORSPACE_RGB, TRUE, 8, sdlappicon.width, sdlappicon.height, + sdlappicon.width*4, NULL, NULL); #endif - if (appicon) gtk_window_set_default_icon(appicon); + if (appicon) gtk_window_set_default_icon(appicon); } void gtkbuild_exit(int r) { - if (!gtkenabled) return; - if (appicon) g_object_unref((gpointer)appicon); - //gtk_exit(r); + if (!gtkenabled) return; + if (appicon) g_object_unref((gpointer)appicon); + //gtk_exit(r); } void *gtkbuild_get_app_icon(void) { - return appicon; + return appicon; } diff --git a/polymer/build/src/hightile.c b/polymer/build/src/hightile.c index eaa32d0c4..b16287d9d 100644 --- a/polymer/build/src/hightile.c +++ b/polymer/build/src/hightile.c @@ -10,15 +10,15 @@ static palette_t hictinting[MAXPALOOKUPS]; struct hicskybox_t { - long ignore; - char *face[6]; + long ignore; + char *face[6]; }; typedef struct hicreplc_t { - struct hicreplc_t *next; - char palnum, ignore, flags, filler; - char *filename; - float alphacut; - struct hicskybox_t *skybox; + struct hicreplc_t *next; + char palnum, ignore, flags, filler; + char *filename; + float alphacut; + struct hicskybox_t *skybox; } hicreplctyp; static hicreplctyp *hicreplc[MAXTILES]; static char hicfirstinit = 0; @@ -28,27 +28,27 @@ static char hicfirstinit = 0; // static hicreplctyp * hicfindsubst(long picnum, long palnum, long skybox) { - hicreplctyp *hr; + hicreplctyp *hr; - if (!hicfirstinit) return NULL; - if ((unsigned long)picnum >= (unsigned long)MAXTILES) return NULL; + if (!hicfirstinit) return NULL; + if ((unsigned long)picnum >= (unsigned long)MAXTILES) return NULL; - do { - for (hr = hicreplc[picnum]; hr; hr = hr->next) { - if (hr->palnum == palnum) { - if (skybox) { - if (hr->skybox && !hr->skybox->ignore) return hr; - } else { - if (!hr->ignore) return hr; - } - } - } + do { + for (hr = hicreplc[picnum]; hr; hr = hr->next) { + if (hr->palnum == palnum) { + if (skybox) { + if (hr->skybox && !hr->skybox->ignore) return hr; + } else { + if (!hr->ignore) return hr; + } + } + } - if (!palnum) break; - palnum = 0; - } while (1); + if (!palnum) break; + palnum = 0; + } while (1); - return NULL; // no replacement found + return NULL; // no replacement found } @@ -58,36 +58,36 @@ static hicreplctyp * hicfindsubst(long picnum, long palnum, long skybox) // void hicinit(void) { - long i,j; - hicreplctyp *hr, *next; - - for (i=0;i=0;i--) { - for (hr=hicreplc[i]; hr; ) { - next = hr->next; + for (i=0;iskybox) { - for (j=5;j>=0;j--) { - if (hr->skybox->face[j]) { - free(hr->skybox->face[j]); - } - } - free(hr->skybox); - } - if (hr->filename) free(hr->filename); - free(hr); + if (hicfirstinit) + for (i=MAXTILES-1;i>=0;i--) { + for (hr=hicreplc[i]; hr; ) { + next = hr->next; - hr = next; - } - } - memset(hicreplc,0,sizeof(hicreplc)); - - hicfirstinit = 1; + if (hr->skybox) { + for (j=5;j>=0;j--) { + if (hr->skybox->face[j]) { + free(hr->skybox->face[j]); + } + } + free(hr->skybox); + } + if (hr->filename) free(hr->filename); + free(hr); + + hr = next; + } + } + memset(hicreplc,0,sizeof(hicreplc)); + + hicfirstinit = 1; } @@ -99,13 +99,13 @@ void hicinit(void) // void hicsetpalettetint(long palnum, unsigned char r, unsigned char g, unsigned char b, unsigned char effect) { - if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return; - if (!hicfirstinit) hicinit(); + if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return; + if (!hicfirstinit) hicinit(); - hictinting[palnum].r = r; - hictinting[palnum].g = g; - hictinting[palnum].b = b; - hictinting[palnum].f = effect & HICEFFECTMASK; + hictinting[palnum].r = r; + hictinting[palnum].g = g; + hictinting[palnum].b = b; + hictinting[palnum].f = effect & HICEFFECTMASK; } @@ -115,44 +115,44 @@ void hicsetpalettetint(long palnum, unsigned char r, unsigned char g, unsigned c // int hicsetsubsttex(long picnum, long palnum, char *filen, float alphacut, char flags) { - hicreplctyp *hr, *hrn; + hicreplctyp *hr, *hrn; - if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; - if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; - if (!hicfirstinit) hicinit(); + if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; + if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; + if (!hicfirstinit) hicinit(); - for (hr = hicreplc[picnum]; hr; hr = hr->next) { - if (hr->palnum == palnum) - break; - } + for (hr = hicreplc[picnum]; hr; hr = hr->next) { + if (hr->palnum == palnum) + break; + } - if (!hr) { - // no replacement yet defined - hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); - if (!hrn) return -1; - hrn->palnum = palnum; - } else hrn = hr; + if (!hr) { + // no replacement yet defined + hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); + if (!hrn) return -1; + hrn->palnum = palnum; + } else hrn = hr; - // store into hicreplc the details for this replacement - if (hrn->filename) free(hrn->filename); + // store into hicreplc the details for this replacement + if (hrn->filename) free(hrn->filename); - hrn->filename = strdup(filen); - if (!hrn->filename) { - if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined - if (hr == NULL) free(hrn); // not yet a link in the chain - return -1; - } - hrn->ignore = 0; - hrn->alphacut = min(alphacut,1.0); - hrn->flags = flags; - if (hr == NULL) { - hrn->next = hicreplc[picnum]; - hicreplc[picnum] = hrn; - } + hrn->filename = strdup(filen); + if (!hrn->filename) { + if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined + if (hr == NULL) free(hrn); // not yet a link in the chain + return -1; + } + hrn->ignore = 0; + hrn->alphacut = min(alphacut,1.0); + hrn->flags = flags; + if (hr == NULL) { + hrn->next = hicreplc[picnum]; + hicreplc[picnum] = hrn; + } - //printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename); + //printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename); - return 0; + return 0; } @@ -162,59 +162,59 @@ int hicsetsubsttex(long picnum, long palnum, char *filen, float alphacut, char f // int hicsetskybox(long picnum, long palnum, char *faces[6]) { - hicreplctyp *hr, *hrn; - long j; + hicreplctyp *hr, *hrn; + long j; - if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; - if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; - for (j=5;j>=0;j--) if (!faces[j]) return -1; - if (!hicfirstinit) hicinit(); + if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; + if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; + for (j=5;j>=0;j--) if (!faces[j]) return -1; + if (!hicfirstinit) hicinit(); - for (hr = hicreplc[picnum]; hr; hr = hr->next) { - if (hr->palnum == palnum) - break; - } + for (hr = hicreplc[picnum]; hr; hr = hr->next) { + if (hr->palnum == palnum) + break; + } - if (!hr) { - // no replacement yet defined - hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); - if (!hrn) return -1; + if (!hr) { + // no replacement yet defined + hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); + if (!hrn) return -1; - hrn->palnum = palnum; - } else hrn = hr; - - if (!hrn->skybox) { - hrn->skybox = (struct hicskybox_t *)calloc(1,sizeof(struct hicskybox_t)); - if (!hrn->skybox) { - if (hr == NULL) free(hrn); // not yet a link in the chain - return -1; - } - } else { - for (j=5;j>=0;j--) { - if (hrn->skybox->face[j]) - free(hrn->skybox->face[j]); - } - } + hrn->palnum = palnum; + } else hrn = hr; - // store each face's filename - for (j=0;j<6;j++) { - hrn->skybox->face[j] = strdup(faces[j]); - if (!hrn->skybox->face[j]) { - for (--j; j>=0; --j) // free any previous faces - free(hrn->skybox->face[j]); - free(hrn->skybox); - hrn->skybox = NULL; - if (hr == NULL) free(hrn); - return -1; - } - } - hrn->skybox->ignore = 0; - if (hr == NULL) { - hrn->next = hicreplc[picnum]; - hicreplc[picnum] = hrn; - } + if (!hrn->skybox) { + hrn->skybox = (struct hicskybox_t *)calloc(1,sizeof(struct hicskybox_t)); + if (!hrn->skybox) { + if (hr == NULL) free(hrn); // not yet a link in the chain + return -1; + } + } else { + for (j=5;j>=0;j--) { + if (hrn->skybox->face[j]) + free(hrn->skybox->face[j]); + } + } - return 0; + // store each face's filename + for (j=0;j<6;j++) { + hrn->skybox->face[j] = strdup(faces[j]); + if (!hrn->skybox->face[j]) { + for (--j; j>=0; --j) // free any previous faces + free(hrn->skybox->face[j]); + free(hrn->skybox); + hrn->skybox = NULL; + if (hr == NULL) free(hrn); + return -1; + } + } + hrn->skybox->ignore = 0; + if (hr == NULL) { + hrn->next = hicreplc[picnum]; + hicreplc[picnum] = hrn; + } + + return 0; } @@ -224,31 +224,31 @@ int hicsetskybox(long picnum, long palnum, char *faces[6]) // int hicclearsubst(long picnum, long palnum) { - hicreplctyp *hr, *hrn = NULL; + hicreplctyp *hr, *hrn = NULL; - if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; - if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; - if (!hicfirstinit) return 0; + if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1; + if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1; + if (!hicfirstinit) return 0; - for (hr = hicreplc[picnum]; hr; hrn = hr, hr = hr->next) { - if (hr->palnum == palnum) - break; - } + for (hr = hicreplc[picnum]; hr; hrn = hr, hr = hr->next) { + if (hr->palnum == palnum) + break; + } - if (!hr) return 0; + if (!hr) return 0; - if (hr->filename) free(hr->filename); - if (hr->skybox) { - int i; - for (i=5;i>=0;i--) - if (hr->skybox->face[i]) - free(hr->skybox->face[i]); - free(hr->skybox); - } + if (hr->filename) free(hr->filename); + if (hr->skybox) { + int i; + for (i=5;i>=0;i--) + if (hr->skybox->face[i]) + free(hr->skybox->face[i]); + free(hr->skybox); + } - if (hrn) hrn->next = hr->next; - else hicreplc[picnum] = hr->next; - free(hr); + if (hrn) hrn->next = hr->next; + else hicreplc[picnum] = hr->next; + free(hr); - return 0; + return 0; } diff --git a/polymer/build/src/kplib.c b/polymer/build/src/kplib.c index f3db7dd75..25a5f11ab 100644 --- a/polymer/build/src/kplib.c +++ b/polymer/build/src/kplib.c @@ -55,12 +55,12 @@ static unsigned short SSWAPIL (unsigned short a) { return((a>>8)+(a<<8)); } #include typedef long long __int64; static __inline long _lrotl (long i, int sh) - { return((i>>(-sh))|(i<>(-sh))|(i<>8) + ((a&0xff00)<<8) + (a<<24) + (a>>24)); + return(((a&0xff0000)>>8) + ((a&0xff00)<<8) + (a<<24) + (a>>24)); } static inline long bitrev (long b, long c) { - long i, j; - for(i=1,j=0,c=(1< 0x8000000) - { - cpuid(0x80000001,cpb); - i |= (cpb[3]&(1<<31)); - if (!((cpid[1]^0x68747541)|(cpid[3]^0x69746e65)|(cpid[2]^0x444d4163))) //AuthenticAMD - i |= (cpb[3]&((1<<22)|(1<<30))); - } - if (i&(1<<25)) i |= (1<<22); //SSE implies MMX+ support - return(i); + long i, cpb[4], cpid[4]; + if (!testflag(0x200000)) return(0); + cpuid(0,cpid); if (!cpid[0]) return(0); + cpuid(1,cpb); i = (cpb[3]&~((1<<22)|(1<<30)|(1<<31))); + cpuid(0x80000000,cpb); + if (((unsigned long)cpb[0]) > 0x8000000) + { + cpuid(0x80000001,cpb); + i |= (cpb[3]&(1<<31)); + if (!((cpid[1]^0x68747541)|(cpid[3]^0x69746e65)|(cpid[2]^0x444d4163))) //AuthenticAMD + i |= (cpb[3]&((1<<22)|(1<<30))); + } + if (i&(1<<25)) i |= (1<<22); //SSE implies MMX+ support + return(i); } static unsigned char fakebuf[8], *nfilptr; static long nbitpos; static void suckbitsnextblock () { - long n; + long n; - if (!zipfilmode) - { - if (!nfilptr) - { //|===|===|crc|lng|typ|===|===| - // \ fakebuf: / - // |===|===| - //----x O---x O-------- - nbitpos = LSWAPIL(*(long *)&filptr[8]); - nfilptr = (unsigned char *)&filptr[nbitpos+12]; - *(long *)&fakebuf[0] = *(long *)&filptr[0]; //Copy last dword of IDAT chunk - if (*(long *)&filptr[12] == LSWAPIB(0x54414449)) //Copy 1st dword of next IDAT chunk - *(long *)&fakebuf[4] = *(long *)&filptr[16]; - filptr = &fakebuf[4]; bitpos -= 32; - } - else - { - filptr = nfilptr; nfilptr = 0; - bitpos -= ((nbitpos-4)<<3); - } - //if (n_from_suckbits < 4) will it crash? - } - else - { - //NOTE: should only read bytes inside compsize, not 64K!!! :/ - *(long *)&olinbuf[0] = *(long *)&olinbuf[sizeof(olinbuf)-4]; - n = min((unsigned)(kzfs.compleng-kzfs.comptell),sizeof(olinbuf)-4); - fread(&olinbuf[4],n,1,kzfs.fil); - kzfs.comptell += n; - bitpos -= ((sizeof(olinbuf)-4)<<3); - } + if (!zipfilmode) + { + if (!nfilptr) + { //|===|===|crc|lng|typ|===|===| + // \ fakebuf: / + // |===|===| + //----x O---x O-------- + nbitpos = LSWAPIL(*(long *)&filptr[8]); + nfilptr = (unsigned char *)&filptr[nbitpos+12]; + *(long *)&fakebuf[0] = *(long *)&filptr[0]; //Copy last dword of IDAT chunk + if (*(long *)&filptr[12] == LSWAPIB(0x54414449)) //Copy 1st dword of next IDAT chunk + *(long *)&fakebuf[4] = *(long *)&filptr[16]; + filptr = &fakebuf[4]; bitpos -= 32; + } + else + { + filptr = nfilptr; nfilptr = 0; + bitpos -= ((nbitpos-4)<<3); + } + //if (n_from_suckbits < 4) will it crash? + } + else + { + //NOTE: should only read bytes inside compsize, not 64K!!! :/ + *(long *)&olinbuf[0] = *(long *)&olinbuf[sizeof(olinbuf)-4]; + n = min((unsigned)(kzfs.compleng-kzfs.comptell),sizeof(olinbuf)-4); + fread(&olinbuf[4],n,1,kzfs.fil); + kzfs.comptell += n; + bitpos -= ((sizeof(olinbuf)-4)<<3); + } } static _inline long peekbits (long n) { return((LSWAPIB(*(long *)&filptr[bitpos>>3])>>(bitpos&7))&pow2mask[n]); } @@ -426,14 +426,14 @@ static _inline long getbits (long n) { long i = peekbits(n); suckbits(n); return static long hufgetsym (long *hitab, long *hbmax) { - long v, n; + long v, n; - v = n = 0; - do { v = (v<<1)+getbits(1)+hbmax[n]-hbmax[n+1]; n++; } while (v >= 0); - return(hitab[hbmax[n]+v]); + v = n = 0; + do { v = (v<<1)+getbits(1)+hbmax[n]-hbmax[n+1]; n++; } while (v >= 0); + return(hitab[hbmax[n]+v]); } - //This did not result in a speed-up on P4-3.6Ghz (02/22/2005) +//This did not result in a speed-up on P4-3.6Ghz (02/22/2005) //static long hufgetsym_skipb (long *hitab, long *hbmax, long n, long addit) //{ // long v; @@ -445,167 +445,167 @@ static long hufgetsym (long *hitab, long *hbmax) static void qhufgencode (long *hitab, long *hbmax, long *qhval, unsigned char *qhbit, long numbits) { - long i, j, k, n, r; + long i, j, k, n, r; - //r is the bit reverse of i. Ex: if: i = 1011100111, r = 1110011101 - i = r = 0; - for(n=1;n<=numbits;n++) - for(k=hbmax[n-1];k>n)&1) + hbmax[n]-hbmax[n+1]; - // - //n = numbits; - //k = hbmax[n]-r; - // - //j = peekbits(LOGQHUFSIZ); i = qhufval[j]; j = qhufbit[j]; - // - //i = j = 0; - //do - //{ - // i = (i<<1)+getbits(1)+nbuf0[j]-nbuf0[j+1]; j++; - //} while (i >= 0); - //i = ibuf0[nbuf0[j]+i]; - //qhval[r] = k; + //k = 0; + //for(n=0;n>n)&1) + hbmax[n]-hbmax[n+1]; + // + //n = numbits; + //k = hbmax[n]-r; + // + //j = peekbits(LOGQHUFSIZ); i = qhufval[j]; j = qhufbit[j]; + // + //i = j = 0; + //do + //{ + // i = (i<<1)+getbits(1)+nbuf0[j]-nbuf0[j+1]; j++; + //} while (i >= 0); + //i = ibuf0[nbuf0[j]+i]; + //qhval[r] = k; - qhbit[r] = 0; //n-32; - } + qhbit[r] = 0; //n-32; + } - // //hufgetsym_skipb related code: - //for(k=n=0;n=0;i--) tbuf[inbuf[i]]++; - tbuf[0] = hbmax[0] = 0; //Hack to remove symbols of length 0? - for(i=0;i<31;i++) hbmax[i+1] = hbmax[i]+tbuf[i]; - for(i=0;i=0;i--) tbuf[inbuf[i]]++; + tbuf[0] = hbmax[0] = 0; //Hack to remove symbols of length 0? + for(i=0;i<31;i++) hbmax[i+1] = hbmax[i]+tbuf[i]; + for(i=0;i>i)&15); - iyoff = ((0x00402010>>i)&15); - if (((ixoff >= xsiz) || (iyoff >= ysiz)) && (intlac >= 2)) { i = -1; intlac--; } - } while (i < 0); - j = ((0x33221100>>i)&15); ixstp = (1<>i)&15); iystp = (1<>i)&15); + iyoff = ((0x00402010>>i)&15); + if (((ixoff >= xsiz) || (iyoff >= ysiz)) && (intlac >= 2)) { i = -1; intlac--; } + } while (i < 0); + j = ((0x33221100>>i)&15); ixstp = (1<>i)&15); iystp = (1<>3) = 2 - //j=3,ixoff=4 2 ((12+(1<<3)-1 - 4)>>3) = 1 - //j=2,ixoff=2 3 4 5 ((12+(1<<2)-1 - 2)>>2) = 3 - //j=1,ixoff=1 6 7 8 9 a b ((12+(1<<1)-1 - 1)>>1) = 6 - ixsiz = ((xsiz+ixstp-1-ixoff)>>j); //It's confusing! See the above example. - nbpl = (bytesperline<>3) = 2 + //j=3,ixoff=4 2 ((12+(1<<3)-1 - 4)>>3) = 1 + //j=2,ixoff=2 3 4 5 ((12+(1<<2)-1 - 2)>>2) = 3 + //j=1,ixoff=1 6 7 8 9 a b ((12+(1<<1)-1 - 1)>>1) = 6 + ixsiz = ((xsiz+ixstp-1-ixoff)>>j); //It's confusing! See the above example. + nbpl = (bytesperline<>(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; - } + //Initialize this to make filters fast: + 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; + } - memset(olinbuf,0,(xsizbpl+1)*sizeof(olinbuf[0])); - *(long *)&opixbuf0[0] = *(long *)&opixbuf1[0] = 0; - xplc = xsizbpl; yplc = globyoffs+iyoff; xm = 0; filt = -1; + memset(olinbuf,0,(xsizbpl+1)*sizeof(olinbuf[0])); + *(long *)&opixbuf0[0] = *(long *)&opixbuf1[0] = 0; + xplc = xsizbpl; yplc = globyoffs+iyoff; xm = 0; filt = -1; - i = globxoffs+ixoff; i = (((-(i>=0))|(ixstp-1))&i); - k = (((-(yplc>=0))|(iystp-1))&yplc); - nfplace = k*bytesperline + (i<<2) + frameplace; + i = globxoffs+ixoff; i = (((-(i>=0))|(ixstp-1))&i); + k = (((-(yplc>=0))|(iystp-1))&yplc); + nfplace = k*bytesperline + (i<<2) + frameplace; - //Precalculate x-clipping to screen borders (speeds up putbuf) - //Equation: (0 <= xr <= ixsiz) && (0 <= xr*ixstp+globxoffs+ixoff <= xres) - xr0 = max((-globxoffs-ixoff+(1<>j,0); - xr1 = min((xres-globxoffs-ixoff+(1<>j,ixsiz); - xr0 = ixsiz-xr0; - xr1 = ixsiz-xr1; + //Precalculate x-clipping to screen borders (speeds up putbuf) + //Equation: (0 <= xr <= ixsiz) && (0 <= xr*ixstp+globxoffs+ixoff <= xres) + xr0 = max((-globxoffs-ixoff+(1<>j,0); + xr1 = min((xres-globxoffs-ixoff+(1<>j,ixsiz); + xr0 = ixsiz-xr0; + xr1 = ixsiz-xr1; - if (coltype == 4) { xr0 = xr0*2; xr1 = xr1*2; } - else if (coltype == 2) { xr0 = xr0*3-2; xr1 = xr1*3-2; } - else if (coltype == 6) { xr0 = xr0*4-2; xr1 = xr1*4-2; } - else - { - switch(bitdepth) - { - case 1: xr0 += ((-ixsiz)&7)+7; - xr1 += ((-ixsiz)&7)+7; break; - case 2: xr0 = ((xr0+((-ixsiz)&3)+3)<<1); - xr1 = ((xr1+((-ixsiz)&3)+3)<<1); break; - case 4: xr0 = ((xr0+((-ixsiz)&1)+1)<<2); - xr1 = ((xr1+((-ixsiz)&1)+1)<<2); break; - } - } - ixstp <<= 2; - return(0); +if (coltype == 4) { xr0 = xr0*2; xr1 = xr1*2; } + else if (coltype == 2) { xr0 = xr0*3-2; xr1 = xr1*3-2; } + else if (coltype == 6) { xr0 = xr0*4-2; xr1 = xr1*4-2; } + else + { + switch(bitdepth) + { + case 1: xr0 += ((-ixsiz)&7)+7; + xr1 += ((-ixsiz)&7)+7; break; + case 2: xr0 = ((xr0+((-ixsiz)&3)+3)<<1); + xr1 = ((xr1+((-ixsiz)&3)+3)<<1); break; + case 4: xr0 = ((xr0+((-ixsiz)&1)+1)<<2); + xr1 = ((xr1+((-ixsiz)&1)+1)<<2); break; + } + } + ixstp <<= 2; + return(0); } static long Paeth (long a, long b, long c) { - long pa, pb, pc; + long pa, pb, pc; - pa = b-c; pb = a-c; pc = labs(pa+pb); pa = labs(pa); pb = labs(pb); - if ((pa <= pb) && (pa <= pc)) return(a); - if (pb <= pc) return(b); else return(c); + pa = b-c; pb = a-c; pc = labs(pa+pb); pa = labs(pa); pb = labs(pb); + if ((pa <= pb) && (pa <= pc)) return(a); + if (pb <= pc) return(b); else return(c); } #if defined(NOASM) static inline long Paeth686 (long a, long b, long c) { - return(Paeth(a,b,c)); + return(Paeth(a,b,c)); } static inline void rgbhlineasm (long x, long xr1, long p, long ixstp) { - long i; - if (!trnsrgb) - { - for(;x>xr1;p+=ixstp,x-=3) *(long *)p = (*(long *)&olinbuf[x])|LSWAPIB(0xff000000); - return; - } - for(;x>xr1;p+=ixstp,x-=3) - { - i = (*(long *)&olinbuf[x])|LSWAPIB(0xff000000); - if (i == trnsrgb) i &= LSWAPIB(0xffffff); - *(long *)p = i; - } + long i; + if (!trnsrgb) + { + for(;x>xr1;p+=ixstp,x-=3) *(long *)p = (*(long *)&olinbuf[x])|LSWAPIB(0xff000000); + return; + } + for(;x>xr1;p+=ixstp,x-=3) + { + i = (*(long *)&olinbuf[x])|LSWAPIB(0xff000000); + if (i == trnsrgb) i &= LSWAPIB(0xffffff); + *(long *)p = i; + } } static inline void pal8hlineasm (long x, long xr1, long p, long ixstp) { - for(;x>xr1;p+=ixstp,x--) *(long *)p = palcol[olinbuf[x]]; + for(;x>xr1;p+=ixstp,x--) *(long *)p = palcol[olinbuf[x]]; } #elif defined(__WATCOMC__) - //NOTE: cmov now has correctly ordered registers (thx to bug fix in 11.0c!) +//NOTE: cmov now has correctly ordered registers (thx to bug fix in 11.0c!) long Paeth686 (long, long, long); #pragma aux Paeth686 =\ ".686"\ @@ -624,7 +624,7 @@ long Paeth686 (long, long, long); modify exact [ecx edx esi edi]\ value [ecx] - //Note: "cmove eax,?" may be faster than "jne ?:and eax,?" but who cares +//Note: "cmove eax,?" may be faster than "jne ?:and eax,?" but who cares void rgbhlineasm (long, long, long, long); #pragma aux rgbhlineasm =\ "sub ecx, edx"\ @@ -673,120 +673,120 @@ void pal8hlineasm (long, long, long, long); static _inline long Paeth686 (long a, long b, long c) { - _asm - { - mov eax, a - mov ebx, b - mov ecx, c - mov edx, ecx - sub edx, eax - sub edx, ebx - lea edx, abstab10[edx*4+2048] - mov esi, [ebx*4+edx] - mov edi, [ecx*4+edx] - cmp edi, esi - cmovge edi, esi - cmovge ecx, ebx - cmp edi, [eax*4+edx] - cmovl eax, ecx - } + _asm + { + mov eax, a + mov ebx, b + mov ecx, c + mov edx, ecx + sub edx, eax + sub edx, ebx + lea edx, abstab10[edx*4+2048] + mov esi, [ebx*4+edx] + mov edi, [ecx*4+edx] + cmp edi, esi + cmovge edi, esi + cmovge ecx, ebx + cmp edi, [eax*4+edx] + cmovl eax, ecx + } } static _inline void rgbhlineasm (long c, long d, long t, long b) { - _asm - { - mov ecx, c - mov edx, d - mov edi, t - mov ebx, b - sub ecx, edx - jle short endit - add edx, offset olinbuf - cmp dword ptr trnsrgb, 0 - jz short begit2 - begit: mov eax, dword ptr [ecx+edx] - or eax, 0xff000000 - cmp eax, dword ptr trnsrgb - jne short skipit - and eax, 0xffffff - skipit: sub ecx, 3 - mov [edi], eax - lea edi, [edi+ebx] - jnz short begit - jmp short endit - begit2: mov eax, dword ptr [ecx+edx] - or eax, 0xff000000 - sub ecx, 3 - mov [edi], eax - lea edi, [edi+ebx] - jnz short begit2 - endit: - } -} + _asm + { + mov ecx, c + mov edx, d + mov edi, t + mov ebx, b + sub ecx, edx + jle short endit + add edx, offset olinbuf + cmp dword ptr trnsrgb, 0 + jz short begit2 + begit: mov eax, dword ptr [ecx+edx] + or eax, 0xff000000 + cmp eax, dword ptr trnsrgb + jne short skipit + and eax, 0xffffff + skipit: sub ecx, 3 + mov [edi], eax + lea edi, [edi+ebx] + jnz short begit + jmp short endit + begit2: mov eax, dword ptr [ecx+edx] + or eax, 0xff000000 + sub ecx, 3 + mov [edi], eax + lea edi, [edi+ebx] + jnz short begit2 + endit: + } + } static _inline void pal8hlineasm (long c, long d, long t, long b) { - _asm - { - mov ecx, c - mov edx, d - mov edi, t - mov ebx, b - sub ecx, edx - jle short endit - add edx, offset olinbuf - 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 - endit: - } -} + _asm + { + mov ecx, c + mov edx, d + mov edi, t + mov ebx, b + sub ecx, edx + jle short endit + add edx, offset olinbuf + 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 + endit: + } + } #elif defined(__GNUC__) && defined(__i386__) static inline long Paeth686 (long a, long b, long 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" - ); - return 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" + ); + return c; } - //Note: "cmove eax,?" may be faster than "jne ?:and eax,?" but who cares +//Note: "cmove eax,?" may be faster than "jne ?:and eax,?" but who cares static inline void rgbhlineasm (long c, long d, long t, long 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" - ); + __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" + ); } static inline void pal8hlineasm (long c, long d, long t, long 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" - ); + __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" + ); } #else @@ -797,400 +797,400 @@ static inline void pal8hlineasm (long c, long d, long t, long b) static void putbuf (const unsigned char *buf, long leng) { - long i, x, p; + long i, x, p; - if (filt < 0) - { - if (leng <= 0) return; - filt = buf[0]; if (filt == gotcmov) filt = 5; - i = 1; - } else i = 0; + if (filt < 0) + { + if (leng <= 0) return; + filt = buf[0]; if (filt == gotcmov) filt = 5; + i = 1; + } else i = 0; - while (i < leng) - { - x = i+xplc; if (x > leng) x = leng; - switch (filt) - { - case 0: - while (i < x) { olinbuf[xplc] = buf[i]; xplc--; i++; } - break; - case 1: - while (i < x) - { - olinbuf[xplc] = (opixbuf1[xm] += buf[i]); - xm = xmn[xm]; xplc--; i++; - } - break; - case 2: - while (i < x) { olinbuf[xplc] += buf[i]; xplc--; i++; } - break; - case 3: - while (i < x) - { - opixbuf1[xm] = olinbuf[xplc] = ((opixbuf1[xm]+olinbuf[xplc])>>1)+buf[i]; - xm = xmn[xm]; xplc--; i++; - } - break; - case 4: - while (i < x) - { - opixbuf1[xm] = (char)(Paeth(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]); - opixbuf0[xm] = olinbuf[xplc]; - olinbuf[xplc] = opixbuf1[xm]; - xm = xmn[xm]; xplc--; i++; - } - break; - case 5: //Special hack for Paeth686 (Doesn't have to be case 5) - while (i < x) - { - opixbuf1[xm] = (char)(Paeth686(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]); - opixbuf0[xm] = olinbuf[xplc]; - olinbuf[xplc] = opixbuf1[xm]; - xm = xmn[xm]; xplc--; i++; - } - break; - } + while (i < leng) + { + x = i+xplc; if (x > leng) x = leng; + switch (filt) + { + case 0: + while (i < x) { olinbuf[xplc] = buf[i]; xplc--; i++; } + break; + case 1: + while (i < x) + { + olinbuf[xplc] = (opixbuf1[xm] += buf[i]); + xm = xmn[xm]; xplc--; i++; + } + break; + case 2: + while (i < x) { olinbuf[xplc] += buf[i]; xplc--; i++; } + break; + case 3: + while (i < x) + { + opixbuf1[xm] = olinbuf[xplc] = ((opixbuf1[xm]+olinbuf[xplc])>>1)+buf[i]; + xm = xmn[xm]; xplc--; i++; + } + break; + case 4: + while (i < x) + { + opixbuf1[xm] = (char)(Paeth(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]); + opixbuf0[xm] = olinbuf[xplc]; + olinbuf[xplc] = opixbuf1[xm]; + xm = xmn[xm]; xplc--; i++; + } + break; + case 5: //Special hack for Paeth686 (Doesn't have to be case 5) + while (i < x) + { + opixbuf1[xm] = (char)(Paeth686(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]); + opixbuf0[xm] = olinbuf[xplc]; + olinbuf[xplc] = opixbuf1[xm]; + xm = xmn[xm]; xplc--; i++; + } + break; + } - if (xplc > 0) return; + if (xplc > 0) return; - //Draw line! - if ((unsigned long)yplc < (unsigned long)yres) - { - x = xr0; p = nfplace; - switch (coltype) - { - case 2: - rgbhlineasm(x,xr1,p,ixstp); - break; - case 4: - for(;x>xr1;p+=ixstp,x-=2) - { + //Draw line! + if ((unsigned long)yplc < (unsigned long)yres) + { + x = xr0; p = nfplace; + switch (coltype) + { + 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) { *(long *)p = palcol[olinbuf[x]]; continue; } - if (!olinbuf[x-1]) { *(long *)p = bakcol; continue; } - //I do >>8, but theoretically should be: /255 - *(char *)(p) = *(char *)(p+1) = *(char *)(p+2) = *(char *)(p+3) = - (((((long)olinbuf[x])-bakr)*(long)olinbuf[x-1])>>8) + bakr; + //Enable this code to process alpha right here! + if (olinbuf[x-1] == 255) { *(long *)p = palcol[olinbuf[x]]; continue; } + if (!olinbuf[x-1]) { *(long *)p = bakcol; continue; } + //I do >>8, but theoretically should be: /255 + *(char *)(p) = *(char *)(p+1) = *(char *)(p+2) = *(char *)(p+3) = + (((((long)olinbuf[x])-bakr)*(long)olinbuf[x-1])>>8) + bakr; #else - *(long *)p = (palcol[olinbuf[x]]&LSWAPIB(0xffffff))|LSWAPIL((long)olinbuf[x-1]); + *(long *)p = (palcol[olinbuf[x]]&LSWAPIB(0xffffff))|LSWAPIL((long)olinbuf[x-1]); #endif - } - break; - case 6: - for(;x>xr1;p+=ixstp,x-=4) - { + } + 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) { *(long *)p = *(long *)&olinbuf[x]; continue; } - if (!olinbuf[x-1]) { *(long *)p = bakcol; continue; } - //I do >>8, but theoretically should be: /255 - *(char *)(p ) = (((((long)olinbuf[x ])-bakr)*(long)olinbuf[x-1])>>8) + bakr; - *(char *)(p+1) = (((((long)olinbuf[x+1])-bakg)*(long)olinbuf[x-1])>>8) + bakg; - *(char *)(p+2) = (((((long)olinbuf[x+2])-bakb)*(long)olinbuf[x-1])>>8) + bakb; + //Enable this code to process alpha right here! + if (olinbuf[x-1] == 255) { *(long *)p = *(long *)&olinbuf[x]; continue; } + if (!olinbuf[x-1]) { *(long *)p = bakcol; continue; } + //I do >>8, but theoretically should be: /255 + *(char *)(p ) = (((((long)olinbuf[x ])-bakr)*(long)olinbuf[x-1])>>8) + bakr; + *(char *)(p+1) = (((((long)olinbuf[x+1])-bakg)*(long)olinbuf[x-1])>>8) + bakg; + *(char *)(p+2) = (((((long)olinbuf[x+2])-bakb)*(long)olinbuf[x-1])>>8) + bakb; #else - *(char *)(p ) = olinbuf[x ]; //R - *(char *)(p+1) = olinbuf[x+1]; //G - *(char *)(p+2) = olinbuf[x+2]; //B - *(char *)(p+3) = olinbuf[x-1]; //A + *(char *)(p ) = olinbuf[x ]; //R + *(char *)(p+1) = olinbuf[x+1]; //G + *(char *)(p+2) = olinbuf[x+2]; //B + *(char *)(p+3) = olinbuf[x-1]; //A #endif - } - break; - default: - switch(bitdepth) - { - case 1: for(;x>xr1;p+=ixstp,x-- ) *(long *)p = palcol[olinbuf[x>>3]>>(x&7)]; break; - case 2: for(;x>xr1;p+=ixstp,x-=2) *(long *)p = palcol[olinbuf[x>>3]>>(x&6)]; break; - case 4: for(;x>xr1;p+=ixstp,x-=4) *(long *)p = palcol[olinbuf[x>>3]>>(x&4)]; break; - case 8: pal8hlineasm(x,xr1,p,ixstp); break; //for(;x>xr1;p+=ixstp,x--) *(long *)p = palcol[olinbuf[x]]; break; - } - break; - } - nfplace += nbpl; - } + } + break; + default: + switch(bitdepth) + { + case 1: for(;x>xr1;p+=ixstp,x-- ) *(long *)p = palcol[olinbuf[x>>3]>>(x&7)]; break; + case 2: for(;x>xr1;p+=ixstp,x-=2) *(long *)p = palcol[olinbuf[x>>3]>>(x&6)]; break; + case 4: for(;x>xr1;p+=ixstp,x-=4) *(long *)p = palcol[olinbuf[x>>3]>>(x&4)]; break; + case 8: pal8hlineasm(x,xr1,p,ixstp); break; //for(;x>xr1;p+=ixstp,x--) *(long *)p = palcol[olinbuf[x]]; break; + } + break; + } + nfplace += nbpl; + } - *(long *)&opixbuf0[0] = *(long *)&opixbuf1[0] = 0; - xplc = xsizbpl; yplc += iystp; - if ((intlac) && (yplc >= globyoffs+ysiz)) { intlac--; initpass(); } - if (i < leng) { filt = buf[i++]; if (filt == gotcmov) filt = 5; } else filt = -1; - } + *(long *)&opixbuf0[0] = *(long *)&opixbuf1[0] = 0; + xplc = xsizbpl; yplc += iystp; + if ((intlac) && (yplc >= globyoffs+ysiz)) { intlac--; initpass(); } + if (i < leng) { filt = buf[i++]; if (filt == gotcmov) filt = 5; } else filt = -1; + } } static void initpngtables() { - long i, j, k; + long i, j, k; - //hxbit[0-58][0-1] is a combination of 4 different tables: - // 1st parameter: [0-29] are distances, [30-58] are lengths - // 2nd parameter: [0]: extra bits, [1]: base number + //hxbit[0-58][0-1] is a combination of 4 different tables: + // 1st parameter: [0-29] are distances, [30-58] are lengths + // 2nd parameter: [0]: extra bits, [1]: base number - j = 1; k = 0; - for(i=0;i<30;i++) - { - hxbit[i][1] = j; j += (1<= 2)); - } - j = 3; k = 0; - for(i=257;i<285;i++) - { - hxbit[i+30-257][1] = j; j += (1<= 264)); - } - hxbit[285+30-257][1] = 258; hxbit[285+30-257][0] = 0; + j = 1; k = 0; + for(i=0;i<30;i++) + { + hxbit[i][1] = j; j += (1<= 2)); + } + j = 3; k = 0; + for(i=257;i<285;i++) + { + hxbit[i+30-257][1] = j; j += (1<= 264)); + } + hxbit[285+30-257][1] = 258; hxbit[285+30-257][0] = 0; - k = getcputype(); - if (k&(1<<15)) - { - gotcmov = 4; - for(i=0;i<512;i++) abstab10[512+i] = abstab10[512-i] = i; - } + k = getcputype(); + if (k&(1<<15)) + { + gotcmov = 4; + for(i=0;i<512;i++) abstab10[512+i] = abstab10[512-i] = i; + } } static long kpngrend (const char *kfilebuf, long kfilength, - long daframeplace, long dabytesperline, long daxres, long dayres, - long daglobxoffs, long daglobyoffs) + long daframeplace, long dabytesperline, long daxres, long dayres, + long daglobxoffs, long daglobyoffs) { - long i, j, k, bfinal, btype, hlit, hdist, leng; - long slidew, slider; - //long qhuf0v, qhuf1v; + long i, j, k, bfinal, btype, hlit, hdist, leng; + long slidew, slider; + //long qhuf0v, qhuf1v; - if (!pnginited) { pnginited = 1; initpngtables(); } + if (!pnginited) { pnginited = 1; initpngtables(); } - if ((*(long *)&kfilebuf[0] != LSWAPIB(0x474e5089)) || (*(long *)&kfilebuf[4] != LSWAPIB(0x0a1a0a0d))) - return(-1); //"Invalid PNG file signature" - filptr = (unsigned char *)&kfilebuf[8]; + if ((*(long *)&kfilebuf[0] != LSWAPIB(0x474e5089)) || (*(long *)&kfilebuf[4] != LSWAPIB(0x0a1a0a0d))) + return(-1); //"Invalid PNG file signature" + filptr = (unsigned char *)&kfilebuf[8]; - trnsrgb = 0; + trnsrgb = 0; - while (1) - { - leng = LSWAPIL(*(long *)&filptr[0]); i = *(long *)&filptr[4]; - filptr = &filptr[8]; + while (1) + { + leng = LSWAPIL(*(long *)&filptr[0]); i = *(long *)&filptr[4]; + filptr = &filptr[8]; - if (i == LSWAPIB(0x52444849)) //IHDR (must be first) - { - xsiz = LSWAPIL(*(long *)&filptr[0]); if (xsiz <= 0) return(-1); - ysiz = LSWAPIL(*(long *)&filptr[4]); if (ysiz <= 0) return(-1); - bitdepth = filptr[8]; if (!((1<= 2) return(-1); //"Unsupported interlace type" - intlac = filptr[12]*7; //0=no interlace/1=Adam7 interlace + if (i == LSWAPIB(0x52444849)) //IHDR (must be first) + { + xsiz = LSWAPIL(*(long *)&filptr[0]); if (xsiz <= 0) return(-1); + ysiz = LSWAPIL(*(long *)&filptr[4]); if (ysiz <= 0) return(-1); + bitdepth = filptr[8]; if (!((1<= 2) return(-1); //"Unsupported interlace type" + intlac = filptr[12]*7; //0=no interlace/1=Adam7 interlace - //Save code by making grayscale look like a palette color scheme - if ((!coltype) || (coltype == 4)) - { - j = 0xff000000; k = (255 / ((1<=0;i--) palcol[i] = LSWAPIB((LSWAPIL(*(long *)&filptr[i*3])>>8)|0xff000000); - } - else if (i == LSWAPIB(0x44474b62)) //bKGD (must be after PLTE and before IDAT) - { - switch(coltype) - { - case 0: case 4: - bakcol = (((long)filptr[0]<<8)+(long)filptr[1])*255/((1<>16)&255); - bakg = ((bakcol>>8)&255); - bakb = (bakcol&255); - bakcol = LSWAPIB(bakcol); - } - else if (i == LSWAPIB(0x534e5274)) //tRNS (must be after PLTE and before IDAT) - { - switch(coltype) - { - case 0: - if (bitdepth <= 8) - palcol[(long)filptr[1]] &= LSWAPIB(0xffffff); - //else {} // /c0 /d16 not yet supported - break; - case 2: - if (bitdepth == 8) - { trnsrgb = LSWAPIB((((long)filptr[1])<<16)+(((long)filptr[3])<<8)+((long)filptr[5])+0xff000000); } - //else {} //WARNING: PNG docs say: MUST compare all 48 bits :( - break; - case 3: - for(i=min(leng,paleng)-1;i>=0;i--) - palcol[i] &= LSWAPIB((((long)filptr[i])<<24)|0xffffff); - break; - default:; - } - } - else if (i == LSWAPIB(0x54414449)) { break; } //IDAT + //Save code by making grayscale look like a palette color scheme + if ((!coltype) || (coltype == 4)) + { + j = 0xff000000; k = (255 / ((1<=0;i--) palcol[i] = LSWAPIB((LSWAPIL(*(long *)&filptr[i*3])>>8)|0xff000000); + } + else if (i == LSWAPIB(0x44474b62)) //bKGD (must be after PLTE and before IDAT) + { + switch(coltype) + { + case 0: case 4: + bakcol = (((long)filptr[0]<<8)+(long)filptr[1])*255/((1<>16)&255); + bakg = ((bakcol>>8)&255); + bakb = (bakcol&255); + bakcol = LSWAPIB(bakcol); + } + else if (i == LSWAPIB(0x534e5274)) //tRNS (must be after PLTE and before IDAT) + { + switch(coltype) + { + case 0: + if (bitdepth <= 8) + palcol[(long)filptr[1]] &= LSWAPIB(0xffffff); + //else {} // /c0 /d16 not yet supported + break; + case 2: + if (bitdepth == 8) + { trnsrgb = LSWAPIB((((long)filptr[1])<<16)+(((long)filptr[3])<<8)+((long)filptr[5])+0xff000000); } + //else {} //WARNING: PNG docs say: MUST compare all 48 bits :( + break; + case 3: + for(i=min(leng,paleng)-1;i>=0;i--) + palcol[i] &= LSWAPIB((((long)filptr[i])<<24)|0xffffff); + break; + default:; + } + } + else if (i == LSWAPIB(0x54414449)) { break; } //IDAT - filptr = &filptr[leng+4]; //crc = LSWAPIL(*(long *)&filptr[-4]); - } + filptr = &filptr[leng+4]; //crc = LSWAPIL(*(long *)&filptr[-4]); + } - //Initialize this for the getbits() function - zipfilmode = 0; - filptr = &filptr[leng-4]; bitpos = -((leng-4)<<3); nfilptr = 0; - //if (leng < 4) will it crash? + //Initialize this for the getbits() function + zipfilmode = 0; + filptr = &filptr[leng-4]; bitpos = -((leng-4)<<3); nfilptr = 0; + //if (leng < 4) will it crash? - frameplace = daframeplace; - bytesperline = dabytesperline; - xres = daxres; - yres = dayres; - globxoffs = daglobxoffs; - globyoffs = daglobyoffs; + frameplace = daframeplace; + bytesperline = dabytesperline; + xres = daxres; + yres = dayres; + globxoffs = daglobxoffs; + globyoffs = daglobyoffs; - 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; - } - 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; - } + 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; + } + 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; + } - //coltype: bitdepth: format: - // 0 1,2,4,8,16 I - // 2 8,16 RGB - // 3 1,2,4,8 P - // 4 8,16 IA - // 6 8,16 RGBA - 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; - } - //Tests to see if xsiz > allocated space in olinbuf - //Note: xsizbpl gets re-written inside initpass() - if ((xsizbpl+1)*sizeof(olinbuf[0]) > sizeof(olinbuf)) return(-1); + //coltype: bitdepth: format: + // 0 1,2,4,8,16 I + // 2 8,16 RGB + // 3 1,2,4,8 P + // 4 8,16 IA + // 6 8,16 RGBA + 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; + } + //Tests to see if xsiz > allocated space in olinbuf + //Note: xsizbpl gets re-written inside initpass() + if ((xsizbpl+1)*sizeof(olinbuf[0]) > sizeof(olinbuf)) return(-1); - initpass(); + initpass(); - slidew = 0; slider = 16384; - suckbits(16); //Actually 2 fields: 8:compmethflags, 8:addflagscheck - do - { - bfinal = getbits(1); btype = getbits(2); - if (btype == 0) - { - //Raw (uncompressed) - suckbits((-bitpos)&7); //Synchronize to start of next byte - i = getbits(16); if ((getbits(16)^i) != 0xffff) return(-1); - for(;i;i--) - { - if (slidew >= slider) - { - putbuf(&slidebuf[(slider-16384)&32767],16384); slider += 16384; - if ((yplc >= yres) && (intlac < 2)) return(0); - } - slidebuf[(slidew++)&32767] = (char)getbits(8); - } - continue; - } - if (btype == 3) continue; + slidew = 0; slider = 16384; + suckbits(16); //Actually 2 fields: 8:compmethflags, 8:addflagscheck + do + { + bfinal = getbits(1); btype = getbits(2); + if (btype == 0) + { + //Raw (uncompressed) + suckbits((-bitpos)&7); //Synchronize to start of next byte + i = getbits(16); if ((getbits(16)^i) != 0xffff) return(-1); + for(;i;i--) + { + if (slidew >= slider) + { + putbuf(&slidebuf[(slider-16384)&32767],16384); slider += 16384; + if ((yplc >= yres) && (intlac < 2)) return(0); + } + slidebuf[(slidew++)&32767] = (char)getbits(8); + } + continue; + } + if (btype == 3) continue; - if (btype == 1) //Fixed Huffman - { - hlit = 288; hdist = 32; i = 0; - for(;i<144;i++) clen[i] = 8; //Fixed bit sizes (literals) - for(;i<256;i++) clen[i] = 9; //Fixed bit sizes (literals) - for(;i<280;i++) clen[i] = 7; //Fixed bit sizes (EOI,lengths) - for(;i<288;i++) clen[i] = 8; //Fixed bit sizes (lengths) - for(;i<320;i++) clen[i] = 5; //Fixed bit sizes (distances) - } - else //Dynamic Huffman - { - hlit = getbits(5)+257; hdist = getbits(5)+1; j = getbits(4)+4; - for(i=0;i= slider) - { - putbuf(&slidebuf[(slider-16384)&32767],16384); slider += 16384; - if ((yplc >= yres) && (intlac < 2)) return(0); - } + while (1) + { + if (slidew >= slider) + { + putbuf(&slidebuf[(slider-16384)&32767],16384); slider += 16384; + if ((yplc >= yres) && (intlac < 2)) return(0); + } - k = peekbits(LOGQHUFSIZ0); - if (qhufbit0[k]) { i = qhufval0[k]; suckbits((long)qhufbit0[k]); } else i = hufgetsym(ibuf0,nbuf0); - //else i = hufgetsym_skipb(ibuf0,nbuf0,LOGQHUFSIZ0,qhuf0v); //hufgetsym_skipb related code + k = peekbits(LOGQHUFSIZ0); + if (qhufbit0[k]) { i = qhufval0[k]; suckbits((long)qhufbit0[k]); } else i = hufgetsym(ibuf0,nbuf0); + //else i = hufgetsym_skipb(ibuf0,nbuf0,LOGQHUFSIZ0,qhuf0v); //hufgetsym_skipb related code - if (i < 256) { slidebuf[(slidew++)&32767] = (char)i; continue; } - if (i == 256) break; - i = getbits(hxbit[i+30-257][0]) + hxbit[i+30-257][1]; + if (i < 256) { slidebuf[(slidew++)&32767] = (char)i; continue; } + if (i == 256) break; + i = getbits(hxbit[i+30-257][0]) + hxbit[i+30-257][1]; - k = peekbits(LOGQHUFSIZ1); - if (qhufbit1[k]) { j = qhufval1[k]; suckbits((long)qhufbit1[k]); } else j = hufgetsym(ibuf1,nbuf1); - //else j = hufgetsym_skipb(ibuf1,nbuf1,LOGQHUFSIZ1,qhuf1v); //hufgetsym_skipb related code + k = peekbits(LOGQHUFSIZ1); + if (qhufbit1[k]) { j = qhufval1[k]; suckbits((long)qhufbit1[k]); } else j = hufgetsym(ibuf1,nbuf1); + //else j = hufgetsym_skipb(ibuf1,nbuf1,LOGQHUFSIZ1,qhuf1v); //hufgetsym_skipb related code - j = getbits(hxbit[j][0]) + hxbit[j][1]; - i += slidew; do { slidebuf[slidew&32767] = slidebuf[(slidew-j)&32767]; slidew++; } while (slidew < i); - } - } while (!bfinal); + j = getbits(hxbit[j][0]) + hxbit[j][1]; + i += slidew; do { slidebuf[slidew&32767] = slidebuf[(slidew-j)&32767]; slidew++; } while (slidew < i); + } + } while (!bfinal); - slider -= 16384; - if (!((slider^slidew)&32768)) - putbuf(&slidebuf[slider&32767],slidew-slider); - else - { - putbuf(&slidebuf[slider&32767],(-slider)&32767); - putbuf(slidebuf,slidew&32767); - } - return(0); + slider -= 16384; + if (!((slider^slidew)&32768)) + putbuf(&slidebuf[slider&32767],slidew-slider); + else + { + putbuf(&slidebuf[slider&32767],(-slider)&32767); + putbuf(slidebuf,slidew&32767); + } + return(0); } //============================= KPNGILIB ends ================================ //============================ KPEGILIB begins =============================== - //11/01/2000: This code was originally from KPEG.C - // All non 32-bit color drawing was removed - // "Motion" JPG code was removed - // A lot of parameters were added to kpeg() for library usage +//11/01/2000: This code was originally from KPEG.C +// All non 32-bit color drawing was removed +// "Motion" JPG code was removed +// A lot of parameters were added to kpeg() for library usage static long kpeginited = 0; static long clipxdim, clipydim; @@ -1209,12 +1209,12 @@ static unsigned char pow2char[8] = {1,2,4,8,16,32,64,128}; static inline long mulshr24 (long a, long b) { - return((long)((((__int64)a)*((__int64)b))>>24)); + return((long)((((__int64)a)*((__int64)b))>>24)); } static inline long mulshr32 (long a, long b) { - return((long)((((__int64)a)*((__int64)b))>>32)); + return((long)((((__int64)a)*((__int64)b))>>32)); } #elif defined(__WATCOMC__) @@ -1237,22 +1237,22 @@ long mulshr32 (long, long); static _inline long mulshr24 (long a, long d) { - _asm - { - mov eax, a - imul d - shrd eax, edx, 24 - } + _asm + { + mov eax, a + imul d + shrd eax, edx, 24 + } } static _inline long mulshr32 (long a, long d) { - _asm - { - mov eax, a - imul d - mov eax, edx - } + _asm + { + mov eax, a + imul d + mov eax, edx + } } #elif defined(__GNUC__) && defined(__i386__) @@ -1276,72 +1276,72 @@ static _inline long mulshr32 (long a, long d) #endif static long cosqr16[8] = //cosqr16[i] = ((cos(PI*i/16)*sqrt(2))<<24); - {23726566,23270667,21920489,19727919,16777216,13181774,9079764,4628823}; + {23726566,23270667,21920489,19727919,16777216,13181774,9079764,4628823}; static long crmul[4096], cbmul[4096]; static void initkpeg () { - long i, x, y; + long i, x, y; - x = 0; //Back & forth diagonal pattern (aligning bytes for best compression) - for(i=0;i<16;i+=2) - { - for(y=8-1;y>=0;y--) - if ((unsigned)(i-y) < (unsigned)8) unzig[x++] = (y<<3)+i-y; - for(y=0;y<8;y++) - if ((unsigned)(i+1-y) < (unsigned)8) unzig[x++] = (y<<3)+i+1-y; - } - for(i=64-1;i>=0;i--) zigit[unzig[i]] = i; - for(i=64-1;i>=0;i--) dcflagor[i] = (unsigned char)(1<<(unzig[i]>>3)); + x = 0; //Back & forth diagonal pattern (aligning bytes for best compression) + for(i=0;i<16;i+=2) + { + for(y=8-1;y>=0;y--) + if ((unsigned)(i-y) < (unsigned)8) unzig[x++] = (y<<3)+i-y; + for(y=0;y<8;y++) + if ((unsigned)(i+1-y) < (unsigned)8) unzig[x++] = (y<<3)+i+1-y; + } + for(i=64-1;i>=0;i--) zigit[unzig[i]] = i; + for(i=64-1;i>=0;i--) dcflagor[i] = (unsigned char)(1<<(unzig[i]>>3)); - for(i=0;i<128;i++) colclip[i] = i+128; - for(i=128;i<512;i++) colclip[i] = 255; - for(i=512;i<896;i++) colclip[i] = 0; - for(i=896;i<1024;i++) colclip[i] = i-896; - for(i=0;i<1024;i++) - { - colclipup8[i] = (colclip[i]<<8); - colclipup16[i] = (colclip[i]<<16)+0xff000000; //Hack: set alphas to 255 - } + for(i=0;i<128;i++) colclip[i] = i+128; + for(i=128;i<512;i++) colclip[i] = 255; + for(i=512;i<896;i++) colclip[i] = 0; + for(i=896;i<1024;i++) colclip[i] = i-896; + for(i=0;i<1024;i++) + { + colclipup8[i] = (colclip[i]<<8); + colclipup16[i] = (colclip[i]<<16)+0xff000000; //Hack: set alphas to 255 + } #if defined(BIGENDIAN) - for(i=0;i<1024;i++) - { - colclip[i] = bswap(colclip[i]); - colclipup8[i] = bswap(colclipup8[i]); - colclipup16[i] = bswap(colclipup16[i]); - } + for(i=0;i<1024;i++) + { + colclip[i] = bswap(colclip[i]); + colclipup8[i] = bswap(colclipup8[i]); + colclipup16[i] = bswap(colclipup16[i]); + } #endif - for(i=0;i<2048;i++) - { - crmul[(i<<1)+0] = (i-1024)*1470104; //1.402*1048576 - crmul[(i<<1)+1] = (i-1024)*-748830; //-0.71414*1048576 - cbmul[(i<<1)+0] = (i-1024)*-360857; //-0.34414*1048576 - cbmul[(i<<1)+1] = (i-1024)*1858077; //1.772*1048576 - } + for(i=0;i<2048;i++) + { + crmul[(i<<1)+0] = (i-1024)*1470104; //1.402*1048576 + crmul[(i<<1)+1] = (i-1024)*-748830; //-0.71414*1048576 + cbmul[(i<<1)+0] = (i-1024)*-360857; //-0.34414*1048576 + cbmul[(i<<1)+1] = (i-1024)*1858077; //1.772*1048576 + } - memset((void *)&dct[10][0],0,64*2*sizeof(dct[0][0])); + memset((void *)&dct[10][0],0,64*2*sizeof(dct[0][0])); } static void huffgetval (long index, long curbits, long num, long *daval, long *dabits) { - long b, v, pow2, *hmax; + long b, v, pow2, *hmax; - hmax = &hufmaxatbit[index][0]; - pow2 = pow2long[curbits-1]; - if (num&pow2) v = 1; else v = 0; - for(b=1;b<=16;b++) - { - if (v < hmax[b]) - { - *dabits = b; - *daval = huftable[index][hufvalatbit[index][b]+v]; - return; - } - pow2 >>= 1; v <<= 1; - if (num&pow2) v++; - } - *dabits = 16; *daval = 0; + hmax = &hufmaxatbit[index][0]; + pow2 = pow2long[curbits-1]; + if (num&pow2) v = 1; else v = 0; + for(b=1;b<=16;b++) + { + if (v < hmax[b]) + { + *dabits = b; + *daval = huftable[index][hufvalatbit[index][b]+v]; + return; + } + pow2 >>= 1; v <<= 1; + if (num&pow2) v++; + } + *dabits = 16; *daval = 0; } static void invdct8x8 (long *dc, unsigned char dcflag) @@ -1350,527 +1350,527 @@ static void invdct8x8 (long *dc, unsigned char dcflag) #define C182 31000253 //(cos(PI/8)*2)<<24 #define C18S22 43840978 //(cos(PI/8)*sqrt(2)*2)<<24 #define C38S22 18159528 //(cos(PI*3/8)*sqrt(2)*2)<<24 - long *edc, t0, t1, t2, t3, t4, t5, t6, t7; + long *edc, t0, t1, t2, t3, t4, t5, t6, t7; - edc = dc+64; - do - { - if (dcflag&1) //pow2char[z]) - { - t3 = dc[2] + dc[6]; - t2 = (mulshr32(dc[2]-dc[6],SQRT2<<6)<<2) - t3; - t4 = dc[0] + dc[4]; t5 = dc[0] - dc[4]; - t0 = t4+t3; t3 = t4-t3; t1 = t5+t2; t2 = t5-t2; - t4 = (mulshr32(dc[5]-dc[3]+dc[1]-dc[7],C182<<6)<<2); - t7 = dc[1] + dc[7] + dc[5] + dc[3]; - t6 = (mulshr32(dc[3]-dc[5],C18S22<<5)<<3) + t4 - t7; - t5 = (mulshr32(dc[1]+dc[7]-dc[5]-dc[3],SQRT2<<6)<<2) - t6; - t4 = (mulshr32(dc[1]-dc[7],C38S22<<6)<<2) - t4 + t5; - dc[0] = t0+t7; dc[7] = t0-t7; dc[1] = t1+t6; dc[6] = t1-t6; - dc[2] = t2+t5; dc[5] = t2-t5; dc[4] = t3+t4; dc[3] = t3-t4; - } - dc += 8; dcflag >>= 1; - } while (dc < edc); - dc -= 32; edc -= 24; - do - { - t3 = dc[2*8-32] + dc[6*8-32]; - t2 = (mulshr32(dc[2*8-32]-dc[6*8-32],SQRT2<<6)<<2) - t3; - t4 = dc[0*8-32] + dc[4*8-32]; t5 = dc[0*8-32] - dc[4*8-32]; - t0 = t4+t3; t3 = t4-t3; t1 = t5+t2; t2 = t5-t2; - t4 = (mulshr32(dc[5*8-32]-dc[3*8-32]+dc[1*8-32]-dc[7*8-32],C182<<6)<<2); - t7 = dc[1*8-32] + dc[7*8-32] + dc[5*8-32] + dc[3*8-32]; - t6 = (mulshr32(dc[3*8-32]-dc[5*8-32],C18S22<<5)<<3) + t4 - t7; - t5 = (mulshr32(dc[1*8-32]+dc[7*8-32]-dc[5*8-32]-dc[3*8-32],SQRT2<<6)<<2) - t6; - t4 = (mulshr32(dc[1*8-32]-dc[7*8-32],C38S22<<6)<<2) - t4 + t5; - dc[0*8-32] = t0+t7; dc[7*8-32] = t0-t7; dc[1*8-32] = t1+t6; dc[6*8-32] = t1-t6; - dc[2*8-32] = t2+t5; dc[5*8-32] = t2-t5; dc[4*8-32] = t3+t4; dc[3*8-32] = t3-t4; - dc++; - } while (dc < edc); + edc = dc+64; + do + { + if (dcflag&1) //pow2char[z]) + { + t3 = dc[2] + dc[6]; + t2 = (mulshr32(dc[2]-dc[6],SQRT2<<6)<<2) - t3; + t4 = dc[0] + dc[4]; t5 = dc[0] - dc[4]; + t0 = t4+t3; t3 = t4-t3; t1 = t5+t2; t2 = t5-t2; + t4 = (mulshr32(dc[5]-dc[3]+dc[1]-dc[7],C182<<6)<<2); + t7 = dc[1] + dc[7] + dc[5] + dc[3]; + t6 = (mulshr32(dc[3]-dc[5],C18S22<<5)<<3) + t4 - t7; + t5 = (mulshr32(dc[1]+dc[7]-dc[5]-dc[3],SQRT2<<6)<<2) - t6; + t4 = (mulshr32(dc[1]-dc[7],C38S22<<6)<<2) - t4 + t5; + dc[0] = t0+t7; dc[7] = t0-t7; dc[1] = t1+t6; dc[6] = t1-t6; + dc[2] = t2+t5; dc[5] = t2-t5; dc[4] = t3+t4; dc[3] = t3-t4; + } + dc += 8; dcflag >>= 1; + } while (dc < edc); + dc -= 32; edc -= 24; + do + { + t3 = dc[2*8-32] + dc[6*8-32]; + t2 = (mulshr32(dc[2*8-32]-dc[6*8-32],SQRT2<<6)<<2) - t3; + t4 = dc[0*8-32] + dc[4*8-32]; t5 = dc[0*8-32] - dc[4*8-32]; + t0 = t4+t3; t3 = t4-t3; t1 = t5+t2; t2 = t5-t2; + t4 = (mulshr32(dc[5*8-32]-dc[3*8-32]+dc[1*8-32]-dc[7*8-32],C182<<6)<<2); + t7 = dc[1*8-32] + dc[7*8-32] + dc[5*8-32] + dc[3*8-32]; + t6 = (mulshr32(dc[3*8-32]-dc[5*8-32],C18S22<<5)<<3) + t4 - t7; + t5 = (mulshr32(dc[1*8-32]+dc[7*8-32]-dc[5*8-32]-dc[3*8-32],SQRT2<<6)<<2) - t6; + t4 = (mulshr32(dc[1*8-32]-dc[7*8-32],C38S22<<6)<<2) - t4 + t5; + dc[0*8-32] = t0+t7; dc[7*8-32] = t0-t7; dc[1*8-32] = t1+t6; dc[6*8-32] = t1-t6; + dc[2*8-32] = t2+t5; dc[5*8-32] = t2-t5; dc[4*8-32] = t3+t4; dc[3*8-32] = t3-t4; + dc++; + } while (dc < edc); } static void yrbrend (long x, long y) { - long i, j, ox, oy, xx, yy, xxx, yyy, xxxend, yyyend, yv, cr, cb, p, pp, *odc, *dc, *dc2; + long i, j, ox, oy, xx, yy, xxx, yyy, xxxend, yyyend, yv, cr, cb, p, pp, *odc, *dc, *dc2; - odc = dct[0]; dc2 = dct[10]; - for(yy=0;yy<(lcompvsamp[0]<<3);yy+=8) - { - oy = y+yy+globyoffs; if ((unsigned)oy >= (unsigned)clipydim) { odc += (lcomphsamp[0]<<6); continue; } - pp = oy*bytesperline + ((x+globxoffs)<<2) + frameplace; - for(xx=0;xx<(lcomphsamp[0]<<3);xx+=8,odc+=64) - { - 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)]; - xxxend = min(clipxdim-ox,8); - yyyend = min(clipydim-oy,8); - if ((lcomphsamp[0] == 1) && (xxxend == 8)) - { - for(yyy=0;yyy>13)&~1; - cb = (dc2[xxx ]>>13)&~1; - ((long *)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]; - } - p += bytesperline; - dc += 8; - if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; - } - } - else if ((lcomphsamp[0] == 2) && (xxxend == 8)) - { - for(yyy=0;yyy>1)+64]>>13)&~1; - cb = (dc2[(xxx>>1) ]>>13)&~1; - i = crmul[cr+2049]+cbmul[cb+2048]; - cr = crmul[cr+2048]; - cb = cbmul[cb+2049]; - ((long *)p)[xxx] = colclipup16[(unsigned)(yv+cr)>>22]+ - colclipup8[(unsigned)(yv+ i)>>22]+ - colclip[(unsigned)(yv+cb)>>22]; - yv = dc[xxx+1]; - ((long *)p)[xxx+1] = colclipup16[(unsigned)(yv+cr)>>22]+ - colclipup8[(unsigned)(yv+ i)>>22]+ - colclip[(unsigned)(yv+cb)>>22]; - } - p += bytesperline; - dc += 8; - if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; - } - } - else - { - for(yyy=0;yyy>13)&~1; - cb = (dc2[i ]>>13)&~1; - i++; - } - ((long *)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]; - } - p += bytesperline; - dc += 8; - if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; - } - } - } - } + odc = dct[0]; dc2 = dct[10]; + for(yy=0;yy<(lcompvsamp[0]<<3);yy+=8) + { + oy = y+yy+globyoffs; if ((unsigned)oy >= (unsigned)clipydim) { odc += (lcomphsamp[0]<<6); continue; } + pp = oy*bytesperline + ((x+globxoffs)<<2) + frameplace; + for(xx=0;xx<(lcomphsamp[0]<<3);xx+=8,odc+=64) + { + 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)]; + xxxend = min(clipxdim-ox,8); + yyyend = min(clipydim-oy,8); + if ((lcomphsamp[0] == 1) && (xxxend == 8)) + { + for(yyy=0;yyy>13)&~1; + cb = (dc2[xxx ]>>13)&~1; + ((long *)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]; + } + p += bytesperline; + dc += 8; + if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; + } + } + else if ((lcomphsamp[0] == 2) && (xxxend == 8)) + { + for(yyy=0;yyy>1)+64]>>13)&~1; + cb = (dc2[(xxx>>1) ]>>13)&~1; + i = crmul[cr+2049]+cbmul[cb+2048]; + cr = crmul[cr+2048]; + cb = cbmul[cb+2049]; + ((long *)p)[xxx] = colclipup16[(unsigned)(yv+cr)>>22]+ + colclipup8[(unsigned)(yv+ i)>>22]+ + colclip[(unsigned)(yv+cb)>>22]; + yv = dc[xxx+1]; + ((long *)p)[xxx+1] = colclipup16[(unsigned)(yv+cr)>>22]+ + colclipup8[(unsigned)(yv+ i)>>22]+ + colclip[(unsigned)(yv+cb)>>22]; + } + p += bytesperline; + dc += 8; + if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; + } + } + else + { + for(yyy=0;yyy>13)&~1; + cb = (dc2[i ]>>13)&~1; + i++; + } + ((long *)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]; + } + p += bytesperline; + dc += 8; + if (!((yyy+1)&(lcompvsamp[0]-1))) dc2 += 8; + } + } + } + } } static long kpegrend (const char *kfilebuf, long kfilength, - long daframeplace, long dabytesperline, long daxres, long dayres, - long daglobxoffs, long daglobyoffs) + long daframeplace, long dabytesperline, long daxres, long dayres, + long daglobxoffs, long daglobyoffs) { - long i, j, p, v, leng, xdim, ydim, index, prec, restartcnt, restartinterval; - long x, y, z, xx, yy, zz, *dc, *dc2, num, curbits, c, daval, dabits, *hqval, *hqbits, hqcnt, *quanptr; - long passcnt = 0, ghsampmax, gvsampmax, glhsampmax, glvsampmax, glhstep, glvstep; - long eobrun, Ss, Se, Ah, Al, Alut[2], dctx[12], dcty[12], ldctx[12], ldcty[12], lshx[4], lshy[4]; - short *dctbuf = 0, *dctptr[12], *ldctptr[12], *dcs; - unsigned char ch, marker, dcflag; - const unsigned char *kfileptr; + long i, j, p, v, leng, xdim, ydim, index, prec, restartcnt, restartinterval; + long x, y, z, xx, yy, zz, *dc, *dc2, num, curbits, c, daval, dabits, *hqval, *hqbits, hqcnt, *quanptr; + long passcnt = 0, ghsampmax, gvsampmax, glhsampmax, glvsampmax, glhstep, glvstep; + long eobrun, Ss, Se, Ah, Al, Alut[2], dctx[12], dcty[12], ldctx[12], ldcty[12], lshx[4], lshy[4]; + short *dctbuf = 0, *dctptr[12], *ldctptr[12], *dcs; + unsigned char ch, marker, dcflag; + const unsigned char *kfileptr; - if (!kpeginited) { kpeginited = 1; initkpeg(); } + if (!kpeginited) { kpeginited = 1; initkpeg(); } - kfileptr = (unsigned char *)kfilebuf; + kfileptr = (unsigned char *)kfilebuf; - if (*(unsigned short *)kfileptr == SSWAPIB(0xd8ff)) kfileptr += 2; - else return(-1); //"%s is not a JPEG file\n",filename + if (*(unsigned short *)kfileptr == SSWAPIB(0xd8ff)) kfileptr += 2; + else return(-1); //"%s is not a JPEG file\n",filename - restartinterval = 0; - for(i=0;i<4;i++) lastdc[i] = 0; - for(i=0;i<8;i++) hufcnt[i] = 0; + restartinterval = 0; + for(i=0;i<4;i++) lastdc[i] = 0; + for(i=0;i<8;i++) hufcnt[i] = 0; - coltype = 0; bitdepth = 8; //For PNGOUT - do - { - ch = *kfileptr++; if (ch != 255) continue; - do { marker = *kfileptr++; } while (marker == 255); - if (marker != 0xd9) //Don't read past end of buffer - { - leng = ((long)kfileptr[0]<<8)+(long)kfileptr[1]-2; - kfileptr += 2; - } - //printf("fileoffs=%08x, marker=%02x,leng=%d",((long)kfileptr)-((long)kfilebuf)-2,marker,leng); - switch(marker) - { - case 0xc0: case 0xc1: case 0xc2: - //processit! - kfileptr++; //numbits = *kfileptr++; + coltype = 0; bitdepth = 8; //For PNGOUT + do + { + ch = *kfileptr++; if (ch != 255) continue; + do { marker = *kfileptr++; } while (marker == 255); + if (marker != 0xd9) //Don't read past end of buffer + { + leng = ((long)kfileptr[0]<<8)+(long)kfileptr[1]-2; + kfileptr += 2; + } + //printf("fileoffs=%08x, marker=%02x,leng=%d",((long)kfileptr)-((long)kfilebuf)-2,marker,leng); + switch(marker) + { +case 0xc0: case 0xc1: case 0xc2: + //processit! + kfileptr++; //numbits = *kfileptr++; - ydim = SSWAPIL(*(unsigned short *)&kfileptr[0]); - xdim = SSWAPIL(*(unsigned short *)&kfileptr[2]); - //printf("%s: %ld / %ld = %ld\n",filename,xdim*ydim*3,kfilength,(xdim*ydim*3)/kfilength); + ydim = SSWAPIL(*(unsigned short *)&kfileptr[0]); + xdim = SSWAPIL(*(unsigned short *)&kfileptr[2]); + //printf("%s: %ld / %ld = %ld\n",filename,xdim*ydim*3,kfilength,(xdim*ydim*3)/kfilength); - frameplace = daframeplace; - bytesperline = dabytesperline; - xres = daxres; - yres = dayres; - globxoffs = daglobxoffs; - globyoffs = daglobyoffs; + frameplace = daframeplace; + bytesperline = dabytesperline; + xres = daxres; + yres = dayres; + globxoffs = daglobxoffs; + globyoffs = daglobyoffs; - gnumcomponents = kfileptr[4]; - kfileptr += 5; - ghsampmax = gvsampmax = glhsampmax = glvsampmax = 0; - for(z=0;z>4); - gcompvsamp[z] = (kfileptr[1]&15); - gcompquantab[z] = kfileptr[2]; - for(i=0;i<8;i++) if (gcomphsamp[z] == pow2long[i]) { gcomphsampshift[z] = i; break; } - for(i=0;i<8;i++) if (gcompvsamp[z] == pow2long[i]) { gcompvsampshift[z] = i; break; } - if (gcomphsamp[z] > ghsampmax) { ghsampmax = gcomphsamp[z]; glhsampmax = gcomphsampshift[z]; } - if (gcompvsamp[z] > gvsampmax) { gvsampmax = gcompvsamp[z]; glvsampmax = gcompvsampshift[z]; } - kfileptr += 3; - } + gnumcomponents = kfileptr[4]; + kfileptr += 5; + ghsampmax = gvsampmax = glhsampmax = glvsampmax = 0; + for(z=0;z>4); + gcompvsamp[z] = (kfileptr[1]&15); + gcompquantab[z] = kfileptr[2]; + for(i=0;i<8;i++) if (gcomphsamp[z] == pow2long[i]) { gcomphsampshift[z] = i; break; } + for(i=0;i<8;i++) if (gcompvsamp[z] == pow2long[i]) { gcompvsampshift[z] = i; break; } + if (gcomphsamp[z] > ghsampmax) { ghsampmax = gcomphsamp[z]; glhsampmax = gcomphsampshift[z]; } + if (gcompvsamp[z] > gvsampmax) { gvsampmax = gcompvsamp[z]; glvsampmax = gcompvsampshift[z]; } + kfileptr += 3; + } - break; - case 0xc4: //Huffman table - do - { - ch = *kfileptr++; leng--; - if (ch >= 16) { index = ch-12; } - else { index = ch; } - memcpy((void *)&hufnumatbit[index][1],(void *)kfileptr,16); kfileptr += 16; - leng -= 16; + break; + case 0xc4: //Huffman table + do + { + ch = *kfileptr++; leng--; + if (ch >= 16) { index = ch-12; } + else { index = ch; } + memcpy((void *)&hufnumatbit[index][1],(void *)kfileptr,16); kfileptr += 16; + leng -= 16; - v = 0; hufcnt[index] = 0; - hufquickcnt[index] = 0; - for(i=1;i<=16;i++) - { - hufmaxatbit[index][i] = v+hufnumatbit[index][i]; - hufvalatbit[index][i] = hufcnt[index]-v; - memcpy((void *)&huftable[index][hufcnt[index]],(void *)kfileptr,(long)hufnumatbit[index][i]); - if (i <= 10) - for(c=0;c0;j--) - { - hufquickval[index][hufquickcnt[index]] = huftable[index][hufcnt[index]+c]; - hufquickbits[index][hufquickcnt[index]] = i; - hufquickcnt[index]++; - } - kfileptr += hufnumatbit[index][i]; - leng -= hufnumatbit[index][i]; - hufcnt[index] += hufnumatbit[index][i]; - v = ((v+hufnumatbit[index][i])<<1); - } + v = 0; hufcnt[index] = 0; + hufquickcnt[index] = 0; + for(i=1;i<=16;i++) + { + hufmaxatbit[index][i] = v+hufnumatbit[index][i]; + hufvalatbit[index][i] = hufcnt[index]-v; + memcpy((void *)&huftable[index][hufcnt[index]],(void *)kfileptr,(long)hufnumatbit[index][i]); + if (i <= 10) + for(c=0;c0;j--) + { + hufquickval[index][hufquickcnt[index]] = huftable[index][hufcnt[index]+c]; + hufquickbits[index][hufquickcnt[index]] = i; + hufquickcnt[index]++; + } + kfileptr += hufnumatbit[index][i]; + leng -= hufnumatbit[index][i]; + hufcnt[index] += hufnumatbit[index][i]; + v = ((v+hufnumatbit[index][i])<<1); + } - } while (leng > 0); - break; - case 0xdb: - do - { - ch = *kfileptr++; leng--; - index = (ch&15); - prec = (ch>>4); - for(z=0;z<64;z++) - { - v = (long)(*kfileptr++); - if (prec) v = (v<<8)+((long)(*kfileptr++)); - 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; - if (prec) leng -= 64; - } while (leng > 0); - break; - case 0xdd: - restartinterval = SSWAPIL(*(unsigned short *)&kfileptr[0]); - kfileptr += leng; - break; - case 0xda: - if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) free(dctbuf); return(-1); } + } while (leng > 0); + break; + case 0xdb: + do + { + ch = *kfileptr++; leng--; + index = (ch&15); + prec = (ch>>4); + for(z=0;z<64;z++) + { + v = (long)(*kfileptr++); + if (prec) v = (v<<8)+((long)(*kfileptr++)); + 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; + if (prec) leng -= 64; + } while (leng > 0); + break; + case 0xdd: + restartinterval = SSWAPIL(*(unsigned short *)&kfileptr[0]); + kfileptr += leng; + break; + case 0xda: + if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) free(dctbuf); return(-1); } - lnumcomponents = (long)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) free(dctbuf); return(-1); } - if (lnumcomponents > 1) coltype = 2; - for(z=0;z>4); - lcompac[z] = (kfileptr[1]&15); - kfileptr += 2; - } + lnumcomponents = (long)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) free(dctbuf); return(-1); } + if (lnumcomponents > 1) coltype = 2; + for(z=0;z>4); + lcompac[z] = (kfileptr[1]&15); + kfileptr += 2; + } - Ss = kfileptr[0]; - Se = kfileptr[1]; - Ah = (kfileptr[2]>>4); - Al = (kfileptr[2]&15); - kfileptr += 3; - //printf("passcnt=%d, Ss=%d, Se=%d, Ah=%d, Al=%d\n",passcnt,Ss,Se,Ah,Al); + Ss = kfileptr[0]; + Se = kfileptr[1]; + Ah = (kfileptr[2]>>4); + Al = (kfileptr[2]&15); + kfileptr += 3; + //printf("passcnt=%d, Ss=%d, Se=%d, Ah=%d, Al=%d\n",passcnt,Ss,Se,Ah,Al); - if ((!passcnt) && ((Ss) || (Se != 63) || (Ah) || (Al))) - { - for(z=zz=0;z>(glhsampmax+3)) << gcomphsampshift[z]; - dcty[z] = ((ydim+(gvsampmax<<3)-1)>>(glvsampmax+3)) << gcompvsampshift[z]; - zz += dctx[z]*dcty[z]; - } - z = zz*64*sizeof(short); - dctbuf = (short *)malloc(z); if (!dctbuf) return(-1); - memset(dctbuf,0,z); - for(z=zz=0;z>(glhsampmax+3)) << gcomphsampshift[z]; + dcty[z] = ((ydim+(gvsampmax<<3)-1)>>(glvsampmax+3)) << gcompvsampshift[z]; + zz += dctx[z]*dcty[z]; + } + z = zz*64*sizeof(short); + dctbuf = (short *)malloc(z); if (!dctbuf) return(-1); + memset(dctbuf,0,z); + for(z=zz=0;z>glhstep); lcomphsamp[0] = min(lcomphsamp[0],glhstep); glhstep <<= 3; - glvstep = (gvsampmax>>glvstep); lcompvsamp[0] = min(lcompvsamp[0],glvstep); glvstep <<= 3; - lcomphvsamp0 = lcomphsamp[0]*lcompvsamp[0]; + glhstep = glvstep = 0x7fffffff; + for(z=0;z>glhstep); lcomphsamp[0] = min(lcomphsamp[0],glhstep); glhstep <<= 3; + glvstep = (gvsampmax>>glvstep); lcompvsamp[0] = min(lcompvsamp[0],glvstep); glvstep <<= 3; + lcomphvsamp0 = lcomphsamp[0]*lcompvsamp[0]; - clipxdim = min(xdim+globxoffs,xres); - clipydim = min(ydim+globyoffs,yres); + clipxdim = min(xdim+globxoffs,xres); + clipydim = min(ydim+globyoffs,yres); - if ((max(globxoffs,0) >= xres) || (min(globxoffs+xdim,xres) <= 0) || - (max(globyoffs,0) >= yres) || (min(globyoffs+ydim,yres) <= 0)) - { if (dctbuf) free(dctbuf); return(0); } + if ((max(globxoffs,0) >= xres) || (min(globxoffs+xdim,xres) <= 0) || + (max(globyoffs,0) >= yres) || (min(globyoffs+ydim,yres) <= 0)) + { if (dctbuf) free(dctbuf); return(0); } - Alut[0] = (1<= kfilength) goto kpegrend_break2; //rest of file is missing! + restartcnt = restartinterval; eobrun = 0; marker = 0xd0; + num = 0; curbits = 0; + for(y=0;y= 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]; + if (dctbuf) dcs = &ldctptr[c][(((y+yy)>>lshy[c])*ldctx[c] + ((x+xx)>>lshx[c]))<<6]; - //Get DC - if (!Ss) - { - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } + //Get DC + if (!Ss) + { + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } - if (!Ah) - { - i = ((num>>(curbits-10))&1023); - if (i < hufquickcnt[lcompdc[c]]) - { daval = hufquickval[lcompdc[c]][i]; curbits -= hufquickbits[lcompdc[c]][i]; } - else { huffgetval(lcompdc[c],curbits,num,&daval,&dabits); curbits -= dabits; } + if (!Ah) + { + i = ((num>>(curbits-10))&1023); + if (i < hufquickcnt[lcompdc[c]]) + { daval = hufquickval[lcompdc[c]][i]; curbits -= hufquickbits[lcompdc[c]][i]; } + else { huffgetval(lcompdc[c],curbits,num,&daval,&dabits); curbits -= dabits; } - if (daval) - { - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } + if (daval) + { + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } - curbits -= daval; v = ((unsigned)num >> curbits) & pow2mask[daval]; - if (v <= pow2mask[daval-1]) v -= pow2mask[daval]; - lastdc[c] += v; - } - if (!dctbuf) dc[0] = lastdc[c]; else dcs[0] = (short)(lastdc[c]<> curbits) & pow2mask[daval]; + if (v <= pow2mask[daval-1]) v -= pow2mask[daval]; + lastdc[c] += v; + } + if (!dctbuf) dc[0] = lastdc[c]; else dcs[0] = (short)(lastdc[c]<>(curbits-10))&1023); - if (i < hqcnt) - { daval = hqval[i]; curbits -= hqbits[i]; } - else { huffgetval(lcompac[c]+4,curbits,num,&daval,&dabits); curbits -= dabits; } + //Get AC + if (!dctbuf) memset((void *)&dc[1],0,63*4); + z = max(Ss,1); dcflag = 1; + if (eobrun <= 0) + { + for(;z<=Se;z++) + { + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } + i = ((num>>(curbits-10))&1023); + if (i < hqcnt) + { daval = hqval[i]; curbits -= hqbits[i]; } + else { huffgetval(lcompac[c]+4,curbits,num,&daval,&dabits); curbits -= dabits; } - zz = (daval>>4); daval &= 15; - if (daval) - { - if (Ah) - { - //NOTE: Getbits not needed here - buffer should have enough bits - if (num&(pow2long[--curbits])) daval = Alut[0]; else daval = Alut[1]; - } - } - else if (zz < 15) - { - eobrun = pow2long[zz]; - if (zz) - { - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } - curbits -= zz; eobrun += ((unsigned)num >> curbits) & pow2mask[zz]; - } - if (!Ah) eobrun--; - break; - } - if (Ah) - { - do - { - if (dcs[z]) - { - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } - if (num&(pow2long[--curbits])) dcs[z] += ((short)Alut[dcs[z] < 0]); - } else if (--zz < 0) break; - z++; - } while (z <= Se); - if (daval) dcs[z] = daval; - } - else - { - z += zz; if (z > Se) break; + zz = (daval>>4); daval &= 15; + if (daval) + { + if (Ah) + { + //NOTE: Getbits not needed here - buffer should have enough bits + if (num&(pow2long[--curbits])) daval = Alut[0]; else daval = Alut[1]; + } + } + else if (zz < 15) + { + eobrun = pow2long[zz]; + if (zz) + { + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } + curbits -= zz; eobrun += ((unsigned)num >> curbits) & pow2mask[zz]; + } + if (!Ah) eobrun--; + break; + } + if (Ah) + { + do + { + if (dcs[z]) + { + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } + if (num&(pow2long[--curbits])) dcs[z] += ((short)Alut[dcs[z] < 0]); + } else if (--zz < 0) break; + z++; + } while (z <= Se); + if (daval) dcs[z] = daval; + } + else + { + z += zz; if (z > Se) break; - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } - curbits -= daval; v = ((unsigned)num >> curbits) & pow2mask[daval]; - if (v <= pow2mask[daval-1]) v -= pow2mask[daval]; - dcflag |= dcflagor[z]; - if (!dctbuf) dc[unzig[z]] = v; else dcs[z] = (short)(v< 0)) - { - eobrun--; - for(;z<=Se;z++) - { - if (!dcs[z]) continue; - while (curbits < 24) //Getbits - { - ch = *kfileptr++; if (ch == 255) kfileptr++; - num = (num<<8)+((long)ch); curbits += 8; - } - if (num&(pow2long[--curbits])) dcs[z] += ((short)Alut[dcs[z] < 0]); - } - } + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } + curbits -= daval; v = ((unsigned)num >> curbits) & pow2mask[daval]; + if (v <= pow2mask[daval-1]) v -= pow2mask[daval]; + dcflag |= dcflagor[z]; + if (!dctbuf) dc[unzig[z]] = v; else dcs[z] = (short)(v< 0)) + { + eobrun--; + for(;z<=Se;z++) + { + if (!dcs[z]) continue; + while (curbits < 24) //Getbits + { + ch = *kfileptr++; if (ch == 255) kfileptr++; + num = (num<<8)+((long)ch); curbits += 8; + } + if (num&(pow2long[--curbits])) dcs[z] += ((short)Alut[dcs[z] < 0]); + } + } - if (!dctbuf) - { - for(z=64-1;z>=0;z--) dc[z] *= quanptr[z]; - invdct8x8(dc,dcflag); dc += 64; - } - } - } + if (!dctbuf) + { + for(z=64-1;z>=0;z--) dc[z] *= quanptr[z]; + invdct8x8(dc,dcflag); dc += 64; + } + } + } - if (!dctbuf) yrbrend(x,y); + if (!dctbuf) yrbrend(x,y); - restartcnt--; - if (!restartcnt) - { - kfileptr += 1-(curbits>>3); curbits = 0; - if ((kfileptr[-2] != 255) || (kfileptr[-1] != marker)) kfileptr--; - marker++; if (marker >= 0xd8) marker = 0xd0; - restartcnt = restartinterval; - for(i=0;i<4;i++) lastdc[i] = 0; - eobrun = 0; - } - } + restartcnt--; + if (!restartcnt) + { + kfileptr += 1-(curbits>>3); curbits = 0; + if ((kfileptr[-2] != 255) || (kfileptr[-1] != marker)) kfileptr--; + marker++; if (marker >= 0xd8) marker = 0xd0; + restartcnt = restartinterval; + for(i=0;i<4;i++) lastdc[i] = 0; + eobrun = 0; + } + } kpegrend_break2:; - if (!dctbuf) return(0); - passcnt++; kfileptr -= ((curbits>>3)+1); break; - case 0xd9: break; - default: kfileptr += leng; break; - } - } while (kfileptr-(unsigned char *)kfilebuf < kfilength); + if (!dctbuf) return(0); + passcnt++; kfileptr -= ((curbits>>3)+1); break; + case 0xd9: break; + default: kfileptr += leng; break; + } + } while (kfileptr-(unsigned char *)kfilebuf < kfilength); - if (!dctbuf) return(0); + if (!dctbuf) return(0); - lnumcomponents = gnumcomponents; - for(i=0;i>lshy[c])*dctx[c] + ((x+xx)>>lshx[c]))<<6]; - quanptr = &quantab[gcompquantab[c]][0]; - for(z=0;z<64;z++) dc[z] = ((long)dcs[zigit[z]])*quanptr[z]; - invdct8x8(dc,-1); - } - yrbrend(x,y); - } + lnumcomponents = gnumcomponents; + for(i=0;i>lshy[c])*dctx[c] + ((x+xx)>>lshx[c]))<<6]; + quanptr = &quantab[gcompquantab[c]][0]; + for(z=0;z<64;z++) dc[z] = ((long)dcs[zigit[z]])*quanptr[z]; + invdct8x8(dc,-1); + } + yrbrend(x,y); + } - free(dctbuf); return(0); + free(dctbuf); return(0); } //============================== KPEGILIB ends ============================== @@ -1880,467 +1880,467 @@ static unsigned char suffix[4100], filbuffer[768], tempstack[4096]; static long prefix[4100]; static long kgifrend (const char *kfilebuf, long kfilelength, - long daframeplace, long dabytesperline, long daxres, long dayres, - long daglobxoffs, long daglobyoffs) + long daframeplace, long dabytesperline, long daxres, long dayres, + long daglobxoffs, long daglobyoffs) { - long i, x, y, xsiz, ysiz, yinc, xend, xspan, yspan, currstr, numbitgoal; - long lzcols, dat, blocklen, bitcnt, xoff, yoff, transcol, backcol, *lptr; - char numbits, startnumbits, chunkind, ilacefirst; - const unsigned char *ptr, *cptr; + long i, x, y, xsiz, ysiz, yinc, xend, xspan, yspan, currstr, numbitgoal; + long lzcols, dat, blocklen, bitcnt, xoff, yoff, transcol, backcol, *lptr; + char numbits, startnumbits, chunkind, ilacefirst; + const unsigned char *ptr, *cptr; - coltype = 3; bitdepth = 8; //For PNGOUT + coltype = 3; bitdepth = 8; //For PNGOUT - if ((kfilebuf[0] != 'G') || (kfilebuf[1] != 'I') || - (kfilebuf[2] != 'F') || (kfilebuf[12])) return(-1); - paleng = (1<<((kfilebuf[10]&7)+1)); - ptr = (unsigned char *)&kfilebuf[13]; - if (kfilebuf[10]&128) { cptr = ptr; ptr += paleng*3; } - transcol = -1; - while ((chunkind = *ptr++) == '!') - { //! 0xf9 leng flags ?? ?? transcol - if (ptr[0] == 0xf9) { if (ptr[2]&1) transcol = (long)(((unsigned char)ptr[5])); } - ptr++; - do { i = *ptr++; ptr += i; } while (i); - } - if (chunkind != ',') return(-1); + if ((kfilebuf[0] != 'G') || (kfilebuf[1] != 'I') || + (kfilebuf[2] != 'F') || (kfilebuf[12])) return(-1); + paleng = (1<<((kfilebuf[10]&7)+1)); + ptr = (unsigned char *)&kfilebuf[13]; +if (kfilebuf[10]&128) { cptr = ptr; ptr += paleng*3; } + transcol = -1; + while ((chunkind = *ptr++) == '!') + { //! 0xf9 leng flags ?? ?? transcol + if (ptr[0] == 0xf9) { if (ptr[2]&1) transcol = (long)(((unsigned char)ptr[5])); } + ptr++; + do { i = *ptr++; ptr += i; } while (i); + } + if (chunkind != ',') return(-1); - xoff = SSWAPIB(*(unsigned short *)&ptr[0]); - yoff = SSWAPIB(*(unsigned short *)&ptr[2]); - xspan = SSWAPIB(*(unsigned short *)&ptr[4]); - yspan = SSWAPIB(*(unsigned short *)&ptr[6]); ptr += 9; - if (ptr[-1]&64) { yinc = 8; ilacefirst = 1; } - else { yinc = 1; ilacefirst = 0; } - if (ptr[-1]&128) - { - paleng = (1<<((ptr[-1]&7)+1)); - cptr = ptr; ptr += paleng*3; - } + xoff = SSWAPIB(*(unsigned short *)&ptr[0]); + yoff = SSWAPIB(*(unsigned short *)&ptr[2]); + xspan = SSWAPIB(*(unsigned short *)&ptr[4]); + yspan = SSWAPIB(*(unsigned short *)&ptr[6]); ptr += 9; +if (ptr[-1]&64) { yinc = 8; ilacefirst = 1; } + else { yinc = 1; ilacefirst = 0; } + if (ptr[-1]&128) + { + paleng = (1<<((ptr[-1]&7)+1)); + cptr = ptr; ptr += paleng*3; + } - for(i=0;i= 0) palcol[transcol] &= LSWAPIB(~0xff000000); + for(i=0;i= 0) palcol[transcol] &= LSWAPIB(~0xff000000); - //Handle GIF files with different logical&image sizes or non-0 offsets (added 05/15/2004) - xsiz = SSWAPIB(*(unsigned short *)&kfilebuf[6]); - ysiz = SSWAPIB(*(unsigned short *)&kfilebuf[8]); - if ((xoff != 0) || (yoff != 0) || (xsiz != xspan) || (ysiz != yspan)) - { - long xx[4], yy[4]; - if (kfilebuf[10]&128) backcol = palcol[(unsigned char)kfilebuf[11]]; else backcol = 0; + //Handle GIF files with different logical&image sizes or non-0 offsets (added 05/15/2004) + xsiz = SSWAPIB(*(unsigned short *)&kfilebuf[6]); + ysiz = SSWAPIB(*(unsigned short *)&kfilebuf[8]); + if ((xoff != 0) || (yoff != 0) || (xsiz != xspan) || (ysiz != yspan)) + { + long xx[4], yy[4]; + if (kfilebuf[10]&128) backcol = palcol[(unsigned char)kfilebuf[11]]; else backcol = 0; - //Fill border to backcol - xx[0] = max(daglobxoffs , 0); yy[0] = max(daglobyoffs , 0); - xx[1] = min(daglobxoffs+xoff ,daxres); yy[1] = min(daglobyoffs+yoff ,dayres); - xx[2] = max(daglobxoffs+xoff+xspan, 0); yy[2] = min(daglobyoffs+yoff+yspan,dayres); - xx[3] = min(daglobxoffs+xsiz ,daxres); yy[3] = min(daglobyoffs+ysiz ,dayres); + //Fill border to backcol + xx[0] = max(daglobxoffs , 0); yy[0] = max(daglobyoffs , 0); + xx[1] = min(daglobxoffs+xoff ,daxres); yy[1] = min(daglobyoffs+yoff ,dayres); + xx[2] = max(daglobxoffs+xoff+xspan, 0); yy[2] = min(daglobyoffs+yoff+yspan,dayres); + xx[3] = min(daglobxoffs+xsiz ,daxres); yy[3] = min(daglobyoffs+ysiz ,dayres); - lptr = (long *)(yy[0]*dabytesperline+daframeplace); - for(y=yy[0];y=0;i--) { suffix[i] = (char)(prefix[i] = i); } - currstr = lzcols+2; numbits = startnumbits; numbitgoal = (lzcols<<1); - blocklen = *ptr++; - memcpy(filbuffer,ptr,blocklen); ptr += blocklen; - bitcnt = 0; - while (1) - { - dat = (LSWAPIB(*(long *)&filbuffer[bitcnt>>3])>>(bitcnt&7)) & (numbitgoal-1); - bitcnt += numbits; - if ((bitcnt>>3) > blocklen-3) - { - *(short *)filbuffer = *(short *)&filbuffer[bitcnt>>3]; - i = blocklen-(bitcnt>>3); - blocklen = (long)*ptr++; - memcpy(&filbuffer[i],ptr,blocklen); ptr += blocklen; - bitcnt &= 7; blocklen += i; - } - if (dat == lzcols) - { - currstr = lzcols+2; numbits = startnumbits; numbitgoal = (lzcols<<1); - continue; - } - if ((currstr == numbitgoal) && (numbits < 12)) - { numbits++; numbitgoal <<= 1; } + lzcols = (1<<(*ptr)); startnumbits = (char)((*ptr)+1); ptr++; + for(i=lzcols-1;i>=0;i--) { suffix[i] = (char)(prefix[i] = i); } + currstr = lzcols+2; numbits = startnumbits; numbitgoal = (lzcols<<1); + blocklen = *ptr++; + memcpy(filbuffer,ptr,blocklen); ptr += blocklen; + bitcnt = 0; + while (1) + { + dat = (LSWAPIB(*(long *)&filbuffer[bitcnt>>3])>>(bitcnt&7)) & (numbitgoal-1); + bitcnt += numbits; + if ((bitcnt>>3) > blocklen-3) + { + *(short *)filbuffer = *(short *)&filbuffer[bitcnt>>3]; + i = blocklen-(bitcnt>>3); + blocklen = (long)*ptr++; + memcpy(&filbuffer[i],ptr,blocklen); ptr += blocklen; + bitcnt &= 7; blocklen += i; + } + if (dat == lzcols) + { + currstr = lzcols+2; numbits = startnumbits; numbitgoal = (lzcols<<1); + continue; + } + if ((currstr == numbitgoal) && (numbits < 12)) + { numbits++; numbitgoal <<= 1; } - prefix[currstr] = dat; - for(i=0;dat>=lzcols;dat=prefix[dat]) tempstack[i++] = suffix[dat]; - tempstack[i] = (char)prefix[dat]; - suffix[currstr-1] = suffix[currstr] = (char)dat; + prefix[currstr] = dat; + for(i=0;dat>=lzcols;dat=prefix[dat]) tempstack[i++] = suffix[dat]; + tempstack[i] = (char)prefix[dat]; + suffix[currstr-1] = suffix[currstr] = (char)dat; - for(;i>=0;i--) - { - if ((unsigned long)x < (unsigned long)daxres) - *(long *)(yoff+(x<<2)) = palcol[(long)tempstack[i]]; - x++; - if (x == xend) - { - y += yinc; - if (y >= yspan) - switch(yinc) - { - 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); - } - if ((unsigned long)y < (unsigned long)dayres) - { yoff = y*dabytesperline+daframeplace; x = daglobxoffs; xend = xspan; } - else - { x = daglobxoffs+0x80000000; xend = xspan+0x80000000; } - } - } - currstr++; - } + for(;i>=0;i--) + { + if ((unsigned long)x < (unsigned long)daxres) + *(long *)(yoff+(x<<2)) = palcol[(long)tempstack[i]]; + x++; + if (x == xend) + { + y += yinc; + if (y >= yspan) + switch(yinc) + { + 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); + } + if ((unsigned long)y < (unsigned long)dayres) + { yoff = y*dabytesperline+daframeplace; x = daglobxoffs; xend = xspan; } + else + { x = daglobxoffs+0x80000000; xend = xspan+0x80000000; } + } + } + currstr++; + } } //=============================== GIF ends ================================== //============================== CEL begins ================================= - // //old .CEL format: - //short id = 0x9119, xdim, ydim, xoff, yoff, id = 0x0008; - //long imagebytes, filler[4]; - //char pal6bit[256][3], image[ydim][xdim]; +// //old .CEL format: +//short id = 0x9119, xdim, ydim, xoff, yoff, id = 0x0008; +//long imagebytes, filler[4]; +//char pal6bit[256][3], image[ydim][xdim]; static long kcelrend (const char *buf, long fleng, - long daframeplace, long dabytesperline, long daxres, long dayres, - long daglobxoffs, long daglobyoffs) + long daframeplace, long dabytesperline, long daxres, long dayres, + long daglobxoffs, long daglobyoffs) { - long i, x, y, x0, x1, y0, y1, xsiz, ysiz; - const char *cptr; + long i, x, y, x0, x1, y0, y1, xsiz, ysiz; + const char *cptr; - if ((buf[0] != 0x19) || (buf[1] != 0x91) || - (buf[10] != 8) || (buf[11] != 0)) return(-1); + if ((buf[0] != 0x19) || (buf[1] != 0x91) || + (buf[10] != 8) || (buf[11] != 0)) return(-1); - coltype = 3; bitdepth = 8; paleng = 256; //For PNGOUT + coltype = 3; bitdepth = 8; paleng = 256; //For PNGOUT - xsiz = (long)SSWAPIB(*(unsigned short *)&buf[2]); if (xsiz <= 0) return(-1); - ysiz = (long)SSWAPIB(*(unsigned short *)&buf[4]); if (ysiz <= 0) return(-1); + xsiz = (long)SSWAPIB(*(unsigned short *)&buf[2]); if (xsiz <= 0) return(-1); + ysiz = (long)SSWAPIB(*(unsigned short *)&buf[4]); if (ysiz <= 0) return(-1); - cptr = &buf[32]; - for(i=0;i<256;i++) - { - palcol[i] = (((long)cptr[0])<<18) + - (((long)cptr[1])<<10) + - (((long)cptr[2])<< 2) + LSWAPIB(0xff000000); - cptr += 3; - } + cptr = &buf[32]; + for(i=0;i<256;i++) + { + palcol[i] = (((long)cptr[0])<<18) + + (((long)cptr[1])<<10) + + (((long)cptr[2])<< 2) + LSWAPIB(0xff000000); + cptr += 3; + } - x0 = daglobyoffs; x1 = xsiz+daglobyoffs; - y0 = daglobyoffs; y1 = ysiz+daglobyoffs; - for(y=y0;y= 12) || (!((1< 32)) return(-1); - if (header[17]&0xc0) return(-1); + //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 = (unsigned char *)&header[header[0]+18]; - xsiz = (long)SSWAPIB(*(unsigned short *)&header[12]); if (xsiz <= 0) return(-1); - ysiz = (long)SSWAPIB(*(unsigned short *)&header[14]); if (ysiz <= 0) return(-1); - colbyte = ((((long)header[16])+7)>>3); + fptr = (unsigned char *)&header[header[0]+18]; + xsiz = (long)SSWAPIB(*(unsigned short *)&header[12]); if (xsiz <= 0) return(-1); + ysiz = (long)SSWAPIB(*(unsigned short *)&header[14]); if (ysiz <= 0) return(-1); + colbyte = ((((long)header[16])+7)>>3); - if (header[1] == 1) - { - pixbyte = ((((long)header[7])+7)>>3); - cptr = &fptr[-SSWAPIB(*(unsigned short *)&header[3])*pixbyte]; - fptr += SSWAPIB(*(unsigned short *)&header[5])*pixbyte; - } else pixbyte = colbyte; + if (header[1] == 1) + { + pixbyte = ((((long)header[7])+7)>>3); + cptr = &fptr[-SSWAPIB(*(unsigned short *)&header[3])*pixbyte]; + fptr += SSWAPIB(*(unsigned short *)&header[5])*pixbyte; + } else pixbyte = colbyte; - switch(pixbyte) //For PNGOUT - { - 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; - } + switch(pixbyte) //For PNGOUT + { + 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; + } - if (!(header[17]&16)) { x0 = 0; x1 = xsiz; xi = 1; } - else { x0 = xsiz-1; x1 = -1; xi =-1; } - if (header[17]&32) { y0 = 0; y1 = ysiz; yi = 1; pi = dabytesperline; } - else { y0 = ysiz-1; y1 = -1; yi =-1; pi =-dabytesperline; } - x0 += daglobxoffs; y0 += daglobyoffs; - x1 += daglobxoffs; y1 += daglobyoffs; - if (header[2] < 8) rlestat = -2; else rlestat = -1; +if (!(header[17]&16)) { x0 = 0; x1 = xsiz; xi = 1; } + else { x0 = xsiz-1; x1 = -1; xi =-1; } + if (header[17]&32) { y0 = 0; y1 = ysiz; yi = 1; pi = dabytesperline; } + else { y0 = ysiz-1; y1 = -1; yi =-1; pi =-dabytesperline; } + x0 += daglobxoffs; y0 += daglobyoffs; + x1 += daglobxoffs; y1 += daglobyoffs; + if (header[2] < 8) rlestat = -2; else rlestat = -1; - p = y0*dabytesperline+daframeplace; - for(y=y0;y!=y1;y+=yi,p+=pi) - for(x=x0;x!=x1;x+=xi) - { - if (rlestat < 128) - { - if ((rlestat&127) == 127) { rlestat = (long)fptr[0]; fptr++; } - if (header[1] == 1) - { - if (colbyte == 1) i = fptr[0]; - else i = (long)SSWAPIB(*(unsigned short *)&fptr[0]); - nptr = &cptr[i*pixbyte]; - } else nptr = fptr; + p = y0*dabytesperline+daframeplace; + for(y=y0;y!=y1;y+=yi,p+=pi) + for(x=x0;x!=x1;x+=xi) + { + if (rlestat < 128) + { + if ((rlestat&127) == 127) { rlestat = (long)fptr[0]; fptr++; } + if (header[1] == 1) + { + if (colbyte == 1) i = fptr[0]; + else i = (long)SSWAPIB(*(unsigned short *)&fptr[0]); + nptr = &cptr[i*pixbyte]; + } else nptr = fptr; - switch(pixbyte) - { - case 1: i = palcol[(long)nptr[0]]; break; - case 2: i = (long)SSWAPIB(*(unsigned short *)&nptr[0]); - i = LSWAPIB(((i&0x7c00)<<9) + ((i&0x03e0)<<6) + ((i&0x001f)<<3) + 0xff000000); - break; - case 3: i = (*(long *)&nptr[0]) | LSWAPIB(0xff000000); break; - case 4: i = (*(long *)&nptr[0]); break; - } - fptr += colbyte; - } - if (rlestat >= 0) rlestat--; + switch(pixbyte) + { + case 1: i = palcol[(long)nptr[0]]; break; + case 2: i = (long)SSWAPIB(*(unsigned short *)&nptr[0]); + i = LSWAPIB(((i&0x7c00)<<9) + ((i&0x03e0)<<6) + ((i&0x001f)<<3) + 0xff000000); + break; + case 3: i = (*(long *)&nptr[0]) | LSWAPIB(0xff000000); break; + case 4: i = (*(long *)&nptr[0]); break; + } + fptr += colbyte; + } + if (rlestat >= 0) rlestat--; - if (((unsigned long)x < (unsigned long)daxres) && ((unsigned long)y < (unsigned long)dayres)) - *(long *)(x*4+p) = i; - } - return(0); + if (((unsigned long)x < (unsigned long)daxres) && ((unsigned long)y < (unsigned long)dayres)) + *(long *)(x*4+p) = i; + } + return(0); } //============================== TARGA ends ================================= //============================== BMP begins ================================= - //TODO: handle BI_RLE8 and BI_RLE4 (compression types 1&2 respectively) - // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ - // ³ 0(2): "BM" ³ - // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ 10(4): rastoff³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ - // ³headsiz=12 (OS/2 1.x)³³ 14(4): headsiz³ ³ All new formats: ³ - //ÚÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÁÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ - //³ 18(2): xsiz ³ 18(4): xsiz ³ - //³ 20(2): ysiz ³ 22(4): ysiz ³ - //³ 22(2): planes (always 1) ³ 26(2): planes (always 1) ³ - //³ 24(2): cdim (1,4,8,24) ³ 28(2): cdim (1,4,8,16,24,32) ³ - //³ if (cdim < 16) ³ 30(4): compression (0,1,2,3!?,4) ³ - //³ 26(rastoff-14-headsiz): pal(bgr) ³ 34(4): (bitmap data size+3)&3 ³ - //³ ³ 46(4): N colors (0=2^cdim) ³ - //³ ³ if (cdim < 16) ³ - //³ ³ 14+headsiz(rastoff-14-headsiz): pal(bgr0) ³ - //ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ - // ³ rastoff(?): bitmap data ³ - // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ +//TODO: handle BI_RLE8 and BI_RLE4 (compression types 1&2 respectively) +// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +// ³ 0(2): "BM" ³ +// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ 10(4): rastoff³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +// ³headsiz=12 (OS/2 1.x)³³ 14(4): headsiz³ ³ All new formats: ³ +//ÚÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÁÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ +//³ 18(2): xsiz ³ 18(4): xsiz ³ +//³ 20(2): ysiz ³ 22(4): ysiz ³ +//³ 22(2): planes (always 1) ³ 26(2): planes (always 1) ³ +//³ 24(2): cdim (1,4,8,24) ³ 28(2): cdim (1,4,8,16,24,32) ³ +//³ if (cdim < 16) ³ 30(4): compression (0,1,2,3!?,4) ³ +//³ 26(rastoff-14-headsiz): pal(bgr) ³ 34(4): (bitmap data size+3)&3 ³ +//³ ³ 46(4): N colors (0=2^cdim) ³ +//³ ³ if (cdim < 16) ³ +//³ ³ 14+headsiz(rastoff-14-headsiz): pal(bgr0) ³ +//ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ +// ³ rastoff(?): bitmap data ³ +// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ static long kbmprend (const char *buf, long fleng, - long daframeplace, long dabytesperline, long daxres, long dayres, - long daglobxoffs, long daglobyoffs) + long daframeplace, long dabytesperline, long daxres, long dayres, + long daglobxoffs, long daglobyoffs) { - long i, j, x, y, x0, x1, y0, y1, rastoff, headsiz, xsiz, ysiz, cdim, comp, cptrinc, *lptr; - const char *cptr; + long i, j, x, y, x0, x1, y0, y1, rastoff, headsiz, xsiz, ysiz, cdim, comp, cptrinc, *lptr; + const char *cptr; - headsiz = *(long *)&buf[14]; - if (headsiz == LSWAPIB(12)) //OS/2 1.x (old format) - { - if (*(short *)(&buf[22]) != SSWAPIB(1)) return(-1); - xsiz = (long)SSWAPIB(*(unsigned short *)&buf[18]); - ysiz = (long)SSWAPIB(*(unsigned short *)&buf[20]); - cdim = (long)SSWAPIB(*(unsigned short *)&buf[24]); - comp = 0; - } - else //All newer formats... - { - if (*(short *)(&buf[26]) != SSWAPIB(1)) return(-1); - xsiz = LSWAPIB(*(long *)&buf[18]); - ysiz = LSWAPIB(*(long *)&buf[22]); - cdim = (long)SSWAPIB(*(unsigned short *)&buf[28]); - comp = LSWAPIB(*(long *)&buf[30]); - } - if ((xsiz <= 0) || (!ysiz)) return(-1); - //cdim must be: (1,4,8,16,24,32) - if (((unsigned long)(cdim-1) >= (unsigned long)32) || (!((1<= (unsigned long)32) || (!((1<>1); - } - for(palcol[i+3]=0;palcol[i+3]<32;palcol[i+3]++) - { - if (!(j&1)) break; - j = (((unsigned long)j)>>1); - } - } - } - palcol[0] = 24-(palcol[0]+palcol[3]); - palcol[1] = 16-(palcol[1]+palcol[4]); - palcol[2] = 8-(palcol[2]+palcol[5]); - palcol[3] = ((-1<<(24-palcol[3]))&0x00ff0000); - palcol[4] = ((-1<<(16-palcol[4]))&0x0000ff00); - palcol[5] = ((-1<<( 8-palcol[5]))&0x000000ff); - } + if (cdim < 16) + { + if (cdim == 2) { palcol[0] = 0xffffffff; palcol[1] = LSWAPIB(0xff000000); } + if (headsiz == LSWAPIB(12)) j = 3; else j = 4; + for(i=0,cptr=&buf[headsiz+14];cptr<&buf[rastoff];i++,cptr+=j) + palcol[i] = ((*(long *)&cptr[0])|LSWAPIB(0xff000000)); + coltype = 3; bitdepth = 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; + } + if (comp == 3) //BI_BITFIELD (RGB masks) + { + for(i=0;i<3;i++) + { + j = *(long *)&buf[headsiz+(i<<2)+14]; + for(palcol[i]=0;palcol[i]<32;palcol[i]++) + { + if (j&1) break; + j = (((unsigned long)j)>>1); + } + for(palcol[i+3]=0;palcol[i+3]<32;palcol[i+3]++) + { + if (!(j&1)) break; + j = (((unsigned long)j)>>1); + } + } + } + palcol[0] = 24-(palcol[0]+palcol[3]); + palcol[1] = 16-(palcol[1]+palcol[4]); + palcol[2] = 8-(palcol[2]+palcol[5]); + palcol[3] = ((-1<<(24-palcol[3]))&0x00ff0000); + palcol[4] = ((-1<<(16-palcol[4]))&0x0000ff00); + palcol[5] = ((-1<<( 8-palcol[5]))&0x000000ff); + } - cptrinc = (((xsiz*cdim+31)>>3)&~3); cptr = &buf[rastoff]; - if (ysiz < 0) { ysiz = -ysiz; } else { cptr = &cptr[(ysiz-1)*cptrinc]; cptrinc = -cptrinc; } + cptrinc = (((xsiz*cdim+31)>>3)&~3); cptr = &buf[rastoff]; +if (ysiz < 0) { ysiz = -ysiz; } else { cptr = &cptr[(ysiz-1)*cptrinc]; cptrinc = -cptrinc; } - x0 = daglobxoffs; x1 = xsiz+daglobxoffs; - y0 = daglobyoffs; y1 = ysiz+daglobyoffs; - if ((x0 >= daxres) || (x1 <= 0) || (y0 >= dayres) || (y1 <= 0)) return(0); - if (x0 < 0) x0 = 0; - if (x1 > daxres) x1 = daxres; - for(y=y0;y= (unsigned long)dayres) continue; - lptr = (long *)(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= daxres) || (x1 <= 0) || (y0 >= dayres) || (y1 <= 0)) return(0); + if (x0 < 0) x0 = 0; + if (x1 > daxres) x1 = daxres; + for(y=y0;y= (unsigned long)dayres) continue; + lptr = (long *)(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= x1) { x = x0; y++; p += dabytesperline; } - } - } while (y < y1); - } - else if (nplanes == 3) //24-bit PCX - { - do - { - c = *cptr++; if (c < 192) i = 1; else { i = (c&63); c = *cptr++; } - for(;i;i--) - { - if ((unsigned long)y < (unsigned long)dayres) - if ((unsigned long)x < (unsigned long)daxres) *(char *)(x+p) = c; - x += 4; if (x >= x1) { j--; if (j < 0) { j = 3-1; y++; p += dabytesperline; } x = x0+j; } - } - } while (y < y1); - } + j = nplanes-1; daxres <<= 2; x0 <<= 2; x1 <<= 2; x <<= 2; x += j; + if (nplanes == 1) //8-bit PCX + { + do + { + c = *cptr++; if (c < 192) i = 1; else { i = (c&63); c = *cptr++; } + j = palcol[(long)c]; + for(;i;i--) + { + if ((unsigned long)y < (unsigned long)dayres) + if ((unsigned long)x < (unsigned long)daxres) *(long *)(x+p) = j; + x += 4; if (x >= x1) { x = x0; y++; p += dabytesperline; } + } + } while (y < y1); + } + else if (nplanes == 3) //24-bit PCX + { + do + { + c = *cptr++; if (c < 192) i = 1; else { i = (c&63); c = *cptr++; } + for(;i;i--) + { + if ((unsigned long)y < (unsigned long)dayres) + if ((unsigned long)x < (unsigned long)daxres) *(char *)(x+p) = c; + x += 4; if (x >= x1) { j--; if (j < 0) { j = 3-1; y++; p += dabytesperline; } x = x0+j; } + } + } while (y < y1); + } - return(0); + return(0); } //=============================== BMP ends ================================== @@ -2348,345 +2348,345 @@ static long kpcxrend (const char *buf, long fleng, void kpgetdim (const char *buf, long leng, long *xsiz, long *ysiz) { - long *lptr; - const unsigned char *cptr; - unsigned char *ubuf = (unsigned char *)buf; + long *lptr; + const unsigned char *cptr; + unsigned char *ubuf = (unsigned char *)buf; - (*xsiz) = (*ysiz) = 0; if (leng < 16) return; - if ((ubuf[0] == 0x89) && (ubuf[1] == 0x50)) //.PNG - { - lptr = (long *)buf; - if ((lptr[0] != LSWAPIB(0x474e5089)) || (lptr[1] != LSWAPIB(0x0a1a0a0d))) return; - lptr = &lptr[2]; - while (((unsigned long)lptr-(unsigned long)buf) < (unsigned long)(leng-16)) - { - if (lptr[1] == LSWAPIB(0x52444849)) //IHDR - { (*xsiz) = LSWAPIL(lptr[2]); (*ysiz) = LSWAPIL(lptr[3]); break; } - lptr = (long *)((long)lptr + LSWAPIL(lptr[0]) + 12); - } - } - else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)) //.JPG - { - cptr = (unsigned char *)&buf[2]; - while (((unsigned long)cptr-(unsigned long)buf) < (unsigned long)(leng-8)) - { - if (cptr[0] != 255) { cptr = &cptr[1]; continue; } - if ((unsigned long)(cptr[1]-0xc0) < 3) - { - (*ysiz) = SSWAPIL(*(unsigned short *)&cptr[5]); - (*xsiz) = SSWAPIL(*(unsigned short *)&cptr[7]); - break; - } - cptr = &cptr[SSWAPIL(*(unsigned short *)&cptr[2])+2]; - } - } - else if ((ubuf[0] == 'G') && (ubuf[1] == 'I') && (ubuf[2] == 'F') && (ubuf[12] == 0)) //.GIF - { - (*xsiz) = (long)SSWAPIB(*(unsigned short *)&buf[6]); - (*ysiz) = (long)SSWAPIB(*(unsigned short *)&buf[8]); - } - else if ((ubuf[0] == 0x19) && (ubuf[1] == 0x91) && (ubuf[10] == 8) && (ubuf[11] == 0)) //old .CEL/.PIC - { - (*xsiz) = (long)SSWAPIB(*(unsigned short *)&buf[2]); - (*ysiz) = (long)SSWAPIB(*(unsigned short *)&buf[4]); - } - else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP - { - if (*(long *)(&buf[14]) == LSWAPIB(12)) //OS/2 1.x (old format) - { - if (*(short *)(&buf[22]) != SSWAPIB(1)) return; - (*xsiz) = (long)SSWAPIB(*(unsigned short *)&buf[18]); - (*ysiz) = (long)SSWAPIB(*(unsigned short *)&buf[20]); - } - else //All newer formats... - { - if (*(short *)(&buf[26]) != SSWAPIB(1)) return; - (*xsiz) = LSWAPIB(*(long *)&buf[18]); - (*ysiz) = LSWAPIB(*(long *)&buf[22]); - } - } - else if (*(long *)ubuf == LSWAPIB(0x0801050a)) //.PCX - { - (*xsiz) = SSWAPIB(*(short *)&buf[ 8])-SSWAPIB(*(short *)&buf[4])+1; - (*ysiz) = SSWAPIB(*(short *)&buf[10])-SSWAPIB(*(short *)&buf[6])+1; - } - else - { //Unreliable .TGA identification - this MUST be final case! - if ((leng >= 20) && (!(ubuf[1]&0xfe))) - if ((ubuf[2] < 12) && ((1<= 20) && (!(ubuf[1]&0xfe))) + if ((ubuf[2] < 12) && ((1<= 20) && (!(ubuf[1]&0xfe))) - if ((ubuf[2] < 12) && ((1<= 20) && (!(ubuf[1]&0xfe))) + if ((ubuf[2] < 12) && ((1<= 'a') && (c0 <= 'z')) c0 -= 32; - c1 = *j; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32; - if (c0 == '/') c0 = '\\'; - if (c1 == '/') c1 = '\\'; - if (c0 != c1) return(0); - i++; j++; - } while (*j); - return(!*i); + if (!*j) return(1); + do + { + if (*j == '*') + { + for(k=i,j++;*k;k++) if (wildmatch(k,j)) return(1); + continue; + } + if (!*i) return(0); + if (*j == '?') { i++; j++; continue; } + c0 = *i; if ((c0 >= 'a') && (c0 <= 'z')) c0 -= 32; + c1 = *j; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32; + if (c0 == '/') c0 = '\\'; + if (c1 == '/') c1 = '\\'; + if (c0 != c1) return(0); + i++; j++; + } while (*j); + return(!*i); } - //Same as: stricmp(st0,st1) except: '/' == '\' +//Same as: stricmp(st0,st1) except: '/' == '\' static long filnamcmp (const char *st0, const char *st1) { - long i; - char ch0, ch1; + long i; + char ch0, ch1; - for(i=0;st0[i];i++) - { - ch0 = st0[i]; if ((ch0 >= 'a') && (ch0 <= 'z')) ch0 -= 32; - ch1 = st1[i]; if ((ch1 >= 'a') && (ch1 <= 'z')) ch1 -= 32; - if (ch0 == '/') ch0 = '\\'; - if (ch1 == '/') ch1 = '\\'; - if (ch0 != ch1) return(-1); - } - if (!st1[i]) return(0); - return(-1); + for(i=0;st0[i];i++) + { + ch0 = st0[i]; if ((ch0 >= 'a') && (ch0 <= 'z')) ch0 -= 32; + ch1 = st1[i]; if ((ch1 >= 'a') && (ch1 <= 'z')) ch1 -= 32; + if (ch0 == '/') ch0 = '\\'; + if (ch1 == '/') ch1 = '\\'; + if (ch0 != ch1) return(-1); + } + if (!st1[i]) return(0); + return(-1); } //===================== ZIP decompression code begins ======================== - //format: (used by kzaddstack/kzopen to cache file name&start info) - //[char zipnam[?]\0] - //[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] - //[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] - //... - //[char zipnam[?]\0] - //[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] - //[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] - //... +//format: (used by kzaddstack/kzopen to cache file name&start info) +//[char zipnam[?]\0] +//[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] +//[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] +//... +//[char zipnam[?]\0] +//[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] +//[next hashindex/-1][next index/-1][zipnam index][zipseek][char filnam[?]\0] +//... #define KZHASHINITSIZE 8192 static char *kzhashbuf = 0; static long kzhashead[256], kzhashpos, kzlastfnam, kzhashsiz; static long kzcheckhashsiz (long siz) { - long i; + long i; - if (!kzhashbuf) //Initialize hash table on first call - { - memset(kzhashead,-1,sizeof(kzhashead)); - kzhashbuf = (char *)malloc(KZHASHINITSIZE); if (!kzhashbuf) return(0); - kzhashpos = 0; kzlastfnam = -1; kzhashsiz = KZHASHINITSIZE; - } - if (kzhashpos+siz > kzhashsiz) //Make sure string fits in kzhashbuf - { - i = kzhashsiz; do { i <<= 1; } while (kzhashpos+siz > i); - kzhashbuf = (char *)realloc(kzhashbuf,i); if (!kzhashbuf) return(0); - kzhashsiz = i; - } - return(1); + if (!kzhashbuf) //Initialize hash table on first call + { + memset(kzhashead,-1,sizeof(kzhashead)); + kzhashbuf = (char *)malloc(KZHASHINITSIZE); if (!kzhashbuf) return(0); + kzhashpos = 0; kzlastfnam = -1; kzhashsiz = KZHASHINITSIZE; + } + if (kzhashpos+siz > kzhashsiz) //Make sure string fits in kzhashbuf + { + i = kzhashsiz; do { i <<= 1; } while (kzhashpos+siz > i); + kzhashbuf = (char *)realloc(kzhashbuf,i); if (!kzhashbuf) return(0); + kzhashsiz = i; + } + return(1); } static long kzcalchash (const char *st) { - long i, hashind; - char ch; + long i, hashind; + char ch; - for(i=0,hashind=0;st[i];i++) - { - ch = st[i]; - if ((ch >= 'a') && (ch <= 'z')) ch -= 32; - if (ch == '/') ch = '\\'; - hashind = (ch - hashind*3); - } - return(hashind%(sizeof(kzhashead)/sizeof(kzhashead[0]))); + for(i=0,hashind=0;st[i];i++) + { + ch = st[i]; + if ((ch >= 'a') && (ch <= 'z')) ch -= 32; + if (ch == '/') ch = '\\'; + hashind = (ch - hashind*3); + } + return(hashind%(sizeof(kzhashead)/sizeof(kzhashead[0]))); } static long kzcheckhash (const char *filnam, char **zipnam, long *zipseek) { - long i; + long i; - if (!kzhashbuf) return(0); - if (filnam[0] == '|') filnam++; - for(i=kzhashead[kzcalchash(filnam)];i>=0;i=(*(long *)&kzhashbuf[i])) - if (!filnamcmp(filnam,&kzhashbuf[i+16])) - { - (*zipnam) = &kzhashbuf[*(long *)&kzhashbuf[i+8]]; - (*zipseek) = *(long *)&kzhashbuf[i+12]; - return(1); - } - return(0); + if (!kzhashbuf) return(0); + if (filnam[0] == '|') filnam++; + for(i=kzhashead[kzcalchash(filnam)];i>=0;i=(*(long *)&kzhashbuf[i])) + if (!filnamcmp(filnam,&kzhashbuf[i+16])) + { + (*zipnam) = &kzhashbuf[*(long *)&kzhashbuf[i+8]]; + (*zipseek) = *(long *)&kzhashbuf[i+12]; + return(1); + } + return(0); } void kzuninit () { - if (kzhashbuf) { free(kzhashbuf); kzhashbuf = 0; } - kzhashpos = kzhashsiz = 0; + if (kzhashbuf) { free(kzhashbuf); kzhashbuf = 0; } + kzhashpos = kzhashsiz = 0; } - //Load ZIP directory into memory (hash) to allow fast access later +//Load ZIP directory into memory (hash) to allow fast access later long kzaddstack (const char *zipnam) { - FILE *fil; - long i, j, hashind, zipnamoffs, numfiles; - char tempbuf[260+46]; + FILE *fil; + long i, j, hashind, zipnamoffs, numfiles; + char tempbuf[260+46]; - fil = fopen(zipnam,"rb"); if (!fil) return(-1); + fil = fopen(zipnam,"rb"); if (!fil) return(-1); - //Write ZIP filename to hash - i = strlen(zipnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } - strcpy(&kzhashbuf[kzhashpos],zipnam); - zipnamoffs = kzhashpos; kzhashpos += i; + //Write ZIP filename to hash +i = strlen(zipnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } + strcpy(&kzhashbuf[kzhashpos],zipnam); + zipnamoffs = kzhashpos; kzhashpos += i; - fseek(fil,-22,SEEK_END); - fread(tempbuf,22,1,fil); - if (*(long *)&tempbuf[0] == LSWAPIB(0x06054b50)) //Fast way of finding dir info - { - numfiles = SSWAPIB(*(short *)&tempbuf[10]); - fseek(fil,LSWAPIB(*(long *)&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(*(long *)&tempbuf[14]) + SSWAPIB(*(short *)&tempbuf[24]) + SSWAPIB(*(short *)&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 + //WARNING: No file in ZIP can be > 2GB-32K bytes + gslidew = 0x7fffffff; //Force reload at beginning - return((long)kzfs.fil); - default: fclose(kzfs.fil); kzfs.fil = 0; return(0); - } - } - return(0); + return((long)kzfs.fil); + default: fclose(kzfs.fil); kzfs.fil = 0; return(0); + } + } + return(0); } // -------------------------------------------------------------------------- @@ -2709,121 +2709,121 @@ static struct dirent *findata = NULL; void kzfindfilestart (const char *st) { #ifdef _WIN32 - if (hfind != INVALID_HANDLE_VALUE) - { FindClose(hfind); hfind = INVALID_HANDLE_VALUE; } + if (hfind != INVALID_HANDLE_VALUE) + { FindClose(hfind); hfind = INVALID_HANDLE_VALUE; } #else - if (hfind) { closedir(hfind); hfind = NULL; } + if (hfind) { closedir(hfind); hfind = NULL; } #endif - strcpy(wildst,st); - srchstat = -3; + strcpy(wildst,st); + srchstat = -3; } long kzfindfile (char *filnam) { - long i; + long i; - filnam[0] = 0; - if (srchstat == -3) - { - if (!wildst[0]) { srchstat = -1; return(0); } - do - { - srchstat = -2; + filnam[0] = 0; + if (srchstat == -3) + { + if (!wildst[0]) { srchstat = -1; return(0); } + do + { + srchstat = -2; - //Extract directory from wildcard string for pre-pending - wildstpathleng = 0; - for(i=0;wildst[i];i++) - if ((wildst[i] == '/') || (wildst[i] == '\\')) - wildstpathleng = i+1; + //Extract directory from wildcard string for pre-pending + wildstpathleng = 0; + for(i=0;wildst[i];i++) + if ((wildst[i] == '/') || (wildst[i] == '\\')) + wildstpathleng = i+1; - memcpy(filnam,wildst,wildstpathleng); + memcpy(filnam,wildst,wildstpathleng); #if defined(__DOS__) - if (_dos_findfirst(wildst,_A_SUBDIR,&findata)) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; 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],"\\"); + if (_dos_findfirst(wildst,_A_SUBDIR,&findata)) + { if (!kzhashbuf) return(0); srchstat = kzlastfnam; 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); - if (hfind == INVALID_HANDLE_VALUE) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; } - if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; - i = wildstpathleng; - if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) - if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue; - strcpy(&filnam[i],findata.cFileName); - if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\"); + hfind = FindFirstFile(wildst,&findata); + if (hfind == INVALID_HANDLE_VALUE) + { if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; } + if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; + i = wildstpathleng; + if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) + if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue; + strcpy(&filnam[i],findata.cFileName); + if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\"); #else - if (!hfind) - { - char *s = "."; - if (wildstpathleng > 0) { - filnam[wildstpathleng] = 0; - s = filnam; - } - hfind = opendir(s); - if (!hfind) { if (!kzhashbuf) return 0; srchstat = kzlastfnam; continue; } - } - break; // process srchstat == -2 + if (!hfind) + { + char *s = "."; + if (wildstpathleng > 0) { + filnam[wildstpathleng] = 0; + s = filnam; + } + hfind = opendir(s); + if (!hfind) { if (!kzhashbuf) return 0; srchstat = kzlastfnam; continue; } + } + break; // process srchstat == -2 #endif - return(1); - } while (0); - } - if (srchstat == -2) - while (1) - { - memcpy(filnam,wildst,wildstpathleng); + return(1); + } while (0); + } + if (srchstat == -2) + while (1) + { + memcpy(filnam,wildst,wildstpathleng); #if defined(__DOS__) - if (_dos_findnext(&findata)) - { if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; } - 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],"\\"); + if (_dos_findnext(&findata)) + { if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; } + 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) - if (!FindNextFile(hfind,&findata)) - { FindClose(hfind); if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; } - if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; - i = wildstpathleng; - if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) - if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue; - strcpy(&filnam[i],findata.cFileName); - if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\"); + if (!FindNextFile(hfind,&findata)) + { FindClose(hfind); if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; } + if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; + i = wildstpathleng; + if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) + if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue; + strcpy(&filnam[i],findata.cFileName); + if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\"); #else - { - struct stat st; - if ((findata = readdir(hfind)) == NULL) - { closedir(hfind); hfind = NULL; if (!kzhashbuf) return 0; srchstat = kzlastfnam; break; } - i = wildstpathleng; - strcpy(&filnam[i],findata->d_name); - if (stat(filnam,&st) < 0) continue; - if (st.st_mode & S_IFDIR) - { if (findata->d_name[0] == '.' && !findata->d_name[1]) continue; } //skip . - else if ((st.st_mode & S_IFREG) || (st.st_mode & S_IFLNK)) - { 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 (st.st_mode & S_IFDIR) strcat(&filnam[i],"/"); - } + { + struct stat st; + if ((findata = readdir(hfind)) == NULL) + { closedir(hfind); hfind = NULL; if (!kzhashbuf) return 0; srchstat = kzlastfnam; break; } + i = wildstpathleng; + strcpy(&filnam[i],findata->d_name); + if (stat(filnam,&st) < 0) continue; + if (st.st_mode & S_IFDIR) + { if (findata->d_name[0] == '.' && !findata->d_name[1]) continue; } //skip . + else if ((st.st_mode & S_IFREG) || (st.st_mode & S_IFLNK)) + { 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 (st.st_mode & S_IFDIR) strcat(&filnam[i],"/"); + } #endif - return(1); - } - while (srchstat >= 0) - { - if (wildmatch(&kzhashbuf[srchstat+16],wildst)) - { - //strcpy(filnam,&kzhashbuf[srchstat+16]); - filnam[0] = '|'; strcpy(&filnam[1],&kzhashbuf[srchstat+16]); - srchstat = *(long *)&kzhashbuf[srchstat+4]; - return(1); - } - srchstat = *(long *)&kzhashbuf[srchstat+4]; - } - return(0); + return(1); + } + while (srchstat >= 0) + { + if (wildmatch(&kzhashbuf[srchstat+16],wildst)) + { + //strcpy(filnam,&kzhashbuf[srchstat+16]); + filnam[0] = '|'; strcpy(&filnam[1],&kzhashbuf[srchstat+16]); + srchstat = *(long *)&kzhashbuf[srchstat+4]; + return(1); + } + srchstat = *(long *)&kzhashbuf[srchstat+4]; + } + return(0); } //File searching code (supports inside ZIP files!) How to use this code: @@ -2839,258 +2839,258 @@ long kzfindfile (char *filnam) static char *gzbufptr; static void putbuf4zip (const unsigned char *buf, long uncomp0, long uncomp1) { - long i0, i1; - // uncomp0 ... uncomp1 - // &gzbufptr[kzfs.pos] ... &gzbufptr[kzfs.endpos]; - i0 = max(uncomp0,kzfs.pos); - i1 = min(uncomp1,kzfs.endpos); - if (i0 < i1) memcpy(&gzbufptr[i0],&buf[i0-uncomp0],i1-i0); + long i0, i1; + // uncomp0 ... uncomp1 + // &gzbufptr[kzfs.pos] ... &gzbufptr[kzfs.endpos]; + i0 = max(uncomp0,kzfs.pos); + i1 = min(uncomp1,kzfs.endpos); + if (i0 < i1) memcpy(&gzbufptr[i0],&buf[i0-uncomp0],i1-i0); } - //returns number of bytes copied +//returns number of bytes copied long kzread (void *buffer, long leng) { - long i, j, k, bfinal, btype, hlit, hdist; + long i, j, k, bfinal, btype, hlit, hdist; - if ((!kzfs.fil) || (leng <= 0)) return(0); + if ((!kzfs.fil) || (leng <= 0)) return(0); - if (kzfs.comptyp == 0) - { - if (kzfs.pos != kzfs.i) //Seek only when position changes - fseek(kzfs.fil,kzfs.seek0+kzfs.pos,SEEK_SET); - i = min(kzfs.leng-kzfs.pos,leng); - fread(buffer,i,1,kzfs.fil); - kzfs.i += i; //kzfs.i is a local copy of ftell(kzfs.fil); - } - else if (kzfs.comptyp == 8) - { - zipfilmode = 1; + if (kzfs.comptyp == 0) + { + if (kzfs.pos != kzfs.i) //Seek only when position changes + fseek(kzfs.fil,kzfs.seek0+kzfs.pos,SEEK_SET); + i = min(kzfs.leng-kzfs.pos,leng); + fread(buffer,i,1,kzfs.fil); + kzfs.i += i; //kzfs.i is a local copy of ftell(kzfs.fil); + } + else if (kzfs.comptyp == 8) + { + zipfilmode = 1; - //Initialize for putbuf4zip - gzbufptr = (char *)buffer; gzbufptr = &gzbufptr[-kzfs.pos]; - kzfs.endpos = min(kzfs.pos+leng,kzfs.leng); - if (kzfs.endpos == kzfs.pos) return(0); //Guard against reading 0 length + //Initialize for putbuf4zip + gzbufptr = (char *)buffer; gzbufptr = &gzbufptr[-kzfs.pos]; + kzfs.endpos = min(kzfs.pos+leng,kzfs.leng); + if (kzfs.endpos == kzfs.pos) return(0); //Guard against reading 0 length - if (kzfs.pos < gslidew-32768) // Must go back to start :( - { - if (kzfs.comptell) fseek(kzfs.fil,kzfs.seek0,SEEK_SET); + if (kzfs.pos < gslidew-32768) // Must go back to start :( + { + if (kzfs.comptell) fseek(kzfs.fil,kzfs.seek0,SEEK_SET); - gslidew = 0; gslider = 16384; - kzfs.jmpplc = 0; + gslidew = 0; gslider = 16384; + kzfs.jmpplc = 0; - //Initialize for suckbits/peekbits/getbits - kzfs.comptell = min((unsigned)kzfs.compleng,sizeof(olinbuf)); - fread(&olinbuf[0],kzfs.comptell,1,kzfs.fil); - //Make it re-load when there are < 32 bits left in FIFO - bitpos = -(((long)sizeof(olinbuf)-4)<<3); - //Identity: filptr + (bitpos>>3) = &olinbuf[0] - filptr = &olinbuf[-(bitpos>>3)]; - } - else - { - i = max(gslidew-32768,0); j = gslider-16384; + //Initialize for suckbits/peekbits/getbits + kzfs.comptell = min((unsigned)kzfs.compleng,sizeof(olinbuf)); + fread(&olinbuf[0],kzfs.comptell,1,kzfs.fil); + //Make it re-load when there are < 32 bits left in FIFO + bitpos = -(((long)sizeof(olinbuf)-4)<<3); + //Identity: filptr + (bitpos>>3) = &olinbuf[0] + filptr = &olinbuf[-(bitpos>>3)]; + } + else + { + i = max(gslidew-32768,0); j = gslider-16384; - //HACK: Don't unzip anything until you have to... - // (keeps file pointer as low as possible) - if (kzfs.endpos <= gslidew) j = kzfs.endpos; + //HACK: Don't unzip anything until you have to... + // (keeps file pointer as low as possible) + if (kzfs.endpos <= gslidew) j = kzfs.endpos; - //write uncompoffs on slidebuf from: i to j - if (!((i^j)&32768)) - putbuf4zip(&slidebuf[i&32767],i,j); - else - { - putbuf4zip(&slidebuf[i&32767],i,j&~32767); - putbuf4zip(slidebuf,j&~32767,j); - } + //write uncompoffs on slidebuf from: i to j + if (!((i^j)&32768)) + putbuf4zip(&slidebuf[i&32767],i,j); + else + { + putbuf4zip(&slidebuf[i&32767],i,j&~32767); + putbuf4zip(slidebuf,j&~32767,j); + } - //HACK: Don't unzip anything until you have to... - // (keeps file pointer as low as possible) - if (kzfs.endpos <= gslidew) goto retkzread; - } + //HACK: Don't unzip anything until you have to... + // (keeps file pointer as low as possible) + if (kzfs.endpos <= gslidew) goto retkzread; + } - switch (kzfs.jmpplc) - { - case 0: goto kzreadplc0; - case 1: goto kzreadplc1; - case 2: goto kzreadplc2; - case 3: goto kzreadplc3; - } + switch (kzfs.jmpplc) + { + case 0: goto kzreadplc0; + case 1: goto kzreadplc1; + case 2: goto kzreadplc2; + case 3: goto kzreadplc3; + } kzreadplc0:; - do - { - bfinal = getbits(1); btype = getbits(2); + do + { + bfinal = getbits(1); btype = getbits(2); #if 0 - //Display Huffman block offsets&lengths of input file - for debugging only! - { - static long ouncomppos = 0, ocomppos = 0; - if (kzfs.comptell == sizeof(olinbuf)) i = 0; - else if (kzfs.comptell < kzfs.compleng) i = kzfs.comptell-(sizeof(olinbuf)-4); - else i = kzfs.comptell-(kzfs.comptell%(sizeof(olinbuf)-4)); - i += ((long)&filptr[bitpos>>3])-((long)(&olinbuf[0])); - i = (i<<3)+(bitpos&7)-3; - if (gslidew) printf(" ULng:0x%08x CLng:0x%08x.%x",gslidew-ouncomppos,(i-ocomppos)>>3,((i-ocomppos)&7)<<1); - printf("\ntype:%d, Uoff:0x%08x Coff:0x%08x.%x",btype,gslidew,i>>3,(i&7)<<1); - if (bfinal) - { - printf(" ULng:0x%08x CLng:0x%08x.%x",kzfs.leng-gslidew,((kzfs.compleng<<3)-i)>>3,(((kzfs.compleng<<3)-i)&7)<<1); - printf("\n Uoff:0x%08x Coff:0x%08x.0",kzfs.leng,kzfs.compleng); - ouncomppos = ocomppos = 0; - } - else { ouncomppos = gslidew; ocomppos = i; } - } + //Display Huffman block offsets&lengths of input file - for debugging only! + { + static long ouncomppos = 0, ocomppos = 0; + if (kzfs.comptell == sizeof(olinbuf)) i = 0; + else if (kzfs.comptell < kzfs.compleng) i = kzfs.comptell-(sizeof(olinbuf)-4); + else i = kzfs.comptell-(kzfs.comptell%(sizeof(olinbuf)-4)); + i += ((long)&filptr[bitpos>>3])-((long)(&olinbuf[0])); + i = (i<<3)+(bitpos&7)-3; + if (gslidew) printf(" ULng:0x%08x CLng:0x%08x.%x",gslidew-ouncomppos,(i-ocomppos)>>3,((i-ocomppos)&7)<<1); + printf("\ntype:%d, Uoff:0x%08x Coff:0x%08x.%x",btype,gslidew,i>>3,(i&7)<<1); + if (bfinal) + { + printf(" ULng:0x%08x CLng:0x%08x.%x",kzfs.leng-gslidew,((kzfs.compleng<<3)-i)>>3,(((kzfs.compleng<<3)-i)&7)<<1); + printf("\n Uoff:0x%08x Coff:0x%08x.0",kzfs.leng,kzfs.compleng); + ouncomppos = ocomppos = 0; + } + else { ouncomppos = gslidew; ocomppos = i; } + } #endif - if (btype == 0) - { - //Raw (uncompressed) - suckbits((-bitpos)&7); //Synchronize to start of next byte - i = getbits(16); if ((getbits(16)^i) != 0xffff) return(-1); - for(;i;i--) - { - if (gslidew >= gslider) - { - putbuf4zip(&slidebuf[(gslider-16384)&32767],gslider-16384,gslider); gslider += 16384; - if (gslider-16384 >= kzfs.endpos) - { - kzfs.jmpplc = 1; kzfs.i = i; kzfs.bfinal = bfinal; - goto retkzread; + if (btype == 0) + { + //Raw (uncompressed) + suckbits((-bitpos)&7); //Synchronize to start of next byte + i = getbits(16); if ((getbits(16)^i) != 0xffff) return(-1); + for(;i;i--) + { + if (gslidew >= gslider) + { + putbuf4zip(&slidebuf[(gslider-16384)&32767],gslider-16384,gslider); gslider += 16384; + if (gslider-16384 >= kzfs.endpos) + { + kzfs.jmpplc = 1; kzfs.i = i; kzfs.bfinal = bfinal; + goto retkzread; kzreadplc1:; i = kzfs.i; bfinal = kzfs.bfinal; - } - } - slidebuf[(gslidew++)&32767] = (char)getbits(8); - } - continue; - } - if (btype == 3) continue; + } + } + slidebuf[(gslidew++)&32767] = (char)getbits(8); + } + continue; + } + if (btype == 3) continue; - if (btype == 1) //Fixed Huffman - { - hlit = 288; hdist = 32; i = 0; - for(;i<144;i++) clen[i] = 8; //Fixed bit sizes (literals) - for(;i<256;i++) clen[i] = 9; //Fixed bit sizes (literals) - for(;i<280;i++) clen[i] = 7; //Fixed bit sizes (EOI,lengths) - for(;i<288;i++) clen[i] = 8; //Fixed bit sizes (lengths) - for(;i<320;i++) clen[i] = 5; //Fixed bit sizes (distances) - } - else //Dynamic Huffman - { - hlit = getbits(5)+257; hdist = getbits(5)+1; j = getbits(4)+4; - for(i=0;i= gslider) - { - putbuf4zip(&slidebuf[(gslider-16384)&32767],gslider-16384,gslider); gslider += 16384; - if (gslider-16384 >= kzfs.endpos) - { - kzfs.jmpplc = 2; kzfs.bfinal = bfinal; goto retkzread; + while (1) + { + if (gslidew >= gslider) + { + putbuf4zip(&slidebuf[(gslider-16384)&32767],gslider-16384,gslider); gslider += 16384; + if (gslider-16384 >= kzfs.endpos) + { + kzfs.jmpplc = 2; kzfs.bfinal = bfinal; goto retkzread; kzreadplc2:; bfinal = kzfs.bfinal; - } - } + } + } - k = peekbits(LOGQHUFSIZ0); - if (qhufbit0[k]) { i = qhufval0[k]; suckbits((long)qhufbit0[k]); } - else i = hufgetsym(ibuf0,nbuf0); + k = peekbits(LOGQHUFSIZ0); + if (qhufbit0[k]) { i = qhufval0[k]; suckbits((long)qhufbit0[k]); } + else i = hufgetsym(ibuf0,nbuf0); - if (i < 256) { slidebuf[(gslidew++)&32767] = (char)i; continue; } - if (i == 256) break; - i = getbits(hxbit[i+30-257][0]) + hxbit[i+30-257][1]; + if (i < 256) { slidebuf[(gslidew++)&32767] = (char)i; continue; } + if (i == 256) break; + i = getbits(hxbit[i+30-257][0]) + hxbit[i+30-257][1]; - k = peekbits(LOGQHUFSIZ1); - if (qhufbit1[k]) { j = qhufval1[k]; suckbits((long)qhufbit1[k]); } - else j = hufgetsym(ibuf1,nbuf1); + k = peekbits(LOGQHUFSIZ1); + if (qhufbit1[k]) { j = qhufval1[k]; suckbits((long)qhufbit1[k]); } + else j = hufgetsym(ibuf1,nbuf1); - j = getbits(hxbit[j][0]) + hxbit[j][1]; - for(;i;i--,gslidew++) slidebuf[gslidew&32767] = slidebuf[(gslidew-j)&32767]; - } - } while (!bfinal); + j = getbits(hxbit[j][0]) + hxbit[j][1]; + for(;i;i--,gslidew++) slidebuf[gslidew&32767] = slidebuf[(gslidew-j)&32767]; + } + } while (!bfinal); - gslider -= 16384; - if (!((gslider^gslidew)&32768)) - putbuf4zip(&slidebuf[gslider&32767],gslider,gslidew); - else - { - putbuf4zip(&slidebuf[gslider&32767],gslider,gslidew&~32767); - putbuf4zip(slidebuf,gslidew&~32767,gslidew); - } + gslider -= 16384; + if (!((gslider^gslidew)&32768)) + putbuf4zip(&slidebuf[gslider&32767],gslider,gslidew); + else + { + putbuf4zip(&slidebuf[gslider&32767],gslider,gslidew&~32767); + putbuf4zip(slidebuf,gslidew&~32767,gslidew); + } kzreadplc3:; kzfs.jmpplc = 3; - } + } retkzread:; - i = kzfs.pos; - kzfs.pos += leng; if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; - return(kzfs.pos-i); + i = kzfs.pos; + kzfs.pos += leng; if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; + return(kzfs.pos-i); } long kzfilelength () { - if (!kzfs.fil) return(0); - return(kzfs.leng); + if (!kzfs.fil) return(0); + return(kzfs.leng); } - //WARNING: kzseek(<-32768,SEEK_CUR); or: - // kzseek(0,SEEK_END); can make next kzread very slow!!! +//WARNING: kzseek(<-32768,SEEK_CUR); or: +// kzseek(0,SEEK_END); can make next kzread very slow!!! long kzseek (long offset, long 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; - } - if (kzfs.pos < 0) kzfs.pos = 0; - if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; - return(kzfs.pos); + 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; + } + if (kzfs.pos < 0) kzfs.pos = 0; + if (kzfs.pos > kzfs.leng) kzfs.pos = kzfs.leng; + return(kzfs.pos); } long kztell () { - if (!kzfs.fil) return(-1); - return(kzfs.pos); + if (!kzfs.fil) return(-1); + return(kzfs.pos); } long kzgetc () { - char ch; - if (!kzread(&ch,1)) return(-1); - return((long)ch); + char ch; + if (!kzread(&ch,1)) return(-1); + return((long)ch); } long kzeof () { - if (!kzfs.fil) return(-1); - return(kzfs.pos >= kzfs.leng); + if (!kzfs.fil) return(-1); + return(kzfs.pos >= kzfs.leng); } void kzclose () { - if (kzfs.fil) { fclose(kzfs.fil); kzfs.fil = 0; } + if (kzfs.fil) { fclose(kzfs.fil); kzfs.fil = 0; } } //====================== ZIP decompression code ends ========================= @@ -3098,20 +3098,20 @@ void kzclose () void kpzload (const char *filnam, long *pic, long *bpl, long *xsiz, long *ysiz) { - char *buf; - long leng; + char *buf; + long leng; - (*pic) = 0; - if (!kzopen(filnam)) return; - leng = kzfilelength(); - buf = (char *)malloc(leng); if (!buf) return; - kzread(buf,leng); - kzclose(); + (*pic) = 0; + if (!kzopen(filnam)) return; + leng = kzfilelength(); + buf = (char *)malloc(leng); if (!buf) return; + kzread(buf,leng); + kzclose(); - kpgetdim(buf,leng,xsiz,ysiz); - (*bpl) = ((*xsiz)<<2); - (*pic) = (long)malloc((*ysiz)*(*bpl)); if (!(*pic)) { free(buf); return; } - if (kprender(buf,leng,*pic,*bpl,*xsiz,*ysiz,0,0) < 0) { free(buf); free((void *)*pic); (*pic) = 0; return; } - free(buf); + kpgetdim(buf,leng,xsiz,ysiz); + (*bpl) = ((*xsiz)<<2); +(*pic) = (long)malloc((*ysiz)*(*bpl)); if (!(*pic)) { free(buf); return; } + if (kprender(buf,leng,*pic,*bpl,*xsiz,*ysiz,0,0) < 0) { free(buf); free((void *)*pic); (*pic) = 0; return; } + free(buf); } //====================== HANDY PICTURE function ends ========================= diff --git a/polymer/build/src/lzf_c.c b/polymer/build/src/lzf_c.c index b9b9ef991..6178d2438 100644 --- a/polymer/build/src/lzf_c.c +++ b/polymer/build/src/lzf_c.c @@ -82,161 +82,161 @@ unsigned int lzf_compress (const void *const in_data, unsigned int in_len, - void *out_data, unsigned int out_len + void *out_data, unsigned int out_len #if LZF_STATE_ARG , LZF_STATE *htab #endif - ) + ) { #if !LZF_STATE_ARG - LZF_STATE htab; + LZF_STATE htab; #endif - const u8 **hslot; - const u8 *ip = (const u8 *)in_data; - u8 *op = (u8 *)out_data; - const u8 *in_end = ip + in_len; - u8 *out_end = op + out_len; - const u8 *ref; + const u8 **hslot; + const u8 *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + const u8 *in_end = ip + in_len; + u8 *out_end = op + out_len; + const u8 *ref; - unsigned int hval = FRST (ip); - unsigned long off; - int lit = 0; + unsigned int hval = FRST (ip); + unsigned long off; + int lit = 0; #if INIT_HTAB # if USE_MEMCPY memset (htab, 0, sizeof (htab)); # else for (hslot = htab; hslot < htab + HSIZE; hslot++) - *hslot++ = ip; + *hslot++ = ip; # endif #endif - for (;;) + for (;;) { - if (ip < in_end - 2) + if (ip < in_end - 2) { - hval = NEXT (hval, ip); - hslot = htab + IDX (hval); - ref = *hslot; *hslot = ip; + hval = NEXT (hval, ip); + hslot = htab + IDX (hval); + ref = *hslot; *hslot = ip; - if (1 + if (1 #if INIT_HTAB && !USE_MEMCPY - && ref < ip /* the next test will actually take care of this, but this is faster */ + && ref < ip /* the next test will actually take care of this, but this is faster */ #endif - && (off = ip - ref - 1) < MAX_OFF - && ip + 4 < in_end - && ref > (u8 *)in_data + && (off = ip - ref - 1) < MAX_OFF + && ip + 4 < in_end + && ref > (u8 *)in_data #if STRICT_ALIGN - && ref[0] == ip[0] - && ref[1] == ip[1] - && ref[2] == ip[2] + && ref[0] == ip[0] + && ref[1] == ip[1] + && ref[2] == ip[2] #else - && *(u16 *)ref == *(u16 *)ip - && ref[2] == ip[2] + && *(u16 *)ref == *(u16 *)ip + && ref[2] == ip[2] #endif - ) + ) { - /* match found at *ref++ */ - unsigned int len = 2; - unsigned int maxlen = in_end - ip - len; - maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; + /* match found at *ref++ */ + unsigned int len = 2; + unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; - if (op + lit + 1 + 3 >= out_end) - return 0; + if (op + lit + 1 + 3 >= out_end) + return 0; - do - len++; - while (len < maxlen && ref[len] == ip[len]); + do + len++; + while (len < maxlen && ref[len] == ip[len]); - if (lit) + if (lit) { - *op++ = lit - 1; - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); + *op++ = lit - 1; + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); } - len -= 2; - ip++; + len -= 2; + ip++; - if (len < 7) + if (len < 7) { - *op++ = (off >> 8) + (len << 5); + *op++ = (off >> 8) + (len << 5); } - else + else { - *op++ = (off >> 8) + ( 7 << 5); - *op++ = len - 7; + *op++ = (off >> 8) + ( 7 << 5); + *op++ = len - 7; } - *op++ = off; + *op++ = off; #if ULTRA_FAST || VERY_FAST - ip += len; + ip += len; #if VERY_FAST && !ULTRA_FAST - --ip; + --ip; #endif - hval = FRST (ip); + hval = FRST (ip); - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; #if VERY_FAST && !ULTRA_FAST - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; #endif #else - do + do { - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; } - while (len--); + while (len--); #endif - continue; + continue; } } - else if (ip == in_end) - break; + else if (ip == in_end) + break; - /* one more literal byte we must copy */ - lit++; - ip++; + /* one more literal byte we must copy */ + lit++; + ip++; - if (lit == MAX_LIT) + if (lit == MAX_LIT) { - if (op + 1 + MAX_LIT >= out_end) - return 0; + if (op + 1 + MAX_LIT >= out_end) + return 0; - *op++ = MAX_LIT - 1; + *op++ = MAX_LIT - 1; #if USE_MEMCPY - memcpy (op, ip - MAX_LIT, MAX_LIT); - op += MAX_LIT; - lit = 0; + memcpy (op, ip - MAX_LIT, MAX_LIT); + op += MAX_LIT; + lit = 0; #else - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); #endif } } - if (lit) + if (lit) { - if (op + lit + 1 >= out_end) - return 0; + if (op + lit + 1 >= out_end) + return 0; - *op++ = lit - 1; - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); + *op++ = lit - 1; + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); } - return op - (u8 *) out_data; + return op - (u8 *) out_data; } diff --git a/polymer/build/src/lzf_d.c b/polymer/build/src/lzf_d.c index d0229d7dc..58b4edc10 100644 --- a/polymer/build/src/lzf_d.c +++ b/polymer/build/src/lzf_d.c @@ -45,72 +45,72 @@ # define SET_ERRNO(n) errno = (n) #endif -unsigned int +unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len) { - u8 const *ip = (const u8 *)in_data; - u8 *op = (u8 *)out_data; - u8 const *const in_end = ip + in_len; - u8 *const out_end = op + out_len; + u8 const *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + u8 const *const in_end = ip + in_len; + u8 *const out_end = op + out_len; - do + do { - unsigned int ctrl = *ip++; + unsigned int ctrl = *ip++; - if (ctrl < (1 << 5)) /* literal run */ + if (ctrl < (1 << 5)) /* literal run */ { - ctrl++; + ctrl++; - if (op + ctrl > out_end) + if (op + ctrl > out_end) { - SET_ERRNO (E2BIG); - return 0; + SET_ERRNO (E2BIG); + return 0; } #if USE_MEMCPY - memcpy (op, ip, ctrl); - op += ctrl; - ip += ctrl; + memcpy (op, ip, ctrl); + op += ctrl; + ip += ctrl; #else - do - *op++ = *ip++; - while (--ctrl); + do + *op++ = *ip++; + while (--ctrl); #endif } - else /* back reference */ + else /* back reference */ { - unsigned int len = ctrl >> 5; + unsigned int len = ctrl >> 5; - u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; + u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; - if (len == 7) - len += *ip++; - - ref -= *ip++; + if (len == 7) + len += *ip++; - if (op + len + 2 > out_end) + ref -= *ip++; + + if (op + len + 2 > out_end) { - SET_ERRNO (E2BIG); - return 0; + SET_ERRNO (E2BIG); + return 0; } - if (ref < (u8 *)out_data) + if (ref < (u8 *)out_data) { - SET_ERRNO (EINVAL); - return 0; + SET_ERRNO (EINVAL); + return 0; } - *op++ = *ref++; - *op++ = *ref++; - - do *op++ = *ref++; - while (--len); + *op++ = *ref++; + + do + *op++ = *ref++; + while (--len); } } - while (op < out_end && ip < in_end); + while (op < out_end && ip < in_end); - return op - (u8 *)out_data; + return op - (u8 *)out_data; } diff --git a/polymer/build/src/lzwnew.c b/polymer/build/src/lzwnew.c index dad07a960..ee93460ce 100644 --- a/polymer/build/src/lzwnew.c +++ b/polymer/build/src/lzwnew.c @@ -10,107 +10,107 @@ static unsigned short SSWAPIB (unsigned short a) { return((a>>8)+(a<<8)); } #define USENEW 1 long lzwcompress (unsigned char *ucompbuf, long ucompleng, unsigned char *compbuf) { - long i, j, numnodes, *lptr, bitcnt, nbits, oneupnbits, hmask, *child; - long *sibly; + long i, j, numnodes, *lptr, bitcnt, nbits, oneupnbits, hmask, *child; + long *sibly; #if USENEW - long *sibry; + long *sibry; #endif - unsigned char *nodev, *cptr, *eptr; + unsigned char *nodev, *cptr, *eptr; - nodev = (unsigned char *)malloc((ucompleng+256)*sizeof(char)); if (!nodev) return(0); - child = (long *)malloc((ucompleng+256)*sizeof(long)); if (!child) { free(nodev); return(0); } - sibly = (long *)malloc((ucompleng+256)*sizeof(long)); if (!sibly) { free(child); free(nodev); return(0); } + nodev = (unsigned char *)malloc((ucompleng+256)*sizeof(char)); if (!nodev) return(0); +child = (long *)malloc((ucompleng+256)*sizeof(long)); if (!child) { free(nodev); return(0); } + sibly = (long *)malloc((ucompleng+256)*sizeof(long)); if (!sibly) { free(child); free(nodev); return(0); } #if USENEW - sibry = (long *)malloc((ucompleng+256)*sizeof(long)); if (!sibry) { free(sibly); free(child); free(nodev); return(0); } + sibry = (long *)malloc((ucompleng+256)*sizeof(long)); if (!sibry) { free(sibly); free(child); free(nodev); return(0); } #endif - for(i=255;i>=0;i--) { nodev[i] = i; child[i] = -1; } - memset(compbuf,0,ucompleng+15); + for(i=255;i>=0;i--) { nodev[i] = i; child[i] = -1; } + memset(compbuf,0,ucompleng+15); - cptr = ucompbuf; eptr = &ucompbuf[ucompleng]; + cptr = ucompbuf; eptr = &ucompbuf[ucompleng]; - numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1); - do - { - for(i=cptr[0];i>=0;i=j) - { - cptr++; if (cptr >= eptr) goto lzwcompbreak2b; - j = child[i]; if (j < 0) { child[i] = numnodes; break; } + numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1); + do + { + for(i=cptr[0];i>=0;i=j) + { + cptr++; if (cptr >= eptr) goto lzwcompbreak2b; + j = child[i]; if (j < 0) { child[i] = numnodes; break; } #if USENEW - //This is about 2x faster when ucompbuf is more random, 5% slower when very compressible - while (cptr[0] != nodev[j]) - { - if (cptr[0] < nodev[j]) - { if (sibly[j] < 0) { sibly[j] = numnodes; goto lzwcompbreak2a; } j = sibly[j]; } - else { if (sibry[j] < 0) { sibry[j] = numnodes; goto lzwcompbreak2a; } j = sibry[j]; } - } + //This is about 2x faster when ucompbuf is more random, 5% slower when very compressible + while (cptr[0] != nodev[j]) + { + if (cptr[0] < nodev[j]) + { if (sibly[j] < 0) { sibly[j] = numnodes; goto lzwcompbreak2a; } j = sibly[j]; } + else { if (sibry[j] < 0) { sibry[j] = numnodes; goto lzwcompbreak2a; } j = sibry[j]; } + } #else - for(;nodev[j]!=cptr[0];j=sibly[j]) - if (sibly[j] < 0) { sibly[j] = numnodes; goto lzwcompbreak2a; } + for(;nodev[j]!=cptr[0];j=sibly[j]) + if (sibly[j] < 0) { sibly[j] = numnodes; goto lzwcompbreak2a; } #endif - } + } lzwcompbreak2a: nodev[numnodes] = cptr[0]; lzwcompbreak2b: child[numnodes] = sibly[numnodes] = -1; #if USENEW - sibry[numnodes] = -1; + sibry[numnodes] = -1; #endif - lptr = (long *)&compbuf[bitcnt>>3]; lptr[0] |= LSWAPIB(i<<(bitcnt&7)); - bitcnt += nbits; if ((i&hmask) > ((numnodes-1)&hmask)) bitcnt--; + lptr = (long *)&compbuf[bitcnt>>3]; lptr[0] |= LSWAPIB(i<<(bitcnt&7)); + bitcnt += nbits; if ((i&hmask) > ((numnodes-1)&hmask)) bitcnt--; - numnodes++; if (numnodes > oneupnbits) { nbits++; oneupnbits <<= 1; hmask = ((oneupnbits>>1)-1); } - } while ((cptr < eptr) && (bitcnt < (ucompleng<<3))); + numnodes++; if (numnodes > oneupnbits) { nbits++; oneupnbits <<= 1; hmask = ((oneupnbits>>1)-1); } + } while ((cptr < eptr) && (bitcnt < (ucompleng<<3))); #if USENEW - free(sibry); + free(sibry); #endif - free(sibly); - free(child); free(nodev); + free(sibly); + free(child); free(nodev); - lptr = (long *)compbuf; - if (((bitcnt+7)>>3) < ucompleng) { lptr[0] = LSWAPIB(numnodes); return((bitcnt+7)>>3); } - memcpy(compbuf,ucompbuf,ucompleng); return(ucompleng); + lptr = (long *)compbuf; +if (((bitcnt+7)>>3) < ucompleng) { lptr[0] = LSWAPIB(numnodes); return((bitcnt+7)>>3); } + memcpy(compbuf,ucompbuf,ucompleng); return(ucompleng); } long lzwuncompress (unsigned char *compbuf, long compleng, unsigned char *ucompbuf, long ucompleng) { - long i, dat, leng, bitcnt, *lptr, numnodes, totnodes, nbits, oneupnbits, hmask, *prefix; - unsigned char ch, *ucptr, *suffix; - long ucomp = (long)ucompbuf; + long i, dat, leng, bitcnt, *lptr, numnodes, totnodes, nbits, oneupnbits, hmask, *prefix; + unsigned char ch, *ucptr, *suffix; + long ucomp = (long)ucompbuf; - if (compleng >= ucompleng) { memcpy(ucompbuf,compbuf,ucompleng); return ucompleng; } + if (compleng >= ucompleng) { memcpy(ucompbuf,compbuf,ucompleng); return ucompleng; } - totnodes = LSWAPIB(((long *)compbuf)[0]); if (totnodes <= 0 || totnodes >= ucompleng+256) return 0; - - prefix = (long *)malloc(totnodes*sizeof(long)); if (!prefix) return 0; - suffix = (unsigned char *)malloc(totnodes*sizeof(char)); if (!suffix) { free(prefix); return 0; } + totnodes = LSWAPIB(((long *)compbuf)[0]); if (totnodes <= 0 || totnodes >= ucompleng+256) return 0; - numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1); - do - { - lptr = (long *)&compbuf[bitcnt>>3]; dat = ((LSWAPIB(lptr[0])>>(bitcnt&7))&(oneupnbits-1)); - bitcnt += nbits; if ((dat&hmask) > ((numnodes-1)&hmask)) { dat &= hmask; bitcnt--; } + prefix = (long *)malloc(totnodes*sizeof(long)); if (!prefix) return 0; +suffix = (unsigned char *)malloc(totnodes*sizeof(char)); if (!suffix) { free(prefix); return 0; } - prefix[numnodes] = dat; + numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1); + do + { + lptr = (long *)&compbuf[bitcnt>>3]; dat = ((LSWAPIB(lptr[0])>>(bitcnt&7))&(oneupnbits-1)); + bitcnt += nbits; if ((dat&hmask) > ((numnodes-1)&hmask)) { dat &= hmask; bitcnt--; } - ucompbuf++; - for(leng=0;dat>=256;dat=prefix[dat]) { - if ((long)ucompbuf+leng-ucomp > ucompleng) goto bail; - ucompbuf[leng++] = suffix[dat]; - } + prefix[numnodes] = dat; - ucptr = &ucompbuf[leng-1]; - for(i=(leng>>1)-1;i>=0;i--) { ch = ucompbuf[i]; ucompbuf[i] = ucptr[-i]; ucptr[-i] = ch; } - ucompbuf[-1] = dat; ucompbuf += leng; + ucompbuf++; + for(leng=0;dat>=256;dat=prefix[dat]) { + if ((long)ucompbuf+leng-ucomp > ucompleng) goto bail; + ucompbuf[leng++] = suffix[dat]; + } - suffix[numnodes-1] = suffix[numnodes] = dat; + ucptr = &ucompbuf[leng-1]; + for(i=(leng>>1)-1;i>=0;i--) { ch = ucompbuf[i]; ucompbuf[i] = ucptr[-i]; ucptr[-i] = ch; } + ucompbuf[-1] = dat; ucompbuf += leng; - numnodes++; if (numnodes > oneupnbits) { nbits++; oneupnbits <<= 1; hmask = ((oneupnbits>>1)-1); } - } while (numnodes < totnodes); + suffix[numnodes-1] = suffix[numnodes] = dat; + + numnodes++; if (numnodes > oneupnbits) { nbits++; oneupnbits <<= 1; hmask = ((oneupnbits>>1)-1); } + } while (numnodes < totnodes); bail: - free(suffix); free(prefix); - - return (long)ucompbuf-ucomp; + free(suffix); free(prefix); + + return (long)ucompbuf-ucomp; } //-------------------------------------------------------------------------------------------------- diff --git a/polymer/build/src/md4.c b/polymer/build/src/md4.c index 7de5776a0..1aab9dfba 100644 --- a/polymer/build/src/md4.c +++ b/polymer/build/src/md4.c @@ -53,10 +53,10 @@ static void Decode (UINT4 *, unsigned char *, unsigned int); #define MD4_memset memset static unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; /* F, G and H are basic MD4 functions. */ @@ -85,25 +85,25 @@ static unsigned char PADDING[64] = { void md4once(unsigned char *block, unsigned int len, unsigned char digest[16]) { - MD4_CTX ctx; - - md4init(&ctx); - md4block(&ctx, block, len); - md4finish(digest, &ctx); + MD4_CTX ctx; + + md4init(&ctx); + md4block(&ctx, block, len); + md4finish(digest, &ctx); } /* MD4 initialization. Begins an MD4 operation, writing a new context. */ void md4init (MD4_CTX *context) { - context->count[0] = context->count[1] = 0; + context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; + /* Load magic initialization constants. + */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; } /* MD4 block update operation. Continues an MD4 message-digest @@ -112,35 +112,35 @@ void md4init (MD4_CTX *context) */ void md4block (MD4_CTX *context, unsigned char *input, unsigned int inputLen) { - unsigned int i, index, partLen; + unsigned int i, index, partLen; - /* Compute number of bytes mod 64 */ - index = (unsigned int)((context->count[0] >> 3) & 0x3F); - /* Update number of bits */ - if ((context->count[0] += ((UINT4)inputLen << 3)) - < ((UINT4)inputLen << 3)) - context->count[1]++; - context->count[1] += ((UINT4)inputLen >> 29); + /* Compute number of bytes mod 64 */ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + /* Update number of bits */ + if ((context->count[0] += ((UINT4)inputLen << 3)) + < ((UINT4)inputLen << 3)) + context->count[1]++; + context->count[1] += ((UINT4)inputLen >> 29); - partLen = 64 - index; + partLen = 64 - index; - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { + /* Transform as many times as possible. + */ + if (inputLen >= partLen) { + MD4_memcpy + ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD4Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD4Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + + /* Buffer remaining input */ MD4_memcpy - ((POINTER)&context->buffer[index], (POINTER)input, partLen); - MD4Transform (context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD4Transform (context->state, &input[i]); - - index = 0; - } - else - i = 0; - - /* Buffer remaining input */ - MD4_memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); } @@ -150,98 +150,98 @@ void md4block (MD4_CTX *context, unsigned char *input, unsigned int inputLen) */ void md4finish (unsigned char digest[16], MD4_CTX *context) { - unsigned char bits[8]; - unsigned int index, padLen; + unsigned char bits[8]; + unsigned int index, padLen; - /* Save number of bits */ - Encode (bits, context->count, 8); + /* Save number of bits */ + Encode (bits, context->count, 8); - /* Pad out to 56 mod 64. - */ - index = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - md4block (context, PADDING, padLen); + /* Pad out to 56 mod 64. + */ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + md4block (context, PADDING, padLen); - /* Append length (before padding) */ - md4block (context, bits, 8); - /* Store state in digest */ - Encode (digest, context->state, 16); + /* Append length (before padding) */ + md4block (context, bits, 8); + /* Store state in digest */ + Encode (digest, context->state, 16); - /* Zeroize sensitive information. - */ - MD4_memset ((POINTER)context, 0, sizeof (*context)); + /* Zeroize sensitive information. + */ + MD4_memset ((POINTER)context, 0, sizeof (*context)); } /* MD4 basic transformation. Transforms state based on block. */ static void MD4Transform (UINT4 state[4], unsigned char block[64]) { - UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - Decode (x, block, 64); + Decode (x, block, 64); - /* Round 1 */ - FF (a, b, c, d, x[ 0], S11); /* 1 */ - FF (d, a, b, c, x[ 1], S12); /* 2 */ - FF (c, d, a, b, x[ 2], S13); /* 3 */ - FF (b, c, d, a, x[ 3], S14); /* 4 */ - FF (a, b, c, d, x[ 4], S11); /* 5 */ - FF (d, a, b, c, x[ 5], S12); /* 6 */ - FF (c, d, a, b, x[ 6], S13); /* 7 */ - FF (b, c, d, a, x[ 7], S14); /* 8 */ - FF (a, b, c, d, x[ 8], S11); /* 9 */ - FF (d, a, b, c, x[ 9], S12); /* 10 */ - FF (c, d, a, b, x[10], S13); /* 11 */ - FF (b, c, d, a, x[11], S14); /* 12 */ - FF (a, b, c, d, x[12], S11); /* 13 */ - FF (d, a, b, c, x[13], S12); /* 14 */ - FF (c, d, a, b, x[14], S13); /* 15 */ - FF (b, c, d, a, x[15], S14); /* 16 */ + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11); /* 1 */ + FF (d, a, b, c, x[ 1], S12); /* 2 */ + FF (c, d, a, b, x[ 2], S13); /* 3 */ + FF (b, c, d, a, x[ 3], S14); /* 4 */ + FF (a, b, c, d, x[ 4], S11); /* 5 */ + FF (d, a, b, c, x[ 5], S12); /* 6 */ + FF (c, d, a, b, x[ 6], S13); /* 7 */ + FF (b, c, d, a, x[ 7], S14); /* 8 */ + FF (a, b, c, d, x[ 8], S11); /* 9 */ + FF (d, a, b, c, x[ 9], S12); /* 10 */ + FF (c, d, a, b, x[10], S13); /* 11 */ + FF (b, c, d, a, x[11], S14); /* 12 */ + FF (a, b, c, d, x[12], S11); /* 13 */ + FF (d, a, b, c, x[13], S12); /* 14 */ + FF (c, d, a, b, x[14], S13); /* 15 */ + FF (b, c, d, a, x[15], S14); /* 16 */ - /* Round 2 */ - GG (a, b, c, d, x[ 0], S21); /* 17 */ - GG (d, a, b, c, x[ 4], S22); /* 18 */ - GG (c, d, a, b, x[ 8], S23); /* 19 */ - GG (b, c, d, a, x[12], S24); /* 20 */ - GG (a, b, c, d, x[ 1], S21); /* 21 */ - GG (d, a, b, c, x[ 5], S22); /* 22 */ - GG (c, d, a, b, x[ 9], S23); /* 23 */ - GG (b, c, d, a, x[13], S24); /* 24 */ - GG (a, b, c, d, x[ 2], S21); /* 25 */ - GG (d, a, b, c, x[ 6], S22); /* 26 */ - GG (c, d, a, b, x[10], S23); /* 27 */ - GG (b, c, d, a, x[14], S24); /* 28 */ - GG (a, b, c, d, x[ 3], S21); /* 29 */ - GG (d, a, b, c, x[ 7], S22); /* 30 */ - GG (c, d, a, b, x[11], S23); /* 31 */ - GG (b, c, d, a, x[15], S24); /* 32 */ + /* Round 2 */ + GG (a, b, c, d, x[ 0], S21); /* 17 */ + GG (d, a, b, c, x[ 4], S22); /* 18 */ + GG (c, d, a, b, x[ 8], S23); /* 19 */ + GG (b, c, d, a, x[12], S24); /* 20 */ + GG (a, b, c, d, x[ 1], S21); /* 21 */ + GG (d, a, b, c, x[ 5], S22); /* 22 */ + GG (c, d, a, b, x[ 9], S23); /* 23 */ + GG (b, c, d, a, x[13], S24); /* 24 */ + GG (a, b, c, d, x[ 2], S21); /* 25 */ + GG (d, a, b, c, x[ 6], S22); /* 26 */ + GG (c, d, a, b, x[10], S23); /* 27 */ + GG (b, c, d, a, x[14], S24); /* 28 */ + GG (a, b, c, d, x[ 3], S21); /* 29 */ + GG (d, a, b, c, x[ 7], S22); /* 30 */ + GG (c, d, a, b, x[11], S23); /* 31 */ + GG (b, c, d, a, x[15], S24); /* 32 */ - /* Round 3 */ - HH (a, b, c, d, x[ 0], S31); /* 33 */ - HH (d, a, b, c, x[ 8], S32); /* 34 */ - HH (c, d, a, b, x[ 4], S33); /* 35 */ - HH (b, c, d, a, x[12], S34); /* 36 */ - HH (a, b, c, d, x[ 2], S31); /* 37 */ - HH (d, a, b, c, x[10], S32); /* 38 */ - HH (c, d, a, b, x[ 6], S33); /* 39 */ - HH (b, c, d, a, x[14], S34); /* 40 */ - HH (a, b, c, d, x[ 1], S31); /* 41 */ - HH (d, a, b, c, x[ 9], S32); /* 42 */ - HH (c, d, a, b, x[ 5], S33); /* 43 */ - HH (b, c, d, a, x[13], S34); /* 44 */ - HH (a, b, c, d, x[ 3], S31); /* 45 */ - HH (d, a, b, c, x[11], S32); /* 46 */ - HH (c, d, a, b, x[ 7], S33); /* 47 */ - HH (b, c, d, a, x[15], S34); /* 48 */ + /* Round 3 */ + HH (a, b, c, d, x[ 0], S31); /* 33 */ + HH (d, a, b, c, x[ 8], S32); /* 34 */ + HH (c, d, a, b, x[ 4], S33); /* 35 */ + HH (b, c, d, a, x[12], S34); /* 36 */ + HH (a, b, c, d, x[ 2], S31); /* 37 */ + HH (d, a, b, c, x[10], S32); /* 38 */ + HH (c, d, a, b, x[ 6], S33); /* 39 */ + HH (b, c, d, a, x[14], S34); /* 40 */ + HH (a, b, c, d, x[ 1], S31); /* 41 */ + HH (d, a, b, c, x[ 9], S32); /* 42 */ + HH (c, d, a, b, x[ 5], S33); /* 43 */ + HH (b, c, d, a, x[13], S34); /* 44 */ + HH (a, b, c, d, x[ 3], S31); /* 45 */ + HH (d, a, b, c, x[11], S32); /* 46 */ + HH (c, d, a, b, x[ 7], S33); /* 47 */ + HH (b, c, d, a, x[15], S34); /* 48 */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; - /* Zeroize sensitive information. - */ - MD4_memset ((POINTER)x, 0, sizeof (x)); + /* Zeroize sensitive information. + */ + MD4_memset ((POINTER)x, 0, sizeof (x)); } /* Encodes input (UINT4) into output (unsigned char). Assumes len is @@ -249,14 +249,14 @@ static void MD4Transform (UINT4 state[4], unsigned char block[64]) */ static void Encode (unsigned char *output, UINT4 *input, unsigned int len) { - unsigned int i, j; + unsigned int i, j; - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); - } + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is @@ -264,9 +264,9 @@ static void Encode (unsigned char *output, UINT4 *input, unsigned int len) */ static void Decode (UINT4 *output, unsigned char *input, unsigned int len) { - unsigned int i, j; + unsigned int i, j; - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } diff --git a/polymer/build/src/mdsprite.c b/polymer/build/src/mdsprite.c index a5d6b1563..e12c18657 100644 --- a/polymer/build/src/mdsprite.c +++ b/polymer/build/src/mdsprite.c @@ -8,10 +8,10 @@ typedef struct { - long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! - long shadeoff; - float scale, bscale, zadd; - GLuint *texid; // skins + long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! + long shadeoff; + float scale, bscale, zadd; + GLuint *texid; // skins } mdmodel; typedef struct _mdanim_t @@ -25,19 +25,19 @@ typedef struct _mdanim_t typedef struct _mdskinmap_t { - unsigned char palette, filler[3]; // Build palette number - int skinnum, surfnum; // Skin identifier, surface number - char *fn; // Skin filename - GLuint texid[HICEFFECTMASK+1]; // OpenGL texture numbers for effect variations - struct _mdskinmap_t *next; + unsigned char palette, filler[3]; // Build palette number + int skinnum, surfnum; // Skin identifier, surface number + char *fn; // Skin filename + GLuint texid[HICEFFECTMASK+1]; // OpenGL texture numbers for effect variations + struct _mdskinmap_t *next; } mdskinmap_t; - //This MD2 code is based on the source code from David Henry (tfc_duke(at)hotmail.com) - // Was at http://tfc.duke.free.fr/us/tutorials/models/md2.htm - // Available from http://web.archive.org/web/20030816010242/http://tfc.duke.free.fr/us/tutorials/models/md2.htm - // Now at http://tfc.duke.free.fr/coding/md2.html (in French) - //He probably wouldn't recognize it if he looked at it though :) +//This MD2 code is based on the source code from David Henry (tfc_duke(at)hotmail.com) +// Was at http://tfc.duke.free.fr/us/tutorials/models/md2.htm +// Available from http://web.archive.org/web/20030816010242/http://tfc.duke.free.fr/us/tutorials/models/md2.htm +// Now at http://tfc.duke.free.fr/coding/md2.html (in French) +//He probably wouldn't recognize it if he looked at it though :) typedef struct { float x, y, z; } point3d; typedef struct @@ -57,11 +57,11 @@ typedef struct typedef struct { - //WARNING: This top block is a union between md2model&md3model: Make sure it matches! - long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! - long shadeoff; - float scale, bscale, zadd; - GLuint *texid; // texture ids for base skin if no mappings defined + //WARNING: This top block is a union between md2model&md3model: Make sure it matches! + long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! + long shadeoff; + float scale, bscale, zadd; + GLuint *texid; // texture ids for base skin if no mappings defined long numframes, cframe, nframe, fpssc, usesalpha; float oldtime, curtime, interpol; @@ -69,7 +69,7 @@ typedef struct mdskinmap_t *skinmap; long numskins, skinloaded; // set to 1+numofskin when a skin is loaded and the tex coords are modified, - //MD2 specific stuff: + //MD2 specific stuff: long numverts, numglcmds, framebytes, *glcmds; char *frames; char *basepath; // pointer to string of base path @@ -122,7 +122,7 @@ typedef struct typedef struct { - //WARNING: This top block is a union between md2model&md3model: Make sure it matches! + //WARNING: This top block is a union between md2model&md3model: Make sure it matches! long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! long shadeoff; float scale, bscale, zadd; @@ -134,8 +134,8 @@ typedef struct mdskinmap_t *skinmap; long numskins, skinloaded; // set to 1+numofskin when a skin is loaded and the tex coords are modified, - //MD3 specific - md3head_t head; + //MD3 specific + md3head_t head; } md3model; #define VOXBORDWIDTH 1 //use 0 to save memory, but has texture artifacts; 1 looks better... @@ -148,13 +148,13 @@ typedef struct { unsigned short x, y, z, u, v; } vert_t; typedef struct { vert_t v[4]; } voxrect_t; typedef struct { - //WARNING: This top block is a union of md2model,md3model,voxmodel: Make sure it matches! + //WARNING: This top block is a union of md2model,md3model,voxmodel: Make sure it matches! long mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! long shadeoff; float scale, bscale, zadd; unsigned int *texid; // skins for palettes - //VOX specific stuff: + //VOX specific stuff: voxrect_t *quad; long qcnt, qfacind[7]; long *mytex, mytexx, mytexy; long xsiz, ysiz, zsiz; @@ -171,7 +171,7 @@ typedef struct } tile2model_t; static tile2model_t tile2model[MAXTILES]; - //Move this to appropriate place! +//Move this to appropriate place! typedef struct { float xadd, yadd, zadd; short angadd, flags; } hudtyp; hudtyp hudmem[2][MAXTILES]; //~320KB ... ok for now ... could replace with dynamic alloc @@ -303,8 +303,8 @@ static long framename2index (mdmodel *vm, const char *nam) switch(vm->mdnum) { - case 2: - { + case 2: + { md2model *m = (md2model *)vm; md2frame_t *fr; for(i=0;inumframes;i++) @@ -312,15 +312,15 @@ static long framename2index (mdmodel *vm, const char *nam) fr = (md2frame_t *)&m->frames[i*m->framebytes]; if (!Bstrcmp(fr->name, nam)) break; } - } - break; - case 3: - { + } + break; + case 3: + { md3model *m = (md3model *)vm; for(i=0;inumframes;i++) if (!Bstrcmp(m->head.frames[i].nam,nam)) break; - } - break; + } + break; } return(i); } @@ -368,12 +368,12 @@ int md_defineanimation (int modelid, const char *framestart, const char *frameen m = (md2model *)models[modelid]; if (m->mdnum < 2) return 0; - //find index of start frame + //find index of start frame i = framename2index((mdmodel*)m,framestart); if (i == m->numframes) return -2; ma.startframe = i; - //find index of finish frame which must trail start frame + //find index of finish frame which must trail start frame i = framename2index((mdmodel*)m,frameend); if (i == m->numframes) return -3; ma.endframe = i; @@ -472,14 +472,14 @@ int md_undefinemodel(int modelid) static int daskinloader (long filh, long *fptr, long *bpl, long *sizx, long *sizy, long *osizx, long *osizy, char *hasalpha, char effect) { - long picfillen, j,y,x; - char *picfil,*cptr,al=255; - coltype *pic; - long xsiz, ysiz, tsizx, tsizy; + long picfillen, j,y,x; + char *picfil,*cptr,al=255; + coltype *pic; + long xsiz, ysiz, tsizx, tsizy; - picfillen = kfilelength(filh); - picfil = (char *)malloc(picfillen); if (!picfil) { return -1; } - kread(filh, picfil, picfillen); + picfillen = kfilelength(filh); + picfil = (char *)malloc(picfillen); if (!picfil) { return -1; } + kread(filh, picfil, picfillen); // tsizx/y = replacement texture's natural size // xsiz/y = 2^x size of replacement @@ -500,13 +500,13 @@ static int daskinloader (long filh, long *fptr, long *bpl, long *sizx, long *siz memset(pic,0,xsiz*ysiz*sizeof(coltype)); if (kprender(picfil,picfillen,(long)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0)) - { free(picfil); free(pic); return -1; } + { free(picfil); free(pic); return -1; } free(picfil); - cptr = &britable[gammabrightness ? 0 : curbrightness][0]; - for(y=0,j=0;ymagic, "Polymost", 8)) goto failure; + long fil, fp; + char cachefn[BMAX_PATH], *cp; + unsigned char mdsum[16]; - head->xdim = B_LITTLE32(head->xdim); - head->ydim = B_LITTLE32(head->ydim); - head->flags = B_LITTLE32(head->flags); + if (!glinfo.texcompr || !glusetexcompr || !glusetexcache) return -1; + if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB) { + // lacking the necessary extensions to do this + initprintf("Warning: the GL driver lacks necessary functions to use caching\n"); + glusetexcache = 0; + return -1; + } - if (!glinfo.texnpot && (head->flags & 1)) goto failure; - - return fil; + md4once(fn, strlen(fn), mdsum); + for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); + *(cp++) = '/'; + for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); + sprintf(cp, "-%lx-0%x", len, effect); + + fil = kopen4load(cachefn, 0); + if (fil < 0) return -1; + + /* initprintf("Loading cached skin: %s\n", cachefn); */ + + if (kread(fil, head, sizeof(texcacheheader)) < (int)sizeof(texcacheheader)) goto failure; + if (memcmp(head->magic, "Polymost", 8)) goto failure; + + head->xdim = B_LITTLE32(head->xdim); + head->ydim = B_LITTLE32(head->ydim); + head->flags = B_LITTLE32(head->flags); + + if (!glinfo.texnpot && (head->flags & 1)) goto failure; + + return fil; failure: - kclose(fil); - return -1; + kclose(fil); + return -1; } static long mdloadskin_cached(long fil, texcacheheader *head, long *doalloc, GLuint *glpic, long *xsiz, long *ysiz) { - int level, r; - texcachepicture pict; - void *pic = NULL, *packbuf = NULL; - void *midbuf = NULL; - long alloclen=0; - - if (*doalloc&1) { - bglGenTextures(1,glpic); //# of textures (make OpenGL allocate structure) - *doalloc |= 2; // prevents bglGenTextures being called again if we fail in here - } - bglBindTexture(GL_TEXTURE_2D,*glpic); - - bglGetError(); - - // load the mipmaps - for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++) { - r = kread(fil, &pict, sizeof(texcachepicture)); - if (r < (int)sizeof(texcachepicture)) goto failure; + int level, r; + texcachepicture pict; + void *pic = NULL, *packbuf = NULL; + void *midbuf = NULL; + long alloclen=0; - pict.size = B_LITTLE32(pict.size); - pict.format = B_LITTLE32(pict.format); - pict.xdim = B_LITTLE32(pict.xdim); - pict.ydim = B_LITTLE32(pict.ydim); - pict.border = B_LITTLE32(pict.border); - pict.depth = B_LITTLE32(pict.depth); + if (*doalloc&1) { + bglGenTextures(1,glpic); //# of textures (make OpenGL allocate structure) + *doalloc |= 2; // prevents bglGenTextures being called again if we fail in here + } + bglBindTexture(GL_TEXTURE_2D,*glpic); - if (level == 0) { *xsiz = pict.xdim; *ysiz = pict.ydim; } - - if (alloclen < pict.size) { - void *picc = realloc(pic, pict.size); - if (!picc) goto failure; else pic = picc; - alloclen = pict.size; - - picc = realloc(packbuf, alloclen+16); - if (!picc) goto failure; else packbuf = picc; - - picc = realloc(midbuf, pict.size); - if (!picc) goto failure; else midbuf = picc; - } - - if (dedxtfilter(fil, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) goto failure; - - bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border, - pict.size,pic); - if (bglGetError() != GL_NO_ERROR) goto failure; - } - - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); - return 0; + bglGetError(); + + // load the mipmaps + for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++) { + r = kread(fil, &pict, sizeof(texcachepicture)); + if (r < (int)sizeof(texcachepicture)) goto failure; + + pict.size = B_LITTLE32(pict.size); + pict.format = B_LITTLE32(pict.format); + pict.xdim = B_LITTLE32(pict.xdim); + pict.ydim = B_LITTLE32(pict.ydim); + pict.border = B_LITTLE32(pict.border); + pict.depth = B_LITTLE32(pict.depth); + + if (level == 0) { *xsiz = pict.xdim; *ysiz = pict.ydim; } + + if (alloclen < pict.size) { + void *picc = realloc(pic, pict.size); + if (!picc) goto failure; else pic = picc; + alloclen = pict.size; + + picc = realloc(packbuf, alloclen+16); + if (!picc) goto failure; else packbuf = picc; + + picc = realloc(midbuf, pict.size); + if (!picc) goto failure; else midbuf = picc; + } + + if (dedxtfilter(fil, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) goto failure; + + bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border, + pict.size,pic); + if (bglGetError() != GL_NO_ERROR) goto failure; + } + + if (midbuf) free(midbuf); + if (pic) free(pic); + if (packbuf) free(packbuf); + return 0; failure: - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); - return -1; + if (midbuf) free(midbuf); + if (pic) free(pic); + if (packbuf) free(packbuf); + return -1; } // --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF - //Note: even though it says md2model, it works for both md2model&md3model +//Note: even though it says md2model, it works for both md2model&md3model static long mdloadskin (md2model *m, int number, int pal, int surf) { - long i,j, fptr=0, bpl, xsiz, ysiz, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA; - char *skinfile, hasalpha, fn[BMAX_PATH+65]; - GLuint *texidx = NULL; - mdskinmap_t *sk, *skzero = NULL; - long doalloc = 1, filh; + long i,j, fptr=0, bpl, xsiz, ysiz, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA; + char *skinfile, hasalpha, fn[BMAX_PATH+65]; + GLuint *texidx = NULL; + mdskinmap_t *sk, *skzero = NULL; + long doalloc = 1, filh; - long cachefil = -1, picfillen; - texcacheheader cachead; - - if (m->mdnum == 2) surf = 0; + long cachefil = -1, picfillen; + texcacheheader cachead; + + if (m->mdnum == 2) surf = 0; if ((unsigned)pal >= (unsigned)MAXPALOOKUPS) return 0; i = -1; @@ -674,7 +674,7 @@ static long mdloadskin (md2model *m, int number, int pal, int surf) //OSD_Printf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile); break; } - //If no match, give highest priority to number, then pal.. (Parkar's request, 02/27/2005) + //If no match, give highest priority to number, then pal.. (Parkar's request, 02/27/2005) else if (((int)sk->palette == 0) && (sk->skinnum == number) && (sk->surfnum == surf) && (i < 5)) { i = 5; skzero = sk; } else if (((int)sk->palette == pal) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 4)) { i = 4; skzero = sk; } else if (((int)sk->palette == 0) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 3)) { i = 3; skzero = sk; } @@ -705,108 +705,108 @@ static long mdloadskin (md2model *m, int number, int pal, int surf) if (*texidx) return *texidx; *texidx = 0; - if ((filh = kopen4load(fn, 0)) < 0) { - initprintf("Skin %s not found.\n",fn); - skinfile[0] = 0; - return 0; - } + if ((filh = kopen4load(fn, 0)) < 0) { + initprintf("Skin %s not found.\n",fn); + skinfile[0] = 0; + return 0; + } - picfillen = kfilelength(filh); - kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c + picfillen = kfilelength(filh); + kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c - cachefil = mdloadskin_trytexcache(fn, picfillen, hictinting[pal].f, &cachead); - if (cachefil >= 0 && !mdloadskin_cached(cachefil, &cachead, &doalloc, texidx, &xsiz, &ysiz)) { - osizx = cachead.xdim; - osizy = cachead.ydim; - m->usesalpha = hasalpha = (cachead.flags & 2) ? 1 : 0; - kclose(cachefil); - //kclose(filh); // FIXME: uncomment when cache1d.c is fixed - // cachefil >= 0, so it won't be rewritten - } else { - if (cachefil >= 0) kclose(cachefil); - cachefil = -1; // the compressed version will be saved to disk - - if ((filh = kopen4load(fn, 0)) < 0) return -1; - if (daskinloader(filh,&fptr,&bpl,&xsiz,&ysiz,&osizx,&osizy,&hasalpha,hictinting[pal].f)) - { - kclose(filh); - initprintf("Failed loading skin file \"%s\"\n", fn); - skinfile[0] = 0; - return(0); - } else kclose(filh); - m->usesalpha = hasalpha; + cachefil = mdloadskin_trytexcache(fn, picfillen, hictinting[pal].f, &cachead); + if (cachefil >= 0 && !mdloadskin_cached(cachefil, &cachead, &doalloc, texidx, &xsiz, &ysiz)) { + osizx = cachead.xdim; + osizy = cachead.ydim; + m->usesalpha = hasalpha = (cachead.flags & 2) ? 1 : 0; + kclose(cachefil); + //kclose(filh); // FIXME: uncomment when cache1d.c is fixed + // cachefil >= 0, so it won't be rewritten + } else { + if (cachefil >= 0) kclose(cachefil); + cachefil = -1; // the compressed version will be saved to disk - if ((doalloc&3)==1) bglGenTextures(1,(GLuint*)texidx); - bglBindTexture(GL_TEXTURE_2D,*texidx); + if ((filh = kopen4load(fn, 0)) < 0) return -1; + if (daskinloader(filh,&fptr,&bpl,&xsiz,&ysiz,&osizx,&osizy,&hasalpha,hictinting[pal].f)) + { + kclose(filh); + initprintf("Failed loading skin file \"%s\"\n", fn); + skinfile[0] = 0; + return(0); + } else kclose(filh); + m->usesalpha = hasalpha; - //gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,xsiz,ysiz,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(char *)fptr); - if (glinfo.texcompr && glusetexcompr) intexfmt = hasalpha ? GL_COMPRESSED_RGBA_ARB : GL_COMPRESSED_RGB_ARB; - else if (!hasalpha) intexfmt = GL_RGB; - if (glinfo.bgra) texfmt = GL_BGRA; - uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype*)fptr, xsiz, ysiz, 0); - free((void*)fptr); - } + if ((doalloc&3)==1) bglGenTextures(1,(GLuint*)texidx); + bglBindTexture(GL_TEXTURE_2D,*texidx); - if (!m->skinloaded) - { - if (xsiz != osizx || ysiz != osizy) - { - float fx, fy; - fx = ((float)osizx)/((float)xsiz); - fy = ((float)osizy)/((float)ysiz); - if (m->mdnum == 2) - { - long *lptr; - for(lptr=m->glcmds;(i=*lptr++);) - for(i=labs(i);i>0;i--,lptr+=3) - { - ((float *)lptr)[0] *= fx; - ((float *)lptr)[1] *= fy; - } - } - else if (m->mdnum == 3) - { - md3model *m3 = (md3model *)m; - md3surf_t *s; - long surfi; - for (surfi=0;surfihead.numsurfs;surfi++) - { - s = &m3->head.surfs[surfi]; - for(i=s->numverts-1;i>=0;i--) - { - s->uv[i].u *= fx; - s->uv[i].v *= fy; - } - } - } - } - m->skinloaded = 1+number; - } + //gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,xsiz,ysiz,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(char *)fptr); + if (glinfo.texcompr && glusetexcompr) intexfmt = hasalpha ? GL_COMPRESSED_RGBA_ARB : GL_COMPRESSED_RGB_ARB; + else if (!hasalpha) intexfmt = GL_RGB; + if (glinfo.bgra) texfmt = GL_BGRA; + uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype*)fptr, xsiz, ysiz, 0); + free((void*)fptr); + } - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (glinfo.maxanisotropy > 1.0) - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + if (!m->skinloaded) + { + if (xsiz != osizx || ysiz != osizy) + { + float fx, fy; + fx = ((float)osizx)/((float)xsiz); + fy = ((float)osizy)/((float)ysiz); + if (m->mdnum == 2) + { + long *lptr; + for(lptr=m->glcmds;(i=*lptr++);) + for(i=labs(i);i>0;i--,lptr+=3) + { + ((float *)lptr)[0] *= fx; + ((float *)lptr)[1] *= fy; + } + } + else if (m->mdnum == 3) + { + md3model *m3 = (md3model *)m; + md3surf_t *s; + long surfi; + for (surfi=0;surfihead.numsurfs;surfi++) + { + s = &m3->head.surfs[surfi]; + for(i=s->numverts-1;i>=0;i--) + { + s->uv[i].u *= fx; + s->uv[i].v *= fy; + } + } + } + } + m->skinloaded = 1+number; + } - if (cachefil < 0) { - // save off the compressed version - cachead.xdim = osizx; - cachead.ydim = osizy; - i = 0; - for (j=0;j<31;j++) { - if (xsiz == pow2long[j]) { i |= 1; } - if (ysiz == pow2long[j]) { i |= 2; } - } - cachead.flags = (i!=3) | (hasalpha ? 2 : 0); - writexcache(fn, picfillen, 0, hictinting[pal].f, &cachead); - } - - return(*texidx); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + if (glinfo.maxanisotropy > 1.0) + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + + if (cachefil < 0) { + // save off the compressed version + cachead.xdim = osizx; + cachead.ydim = osizy; + i = 0; + for (j=0;j<31;j++) { + if (xsiz == pow2long[j]) { i |= 1; } + if (ysiz == pow2long[j]) { i |= 2; } + } + cachead.flags = (i!=3) | (hasalpha ? 2 : 0); + writexcache(fn, picfillen, 0, hictinting[pal].f, &cachead); + } + + return(*texidx); } - //Note: even though it says md2model, it works for both md2model&md3model +//Note: even though it says md2model, it works for both md2model&md3model static void updateanimation (md2model *m, spritetype *tspr) { mdanim_t *anim; @@ -815,9 +815,9 @@ static void updateanimation (md2model *m, spritetype *tspr) m->cframe = m->nframe = tile2model[tspr->picnum].framenum; for (anim = m->animations; - anim && anim->startframe != m->cframe; - anim = anim->next) ; - if (!anim) { m->interpol = 0; return; } + anim && anim->startframe != m->cframe; + anim = anim->next) ; +if (!anim) { m->interpol = 0; return; } if (((long)spriteext[tspr->owner].mdanimcur) != anim->startframe || (spriteext[tspr->owner].flags & SPREXT_NOMDANIM)) @@ -832,15 +832,15 @@ static void updateanimation (md2model *m, spritetype *tspr) i = (mdtims-spriteext[tspr->owner].mdanimtims)*anim->fpssc; j = ((anim->endframe+1-anim->startframe)<<16); - //Just in case you play the game for a VERY long time... + //Just in case you play the game for a VERY long time... if (i < 0) { i = 0; spriteext[tspr->owner].mdanimtims = mdtims; } - //compare with j*2 instead of j to ensure i stays > j-65536 for MDANIM_ONESHOT + //compare with j*2 instead of j to ensure i stays > j-65536 for MDANIM_ONESHOT if ((i >= j+j) && (anim->fpssc)) //Keep mdanimtims close to mdtims to avoid the use of MOD spriteext[tspr->owner].mdanimtims += j/anim->fpssc; if (anim->flags&MDANIM_ONESHOT) - { if (i > j-65536) i = j-65536; } - else { if (i >= j) { i -= j; if (i >= j) i %= j; } } + { if (i > j-65536) i = j-65536; } +else { if (i >= j) { i -= j; if (i >= j) i %= j; } } m->cframe = (i>>16)+anim->startframe; m->nframe = m->cframe+1; if (m->nframe > anim->endframe) m->nframe = anim->startframe; @@ -886,69 +886,69 @@ static md2model *md2load (int fil, const char *filnam) m = (md2model *)calloc(1,sizeof(md2model)); if (!m) return(0); m->mdnum = 2; m->scale = .01; - kread(fil,(char *)&head,sizeof(md2head_t)); - head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers); - head.skinxsiz = B_LITTLE32(head.skinxsiz); head.skinysiz = B_LITTLE32(head.skinysiz); - head.framebytes = B_LITTLE32(head.framebytes); head.numskins = B_LITTLE32(head.numskins); - head.numverts = B_LITTLE32(head.numverts); head.numuv = B_LITTLE32(head.numuv); - head.numtris = B_LITTLE32(head.numtris); head.numglcmds = B_LITTLE32(head.numglcmds); - head.numframes = B_LITTLE32(head.numframes); head.ofsskins = B_LITTLE32(head.ofsskins); - head.ofsuv = B_LITTLE32(head.ofsuv); head.ofstris = B_LITTLE32(head.ofstris); - head.ofsframes = B_LITTLE32(head.ofsframes); head.ofsglcmds = B_LITTLE32(head.ofsglcmds); - head.ofseof = B_LITTLE32(head.ofseof); - - if ((head.id != 0x32504449) || (head.vers != 8)) { free(m); return(0); } //"IDP2" + kread(fil,(char *)&head,sizeof(md2head_t)); + head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers); + head.skinxsiz = B_LITTLE32(head.skinxsiz); head.skinysiz = B_LITTLE32(head.skinysiz); + head.framebytes = B_LITTLE32(head.framebytes); head.numskins = B_LITTLE32(head.numskins); + head.numverts = B_LITTLE32(head.numverts); head.numuv = B_LITTLE32(head.numuv); + head.numtris = B_LITTLE32(head.numtris); head.numglcmds = B_LITTLE32(head.numglcmds); + head.numframes = B_LITTLE32(head.numframes); head.ofsskins = B_LITTLE32(head.ofsskins); + head.ofsuv = B_LITTLE32(head.ofsuv); head.ofstris = B_LITTLE32(head.ofstris); + head.ofsframes = B_LITTLE32(head.ofsframes); head.ofsglcmds = B_LITTLE32(head.ofsglcmds); + head.ofseof = B_LITTLE32(head.ofseof); - m->numskins = head.numskins; - m->numframes = head.numframes; - m->numverts = head.numverts; - m->numglcmds = head.numglcmds; - m->framebytes = head.framebytes; - m->frames = (char *)calloc(m->numframes,m->framebytes); if (!m->frames) { free(m); return(0); } - m->glcmds = (long *)calloc(m->numglcmds,sizeof(long)); if (!m->glcmds) { free(m->frames); free(m); return(0); } - klseek(fil,head.ofsframes,SEEK_SET); - if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes) - { free(m->glcmds); free(m->frames); free(m); return(0); } - klseek(fil,head.ofsglcmds,SEEK_SET); - if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(long)) != (long)(m->numglcmds*sizeof(long))) - { free(m->glcmds); free(m->frames); free(m); return(0); } +if ((head.id != 0x32504449) || (head.vers != 8)) { free(m); return(0); } //"IDP2" + + m->numskins = head.numskins; + m->numframes = head.numframes; + m->numverts = head.numverts; + m->numglcmds = head.numglcmds; + m->framebytes = head.framebytes; + m->frames = (char *)calloc(m->numframes,m->framebytes); if (!m->frames) { free(m); return(0); } + m->glcmds = (long *)calloc(m->numglcmds,sizeof(long)); if (!m->glcmds) { free(m->frames); free(m); return(0); } + klseek(fil,head.ofsframes,SEEK_SET); + if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes) + { free(m->glcmds); free(m->frames); free(m); return(0); } + klseek(fil,head.ofsglcmds,SEEK_SET); + if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(long)) != (long)(m->numglcmds*sizeof(long))) + { free(m->glcmds); free(m->frames); free(m); return(0); } #if B_BIG_ENDIAN != 0 - { - char *f = (char *)m->frames; - long *l,j; - md2frame_t *fr; - - for (i = m->numframes-1; i>=0; i--) { - fr = (md2frame_t *)f; - l = (long *)&fr->mul; - for (j=5;j>=0;j--) l[j] = B_LITTLE32(l[j]); - f += m->framebytes; - } - - for (i = m->numglcmds-1; i>=0; i--) { - m->glcmds[i] = B_LITTLE32(m->glcmds[i]); - } - } + { + char *f = (char *)m->frames; + long *l,j; + md2frame_t *fr; + + for (i = m->numframes-1; i>=0; i--) { + fr = (md2frame_t *)f; + l = (long *)&fr->mul; + for (j=5;j>=0;j--) l[j] = B_LITTLE32(l[j]); + f += m->framebytes; + } + + for (i = m->numglcmds-1; i>=0; i--) { + m->glcmds[i] = B_LITTLE32(m->glcmds[i]); + } + } #endif strcpy(st,filnam); for(i=strlen(st)-1;i>0;i--) - if ((st[i] == '/') || (st[i] == '\\')) { i++; break; } + if ((st[i] == '/') || (st[i] == '\\')) { i++; break; } if (i<0) i=0; st[i] = 0; - m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->glcmds); free(m->frames); free(m); return(0); } +m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->glcmds); free(m->frames); free(m); return(0); } strcpy(m->basepath, st); - m->skinfn = (char *)calloc(m->numskins,64); if (!m->skinfn) { free(m->basepath); free(m->glcmds); free(m->frames); free(m); return(0); } - klseek(fil,head.ofsskins,SEEK_SET); - if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins) - { free(m->glcmds); free(m->frames); free(m); return(0); } + m->skinfn = (char *)calloc(m->numskins,64); if (!m->skinfn) { free(m->basepath); free(m->glcmds); free(m->frames); free(m); return(0); } + klseek(fil,head.ofsskins,SEEK_SET); + if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins) + { free(m->glcmds); free(m->frames); free(m); return(0); } - m->texid = (GLuint *)calloc(m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1)); - if (!m->texid) { free(m->skinfn); free(m->basepath); free(m->glcmds); free(m->frames); free(m); return(0); } + m->texid = (GLuint *)calloc(m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1)); + if (!m->texid) { free(m->skinfn); free(m->basepath); free(m->glcmds); free(m->frames); free(m); return(0); } - maxmodelverts = max(maxmodelverts, m->numverts); + maxmodelverts = max(maxmodelverts, m->numverts); return(m); } @@ -961,13 +961,13 @@ static int md2draw (md2model *m, spritetype *tspr) long i, *lptr; float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4]; -// if ((tspr->cstat&48) == 32) return 0; + // if ((tspr->cstat&48) == 32) return 0; updateanimation(m,tspr); -// -------- Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 --------- + // -------- Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 --------- - //create current&next frame's vertex list from whole list + //create current&next frame's vertex list from whole list f0 = (md2frame_t *)&m->frames[m->cframe*m->framebytes]; f1 = (md2frame_t *)&m->frames[m->nframe*m->framebytes]; f = m->interpol; g = 1-f; @@ -979,39 +979,39 @@ static int md2draw (md2model *m, spritetype *tspr) a0.z = f0->add.z*m->scale; a0.z = (f1->add.z*m->scale-a0.z)*f+a0.z + m->zadd*m->scale; c0 = &f0->verts[0].v[0]; c1 = &f1->verts[0].v[0]; - // Parkar: Moved up to be able to use k0 for the y-flipping code - k0 = tspr->z; - if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1); - - // Parkar: Changed to use the same method as centeroriented sprites - if (globalorientation&8) //y-flipping - { - m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; - k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<2); - } - if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping + // Parkar: Moved up to be able to use k0 for the y-flipping code + k0 = tspr->z; + if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1); + + // Parkar: Changed to use the same method as centeroriented sprites + if (globalorientation&8) //y-flipping + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<2); + } + if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping f = ((float)tspr->xrepeat)/64*m->bscale; m0.x *= f; m1.x *= f; a0.x *= f; f = -f; // 20040610: backwards models aren't cool m0.y *= f; m1.y *= f; a0.y *= f; f = ((float)tspr->yrepeat)/64*m->bscale; m0.z *= f; m1.z *= f; a0.z *= f; - - // floor aligned - k1 = tspr->y; - if((globalorientation&48)==32) - { - m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; - m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; - f = a0.x; a0.x = a0.z; a0.z = f; - k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3); - } - f = (65536.0*512.0)/((float)xdimen*viewingrange); - g = 32.0/((float)xdimen*gxyaspect); - m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f; - m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f; - m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g; + // floor aligned + k1 = tspr->y; + if((globalorientation&48)==32) + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; + f = a0.x; a0.x = a0.z; a0.z = f; + k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3); + } + + f = (65536.0*512.0)/((float)xdimen*viewingrange); + g = 32.0/((float)xdimen*gxyaspect); + m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f; + m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f; + m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g; k0 = ((float)(tspr->x-globalposx))*f/1024.0; k1 = ((float)(tspr->y-globalposy))*f/1024.0; @@ -1027,39 +1027,39 @@ static int md2draw (md2model *m, spritetype *tspr) mat[1] = k4*k6 + k5*k7; mat[5] = gchang*gctang; mat[ 9] = k4*k7 - k5*k6; mat[13] = k2*k6 + k3*k7; k6 = gcosang2*gchang; k7 = gsinang2*gchang; mat[2] = k4*k6 + k5*k7; mat[6] =-gshang; mat[10] = k4*k7 - k5*k6; mat[14] = k2*k6 + k3*k7; - + mat[12] += a0.y*mat[0] + a0.z*mat[4] + a0.x*mat[ 8]; mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9]; mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10]; - - // floor aligned - if((globalorientation&48)==32) - { + + // floor aligned + if((globalorientation&48)==32) + { f = mat[4]; mat[4] = mat[8]*16.0; mat[8] = -f*(1.0/16.0); f = mat[5]; mat[5] = mat[9]*16.0; mat[9] = -f*(1.0/16.0); f = mat[6]; mat[6] = mat[10]*16.0; mat[10] = -f*(1.0/16.0); } - - //Mirrors + + //Mirrors if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } -// ------ Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 ends ------ + // ------ Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 ends ------ -// PLAG: Cleaner model rotation code + // PLAG: Cleaner model rotation code if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll) { - if (spriteext[tspr->owner].xoff) - a0.x = (int)(spriteext[tspr->owner].xoff / (2048 * (m0.x+m1.x))); - else - a0.x = 0; - if (spriteext[tspr->owner].yoff) - a0.y = (int)(spriteext[tspr->owner].yoff / (2048 * (m0.y+m1.y))); - else - a0.y = 0; - if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024)) - a0.z = (int)(spriteext[tspr->owner].zoff / (524288 * (m0.z+m1.z))); - else - a0.z = 0; + if (spriteext[tspr->owner].xoff) + a0.x = (int)(spriteext[tspr->owner].xoff / (2048 * (m0.x+m1.x))); + else + a0.x = 0; + if (spriteext[tspr->owner].yoff) + a0.y = (int)(spriteext[tspr->owner].yoff / (2048 * (m0.y+m1.y))); + else + a0.y = 0; + if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024)) + a0.z = (int)(spriteext[tspr->owner].zoff / (524288 * (m0.z+m1.z))); + else + a0.z = 0; k0 = (float)sintable[(spriteext[tspr->owner].pitch+512)&2047] / 16384.0; k1 = (float)sintable[spriteext[tspr->owner].pitch&2047] / 16384.0; k2 = (float)sintable[(spriteext[tspr->owner].roll+512)&2047] / 16384.0; @@ -1069,35 +1069,35 @@ static int md2draw (md2model *m, spritetype *tspr) { if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll) { - fp.z = c0[(i<<2)+0] + a0.x; - fp.x = c0[(i<<2)+1] + a0.y; - fp.y = c0[(i<<2)+2] + a0.z; - fp1.x = fp.x*k2 + fp.y*k3; - fp1.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); - fp1.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; - fp.z = c1[(i<<2)+0] + a0.x; - fp.x = c1[(i<<2)+1] + a0.y; - fp2.y = c1[(i<<2)+2] + a0.z; - fp2.x = fp.x*k2 + fp.y*k3; - fp2.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); - fp2.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; + fp.z = c0[(i<<2)+0] + a0.x; + fp.x = c0[(i<<2)+1] + a0.y; + fp.y = c0[(i<<2)+2] + a0.z; + fp1.x = fp.x*k2 + fp.y*k3; + fp1.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); + fp1.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; + fp.z = c1[(i<<2)+0] + a0.x; + fp.x = c1[(i<<2)+1] + a0.y; + fp2.y = c1[(i<<2)+2] + a0.z; + fp2.x = fp.x*k2 + fp.y*k3; + fp2.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); + fp2.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; fp.z = (fp1.z - a0.x)*m0.x + (fp2.z - a0.x)*m1.x; fp.x = (fp1.x - a0.y)*m0.y + (fp2.x - a0.y)*m1.y; fp.y = (fp1.y - a0.z)*m0.z + (fp2.y - a0.z)*m1.z; } else { - fp.z = c0[(i<<2)+0]*m0.x + c1[(i<<2)+0]*m1.x; - fp.y = c0[(i<<2)+2]*m0.z + c1[(i<<2)+2]*m1.z; - fp.x = c0[(i<<2)+1]*m0.y + c1[(i<<2)+1]*m1.y; + fp.z = c0[(i<<2)+0]*m0.x + c1[(i<<2)+0]*m1.x; + fp.y = c0[(i<<2)+2]*m0.z + c1[(i<<2)+2]*m1.z; + fp.x = c0[(i<<2)+1]*m0.y + c1[(i<<2)+1]*m1.y; } vertlist[i].x = fp.x; vertlist[i].y = fp.y; vertlist[i].z = fp.z; } - bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation - mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); -// PLAG: End + bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation + mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); + // PLAG: End i = mdloadskin(m,tile2model[tspr->picnum].skinnum,globalpal,0); if (!i) return 0; @@ -1120,11 +1120,11 @@ static int md2draw (md2model *m, spritetype *tspr) pc[0] *= (float)hictinting[globalpal].r / 255.0; pc[1] *= (float)hictinting[globalpal].g / 255.0; pc[2] *= (float)hictinting[globalpal].b / 255.0; - if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; +if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; if (m->usesalpha) //Sprites with alpha in texture { -// bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); -// bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32); + // bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + // bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32); float al = 0.32; if (alphahackarray[globalpicnum] != 0) al=alphahackarray[globalpicnum]; @@ -1141,7 +1141,7 @@ static int md2draw (md2model *m, spritetype *tspr) for(lptr=m->glcmds;(i=*lptr++);) { if (i < 0) { bglBegin(GL_TRIANGLE_FAN); i = -i; } - else { bglBegin(GL_TRIANGLE_STRIP); } + else { bglBegin(GL_TRIANGLE_STRIP); } for(;i>0;i--,lptr+=3) { bglTexCoord2f(((float *)lptr)[0],((float *)lptr)[1]); @@ -1210,23 +1210,23 @@ void quicksort(unsigned short *indexes, float *depths, int first, int last) { static md3model *md3load (int fil) { - char *buf, st[BMAX_PATH+2], bst[BMAX_PATH+2]; - long i, j, surfi, ofsurf, bsc, offs[4], leng[4]; - md3model *m; - md3surf_t *s; + char *buf, st[BMAX_PATH+2], bst[BMAX_PATH+2]; + long i, j, surfi, ofsurf, bsc, offs[4], leng[4]; + md3model *m; + md3surf_t *s; m = (md3model *)calloc(1,sizeof(md3model)); if (!m) return(0); m->mdnum = 3; m->texid = 0; m->scale = .01; - kread(fil,&m->head,sizeof(md3head_t)); - m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers); - m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes); - m->head.numtags = B_LITTLE32(m->head.numtags); m->head.numsurfs = B_LITTLE32(m->head.numsurfs); - m->head.numskins = B_LITTLE32(m->head.numskins); m->head.frames = (md3frame_t*)B_LITTLE32((long)m->head.frames); - m->head.tags = (md3tag_t*)B_LITTLE32((long)m->head.tags); m->head.surfs = (md3surf_t*)B_LITTLE32((long)m->head.surfs); - m->head.eof = B_LITTLE32(m->head.eof); - - if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { free(m); return(0); } //"IDP3" + kread(fil,&m->head,sizeof(md3head_t)); + m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers); + m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes); + m->head.numtags = B_LITTLE32(m->head.numtags); m->head.numsurfs = B_LITTLE32(m->head.numsurfs); + m->head.numskins = B_LITTLE32(m->head.numskins); m->head.frames = (md3frame_t*)B_LITTLE32((long)m->head.frames); + m->head.tags = (md3tag_t*)B_LITTLE32((long)m->head.tags); m->head.surfs = (md3surf_t*)B_LITTLE32((long)m->head.surfs); + m->head.eof = B_LITTLE32(m->head.eof); + +if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { free(m); return(0); } //"IDP3" m->numskins = m->head.numskins; //<- dead code? m->numframes = m->head.numframes; @@ -1248,39 +1248,39 @@ static md3model *md3load (int fil) m->head.surfs = (md3surf_t *)malloc(i); if (!m->head.surfs) { if (m->head.tags) free(m->head.tags); free(m->head.frames); free(m); return(0); } #if B_BIG_ENDIAN != 0 - { - long *l; - - for (i = m->head.numframes-1; i>=0; i--) { - l = (long *)&m->head.frames[i].min; - for (j=3+3+3+1-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); - } - - for (i = m->head.numtags-1; i>=0; i--) { - l = (long *)&m->head.tags[i].p; - for (j=3+3+3+3-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); - } - } + { + long *l; + + for (i = m->head.numframes-1; i>=0; i--) { + l = (long *)&m->head.frames[i].min; + for (j=3+3+3+1-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); + } + + for (i = m->head.numtags-1; i>=0; i--) { + l = (long *)&m->head.tags[i].p; + for (j=3+3+3+3-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); + } + } #endif - for(surfi=0;surfihead.numsurfs;surfi++) - { - s = &m->head.surfs[surfi]; - klseek(fil,ofsurf,SEEK_SET); kread(fil,s,sizeof(md3surf_t)); + for(surfi=0;surfihead.numsurfs;surfi++) + { + s = &m->head.surfs[surfi]; + klseek(fil,ofsurf,SEEK_SET); kread(fil,s,sizeof(md3surf_t)); #if B_BIG_ENDIAN != 0 - { - long *l; - s->id = B_LITTLE32(s->id); - l = (long *)&s->flags; - for (j=1+1+1+1+1+1+1+1+1+1-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); - } + { + long *l; + s->id = B_LITTLE32(s->id); + l = (long *)&s->flags; + for (j=1+1+1+1+1+1+1+1+1+1-1;j>=0;j--) l[j] = B_LITTLE32(l[j]); + } #endif - offs[0] = ofsurf+((long)(s->tris )); leng[0] = s->numtris*sizeof(md3tri_t); - offs[1] = ofsurf+((long)(s->shaders)); leng[1] = s->numshaders*sizeof(md3shader_t); - offs[2] = ofsurf+((long)(s->uv )); leng[2] = s->numverts*sizeof(md3uv_t); - offs[3] = ofsurf+((long)(s->xyzn )); leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t); + offs[0] = ofsurf+((long)(s->tris )); leng[0] = s->numtris*sizeof(md3tri_t); + offs[1] = ofsurf+((long)(s->shaders)); leng[1] = s->numshaders*sizeof(md3shader_t); + offs[2] = ofsurf+((long)(s->uv )); leng[2] = s->numverts*sizeof(md3uv_t); + offs[3] = ofsurf+((long)(s->xyzn )); leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t); s->tris = (md3tri_t *)malloc(leng[0]+leng[1]+leng[2]+leng[3]); if (!s->tris) @@ -1298,30 +1298,30 @@ static md3model *md3load (int fil) klseek(fil,offs[3],SEEK_SET); kread(fil,s->xyzn ,leng[3]); #if B_BIG_ENDIAN != 0 - { - long *l; - - for (i=s->numtris-1;i>=0;i--) { - for (j=2;j>=0;j--) s->tris[i].i[j] = B_LITTLE32(s->tris[i].i[j]); - } - for (i=s->numshaders-1;i>=0;i--) { - s->shaders[i].i = B_LITTLE32(s->shaders[i].i); - } - for (i=s->numverts-1;i>=0;i--) { - l = (long*)&s->uv[i].u; - l[0] = B_LITTLE32(l[0]); - l[1] = B_LITTLE32(l[1]); - } - for (i=s->numframes*s->numverts-1;i>=0;i--) { - s->xyzn[i].x = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].x); - s->xyzn[i].y = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].y); - s->xyzn[i].z = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].z); - } - } + { + long *l; + + for (i=s->numtris-1;i>=0;i--) { + for (j=2;j>=0;j--) s->tris[i].i[j] = B_LITTLE32(s->tris[i].i[j]); + } + for (i=s->numshaders-1;i>=0;i--) { + s->shaders[i].i = B_LITTLE32(s->shaders[i].i); + } + for (i=s->numverts-1;i>=0;i--) { + l = (long*)&s->uv[i].u; + l[0] = B_LITTLE32(l[0]); + l[1] = B_LITTLE32(l[1]); + } + for (i=s->numframes*s->numverts-1;i>=0;i--) { + s->xyzn[i].x = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].x); + s->xyzn[i].y = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].y); + s->xyzn[i].z = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].z); + } + } #endif - maxmodelverts = max(maxmodelverts, s->numverts); - ofsurf += s->ofsend; - } + maxmodelverts = max(maxmodelverts, s->numverts); + ofsurf += s->ofsend; + } #if 0 strcpy(st,filnam); @@ -1334,11 +1334,11 @@ static md3model *md3load (int fil) for(i=0,j=0;st[i];i++) if (st[i] == '.') j = i+1; if ((!stricmp(&st[j],"JPG")) || (!stricmp(&st[j],"PNG")) || (!stricmp(&st[j],"GIF")) || - (!stricmp(&st[j],"PCX")) || (!stricmp(&st[j],"TGA")) || (!stricmp(&st[j],"BMP")) || - (!stricmp(&st[j],"CEL"))) + (!stricmp(&st[j],"PCX")) || (!stricmp(&st[j],"TGA")) || (!stricmp(&st[j],"BMP")) || + (!stricmp(&st[j],"CEL"))) { for(i=0;st[i];i++) if (st[i] != filnam[i]) break; - if (i > bsc) { bsc = i; strcpy(bst,st); } + if (i > bsc) { bsc = i; strcpy(bst,st); } } } if (!mdloadskin(&m->texid,&m->usesalpha,bst)) ;//bad! @@ -1349,38 +1349,38 @@ static md3model *md3load (int fil) static int md3draw (md3model *m, spritetype *tspr) { - point3d fp, fp1, fp2, m0, m1, a0, a1; - md3xyzn_t *v0, *v1; - long i, j, k, surfi, *lptr; - float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4]; - md3surf_t *s; - //PLAG : sorting stuff - unsigned short *indexes; - float *maxdepths; - unsigned short tempus; + point3d fp, fp1, fp2, m0, m1, a0, a1; + md3xyzn_t *v0, *v1; + long i, j, k, surfi, *lptr; + float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4]; + md3surf_t *s; + //PLAG : sorting stuff + unsigned short *indexes; + float *maxdepths; + unsigned short tempus; -// if ((tspr->cstat&48) == 32) return 0; + // if ((tspr->cstat&48) == 32) return 0; updateanimation((md2model *)m,tspr); - //create current&next frame's vertex list from whole list + //create current&next frame's vertex list from whole list - f = m->interpol; g = 1-f; - m0.x = (1.0/64.0)*m->scale*g; m1.x = (1.0/64.0)*m->scale*f; - m0.y = (1.0/64.0)*m->scale*g; m1.y = (1.0/64.0)*m->scale*f; - m0.z = (1.0/64.0)*m->scale*g; m1.z = (1.0/64.0)*m->scale*f; - a0.x = a0.y = 0; a0.z = m->zadd*m->scale; + f = m->interpol; g = 1-f; + m0.x = (1.0/64.0)*m->scale*g; m1.x = (1.0/64.0)*m->scale*f; + m0.y = (1.0/64.0)*m->scale*g; m1.y = (1.0/64.0)*m->scale*f; + m0.z = (1.0/64.0)*m->scale*g; m1.z = (1.0/64.0)*m->scale*f; + a0.x = a0.y = 0; a0.z = m->zadd*m->scale; // Parkar: Moved up to be able to use k0 for the y-flipping code - k0 = tspr->z; - if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1); + k0 = tspr->z; + if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1); // Parkar: Changed to use the same method as centeroriented sprites - if (globalorientation&8) //y-flipping - { - m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; - k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<2); + if (globalorientation&8) //y-flipping + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<2); } if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping @@ -1389,22 +1389,22 @@ static int md3draw (md3model *m, spritetype *tspr) m0.y *= f; m1.y *= f; a0.y *= f; f = ((float)tspr->yrepeat)/64*m->bscale; m0.z *= f; m1.z *= f; a0.z *= f; - - // floor aligned - k1 = tspr->y; - if((globalorientation&48)==32) - { - m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; - m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; - f = a0.x; a0.x = a0.z; a0.z = f; - k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3); - } - f = (65536.0*512.0)/((float)xdimen*viewingrange); - g = 32.0/((float)xdimen*gxyaspect); - m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f; - m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f; - m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g; + // floor aligned + k1 = tspr->y; + if((globalorientation&48)==32) + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; + f = a0.x; a0.x = a0.z; a0.z = f; + k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3); + } + + f = (65536.0*512.0)/((float)xdimen*viewingrange); + g = 32.0/((float)xdimen*gxyaspect); + m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f; + m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f; + m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g; k0 = ((float)(tspr->x-globalposx))*f/1024.0; k1 = ((float)(tspr->y-globalposy))*f/1024.0; @@ -1425,18 +1425,18 @@ static int md3draw (md3model *m, spritetype *tspr) mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9]; mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10]; - // floor aligned - if((globalorientation&48)==32) - { - f = mat[4]; mat[4] = mat[8]*16.0; mat[8] = -f*(1.0/16.0); - f = mat[5]; mat[5] = mat[9]*16.0; mat[9] = -f*(1.0/16.0); - f = mat[6]; mat[6] = mat[10]*16.0; mat[10] = -f*(1.0/16.0); - } - - //Mirrors - if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } - -//------------ + // floor aligned + if((globalorientation&48)==32) + { + f = mat[4]; mat[4] = mat[8]*16.0; mat[8] = -f*(1.0/16.0); + f = mat[5]; mat[5] = mat[9]*16.0; mat[9] = -f*(1.0/16.0); + f = mat[6]; mat[6] = mat[10]*16.0; mat[10] = -f*(1.0/16.0); + } + + //Mirrors + if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } + + //------------ //bit 10 is an ugly hack in game.c\animatesprites telling MD2SPRITE //to use Z-buffer hacks to hide overdraw problems with the shadows if (tspr->cstat&1024) @@ -1455,14 +1455,14 @@ static int md3draw (md3model *m, spritetype *tspr) pc[0] *= (float)hictinting[globalpal].r / 255.0; pc[1] *= (float)hictinting[globalpal].g / 255.0; pc[2] *= (float)hictinting[globalpal].b / 255.0; - if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; +if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; if (m->usesalpha) //Sprites with alpha in texture { -// bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); -// bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32); -// float al = 0.32; + // bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + // bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32); + // float al = 0.32; // PLAG : default cutoff removed - float al = 0.0; + float al = 0.0; if (alphahackarray[globalpicnum] != 0) al=alphahackarray[globalpicnum]; bglEnable(GL_BLEND); @@ -1474,23 +1474,23 @@ static int md3draw (md3model *m, spritetype *tspr) if (tspr->cstat&2) bglEnable(GL_BLEND); else bglDisable(GL_BLEND); } bglColor4f(pc[0],pc[1],pc[2],pc[3]); -//------------ + //------------ -// PLAG: Cleaner model rotation code + // PLAG: Cleaner model rotation code if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll) { - if (spriteext[tspr->owner].xoff) - a0.x = (int)(spriteext[tspr->owner].xoff / (2048 * (m0.x+m1.x))); - else - a0.x = 0; - if (spriteext[tspr->owner].yoff) - a0.y = (int)(spriteext[tspr->owner].yoff / (2048 * (m0.x+m1.x))); - else - a0.y = 0; - if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024)) - a0.z = (int)(spriteext[tspr->owner].zoff / (524288 * (m0.z+m1.z))); - else - a0.z = 0; + if (spriteext[tspr->owner].xoff) + a0.x = (int)(spriteext[tspr->owner].xoff / (2048 * (m0.x+m1.x))); + else + a0.x = 0; + if (spriteext[tspr->owner].yoff) + a0.y = (int)(spriteext[tspr->owner].yoff / (2048 * (m0.x+m1.x))); + else + a0.y = 0; + if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024)) + a0.z = (int)(spriteext[tspr->owner].zoff / (524288 * (m0.z+m1.z))); + else + a0.z = 0; k0 = (float)sintable[(spriteext[tspr->owner].pitch+512)&2047] / 16384.0; k1 = (float)sintable[spriteext[tspr->owner].pitch&2047] / 16384.0; k2 = (float)sintable[(spriteext[tspr->owner].roll+512)&2047] / 16384.0; @@ -1534,18 +1534,18 @@ static int md3draw (md3model *m, spritetype *tspr) } bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); -// PLAG: End + // PLAG: End i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,globalpal,surfi); if (!i) continue; //i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,surfi); //hack for testing multiple surfaces per MD3 bglBindTexture(GL_TEXTURE_2D, i); -//PLAG: delayed polygon-level sorted rendering + //PLAG: delayed polygon-level sorted rendering if (m->usesalpha && !(tspr->cstat & 1024)) { indexes = malloc(sizeof(unsigned short) * s->numtris); maxdepths = malloc(sizeof(float) * s->numtris); - + // old sorting methods - dead code /*for(i=s->numtris-1;i>=0;i--) { @@ -1557,7 +1557,7 @@ static int md3draw (md3model *m, spritetype *tspr) maxdepths[i] = tempf; indexes[i] = i; } - + for(i=s->numtris-1;i>=0;i--) { tempf = (vertlist[s->tris[i].i[0]].x * mat[2]) + (vertlist[s->tris[i].i[0]].y * mat[6]) + (vertlist[s->tris[i].i[0]].z * mat[10]) + mat[14]; @@ -1567,7 +1567,7 @@ static int md3draw (md3model *m, spritetype *tspr) maxdepths[i] = tempf; indexes[i] = i; } - + for(i=s->numtris-1;i>=0;i--) { tempvec[0].x = (vertlist[s->tris[i].i[0]].x * mat[0]) + (vertlist[s->tris[i].i[0]].y * mat[4]) + (vertlist[s->tris[i].i[0]].z * mat[8]) + mat[12]; @@ -1589,24 +1589,24 @@ static int md3draw (md3model *m, spritetype *tspr) maxdepths[i] = tempf; indexes[i] = i; }*/ - + for(i=s->numtris-1;i>=0;i--) { // Matrix multiplication - ugly but clear fp.x = (vertlist[s->tris[i].i[0]].x * mat[0]) + (vertlist[s->tris[i].i[0]].y * mat[4]) + (vertlist[s->tris[i].i[0]].z * mat[8]) + mat[12]; fp.y = (vertlist[s->tris[i].i[0]].x * mat[1]) + (vertlist[s->tris[i].i[0]].y * mat[5]) + (vertlist[s->tris[i].i[0]].z * mat[9]) + mat[13]; fp.z = (vertlist[s->tris[i].i[0]].x * mat[2]) + (vertlist[s->tris[i].i[0]].y * mat[6]) + (vertlist[s->tris[i].i[0]].z * mat[10]) + mat[14]; - + fp1.x = (vertlist[s->tris[i].i[1]].x * mat[0]) + (vertlist[s->tris[i].i[1]].y * mat[4]) + (vertlist[s->tris[i].i[1]].z * mat[8]) + mat[12]; fp1.y = (vertlist[s->tris[i].i[1]].x * mat[1]) + (vertlist[s->tris[i].i[1]].y * mat[5]) + (vertlist[s->tris[i].i[1]].z * mat[9]) + mat[13]; fp1.z = (vertlist[s->tris[i].i[1]].x * mat[2]) + (vertlist[s->tris[i].i[1]].y * mat[6]) + (vertlist[s->tris[i].i[1]].z * mat[10]) + mat[14]; - + fp2.x = (vertlist[s->tris[i].i[2]].x * mat[0]) + (vertlist[s->tris[i].i[2]].y * mat[4]) + (vertlist[s->tris[i].i[2]].z * mat[8]) + mat[12]; fp2.y = (vertlist[s->tris[i].i[2]].x * mat[1]) + (vertlist[s->tris[i].i[2]].y * mat[5]) + (vertlist[s->tris[i].i[2]].z * mat[9]) + mat[13]; fp2.z = (vertlist[s->tris[i].i[2]].x * mat[2]) + (vertlist[s->tris[i].i[2]].y * mat[6]) + (vertlist[s->tris[i].i[2]].z * mat[10]) + mat[14]; f = (fp.x * fp.x) + (fp.y * fp.y) + (fp.z * fp.z); - + g = (fp1.x * fp1.x) + (fp1.y * fp1.y) + (fp1.z * fp1.z); if (f > g) f = g; @@ -1617,7 +1617,7 @@ static int md3draw (md3model *m, spritetype *tspr) maxdepths[i] = f; indexes[i] = i; } - + //bubble sort - dead code /*test = 0; j = 0; @@ -1637,7 +1637,7 @@ static int md3draw (md3model *m, spritetype *tspr) j = 0; } }*/ - + // dichotomic recursive sorting - about 100x less iterations than bubblesort quicksort(indexes, maxdepths, 0, s->numtris - 1); @@ -1650,7 +1650,7 @@ static int md3draw (md3model *m, spritetype *tspr) bglVertex3fv((float *)&vertlist[k]); } bglEnd(); - + free(indexes); free(maxdepths); } @@ -1667,8 +1667,8 @@ static int md3draw (md3model *m, spritetype *tspr) bglEnd(); } } -//------------ - + //------------ + if (m->usesalpha) bglDisable(GL_ALPHA_TEST); bglDisable(GL_CULL_FACE); bglPopAttrib(); @@ -1723,7 +1723,7 @@ static void md3free (md3model *m) //---------------------------------------- MD3 LIBRARY ENDS ---------------------------------------- //--------------------------------------- VOX LIBRARY BEGINS --------------------------------------- - //For loading/conversion only +//For loading/conversion only static long xsiz, ysiz, zsiz, yzsiz, *vbit = 0; //vbit: 1 bit per voxel: 0=air,1=solid static float xpiv, ypiv, zpiv; //Might want to use more complex/unique names! static long *vcolhashead = 0, vcolhashsizm1; @@ -1735,7 +1735,7 @@ static long *shcntmal, *shcnt = 0, shcntp; static long mytexo5, *zbit, gmaxx, gmaxy, garea, pow2m1[33]; static voxmodel *gvox; - //pitch must equal xsiz*4 +//pitch must equal xsiz*4 unsigned gloadtex (long *picbuf, long xsiz, long ysiz, long is8bit, long dapal) { unsigned rtexid; @@ -1743,30 +1743,30 @@ unsigned gloadtex (long *picbuf, long xsiz, long ysiz, long is8bit, long dapal) unsigned char *cptr; long i; - pic = (coltype *)picbuf; //Correct for GL's RGB order; also apply gamma here.. - pic2 = (coltype *)malloc(xsiz*ysiz*sizeof(long)); if (!pic2) return((unsigned)-1); - cptr = (unsigned char*)&britable[gammabrightness ? 0 : curbrightness][0]; - if (!is8bit) - { - for(i=xsiz*ysiz-1;i>=0;i--) - { - pic2[i].b = cptr[pic[i].r]; - pic2[i].g = cptr[pic[i].g]; - pic2[i].r = cptr[pic[i].b]; - pic2[i].a = 255; - } - } - else - { - if (palookup[dapal] == 0) dapal = 0; - for(i=xsiz*ysiz-1;i>=0;i--) - { - pic2[i].b = cptr[palette[(long)palookup[dapal][pic[i].a]*3+2]*4]; - pic2[i].g = cptr[palette[(long)palookup[dapal][pic[i].a]*3+1]*4]; - pic2[i].r = cptr[palette[(long)palookup[dapal][pic[i].a]*3+0]*4]; - pic2[i].a = 255; - } - } + pic = (coltype *)picbuf; //Correct for GL's RGB order; also apply gamma here.. + pic2 = (coltype *)malloc(xsiz*ysiz*sizeof(long)); if (!pic2) return((unsigned)-1); + cptr = (unsigned char*)&britable[gammabrightness ? 0 : curbrightness][0]; + if (!is8bit) + { + for(i=xsiz*ysiz-1;i>=0;i--) + { + pic2[i].b = cptr[pic[i].r]; + pic2[i].g = cptr[pic[i].g]; + pic2[i].r = cptr[pic[i].b]; + pic2[i].a = 255; + } + } + else + { + if (palookup[dapal] == 0) dapal = 0; + for(i=xsiz*ysiz-1;i>=0;i--) + { + pic2[i].b = cptr[palette[(long)palookup[dapal][pic[i].a]*3+2]*4]; + pic2[i].g = cptr[palette[(long)palookup[dapal][pic[i].a]*3+1]*4]; + pic2[i].r = cptr[palette[(long)palookup[dapal][pic[i].a]*3+0]*4]; + pic2[i].a = 255; + } + } bglGenTextures(1,(GLuint*)&rtexid); bglBindTexture(GL_TEXTURE_2D,rtexid); @@ -1795,33 +1795,33 @@ static void putvox (long x, long y, long z, long col) vcol[vnum].n = vcolhashead[z]; vcolhashead[z] = vnum++; } - //Set all bits in vbit from (x,y,z0) to (x,y,z1-1) to 0's +//Set all bits in vbit from (x,y,z0) to (x,y,z1-1) to 0's static void setzrange0 (long *lptr, long z0, long z1) { - long z, ze; - if (!((z0^z1)&~31)) { lptr[z0>>5] &= ((~(-1<>5); ze = (z1>>5); - lptr[z] &=~(-1<>5] &= ((~(-1<>5); ze = (z1>>5); + lptr[z] &=~(-1<>5] |= ((~(-1<>5); ze = (z1>>5); - lptr[z] |= (-1<>5] |= ((~(-1<>5); ze = (z1>>5); + lptr[z] |= (-1<mytexx + x0; - for(dy=0;dy;dy--,i+=gvox->mytexx) - for(x=0;x>5]&(1<mytexx + x0; + for(dy=0;dy;dy--,i+=gvox->mytexx) + for(x=0;x>5]&(1<mytexx + x0; - for(y=0;ymytexx) - for(x=0;x>5] |= (1<mytexx + x0; + for(y=0;ymytexx) + for(x=0;x>5] |= (1< gmaxx) gmaxx = x; if (y > gmaxy) gmaxy = y; @@ -1885,55 +1885,55 @@ static void addquad (long x0, long y0, long z0, long x1, long y1, long z1, long x = labs(x2-x0); y = labs(y2-y0); z = labs(z2-z0); if (!x) { x = y; y = z; i = 0; } else if (!y) { y = z; i = 1; } else i = 2; - if (x < y) { z = x; x = y; y = z; i += 3; } +if (x < y) { z = x; x = y; y = z; i += 3; } z = shcnt[y*shcntp+x]++; lptr = &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+(shp[z].x+VOXBORDWIDTH)]; switch(face) { - case 0: ny = y1; x2 = x0; x0 = x1; x1 = x2; break; - case 1: ny = y0; y0++; y1++; y2++; break; - case 2: nz = z1; y0 = y2; y2 = y1; y1 = y0; z0++; z1++; z2++; break; - case 3: nz = z0; break; - case 4: nx = x1; y2 = y0; y0 = y1; y1 = y2; x0++; x1++; x2++; break; - case 5: nx = x0; break; + case 0: ny = y1; x2 = x0; x0 = x1; x1 = x2; break; + case 1: ny = y0; y0++; y1++; y2++; break; + case 2: nz = z1; y0 = y2; y2 = y1; y1 = y0; z0++; z1++; z2++; break; + case 3: nz = z0; break; + case 4: nx = x1; y2 = y0; y0 = y1; y1 = y2; x0++; x1++; x2++; break; + case 5: nx = x0; break; } for(yy=0;yymytexx) for(xx=0;xxmytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x]; lptr[xx] = lptr[VOXBORDWIDTH]; lptr[xx+x+VOXBORDWIDTH] = lptr[x-1+VOXBORDWIDTH]; } - //Extend borders vertically + //Extend borders vertically 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); memcpy(&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]; @@ -1956,10 +1956,10 @@ static void addquad (long x0, long y0, long z0, long x1, long y1, long z1, long static long isolid (long x, long y, long z) { - if ((unsigned long)x >= (unsigned long)xsiz) return(0); - if ((unsigned long)y >= (unsigned long)ysiz) return(0); - if ((unsigned long)z >= (unsigned long)zsiz) return(0); - z += x*yzsiz + y*zsiz; return(vbit[z>>5]&(1<= (unsigned long)xsiz) return(0); + if ((unsigned long)y >= (unsigned long)ysiz) return(0); + if ((unsigned long)z >= (unsigned long)zsiz) return(0); + z += x*yzsiz + y*zsiz; return(vbit[z>>5]&(1<qfacind[i] = -1; i = ((max(ysiz,zsiz)+1)<<2); - bx0 = (long *)malloc(i<<1); if (!bx0) { free(gvox); return(0); } +bx0 = (long *)malloc(i<<1); if (!bx0) { free(gvox); return(0); } by0 = (long *)(((long)bx0)+i); for(cnt=0;cnt<2;cnt++) { if (!cnt) daquad = cntquad; - else daquad = addquad; + else daquad = addquad; gvox->qcnt = 0; memset(by0,-1,(max(ysiz,zsiz)+1)<<2); v = 0; @@ -2003,7 +2003,7 @@ static voxmodel *vox2poly () { ov = v; v = (isolid(x,y,z) && (!isolid(x,y+i,z))); if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov))) - { daquad(bx0[z],y,by0[z],x,y,by0[z],x,y,z,i>=0); by0[z] = -1; } + { daquad(bx0[z],y,by0[z],x,y,by0[z],x,y,z,i>=0); by0[z] = -1; } if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = x; by0[z] = oz; } } @@ -2014,7 +2014,7 @@ static voxmodel *vox2poly () { ov = v; v = (isolid(x,y,z) && (!isolid(x,y,z-i))); if ((by0[y] >= 0) && ((by0[y] != oz) || (v >= ov))) - { daquad(bx0[y],by0[y],z,x,by0[y],z,x,y,z,(i>=0)+2); by0[y] = -1; } + { daquad(bx0[y],by0[y],z,x,by0[y],z,x,y,z,(i>=0)+2); by0[y] = -1; } if (v > ov) oz = y; else if ((v < ov) && (by0[y] != oz)) { bx0[y] = x; by0[y] = oz; } } @@ -2025,7 +2025,7 @@ static voxmodel *vox2poly () { ov = v; v = (isolid(x,y,z) && (!isolid(x-i,y,z))); if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov))) - { daquad(x,bx0[z],by0[z],x,y,by0[z],x,y,z,(i>=0)+4); by0[z] = -1; } + { daquad(x,bx0[z],by0[z],x,y,by0[z],x,y,z,(i>=0)+4); by0[z] = -1; } if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = y; by0[z] = oz; } } @@ -2052,7 +2052,7 @@ skindidntfit:; mytexo5 = (gvox->mytexx>>5); i = (((gvox->mytexx*gvox->mytexy+31)>>5)<<2); - zbit = (long *)malloc(i); if (!zbit) { free(bx0); free(gvox); free(shp); return(0); } + zbit = (long *)malloc(i); if (!zbit) { free(bx0); free(gvox); free(shp); return(0); } memset(zbit,0,i); v = gvox->mytexx*gvox->mytexy; @@ -2073,7 +2073,7 @@ skindidntfit:; { free(zbit); - //Re-generate shp[].x/y (box sizes) from shcnt (now head indices) for next pass :/ + //Re-generate shp[].x/y (box sizes) from shcnt (now head indices) for next pass :/ j = 0; for(y=gmaxy;y;y--) for(x=gmaxx;x>=y;x--) @@ -2094,7 +2094,7 @@ skindidntfit:; } gvox->quad = (voxrect_t *)malloc(gvox->qcnt*sizeof(voxrect_t)); - if (!gvox->quad) { free(zbit); free(shp); free(bx0); free(gvox); return(0); } + if (!gvox->quad) { free(zbit); free(shp); free(bx0); free(gvox); return(0); } gvox->mytex = (long *)malloc(gvox->mytexx*gvox->mytexy*sizeof(long)); if (!gvox->mytex) { free(gvox->quad); free(zbit); free(shp); free(bx0); free(gvox); return(0); } @@ -2119,7 +2119,7 @@ static long loadvox (const char *filnam) klseek(fil,-768,SEEK_END); for(i=0;i<256;i++) - { kread(fil,c,3); pal[i] = (((long)c[0])<<18)+(((long)c[1])<<10)+(((long)c[2])<<2)+(i<<24); } + { kread(fil,c,3); pal[i] = (((long)c[0])<<18)+(((long)c[1])<<10)+(((long)c[2])<<2)+(i<<24); } pal[255] = -1; vcolhashsizm1 = 8192-1; @@ -2132,35 +2132,35 @@ static long loadvox (const char *filnam) tbuf = (unsigned char *)malloc(zsiz*sizeof(char)); if (!tbuf) { kclose(fil); return(-1); } - klseek(fil,12,SEEK_SET); - for(x=0;x=0;z--) - { if (tbuf[z] != 255) { i = j+z; vbit[i>>5] |= (1<=0;z--) + { if (tbuf[z] != 255) { i = j+z; vbit[i>>5] |= (1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]); klseek(fil,-768,SEEK_END); for(i=0;i<256;i++) - { kread(fil,c,3); pal[i] = B_LITTLE32((((long)c[0])<<18)+(((long)c[1])<<10)+(((long)c[2])<<2)+(i<<24)); } + { kread(fil,c,3); pal[i] = B_LITTLE32((((long)c[0])<<18)+(((long)c[1])<<10)+(((long)c[2])<<2)+(i<<24)); } yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3); vbit = (long *)malloc(i); if (!vbit) { free(xyoffs); kclose(fil); return(-1); } memset(vbit,0,i); for(vcolhashsizm1=4096;vcolhashsizm1<(mip1leng>>1);vcolhashsizm1<<=1); vcolhashsizm1--; //approx to numvoxs! - vcolhashead = (long *)malloc((vcolhashsizm1+1)*sizeof(long)); if (!vcolhashead) { free(xyoffs); kclose(fil); return(-1); } +vcolhashead = (long *)malloc((vcolhashsizm1+1)*sizeof(long)); if (!vcolhashead) { free(xyoffs); kclose(fil); return(-1); } memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(long)); klseek(fil,28+((xsiz+1)<<2)+((ysizp1*xsiz)<<1),SEEK_SET); @@ -2229,7 +2229,7 @@ static long loadkv6 (const char *filnam) unsigned char c[8]; fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1); - kread(fil,&i,4); if (B_LITTLE32(i) != 0x6c78764b) { kclose(fil); return(-1); } //Kvxl +kread(fil,&i,4); if (B_LITTLE32(i) != 0x6c78764b) { kclose(fil); return(-1); } //Kvxl kread(fil,&xsiz,4); xsiz = B_LITTLE32(xsiz); kread(fil,&ysiz,4); ysiz = B_LITTLE32(ysiz); kread(fil,&zsiz,4); zsiz = B_LITTLE32(zsiz); @@ -2246,32 +2246,32 @@ static long loadkv6 (const char *filnam) klseek(fil,32,SEEK_SET); yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3); - vbit = (long *)malloc(i); if (!vbit) { free(ylen); kclose(fil); return(-1); } +vbit = (long *)malloc(i); if (!vbit) { free(ylen); kclose(fil); return(-1); } memset(vbit,0,i); for(vcolhashsizm1=4096;vcolhashsizm10;i--) - { - kread(fil,c,8); //b,g,r,a,z_lo,z_hi,vis,dir - z0 = B_LITTLE16(*(unsigned short *)&c[4]); - if (!(c[6]&16)) setzrange1(vbit,j+z1,j+z0); - vbit[(j+z0)>>5] |= (1<0;i--) + { + kread(fil,c,8); //b,g,r,a,z_lo,z_hi,vis,dir + z0 = B_LITTLE16(*(unsigned short *)&c[4]); + if (!(c[6]&16)) setzrange1(vbit,j+z1,j+z0); + vbit[(j+z0)>>5] |= (1<= 0) vm = vox2poly(); else vm = 0; if (vm) @@ -2359,7 +2359,7 @@ static voxmodel *voxload (const char *filnam) return(vm); } - //Draw voxel model as perfect cubes +//Draw voxel model as perfect cubes static int voxdraw (voxmodel *m, spritetype *tspr) { point3d fp, m0, a0; @@ -2421,10 +2421,10 @@ static int voxdraw (voxmodel *m, spritetype *tspr) mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9]; mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10]; - //Mirrors - if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } + //Mirrors +if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } -//------------ + //------------ //bit 10 is an ugly hack in game.c\animatesprites telling MD2SPRITE //to use Z-buffer hacks to hide overdraw problems with the shadows if (tspr->cstat&1024) @@ -2443,11 +2443,11 @@ static int voxdraw (voxmodel *m, spritetype *tspr) pc[0] *= (float)hictinting[globalpal].r / 255.0; pc[1] *= (float)hictinting[globalpal].g / 255.0; pc[2] *= (float)hictinting[globalpal].b / 255.0; - if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; +if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; if (tspr->cstat&2) bglEnable(GL_BLEND); else bglDisable(GL_BLEND); -//------------ + //------------ - //transform to Build coords + //transform to Build coords memcpy(omat,mat,sizeof(omat)); f = 1.f/64.f; g = m0.x*f; mat[0] *= g; mat[1] *= g; mat[2] *= g; @@ -2470,7 +2470,7 @@ static int voxdraw (voxmodel *m, spritetype *tspr) phack[0] = 0; phack[1] = 1.f/256.f; if (!m->texid[globalpal]) m->texid[globalpal] = gloadtex(m->mytex,m->mytexx,m->mytexy,m->is8bit,globalpal); - else bglBindTexture(GL_TEXTURE_2D,m->texid[globalpal]); + else bglBindTexture(GL_TEXTURE_2D,m->texid[globalpal]); bglBegin(GL_QUADS); for(i=0,fi=0;iqcnt;i++) { @@ -2485,7 +2485,7 @@ static int voxdraw (voxmodel *m, spritetype *tspr) { #if (VOXBORDWIDTH == 0) bglTexCoord2f(((float)vptr[j].u)*ru+uhack[vptr[j].u!=vptr[0].u], - ((float)vptr[j].v)*rv+vhack[vptr[j].v!=vptr[0].v]); + ((float)vptr[j].v)*rv+vhack[vptr[j].v!=vptr[0].v]); #else bglTexCoord2f(((float)vptr[j].u)*ru,((float)vptr[j].v)*rv); #endif @@ -2497,7 +2497,7 @@ static int voxdraw (voxmodel *m, spritetype *tspr) } bglEnd(); -//------------ + //------------ bglDisable(GL_CULL_FACE); bglPopAttrib(); if (tspr->cstat&1024) @@ -2520,16 +2520,16 @@ mdmodel *mdload (const char *filnam) vm = (mdmodel*)voxload(filnam); if (vm) return(vm); - fil = kopen4load((char *)filnam,0); if (fil < 0) return(0); - kread(fil,&i,4); klseek(fil,0,SEEK_SET); - switch(B_LITTLE32(i)) - { - case 0x32504449: vm = (mdmodel*)md2load(fil,filnam); break; //IDP2 - case 0x33504449: vm = (mdmodel*)md3load(fil); break; //IDP3 - default: vm = (mdmodel*)0; break; - } - kclose(fil); - return(vm); + fil = kopen4load((char *)filnam,0); if (fil < 0) return(0); + kread(fil,&i,4); klseek(fil,0,SEEK_SET); + switch(B_LITTLE32(i)) + { + case 0x32504449: vm = (mdmodel*)md2load(fil,filnam); break; //IDP2 + case 0x33504449: vm = (mdmodel*)md3load(fil); break; //IDP3 + default: vm = (mdmodel*)0; break; + } + kclose(fil); + return(vm); } int mddraw (spritetype *tspr) diff --git a/polymer/build/src/mmulti.c b/polymer/build/src/mmulti.c index 4d03468e2..01640de9b 100644 --- a/polymer/build/src/mmulti.c +++ b/polymer/build/src/mmulti.c @@ -29,13 +29,13 @@ #include static long GetTickCount(void) { - struct timeval tv; - long ti; - if (gettimeofday(&tv,NULL) < 0) return 0; - // tv is sec.usec, GTC gives msec - ti = tv.tv_sec * 1000; - ti += tv.tv_usec / 1000; - return ti; + struct timeval tv; + long ti; + if (gettimeofday(&tv,NULL) < 0) return 0; + // tv is sec.usec, GTC gives msec + ti = tv.tv_sec * 1000; + ti += tv.tv_usec / 1000; + return ti; } #endif @@ -79,113 +79,113 @@ static long snatchip = 0, snatchport = 0, danetmode = 255, netready = 0; void netuninit () { - if (mysock != (SOCKET)INVALID_HANDLE_VALUE) closesocket(mysock); + if (mysock != (SOCKET)INVALID_HANDLE_VALUE) closesocket(mysock); #ifdef _WIN32 - WSACleanup(); + WSACleanup(); #endif } long netinit (long portnum) { - LPHOSTENT lpHostEnt; - char hostnam[256]; - struct sockaddr_in ip; - long i; + LPHOSTENT lpHostEnt; + char hostnam[256]; + struct sockaddr_in ip; + long i; #ifdef _WIN32 - WSADATA ws; + WSADATA ws; - if (WSAStartup(0x101,&ws) == SOCKET_ERROR) return(0); + if (WSAStartup(0x101,&ws) == SOCKET_ERROR) return(0); #endif - mysock = socket(AF_INET,SOCK_DGRAM,0); if (mysock == INVALID_SOCKET) return(0); + mysock = socket(AF_INET,SOCK_DGRAM,0); if (mysock == INVALID_SOCKET) return(0); #ifdef __BEOS__ - i = 1; if (setsockopt(mysock,SOL_SOCKET,SO_NONBLOCK,&i,sizeof(i)) < 0) return(0); + i = 1; if (setsockopt(mysock,SOL_SOCKET,SO_NONBLOCK,&i,sizeof(i)) < 0) return(0); #else - i = 1; if (ioctlsocket(mysock,FIONBIO,(unsigned long *)&i) == SOCKET_ERROR) return(0); + i = 1; if (ioctlsocket(mysock,FIONBIO,(unsigned long *)&i) == SOCKET_ERROR) return(0); #endif - ip.sin_family = AF_INET; - ip.sin_addr.s_addr = INADDR_ANY; - ip.sin_port = htons(portnum); - if (bind(mysock,(struct sockaddr *)&ip,sizeof(ip)) != SOCKET_ERROR) - { - myport = portnum; - if (gethostname(hostnam,sizeof(hostnam)) != SOCKET_ERROR) - if ((lpHostEnt = gethostbyname(hostnam))) - { - myip = ip.sin_addr.s_addr = *(long *)lpHostEnt->h_addr; - printf("mmulti: This machine's IP is %s\n", inet_ntoa(ip.sin_addr)); - } - return(1); - } - return(0); + ip.sin_family = AF_INET; + ip.sin_addr.s_addr = INADDR_ANY; + ip.sin_port = htons(portnum); + if (bind(mysock,(struct sockaddr *)&ip,sizeof(ip)) != SOCKET_ERROR) + { + myport = portnum; + if (gethostname(hostnam,sizeof(hostnam)) != SOCKET_ERROR) + if ((lpHostEnt = gethostbyname(hostnam))) + { + myip = ip.sin_addr.s_addr = *(long *)lpHostEnt->h_addr; + printf("mmulti: This machine's IP is %s\n", inet_ntoa(ip.sin_addr)); + } + return(1); + } + return(0); } long netsend (long other, char *dabuf, long bufsiz) //0:buffer full... can't send { - struct sockaddr_in ip; + struct sockaddr_in ip; - if (!otherip[other]) return(0); - ip.sin_family = AF_INET; - ip.sin_addr.s_addr = otherip[other]; - ip.sin_port = otherport[other]; - return(sendto(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,sizeof(struct sockaddr_in)) != SOCKET_ERROR); + if (!otherip[other]) return(0); + ip.sin_family = AF_INET; + ip.sin_addr.s_addr = otherip[other]; + ip.sin_port = otherport[other]; + return(sendto(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,sizeof(struct sockaddr_in)) != SOCKET_ERROR); } long netread (long *other, char *dabuf, long bufsiz) //0:no packets in buffer { - struct sockaddr_in ip; - long i; + struct sockaddr_in ip; + long i; - i = sizeof(ip); - if (recvfrom(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,(int *)&i) == -1) return(0); + i = sizeof(ip); + if (recvfrom(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,(int *)&i) == -1) return(0); #if (SIMMIS > 0) - if ((rand()&255) < SIMMIS) return(0); + if ((rand()&255) < SIMMIS) return(0); #endif - snatchip = (long)ip.sin_addr.s_addr; snatchport = (long)ip.sin_port; + snatchip = (long)ip.sin_addr.s_addr; snatchport = (long)ip.sin_port; - (*other) = myconnectindex; - for(i=0;i 1) - i = simlagcnt[*other]%(SIMLAG+1); - *(short *)&simlagfif[*other][i][0] = bufsiz; memcpy(&simlagfif[*other][i][2],dabuf,bufsiz); - simlagcnt[*other]++; if (simlagcnt[*other] < SIMLAG+1) return(0); - i = simlagcnt[*other]%(SIMLAG+1); - bufsiz = *(short *)&simlagfif[*other][i][0]; memcpy(dabuf,&simlagfif[*other][i][2],bufsiz); + i = simlagcnt[*other]%(SIMLAG+1); + *(short *)&simlagfif[*other][i][0] = bufsiz; memcpy(&simlagfif[*other][i][2],dabuf,bufsiz); + simlagcnt[*other]++; if (simlagcnt[*other] < SIMLAG+1) return(0); + i = simlagcnt[*other]%(SIMLAG+1); + bufsiz = *(short *)&simlagfif[*other][i][0]; memcpy(dabuf,&simlagfif[*other][i][2],bufsiz); #endif - return(1); + return(1); } long isvalidipaddress (char *st) { - long i, bcnt, num; + long i, bcnt, num; - bcnt = 0; num = 0; - for(i=0;st[i];i++) - { - if (st[i] == '.') { bcnt++; num = 0; continue; } - if (st[i] == ':') - { - if (bcnt != 3) return(0); - num = 0; - for(i++;st[i];i++) - { - if ((st[i] >= '0') && (st[i] <= '9')) - { num = num*10+st[i]-'0'; if (num >= 65536) return(0); } - else return(0); - } - return(1); - } - if ((st[i] >= '0') && (st[i] <= '9')) - { num = num*10+st[i]-'0'; if (num >= 256) return(0); } + bcnt = 0; num = 0; + for(i=0;st[i];i++) + { + if (st[i] == '.') { bcnt++; num = 0; continue; } + if (st[i] == ':') + { + if (bcnt != 3) return(0); + num = 0; + for(i++;st[i];i++) + { + if ((st[i] >= '0') && (st[i] <= '9')) + { num = num*10+st[i]-'0'; if (num >= 65536) return(0); } + else return(0); + } + return(1); + } + if ((st[i] >= '0') && (st[i] <= '9')) + { num = num*10+st[i]-'0'; if (num >= 256) return(0); } - } - return(bcnt == 3); + } + return(bcnt == 3); } //---------------------------------- Obsolete variables&functions ---------------------------------- @@ -202,25 +202,25 @@ void sendlogoff () {} static long crctab16[256]; static void initcrc16 () { - long i, j, k, a; - for(j=0;j<256;j++) - { - for(i=7,k=(j<<8),a=0;i>=0;i--,k=((k<<1)&65535)) - { - if ((k^a)&0x8000) a = ((a<<1)&65535)^0x1021; - else a = ((a<<1)&65535); - } - crctab16[j] = (a&65535); - } + long i, j, k, a; + for(j=0;j<256;j++) + { + for(i=7,k=(j<<8),a=0;i>=0;i--,k=((k<<1)&65535)) + { + if ((k^a)&0x8000) a = ((a<<1)&65535)^0x1021; + else a = ((a<<1)&65535); + } + crctab16[j] = (a&65535); + } } #define updatecrc16(crc,dat) crc = (((crc<<8)&65535)^crctab16[((((unsigned short)crc)>>8)&65535)^dat]) static unsigned short getcrc16 (char *buffer, long bufleng) { - long i, j; + long i, j; - j = 0; - for(i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]); - return((unsigned short)(j&65535)); + j = 0; + for(i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]); + return((unsigned short)(j&65535)); } void uninitmultiplayers () { netuninit(); } @@ -228,422 +228,422 @@ void uninitmultiplayers () { netuninit(); } long getpacket(long *, char *); static void initmultiplayers_reset(void) { - long i; + long i; - initcrc16(); - memset(icnt0,0,sizeof(icnt0)); - memset(ocnt0,0,sizeof(ocnt0)); - memset(ocnt1,0,sizeof(ocnt1)); - memset(ipak,0,sizeof(ipak)); - //memset(opak,0,sizeof(opak)); //Don't need to init opak - //memset(pakmem,0,sizeof(pakmem)); //Don't need to init pakmem + initcrc16(); + memset(icnt0,0,sizeof(icnt0)); + memset(ocnt0,0,sizeof(ocnt0)); + memset(ocnt1,0,sizeof(ocnt1)); + memset(ipak,0,sizeof(ipak)); + //memset(opak,0,sizeof(opak)); //Don't need to init opak + //memset(pakmem,0,sizeof(pakmem)); //Don't need to init pakmem #if (SIMLAG > 1) - memset(simlagcnt,0,sizeof(simlagcnt)); + memset(simlagcnt,0,sizeof(simlagcnt)); #endif - lastsendtims[0] = GetTickCount(); - for(i=1;i 1024 && j<65535) portnum = j; + // go looking for the port, if specified + for (i=0;i 1024 && j<65535) portnum = j; - printf("mmulti: Using port %ld\n", portnum); - } - } + printf("mmulti: Using port %ld\n", portnum); + } + } - netinit(portnum); + netinit(portnum); - for(i=0;i= '0') && (argv[i][4] <= '9')) - { - numplayers = (argv[i][4]-'0'); - if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) numplayers = numplayers*10+(argv[i][5]-'0'); - printf("mmulti: %ld-player game\n", numplayers); - } - printf("mmulti: Master-slave mode\n"); - } - else if (argv[i][2] == '1') - { - danetmode = 1; - myconnectindex = daindex; daindex++; - printf("mmulti: Peer-to-peer mode\n"); - } - continue; - } - else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; - } + if ((argv[i][0] == '-') || (argv[i][0] == '/')) { + if ((argv[i][1] == 'N') || (argv[i][1] == 'n') || (argv[i][1] == 'I') || (argv[i][1] == 'i')) + { + numplayers = 2; + if (argv[i][2] == '0') + { + danetmode = 0; + if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9')) + { + numplayers = (argv[i][4]-'0'); + if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) numplayers = numplayers*10+(argv[i][5]-'0'); + printf("mmulti: %ld-player game\n", numplayers); + } + printf("mmulti: Master-slave mode\n"); + } + else if (argv[i][2] == '1') + { + danetmode = 1; + myconnectindex = daindex; daindex++; + printf("mmulti: Peer-to-peer mode\n"); + } + continue; + } + else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; + } - st = strdup(argv[i]); if (!st) break; - if (isvalidipaddress(st)) - { - if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; - for(j=0;st[j];j++) { - if (st[j] == ':') - { otherport[daindex] = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } - } - otherip[daindex] = inet_addr(st); - printf("mmulti: Player %ld at %s:%d\n",daindex,st,ntohs(otherport[daindex])); - daindex++; - } - else - { - LPHOSTENT lph; - unsigned short pt = htons(NETPORT); + st = strdup(argv[i]); if (!st) break; + if (isvalidipaddress(st)) + { + if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; + for(j=0;st[j];j++) { + if (st[j] == ':') + { otherport[daindex] = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } + } + otherip[daindex] = inet_addr(st); + printf("mmulti: Player %ld at %s:%d\n",daindex,st,ntohs(otherport[daindex])); + daindex++; + } + else + { + LPHOSTENT lph; + unsigned short pt = htons(NETPORT); - for(j=0;st[j];j++) - if (st[j] == ':') - { pt = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } - if ((lph = gethostbyname(st))) - { - if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; - otherip[daindex] = *(long *)lph->h_addr; - otherport[daindex] = pt; - printf("mmulti: Player %ld at %s:%d (%s)\n",daindex, - inet_ntoa(*(struct in_addr *)lph->h_addr),ntohs(pt),argv[i]); - daindex++; - } else printf("mmulti: Failed resolving %s\n",argv[i]); - } - free(st); - } - if ((danetmode == 255) && (daindex)) { numplayers = 2; danetmode = 0; } //an IP w/o /n# defaults to /n0 - if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1; - if (daindex > numplayers) numplayers = daindex; + for(j=0;st[j];j++) + if (st[j] == ':') + { pt = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } + if ((lph = gethostbyname(st))) + { + if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; + otherip[daindex] = *(long *)lph->h_addr; + otherport[daindex] = pt; + printf("mmulti: Player %ld at %s:%d (%s)\n",daindex, + inet_ntoa(*(struct in_addr *)lph->h_addr),ntohs(pt),argv[i]); + daindex++; + } else printf("mmulti: Failed resolving %s\n",argv[i]); + } + free(st); + } +if ((danetmode == 255) && (daindex)) { numplayers = 2; danetmode = 0; } //an IP w/o /n# defaults to /n0 + if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1; + if (daindex > numplayers) numplayers = daindex; - //for(i=0;i>8)&255,(otherip[i]>>16)&255,((unsigned long)otherip[i])>>24,ntohs(otherport[i])); + //for(i=0;i>8)&255,(otherip[i]>>16)&255,((unsigned long)otherip[i])>>24,ntohs(otherport[i])); - connecthead = 0; - for(i=0;i= 2)) || (numplayers == 2)); + return (((!danetmode) && (numplayers >= 2)) || (numplayers == 2)); } long initmultiplayerscycle(void) { - long i, k; + long i, k; extern long totalclock; - + #ifdef _WIN32 Sleep(1); #else usleep(1); #endif - getpacket(&i,0); + getpacket(&i,0); - tims = GetTickCount(); - if (myconnectindex == connecthead) - { - for(i=numplayers-1;i>0;i--) - if (!otherip[i]) break; - if (!i) { - netready = 1; - return 0; - } - } - else - { - if (netready) return 0; - if (tims < lastsendtims[connecthead]) lastsendtims[connecthead] = tims; - if (tims >= lastsendtims[connecthead]+250) //1000/PAKRATE) - { - lastsendtims[connecthead] = tims; + tims = GetTickCount(); + if (myconnectindex == connecthead) + { + for(i=numplayers-1;i>0;i--) + if (!otherip[i]) break; + if (!i) { + netready = 1; + return 0; + } + } + else + { + if (netready) return 0; + if (tims < lastsendtims[connecthead]) lastsendtims[connecthead] = tims; + if (tims >= lastsendtims[connecthead]+250) //1000/PAKRATE) + { + lastsendtims[connecthead] = tims; - // short crc16ofs; //offset of crc16 - // long icnt0; //-1 (special packet for MMULTI.C's player collection) - // ... - // unsigned short crc16; //CRC16 of everything except crc16 - k = 2; - *(long *)&pakbuf[k] = -1; k += 4; - pakbuf[k++] = 0xaa; - *(unsigned short *)&pakbuf[0] = (unsigned short)k; - *(unsigned short *)&pakbuf[k] = getcrc16(pakbuf,k); k += 2; - netsend(connecthead,pakbuf,k); - } - } + // short crc16ofs; //offset of crc16 + // long icnt0; //-1 (special packet for MMULTI.C's player collection) + // ... + // unsigned short crc16; //CRC16 of everything except crc16 + k = 2; + *(long *)&pakbuf[k] = -1; k += 4; + pakbuf[k++] = 0xaa; + *(unsigned short *)&pakbuf[0] = (unsigned short)k; + *(unsigned short *)&pakbuf[k] = getcrc16(pakbuf,k); k += 2; + netsend(connecthead,pakbuf,k); + } + } - return 1; + return 1; } void initmultiplayers (long argc, char **argv, char damultioption, char dacomrateoption, char dapriority) { - long i, j, k, otims; + long i, j, k, otims; - if (initmultiplayersparms(argc,argv)) - { + if (initmultiplayersparms(argc,argv)) + { #if 0 - //Console code seems to crash Win98 upon quitting game - //it's not necessary and it's not portable anyway - char tbuf[1024]; - unsigned long u; - HANDLE hconsout; - AllocConsole(); - SetConsoleTitle("Multiplayer status..."); - hconsout = GetStdHandle(STD_OUTPUT_HANDLE); - otims = 0; + //Console code seems to crash Win98 upon quitting game + //it's not necessary and it's not portable anyway + char tbuf[1024]; + unsigned long u; + HANDLE hconsout; + AllocConsole(); + SetConsoleTitle("Multiplayer status..."); + hconsout = GetStdHandle(STD_OUTPUT_HANDLE); + otims = 0; #endif - while (initmultiplayerscycle()) - { + while (initmultiplayerscycle()) + { #if 0 - if ((tims < otims) || (tims > otims+100)) - { - otims = tims; - sprintf(tbuf,"\rWait for players (%d/%d): ",myconnectindex,numplayers); - for(i=0;i "); continue; } - if (!otherip[i]) { strcat(tbuf,"?.?.?.?:? "); continue; } - sprintf(&tbuf[strlen(tbuf)],"%d.%d.%d.%d:%04x ",otherip[i]&255,(otherip[i]>>8)&255,(otherip[i]>>16)&255,(((unsigned long)otherip[i])>>24),otherport[i]); - } - WriteConsole(hconsout,tbuf,strlen(tbuf),&u,0); - } - } - FreeConsole(); + if ((tims < otims) || (tims > otims+100)) + { + otims = tims; + sprintf(tbuf,"\rWait for players (%d/%d): ",myconnectindex,numplayers); + for(i=0;i "); continue; } + if (!otherip[i]) { strcat(tbuf,"?.?.?.?:? "); continue; } + sprintf(&tbuf[strlen(tbuf)],"%d.%d.%d.%d:%04x ",otherip[i]&255,(otherip[i]>>8)&255,(otherip[i]>>16)&255,(((unsigned long)otherip[i])>>24),otherport[i]); + } + WriteConsole(hconsout,tbuf,strlen(tbuf),&u,0); + } + } + FreeConsole(); #else - } + } #endif - } - netready = 1; + } + netready = 1; } void dosendpackets (long other) { - long i, j, k; + long i, j, k; - if (!otherip[other]) return; + if (!otherip[other]) return; - //Packet format: - // short crc16ofs; //offset of crc16 - // long icnt0; //earliest unacked packet - // char ibits[32]; //ack status of packets icnt0<=i>3)+k] |= (1<<((i-icnt0[other])&7)); - k += 32; + k = 2; + *(long *)&pakbuf[k] = icnt0[other]; k += 4; + memset(&pakbuf[k],0,32); + for(i=icnt0[other];i>3)+k] |= (1<<((i-icnt0[other])&7)); + k += 32; - while ((ocnt0[other] < ocnt1[other]) && (!opak[other][ocnt0[other]&(FIFSIZ-1)])) ocnt0[other]++; - for(i=ocnt0[other];i (long)sizeof(pakbuf)) break; + while ((ocnt0[other] < ocnt1[other]) && (!opak[other][ocnt0[other]&(FIFSIZ-1)])) ocnt0[other]++; + for(i=ocnt0[other];i (long)sizeof(pakbuf)) break; - *(unsigned short *)&pakbuf[k] = (unsigned short)j; k += 2; - *(long *)&pakbuf[k] = i; k += 4; - memcpy(&pakbuf[k],&pakmem[opak[other][i&(FIFSIZ-1)]+2],j); k += j; - } - *(unsigned short *)&pakbuf[k] = 0; k += 2; - *(unsigned short *)&pakbuf[0] = (unsigned short)k; - *(unsigned short *)&pakbuf[k] = getcrc16(pakbuf,k); k += 2; + *(unsigned short *)&pakbuf[k] = (unsigned short)j; k += 2; + *(long *)&pakbuf[k] = i; k += 4; + memcpy(&pakbuf[k],&pakmem[opak[other][i&(FIFSIZ-1)]+2],j); k += j; + } + *(unsigned short *)&pakbuf[k] = 0; k += 2; + *(unsigned short *)&pakbuf[0] = (unsigned short)k; + *(unsigned short *)&pakbuf[k] = getcrc16(pakbuf,k); k += 2; - //printf("Send: "); for(i=0;i (long)sizeof(pakmem)) pakmemi = 1; - opak[other][ocnt1[other]&(FIFSIZ-1)] = pakmemi; - *(short *)&pakmem[pakmemi] = messleng; - memcpy(&pakmem[pakmemi+2],bufptr,messleng); pakmemi += messleng+2; - ocnt1[other]++; + if (pakmemi+messleng+2 > (long)sizeof(pakmem)) pakmemi = 1; + opak[other][ocnt1[other]&(FIFSIZ-1)] = pakmemi; + *(short *)&pakmem[pakmemi] = messleng; + memcpy(&pakmem[pakmemi+2],bufptr,messleng); pakmemi += messleng+2; + ocnt1[other]++; - //printf("Send: "); for(i=0;i=0;i=connectpoint2[i]) - { - if (i != myconnectindex) dosendpackets(i); - if ((!danetmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master - } - } + if (netready) + { + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) dosendpackets(i); + if ((!danetmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + } - while (netread(&other,pakbuf,sizeof(pakbuf))) - { - //Packet format: - // short crc16ofs; //offset of crc16 - // long icnt0; //earliest unacked packet - // char ibits[32]; //ack status of packets icnt0<=i>3)+k]&(1<<((i-ic0)&7))) - opak[other][i&(FIFSIZ-1)] = 0; - k += 32; + otherip[connecthead] = snatchip; + otherport[connecthead] = snatchport; + netready = 1; + } + } + } + else + { + if (ocnt0[other] < ic0) ocnt0[other] = ic0; + for(i=ic0;i>3)+k]&(1<<((i-ic0)&7))) + opak[other][i&(FIFSIZ-1)] = 0; + k += 32; - messleng = (long)(*(unsigned short *)&pakbuf[k]); k += 2; - while (messleng) - { - j = *(long *)&pakbuf[k]; k += 4; - if ((j >= icnt0[other]) && (!ipak[other][j&(FIFSIZ-1)])) - { - if (pakmemi+messleng+2 > (long)sizeof(pakmem)) pakmemi = 1; - ipak[other][j&(FIFSIZ-1)] = pakmemi; - *(short *)&pakmem[pakmemi] = messleng; - memcpy(&pakmem[pakmemi+2],&pakbuf[k],messleng); pakmemi += messleng+2; - } - k += messleng; - messleng = (long)(*(unsigned short *)&pakbuf[k]); k += 2; - } - } - } - } + messleng = (long)(*(unsigned short *)&pakbuf[k]); k += 2; + while (messleng) + { + j = *(long *)&pakbuf[k]; k += 4; + if ((j >= icnt0[other]) && (!ipak[other][j&(FIFSIZ-1)])) + { + if (pakmemi+messleng+2 > (long)sizeof(pakmem)) pakmemi = 1; + ipak[other][j&(FIFSIZ-1)] = pakmemi; + *(short *)&pakmem[pakmemi] = messleng; + memcpy(&pakmem[pakmemi+2],&pakbuf[k],messleng); pakmemi += messleng+2; + } + k += messleng; + messleng = (long)(*(unsigned short *)&pakbuf[k]); k += 2; + } + } + } + } - //Return next valid packet from any player - if (!bufptr) return(0); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (i != myconnectindex) - { - j = ipak[i][icnt0[i]&(FIFSIZ-1)]; - if (j) - { - messleng = *(short *)&pakmem[j]; memcpy(bufptr,&pakmem[j+2],messleng); - *retother = i; ipak[i][icnt0[i]&(FIFSIZ-1)] = 0; icnt0[i]++; - //printf("Recv: "); for(i=0;i=0;i=connectpoint2[i]) + { + if (i != myconnectindex) + { + j = ipak[i][icnt0[i]&(FIFSIZ-1)]; + if (j) + { + messleng = *(short *)&pakmem[j]; memcpy(bufptr,&pakmem[j+2],messleng); + *retother = i; ipak[i][icnt0[i]&(FIFSIZ-1)] = 0; icnt0[i]++; + //printf("Recv: "); for(i=0;i k) { k = j; white = i; } - } - } + if (white<0) { + // find the palette index closest to white + k=0; + for(i=0;i<256;i++) + { + j = ((int)curpalette[i].r)+((int)curpalette[i].g)+((int)curpalette[i].b); + if (j > k) { k = j; white = i; } + } + } - printext256(4+(x<<3),4+(y<<3), white, -1, st, 0); + printext256(4+(x<<3),4+(y<<3), white, -1, st, 0); } static void _internal_drawosdstr(int x, int y, char *ch, int len, int shade, int pal) { - int i,j,k; - char st[1024]; + int i,j,k; + char st[1024]; - if (len>1023) len=1023; - memcpy(st,ch,len); - st[len]=0; - - if (white<0) { - // find the palette index closest to white - k=0; - for(i=0;i<256;i++) - { - j = ((int)curpalette[i].r)+((int)curpalette[i].g)+((int)curpalette[i].b); - if (j > k) { k = j; white = i; } - } - } + if (len>1023) len=1023; + memcpy(st,ch,len); + st[len]=0; - printext256(4+(x<<3),4+(y<<3), white, -1, st, 0); + if (white<0) { + // find the palette index closest to white + k=0; + for(i=0;i<256;i++) + { + j = ((int)curpalette[i].r)+((int)curpalette[i].g)+((int)curpalette[i].b); + if (j > k) { k = j; white = i; } + } + } + + printext256(4+(x<<3),4+(y<<3), white, -1, st, 0); } static void _internal_drawosdcursor(int x, int y, int type, int lastkeypress) { - int i,j,k; - char st[2] = { '_',0 }; + int i,j,k; + char st[2] = { '_',0 }; - if (type) st[0] = '#'; + if (type) st[0] = '#'; - if (white<0) { - // find the palette index closest to white - k=0; - for(i=0;i<256;i++) - { - j = ((int)palette[i*3])+((int)palette[i*3+1])+((int)palette[i*3+2]); - if (j > k) { k = j; white = i; } - } - } + if (white<0) { + // find the palette index closest to white + k=0; + for(i=0;i<256;i++) + { + j = ((int)palette[i*3])+((int)palette[i*3+1])+((int)palette[i*3+2]); + if (j > k) { k = j; white = i; } + } + } - printext256(4+(x<<3),4+(y<<3)+2, white, -1, st, 0); + printext256(4+(x<<3),4+(y<<3)+2, white, -1, st, 0); } static int _internal_getcolumnwidth(int w) { - return w/8 - 1; + return w/8 - 1; } static int _internal_getrowheight(int w) { - return w/8; + return w/8; } static void _internal_clearbackground(int cols, int rows) @@ -178,7 +178,7 @@ static void _internal_clearbackground(int cols, int rows) static int _internal_gettime(void) { - return 0; + return 0; } static void _internal_onshowosd(int a) @@ -189,44 +189,44 @@ static void _internal_onshowosd(int a) static int _internal_osdfunc_vars(const osdfuncparm_t *parm) { - int showval = (parm->numparms < 1); + int showval = (parm->numparms < 1); - if (!Bstrcasecmp(parm->name, "osdrows")) { - if (showval) { OSD_Printf("osdrows is %d\n", osdrows); return OSDCMD_OK; } - else { - osdrows = atoi(parm->parms[0]); - if (osdrows < 1) osdrows = 1; - else if (osdrows > osdmaxrows) osdrows = osdmaxrows; - return OSDCMD_OK; - } - } - return OSDCMD_SHOWHELP; + if (!Bstrcasecmp(parm->name, "osdrows")) { + if (showval) { OSD_Printf("osdrows is %d\n", osdrows); return OSDCMD_OK; } + else { + osdrows = atoi(parm->parms[0]); + if (osdrows < 1) osdrows = 1; + else if (osdrows > osdmaxrows) osdrows = osdmaxrows; + return OSDCMD_OK; + } + } + return OSDCMD_SHOWHELP; } static int _internal_osdfunc_listsymbols(const osdfuncparm_t *parm) { - symbol_t *i; + symbol_t *i; - OSD_Printf("Symbol listing:\n"); - for (i=symbols; i!=NULL; i=i->next) - OSD_Printf(" %s\n", i->name); - - return OSDCMD_OK; + OSD_Printf("Symbol listing:\n"); + for (i=symbols; i!=NULL; i=i->next) + OSD_Printf(" %s\n", i->name); + + return OSDCMD_OK; } static int _internal_osdfunc_help(const osdfuncparm_t *parm) { - symbol_t *symb; + symbol_t *symb; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; - symb = findexactsymbol(parm->parms[0]); - if (!symb) { - OSD_Printf("Help Error: \"%s\" is not a defined variable or function\n", parm->parms[0]); - } else { - OSD_Printf("%s\n", symb->help); - } - - return OSDCMD_OK; + if (parm->numparms != 1) return OSDCMD_SHOWHELP; + symb = findexactsymbol(parm->parms[0]); + if (!symb) { + OSD_Printf("Help Error: \"%s\" is not a defined variable or function\n", parm->parms[0]); + } else { + OSD_Printf("%s\n", symb->help); + } + + return OSDCMD_OK; } @@ -239,17 +239,17 @@ static int _internal_osdfunc_help(const osdfuncparm_t *parm) // void OSD_Cleanup(void) { - symbol_t *s; + symbol_t *s; - for (; symbols; symbols=s) { - s=symbols->next; - Bfree(symbols); - } + for (; symbols; symbols=s) { + s=symbols->next; + Bfree(symbols); + } - if (osdlog) Bfclose(osdlog); - osdlog = NULL; + if (osdlog) Bfclose(osdlog); + osdlog = NULL; - osdinited=0; + osdinited=0; } @@ -258,16 +258,16 @@ void OSD_Cleanup(void) // void OSD_Init(void) { - Bmemset(osdtext, 32, TEXTSIZE); - osdlines=1; + Bmemset(osdtext, 32, TEXTSIZE); + osdlines=1; - osdinited=1; + osdinited=1; - OSD_RegisterFunction("listsymbols","listsymbols: lists all the recognized symbols",_internal_osdfunc_listsymbols); - OSD_RegisterFunction("help","help: displays help on the named symbol",_internal_osdfunc_help); - OSD_RegisterFunction("osdrows","osdrows: sets the number of visible lines of the OSD",_internal_osdfunc_vars); + OSD_RegisterFunction("listsymbols","listsymbols: lists all the recognized symbols",_internal_osdfunc_listsymbols); + OSD_RegisterFunction("help","help: displays help on the named symbol",_internal_osdfunc_help); + OSD_RegisterFunction("osdrows","osdrows: sets the number of visible lines of the OSD",_internal_osdfunc_vars); - atexit(OSD_Cleanup); + atexit(OSD_Cleanup); } @@ -276,10 +276,10 @@ void OSD_Init(void) // void OSD_SetLogFile(char *fn) { - if (osdlog) Bfclose(osdlog); - osdlog = NULL; - if (fn) osdlog = Bfopen(fn,"w"); - if (osdlog) setvbuf(osdlog, (char*)NULL, _IONBF, 0); + if (osdlog) Bfclose(osdlog); + osdlog = NULL; + if (fn) osdlog = Bfopen(fn,"w"); + if (osdlog) setvbuf(osdlog, (char*)NULL, _IONBF, 0); } @@ -287,33 +287,33 @@ void OSD_SetLogFile(char *fn) // OSD_SetFunctions() -- Sets some callbacks which the OSD uses to understand its world // void OSD_SetFunctions( - void (*drawchar)(int,int,char,int,int), - void (*drawstr)(int,int,char*,int,int,int), - void (*drawcursor)(int,int,int,int), - int (*colwidth)(int), - int (*rowheight)(int), - void (*clearbg)(int,int), - int (*gtime)(void), - void (*showosd)(int) - ) + void (*drawchar)(int,int,char,int,int), + void (*drawstr)(int,int,char*,int,int,int), + void (*drawcursor)(int,int,int,int), + int (*colwidth)(int), + int (*rowheight)(int), + void (*clearbg)(int,int), + int (*gtime)(void), + void (*showosd)(int) +) { - drawosdchar = drawchar; - drawosdstr = drawstr; - drawosdcursor = drawcursor; - getcolumnwidth = colwidth; - getrowheight = rowheight; - clearbackground = clearbg; - gettime = gtime; - onshowosd = showosd; + drawosdchar = drawchar; + drawosdstr = drawstr; + drawosdcursor = drawcursor; + getcolumnwidth = colwidth; + getrowheight = rowheight; + clearbackground = clearbg; + gettime = gtime; + onshowosd = showosd; - if (!drawosdchar) drawosdchar = _internal_drawosdchar; - if (!drawosdstr) drawosdstr = _internal_drawosdstr; - if (!drawosdcursor) drawosdcursor = _internal_drawosdcursor; - if (!getcolumnwidth) getcolumnwidth = _internal_getcolumnwidth; - if (!getrowheight) getrowheight = _internal_getrowheight; - if (!clearbackground) clearbackground = _internal_clearbackground; - if (!gettime) gettime = _internal_gettime; - if (!onshowosd) onshowosd = _internal_onshowosd; + if (!drawosdchar) drawosdchar = _internal_drawosdchar; + if (!drawosdstr) drawosdstr = _internal_drawosdstr; + if (!drawosdcursor) drawosdcursor = _internal_drawosdcursor; + if (!getcolumnwidth) getcolumnwidth = _internal_getcolumnwidth; + if (!getrowheight) getrowheight = _internal_getrowheight; + if (!clearbackground) clearbackground = _internal_clearbackground; + if (!gettime) gettime = _internal_gettime; + if (!onshowosd) onshowosd = _internal_onshowosd; } @@ -321,17 +321,17 @@ void OSD_SetFunctions( // OSD_SetParameters() -- Sets the parameters for presenting the text // void OSD_SetParameters( - int promptshade, int promptpal, - int editshade, int editpal, - int textshade, int textpal - ) + int promptshade, int promptpal, + int editshade, int editpal, + int textshade, int textpal +) { - osdpromptshade = promptshade; - osdpromptpal = promptpal; - osdeditshade = editshade; - osdeditpal = editpal; - osdtextshade = textshade; - osdtextpal = textpal; + osdpromptshade = promptshade; + osdpromptpal = promptpal; + osdeditshade = editshade; + osdeditpal = editpal; + osdtextshade = textshade; + osdtextpal = textpal; } @@ -340,7 +340,7 @@ void OSD_SetParameters( // void OSD_CaptureKey(int sc) { - osdkey = sc; + osdkey = sc; } @@ -351,262 +351,262 @@ void OSD_CaptureKey(int sc) // int OSD_HandleKey(int sc, int press) { - char ch; - int i,j; - symbol_t *tabc = NULL; - static symbol_t *lastmatch = NULL; - - if (!osdinited) return sc; + char ch; + int i,j; + symbol_t *tabc = NULL; + static symbol_t *lastmatch = NULL; - if (sc == osdkey) { - if (press) { - OSD_ShowDisplay(osdvisible ^ 1); - bflushchars(); - } - return 0;//sc; - } else if (!osdvisible) { - return sc; - } + if (!osdinited) return sc; - if (!press) { - if (sc == 42 || sc == 54) // shift - osdeditshift = 0; - if (sc == 29 || sc == 157) // control - osdeditcontrol = 0; - return 0;//sc; - } + if (sc == osdkey) { + if (press) { + OSD_ShowDisplay(osdvisible ^ 1); + bflushchars(); + } + return 0;//sc; + } else if (!osdvisible) { + return sc; + } - keytime = gettime(); + if (!press) { + if (sc == 42 || sc == 54) // shift + osdeditshift = 0; + if (sc == 29 || sc == 157) // control + osdeditcontrol = 0; + return 0;//sc; + } - if (sc != 15) lastmatch = NULL; // tab + keytime = gettime(); - while ( (ch = bgetchar()) ) { - if (ch == 1) { // control a. jump to beginning of line - } else if (ch == 2) { // control b, move one character left - } else if (ch == 5) { // control e, jump to end of line - } else if (ch == 6) { // control f, move one character right - } else if (ch == 8 || ch == 127) { // control h, backspace - if (!osdeditcursor || !osdeditlen) return 0; - if (!osdovertype) { - if (osdeditcursor < osdeditlen) - Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor); - osdeditlen--; - } - osdeditcursor--; - if (osdeditcursor0;i--) if (osdeditbuf[i-1] == ' ') break; - for (j=0;osdeditbuf[i] != ' ' && i < osdeditlen;j++,i++) - osdedittmp[j] = osdeditbuf[i]; - osdedittmp[j] = 0; + if (sc != 15) lastmatch = NULL; // tab - if (j > 0) - tabc = findsymbol(osdedittmp, NULL); - } else { - tabc = findsymbol(osdedittmp, lastmatch->next); - if (!tabc && lastmatch) - tabc = findsymbol(osdedittmp, NULL); // wrap - } + while ( (ch = bgetchar()) ) { + if (ch == 1) { // control a. jump to beginning of line + } else if (ch == 2) { // control b, move one character left + } else if (ch == 5) { // control e, jump to end of line + } else if (ch == 6) { // control f, move one character right + } else if (ch == 8 || ch == 127) { // control h, backspace + if (!osdeditcursor || !osdeditlen) return 0; + if (!osdovertype) { + if (osdeditcursor < osdeditlen) + Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor); + osdeditlen--; + } + osdeditcursor--; + if (osdeditcursor0;i--) if (osdeditbuf[i-1] == ' ') break; + for (j=0;osdeditbuf[i] != ' ' && i < osdeditlen;j++,i++) + osdedittmp[j] = osdeditbuf[i]; + osdedittmp[j] = 0; - if (tabc) { - for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break; - osdeditlen = i; - for (j=0;tabc->name[j] && osdeditlen <= EDITLENGTH;i++,j++,osdeditlen++) - osdeditbuf[i] = tabc->name[j]; - osdeditcursor = osdeditlen; - osdeditwinend = osdeditcursor; - osdeditwinstart = osdeditwinend-editlinewidth; - if (osdeditwinstart<0) { - osdeditwinstart=0; - osdeditwinend = editlinewidth; - } - - lastmatch = tabc; - } - } else if (ch == 11) { // control k, delete all to end of line - } else if (ch == 12) { // control l, clear screen - } else if (ch == 13) { // control m, enter - if (osdeditlen>0) { - osdeditbuf[osdeditlen] = 0; - Bmemmove(osdhistorybuf[1], osdhistorybuf[0], HISTORYDEPTH*(EDITLENGTH+1)); - Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1); - if (osdhistorysize < HISTORYDEPTH) osdhistorysize++; - if (osdexeccount == HISTORYDEPTH) - OSD_Printf("Command Buffer Warning: Failed queueing command " - "for execution. Buffer full.\n"); - else - osdexeccount++; - osdhistorypos=-1; - } + if (j > 0) + tabc = findsymbol(osdedittmp, NULL); + } else { + tabc = findsymbol(osdedittmp, lastmatch->next); + if (!tabc && lastmatch) + tabc = findsymbol(osdedittmp, NULL); // wrap + } - osdeditlen=0; - osdeditcursor=0; - osdeditwinstart=0; - osdeditwinend=editlinewidth; - } else if (ch == 16) { // control p, previous (ie. up arrow) - } else if (ch == 20) { // control t, swap previous two chars - } else if (ch == 21) { // control u, delete all to beginning - if (osdeditcursor>0 && osdeditlen) { - if (osdeditcursor0 && osdeditlen>0) { - i=osdeditcursor; - while (i>0 && osdeditbuf[i-1]==32) i--; - while (i>0 && osdeditbuf[i-1]!=32) i--; - if (osdeditcursor= 32) { // text char - if (!osdovertype && osdeditlen == EDITLENGTH) // buffer full, can't insert another char - return 0; + if (tabc) { + for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break; + osdeditlen = i; + for (j=0;tabc->name[j] && osdeditlen <= EDITLENGTH;i++,j++,osdeditlen++) + osdeditbuf[i] = tabc->name[j]; + osdeditcursor = osdeditlen; + osdeditwinend = osdeditcursor; + osdeditwinstart = osdeditwinend-editlinewidth; + if (osdeditwinstart<0) { + osdeditwinstart=0; + osdeditwinend = editlinewidth; + } - if (!osdovertype) { - if (osdeditcursor < osdeditlen) - Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor); - osdeditlen++; - } else { - if (osdeditcursor == osdeditlen) - osdeditlen++; - } - osdeditbuf[osdeditcursor] = ch; - osdeditcursor++; - if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++; - } - } + lastmatch = tabc; + } + } else if (ch == 11) { // control k, delete all to end of line + } else if (ch == 12) { // control l, clear screen + } else if (ch == 13) { // control m, enter + if (osdeditlen>0) { + osdeditbuf[osdeditlen] = 0; + Bmemmove(osdhistorybuf[1], osdhistorybuf[0], HISTORYDEPTH*(EDITLENGTH+1)); + Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1); + if (osdhistorysize < HISTORYDEPTH) osdhistorysize++; + if (osdexeccount == HISTORYDEPTH) + OSD_Printf("Command Buffer Warning: Failed queueing command " + "for execution. Buffer full.\n"); + else + osdexeccount++; + osdhistorypos=-1; + } - if (sc == 15) { // tab - } else if (sc == 1) { // escape - OSD_ShowDisplay(0); - } else if (sc == 201) { // page up - if (osdhead < osdlines-1) - osdhead++; - } else if (sc == 209) { // page down - if (osdhead > 0) - osdhead--; - } else if (sc == 199) { // home - if (osdeditcontrol) { - osdhead = osdlines-1; - } else { - osdeditcursor = 0; - osdeditwinstart = osdeditcursor; - osdeditwinend = osdeditwinstart+editlinewidth; - } - } else if (sc == 207) { // end - if (osdeditcontrol) { - osdhead = 0; - } else { - osdeditcursor = osdeditlen; - osdeditwinend = osdeditcursor; - osdeditwinstart = osdeditwinend-editlinewidth; - if (osdeditwinstart<0) { - osdeditwinstart=0; - osdeditwinend = editlinewidth; - } - } - } else if (sc == 210) { // insert - osdovertype ^= 1; - } else if (sc == 203) { // left - if (osdeditcursor>0) { - if (osdeditcontrol) { - while (osdeditcursor>0) { - if (osdeditbuf[osdeditcursor-1] != 32) break; - osdeditcursor--; - } - while (osdeditcursor>0) { - if (osdeditbuf[osdeditcursor-1] == 32) break; - osdeditcursor--; - } - } else osdeditcursor--; - } - if (osdeditcursor=osdeditwinend) - osdeditwinstart+=(osdeditcursor-osdeditwinend), - osdeditwinend+=(osdeditcursor-osdeditwinend); - } else if (sc == 200) { // up - if (osdhistorypos < osdhistorysize-1) { - osdhistorypos++; - memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1); - osdeditlen = osdeditcursor = 0; - while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++; - if (osdeditcursor=osdeditwinend) - osdeditwinstart+=(osdeditcursor-osdeditwinend), - osdeditwinend+=(osdeditcursor-osdeditwinend); - } - } else if (sc == 208) { // down - if (osdhistorypos >= 0) { - if (osdhistorypos == 0) { - osdeditlen=0; - osdeditcursor=0; - osdeditwinstart=0; - osdeditwinend=editlinewidth; - osdhistorypos = -1; - } else { - osdhistorypos--; - memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1); - osdeditlen = osdeditcursor = 0; - while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++; - if (osdeditcursor=osdeditwinend) - osdeditwinstart+=(osdeditcursor-osdeditwinend), - osdeditwinend+=(osdeditcursor-osdeditwinend); - } - } - } else if (sc == 42 || sc == 54) { // shift - osdeditshift = 1; - } else if (sc == 29 || sc == 157) { // control - osdeditcontrol = 1; - } else if (sc == 58) { // capslock - osdeditcaps ^= 1; - } else if (sc == 28 || sc == 156) { // enter - } else if (sc == 14) { // backspace - } else if (sc == 211) { // delete - if (osdeditcursor == osdeditlen || !osdeditlen) return 0; - if (osdeditcursor <= osdeditlen-1) Bmemmove(osdeditbuf+osdeditcursor, osdeditbuf+osdeditcursor+1, osdeditlen-osdeditcursor-1); - osdeditlen--; - } - - return 0; + osdeditlen=0; + osdeditcursor=0; + osdeditwinstart=0; + osdeditwinend=editlinewidth; + } else if (ch == 16) { // control p, previous (ie. up arrow) + } else if (ch == 20) { // control t, swap previous two chars + } else if (ch == 21) { // control u, delete all to beginning + if (osdeditcursor>0 && osdeditlen) { + if (osdeditcursor0 && osdeditlen>0) { + i=osdeditcursor; + while (i>0 && osdeditbuf[i-1]==32) i--; + while (i>0 && osdeditbuf[i-1]!=32) i--; + if (osdeditcursor= 32) { // text char + if (!osdovertype && osdeditlen == EDITLENGTH) // buffer full, can't insert another char + return 0; + + if (!osdovertype) { + if (osdeditcursor < osdeditlen) + Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor); + osdeditlen++; + } else { + if (osdeditcursor == osdeditlen) + osdeditlen++; + } + osdeditbuf[osdeditcursor] = ch; + osdeditcursor++; + if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++; + } + } + + if (sc == 15) { // tab + } else if (sc == 1) { // escape + OSD_ShowDisplay(0); + } else if (sc == 201) { // page up + if (osdhead < osdlines-1) + osdhead++; + } else if (sc == 209) { // page down + if (osdhead > 0) + osdhead--; + } else if (sc == 199) { // home + if (osdeditcontrol) { + osdhead = osdlines-1; + } else { + osdeditcursor = 0; + osdeditwinstart = osdeditcursor; + osdeditwinend = osdeditwinstart+editlinewidth; + } + } else if (sc == 207) { // end + if (osdeditcontrol) { + osdhead = 0; + } else { + osdeditcursor = osdeditlen; + osdeditwinend = osdeditcursor; + osdeditwinstart = osdeditwinend-editlinewidth; + if (osdeditwinstart<0) { + osdeditwinstart=0; + osdeditwinend = editlinewidth; + } + } + } else if (sc == 210) { // insert + osdovertype ^= 1; + } else if (sc == 203) { // left + if (osdeditcursor>0) { + if (osdeditcontrol) { + while (osdeditcursor>0) { + if (osdeditbuf[osdeditcursor-1] != 32) break; + osdeditcursor--; + } + while (osdeditcursor>0) { + if (osdeditbuf[osdeditcursor-1] == 32) break; + osdeditcursor--; + } + } else osdeditcursor--; + } + if (osdeditcursor=osdeditwinend) + osdeditwinstart+=(osdeditcursor-osdeditwinend), + osdeditwinend+=(osdeditcursor-osdeditwinend); + } else if (sc == 200) { // up + if (osdhistorypos < osdhistorysize-1) { + osdhistorypos++; + memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1); + osdeditlen = osdeditcursor = 0; + while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++; + if (osdeditcursor=osdeditwinend) + osdeditwinstart+=(osdeditcursor-osdeditwinend), + osdeditwinend+=(osdeditcursor-osdeditwinend); + } + } else if (sc == 208) { // down + if (osdhistorypos >= 0) { + if (osdhistorypos == 0) { + osdeditlen=0; + osdeditcursor=0; + osdeditwinstart=0; + osdeditwinend=editlinewidth; + osdhistorypos = -1; + } else { + osdhistorypos--; + memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1); + osdeditlen = osdeditcursor = 0; + while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++; + if (osdeditcursor=osdeditwinend) + osdeditwinstart+=(osdeditcursor-osdeditwinend), + osdeditwinend+=(osdeditcursor-osdeditwinend); + } + } + } else if (sc == 42 || sc == 54) { // shift + osdeditshift = 1; + } else if (sc == 29 || sc == 157) { // control + osdeditcontrol = 1; + } else if (sc == 58) { // capslock + osdeditcaps ^= 1; + } else if (sc == 28 || sc == 156) { // enter + } else if (sc == 14) { // backspace + } else if (sc == 211) { // delete + if (osdeditcursor == osdeditlen || !osdeditlen) return 0; + if (osdeditcursor <= osdeditlen-1) Bmemmove(osdeditbuf+osdeditcursor, osdeditbuf+osdeditcursor+1, osdeditlen-osdeditcursor-1); + osdeditlen--; + } + + return 0; } @@ -616,34 +616,34 @@ int OSD_HandleKey(int sc, int press) // void OSD_ResizeDisplay(int w, int h) { - int newcols; - int newmaxlines; - char newtext[TEXTSIZE]; - int i,j,k; + int newcols; + int newmaxlines; + char newtext[TEXTSIZE]; + int i,j,k; - newcols = getcolumnwidth(w); - newmaxlines = TEXTSIZE / newcols; + newcols = getcolumnwidth(w); + newmaxlines = TEXTSIZE / newcols; - j = min(newmaxlines, osdmaxlines); - k = min(newcols, osdcols); + j = min(newmaxlines, osdmaxlines); + k = min(newcols, osdcols); - memset(newtext, 32, TEXTSIZE); - for (i=0;i osdmaxrows) osdrows = osdmaxrows; - - osdpos = 0; - osdhead = 0; - osdeditwinstart = 0; - osdeditwinend = editlinewidth; - white = -1; + memcpy(osdtext, newtext, TEXTSIZE); + osdcols = newcols; + osdmaxlines = newmaxlines; + osdmaxrows = getrowheight(h)-2; + + if (osdrows > osdmaxrows) osdrows = osdmaxrows; + + osdpos = 0; + osdhead = 0; + osdeditwinstart = 0; + osdeditwinend = editlinewidth; + white = -1; } @@ -652,13 +652,13 @@ void OSD_ResizeDisplay(int w, int h) // void OSD_ShowDisplay(int onf) { - osdvisible = (onf != 0); - osdeditcontrol = 0; - osdeditshift = 0; + osdvisible = (onf != 0); + osdeditcontrol = 0; + osdeditshift = 0; - grabmouse(osdvisible == 0); - onshowosd(osdvisible); - if (osdvisible) releaseallbuttons(); + grabmouse(osdvisible == 0); + onshowosd(osdvisible); + if (osdvisible) releaseallbuttons(); } @@ -667,35 +667,35 @@ void OSD_ShowDisplay(int onf) // void OSD_Draw(void) { - unsigned topoffs; - int row, lines, x, len; - - if (!osdvisible || !osdinited) return; + unsigned topoffs; + int row, lines, x, len; - topoffs = osdhead * osdcols; - row = osdrows-1; - lines = min( osdlines-osdhead, osdrows ); - - begindrawing(); + if (!osdvisible || !osdinited) return; - clearbackground(osdcols,osdrows+1); + topoffs = osdhead * osdcols; + row = osdrows-1; + lines = min( osdlines-osdhead, osdrows ); - for (; lines>0; lines--, row--) { - drawosdstr(0,row,osdtext+topoffs,osdcols,osdtextshade,osdtextpal); - topoffs+=osdcols; - } + begindrawing(); - drawosdchar(2,osdrows,'>',osdpromptshade,osdpromptpal); - if (osdeditcaps) drawosdchar(0,osdrows,'C',osdpromptshade,osdpromptpal); - if (osdeditshift) drawosdchar(1,osdrows,'H',osdpromptshade,osdpromptpal); - - len = min(osdcols-1-3, osdeditlen-osdeditwinstart); - for (x=0; x0; lines--, row--) { + drawosdstr(0,row,osdtext+topoffs,osdcols,osdtextshade,osdtextpal); + topoffs+=osdcols; + } + + drawosdchar(2,osdrows,'>',osdpromptshade,osdpromptpal); + if (osdeditcaps) drawosdchar(0,osdrows,'C',osdpromptshade,osdpromptpal); + if (osdeditshift) drawosdchar(1,osdrows,'H',osdpromptshade,osdpromptpal); + + len = min(osdcols-1-3, osdeditlen-osdeditwinstart); + for (x=0; x=0; cmd--) { - OSD_Dispatch((const char *)osdhistorybuf[cmd]); - } + cmd=osdexeccount-1; + osdexeccount=0; + + for (; cmd>=0; cmd--) { + OSD_Dispatch((const char *)osdhistorybuf[cmd]); + } } @@ -765,127 +765,127 @@ void OSD_DispatchQueued(void) static char *strtoken(char *s, char **ptrptr, int *restart) { - char *p, *p2, *start; - - *restart = 0; - if (!ptrptr) return NULL; - - // if s != NULL, we process from the start of s, otherwise - // we just continue with where ptrptr points to - if (s) p = s; - else p = *ptrptr; - - if (!p) return NULL; - - // eat up any leading whitespace - while (*p != 0 && *p != ';' && *p == ' ') p++; - - // a semicolon is an end of statement delimiter like a \0 is, so we signal - // the caller to 'restart' for the rest of the string pointed at by *ptrptr - if (*p == ';') { - *restart = 1; - *ptrptr = p+1; - return NULL; - } - // or if we hit the end of the input, signal all done by nulling *ptrptr - else if (*p == 0) { - *ptrptr = NULL; - return NULL; - } - - if (*p == '\"') { - // quoted string - start = ++p; - p2 = p; - while (*p != 0) { - if (*p == '\"') { - p++; - break; - } else if (*p == '\\') { - switch (*(++p)) { - case 'n': *p2 = '\n'; break; - case 'r': *p2 = '\r'; break; - default: *p2 = *p; break; - } - } else { - *p2 = *p; - } - p2++, p++; - } - *p2 = 0; - } else { - start = p; - while (*p != 0 && *p != ';' && *p != ' ') p++; - } - - // if we hit the end of input, signal all done by nulling *ptrptr - if (*p == 0) { - *ptrptr = NULL; - } - // or if we came upon a semicolon, signal caller to restart with the - // string at *ptrptr - else if (*p == ';') { - *p = 0; - *ptrptr = p+1; - *restart = 1; - } - // otherwise, clip off the token and carry on - else { - *(p++) = 0; - *ptrptr = p; - } - - return start; + char *p, *p2, *start; + + *restart = 0; + if (!ptrptr) return NULL; + + // if s != NULL, we process from the start of s, otherwise + // we just continue with where ptrptr points to + if (s) p = s; + else p = *ptrptr; + + if (!p) return NULL; + + // eat up any leading whitespace + while (*p != 0 && *p != ';' && *p == ' ') p++; + + // a semicolon is an end of statement delimiter like a \0 is, so we signal + // the caller to 'restart' for the rest of the string pointed at by *ptrptr + if (*p == ';') { + *restart = 1; + *ptrptr = p+1; + return NULL; + } + // or if we hit the end of the input, signal all done by nulling *ptrptr + else if (*p == 0) { + *ptrptr = NULL; + return NULL; + } + + if (*p == '\"') { + // quoted string + start = ++p; + p2 = p; + while (*p != 0) { + if (*p == '\"') { + p++; + break; + } else if (*p == '\\') { + switch (*(++p)) { + case 'n': *p2 = '\n'; break; + case 'r': *p2 = '\r'; break; + default: *p2 = *p; break; + } + } else { + *p2 = *p; + } + p2++, p++; + } + *p2 = 0; + } else { + start = p; + while (*p != 0 && *p != ';' && *p != ' ') p++; + } + + // if we hit the end of input, signal all done by nulling *ptrptr + if (*p == 0) { + *ptrptr = NULL; + } + // or if we came upon a semicolon, signal caller to restart with the + // string at *ptrptr + else if (*p == ';') { + *p = 0; + *ptrptr = p+1; + *restart = 1; + } + // otherwise, clip off the token and carry on + else { + *(p++) = 0; + *ptrptr = p; + } + + return start; } #define MAXPARMS 512 int OSD_Dispatch(const char *cmd) { - char *workbuf, *wp, *wtp, *state; - char *parms[MAXPARMS]; - int numparms, restart = 0; - osdfuncparm_t ofp; - symbol_t *symb; - //int i; - - workbuf = state = Bstrdup(cmd); - if (!workbuf) return -1; + char *workbuf, *wp, *wtp, *state; + char *parms[MAXPARMS]; + int numparms, restart = 0; + osdfuncparm_t ofp; + symbol_t *symb; + //int i; - do { - numparms = 0; - Bmemset(parms, 0, sizeof(parms)); - wp = strtoken(state, &wtp, &restart); - if (!wp) { - state = wtp; - continue; - } + workbuf = state = Bstrdup(cmd); + if (!workbuf) return -1; - symb = findexactsymbol(wp); - if (!symb) { - OSD_Printf("Error: \"%s\" is not defined\n", wp); - free(workbuf); - return -1; - } - - ofp.name = wp; - while (wtp && !restart) { - wp = strtoken(NULL, &wtp, &restart); - if (wp && numparms < MAXPARMS) parms[numparms++] = wp; - } - ofp.numparms = numparms; - ofp.parms = (const char **)parms; - ofp.raw = cmd; - switch (symb->func(&ofp)) { - case OSDCMD_OK: break; - case OSDCMD_SHOWHELP: OSD_Printf("%s\n", symb->help); break; - } - - state = wtp; - } while (wtp && restart); - - free(workbuf); - - return 0; + do { + numparms = 0; + Bmemset(parms, 0, sizeof(parms)); + wp = strtoken(state, &wtp, &restart); + if (!wp) { + state = wtp; + continue; + } + + symb = findexactsymbol(wp); + if (!symb) { + OSD_Printf("Error: \"%s\" is not defined\n", wp); + free(workbuf); + return -1; + } + + ofp.name = wp; + while (wtp && !restart) { + wp = strtoken(NULL, &wtp, &restart); + if (wp && numparms < MAXPARMS) parms[numparms++] = wp; + } + ofp.numparms = numparms; + ofp.parms = (const char **)parms; + ofp.raw = cmd; + switch (symb->func(&ofp)) { + case OSDCMD_OK: break; + case OSDCMD_SHOWHELP: OSD_Printf("%s\n", symb->help); break; + } + + state = wtp; + } while (wtp && restart); + + free(workbuf); + + return 0; } @@ -894,58 +894,58 @@ int OSD_Dispatch(const char *cmd) // int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const osdfuncparm_t*)) { - symbol_t *symb; - const char *cp; + symbol_t *symb; + const char *cp; - if (!osdinited) OSD_Init(); + if (!osdinited) OSD_Init(); - if (!name) { - Bprintf("OSD_RegisterFunction(): may not register a function with a null name\n"); - return -1; - } - if (!name[0]) { - Bprintf("OSD_RegisterFunction(): may not register a function with no name\n"); - return -1; - } + if (!name) { + Bprintf("OSD_RegisterFunction(): may not register a function with a null name\n"); + return -1; + } + if (!name[0]) { + Bprintf("OSD_RegisterFunction(): may not register a function with no name\n"); + return -1; + } - // check for illegal characters in name - for (cp = name; *cp; cp++) { - if ((cp == name) && (*cp >= '0') && (*cp <= '9')) { - Bprintf("OSD_RegisterFunction(): first character of function name \"%s\" must not be a numeral\n", name); - return -1; - } - if ((*cp < '0') || - (*cp > '9' && *cp < 'A') || - (*cp > 'Z' && *cp < 'a' && *cp != '_') || - (*cp > 'z')) { - Bprintf("OSD_RegisterFunction(): illegal character in function name \"%s\"\n", name); - return -1; - } - } + // check for illegal characters in name + for (cp = name; *cp; cp++) { + if ((cp == name) && (*cp >= '0') && (*cp <= '9')) { + Bprintf("OSD_RegisterFunction(): first character of function name \"%s\" must not be a numeral\n", name); + return -1; + } + if ((*cp < '0') || + (*cp > '9' && *cp < 'A') || + (*cp > 'Z' && *cp < 'a' && *cp != '_') || + (*cp > 'z')) { + Bprintf("OSD_RegisterFunction(): illegal character in function name \"%s\"\n", name); + return -1; + } + } - if (!help) help = "(no description for this function)"; - if (!func) { - Bprintf("OSD_RegisterFunction(): may not register a null function\n"); - return -1; - } + if (!help) help = "(no description for this function)"; + if (!func) { + Bprintf("OSD_RegisterFunction(): may not register a null function\n"); + return -1; + } - symb = findexactsymbol(name); - if (symb) { - Bprintf("OSD_RegisterFunction(): \"%s\" is already defined\n", name); - return -1; - } - - symb = addnewsymbol(name); - if (!symb) { - Bprintf("OSD_RegisterFunction(): Failed registering function \"%s\"\n", name); - return -1; - } + symb = findexactsymbol(name); + if (symb) { + Bprintf("OSD_RegisterFunction(): \"%s\" is already defined\n", name); + return -1; + } - symb->name = name; - symb->help = help; - symb->func = func; + symb = addnewsymbol(name); + if (!symb) { + Bprintf("OSD_RegisterFunction(): Failed registering function \"%s\"\n", name); + return -1; + } - return 0; + symb->name = name; + symb->help = help; + symb->func = func; + + return 0; } @@ -955,64 +955,64 @@ int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const o // static symbol_t *addnewsymbol(const char *name) { - symbol_t *newsymb, *s, *t; + symbol_t *newsymb, *s, *t; - newsymb = (symbol_t *)Bmalloc(sizeof(symbol_t)); - if (!newsymb) { return NULL; } - Bmemset(newsymb, 0, sizeof(symbol_t)); + newsymb = (symbol_t *)Bmalloc(sizeof(symbol_t)); + if (!newsymb) { return NULL; } + Bmemset(newsymb, 0, sizeof(symbol_t)); - // link it to the main chain - if (!symbols) { - symbols = newsymb; - } else { - if (Bstrcasecmp(name, symbols->name) <= 0) { - t = symbols; - symbols = newsymb; - symbols->next = t; - } else { - s = symbols; - while (s->next) { - if (Bstrcasecmp(s->next->name, name) > 0) break; - s=s->next; - } - t = s->next; - s->next = newsymb; - newsymb->next = t; - } - } + // link it to the main chain + if (!symbols) { + symbols = newsymb; + } else { + if (Bstrcasecmp(name, symbols->name) <= 0) { + t = symbols; + symbols = newsymb; + symbols->next = t; + } else { + s = symbols; + while (s->next) { + if (Bstrcasecmp(s->next->name, name) > 0) break; + s=s->next; + } + t = s->next; + s->next = newsymb; + newsymb->next = t; + } + } - return newsymb; + return newsymb; } // // findsymbol() -- Finds a symbol, possibly partially named -// +// static symbol_t *findsymbol(const char *name, symbol_t *startingat) { - if (!startingat) startingat = symbols; - if (!startingat) return NULL; + if (!startingat) startingat = symbols; + if (!startingat) return NULL; - for (; startingat; startingat=startingat->next) - if (!Bstrncasecmp(name, startingat->name, Bstrlen(name))) return startingat; + for (; startingat; startingat=startingat->next) + if (!Bstrncasecmp(name, startingat->name, Bstrlen(name))) return startingat; - return NULL; + return NULL; } // // findexactsymbol() -- Finds a symbol, complete named -// +// static symbol_t *findexactsymbol(const char *name) { - symbol_t *startingat; - if (!symbols) return NULL; + symbol_t *startingat; + if (!symbols) return NULL; - startingat = symbols; + startingat = symbols; - for (; startingat; startingat=startingat->next) - if (!Bstrcasecmp(name, startingat->name)) return startingat; + for (; startingat; startingat=startingat->next) + if (!Bstrcasecmp(name, startingat->name)) return startingat; - return NULL; + return NULL; } diff --git a/polymer/build/src/polymer.c b/polymer/build/src/polymer.c index a305e432c..d44333aa1 100644 --- a/polymer/build/src/polymer.c +++ b/polymer/build/src/polymer.c @@ -18,7 +18,7 @@ void polymer_drawsector(short sectnum) { sectortype *sec; walltype *wal; - + sec = §or[sectnum]; wal = &wall[sec->wallptr]; OSD_Printf("%i\n", sec->wallnum); diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 733c8c99c..0328971b9 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -102,16 +102,16 @@ long glredbluemode = 0; static long lastglredbluemode = 0, redblueclearcnt = 0; static struct glfiltermodes { - char *name; - long min,mag; + char *name; + long min,mag; } glfiltermodes[] = { - {"GL_NEAREST",GL_NEAREST,GL_NEAREST}, - {"GL_LINEAR",GL_LINEAR,GL_LINEAR}, - {"GL_NEAREST_MIPMAP_NEAREST",GL_NEAREST_MIPMAP_NEAREST,GL_NEAREST}, - {"GL_LINEAR_MIPMAP_NEAREST",GL_LINEAR_MIPMAP_NEAREST,GL_LINEAR}, - {"GL_NEAREST_MIPMAP_LINEAR",GL_NEAREST_MIPMAP_LINEAR,GL_NEAREST}, - {"GL_LINEAR_MIPMAP_LINEAR",GL_LINEAR_MIPMAP_LINEAR,GL_LINEAR} -}; + {"GL_NEAREST",GL_NEAREST,GL_NEAREST}, + {"GL_LINEAR",GL_LINEAR,GL_LINEAR}, + {"GL_NEAREST_MIPMAP_NEAREST",GL_NEAREST_MIPMAP_NEAREST,GL_NEAREST}, + {"GL_LINEAR_MIPMAP_NEAREST",GL_LINEAR_MIPMAP_NEAREST,GL_LINEAR}, + {"GL_NEAREST_MIPMAP_LINEAR",GL_NEAREST_MIPMAP_LINEAR,GL_NEAREST}, + {"GL_LINEAR_MIPMAP_LINEAR",GL_LINEAR_MIPMAP_LINEAR,GL_LINEAR} + }; #define numglfiltermodes (sizeof(glfiltermodes)/sizeof(glfiltermodes[0])) long glanisotropy = 1; // 0 = maximum supported by card @@ -132,22 +132,22 @@ extern char nofog; #if defined(USE_MSC_PRAGMAS) static inline void ftol (float f, long *a) { - _asm - { - mov eax, a - fld f - fistp dword ptr [eax] - } + _asm + { + mov eax, a + fld f + fistp dword ptr [eax] + } } static inline void dtol (double d, long *a) { - _asm - { - mov eax, a - fld d - fistp dword ptr [eax] - } + _asm + { + mov eax, a + fld d + fistp dword ptr [eax] + } } #elif defined(USE_WATCOM_PRAGMAS) @@ -162,81 +162,81 @@ static inline void dtol (double d, long *a) static inline void ftol (float f, long *a) { - __asm__ __volatile__ ( + __asm__ __volatile__ ( #if 0 //(__GNUC__ >= 3) - "flds %1; fistpl %0;" + "flds %1; fistpl %0;" #else - "flds %1; fistpl (%0);" +"flds %1; fistpl (%0);" #endif - : "=r" (a) : "m" (f) : "memory","cc"); + : "=r" (a) : "m" (f) : "memory","cc"); } static inline void dtol (double d, long *a) { - __asm__ __volatile__ ( + __asm__ __volatile__ ( #if 0 //(__GNUC__ >= 3) - "fldl %1; fistpl %0;" + "fldl %1; fistpl %0;" #else - "fldl %1; fistpl (%0);" +"fldl %1; fistpl (%0);" #endif - : "=r" (a) : "m" (d) : "memory","cc"); + : "=r" (a) : "m" (d) : "memory","cc"); } #else static inline void ftol (float f, long *a) { - *a = (long)f; + *a = (long)f; } static inline void dtol (double d, long *a) { - *a = (long)d; + *a = (long)d; } #endif static inline long imod (long a, long b) { - if (a >= 0) return(a%b); - return(((a+1)%b)+b-1); + if (a >= 0) return(a%b); + return(((a+1)%b)+b-1); } void drawline2d (float x0, float y0, float x1, float y1, char col) { - float f, dx, dy, fxres, fyres; - long e, inc, x, y; - unsigned long up16; + float f, dx, dy, fxres, fyres; + long e, inc, x, y; + unsigned long up16; - dx = x1-x0; dy = y1-y0; if ((dx == 0) && (dy == 0)) return; - fxres = (float)xdimen; fyres = (float)ydimen; - if (x0 >= fxres) { if (x1 >= fxres) return; y0 += (fxres-x0)*dy/dx; x0 = fxres; } - else if (x0 < 0) { if (x1 < 0) return; y0 += ( 0-x0)*dy/dx; x0 = 0; } - if (x1 >= fxres) { y1 += (fxres-x1)*dy/dx; x1 = fxres; } - else if (x1 < 0) { y1 += ( 0-x1)*dy/dx; x1 = 0; } - if (y0 >= fyres) { if (y1 >= fyres) return; x0 += (fyres-y0)*dx/dy; y0 = fyres; } - else if (y0 < 0) { if (y1 < 0) return; x0 += ( 0-y0)*dx/dy; y0 = 0; } - if (y1 >= fyres) { x1 += (fyres-y1)*dx/dy; y1 = fyres; } - else if (y1 < 0) { x1 += ( 0-y1)*dx/dy; y1 = 0; } + dx = x1-x0; dy = y1-y0; if ((dx == 0) && (dy == 0)) return; + fxres = (float)xdimen; fyres = (float)ydimen; +if (x0 >= fxres) { if (x1 >= fxres) return; y0 += (fxres-x0)*dy/dx; x0 = fxres; } +else if (x0 < 0) { if (x1 < 0) return; y0 += ( 0-x0)*dy/dx; x0 = 0; } +if (x1 >= fxres) { y1 += (fxres-x1)*dy/dx; x1 = fxres; } + else if (x1 < 0) { y1 += ( 0-x1)*dy/dx; x1 = 0; } + if (y0 >= fyres) { if (y1 >= fyres) return; x0 += (fyres-y0)*dx/dy; y0 = fyres; } +else if (y0 < 0) { if (y1 < 0) return; x0 += ( 0-y0)*dx/dy; y0 = 0; } +if (y1 >= fyres) { x1 += (fyres-y1)*dx/dy; y1 = fyres; } + else if (y1 < 0) { x1 += ( 0-y1)*dx/dy; y1 = 0; } - if (fabs(dx) > fabs(dy)) - { - if (x0 > x1) { f = x0; x0 = x1; x1 = f; f = y0; y0 = y1; y1 = f; } - y = (long)(y0*65536.f)+32768; - inc = (long)(dy/dx*65536.f+.5f); - x = (long)(x0+.5); if (x < 0) { y -= inc*x; x = 0; } //if for safety - e = (long)(x1+.5); if (e > xdimen) e = xdimen; //if for safety - up16 = (ydimen<<16); - for(;x>16]+x+frameoffset) = col; - } - else - { - if (y0 > y1) { f = x0; x0 = x1; x1 = f; f = y0; y0 = y1; y1 = f; } - x = (long)(x0*65536.f)+32768; - inc = (long)(dx/dy*65536.f+.5f); - y = (long)(y0+.5); if (y < 0) { x -= inc*y; y = 0; } //if for safety - e = (long)(y1+.5); if (e > ydimen) e = ydimen; //if for safety - up16 = (xdimen<<16); - for(;y>16)+frameoffset) = col; - } + if (fabs(dx) > fabs(dy)) + { + if (x0 > x1) { f = x0; x0 = x1; x1 = f; f = y0; y0 = y1; y1 = f; } + y = (long)(y0*65536.f)+32768; + inc = (long)(dy/dx*65536.f+.5f); + x = (long)(x0+.5); if (x < 0) { y -= inc*x; x = 0; } //if for safety + e = (long)(x1+.5); if (e > xdimen) e = xdimen; //if for safety + up16 = (ydimen<<16); + for(;x>16]+x+frameoffset) = col; + } + else + { + if (y0 > y1) { f = x0; x0 = x1; x1 = f; f = y0; y0 = y1; y1 = f; } + x = (long)(x0*65536.f)+32768; + inc = (long)(dx/dy*65536.f+.5f); + y = (long)(y0+.5); if (y < 0) { x -= inc*y; y = 0; } //if for safety + e = (long)(y1+.5); if (e > ydimen) e = ydimen; //if for safety + up16 = (xdimen<<16); + for(;y>16)+frameoffset) = col; + } } #ifdef USE_OPENGL @@ -257,15 +257,15 @@ static void uploadtexture(long doalloc, long xsiz, long ysiz, long intexfmt, lon static char TEXCACHEDIR[] = "texcache"; typedef struct { - char magic[8]; // 'Polymost' - long xdim, ydim; // of image, unpadded - long flags; // 1 = !2^x, 2 = has alpha, 4 = lzw compressed + char magic[8]; // 'Polymost' + long xdim, ydim; // of image, unpadded + long flags; // 1 = !2^x, 2 = has alpha, 4 = lzw compressed } texcacheheader; typedef struct { - long size; - long format; - long xdim, ydim; // of mipmap (possibly padded) - long border, depth; + long size; + long format; + long xdim, ydim; // of mipmap (possibly padded) + long border, depth; } texcachepicture; int dxtfilter(int fil, texcachepicture *pict, char *pic, void *midbuf, char *packbuf, unsigned long miplen); @@ -286,17 +286,17 @@ float alphahackarray[MAXTILES]; typedef struct pthtyp_t { - struct pthtyp_t *next; - GLuint glpic; - short picnum; - char palnum; - char effects; - char flags; // 1 = clamped (dameth&4), 2 = hightile, 4 = skybox face, 8 = hasalpha, 128 = invalidated - char skyface; - hicreplctyp *hicr; + struct pthtyp_t *next; + GLuint glpic; + short picnum; + char palnum; + char effects; + char flags; // 1 = clamped (dameth&4), 2 = hightile, 4 = skybox face, 8 = hasalpha, 128 = invalidated + char skyface; + hicreplctyp *hicr; - unsigned short sizx, sizy; - float scalex, scaley; + unsigned short sizx, sizy; + float scalex, scaley; } pthtyp; #define GLTEXCACHEADSIZ 8192 @@ -309,4325 +309,4325 @@ int gloadtile_hi(long,long,hicreplctyp*,long,pthtyp*,long,char); static int hicprecaching = 0; static pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth) { - long i, j; - hicreplctyp *si; - pthtyp *pth; + long i, j; + hicreplctyp *si; + pthtyp *pth; - j = (dapicnum&(GLTEXCACHEADSIZ-1)); + j = (dapicnum&(GLTEXCACHEADSIZ-1)); - if (usehightile) si = hicfindsubst(dapicnum,dapalnum,drawingskybox); - else si = NULL; - if (!si) { - if (drawingskybox) return NULL; - goto tryart; - } + if (usehightile) si = hicfindsubst(dapicnum,dapalnum,drawingskybox); + else si = NULL; + if (!si) { + if (drawingskybox) return NULL; + goto tryart; + } - /* if palette > 0 && replacement found - * no effects are applied to the texture - * else if palette > 0 && no replacement found - * effects are applied to the palette 0 texture if it exists - */ + /* if palette > 0 && replacement found + * no effects are applied to the texture + * else if palette > 0 && no replacement found + * effects are applied to the palette 0 texture if it exists + */ - // load a replacement - for(pth=gltexcachead[j]; pth; pth=pth->next) { - if (pth->picnum == dapicnum && - pth->palnum == si->palnum && - (si->palnum>0 ? 1 : (pth->effects == hictinting[dapalnum].f)) && - (pth->flags & (1+2+4)) == (((dameth&4)>>2)+2+((drawingskybox>0)<<2)) && - (drawingskybox>0 ? (pth->skyface == drawingskybox) : 1) - ) - { - if (pth->flags & 128) - { - pth->flags &= ~128; - if (gloadtile_hi(dapicnum,drawingskybox,si,dameth,pth,0, - (si->palnum>0) ? 0 : hictinting[dapalnum].f)) { // reload tile - if (drawingskybox) return NULL; - goto tryart; // failed, so try for ART - } - } - return(pth); - } - } + // load a replacement + for(pth=gltexcachead[j]; pth; pth=pth->next) { + if (pth->picnum == dapicnum && + pth->palnum == si->palnum && + (si->palnum>0 ? 1 : (pth->effects == hictinting[dapalnum].f)) && + (pth->flags & (1+2+4)) == (((dameth&4)>>2)+2+((drawingskybox>0)<<2)) && + (drawingskybox>0 ? (pth->skyface == drawingskybox) : 1) + ) + { + if (pth->flags & 128) + { + pth->flags &= ~128; + if (gloadtile_hi(dapicnum,drawingskybox,si,dameth,pth,0, + (si->palnum>0) ? 0 : hictinting[dapalnum].f)) { // reload tile + if (drawingskybox) return NULL; + goto tryart; // failed, so try for ART + } + } + return(pth); + } + } - pth = (pthtyp *)calloc(1,sizeof(pthtyp)); - if (!pth) return NULL; + pth = (pthtyp *)calloc(1,sizeof(pthtyp)); + if (!pth) return NULL; - if (gloadtile_hi(dapicnum,drawingskybox,si,dameth,pth,1, (si->palnum>0) ? 0 : hictinting[dapalnum].f)) { - free(pth); - if (drawingskybox) return NULL; - goto tryart; // failed, so try for ART - } - pth->palnum = si->palnum; - pth->next = gltexcachead[j]; - gltexcachead[j] = pth; - return(pth); + if (gloadtile_hi(dapicnum,drawingskybox,si,dameth,pth,1, (si->palnum>0) ? 0 : hictinting[dapalnum].f)) { + free(pth); + if (drawingskybox) return NULL; + goto tryart; // failed, so try for ART + } + pth->palnum = si->palnum; + pth->next = gltexcachead[j]; + gltexcachead[j] = pth; + return(pth); tryart: - if (hicprecaching) return NULL; + if (hicprecaching) return NULL; - // load from art - for(pth=gltexcachead[j]; pth; pth=pth->next) - if (pth->picnum == dapicnum && - pth->palnum == dapalnum && - (pth->flags & (1+2)) == ((dameth&4)>>2) - ) - { - if (pth->flags & 128) - { - pth->flags &= ~128; - if (gloadtile_art(dapicnum,dapalnum,dameth,pth,0)) return NULL; //reload tile (for animations) - } - return(pth); - } + // load from art + for(pth=gltexcachead[j]; pth; pth=pth->next) + if (pth->picnum == dapicnum && + pth->palnum == dapalnum && + (pth->flags & (1+2)) == ((dameth&4)>>2) + ) + { + if (pth->flags & 128) + { + pth->flags &= ~128; + if (gloadtile_art(dapicnum,dapalnum,dameth,pth,0)) return NULL; //reload tile (for animations) + } + return(pth); + } - pth = (pthtyp *)calloc(1,sizeof(pthtyp)); - if (!pth) return NULL; + pth = (pthtyp *)calloc(1,sizeof(pthtyp)); + if (!pth) return NULL; - if (gloadtile_art(dapicnum,dapalnum,dameth,pth,1)) { - free(pth); - return NULL; - } - pth->next = gltexcachead[j]; - gltexcachead[j] = pth; - return(pth); + if (gloadtile_art(dapicnum,dapalnum,dameth,pth,1)) { + free(pth); + return NULL; + } + pth->next = gltexcachead[j]; + gltexcachead[j] = pth; + return(pth); } long gltexmayhavealpha (long dapicnum, long dapalnum) { - long j = (dapicnum&(GLTEXCACHEADSIZ-1)); - pthtyp *pth; + long j = (dapicnum&(GLTEXCACHEADSIZ-1)); + pthtyp *pth; - for(pth=gltexcachead[j]; pth; pth=pth->next) - if ((pth->picnum == dapicnum) && (pth->palnum == dapalnum)) - return((pth->flags&8) != 0); - return(1); + for(pth=gltexcachead[j]; pth; pth=pth->next) + if ((pth->picnum == dapicnum) && (pth->palnum == dapalnum)) + return((pth->flags&8) != 0); + return(1); } void gltexinvalidate (long dapicnum, long dapalnum, long dameth) { - long i, j; - pthtyp *pth; + long i, j; + pthtyp *pth; - j = (dapicnum&(GLTEXCACHEADSIZ-1)); - for(pth=gltexcachead[j]; pth; pth=pth->next) - if (pth->picnum == dapicnum && pth->palnum == dapalnum && (pth->flags & 1) == ((dameth&4)>>2) ) - { pth->flags |= 128; } + j = (dapicnum&(GLTEXCACHEADSIZ-1)); + for(pth=gltexcachead[j]; pth; pth=pth->next) + if (pth->picnum == dapicnum && pth->palnum == dapalnum && (pth->flags & 1) == ((dameth&4)>>2) ) + { pth->flags |= 128; } } - //Make all textures "dirty" so they reload, but not re-allocate - //This should be much faster than polymost_glreset() - //Use this for palette effects ... but not ones that change every frame! +//Make all textures "dirty" so they reload, but not re-allocate +//This should be much faster than polymost_glreset() +//Use this for palette effects ... but not ones that change every frame! void gltexinvalidateall () { - long j; - pthtyp *pth; + long j; + pthtyp *pth; - for(j=GLTEXCACHEADSIZ-1;j>=0;j--) - for(pth=gltexcachead[j];pth;pth=pth->next) - pth->flags |= 128; - clearskins(); + for(j=GLTEXCACHEADSIZ-1;j>=0;j--) + for(pth=gltexcachead[j];pth;pth=pth->next) + pth->flags |= 128; + clearskins(); #ifdef DEBUGGINGAIDS - OSD_Printf("gltexinvalidateall()\n"); + OSD_Printf("gltexinvalidateall()\n"); #endif } void gltexapplyprops (void) { - long i; - pthtyp *pth; - - if (glinfo.maxanisotropy > 1.0) - { - if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; - } - - if (gltexfiltermode < 0) gltexfiltermode = 0; - else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; - for(i=GLTEXCACHEADSIZ-1;i>=0;i--) { - for(pth=gltexcachead[i];pth;pth=pth->next) { - bglBindTexture(GL_TEXTURE_2D,pth->glpic); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (glinfo.maxanisotropy > 1.0) - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - } - } + long i; + pthtyp *pth; - { - int j; - mdskinmap_t *sk; - md2model *m; + if (glinfo.maxanisotropy > 1.0) + { + if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; + } - for (i=0;imdnum < 2) continue; - for (j=0;jnumskins*(HICEFFECTMASK+1);j++) - { - if (!m->texid[j]) continue; - bglBindTexture(GL_TEXTURE_2D,m->texid[j]); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (glinfo.maxanisotropy > 1.0) - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - } + if (gltexfiltermode < 0) gltexfiltermode = 0; + else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; + for(i=GLTEXCACHEADSIZ-1;i>=0;i--) { + for(pth=gltexcachead[i];pth;pth=pth->next) { + bglBindTexture(GL_TEXTURE_2D,pth->glpic); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + if (glinfo.maxanisotropy > 1.0) + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + } + } - for (sk=m->skinmap;sk;sk=sk->next) - for (j=0;j<(HICEFFECTMASK+1);j++) - { - if (!sk->texid[j]) continue; - bglBindTexture(GL_TEXTURE_2D,sk->texid[j]); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (glinfo.maxanisotropy > 1.0) - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - } - } - } + { + int j; + mdskinmap_t *sk; + md2model *m; + + for (i=0;imdnum < 2) continue; + for (j=0;jnumskins*(HICEFFECTMASK+1);j++) + { + if (!m->texid[j]) continue; + bglBindTexture(GL_TEXTURE_2D,m->texid[j]); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + if (glinfo.maxanisotropy > 1.0) + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + } + + for (sk=m->skinmap;sk;sk=sk->next) + for (j=0;j<(HICEFFECTMASK+1);j++) + { + if (!sk->texid[j]) continue; + bglBindTexture(GL_TEXTURE_2D,sk->texid[j]); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + if (glinfo.maxanisotropy > 1.0) + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + } + } + } } //-------------------------------------------------------------------------------------------------- static float glox1, gloy1, glox2, gloy2; - //Use this for both initialization and uninitialization of OpenGL. +//Use this for both initialization and uninitialization of OpenGL. static int gltexcacnum = -1; void polymost_glreset () { - long i; - pthtyp *pth, *next; - //Reset if this is -1 (meaning 1st texture call ever), or > 0 (textures in memory) - if (gltexcacnum < 0) - { - gltexcacnum = 0; + long i; + pthtyp *pth, *next; + //Reset if this is -1 (meaning 1st texture call ever), or > 0 (textures in memory) + if (gltexcacnum < 0) + { + gltexcacnum = 0; - //Hack for polymost_dorotatesprite calls before 1st polymost_drawrooms() - gcosang = gcosang2 = ((double)16384)/262144.0; - gsinang = gsinang2 = ((double) 0)/262144.0; - } - else - { - for (i=GLTEXCACHEADSIZ-1; i>=0; i--) { - for (pth=gltexcachead[i]; pth;) { - next = pth->next; - bglDeleteTextures(1,&pth->glpic); - free(pth); - pth = next; - } - gltexcachead[i] = NULL; - } - clearskins(); - } - - if (polymosttext) bglDeleteTextures(1,&polymosttext); - polymosttext=0; - - memset(gltexcachead,0,sizeof(gltexcachead)); - glox1 = -1; + //Hack for polymost_dorotatesprite calls before 1st polymost_drawrooms() + gcosang = gcosang2 = ((double)16384)/262144.0; + gsinang = gsinang2 = ((double) 0)/262144.0; + } + else + { + for (i=GLTEXCACHEADSIZ-1; i>=0; i--) { + for (pth=gltexcachead[i]; pth;) { + next = pth->next; + bglDeleteTextures(1,&pth->glpic); + free(pth); + pth = next; + } + gltexcachead[i] = NULL; + } + clearskins(); + } + + if (polymosttext) bglDeleteTextures(1,&polymosttext); + polymosttext=0; + + memset(gltexcachead,0,sizeof(gltexcachead)); + glox1 = -1; } // one-time initialisation of OpenGL for polymost void polymost_glinit() { - GLfloat col[4]; - - bglFogi(GL_FOG_MODE,GL_EXP); //GL_EXP(default),GL_EXP2,GL_LINEAR - //bglHint(GL_FOG_HINT,GL_NICEST); - bglFogf(GL_FOG_DENSITY,1.0); //must be > 0, default is 1 - bglFogf(GL_FOG_START,0.0); //default is 0 - bglFogf(GL_FOG_END,1.0); //default is 1 - col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; //range:0 to 1 - bglFogfv(GL_FOG_COLOR,col); //default is 0,0,0,0 + GLfloat col[4]; - bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + bglFogi(GL_FOG_MODE,GL_EXP); //GL_EXP(default),GL_EXP2,GL_LINEAR + //bglHint(GL_FOG_HINT,GL_NICEST); + bglFogf(GL_FOG_DENSITY,1.0); //must be > 0, default is 1 + bglFogf(GL_FOG_START,0.0); //default is 0 + bglFogf(GL_FOG_END,1.0); //default is 1 + col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; //range:0 to 1 + bglFogfv(GL_FOG_COLOR,col); //default is 0,0,0,0 - if (glmultisample > 0 && glinfo.multisample) { - if (glinfo.nvmultisamplehint) - bglHint(GL_MULTISAMPLE_FILTER_HINT_NV, glnvmultisamplehint ? GL_NICEST:GL_FASTEST); - bglEnable(GL_MULTISAMPLE_ARB); - } + bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + if (glmultisample > 0 && glinfo.multisample) { + if (glinfo.nvmultisamplehint) + bglHint(GL_MULTISAMPLE_FILTER_HINT_NV, glnvmultisamplehint ? GL_NICEST:GL_FASTEST); + bglEnable(GL_MULTISAMPLE_ARB); + } } void resizeglcheck () { - float m[4][4]; + float m[4][4]; float ratioratio = 1.0; int fovcorrect; - if (glredbluemode < lastglredbluemode) { - glox1 = -1; - bglColorMask(1,1,1,1); - } else if (glredbluemode != lastglredbluemode) { - redblueclearcnt = 0; - } - lastglredbluemode = glredbluemode; + if (glredbluemode < lastglredbluemode) { + glox1 = -1; + bglColorMask(1,1,1,1); + } else if (glredbluemode != lastglredbluemode) { + redblueclearcnt = 0; + } + lastglredbluemode = glredbluemode; - //FUK - if (lastglpolygonmode != glpolygonmode) - { - lastglpolygonmode = glpolygonmode; - switch(glpolygonmode) - { - default: - case 0: bglPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; - case 1: bglPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; - case 2: bglPolygonMode(GL_FRONT_AND_BACK,GL_POINT); break; - } - } - if (glpolygonmode) //FUK - { - bglClearColor(1.0,1.0,1.0,0.0); - bglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - bglDisable(GL_TEXTURE_2D); - } + //FUK + if (lastglpolygonmode != glpolygonmode) + { + lastglpolygonmode = glpolygonmode; + switch(glpolygonmode) + { + default: + case 0: bglPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; + case 1: bglPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; + case 2: bglPolygonMode(GL_FRONT_AND_BACK,GL_POINT); break; + } + } + if (glpolygonmode) //FUK + { + bglClearColor(1.0,1.0,1.0,0.0); + bglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + bglDisable(GL_TEXTURE_2D); + } + + if ((glox1 != windowx1) || (gloy1 != windowy1) || (glox2 != windowx2) || (gloy2 != windowy2)) + { + glox1 = windowx1; gloy1 = windowy1; + glox2 = windowx2; gloy2 = windowy2; - if ((glox1 != windowx1) || (gloy1 != windowy1) || (glox2 != windowx2) || (gloy2 != windowy2)) - { - glox1 = windowx1; gloy1 = windowy1; - glox2 = windowx2; gloy2 = windowy2; - ratioratio = 1.6 / (((float)(windowx2-windowx1+1)) / (windowy2-windowy1)); // computes the ratio between 16/10 and current resolution ratio fovcorrect = (ratioratio > 1) ? (((windowx2-windowx1+1) * ratioratio) - (windowx2-windowx1+1)) * ((float)glratiocorrection / 63) : 0; - bglViewport(windowx1 - (fovcorrect / 2), yres-(windowy2+1),windowx2-windowx1+1 + fovcorrect, windowy2-windowy1+1); + bglViewport(windowx1 - (fovcorrect / 2), yres-(windowy2+1),windowx2-windowx1+1 + fovcorrect, windowy2-windowy1+1); - bglMatrixMode(GL_PROJECTION); - memset(m,0,sizeof(m)); - m[0][0] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); m[0][2] = 1.0; - m[1][1] = (float)xdimen; m[1][2] = 1.0; - m[2][2] = 1.0; m[2][3] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); - m[3][2] =-1.0; - bglLoadMatrixf(&m[0][0]); - //bglLoadIdentity(); + bglMatrixMode(GL_PROJECTION); + memset(m,0,sizeof(m)); + m[0][0] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); m[0][2] = 1.0; + m[1][1] = (float)xdimen; m[1][2] = 1.0; + m[2][2] = 1.0; m[2][3] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); + m[3][2] =-1.0; + bglLoadMatrixf(&m[0][0]); + //bglLoadIdentity(); - bglMatrixMode(GL_MODELVIEW); - bglLoadIdentity(); + bglMatrixMode(GL_MODELVIEW); + bglLoadIdentity(); - if (!nofog) bglEnable(GL_FOG); + if (!nofog) bglEnable(GL_FOG); - //bglEnable(GL_TEXTURE_2D); - } + //bglEnable(GL_TEXTURE_2D); + } } void fixtransparency (coltype *dapic, long daxsiz, long daysiz, long daxsiz2, long daysiz2, long dameth) { - coltype *wpptr; - long j, x, y, r, g, b, dox, doy, naxsiz2; + coltype *wpptr; + long j, x, y, r, g, b, dox, doy, naxsiz2; - dox = daxsiz2-1; doy = daysiz2-1; - if (dameth&4) { dox = min(dox,daxsiz); doy = min(doy,daysiz); } - else { daxsiz = daxsiz2; daysiz = daysiz2; } //Make repeating textures duplicate top/left parts + dox = daxsiz2-1; doy = daysiz2-1; + if (dameth&4) { dox = min(dox,daxsiz); doy = min(doy,daysiz); } + else { daxsiz = daxsiz2; daysiz = daysiz2; } //Make repeating textures duplicate top/left parts - daxsiz--; daysiz--; naxsiz2 = -daxsiz2; //Hacks for optimization inside loop + daxsiz--; daysiz--; naxsiz2 = -daxsiz2; //Hacks for optimization inside loop - //Set transparent pixels to average color of neighboring opaque pixels - //Doing this makes bilinear filtering look much better for masked textures (I.E. sprites) - for(y=doy;y>=0;y--) - { - wpptr = &dapic[y*daxsiz2+dox]; - for(x=dox;x>=0;x--,wpptr--) - { - if (wpptr->a) continue; - r = g = b = j = 0; - if ((x> 0) && (wpptr[ -1].a)) { r += (long)wpptr[ -1].r; g += (long)wpptr[ -1].g; b += (long)wpptr[ -1].b; j++; } - if ((x 0) && (wpptr[naxsiz2].a)) { r += (long)wpptr[naxsiz2].r; g += (long)wpptr[naxsiz2].g; b += (long)wpptr[naxsiz2].b; j++; } - if ((yr = r ; wpptr->g = g ; wpptr->b = b ; break; - case 2: wpptr->r = ((r + 1)>>1); wpptr->g = ((g + 1)>>1); wpptr->b = ((b + 1)>>1); break; - case 3: wpptr->r = ((r*85+128)>>8); wpptr->g = ((g*85+128)>>8); wpptr->b = ((b*85+128)>>8); break; - case 4: wpptr->r = ((r + 2)>>2); wpptr->g = ((g + 2)>>2); wpptr->b = ((b + 2)>>2); break; - default: break; - } - } - } + //Set transparent pixels to average color of neighboring opaque pixels + //Doing this makes bilinear filtering look much better for masked textures (I.E. sprites) + for(y=doy;y>=0;y--) + { + wpptr = &dapic[y*daxsiz2+dox]; + for(x=dox;x>=0;x--,wpptr--) + { + if (wpptr->a) continue; + r = g = b = j = 0; + if ((x> 0) && (wpptr[ -1].a)) { r += (long)wpptr[ -1].r; g += (long)wpptr[ -1].g; b += (long)wpptr[ -1].b; j++; } + if ((x 0) && (wpptr[naxsiz2].a)) { r += (long)wpptr[naxsiz2].r; g += (long)wpptr[naxsiz2].g; b += (long)wpptr[naxsiz2].b; j++; } + if ((yr = r ; wpptr->g = g ; wpptr->b = b ; break; + case 2: wpptr->r = ((r + 1)>>1); wpptr->g = ((g + 1)>>1); wpptr->b = ((b + 1)>>1); break; + case 3: wpptr->r = ((r*85+128)>>8); wpptr->g = ((g*85+128)>>8); wpptr->b = ((b*85+128)>>8); break; + case 4: wpptr->r = ((r + 2)>>2); wpptr->g = ((g + 2)>>2); wpptr->b = ((b + 2)>>2); break; + default: break; + } + } + } } static void uploadtexture(long doalloc, long xsiz, long ysiz, long intexfmt, long texfmt, coltype *pic, long tsizx, long tsizy, long dameth) { - coltype *wpptr, *rpptr; - long x2, y2, j, js=0, x3, y3, y, x, r, g, b, a, k; + coltype *wpptr, *rpptr; + long x2, y2, j, js=0, x3, y3, y, x, r, g, b, a, k; - if (gltexmaxsize <= 0) { - GLint i = 0; - bglGetIntegerv(GL_MAX_TEXTURE_SIZE, &i); - if (!i) gltexmaxsize = 6; // 2^6 = 64 == default GL max texture size - else { - gltexmaxsize = 0; - for (; i>1; i>>=1) gltexmaxsize++; - } - } - - js = max(0,min(gltexmaxsize-1,gltexmiplevel)); - gltexmiplevel = js; - while ((xsiz>>js) > (1<>js) > (1<1; i>>=1) gltexmaxsize++; + } + } - /* - OSD_Printf("Uploading %dx%d %s as %s\n", xsiz,ysiz, - (texfmt==GL_RGBA?"GL_RGBA": - texfmt==GL_RGB?"GL_RGB": - texfmt==GL_BGR?"GL_BGR": - texfmt==GL_BGRA?"GL_BGRA":"other"), - (intexfmt==GL_RGBA?"GL_RGBA": - intexfmt==GL_RGB?"GL_RGB": - intexfmt==GL_COMPRESSED_RGBA_ARB?"GL_COMPRESSED_RGBA_ARB": - intexfmt==GL_COMPRESSED_RGB_ARB?"GL_COMPRESSED_RGB_ARB":"other")); - */ - - if (js == 0) { - if (doalloc&1) - bglTexImage2D(GL_TEXTURE_2D,0,intexfmt,xsiz,ysiz,0,texfmt,GL_UNSIGNED_BYTE,pic); //loading 1st time - else - bglTexSubImage2D(GL_TEXTURE_2D,0,0,0,xsiz,ysiz,texfmt,GL_UNSIGNED_BYTE,pic); //overwrite old texture - } + js = max(0,min(gltexmaxsize-1,gltexmiplevel)); + gltexmiplevel = js; + while ((xsiz>>js) > (1<>js) > (1< 1) || (y2 > 1);j++) - { - //x3 = ((x2+1)>>1); y3 = ((y2+1)>>1); - x3 = max(1, x2 >> 1); y3 = max(1, y2 >> 1); // this came from the GL_ARB_texture_non_power_of_two spec - for(y=0;yr = r; wpptr->g = g; wpptr->b = b; wpptr->a = a; break; - case 2: wpptr->r = ((r+1)>>1); wpptr->g = ((g+1)>>1); wpptr->b = ((b+1)>>1); wpptr->a = ((a+1)>>1); break; - case 3: wpptr->r = ((r*85+128)>>8); wpptr->g = ((g*85+128)>>8); wpptr->b = ((b*85+128)>>8); wpptr->a = ((a*85+128)>>8); break; - case 4: wpptr->r = ((r+2)>>2); wpptr->g = ((g+2)>>2); wpptr->b = ((b+2)>>2); wpptr->a = ((a+2)>>2); break; - default: break; - } - //if (wpptr->a) wpptr->a = 255; - } - } - if (tsizx >= 0) fixtransparency(pic,(tsizx+(1<>j,(tsizy+(1<>j,x3,y3,dameth); - if (j >= js) { - if (doalloc&1) - bglTexImage2D(GL_TEXTURE_2D,j-js,intexfmt,x3,y3,0,texfmt,GL_UNSIGNED_BYTE,pic); //loading 1st time - else - bglTexSubImage2D(GL_TEXTURE_2D,j-js,0,0,x3,y3,texfmt,GL_UNSIGNED_BYTE,pic); //overwrite old texture - } - x2 = x3; y2 = y3; - } + x2 = xsiz; y2 = ysiz; + for(j=1;(x2 > 1) || (y2 > 1);j++) + { + //x3 = ((x2+1)>>1); y3 = ((y2+1)>>1); + x3 = max(1, x2 >> 1); y3 = max(1, y2 >> 1); // this came from the GL_ARB_texture_non_power_of_two spec + for(y=0;yr = r; wpptr->g = g; wpptr->b = b; wpptr->a = a; break; + case 2: wpptr->r = ((r+1)>>1); wpptr->g = ((g+1)>>1); wpptr->b = ((b+1)>>1); wpptr->a = ((a+1)>>1); break; + case 3: wpptr->r = ((r*85+128)>>8); wpptr->g = ((g*85+128)>>8); wpptr->b = ((b*85+128)>>8); wpptr->a = ((a*85+128)>>8); break; + case 4: wpptr->r = ((r+2)>>2); wpptr->g = ((g+2)>>2); wpptr->b = ((b+2)>>2); wpptr->a = ((a+2)>>2); break; + default: break; + } + //if (wpptr->a) wpptr->a = 255; + } + } + if (tsizx >= 0) fixtransparency(pic,(tsizx+(1<>j,(tsizy+(1<>j,x3,y3,dameth); + if (j >= js) { + if (doalloc&1) + bglTexImage2D(GL_TEXTURE_2D,j-js,intexfmt,x3,y3,0,texfmt,GL_UNSIGNED_BYTE,pic); //loading 1st time + else + bglTexSubImage2D(GL_TEXTURE_2D,j-js,0,0,x3,y3,texfmt,GL_UNSIGNED_BYTE,pic); //overwrite old texture + } + x2 = x3; y2 = y3; + } #endif } int gloadtile_art (long dapic, long dapal, long dameth, pthtyp *pth, long doalloc) { - coltype *pic, *wpptr; - long j, x, y, x2, y2, xsiz, ysiz, dacol, tsizx, tsizy; - char hasalpha = 0; + coltype *pic, *wpptr; + long j, x, y, x2, y2, xsiz, ysiz, dacol, tsizx, tsizy; + char hasalpha = 0; - tsizx = tilesizx[dapic]; - tsizy = tilesizy[dapic]; - if (!glinfo.texnpot) { - for(xsiz=1;xsiz= tsizx) || (y >= tsizy))) //Clamp texture - { wpptr->r = wpptr->g = wpptr->b = wpptr->a = 0; continue; } - if (x < tsizx) x2 = x; else x2 = x-tsizx; - dacol = (long)(*(unsigned char *)(waloff[dapic]+x2*tsizy+y2)); - if (dacol == 255) { - wpptr->a = 0; hasalpha = 1; - } else { - wpptr->a = 255; - dacol = (long)((unsigned char)palookup[dapal][dacol]); - } - if (gammabrightness) { - wpptr->r = curpalette[dacol].r; - wpptr->g = curpalette[dacol].g; - wpptr->b = curpalette[dacol].b; - } else { - wpptr->r = britable[curbrightness][ curpalette[dacol].r ]; - wpptr->g = britable[curbrightness][ curpalette[dacol].g ]; - wpptr->b = britable[curbrightness][ curpalette[dacol].b ]; - } - } - } - } + if (!waloff[dapic]) + { + //Force invalid textures to draw something - an almost purely transparency texture + //This allows the Z-buffer to be updated for mirrors (which are invalidated textures) + pic[0].r = pic[0].g = pic[0].b = 0; pic[0].a = 1; + tsizx = tsizy = 1; hasalpha = 1; + } + else + { + for(y=0;y= tsizx) || (y >= tsizy))) //Clamp texture + { wpptr->r = wpptr->g = wpptr->b = wpptr->a = 0; continue; } + if (x < tsizx) x2 = x; else x2 = x-tsizx; + dacol = (long)(*(unsigned char *)(waloff[dapic]+x2*tsizy+y2)); + if (dacol == 255) { + wpptr->a = 0; hasalpha = 1; + } else { + wpptr->a = 255; + dacol = (long)((unsigned char)palookup[dapal][dacol]); + } + if (gammabrightness) { + wpptr->r = curpalette[dacol].r; + wpptr->g = curpalette[dacol].g; + wpptr->b = curpalette[dacol].b; + } else { + wpptr->r = britable[curbrightness][ curpalette[dacol].r ]; + wpptr->g = britable[curbrightness][ curpalette[dacol].g ]; + wpptr->b = britable[curbrightness][ curpalette[dacol].b ]; + } + } + } + } - if (doalloc) bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) - bglBindTexture(GL_TEXTURE_2D,pth->glpic); + if (doalloc) bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) + bglBindTexture(GL_TEXTURE_2D,pth->glpic); - fixtransparency(pic,tsizx,tsizy,xsiz,ysiz,dameth); - uploadtexture(doalloc,xsiz,ysiz,hasalpha?GL_RGBA:GL_RGB,GL_RGBA,pic,tsizx,tsizy,dameth); + fixtransparency(pic,tsizx,tsizy,xsiz,ysiz,dameth); + uploadtexture(doalloc,xsiz,ysiz,hasalpha?GL_RGBA:GL_RGB,GL_RGBA,pic,tsizx,tsizy,dameth); - if (gltexfiltermode < 0) gltexfiltermode = 0; - else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + if (gltexfiltermode < 0) gltexfiltermode = 0; + else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (glinfo.maxanisotropy > 1.0) - { - if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - } + if (glinfo.maxanisotropy > 1.0) + { + if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + } - if (!(dameth&4)) - { - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); - } - else - { //For sprite textures, clamping looks better than wrapping - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); - } + if (!(dameth&4)) + { + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + } + else + { //For sprite textures, clamping looks better than wrapping + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); + } - if (pic) free(pic); + if (pic) free(pic); - pth->picnum = dapic; - pth->palnum = dapal; - pth->effects = 0; - pth->flags = ((dameth&4)>>2) | (hasalpha<<3); - pth->hicr = NULL; - - return 0; + pth->picnum = dapic; + pth->palnum = dapal; + pth->effects = 0; + pth->flags = ((dameth&4)>>2) | (hasalpha<<3); + pth->hicr = NULL; + + return 0; } // JONOF'S COMPRESSED TEXTURE CACHE STUFF --------------------------------------------------- static inline void phex(unsigned char v, char *s) { - int x; - x = v>>4; - s[0] = x<10 ? (x+'0') : (x-10+'a'); - x = v&15; - s[1] = x<10 ? (x+'0') : (x-10+'a'); + int x; + x = v>>4; + s[0] = x<10 ? (x+'0') : (x-10+'a'); + x = v&15; + s[1] = x<10 ? (x+'0') : (x-10+'a'); } long trytexcache(char *fn, long len, long dameth, char effect, texcacheheader *head) { - long fil, fp; - char cachefn[BMAX_PATH], *cp; - unsigned char mdsum[16]; - - if (!glinfo.texcompr || !glusetexcompr || !glusetexcache) return -1; - if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB) { - // lacking the necessary extensions to do this - initprintf("Warning: the GL driver lacks necessary functions to use caching\n"); - glusetexcache = 0; - return -1; - } - - md4once(fn, strlen(fn), mdsum); - for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); - *(cp++) = '/'; - for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); - sprintf(cp, "-%lx-%lx%x", len, dameth, effect); - - fil = kopen4load(cachefn, 0); - if (fil < 0) return -1; - - /* initprintf("Loading cached tex: %s\n", cachefn); */ - - if (kread(fil, head, sizeof(texcacheheader)) < (int)sizeof(texcacheheader)) goto failure; - if (memcmp(head->magic, "Polymost", 8)) goto failure; - - head->xdim = B_LITTLE32(head->xdim); - head->ydim = B_LITTLE32(head->ydim); - head->flags = B_LITTLE32(head->flags); - - if (!glinfo.texnpot && (head->flags & 1)) goto failure; - - return fil; + long fil, fp; + char cachefn[BMAX_PATH], *cp; + unsigned char mdsum[16]; + + if (!glinfo.texcompr || !glusetexcompr || !glusetexcache) return -1; + if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB) { + // lacking the necessary extensions to do this + initprintf("Warning: the GL driver lacks necessary functions to use caching\n"); + glusetexcache = 0; + return -1; + } + + md4once(fn, strlen(fn), mdsum); + for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); + *(cp++) = '/'; + for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); + sprintf(cp, "-%lx-%lx%x", len, dameth, effect); + + fil = kopen4load(cachefn, 0); + if (fil < 0) return -1; + + /* initprintf("Loading cached tex: %s\n", cachefn); */ + + if (kread(fil, head, sizeof(texcacheheader)) < (int)sizeof(texcacheheader)) goto failure; + if (memcmp(head->magic, "Polymost", 8)) goto failure; + + head->xdim = B_LITTLE32(head->xdim); + head->ydim = B_LITTLE32(head->ydim); + head->flags = B_LITTLE32(head->flags); + + if (!glinfo.texnpot && (head->flags & 1)) goto failure; + + return fil; failure: - kclose(fil); - return -1; + kclose(fil); + return -1; } void writexcache(char *fn, long len, long dameth, char effect, texcacheheader *head) { - long fil=-1, fp; - char cachefn[BMAX_PATH], *cp; - unsigned char mdsum[16]; - texcachepicture pict; - char *pic = NULL, *packbuf = NULL; - void *midbuf = NULL; - unsigned long alloclen=0, level, miplen; - unsigned long padx, pady; - GLuint gi; - long j, k; + long fil=-1, fp; + char cachefn[BMAX_PATH], *cp; + unsigned char mdsum[16]; + texcachepicture pict; + char *pic = NULL, *packbuf = NULL; + void *midbuf = NULL; + unsigned long alloclen=0, level, miplen; + unsigned long padx, pady; + GLuint gi; + long j, k; - if (!glinfo.texcompr || !glusetexcompr || !glusetexcache) return; - if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB) { - // lacking the necessary extensions to do this - initprintf("Warning: the GL driver lacks necessary functions to use caching\n"); - glusetexcache = 0; - return; - } + if (!glinfo.texcompr || !glusetexcompr || !glusetexcache) return; + if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB) { + // lacking the necessary extensions to do this + initprintf("Warning: the GL driver lacks necessary functions to use caching\n"); + glusetexcache = 0; + return; + } - { - struct stat st; - if (stat(TEXCACHEDIR, &st) < 0) { - if (errno == ENOENT) { // path doesn't exist - // try to create the cache directory - if (Bmkdir(TEXCACHEDIR, S_IRWXU) < 0) { - initprintf("Failed to create texture cache directory %s\n", TEXCACHEDIR); - glusetexcache = 0; - return; - } else initprintf("Created texture cache directory %s\n", TEXCACHEDIR); - } else { - // another type of failure - glusetexcache = 0; - return; - } - } else if ((st.st_mode & S_IFDIR) != S_IFDIR) { - // cache directory isn't a directory - glusetexcache = 0; - return; - } - } + { + struct stat st; + if (stat(TEXCACHEDIR, &st) < 0) { + if (errno == ENOENT) { // path doesn't exist + // try to create the cache directory + if (Bmkdir(TEXCACHEDIR, S_IRWXU) < 0) { + initprintf("Failed to create texture cache directory %s\n", TEXCACHEDIR); + glusetexcache = 0; + return; + } else initprintf("Created texture cache directory %s\n", TEXCACHEDIR); + } else { + // another type of failure + glusetexcache = 0; + return; + } + } else if ((st.st_mode & S_IFDIR) != S_IFDIR) { + // cache directory isn't a directory + glusetexcache = 0; + return; + } + } - gi = GL_FALSE; - bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi); - if (gi != GL_TRUE) return; + gi = GL_FALSE; + bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi); + if (gi != GL_TRUE) return; - md4once(fn, strlen(fn), mdsum); - for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); - *(cp++) = '/'; - for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); - sprintf(cp, "-%lx-%lx%x", len, dameth, effect); + md4once(fn, strlen(fn), mdsum); + for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); + *(cp++) = '/'; + for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); + sprintf(cp, "-%lx-%lx%x", len, dameth, effect); - initprintf("Writing cached tex: %s\n", cachefn); + initprintf("Writing cached tex: %s\n", cachefn); - fil = Bopen(cachefn,BO_BINARY|BO_CREAT|BO_TRUNC|BO_RDWR,BS_IREAD|BS_IWRITE); - if (fil < 0) return; + fil = Bopen(cachefn,BO_BINARY|BO_CREAT|BO_TRUNC|BO_RDWR,BS_IREAD|BS_IWRITE); + if (fil < 0) return; - memcpy(head->magic, "Polymost", 8); // sizes are set by caller + memcpy(head->magic, "Polymost", 8); // sizes are set by caller - if (glusetexcachecompression) head->flags |= 4; + if (glusetexcachecompression) head->flags |= 4; - head->xdim = B_LITTLE32(head->xdim); - head->ydim = B_LITTLE32(head->ydim); - head->flags = B_LITTLE32(head->flags); + head->xdim = B_LITTLE32(head->xdim); + head->ydim = B_LITTLE32(head->ydim); + head->flags = B_LITTLE32(head->flags); - if (Bwrite(fil, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure; + if (Bwrite(fil, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure; - bglGetError(); - for (level = 0; level==0 || (padx > 1 || pady > 1); level++) { - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - if (gi != GL_TRUE) goto failure; // an uncompressed mipmap - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - pict.format = B_LITTLE32(gi); - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - padx = gi; pict.xdim = B_LITTLE32(gi); - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - pady = gi; pict.ydim = B_LITTLE32(gi); - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_BORDER, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - pict.border = B_LITTLE32(gi); - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - pict.depth = B_LITTLE32(gi); - bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); - if (bglGetError() != GL_NO_ERROR) goto failure; - miplen = (long)gi; pict.size = B_LITTLE32(gi); + bglGetError(); + for (level = 0; level==0 || (padx > 1 || pady > 1); level++) { + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + if (gi != GL_TRUE) goto failure; // an uncompressed mipmap + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + pict.format = B_LITTLE32(gi); + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + padx = gi; pict.xdim = B_LITTLE32(gi); + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + pady = gi; pict.ydim = B_LITTLE32(gi); + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_BORDER, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + pict.border = B_LITTLE32(gi); + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + pict.depth = B_LITTLE32(gi); + bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); + if (bglGetError() != GL_NO_ERROR) goto failure; + miplen = (long)gi; pict.size = B_LITTLE32(gi); - if (alloclen < miplen) { - void *picc = realloc(pic, miplen); - if (!picc) goto failure; else pic = picc; - alloclen = miplen; + if (alloclen < miplen) { + void *picc = realloc(pic, miplen); + if (!picc) goto failure; else pic = picc; + alloclen = miplen; - picc = realloc(packbuf, alloclen+16); - if (!picc) goto failure; else packbuf = picc; + picc = realloc(packbuf, alloclen+16); + if (!picc) goto failure; else packbuf = picc; - picc = realloc(midbuf, miplen); - if (!picc) goto failure; else midbuf = picc; - } + picc = realloc(midbuf, miplen); + if (!picc) goto failure; else midbuf = picc; + } - bglGetCompressedTexImageARB(GL_TEXTURE_2D, level, pic); - if (bglGetError() != GL_NO_ERROR) goto failure; + bglGetCompressedTexImageARB(GL_TEXTURE_2D, level, pic); + if (bglGetError() != GL_NO_ERROR) goto failure; - if (Bwrite(fil, &pict, sizeof(texcachepicture)) != sizeof(texcachepicture)) goto failure; - if (dxtfilter(fil, &pict, pic, midbuf, packbuf, miplen)) goto failure; - } + if (Bwrite(fil, &pict, sizeof(texcachepicture)) != sizeof(texcachepicture)) goto failure; + if (dxtfilter(fil, &pict, pic, midbuf, packbuf, miplen)) goto failure; + } failure: - if (fil>=0) Bclose(fil); - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); + if (fil>=0) Bclose(fil); + if (midbuf) free(midbuf); + if (pic) free(pic); + if (packbuf) free(packbuf); } int gloadtile_cached(long fil, texcacheheader *head, long *doalloc, pthtyp *pth) { - int level, r; - texcachepicture pict; - char *pic = NULL, *packbuf = NULL; - void *midbuf = NULL; - long alloclen=0; + int level, r; + texcachepicture pict; + char *pic = NULL, *packbuf = NULL; + void *midbuf = NULL; + long alloclen=0; - if (*doalloc&1) { - bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) - *doalloc |= 2; // prevents bglGenTextures being called again if we fail in here - } - bglBindTexture(GL_TEXTURE_2D,pth->glpic); + if (*doalloc&1) { + bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) + *doalloc |= 2; // prevents bglGenTextures being called again if we fail in here + } + bglBindTexture(GL_TEXTURE_2D,pth->glpic); - pth->sizx = head->xdim; - pth->sizy = head->ydim; + pth->sizx = head->xdim; + pth->sizy = head->ydim; - bglGetError(); + bglGetError(); - // load the mipmaps - for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++) { - r = kread(fil, &pict, sizeof(texcachepicture)); - if (r < (int)sizeof(texcachepicture)) goto failure; + // load the mipmaps + for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++) { + r = kread(fil, &pict, sizeof(texcachepicture)); + if (r < (int)sizeof(texcachepicture)) goto failure; - pict.size = B_LITTLE32(pict.size); - pict.format = B_LITTLE32(pict.format); - pict.xdim = B_LITTLE32(pict.xdim); - pict.ydim = B_LITTLE32(pict.ydim); - pict.border = B_LITTLE32(pict.border); - pict.depth = B_LITTLE32(pict.depth); + pict.size = B_LITTLE32(pict.size); + pict.format = B_LITTLE32(pict.format); + pict.xdim = B_LITTLE32(pict.xdim); + pict.ydim = B_LITTLE32(pict.ydim); + pict.border = B_LITTLE32(pict.border); + pict.depth = B_LITTLE32(pict.depth); - if (alloclen < pict.size) { - void *picc = realloc(pic, pict.size); - if (!picc) goto failure; else pic = picc; - alloclen = pict.size; + if (alloclen < pict.size) { + void *picc = realloc(pic, pict.size); + if (!picc) goto failure; else pic = picc; + alloclen = pict.size; - picc = realloc(packbuf, alloclen+16); - if (!picc) goto failure; else packbuf = picc; + picc = realloc(packbuf, alloclen+16); + if (!picc) goto failure; else packbuf = picc; - picc = realloc(midbuf, pict.size); - if (!picc) goto failure; else midbuf = picc; - } + picc = realloc(midbuf, pict.size); + if (!picc) goto failure; else midbuf = picc; + } - if (dedxtfilter(fil, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) goto failure; + if (dedxtfilter(fil, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) goto failure; - bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border, - pict.size,pic); - if (bglGetError() != GL_NO_ERROR) goto failure; - } + bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border, + pict.size,pic); + if (bglGetError() != GL_NO_ERROR) goto failure; + } - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); - return 0; + if (midbuf) free(midbuf); + if (pic) free(pic); + if (packbuf) free(packbuf); + return 0; failure: - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); - return -1; + if (midbuf) free(midbuf); + if (pic) free(pic); + if (packbuf) free(packbuf); + return -1; } // --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF int gloadtile_hi(long dapic, long facen, hicreplctyp *hicr, long dameth, pthtyp *pth, long doalloc, char effect) { - coltype *pic = NULL, *rpptr; + coltype *pic = NULL, *rpptr; long j, x, y, x2, y2, xsiz=0, ysiz=0, tsizx, tsizy; - char *picfil = NULL, *fn, hasalpha = 255; - long picfillen, texfmt = GL_RGBA, intexfmt = GL_RGBA, filh; + char *picfil = NULL, *fn, hasalpha = 255; + long picfillen, texfmt = GL_RGBA, intexfmt = GL_RGBA, filh; - long cachefil = -1; - texcacheheader cachead; + long cachefil = -1; + texcacheheader cachead; - if (!hicr) return -1; - if (facen > 0) { - if (!hicr->skybox) return -1; - if (facen > 6) return -1; - if (!hicr->skybox->face[facen-1]) return -1; - fn = hicr->skybox->face[facen-1]; - } else { - if (!hicr->filename) return -1; - fn = hicr->filename; - } + if (!hicr) return -1; + if (facen > 0) { + if (!hicr->skybox) return -1; + if (facen > 6) return -1; + if (!hicr->skybox->face[facen-1]) return -1; + fn = hicr->skybox->face[facen-1]; + } else { + if (!hicr->filename) return -1; + fn = hicr->filename; + } - if ((filh = kopen4load(fn, 0)) < 0) { - initprintf("hightile: %s (pic %d) not found\n", fn, dapic); - if (facen > 0) - hicr->skybox->ignore = 1; - else - hicr->ignore = 1; - return -1; - } - picfillen = kfilelength(filh); + if ((filh = kopen4load(fn, 0)) < 0) { + initprintf("hightile: %s (pic %d) not found\n", fn, dapic); + if (facen > 0) + hicr->skybox->ignore = 1; + else + hicr->ignore = 1; + return -1; + } + picfillen = kfilelength(filh); - kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c + kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c - cachefil = trytexcache(fn, picfillen, dameth, effect, &cachead); - if (cachefil >= 0 && !gloadtile_cached(cachefil, &cachead, &doalloc, pth)) { - tsizx = cachead.xdim; - tsizy = cachead.ydim; - hasalpha = (cachead.flags & 2) ? 0 : 255; - kclose(cachefil); - //kclose(filh); // FIXME: uncomment when cache1d.c is fixed - // cachefil >= 0, so it won't be rewritten - } else { - if (cachefil >= 0) kclose(cachefil); - cachefil = -1; // the compressed version will be saved to disk - - if ((filh = kopen4load(fn, 0)) < 0) return -1; + cachefil = trytexcache(fn, picfillen, dameth, effect, &cachead); + if (cachefil >= 0 && !gloadtile_cached(cachefil, &cachead, &doalloc, pth)) { + tsizx = cachead.xdim; + tsizy = cachead.ydim; + hasalpha = (cachead.flags & 2) ? 0 : 255; + kclose(cachefil); + //kclose(filh); // FIXME: uncomment when cache1d.c is fixed + // cachefil >= 0, so it won't be rewritten + } else { + if (cachefil >= 0) kclose(cachefil); + cachefil = -1; // the compressed version will be saved to disk - picfil = (char *)malloc(picfillen); if (!picfil) { kclose(filh); return 1; } - kread(filh, picfil, picfillen); - kclose(filh); + if ((filh = kopen4load(fn, 0)) < 0) return -1; - // tsizx/y = replacement texture's natural size - // xsiz/y = 2^x size of replacement + picfil = (char *)malloc(picfillen); if (!picfil) { kclose(filh); return 1; } + kread(filh, picfil, picfillen); + kclose(filh); - kpgetdim(picfil,picfillen,&tsizx,&tsizy); - if (tsizx == 0 || tsizy == 0) { free(picfil); return -1; } - pth->sizx = tsizx; - pth->sizy = tsizy; + // tsizx/y = replacement texture's natural size + // xsiz/y = 2^x size of replacement - if (!glinfo.texnpot) { - for(xsiz=1;xsizsizx = tsizx; + pth->sizy = tsizy; - if (kprender(picfil,picfillen,(long)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0)) { free(picfil); free(pic); return -2; } - for(y=0,j=0;y tsizx) //Copy left to right - { - long *lptr = (long *)pic; - for(y=0;y tsizy) //Copy top to bottom - memcpy(&pic[xsiz*tsizy],pic,(ysiz-tsizy)*xsiz<<2); - } - if (!glinfo.bgra) { - for(j=xsiz*ysiz-1;j>=0;j--) { - swapchar(&pic[j].r, &pic[j].b); - } - } else texfmt = GL_BGRA; - free(picfil); picfil = 0; + if (effect & 1) { + // greyscale + tcol.b = max(tcol.b, max(tcol.g, tcol.r)); + tcol.g = tcol.r = tcol.b; + } + if (effect & 2) { + // invert + tcol.b = 255-tcol.b; + tcol.g = 255-tcol.g; + tcol.r = 255-tcol.r; + } - if (glinfo.texcompr && glusetexcompr && !(hicr->flags & 1)) - intexfmt = (hasalpha == 255) ? GL_COMPRESSED_RGB_ARB : GL_COMPRESSED_RGBA_ARB; - else if (hasalpha == 255) intexfmt = GL_RGB; + rpptr[x].b = tcol.b; + rpptr[x].g = tcol.g; + rpptr[x].r = tcol.r; + rpptr[x].a = tcol.a; + } + } + if ((!(dameth&4)) || (facen)) //Duplicate texture pixels (wrapping tricks for non power of 2 texture sizes) + { + if (xsiz > tsizx) //Copy left to right + { + long *lptr = (long *)pic; + for(y=0;y tsizy) //Copy top to bottom + memcpy(&pic[xsiz*tsizy],pic,(ysiz-tsizy)*xsiz<<2); + } + if (!glinfo.bgra) { + for(j=xsiz*ysiz-1;j>=0;j--) { + swapchar(&pic[j].r, &pic[j].b); + } + } else texfmt = GL_BGRA; + free(picfil); picfil = 0; - if ((doalloc&3)==1) bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) - bglBindTexture(GL_TEXTURE_2D,pth->glpic); + if (glinfo.texcompr && glusetexcompr && !(hicr->flags & 1)) + intexfmt = (hasalpha == 255) ? GL_COMPRESSED_RGB_ARB : GL_COMPRESSED_RGBA_ARB; + else if (hasalpha == 255) intexfmt = GL_RGB; - fixtransparency(pic,tsizx,tsizy,xsiz,ysiz,dameth); - uploadtexture(doalloc,xsiz,ysiz,intexfmt,texfmt,pic,-1,tsizy,dameth); - } + if ((doalloc&3)==1) bglGenTextures(1,(GLuint*)&pth->glpic); //# of textures (make OpenGL allocate structure) + bglBindTexture(GL_TEXTURE_2D,pth->glpic); - // precalculate scaling parameters for replacement - if (facen > 0) { - pth->scalex = ((float)tsizx) / 64.0; - pth->scaley = ((float)tsizy) / 64.0; - } else { - pth->scalex = ((float)tsizx) / ((float)tilesizx[dapic]); - pth->scaley = ((float)tsizy) / ((float)tilesizy[dapic]); - } - - if (gltexfiltermode < 0) gltexfiltermode = 0; - else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); + fixtransparency(pic,tsizx,tsizy,xsiz,ysiz,dameth); + uploadtexture(doalloc,xsiz,ysiz,intexfmt,texfmt,pic,-1,tsizy,dameth); + } - if (glinfo.maxanisotropy > 1.0) - { - if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; - bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); - } + // precalculate scaling parameters for replacement + if (facen > 0) { + pth->scalex = ((float)tsizx) / 64.0; + pth->scaley = ((float)tsizy) / 64.0; + } else { + pth->scalex = ((float)tsizx) / ((float)tilesizx[dapic]); + pth->scaley = ((float)tsizy) / ((float)tilesizy[dapic]); + } - if (!(dameth&4)) - { - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); - } - else - { //For sprite textures, clamping looks better than wrapping - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); - } + if (gltexfiltermode < 0) gltexfiltermode = 0; + else if (gltexfiltermode >= (long)numglfiltermodes) gltexfiltermode = numglfiltermodes-1; + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min); - if (pic) free(pic); + if (glinfo.maxanisotropy > 1.0) + { + if (glanisotropy <= 0 || glanisotropy > glinfo.maxanisotropy) glanisotropy = (long)glinfo.maxanisotropy; + bglTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy); + } - pth->picnum = dapic; - pth->effects = effect; - pth->flags = ((dameth&4)>>2) + 2 + ((facen>0)<<2); if (hasalpha != 255) pth->flags |= 8; - pth->skyface = facen; - pth->hicr = hicr; - - if (cachefil < 0) { - // save off the compressed version - cachead.xdim = tsizx; - cachead.ydim = tsizy; - x = 0; - for (j=0;j<31;j++) { - if (xsiz == pow2long[j]) { x |= 1; } - if (ysiz == pow2long[j]) { x |= 2; } - } - cachead.flags = (x!=3) | (hasalpha != 255 ? 2 : 0); - writexcache(fn, picfillen, dameth, effect, &cachead); - } + if (!(dameth&4)) + { + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + } + else + { //For sprite textures, clamping looks better than wrapping + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); + } - return 0; + if (pic) free(pic); + + pth->picnum = dapic; + pth->effects = effect; + pth->flags = ((dameth&4)>>2) + 2 + ((facen>0)<<2); if (hasalpha != 255) pth->flags |= 8; + pth->skyface = facen; + pth->hicr = hicr; + + if (cachefil < 0) { + // save off the compressed version + cachead.xdim = tsizx; + cachead.ydim = tsizy; + x = 0; + for (j=0;j<31;j++) { + if (xsiz == pow2long[j]) { x |= 1; } + if (ysiz == pow2long[j]) { x |= 2; } + } + cachead.flags = (x!=3) | (hasalpha != 255 ? 2 : 0); + writexcache(fn, picfillen, dameth, effect, &cachead); + } + + return 0; } #endif - //(dpx,dpy) specifies an n-sided polygon. The polygon must be a convex clockwise loop. - // n must be <= 8 (assume clipping can double number of vertices) - //method: 0:solid, 1:masked(255 is transparent), 2:transluscent #1, 3:transluscent #2 - // +4 means it's a sprite, so wraparound isn't needed +//(dpx,dpy) specifies an n-sided polygon. The polygon must be a convex clockwise loop. +// n must be <= 8 (assume clipping can double number of vertices) +//method: 0:solid, 1:masked(255 is transparent), 2:transluscent #1, 3:transluscent #2 +// +4 means it's a sprite, so wraparound isn't needed static long pow2xsplit = 0, skyclamphack = 0; void drawpoly (double *dpx, double *dpy, long n, long method) { #define PI 3.14159265358979323 - double ngdx = 0.0, ngdy = 0.0, ngdo = 0.0, ngux = 0.0, nguy = 0.0, nguo = 0.0; - double ngvx = 0.0, ngvy = 0.0, ngvo = 0.0, dp, up, vp, rdp, du0 = 0.0, du1 = 0.0, dui, duj; - double ngdx2, ngux2, ngvx2; - double f, r, ox, oy, oz, ox2, oy2, oz2, dd[16], uu[16], vv[16], px[16], py[16], uoffs; - long i, j, k, x, y, z, nn, ix0, ix1, mini, maxi, tsizx, tsizy, tsizxm1 = 0, tsizym1 = 0, ltsizy = 0; - long xx, yy, xi, d0, u0, v0, d1, u1, v1, xmodnice = 0, ymulnice = 0, dorot; - char dacol = 0, *walptr, *palptr = NULL, *vidp, *vide; + double ngdx = 0.0, ngdy = 0.0, ngdo = 0.0, ngux = 0.0, nguy = 0.0, nguo = 0.0; + double ngvx = 0.0, ngvy = 0.0, ngvo = 0.0, dp, up, vp, rdp, du0 = 0.0, du1 = 0.0, dui, duj; + double ngdx2, ngux2, ngvx2; + double f, r, ox, oy, oz, ox2, oy2, oz2, dd[16], uu[16], vv[16], px[16], py[16], uoffs; + long i, j, k, x, y, z, nn, ix0, ix1, mini, maxi, tsizx, tsizy, tsizxm1 = 0, tsizym1 = 0, ltsizy = 0; + long xx, yy, xi, d0, u0, v0, d1, u1, v1, xmodnice = 0, ymulnice = 0, dorot; + char dacol = 0, *walptr, *palptr = NULL, *vidp, *vide; #ifdef USE_OPENGL - pthtyp *pth; + pthtyp *pth; #endif - if (method == -1) return; + if (method == -1) return; - if (n == 3) - { - if ((dpx[0]-dpx[1])*(dpy[2]-dpy[1]) >= (dpx[2]-dpx[1])*(dpy[0]-dpy[1])) return; //for triangle - } - else - { - f = 0; //f is area of polygon / 2 - for(i=n-2,j=n-1,k=0;k= (dpx[2]-dpx[1])*(dpy[0]-dpy[1])) return; //for triangle + } + else + { + f = 0; //f is area of polygon / 2 + for(i=n-2,j=n-1,k=0;k= MAXTILES) globalpicnum = 0; - setgotpic(globalpicnum); - tsizx = tilesizx[globalpicnum]; - tsizy = tilesizy[globalpicnum]; - if (!palookup[globalpal]) globalpal = 0; - if (!waloff[globalpicnum]) - { - loadtile(globalpicnum); - if (!waloff[globalpicnum]) - { - if (rendmode != 3) return; - tsizx = tsizy = 1; method = 1; //Hack to update Z-buffer for invalid mirror textures - } - } - walptr = (char *)waloff[globalpicnum]; + //Load texture (globalpicnum) + if ((unsigned long)globalpicnum >= MAXTILES) globalpicnum = 0; + setgotpic(globalpicnum); + tsizx = tilesizx[globalpicnum]; + tsizy = tilesizy[globalpicnum]; + if (!palookup[globalpal]) globalpal = 0; + if (!waloff[globalpicnum]) + { + loadtile(globalpicnum); + if (!waloff[globalpicnum]) + { + if (rendmode != 3) return; + tsizx = tsizy = 1; method = 1; //Hack to update Z-buffer for invalid mirror textures + } + } + walptr = (char *)waloff[globalpicnum]; - j = 0; dorot = ((gchang != 1.0) || (gctang != 1.0)); - if (dorot) - { - for(i=0;i= 3) && (px[j-1] == px[0]) && (py[j-1] == py[0])) j--; - if (j < 3) return; - n = j; + px[j] = ox*r + ghalfx; + py[j] = oy*r + ghoriz; + if ((!j) || (px[j] != px[j-1]) || (py[j] != py[j-1])) j++; + } + } + else + { + for(i=0;i= 3) && (px[j-1] == px[0]) && (py[j-1] == py[0])) j--; + if (j < 3) return; + n = j; #ifdef USE_OPENGL - if (rendmode == 3) - { - float hackscx, hackscy; + if (rendmode == 3) + { + float hackscx, hackscy; - if (skyclamphack) method |= 4; - pth = gltexcache(globalpicnum,globalpal,method&(~3)); - bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + if (skyclamphack) method |= 4; + pth = gltexcache(globalpicnum,globalpal,method&(~3)); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); - if (pth && (pth->flags & 2)) - { - hackscx = pth->scalex; - hackscy = pth->scaley; - tsizx = pth->sizx; - tsizy = pth->sizy; - } - else { hackscx = 1.0; hackscy = 1.0; } + if (pth && (pth->flags & 2)) + { + hackscx = pth->scalex; + hackscy = pth->scaley; + tsizx = pth->sizx; + tsizy = pth->sizy; + } + else { hackscx = 1.0; hackscy = 1.0; } - if (!glinfo.texnpot) { - for(xx=1;xxhicr && pth->hicr->alphacut >= 0.0) al = pth->hicr->alphacut; - if (alphahackarray[globalpicnum]) - al=alphahackarray[globalpicnum]; - if (!waloff[globalpicnum]) al = 0.0; // invalid textures ignore the alpha cutoff settings - bglEnable(GL_BLEND); - bglEnable(GL_ALPHA_TEST); - bglAlphaFunc(GL_GREATER,al); - } + if (!(method&3)) { + bglDisable(GL_BLEND); + bglDisable(GL_ALPHA_TEST); + } else { + float al = 0.0; // PLAG : default alphacut was 0.32 before goodalpha + if (pth && pth->hicr && pth->hicr->alphacut >= 0.0) al = pth->hicr->alphacut; + if (alphahackarray[globalpicnum]) + al=alphahackarray[globalpicnum]; + if (!waloff[globalpicnum]) al = 0.0; // invalid textures ignore the alpha cutoff settings + bglEnable(GL_BLEND); + bglEnable(GL_ALPHA_TEST); + bglAlphaFunc(GL_GREATER,al); + } - if (!dorot) - { - for(i=n-1;i>=0;i--) - { - dd[i] = px[i]*gdx + py[i]*gdy + gdo; - uu[i] = px[i]*gux + py[i]*guy + guo; - vv[i] = px[i]*gvx + py[i]*gvy + gvo; - } - } + if (!dorot) + { + for(i=n-1;i>=0;i--) + { + dd[i] = px[i]*gdx + py[i]*gdy + gdo; + uu[i] = px[i]*gux + py[i]*guy + guo; + vv[i] = px[i]*gvx + py[i]*gvy + gvo; + } + } - { - float pc[4]; - f = ((float)(numpalookups-min(max(globalshade,0),numpalookups)))/((float)numpalookups); - pc[0] = pc[1] = pc[2] = f; - switch(method&3) - { - case 0: pc[3] = 1.0; break; - case 1: pc[3] = 1.0; break; - case 2: pc[3] = 0.66; break; - case 3: pc[3] = 0.33; break; - } - // tinting happens only to hightile textures, and only if the texture we're - // rendering isn't for the same palette as what we asked for - if (pth && (pth->flags & 2) && (pth->palnum != globalpal)) { - // apply tinting for replaced textures - pc[0] *= (float)hictinting[globalpal].r / 255.0; - pc[1] *= (float)hictinting[globalpal].g / 255.0; - pc[2] *= (float)hictinting[globalpal].b / 255.0; - } - bglColor4f(pc[0],pc[1],pc[2],pc[3]); - } + { + float pc[4]; + f = ((float)(numpalookups-min(max(globalshade,0),numpalookups)))/((float)numpalookups); + pc[0] = pc[1] = pc[2] = f; + switch(method&3) + { + case 0: pc[3] = 1.0; break; + case 1: pc[3] = 1.0; break; + case 2: pc[3] = 0.66; break; + case 3: pc[3] = 0.33; break; + } + // tinting happens only to hightile textures, and only if the texture we're + // rendering isn't for the same palette as what we asked for + if (pth && (pth->flags & 2) && (pth->palnum != globalpal)) { + // apply tinting for replaced textures + pc[0] *= (float)hictinting[globalpal].r / 255.0; + pc[1] *= (float)hictinting[globalpal].g / 255.0; + pc[2] *= (float)hictinting[globalpal].b / 255.0; + } + bglColor4f(pc[0],pc[1],pc[2],pc[3]); + } - //Hack for walls&masked walls which use textures that are not a power of 2 - if ((pow2xsplit) && (tsizx != xx)) - { - if (!dorot) - { - ngdx = gdx; ngdy = gdy; ngdo = gdo+(ngdx+ngdy)*.5; - ngux = gux; nguy = guy; nguo = guo+(ngux+nguy)*.5; - ngvx = gvx; ngvy = gvy; ngvo = gvo+(ngvx+ngvy)*.5; - } - else - { - ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; - r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); - ngdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - ngux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - ngvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; - ngdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - nguy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - ngvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - ox = px[0]-.5; oy = py[0]-.5; //.5 centers texture nicely - ngdo = dd[0] - ox*ngdx - oy*ngdy; - nguo = uu[0] - ox*ngux - oy*nguy; - ngvo = vv[0] - ox*ngvx - oy*ngvy; - } + //Hack for walls&masked walls which use textures that are not a power of 2 + if ((pow2xsplit) && (tsizx != xx)) + { + if (!dorot) + { + ngdx = gdx; ngdy = gdy; ngdo = gdo+(ngdx+ngdy)*.5; + ngux = gux; nguy = guy; nguo = guo+(ngux+nguy)*.5; + ngvx = gvx; ngvy = gvy; ngvo = gvo+(ngvx+ngvy)*.5; + } + else + { + ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; + r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); + ngdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + ngux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + ngvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; + ngdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + nguy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + ngvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + ox = px[0]-.5; oy = py[0]-.5; //.5 centers texture nicely + ngdo = dd[0] - ox*ngdx - oy*ngdy; + nguo = uu[0] - ox*ngux - oy*nguy; + ngvo = vv[0] - ox*ngvx - oy*ngvy; + } - ngux *= hackscx; nguy *= hackscx; nguo *= hackscx; - ngvx *= hackscy; ngvy *= hackscy; ngvo *= hackscy; - uoffs = ((double)(xx-tsizx)*.5); - ngux -= ngdx*uoffs; - nguy -= ngdy*uoffs; - nguo -= ngdo*uoffs; + ngux *= hackscx; nguy *= hackscx; nguo *= hackscx; + ngvx *= hackscy; ngvy *= hackscy; ngvo *= hackscy; + uoffs = ((double)(xx-tsizx)*.5); + ngux -= ngdx*uoffs; + nguy -= ngdy*uoffs; + nguo -= ngdo*uoffs; - //Find min&max u coordinates (du0...du1) - for(i=0;i du1) du1 = f; - } + //Find min&max u coordinates (du0...du1) + for(i=0;i du1) du1 = f; + } - f = 1.0/(double)tsizx; - ix0 = (long)floor(du0*f); - ix1 = (long)floor(du1*f); - for(;ix0<=ix1;ix0++) - { - du0 = (double)((ix0 )*tsizx); // + uoffs; - du1 = (double)((ix0+1)*tsizx); // + uoffs; + f = 1.0/(double)tsizx; + ix0 = (long)floor(du0*f); + ix1 = (long)floor(du1*f); + for(;ix0<=ix1;ix0++) + { + du0 = (double)((ix0 )*tsizx); // + uoffs; + du1 = (double)((ix0+1)*tsizx); // + uoffs; - i = 0; nn = 0; - duj = (px[i]*ngux + py[i]*nguy + nguo) / (px[i]*ngdx + py[i]*ngdy + ngdo); - do - { - j = i+1; if (j == n) j = 0; + i = 0; nn = 0; + duj = (px[i]*ngux + py[i]*nguy + nguo) / (px[i]*ngdx + py[i]*ngdy + ngdo); + do + { + j = i+1; if (j == n) j = 0; - dui = duj; duj = (px[j]*ngux + py[j]*nguy + nguo) / (px[j]*ngdx + py[j]*ngdy + ngdo); + dui = duj; duj = (px[j]*ngux + py[j]*nguy + nguo) / (px[j]*ngdx + py[j]*ngdy + ngdo); - if ((du0 <= dui) && (dui <= du1)) { uu[nn] = px[i]; vv[nn] = py[i]; nn++; } - if (duj <= dui) - { - if ((du1 < duj) != (du1 < dui)) - { - //ox*(ngux-ngdx*du1) + oy*(nguy-ngdy*du1) + (nguo-ngdo*du1) = 0 - //(px[j]-px[i])*f + px[i] = ox - //(py[j]-py[i])*f + py[i] = oy + if ((du0 <= dui) && (dui <= du1)) { uu[nn] = px[i]; vv[nn] = py[i]; nn++; } + if (duj <= dui) + { + if ((du1 < duj) != (du1 < dui)) + { + //ox*(ngux-ngdx*du1) + oy*(nguy-ngdy*du1) + (nguo-ngdo*du1) = 0 + //(px[j]-px[i])*f + px[i] = ox + //(py[j]-py[i])*f + py[i] = oy - ///Solve for f - //((px[j]-px[i])*f + px[i])*(ngux-ngdx*du1) + - //((py[j]-py[i])*f + py[i])*(nguy-ngdy*du1) + (nguo-ngdo*du1) = 0 + ///Solve for f + //((px[j]-px[i])*f + px[i])*(ngux-ngdx*du1) + + //((py[j]-py[i])*f + py[i])*(nguy-ngdy*du1) + (nguo-ngdo*du1) = 0 - f = -( px[i] *(ngux-ngdx*du1) + py[i] *(nguy-ngdy*du1) + (nguo-ngdo*du1)) / - ((px[j]-px[i])*(ngux-ngdx*du1) + (py[j]-py[i])*(nguy-ngdy*du1)); - uu[nn] = (px[j]-px[i])*f + px[i]; - vv[nn] = (py[j]-py[i])*f + py[i]; nn++; - } - if ((du0 < duj) != (du0 < dui)) - { - f = -( px[i] *(ngux-ngdx*du0) + py[i] *(nguy-ngdy*du0) + (nguo-ngdo*du0)) / - ((px[j]-px[i])*(ngux-ngdx*du0) + (py[j]-py[i])*(nguy-ngdy*du0)); - uu[nn] = (px[j]-px[i])*f + px[i]; - vv[nn] = (py[j]-py[i])*f + py[i]; nn++; - } - } - else - { - if ((du0 < duj) != (du0 < dui)) - { - f = -( px[i] *(ngux-ngdx*du0) + py[i] *(nguy-ngdy*du0) + (nguo-ngdo*du0)) / - ((px[j]-px[i])*(ngux-ngdx*du0) + (py[j]-py[i])*(nguy-ngdy*du0)); - uu[nn] = (px[j]-px[i])*f + px[i]; - vv[nn] = (py[j]-py[i])*f + py[i]; nn++; - } - if ((du1 < duj) != (du1 < dui)) - { - f = -( px[i] *(ngux-ngdx*du1) + py[i] *(nguy-ngdy*du1) + (nguo-ngdo*du1)) / - ((px[j]-px[i])*(ngux-ngdx*du1) + (py[j]-py[i])*(nguy-ngdy*du1)); - uu[nn] = (px[j]-px[i])*f + px[i]; - vv[nn] = (py[j]-py[i])*f + py[i]; nn++; - } - } - i = j; - } while (i); - if (nn < 3) continue; + f = -( px[i] *(ngux-ngdx*du1) + py[i] *(nguy-ngdy*du1) + (nguo-ngdo*du1)) / + ((px[j]-px[i])*(ngux-ngdx*du1) + (py[j]-py[i])*(nguy-ngdy*du1)); + uu[nn] = (px[j]-px[i])*f + px[i]; + vv[nn] = (py[j]-py[i])*f + py[i]; nn++; + } + if ((du0 < duj) != (du0 < dui)) + { + f = -( px[i] *(ngux-ngdx*du0) + py[i] *(nguy-ngdy*du0) + (nguo-ngdo*du0)) / + ((px[j]-px[i])*(ngux-ngdx*du0) + (py[j]-py[i])*(nguy-ngdy*du0)); + uu[nn] = (px[j]-px[i])*f + px[i]; + vv[nn] = (py[j]-py[i])*f + py[i]; nn++; + } + } + else + { + if ((du0 < duj) != (du0 < dui)) + { + f = -( px[i] *(ngux-ngdx*du0) + py[i] *(nguy-ngdy*du0) + (nguo-ngdo*du0)) / + ((px[j]-px[i])*(ngux-ngdx*du0) + (py[j]-py[i])*(nguy-ngdy*du0)); + uu[nn] = (px[j]-px[i])*f + px[i]; + vv[nn] = (py[j]-py[i])*f + py[i]; nn++; + } + if ((du1 < duj) != (du1 < dui)) + { + f = -( px[i] *(ngux-ngdx*du1) + py[i] *(nguy-ngdy*du1) + (nguo-ngdo*du1)) / + ((px[j]-px[i])*(ngux-ngdx*du1) + (py[j]-py[i])*(nguy-ngdy*du1)); + uu[nn] = (px[j]-px[i])*f + px[i]; + vv[nn] = (py[j]-py[i])*f + py[i]; nn++; + } + } + i = j; + } while (i); + if (nn < 3) continue; - bglBegin(GL_TRIANGLE_FAN); - for(i=0;i>4); - } - else - { - dacol = palookup[0][(long)(*(char *)(waloff[globalpicnum]))+(min(max(globalshade,0),numpalookups-1)<<8)]; - } + tsizxm1 = tsizx-1; xmodnice = (!(tsizxm1&tsizx)); + tsizym1 = tsizy-1; ymulnice = (!(tsizym1&tsizy)); + if ((method&4) && (!xmodnice)) //Sprites don't need a mod on texture coordinates + { xmodnice = 1; for(tsizxm1=1;tsizxm1>4); + } + else + { + dacol = palookup[0][(long)(*(char *)(waloff[globalpicnum]))+(min(max(globalshade,0),numpalookups-1)<<8)]; + } - if (grhalfxdown10x < 0) //Hack for mirrors - { - for(i=((n-1)>>1);i>=0;i--) - { - r = px[i]; px[i] = ((double)xdimen)-px[n-1-i]; px[n-1-i] = ((double)xdimen)-r; - r = py[i]; py[i] = py[n-1-i]; py[n-1-i] = r; - } - ngdo += ((double)xdimen)*ngdx; ngdx = -ngdx; - nguo += ((double)xdimen)*ngux; ngux = -ngux; - ngvo += ((double)xdimen)*ngvx; ngvx = -ngvx; - } + if (grhalfxdown10x < 0) //Hack for mirrors + { + for(i=((n-1)>>1);i>=0;i--) + { + r = px[i]; px[i] = ((double)xdimen)-px[n-1-i]; px[n-1-i] = ((double)xdimen)-r; + r = py[i]; py[i] = py[n-1-i]; py[n-1-i] = r; + } + ngdo += ((double)xdimen)*ngdx; ngdx = -ngdx; + nguo += ((double)xdimen)*ngux; ngux = -ngux; + ngvo += ((double)xdimen)*ngvx; ngvx = -ngvx; + } - ngdx2 = ngdx*(1<= py[1]); maxi = 1-mini; - for(z=2;z py[maxi]) maxi = z; - } + mini = (py[0] >= py[1]); maxi = 1-mini; + for(z=2;z py[maxi]) maxi = z; + } - i = maxi; dtol(py[i],&yy); if (yy > ydimen) yy = ydimen; - do - { - j = i+1; if (j == n) j = 0; - dtol(py[j],&y); if (y < 0) y = 0; - if (y < yy) - { - f = (px[j]-px[i])/(py[j]-py[i]); dtol(f*16384.0,&xi); - dtol((((double)yy-.5-py[j])*f + px[j])*16384.0+8192.0,&x); - for(;yy>y;yy--,x-=xi) lastx[yy-1] = (x>>14); - } - i = j; - } while (i != mini); - do - { - j = i+1; if (j == n) j = 0; - dtol(py[j],&yy); if (yy > ydimen) yy = ydimen; - if (y < yy) - { - f = (px[j]-px[i])/(py[j]-py[i]); dtol(f*16384.0,&xi); - dtol((((double)y+.5-py[j])*f + px[j])*16384.0+8192.0,&x); - for(;y>14); if (ix1 > xdimen) ix1 = xdimen; - if (ix0 < ix1) - { - if (rendmode == 1) - memset((void *)(ylookup[y]+ix0+frameoffset),dacol,ix1-ix0); - else - { - vidp = (char *)(ylookup[y]+frameoffset+ix0); - dp = ngdx*(double)ix0 + ngdy*(double)y + ngdo; - up = ngux*(double)ix0 + nguy*(double)y + nguo; - vp = ngvx*(double)ix0 + ngvy*(double)y + ngvo; - rdp = 65536.0/dp; dp += ngdx2; - dtol( rdp,&d0); - dtol(up*rdp,&u0); up += ngux2; - dtol(vp*rdp,&v0); vp += ngvx2; - rdp = 65536.0/dp; + i = maxi; dtol(py[i],&yy); if (yy > ydimen) yy = ydimen; + do + { + j = i+1; if (j == n) j = 0; + dtol(py[j],&y); if (y < 0) y = 0; + if (y < yy) + { + f = (px[j]-px[i])/(py[j]-py[i]); dtol(f*16384.0,&xi); + dtol((((double)yy-.5-py[j])*f + px[j])*16384.0+8192.0,&x); + for(;yy>y;yy--,x-=xi) lastx[yy-1] = (x>>14); + } + i = j; + } while (i != mini); + do + { + j = i+1; if (j == n) j = 0; + dtol(py[j],&yy); if (yy > ydimen) yy = ydimen; + if (y < yy) + { + f = (px[j]-px[i])/(py[j]-py[i]); dtol(f*16384.0,&xi); + dtol((((double)y+.5-py[j])*f + px[j])*16384.0+8192.0,&x); + for(;y>14); if (ix1 > xdimen) ix1 = xdimen; + if (ix0 < ix1) + { + if (rendmode == 1) + memset((void *)(ylookup[y]+ix0+frameoffset),dacol,ix1-ix0); + else + { + vidp = (char *)(ylookup[y]+frameoffset+ix0); + dp = ngdx*(double)ix0 + ngdy*(double)y + ngdo; + up = ngux*(double)ix0 + nguy*(double)y + nguo; + vp = ngvx*(double)ix0 + ngvy*(double)y + ngvo; + rdp = 65536.0/dp; dp += ngdx2; + dtol( rdp,&d0); + dtol(up*rdp,&u0); up += ngux2; + dtol(vp*rdp,&v0); vp += ngvx2; + rdp = 65536.0/dp; - switch (method&3) - { - case 0: - if (xmodnice&ymulnice) //both u&v texture sizes are powers of 2 :) - { - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16)&tsizxm1)<>16)&tsizym1)]]; //+((d0>>13)&0x3f00)]; + vidp[0] = palptr[walptr[(((u0>>16)&tsizxm1)<>16)&tsizym1)]]; //+((d0>>13)&0x3f00)]; #else - vidp[0] = ((d0>>16)&255); + vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - } - else - { - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]]; //+((d0>>13)&0x3f00)]; + vidp[0] = palptr[walptr[imod(u0>>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]]; //+((d0>>13)&0x3f00)]; #else - vidp[0] = ((d0>>16)&255); + vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - } - break; - case 1: - if (xmodnice) //both u&v texture sizes are powers of 2 :) - { - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16)&tsizxm1)*tsizy) + ((v0>>16)&tsizym1)]; + d0 += d1; u0 += u1; v0 += v1; vidp++; + } + } + } + break; + case 1: + if (xmodnice) //both u&v texture sizes are powers of 2 :) + { + for(xx=ix0;xx>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16)&tsizxm1)*tsizy) + ((v0>>16)&tsizym1)]; #if (DEPTHDEBUG == 0) #if (USEZBUFFER != 0) - if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) - { - zbufoff[(long)vidp] = d0; - vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; - } + if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) + { + zbufoff[(long)vidp] = d0; + vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; + } #else - if (dacol != 255) vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; + if (dacol != 255) vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; #endif #else - if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); + if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - } - else - { - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; + d0 += d1; u0 += u1; v0 += v1; vidp++; + } + } + } + else + { + for(xx=ix0;xx>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; #if (DEPTHDEBUG == 0) #if (USEZBUFFER != 0) - if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) - { - zbufoff[(long)vidp] = d0; - vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; - } + if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) + { + zbufoff[(long)vidp] = d0; + vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; + } #else - if (dacol != 255) vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; + if (dacol != 255) vidp[0] = palptr[((long)dacol)]; //+((d0>>13)&0x3f00)]; #endif #else - if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); + if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - } - break; - case 2: //Transluscence #1 - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; - //dacol = walptr[(((u0>>16)&tsizxm1)<>16)&tsizym1)]; + d0 += d1; u0 += u1; v0 += v1; vidp++; + } + } + } + break; + case 2: //Transluscence #1 + for(xx=ix0;xx>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; + //dacol = walptr[(((u0>>16)&tsizxm1)<>16)&tsizym1)]; #if (DEPTHDEBUG == 0) #if (USEZBUFFER != 0) - if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) - { - zbufoff[(long)vidp] = d0; - vidp[0] = transluc[(((long)vidp[0])<<8)+((long)palptr[((long)dacol)])]; //+((d0>>13)&0x3f00)])]; - } + if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) + { + zbufoff[(long)vidp] = d0; + vidp[0] = transluc[(((long)vidp[0])<<8)+((long)palptr[((long)dacol)])]; //+((d0>>13)&0x3f00)])]; + } #else - if (dacol != 255) - vidp[0] = transluc[(((long)vidp[0])<<8)+((long)palptr[((long)dacol)])]; //+((d0>>13)&0x3f00)])]; + if (dacol != 255) + vidp[0] = transluc[(((long)vidp[0])<<8)+((long)palptr[((long)dacol)])]; //+((d0>>13)&0x3f00)])]; #endif #else - if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); + if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - break; - case 3: //Transluscence #2 - for(xx=ix0;xx>LINTERPSIZ); - dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); - dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); - rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; - //dacol = walptr[(((u0>>16)&tsizxm1)<>16)&tsizym1)]; + d0 += d1; u0 += u1; v0 += v1; vidp++; + } + } + break; + case 3: //Transluscence #2 + for(xx=ix0;xx>LINTERPSIZ); + dtol(up*rdp,&u1); up += ngux2; u1 = ((u1-u0)>>LINTERPSIZ); + dtol(vp*rdp,&v1); vp += ngvx2; v1 = ((v1-v0)>>LINTERPSIZ); + rdp = 65536.0/dp; vide = &vidp[min(ix1-xx,1<>16,tsizx)*tsizy + ((v0>>16)&tsizym1)]; + //dacol = walptr[(((u0>>16)&tsizxm1)<>16)&tsizym1)]; #if (DEPTHDEBUG == 0) #if (USEZBUFFER != 0) - if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) - { - zbufoff[(long)vidp] = d0; - vidp[0] = transluc[((long)vidp[0])+(((long)palptr[((long)dacol)/*+((d0>>13)&0x3f00)*/])<<8)]; - } + if ((dacol != 255) && (d0 <= zbufoff[(long)vidp])) + { + zbufoff[(long)vidp] = d0; + vidp[0] = transluc[((long)vidp[0])+(((long)palptr[((long)dacol)/*+((d0>>13)&0x3f00)*/])<<8)]; + } #else - if (dacol != 255) - vidp[0] = transluc[((long)vidp[0])+(((long)palptr[((long)dacol)/*+((d0>>13)&0x3f00)*/])<<8)]; + if (dacol != 255) + vidp[0] = transluc[((long)vidp[0])+(((long)palptr[((long)dacol)/*+((d0>>13)&0x3f00)*/])<<8)]; #endif #else - if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); + if ((dacol != 255) && (vidp[0] > (d0>>16))) vidp[0] = ((d0>>16)&255); #endif - d0 += d1; u0 += u1; v0 += v1; vidp++; - } - } - break; - } - } - } - } - } - i = j; - } while (i != maxi); + d0 += d1; u0 += u1; v0 += v1; vidp++; + } + } + break; + } + } + } + } + } + i = j; + } while (i != maxi); - if (rendmode == 1) - { - if (method&3) //Only draw border around sprites/maskwalls - { - for(i=0,j=n-1;i=2;i--) if (px[i] < px[imin]) imin = i; + if (n < 3) return; + imin = (px[1] < px[0]); + for(i=n-1;i>=2;i--) if (px[i] < px[imin]) imin = i; - vsp[vcnt].x = px[imin]; - vsp[vcnt].cy[0] = vsp[vcnt].fy[0] = py[imin]; - vcnt++; - i = imin+1; if (i >= n) i = 0; - j = imin-1; if (j < 0) j = n-1; - do - { - if (px[i] < px[j]) - { - if ((vcnt > 1) && (px[i] <= vsp[vcnt-1].x)) vcnt--; - vsp[vcnt].x = px[i]; - vsp[vcnt].cy[0] = py[i]; - k = j+1; if (k >= n) k = 0; - //(px[k],py[k]) - //(px[i],?) - //(px[j],py[j]) - vsp[vcnt].fy[0] = (px[i]-px[k])*(py[j]-py[k])/(px[j]-px[k]) + py[k]; - vcnt++; - i++; if (i >= n) i = 0; - } - else if (px[j] < px[i]) - { - if ((vcnt > 1) && (px[j] <= vsp[vcnt-1].x)) vcnt--; - vsp[vcnt].x = px[j]; - vsp[vcnt].fy[0] = py[j]; - k = i-1; if (k < 0) k = n-1; - //(px[k],py[k]) - //(px[j],?) - //(px[i],py[i]) - vsp[vcnt].cy[0] = (px[j]-px[k])*(py[i]-py[k])/(px[i]-px[k]) + py[k]; - vcnt++; - j--; if (j < 0) j = n-1; - } - else - { - if ((vcnt > 1) && (px[i] <= vsp[vcnt-1].x)) vcnt--; - vsp[vcnt].x = px[i]; - vsp[vcnt].cy[0] = py[i]; - vsp[vcnt].fy[0] = py[j]; - vcnt++; - i++; if (i >= n) i = 0; if (i == j) break; - j--; if (j < 0) j = n-1; - } - } while (i != j); - if (px[i] > vsp[vcnt-1].x) - { - vsp[vcnt].x = px[i]; - vsp[vcnt].cy[0] = vsp[vcnt].fy[0] = py[i]; - vcnt++; - } + vsp[vcnt].x = px[imin]; + vsp[vcnt].cy[0] = vsp[vcnt].fy[0] = py[imin]; + vcnt++; + i = imin+1; if (i >= n) i = 0; + j = imin-1; if (j < 0) j = n-1; + do + { + if (px[i] < px[j]) + { + if ((vcnt > 1) && (px[i] <= vsp[vcnt-1].x)) vcnt--; + vsp[vcnt].x = px[i]; + vsp[vcnt].cy[0] = py[i]; + k = j+1; if (k >= n) k = 0; + //(px[k],py[k]) + //(px[i],?) + //(px[j],py[j]) + vsp[vcnt].fy[0] = (px[i]-px[k])*(py[j]-py[k])/(px[j]-px[k]) + py[k]; + vcnt++; + i++; if (i >= n) i = 0; + } + else if (px[j] < px[i]) + { + if ((vcnt > 1) && (px[j] <= vsp[vcnt-1].x)) vcnt--; + vsp[vcnt].x = px[j]; + vsp[vcnt].fy[0] = py[j]; + k = i-1; if (k < 0) k = n-1; + //(px[k],py[k]) + //(px[j],?) + //(px[i],py[i]) + vsp[vcnt].cy[0] = (px[j]-px[k])*(py[i]-py[k])/(px[i]-px[k]) + py[k]; + vcnt++; + j--; if (j < 0) j = n-1; + } + else + { + if ((vcnt > 1) && (px[i] <= vsp[vcnt-1].x)) vcnt--; + vsp[vcnt].x = px[i]; + vsp[vcnt].cy[0] = py[i]; + vsp[vcnt].fy[0] = py[j]; + vcnt++; + i++; if (i >= n) i = 0; if (i == j) break; + j--; if (j < 0) j = n-1; + } + } while (i != j); + if (px[i] > vsp[vcnt-1].x) + { + vsp[vcnt].x = px[i]; + vsp[vcnt].cy[0] = vsp[vcnt].fy[0] = py[i]; + vcnt++; + } - for(i=0;i= 0)) return(1); - } - return(0); + for(i=vsp[0].n;i;i=newi) + { + newi = vsp[i].n; + if ((x0 < vsp[newi].x) && (vsp[i].x < x1) && (vsp[i].ctag >= 0)) return(1); + } + return(0); } static long domostpolymethod = 0; void domost (float x0, float y0, float x1, float y1) { - double dpx[4], dpy[4]; - float d, f, n, t, slop, dx, dx0, dx1, nx, nx0, ny0, nx1, ny1; - float spx[4], spy[4], cy[2], cv[2]; - long i, j, k, z, ni, vcnt = 0, scnt, newi, dir, spt[4]; - - if (x0 < x1) - { - dir = 1; //clip dmost (floor) - y0 -= .01; y1 -= .01; - } - else - { - if (x0 == x1) return; - f = x0; x0 = x1; x1 = f; - f = y0; y0 = y1; y1 = f; - dir = 0; //clip umost (ceiling) - //y0 += .01; y1 += .01; //necessary? - } + double dpx[4], dpy[4]; + float d, f, n, t, slop, dx, dx0, dx1, nx, nx0, ny0, nx1, ny1; + float spx[4], spy[4], cy[2], cv[2]; + long i, j, k, z, ni, vcnt = 0, scnt, newi, dir, spt[4]; - slop = (y1-y0)/(x1-x0); - for(i=vsp[0].n;i;i=newi) - { - newi = vsp[i].n; nx0 = vsp[i].x; nx1 = vsp[newi].x; - if ((x0 >= nx1) || (nx0 >= x1) || (vsp[i].ctag <= 0)) continue; - dx = nx1-nx0; - cy[0] = vsp[i].cy[0]; cv[0] = vsp[i].cy[1]-cy[0]; - cy[1] = vsp[i].fy[0]; cv[1] = vsp[i].fy[1]-cy[1]; + if (x0 < x1) + { + dir = 1; //clip dmost (floor) + y0 -= .01; y1 -= .01; + } + else + { + if (x0 == x1) return; + f = x0; x0 = x1; x1 = f; + f = y0; y0 = y1; y1 = f; + dir = 0; //clip umost (ceiling) + //y0 += .01; y1 += .01; //necessary? + } - scnt = 0; + slop = (y1-y0)/(x1-x0); + for(i=vsp[0].n;i;i=newi) + { + newi = vsp[i].n; nx0 = vsp[i].x; nx1 = vsp[newi].x; + if ((x0 >= nx1) || (nx0 >= x1) || (vsp[i].ctag <= 0)) continue; + dx = nx1-nx0; + cy[0] = vsp[i].cy[0]; cv[0] = vsp[i].cy[1]-cy[0]; + cy[1] = vsp[i].fy[0]; cv[1] = vsp[i].fy[1]-cy[1]; - //Test if left edge requires split (x0,y0) (nx0,cy(0)), - if ((x0 > nx0) && (x0 < nx1)) - { - t = (x0-nx0)*cv[dir] - (y0-cy[dir])*dx; - if (((!dir) && (t < 0)) || ((dir) && (t > 0))) - { spx[scnt] = x0; spy[scnt] = y0; spt[scnt] = -1; scnt++; } - } + scnt = 0; - //Test for intersection on umost (j == 0) and dmost (j == 1) - for(j=0;j<2;j++) - { - d = (y0-y1)*dx - (x0-x1)*cv[j]; - n = (y0-cy[j])*dx - (x0-nx0)*cv[j]; - if ((fabs(n) <= fabs(d)) && (d*n >= 0) && (d != 0)) - { - t = n/d; nx = (x1-x0)*t + x0; - if ((nx > nx0) && (nx < nx1)) - { - spx[scnt] = nx; spy[scnt] = (y1-y0)*t + y0; - spt[scnt] = j; scnt++; - } - } - } + //Test if left edge requires split (x0,y0) (nx0,cy(0)), + if ((x0 > nx0) && (x0 < nx1)) + { + t = (x0-nx0)*cv[dir] - (y0-cy[dir])*dx; + if (((!dir) && (t < 0)) || ((dir) && (t > 0))) + { spx[scnt] = x0; spy[scnt] = y0; spt[scnt] = -1; scnt++; } + } - //Nice hack to avoid full sort later :) - if ((scnt >= 2) && (spx[scnt-1] < spx[scnt-2])) - { - f = spx[scnt-1]; spx[scnt-1] = spx[scnt-2]; spx[scnt-2] = f; - f = spy[scnt-1]; spy[scnt-1] = spy[scnt-2]; spy[scnt-2] = f; - j = spt[scnt-1]; spt[scnt-1] = spt[scnt-2]; spt[scnt-2] = j; - } + //Test for intersection on umost (j == 0) and dmost (j == 1) + for(j=0;j<2;j++) + { + d = (y0-y1)*dx - (x0-x1)*cv[j]; + n = (y0-cy[j])*dx - (x0-nx0)*cv[j]; + if ((fabs(n) <= fabs(d)) && (d*n >= 0) && (d != 0)) + { + t = n/d; nx = (x1-x0)*t + x0; + if ((nx > nx0) && (nx < nx1)) + { + spx[scnt] = nx; spy[scnt] = (y1-y0)*t + y0; + spt[scnt] = j; scnt++; + } + } + } - //Test if right edge requires split - if ((x1 > nx0) && (x1 < nx1)) - { - t = (x1-nx0)*cv[dir] - (y1-cy[dir])*dx; - if (((!dir) && (t < 0)) || ((dir) && (t > 0))) - { spx[scnt] = x1; spy[scnt] = y1; spt[scnt] = -1; scnt++; } - } + //Nice hack to avoid full sort later :) + if ((scnt >= 2) && (spx[scnt-1] < spx[scnt-2])) + { + f = spx[scnt-1]; spx[scnt-1] = spx[scnt-2]; spx[scnt-2] = f; + f = spy[scnt-1]; spy[scnt-1] = spy[scnt-2]; spy[scnt-2] = f; + j = spt[scnt-1]; spt[scnt-1] = spt[scnt-2]; spt[scnt-2] = j; + } - vsp[i].tag = vsp[newi].tag = -1; - for(z=0;z<=scnt;z++,i=vcnt) - { - if (z < scnt) - { - vcnt = vsinsaft(i); - t = (spx[z]-nx0)/dx; - vsp[i].cy[1] = t*cv[0] + cy[0]; - vsp[i].fy[1] = t*cv[1] + cy[1]; - vsp[vcnt].x = spx[z]; - vsp[vcnt].cy[0] = vsp[i].cy[1]; - vsp[vcnt].fy[0] = vsp[i].fy[1]; - vsp[vcnt].tag = spt[z]; - } + //Test if right edge requires split + if ((x1 > nx0) && (x1 < nx1)) + { + t = (x1-nx0)*cv[dir] - (y1-cy[dir])*dx; + if (((!dir) && (t < 0)) || ((dir) && (t > 0))) + { spx[scnt] = x1; spy[scnt] = y1; spt[scnt] = -1; scnt++; } + } - ni = vsp[i].n; if (!ni) continue; //this 'if' fixes many bugs! - dx0 = vsp[i].x; if (x0 > dx0) continue; - dx1 = vsp[ni].x; if (x1 < dx1) continue; - ny0 = (dx0-x0)*slop + y0; - ny1 = (dx1-x0)*slop + y0; + vsp[i].tag = vsp[newi].tag = -1; + for(z=0;z<=scnt;z++,i=vcnt) + { + if (z < scnt) + { + vcnt = vsinsaft(i); + t = (spx[z]-nx0)/dx; + vsp[i].cy[1] = t*cv[0] + cy[0]; + vsp[i].fy[1] = t*cv[1] + cy[1]; + vsp[vcnt].x = spx[z]; + vsp[vcnt].cy[0] = vsp[i].cy[1]; + vsp[vcnt].fy[0] = vsp[i].fy[1]; + vsp[vcnt].tag = spt[z]; + } - // dx0 dx1 - // ~ ~ - //---------------------------- - // t0+=0 t1+=0 - // vsp[i].cy[0] vsp[i].cy[1] - //============================ - // t0+=1 t1+=3 - //============================ - // vsp[i].fy[0] vsp[i].fy[1] - // t0+=2 t1+=6 - // - // ny0 ? ny1 ? + ni = vsp[i].n; if (!ni) continue; //this 'if' fixes many bugs! + dx0 = vsp[i].x; if (x0 > dx0) continue; + dx1 = vsp[ni].x; if (x1 < dx1) continue; + ny0 = (dx0-x0)*slop + y0; + ny1 = (dx1-x0)*slop + y0; - k = 1+3; - if ((vsp[i].tag == 0) || (ny0 <= vsp[i].cy[0]+.01)) k--; - if ((vsp[i].tag == 1) || (ny0 >= vsp[i].fy[0]-.01)) k++; - if ((vsp[ni].tag == 0) || (ny1 <= vsp[i].cy[1]+.01)) k -= 3; - if ((vsp[ni].tag == 1) || (ny1 >= vsp[i].fy[1]-.01)) k += 3; + // dx0 dx1 + // ~ ~ + //---------------------------- + // t0+=0 t1+=0 + // vsp[i].cy[0] vsp[i].cy[1] + //============================ + // t0+=1 t1+=3 + //============================ + // vsp[i].fy[0] vsp[i].fy[1] + // t0+=2 t1+=6 + // + // ny0 ? ny1 ? - if (!dir) - { - switch(k) - { - case 1: case 2: - dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; - dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; - dpx[2] = dx0; dpy[2] = ny0; drawpoly(dpx,dpy,3,domostpolymethod); - vsp[i].cy[0] = ny0; vsp[i].ctag = gtag; break; - case 3: case 6: - dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; - dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; - dpx[2] = dx1; dpy[2] = ny1; drawpoly(dpx,dpy,3,domostpolymethod); - vsp[i].cy[1] = ny1; vsp[i].ctag = gtag; break; - case 4: case 5: case 7: - dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; - dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; - dpx[2] = dx1; dpy[2] = ny1; - dpx[3] = dx0; dpy[3] = ny0; drawpoly(dpx,dpy,4,domostpolymethod); - vsp[i].cy[0] = ny0; vsp[i].cy[1] = ny1; vsp[i].ctag = gtag; break; - case 8: - dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; - dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; - dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; - dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); - vsp[i].ctag = vsp[i].ftag = -1; break; - default: break; - } - } - else - { - switch(k) - { - case 7: case 6: - dpx[0] = dx0; dpy[0] = ny0; - dpx[1] = dx1; dpy[1] = vsp[i].fy[1]; - dpx[2] = dx0; dpy[2] = vsp[i].fy[0]; drawpoly(dpx,dpy,3,domostpolymethod); - vsp[i].fy[0] = ny0; vsp[i].ftag = gtag; break; - case 5: case 2: - dpx[0] = dx0; dpy[0] = vsp[i].fy[0]; - dpx[1] = dx1; dpy[1] = ny1; - dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; drawpoly(dpx,dpy,3,domostpolymethod); - vsp[i].fy[1] = ny1; vsp[i].ftag = gtag; break; - case 4: case 3: case 1: - dpx[0] = dx0; dpy[0] = ny0; - dpx[1] = dx1; dpy[1] = ny1; - dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; - dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); - vsp[i].fy[0] = ny0; vsp[i].fy[1] = ny1; vsp[i].ftag = gtag; break; - case 0: - dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; - dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; - dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; - dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); - vsp[i].ctag = vsp[i].ftag = -1; break; - default: break; - } - } - } - } + k = 1+3; + if ((vsp[i].tag == 0) || (ny0 <= vsp[i].cy[0]+.01)) k--; + if ((vsp[i].tag == 1) || (ny0 >= vsp[i].fy[0]-.01)) k++; + if ((vsp[ni].tag == 0) || (ny1 <= vsp[i].cy[1]+.01)) k -= 3; + if ((vsp[ni].tag == 1) || (ny1 >= vsp[i].fy[1]-.01)) k += 3; - gtag++; + if (!dir) + { + switch(k) + { + case 1: case 2: + dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; + dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; + dpx[2] = dx0; dpy[2] = ny0; drawpoly(dpx,dpy,3,domostpolymethod); + vsp[i].cy[0] = ny0; vsp[i].ctag = gtag; break; + case 3: case 6: + dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; + dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; + dpx[2] = dx1; dpy[2] = ny1; drawpoly(dpx,dpy,3,domostpolymethod); + vsp[i].cy[1] = ny1; vsp[i].ctag = gtag; break; + case 4: case 5: case 7: + dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; + dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; + dpx[2] = dx1; dpy[2] = ny1; + dpx[3] = dx0; dpy[3] = ny0; drawpoly(dpx,dpy,4,domostpolymethod); + vsp[i].cy[0] = ny0; vsp[i].cy[1] = ny1; vsp[i].ctag = gtag; break; + case 8: + dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; + dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; + dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; + dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); + vsp[i].ctag = vsp[i].ftag = -1; break; + default: break; + } + } + else + { + switch(k) + { + case 7: case 6: + dpx[0] = dx0; dpy[0] = ny0; + dpx[1] = dx1; dpy[1] = vsp[i].fy[1]; + dpx[2] = dx0; dpy[2] = vsp[i].fy[0]; drawpoly(dpx,dpy,3,domostpolymethod); + vsp[i].fy[0] = ny0; vsp[i].ftag = gtag; break; + case 5: case 2: + dpx[0] = dx0; dpy[0] = vsp[i].fy[0]; + dpx[1] = dx1; dpy[1] = ny1; + dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; drawpoly(dpx,dpy,3,domostpolymethod); + vsp[i].fy[1] = ny1; vsp[i].ftag = gtag; break; + case 4: case 3: case 1: + dpx[0] = dx0; dpy[0] = ny0; + dpx[1] = dx1; dpy[1] = ny1; + dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; + dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); + vsp[i].fy[0] = ny0; vsp[i].fy[1] = ny1; vsp[i].ftag = gtag; break; + case 0: + dpx[0] = dx0; dpy[0] = vsp[i].cy[0]; + dpx[1] = dx1; dpy[1] = vsp[i].cy[1]; + dpx[2] = dx1; dpy[2] = vsp[i].fy[1]; + dpx[3] = dx0; dpy[3] = vsp[i].fy[0]; drawpoly(dpx,dpy,4,domostpolymethod); + vsp[i].ctag = vsp[i].ftag = -1; break; + default: break; + } + } + } + } - //Combine neighboring vertical strips with matching collinear top&bottom edges - //This prevents x-splits from propagating through the entire scan - i = vsp[0].n; - while (i) - { - ni = vsp[i].n; - if ((vsp[i].cy[0] >= vsp[i].fy[0]) && (vsp[i].cy[1] >= vsp[i].fy[1])) { vsp[i].ctag = vsp[i].ftag = -1; } - if ((vsp[i].ctag == vsp[ni].ctag) && (vsp[i].ftag == vsp[ni].ftag)) - { vsp[i].cy[1] = vsp[ni].cy[1]; vsp[i].fy[1] = vsp[ni].fy[1]; vsdel(ni); } - else i = ni; - } + gtag++; + + //Combine neighboring vertical strips with matching collinear top&bottom edges + //This prevents x-splits from propagating through the entire scan + i = vsp[0].n; + while (i) + { + ni = vsp[i].n; + if ((vsp[i].cy[0] >= vsp[i].fy[0]) && (vsp[i].cy[1] >= vsp[i].fy[1])) { vsp[i].ctag = vsp[i].ftag = -1; } + if ((vsp[i].ctag == vsp[ni].ctag) && (vsp[i].ftag == vsp[ni].ftag)) + { vsp[i].cy[1] = vsp[ni].cy[1]; vsp[i].fy[1] = vsp[ni].fy[1]; vsdel(ni); } + else i = ni; + } } static void polymost_scansector (long sectnum); static void polymost_drawalls (long bunch) { - sectortype *sec, *nextsec; - walltype *wal, *wal2, *nwal; - double ox, oy, oz, ox2, oy2, px[3], py[3], dd[3], uu[3], vv[3]; - double fx, fy, x0, x1, y0, y1, cy0, cy1, fy0, fy1, xp0, yp0, xp1, yp1, ryp0, ryp1, nx0, ny0, nx1, ny1; - double t, r, t0, t1, ocy0, ocy1, ofy0, ofy1, oxp0, oyp0, ft[4]; - double oguo, ogux, oguy; - long i, x, y, z, cz, fz, wallnum, sectnum, nextsectnum; + sectortype *sec, *nextsec; + walltype *wal, *wal2, *nwal; + double ox, oy, oz, ox2, oy2, px[3], py[3], dd[3], uu[3], vv[3]; + double fx, fy, x0, x1, y0, y1, cy0, cy1, fy0, fy1, xp0, yp0, xp1, yp1, ryp0, ryp1, nx0, ny0, nx1, ny1; + double t, r, t0, t1, ocy0, ocy1, ofy0, ofy1, oxp0, oyp0, ft[4]; + double oguo, ogux, oguy; + long i, x, y, z, cz, fz, wallnum, sectnum, nextsectnum; - sectnum = thesector[bunchfirst[bunch]]; sec = §or[sectnum]; + sectnum = thesector[bunchfirst[bunch]]; sec = §or[sectnum]; #ifdef USE_OPENGL - if (!nofog) { - if (rendmode == 3) { - float col[4]; - col[0] = (float)palookupfog[sec->floorpal].r / 63.f; - col[1] = (float)palookupfog[sec->floorpal].g / 63.f; - col[2] = (float)palookupfog[sec->floorpal].b / 63.f; - col[3] = 0; - bglFogfv(GL_FOG_COLOR,col); - bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); - } - } + if (!nofog) { + if (rendmode == 3) { + float col[4]; + col[0] = (float)palookupfog[sec->floorpal].r / 63.f; + col[1] = (float)palookupfog[sec->floorpal].g / 63.f; + col[2] = (float)palookupfog[sec->floorpal].b / 63.f; + col[3] = 0; + bglFogfv(GL_FOG_COLOR,col); + bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); + } + } #endif - //DRAW WALLS SECTION! - for(z=bunchfirst[bunch];z>=0;z=p2[z]) - { - wallnum = thewall[z]; wal = &wall[wallnum]; wal2 = &wall[wal->point2]; - nextsectnum = wal->nextsector; nextsec = §or[nextsectnum]; + //DRAW WALLS SECTION! + for(z=bunchfirst[bunch];z>=0;z=p2[z]) + { + wallnum = thewall[z]; wal = &wall[wallnum]; wal2 = &wall[wal->point2]; + nextsectnum = wal->nextsector; nextsec = §or[nextsectnum]; - //Offset&Rotate 3D coordinates to screen 3D space - x = wal->x-globalposx; y = wal->y-globalposy; - xp0 = (double)y*gcosang - (double)x*gsinang; - yp0 = (double)x*gcosang2 + (double)y*gsinang2; - x = wal2->x-globalposx; y = wal2->y-globalposy; - xp1 = (double)y*gcosang - (double)x*gsinang; - yp1 = (double)x*gcosang2 + (double)y*gsinang2; + //Offset&Rotate 3D coordinates to screen 3D space + x = wal->x-globalposx; y = wal->y-globalposy; + xp0 = (double)y*gcosang - (double)x*gsinang; + yp0 = (double)x*gcosang2 + (double)y*gsinang2; + x = wal2->x-globalposx; y = wal2->y-globalposy; + xp1 = (double)y*gcosang - (double)x*gsinang; + yp1 = (double)x*gcosang2 + (double)y*gsinang2; - oxp0 = xp0; oyp0 = yp0; + oxp0 = xp0; oyp0 = yp0; - //Clip to close parallel-screen plane - if (yp0 < SCISDIST) - { - if (yp1 < SCISDIST) continue; - t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; - nx0 = (wal2->x-wal->x)*t0+wal->x; - ny0 = (wal2->y-wal->y)*t0+wal->y; - } - else { t0 = 0.f; nx0 = wal->x; ny0 = wal->y; } - if (yp1 < SCISDIST) - { - t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; - nx1 = (wal2->x-wal->x)*t1+wal->x; - ny1 = (wal2->y-wal->y)*t1+wal->y; - } - else { t1 = 1.f; nx1 = wal2->x; ny1 = wal2->y; } + //Clip to close parallel-screen plane + if (yp0 < SCISDIST) + { + if (yp1 < SCISDIST) continue; + t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; + nx0 = (wal2->x-wal->x)*t0+wal->x; + ny0 = (wal2->y-wal->y)*t0+wal->y; + } + else { t0 = 0.f; nx0 = wal->x; ny0 = wal->y; } + if (yp1 < SCISDIST) + { + t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; + nx1 = (wal2->x-wal->x)*t1+wal->x; + ny1 = (wal2->y-wal->y)*t1+wal->y; + } + else { t1 = 1.f; nx1 = wal2->x; ny1 = wal2->y; } - ryp0 = 1.f/yp0; ryp1 = 1.f/yp1; + ryp0 = 1.f/yp0; ryp1 = 1.f/yp1; - //Generate screen coordinates for front side of wall - x0 = ghalfx*xp0*ryp0 + ghalfx; - x1 = ghalfx*xp1*ryp1 + ghalfx; - if (x1 <= x0) continue; + //Generate screen coordinates for front side of wall + x0 = ghalfx*xp0*ryp0 + ghalfx; + x1 = ghalfx*xp1*ryp1 + ghalfx; + if (x1 <= x0) continue; - ryp0 *= gyxscale; ryp1 *= gyxscale; + ryp0 *= gyxscale; ryp1 *= gyxscale; - getzsofslope(sectnum,(long)nx0,(long)ny0,&cz,&fz); - cy0 = ((float)(cz-globalposz))*ryp0 + ghoriz; - fy0 = ((float)(fz-globalposz))*ryp0 + ghoriz; - getzsofslope(sectnum,(long)nx1,(long)ny1,&cz,&fz); - cy1 = ((float)(cz-globalposz))*ryp1 + ghoriz; - fy1 = ((float)(fz-globalposz))*ryp1 + ghoriz; + getzsofslope(sectnum,(long)nx0,(long)ny0,&cz,&fz); + cy0 = ((float)(cz-globalposz))*ryp0 + ghoriz; + fy0 = ((float)(fz-globalposz))*ryp0 + ghoriz; + getzsofslope(sectnum,(long)nx1,(long)ny1,&cz,&fz); + cy1 = ((float)(cz-globalposz))*ryp1 + ghoriz; + fy1 = ((float)(fz-globalposz))*ryp1 + ghoriz; - globalpicnum = sec->floorpicnum; globalshade = sec->floorshade; globalpal = (long)((unsigned char)sec->floorpal); - globalorientation = sec->floorstat; - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,sectnum); - if (!(globalorientation&1)) - { - //(singlobalang/-16384*(sx-ghalfx) + 0*(sy-ghoriz) + (cosviewingrangeglobalang/16384)*ghalfx)*d + globalposx = u*16 - //(cosglobalang/ 16384*(sx-ghalfx) + 0*(sy-ghoriz) + (sinviewingrangeglobalang/16384)*ghalfx)*d + globalposy = v*16 - //( 0*(sx-ghalfx) + 1*(sy-ghoriz) + ( 0)*ghalfx)*d + globalposz/16 = (sec->floorz/16) - if (!(globalorientation&64)) - { ft[0] = globalposx; ft[1] = globalposy; ft[2] = cosglobalang; ft[3] = singlobalang; } - else - { - //relative alignment - fx = (double)(wall[wall[sec->wallptr].point2].x-wall[sec->wallptr].x); - fy = (double)(wall[wall[sec->wallptr].point2].y-wall[sec->wallptr].y); - r = 1.0/sqrt(fx*fx+fy*fy); fx *= r; fy *= r; - ft[2] = cosglobalang*fx + singlobalang*fy; - ft[3] = singlobalang*fx - cosglobalang*fy; - ft[0] = ((double)(globalposx-wall[sec->wallptr].x))*fx + ((double)(globalposy-wall[sec->wallptr].y))*fy; - ft[1] = ((double)(globalposy-wall[sec->wallptr].y))*fx - ((double)(globalposx-wall[sec->wallptr].x))*fy; - if (!(globalorientation&4)) globalorientation ^= 32; else globalorientation ^= 16; - } - gdx = 0; - gdy = gxyaspect; if (!(globalorientation&2)) gdy /= (double)(sec->floorz-globalposz); - gdo = -ghoriz*gdy; - if (globalorientation&8) { ft[0] /= 8; ft[1] /= -8; ft[2] /= 2097152; ft[3] /= 2097152; } - else { ft[0] /= 16; ft[1] /= -16; ft[2] /= 4194304; ft[3] /= 4194304; } - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; + globalpicnum = sec->floorpicnum; globalshade = sec->floorshade; globalpal = (long)((unsigned char)sec->floorpal); + globalorientation = sec->floorstat; + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,sectnum); + if (!(globalorientation&1)) + { + //(singlobalang/-16384*(sx-ghalfx) + 0*(sy-ghoriz) + (cosviewingrangeglobalang/16384)*ghalfx)*d + globalposx = u*16 + //(cosglobalang/ 16384*(sx-ghalfx) + 0*(sy-ghoriz) + (sinviewingrangeglobalang/16384)*ghalfx)*d + globalposy = v*16 + //( 0*(sx-ghalfx) + 1*(sy-ghoriz) + ( 0)*ghalfx)*d + globalposz/16 = (sec->floorz/16) + if (!(globalorientation&64)) + { ft[0] = globalposx; ft[1] = globalposy; ft[2] = cosglobalang; ft[3] = singlobalang; } + else + { + //relative alignment + fx = (double)(wall[wall[sec->wallptr].point2].x-wall[sec->wallptr].x); + fy = (double)(wall[wall[sec->wallptr].point2].y-wall[sec->wallptr].y); + r = 1.0/sqrt(fx*fx+fy*fy); fx *= r; fy *= r; + ft[2] = cosglobalang*fx + singlobalang*fy; + ft[3] = singlobalang*fx - cosglobalang*fy; + ft[0] = ((double)(globalposx-wall[sec->wallptr].x))*fx + ((double)(globalposy-wall[sec->wallptr].y))*fy; + ft[1] = ((double)(globalposy-wall[sec->wallptr].y))*fx - ((double)(globalposx-wall[sec->wallptr].x))*fy; + if (!(globalorientation&4)) globalorientation ^= 32; else globalorientation ^= 16; + } + gdx = 0; + gdy = gxyaspect; if (!(globalorientation&2)) gdy /= (double)(sec->floorz-globalposz); + gdo = -ghoriz*gdy; + if (globalorientation&8) { ft[0] /= 8; ft[1] /= -8; ft[2] /= 2097152; ft[3] /= 2097152; } + else { ft[0] /= 16; ft[1] /= -16; ft[2] /= 4194304; ft[3] /= 4194304; } + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; - //Texture flipping - if (globalorientation&4) - { - r = gux; gux = gvx; gvx = r; - r = guy; guy = gvy; gvy = r; - r = guo; guo = gvo; gvo = r; - } - if (globalorientation&16) { gux = -gux; guy = -guy; guo = -guo; } - if (globalorientation&32) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } + //Texture flipping + if (globalorientation&4) + { + r = gux; gux = gvx; gvx = r; + r = guy; guy = gvy; gvy = r; + r = guo; guo = gvo; gvo = r; + } + if (globalorientation&16) { gux = -gux; guy = -guy; guo = -guo; } + if (globalorientation&32) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } - //Texture panning - fx = (float)sec->floorxpanning*((float)(1<<(picsiz[globalpicnum]&15)))/256.0; - fy = (float)sec->floorypanning*((float)(1<<(picsiz[globalpicnum]>>4)))/256.0; - if ((globalorientation&(2+64)) == (2+64)) //Hack for panning for slopes w/ relative alignment - { - r = (float)sec->floorheinum / 4096.0; r = 1.0/sqrt(r*r+1); - if (!(globalorientation&4)) fy *= r; else fx *= r; - } - guy += gdy*fx; guo += gdo*fx; - gvy += gdy*fy; gvo += gdo*fy; + //Texture panning + fx = (float)sec->floorxpanning*((float)(1<<(picsiz[globalpicnum]&15)))/256.0; + fy = (float)sec->floorypanning*((float)(1<<(picsiz[globalpicnum]>>4)))/256.0; + if ((globalorientation&(2+64)) == (2+64)) //Hack for panning for slopes w/ relative alignment + { + r = (float)sec->floorheinum / 4096.0; r = 1.0/sqrt(r*r+1); + if (!(globalorientation&4)) fy *= r; else fx *= r; + } + guy += gdy*fx; guo += gdo*fx; + gvy += gdy*fy; gvo += gdo*fy; - if (globalorientation&2) //slopes - { - px[0] = x0; py[0] = ryp0 + ghoriz; - px[1] = x1; py[1] = ryp1 + ghoriz; + if (globalorientation&2) //slopes + { + px[0] = x0; py[0] = ryp0 + ghoriz; + px[1] = x1; py[1] = ryp1 + ghoriz; - //Pick some point guaranteed to be not collinear to the 1st two points - ox = nx0 + (ny1-ny0); - oy = ny0 + (nx0-nx1); - ox2 = (double)(oy-globalposy)*gcosang - (double)(ox-globalposx)*gsinang; - oy2 = (double)(ox-globalposx)*gcosang2 + (double)(oy-globalposy)*gsinang2; - oy2 = 1.0/oy2; - px[2] = ghalfx*ox2*oy2 + ghalfx; oy2 *= gyxscale; - py[2] = oy2 + ghoriz; + //Pick some point guaranteed to be not collinear to the 1st two points + ox = nx0 + (ny1-ny0); + oy = ny0 + (nx0-nx1); + ox2 = (double)(oy-globalposy)*gcosang - (double)(ox-globalposx)*gsinang; + oy2 = (double)(ox-globalposx)*gcosang2 + (double)(oy-globalposy)*gsinang2; + oy2 = 1.0/oy2; + px[2] = ghalfx*ox2*oy2 + ghalfx; oy2 *= gyxscale; + py[2] = oy2 + ghoriz; - for(i=0;i<3;i++) - { - dd[i] = px[i]*gdx + py[i]*gdy + gdo; - uu[i] = px[i]*gux + py[i]*guy + guo; - vv[i] = px[i]*gvx + py[i]*gvy + gvo; - } + for(i=0;i<3;i++) + { + dd[i] = px[i]*gdx + py[i]*gdy + gdo; + uu[i] = px[i]*gux + py[i]*guy + guo; + vv[i] = px[i]*gvx + py[i]*gvy + gvo; + } - py[0] = fy0; - py[1] = fy1; - py[2] = (getflorzofslope(sectnum,(long)ox,(long)oy)-globalposz)*oy2 + ghoriz; + py[0] = fy0; + py[1] = fy1; + py[2] = (getflorzofslope(sectnum,(long)ox,(long)oy)-globalposz)*oy2 + ghoriz; - ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; - r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); - gdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - gux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - gvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; - gdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - guy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - gvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - gdo = dd[0] - px[0]*gdx - py[0]*gdy; - guo = uu[0] - px[0]*gux - py[0]*guy; - gvo = vv[0] - px[0]*gvx - py[0]*gvy; + ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; + r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); + gdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + gux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + gvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; + gdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + guy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + gvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + gdo = dd[0] - px[0]*gdx - py[0]*gdy; + guo = uu[0] - px[0]*gux - py[0]*guy; + gvo = vv[0] - px[0]*gvx - py[0]*gvy; - if (globalorientation&64) //Hack for relative alignment on slopes - { - r = (float)sec->floorheinum / 4096.0; - r = sqrt(r*r+1); - if (!(globalorientation&4)) { gvx *= r; gvy *= r; gvo *= r; } - else { gux *= r; guy *= r; guo *= r; } - } - } - domostpolymethod = (globalorientation>>7)&3; - if (globalposz >= getflorzofslope(sectnum,globalposx,globalposy)) domostpolymethod = -1; //Back-face culling - pow2xsplit = 0; domost(x0,fy0,x1,fy1); //flor - domostpolymethod = 0; - } - else if ((nextsectnum < 0) || (!(sector[nextsectnum].floorstat&1))) - { - //Parallaxing sky... hacked for Ken's mountain texture; paper-sky only :/ + if (globalorientation&64) //Hack for relative alignment on slopes + { + r = (float)sec->floorheinum / 4096.0; + r = sqrt(r*r+1); + if (!(globalorientation&4)) { gvx *= r; gvy *= r; gvo *= r; } + else { gux *= r; guy *= r; guo *= r; } + } + } + domostpolymethod = (globalorientation>>7)&3; + if (globalposz >= getflorzofslope(sectnum,globalposx,globalposy)) domostpolymethod = -1; //Back-face culling + pow2xsplit = 0; domost(x0,fy0,x1,fy1); //flor + domostpolymethod = 0; + } + else if ((nextsectnum < 0) || (!(sector[nextsectnum].floorstat&1))) + { + //Parallaxing sky... hacked for Ken's mountain texture; paper-sky only :/ #ifdef USE_OPENGL - if (rendmode == 3) - { - if (!nofog) { - bglDisable(GL_FOG); - //r = ((float)globalpisibility)*((float)((unsigned char)(sec->visibility+16)))*FOGSCALE; - //r *= ((double)xdimscale*(double)viewingrange*gdo) / (65536.0*65536.0); - //bglFogf(GL_FOG_DENSITY,r); - } + if (rendmode == 3) + { + if (!nofog) { + bglDisable(GL_FOG); + //r = ((float)globalpisibility)*((float)((unsigned char)(sec->visibility+16)))*FOGSCALE; + //r *= ((double)xdimscale*(double)viewingrange*gdo) / (65536.0*65536.0); + //bglFogf(GL_FOG_DENSITY,r); + } - //Use clamping for tiled sky textures - for(i=(1<0;i--) - if (pskyoff[i] != pskyoff[i-1]) - { skyclamphack = 1; break; } - } + //Use clamping for tiled sky textures + for(i=(1<0;i--) + if (pskyoff[i] != pskyoff[i-1]) + { skyclamphack = 1; break; } + } #endif - if (bpp == 8 || !usehightile || !hicfindsubst(globalpicnum,globalpal,1)) - { - dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! - t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; - i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; - vv[0] += dd[0]*((double)sec->floorypanning)*((double)i)/256.0; + if (bpp == 8 || !usehightile || !hicfindsubst(globalpicnum,globalpal,1)) + { + dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! + t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; + i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; + vv[0] += dd[0]*((double)sec->floorypanning)*((double)i)/256.0; - //Hack to draw black rectangle below sky when looking down... - gdx = 0; gdy = gxyaspect / 262144.0; gdo = -ghoriz*gdy; - gux = 0; guy = 0; guo = 0; - gvx = 0; gvy = (double)(tilesizy[globalpicnum]-1)*gdy; gvo = (double)(tilesizy[globalpicnum-1])*gdo; - oy = (((double)tilesizy[globalpicnum])*dd[0]-vv[0])/vv[1]; - if ((oy > fy0) && (oy > fy1)) domost(x0,oy,x1,oy); - else if ((oy > fy0) != (oy > fy1)) - { // fy0 fy1 - // \ / - //oy---------- oy---------- - // \ / - // fy1 fy0 - ox = (oy-fy0)*(x1-x0)/(fy1-fy0) + x0; - if (oy > fy0) { domost(x0,oy,ox,oy); domost(ox,oy,x1,fy1); } - else { domost(x0,fy0,ox,oy); domost(ox,oy,x1,oy); } - } else domost(x0,fy0,x1,fy1); + //Hack to draw black rectangle below sky when looking down... + gdx = 0; gdy = gxyaspect / 262144.0; gdo = -ghoriz*gdy; + gux = 0; guy = 0; guo = 0; + gvx = 0; gvy = (double)(tilesizy[globalpicnum]-1)*gdy; gvo = (double)(tilesizy[globalpicnum-1])*gdo; + oy = (((double)tilesizy[globalpicnum])*dd[0]-vv[0])/vv[1]; + if ((oy > fy0) && (oy > fy1)) domost(x0,oy,x1,oy); + else if ((oy > fy0) != (oy > fy1)) + { // fy0 fy1 + // \ / + //oy---------- oy---------- + // \ / + // fy1 fy0 + ox = (oy-fy0)*(x1-x0)/(fy1-fy0) + x0; + if (oy > fy0) { domost(x0,oy,ox,oy); domost(ox,oy,x1,fy1); } + else { domost(x0,fy0,ox,oy); domost(ox,oy,x1,oy); } + } else domost(x0,fy0,x1,fy1); - gdx = 0; gdy = 0; gdo = dd[0]; - gux = gdo*(t*((double)xdimscale)*((double)yxaspect)*((double)viewingrange))/(16384.0*65536.0*65536.0*5.0*1024.0); - guy = 0; //guo calculated later - gvx = 0; gvy = vv[1]; gvo = vv[0]; + gdx = 0; gdy = 0; gdo = dd[0]; + gux = gdo*(t*((double)xdimscale)*((double)yxaspect)*((double)viewingrange))/(16384.0*65536.0*65536.0*5.0*1024.0); + guy = 0; //guo calculated later + gvx = 0; gvy = vv[1]; gvo = vv[0]; - i = globalpicnum; r = (fy1-fy0)/(x1-x0); //slope of line - oy = ((double)viewingrange)/(ghalfx*256.0); oz = 1/oy; + i = globalpicnum; r = (fy1-fy0)/(x1-x0); //slope of line + oy = ((double)viewingrange)/(ghalfx*256.0); oz = 1/oy; - y = ((((long)((x0-ghalfx)*oy))+globalang)>>(11-pskybits)); - fx = x0; - do - { - globalpicnum = pskyoff[y&((1<floorxpanning) - gux*ghalfx; - y++; - ox = fx; fx = ((double)((y<<(11-pskybits))-globalang))*oz+ghalfx; - if (fx > x1) { fx = x1; i = -1; } + y = ((((long)((x0-ghalfx)*oy))+globalang)>>(11-pskybits)); + fx = x0; + do + { + globalpicnum = pskyoff[y&((1<floorxpanning) - gux*ghalfx; + y++; + ox = fx; fx = ((double)((y<<(11-pskybits))-globalang))*oz+ghalfx; + if (fx > x1) { fx = x1; i = -1; } - pow2xsplit = 0; domost(ox,(ox-x0)*r+fy0,fx,(fx-x0)*r+fy0); //flor - } while (i >= 0); + pow2xsplit = 0; domost(ox,(ox-x0)*r+fy0,fx,(fx-x0)*r+fy0); //flor + } while (i >= 0); - } - else //NOTE: code copied from ceiling code... lots of duplicated stuff :/ - { //Skybox code for parallax ceiling! - double _xp0, _yp0, _xp1, _yp1, _oxp0, _oyp0, _t0, _t1, _nx0, _ny0, _nx1, _ny1; - double _ryp0, _ryp1, _x0, _x1, _cy0, _fy0, _cy1, _fy1, _ox0, _ox1; - double nfy0, nfy1; - long skywalx[4] = {-512,512,512,-512}, skywaly[4] = {-512,-512,512,512}; + } + else //NOTE: code copied from ceiling code... lots of duplicated stuff :/ + { //Skybox code for parallax ceiling! + double _xp0, _yp0, _xp1, _yp1, _oxp0, _oyp0, _t0, _t1, _nx0, _ny0, _nx1, _ny1; + double _ryp0, _ryp1, _x0, _x1, _cy0, _fy0, _cy1, _fy1, _ox0, _ox1; + double nfy0, nfy1; + long skywalx[4] = {-512,512,512,-512}, skywaly[4] = {-512,-512,512,512}; - pow2xsplit = 0; - skyclamphack = 1; + pow2xsplit = 0; + skyclamphack = 1; - for(i=0;i<4;i++) - { - x = skywalx[i&3]; y = skywaly[i&3]; - _xp0 = (double)y*gcosang - (double)x*gsinang; - _yp0 = (double)x*gcosang2 + (double)y*gsinang2; - x = skywalx[(i+1)&3]; y = skywaly[(i+1)&3]; - _xp1 = (double)y*gcosang - (double)x*gsinang; - _yp1 = (double)x*gcosang2 + (double)y*gsinang2; + for(i=0;i<4;i++) + { + x = skywalx[i&3]; y = skywaly[i&3]; + _xp0 = (double)y*gcosang - (double)x*gsinang; + _yp0 = (double)x*gcosang2 + (double)y*gsinang2; + x = skywalx[(i+1)&3]; y = skywaly[(i+1)&3]; + _xp1 = (double)y*gcosang - (double)x*gsinang; + _yp1 = (double)x*gcosang2 + (double)y*gsinang2; - _oxp0 = _xp0; _oyp0 = _yp0; + _oxp0 = _xp0; _oyp0 = _yp0; - //Clip to close parallel-screen plane - if (_yp0 < SCISDIST) - { - if (_yp1 < SCISDIST) continue; - _t0 = (SCISDIST-_yp0)/(_yp1-_yp0); _xp0 = (_xp1-_xp0)*_t0+_xp0; _yp0 = SCISDIST; - _nx0 = (skywalx[(i+1)&3]-skywalx[i&3])*_t0+skywalx[i&3]; - _ny0 = (skywaly[(i+1)&3]-skywaly[i&3])*_t0+skywaly[i&3]; - } - else { _t0 = 0.f; _nx0 = skywalx[i&3]; _ny0 = skywaly[i&3]; } - if (_yp1 < SCISDIST) - { - _t1 = (SCISDIST-_oyp0)/(_yp1-_oyp0); _xp1 = (_xp1-_oxp0)*_t1+_oxp0; _yp1 = SCISDIST; - _nx1 = (skywalx[(i+1)&3]-skywalx[i&3])*_t1+skywalx[i&3]; - _ny1 = (skywaly[(i+1)&3]-skywaly[i&3])*_t1+skywaly[i&3]; - } - else { _t1 = 1.f; _nx1 = skywalx[(i+1)&3]; _ny1 = skywaly[(i+1)&3]; } + //Clip to close parallel-screen plane + if (_yp0 < SCISDIST) + { + if (_yp1 < SCISDIST) continue; + _t0 = (SCISDIST-_yp0)/(_yp1-_yp0); _xp0 = (_xp1-_xp0)*_t0+_xp0; _yp0 = SCISDIST; + _nx0 = (skywalx[(i+1)&3]-skywalx[i&3])*_t0+skywalx[i&3]; + _ny0 = (skywaly[(i+1)&3]-skywaly[i&3])*_t0+skywaly[i&3]; + } + else { _t0 = 0.f; _nx0 = skywalx[i&3]; _ny0 = skywaly[i&3]; } + if (_yp1 < SCISDIST) + { + _t1 = (SCISDIST-_oyp0)/(_yp1-_oyp0); _xp1 = (_xp1-_oxp0)*_t1+_oxp0; _yp1 = SCISDIST; + _nx1 = (skywalx[(i+1)&3]-skywalx[i&3])*_t1+skywalx[i&3]; + _ny1 = (skywaly[(i+1)&3]-skywaly[i&3])*_t1+skywaly[i&3]; + } + else { _t1 = 1.f; _nx1 = skywalx[(i+1)&3]; _ny1 = skywaly[(i+1)&3]; } - _ryp0 = 1.f/_yp0; _ryp1 = 1.f/_yp1; + _ryp0 = 1.f/_yp0; _ryp1 = 1.f/_yp1; - //Generate screen coordinates for front side of wall - _x0 = ghalfx*_xp0*_ryp0 + ghalfx; - _x1 = ghalfx*_xp1*_ryp1 + ghalfx; - if (_x1 <= _x0) continue; - if ((_x0 >= x1) || (x0 >= _x1)) continue; + //Generate screen coordinates for front side of wall + _x0 = ghalfx*_xp0*_ryp0 + ghalfx; + _x1 = ghalfx*_xp1*_ryp1 + ghalfx; + if (_x1 <= _x0) continue; + if ((_x0 >= x1) || (x0 >= _x1)) continue; - _ryp0 *= gyxscale; _ryp1 *= gyxscale; + _ryp0 *= gyxscale; _ryp1 *= gyxscale; - _cy0 = -8192.f*_ryp0 + ghoriz; - _fy0 = 8192.f*_ryp0 + ghoriz; - _cy1 = -8192.f*_ryp1 + ghoriz; - _fy1 = 8192.f*_ryp1 + ghoriz; + _cy0 = -8192.f*_ryp0 + ghoriz; + _fy0 = 8192.f*_ryp0 + ghoriz; + _cy1 = -8192.f*_ryp1 + ghoriz; + _fy1 = 8192.f*_ryp1 + ghoriz; - _ox0 = _x0; _ox1 = _x1; + _ox0 = _x0; _ox1 = _x1; - //Make sure: x0<=_x0<_x1<=_x1 - nfy0 = fy0; nfy1 = fy1; - if (_x0 < x0) - { - t = (x0-_x0)/(_x1-_x0); - _cy0 += (_cy1-_cy0)*t; - _fy0 += (_fy1-_fy0)*t; - _x0 = x0; - } - else if (_x0 > x0) nfy0 += (_x0-x0)*(fy1-fy0)/(x1-x0); - if (_x1 > x1) - { - t = (x1-_x1)/(_x1-_x0); - _cy1 += (_cy1-_cy0)*t; - _fy1 += (_fy1-_fy0)*t; - _x1 = x1; - } - else if (_x1 < x1) nfy1 += (_x1-x1)*(fy1-fy0)/(x1-x0); + //Make sure: x0<=_x0<_x1<=_x1 + nfy0 = fy0; nfy1 = fy1; + if (_x0 < x0) + { + t = (x0-_x0)/(_x1-_x0); + _cy0 += (_cy1-_cy0)*t; + _fy0 += (_fy1-_fy0)*t; + _x0 = x0; + } + else if (_x0 > x0) nfy0 += (_x0-x0)*(fy1-fy0)/(x1-x0); + if (_x1 > x1) + { + t = (x1-_x1)/(_x1-_x0); + _cy1 += (_cy1-_cy0)*t; + _fy1 += (_fy1-_fy0)*t; + _x1 = x1; + } + else if (_x1 < x1) nfy1 += (_x1-x1)*(fy1-fy0)/(x1-x0); - // (skybox floor) - //(_x0,_fy0)-(_x1,_fy1) - // (skybox wall) - //(_x0,_cy0)-(_x1,_cy1) - // (skybox ceiling) - //(_x0,nfy0)-(_x1,nfy1) + // (skybox floor) + //(_x0,_fy0)-(_x1,_fy1) + // (skybox wall) + //(_x0,_cy0)-(_x1,_cy1) + // (skybox ceiling) + //(_x0,nfy0)-(_x1,nfy1) - //ceiling of skybox - ft[0] = 512/16; ft[1] = 512/-16; - ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); - ft[3] = ((float)singlobalang)*(1.f/2147483648.f); - gdx = 0; - gdy = gxyaspect*(1.f/4194304.f); - gdo = -ghoriz*gdy; - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; - gvx = -gvx; gvy = -gvy; gvo = -gvo; //y-flip skybox floor + //ceiling of skybox + ft[0] = 512/16; ft[1] = 512/-16; + ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); + ft[3] = ((float)singlobalang)*(1.f/2147483648.f); + gdx = 0; + gdy = gxyaspect*(1.f/4194304.f); + gdo = -ghoriz*gdy; + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; + gvx = -gvx; gvy = -gvy; gvo = -gvo; //y-flip skybox floor #ifdef USE_OPENGL - drawingskybox = 6; //ceiling/5th texture/index 4 of skybox + drawingskybox = 6; //ceiling/5th texture/index 4 of skybox #endif - if ((_fy0 > nfy0) && (_fy1 > nfy1)) domost(_x0,_fy0,_x1,_fy1); - else if ((_fy0 > nfy0) != (_fy1 > nfy1)) - { - //(ox,oy) is intersection of: (_x0,_cy0)-(_x1,_cy1) - // (_x0,nfy0)-(_x1,nfy1) - //ox = _x0 + (_x1-_x0)*t - //oy = _cy0 + (_cy1-_cy0)*t - //oy = nfy0 + (nfy1-nfy0)*t - t = (_fy0-nfy0)/(nfy1-nfy0-_fy1+_fy0); - ox = _x0 + (_x1-_x0)*t; - oy = _fy0 + (_fy1-_fy0)*t; - if (nfy0 > _fy0) { domost(_x0,nfy0,ox,oy); domost(ox,oy,_x1,_fy1); } - else { domost(_x0,_fy0,ox,oy); domost(ox,oy,_x1,nfy1); } - } else domost(_x0,nfy0,_x1,nfy1); + if ((_fy0 > nfy0) && (_fy1 > nfy1)) domost(_x0,_fy0,_x1,_fy1); + else if ((_fy0 > nfy0) != (_fy1 > nfy1)) + { + //(ox,oy) is intersection of: (_x0,_cy0)-(_x1,_cy1) + // (_x0,nfy0)-(_x1,nfy1) + //ox = _x0 + (_x1-_x0)*t + //oy = _cy0 + (_cy1-_cy0)*t + //oy = nfy0 + (nfy1-nfy0)*t + t = (_fy0-nfy0)/(nfy1-nfy0-_fy1+_fy0); + ox = _x0 + (_x1-_x0)*t; + oy = _fy0 + (_fy1-_fy0)*t; + if (nfy0 > _fy0) { domost(_x0,nfy0,ox,oy); domost(ox,oy,_x1,_fy1); } + else { domost(_x0,_fy0,ox,oy); domost(ox,oy,_x1,nfy1); } + } else domost(_x0,nfy0,_x1,nfy1); - //wall of skybox + //wall of skybox #ifdef USE_OPENGL - drawingskybox = i+1; //i+1th texture/index i of skybox + drawingskybox = i+1; //i+1th texture/index i of skybox #endif - gdx = (_ryp0-_ryp1)*gxyaspect*(1.f/512.f) / (_ox0-_ox1); - gdy = 0; - gdo = _ryp0*gxyaspect*(1.f/512.f) - gdx*_ox0; - gux = (_t0*_ryp0 - _t1*_ryp1)*gxyaspect*(64.f/512.f) / (_ox0-_ox1); - guo = _t0*_ryp0*gxyaspect*(64.f/512.f) - gux*_ox0; - guy = 0; - _t0 = -8192.0*_ryp0 + ghoriz; - _t1 = -8192.0*_ryp1 + ghoriz; - t = ((gdx*_ox0 + gdo)*8.f) / ((_ox1-_ox0) * _ryp0 * 2048.f); - gvx = (_t0-_t1)*t; - gvy = (_ox1-_ox0)*t; - gvo = -gvx*_ox0 - gvy*_t0; - if ((_cy0 > nfy0) && (_cy1 > nfy1)) domost(_x0,_cy0,_x1,_cy1); - else if ((_cy0 > nfy0) != (_cy1 > nfy1)) - { - //(ox,oy) is intersection of: (_x0,_fy0)-(_x1,_fy1) - // (_x0,nfy0)-(_x1,nfy1) - //ox = _x0 + (_x1-_x0)*t - //oy = _fy0 + (_fy1-_fy0)*t - //oy = nfy0 + (nfy1-nfy0)*t - t = (_cy0-nfy0)/(nfy1-nfy0-_cy1+_cy0); - ox = _x0 + (_x1-_x0)*t; - oy = _cy0 + (_cy1-_cy0)*t; - if (nfy0 > _cy0) { domost(_x0,nfy0,ox,oy); domost(ox,oy,_x1,_cy1); } - else { domost(_x0,_cy0,ox,oy); domost(ox,oy,_x1,nfy1); } - } else domost(_x0,nfy0,_x1,nfy1); - } + gdx = (_ryp0-_ryp1)*gxyaspect*(1.f/512.f) / (_ox0-_ox1); + gdy = 0; + gdo = _ryp0*gxyaspect*(1.f/512.f) - gdx*_ox0; + gux = (_t0*_ryp0 - _t1*_ryp1)*gxyaspect*(64.f/512.f) / (_ox0-_ox1); + guo = _t0*_ryp0*gxyaspect*(64.f/512.f) - gux*_ox0; + guy = 0; + _t0 = -8192.0*_ryp0 + ghoriz; + _t1 = -8192.0*_ryp1 + ghoriz; + t = ((gdx*_ox0 + gdo)*8.f) / ((_ox1-_ox0) * _ryp0 * 2048.f); + gvx = (_t0-_t1)*t; + gvy = (_ox1-_ox0)*t; + gvo = -gvx*_ox0 - gvy*_t0; + if ((_cy0 > nfy0) && (_cy1 > nfy1)) domost(_x0,_cy0,_x1,_cy1); + else if ((_cy0 > nfy0) != (_cy1 > nfy1)) + { + //(ox,oy) is intersection of: (_x0,_fy0)-(_x1,_fy1) + // (_x0,nfy0)-(_x1,nfy1) + //ox = _x0 + (_x1-_x0)*t + //oy = _fy0 + (_fy1-_fy0)*t + //oy = nfy0 + (nfy1-nfy0)*t + t = (_cy0-nfy0)/(nfy1-nfy0-_cy1+_cy0); + ox = _x0 + (_x1-_x0)*t; + oy = _cy0 + (_cy1-_cy0)*t; + if (nfy0 > _cy0) { domost(_x0,nfy0,ox,oy); domost(ox,oy,_x1,_cy1); } + else { domost(_x0,_cy0,ox,oy); domost(ox,oy,_x1,nfy1); } + } else domost(_x0,nfy0,_x1,nfy1); + } - //Floor of skybox + //Floor of skybox #ifdef USE_OPENGL - drawingskybox = 5; //floor/6th texture/index 5 of skybox + drawingskybox = 5; //floor/6th texture/index 5 of skybox #endif - ft[0] = 512/16; ft[1] = -512/-16; - ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); - ft[3] = ((float)singlobalang)*(1.f/2147483648.f); - gdx = 0; - gdy = gxyaspect*(-1.f/4194304.f); - gdo = -ghoriz*gdy; - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; - domost(x0,fy0,x1,fy1); + ft[0] = 512/16; ft[1] = -512/-16; + ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); + ft[3] = ((float)singlobalang)*(1.f/2147483648.f); + gdx = 0; + gdy = gxyaspect*(-1.f/4194304.f); + gdo = -ghoriz*gdy; + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; + domost(x0,fy0,x1,fy1); - skyclamphack = 0; + skyclamphack = 0; #ifdef USE_OPENGL - drawingskybox = 0; + drawingskybox = 0; #endif - } + } #ifdef USE_OPENGL - if (rendmode == 3) - { - skyclamphack = 0; - if (!nofog) { - bglEnable(GL_FOG); - //bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); - } - } + if (rendmode == 3) + { + skyclamphack = 0; + if (!nofog) { + bglEnable(GL_FOG); + //bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); + } + } #endif - } + } - globalpicnum = sec->ceilingpicnum; globalshade = sec->ceilingshade; globalpal = (long)((unsigned char)sec->ceilingpal); - globalorientation = sec->ceilingstat; - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,sectnum); - if (!(globalorientation&1)) - { - if (!(globalorientation&64)) - { ft[0] = globalposx; ft[1] = globalposy; ft[2] = cosglobalang; ft[3] = singlobalang; } - else - { - //relative alignment - fx = (double)(wall[wall[sec->wallptr].point2].x-wall[sec->wallptr].x); - fy = (double)(wall[wall[sec->wallptr].point2].y-wall[sec->wallptr].y); - r = 1.0/sqrt(fx*fx+fy*fy); fx *= r; fy *= r; - ft[2] = cosglobalang*fx + singlobalang*fy; - ft[3] = singlobalang*fx - cosglobalang*fy; - ft[0] = ((double)(globalposx-wall[sec->wallptr].x))*fx + ((double)(globalposy-wall[sec->wallptr].y))*fy; - ft[1] = ((double)(globalposy-wall[sec->wallptr].y))*fx - ((double)(globalposx-wall[sec->wallptr].x))*fy; - if (!(globalorientation&4)) globalorientation ^= 32; else globalorientation ^= 16; - } - gdx = 0; - gdy = gxyaspect; - if (!(globalorientation&2)) gdy /= (double)(sec->ceilingz-globalposz); - gdo = -ghoriz*gdy; - if (globalorientation&8) { ft[0] /= 8; ft[1] /= -8; ft[2] /= 2097152; ft[3] /= 2097152; } - else { ft[0] /= 16; ft[1] /= -16; ft[2] /= 4194304; ft[3] /= 4194304; } - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; + globalpicnum = sec->ceilingpicnum; globalshade = sec->ceilingshade; globalpal = (long)((unsigned char)sec->ceilingpal); + globalorientation = sec->ceilingstat; + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,sectnum); + if (!(globalorientation&1)) + { + if (!(globalorientation&64)) + { ft[0] = globalposx; ft[1] = globalposy; ft[2] = cosglobalang; ft[3] = singlobalang; } + else + { + //relative alignment + fx = (double)(wall[wall[sec->wallptr].point2].x-wall[sec->wallptr].x); + fy = (double)(wall[wall[sec->wallptr].point2].y-wall[sec->wallptr].y); + r = 1.0/sqrt(fx*fx+fy*fy); fx *= r; fy *= r; + ft[2] = cosglobalang*fx + singlobalang*fy; + ft[3] = singlobalang*fx - cosglobalang*fy; + ft[0] = ((double)(globalposx-wall[sec->wallptr].x))*fx + ((double)(globalposy-wall[sec->wallptr].y))*fy; + ft[1] = ((double)(globalposy-wall[sec->wallptr].y))*fx - ((double)(globalposx-wall[sec->wallptr].x))*fy; + if (!(globalorientation&4)) globalorientation ^= 32; else globalorientation ^= 16; + } + gdx = 0; + gdy = gxyaspect; + if (!(globalorientation&2)) gdy /= (double)(sec->ceilingz-globalposz); + gdo = -ghoriz*gdy; + if (globalorientation&8) { ft[0] /= 8; ft[1] /= -8; ft[2] /= 2097152; ft[3] /= 2097152; } + else { ft[0] /= 16; ft[1] /= -16; ft[2] /= 4194304; ft[3] /= 4194304; } + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; - //Texture flipping - if (globalorientation&4) - { - r = gux; gux = gvx; gvx = r; - r = guy; guy = gvy; gvy = r; - r = guo; guo = gvo; gvo = r; - } - if (globalorientation&16) { gux = -gux; guy = -guy; guo = -guo; } - if (globalorientation&32) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } + //Texture flipping + if (globalorientation&4) + { + r = gux; gux = gvx; gvx = r; + r = guy; guy = gvy; gvy = r; + r = guo; guo = gvo; gvo = r; + } + if (globalorientation&16) { gux = -gux; guy = -guy; guo = -guo; } + if (globalorientation&32) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } - //Texture panning - fx = (float)sec->ceilingxpanning*((float)(1<<(picsiz[globalpicnum]&15)))/256.0; - fy = (float)sec->ceilingypanning*((float)(1<<(picsiz[globalpicnum]>>4)))/256.0; - if ((globalorientation&(2+64)) == (2+64)) //Hack for panning for slopes w/ relative alignment - { - r = (float)sec->ceilingheinum / 4096.0; r = 1.0/sqrt(r*r+1); - if (!(globalorientation&4)) fy *= r; else fx *= r; - } - guy += gdy*fx; guo += gdo*fx; - gvy += gdy*fy; gvo += gdo*fy; + //Texture panning + fx = (float)sec->ceilingxpanning*((float)(1<<(picsiz[globalpicnum]&15)))/256.0; + fy = (float)sec->ceilingypanning*((float)(1<<(picsiz[globalpicnum]>>4)))/256.0; + if ((globalorientation&(2+64)) == (2+64)) //Hack for panning for slopes w/ relative alignment + { + r = (float)sec->ceilingheinum / 4096.0; r = 1.0/sqrt(r*r+1); + if (!(globalorientation&4)) fy *= r; else fx *= r; + } + guy += gdy*fx; guo += gdo*fx; + gvy += gdy*fy; gvo += gdo*fy; - if (globalorientation&2) //slopes - { - px[0] = x0; py[0] = ryp0 + ghoriz; - px[1] = x1; py[1] = ryp1 + ghoriz; + if (globalorientation&2) //slopes + { + px[0] = x0; py[0] = ryp0 + ghoriz; + px[1] = x1; py[1] = ryp1 + ghoriz; - //Pick some point guaranteed to be not collinear to the 1st two points - ox = nx0 + (ny1-ny0); - oy = ny0 + (nx0-nx1); - ox2 = (double)(oy-globalposy)*gcosang - (double)(ox-globalposx)*gsinang ; - oy2 = (double)(ox-globalposx)*gcosang2 + (double)(oy-globalposy)*gsinang2; - oy2 = 1.0/oy2; - px[2] = ghalfx*ox2*oy2 + ghalfx; oy2 *= gyxscale; - py[2] = oy2 + ghoriz; + //Pick some point guaranteed to be not collinear to the 1st two points + ox = nx0 + (ny1-ny0); + oy = ny0 + (nx0-nx1); + ox2 = (double)(oy-globalposy)*gcosang - (double)(ox-globalposx)*gsinang ; + oy2 = (double)(ox-globalposx)*gcosang2 + (double)(oy-globalposy)*gsinang2; + oy2 = 1.0/oy2; + px[2] = ghalfx*ox2*oy2 + ghalfx; oy2 *= gyxscale; + py[2] = oy2 + ghoriz; - for(i=0;i<3;i++) - { - dd[i] = px[i]*gdx + py[i]*gdy + gdo; - uu[i] = px[i]*gux + py[i]*guy + guo; - vv[i] = px[i]*gvx + py[i]*gvy + gvo; - } + for(i=0;i<3;i++) + { + dd[i] = px[i]*gdx + py[i]*gdy + gdo; + uu[i] = px[i]*gux + py[i]*guy + guo; + vv[i] = px[i]*gvx + py[i]*gvy + gvo; + } - py[0] = cy0; - py[1] = cy1; - py[2] = (getceilzofslope(sectnum,(long)ox,(long)oy)-globalposz)*oy2 + ghoriz; + py[0] = cy0; + py[1] = cy1; + py[2] = (getceilzofslope(sectnum,(long)ox,(long)oy)-globalposz)*oy2 + ghoriz; - ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; - r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); - gdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - gux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - gvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; - gdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; - guy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; - gvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; - gdo = dd[0] - px[0]*gdx - py[0]*gdy; - guo = uu[0] - px[0]*gux - py[0]*guy; - gvo = vv[0] - px[0]*gvx - py[0]*gvy; + ox = py[1]-py[2]; oy = py[2]-py[0]; oz = py[0]-py[1]; + r = 1.0 / (ox*px[0] + oy*px[1] + oz*px[2]); + gdx = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + gux = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + gvx = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + ox = px[2]-px[1]; oy = px[0]-px[2]; oz = px[1]-px[0]; + gdy = (ox*dd[0] + oy*dd[1] + oz*dd[2])*r; + guy = (ox*uu[0] + oy*uu[1] + oz*uu[2])*r; + gvy = (ox*vv[0] + oy*vv[1] + oz*vv[2])*r; + gdo = dd[0] - px[0]*gdx - py[0]*gdy; + guo = uu[0] - px[0]*gux - py[0]*guy; + gvo = vv[0] - px[0]*gvx - py[0]*gvy; - if (globalorientation&64) //Hack for relative alignment on slopes - { - r = (float)sec->ceilingheinum / 4096.0; - r = sqrt(r*r+1); - if (!(globalorientation&4)) { gvx *= r; gvy *= r; gvo *= r; } - else { gux *= r; guy *= r; guo *= r; } - } - } - domostpolymethod = (globalorientation>>7)&3; - if (globalposz <= getceilzofslope(sectnum,globalposx,globalposy)) domostpolymethod = -1; //Back-face culling - pow2xsplit = 0; domost(x1,cy1,x0,cy0); //ceil - domostpolymethod = 0; - } - else if ((nextsectnum < 0) || (!(sector[nextsectnum].ceilingstat&1))) - { + if (globalorientation&64) //Hack for relative alignment on slopes + { + r = (float)sec->ceilingheinum / 4096.0; + r = sqrt(r*r+1); + if (!(globalorientation&4)) { gvx *= r; gvy *= r; gvo *= r; } + else { gux *= r; guy *= r; guo *= r; } + } + } + domostpolymethod = (globalorientation>>7)&3; + if (globalposz <= getceilzofslope(sectnum,globalposx,globalposy)) domostpolymethod = -1; //Back-face culling + pow2xsplit = 0; domost(x1,cy1,x0,cy0); //ceil + domostpolymethod = 0; + } + else if ((nextsectnum < 0) || (!(sector[nextsectnum].ceilingstat&1))) + { #ifdef USE_OPENGL - if (rendmode == 3) - { - if (!nofog) { - bglDisable(GL_FOG); - //r = ((float)globalpisibility)*((float)((unsigned char)(sec->visibility+16)))*FOGSCALE; - //r *= ((double)xdimscale*(double)viewingrange*gdo) / (65536.0*65536.0); - //bglFogf(GL_FOG_DENSITY,r); - } + if (rendmode == 3) + { + if (!nofog) { + bglDisable(GL_FOG); + //r = ((float)globalpisibility)*((float)((unsigned char)(sec->visibility+16)))*FOGSCALE; + //r *= ((double)xdimscale*(double)viewingrange*gdo) / (65536.0*65536.0); + //bglFogf(GL_FOG_DENSITY,r); + } - //Use clamping for tiled sky textures - for(i=(1<0;i--) - if (pskyoff[i] != pskyoff[i-1]) - { skyclamphack = 1; break; } - } + //Use clamping for tiled sky textures + for(i=(1<0;i--) + if (pskyoff[i] != pskyoff[i-1]) + { skyclamphack = 1; break; } + } #endif - //Parallaxing sky... - if (bpp == 8 || !usehightile || !hicfindsubst(globalpicnum,globalpal,1)) - { - //Render for parallaxtype == 0 / paper-sky - dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! - t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; - i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; - vv[0] += dd[0]*((double)sec->ceilingypanning)*((double)i)/256.0; + //Parallaxing sky... + if (bpp == 8 || !usehightile || !hicfindsubst(globalpicnum,globalpal,1)) + { + //Render for parallaxtype == 0 / paper-sky + dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! + t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; + i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; + vv[0] += dd[0]*((double)sec->ceilingypanning)*((double)i)/256.0; - //Hack to draw black rectangle below sky when looking down... - gdx = 0; gdy = gxyaspect / -262144.0; gdo = -ghoriz*gdy; - gux = 0; guy = 0; guo = 0; - gvx = 0; gvy = 0; gvo = 0; - oy = -vv[0]/vv[1]; - if ((oy < cy0) && (oy < cy1)) domost(x1,oy,x0,oy); - else if ((oy < cy0) != (oy < cy1)) - { /* cy1 cy0 - // / \ - //oy---------- oy--------- - // / \ - // cy0 cy1 - */ - ox = (oy-cy0)*(x1-x0)/(cy1-cy0) + x0; - if (oy < cy0) { domost(ox,oy,x0,oy); domost(x1,cy1,ox,oy); } - else { domost(ox,oy,x0,cy0); domost(x1,oy,ox,oy); } - } else domost(x1,cy1,x0,cy0); + //Hack to draw black rectangle below sky when looking down... + gdx = 0; gdy = gxyaspect / -262144.0; gdo = -ghoriz*gdy; + gux = 0; guy = 0; guo = 0; + gvx = 0; gvy = 0; gvo = 0; + oy = -vv[0]/vv[1]; + if ((oy < cy0) && (oy < cy1)) domost(x1,oy,x0,oy); + else if ((oy < cy0) != (oy < cy1)) + { /* cy1 cy0 + // / \ + //oy---------- oy--------- + // / \ + // cy0 cy1 + */ + ox = (oy-cy0)*(x1-x0)/(cy1-cy0) + x0; + if (oy < cy0) { domost(ox,oy,x0,oy); domost(x1,cy1,ox,oy); } + else { domost(ox,oy,x0,cy0); domost(x1,oy,ox,oy); } + } else domost(x1,cy1,x0,cy0); - gdx = 0; gdy = 0; gdo = dd[0]; - gux = gdo*(t*((double)xdimscale)*((double)yxaspect)*((double)viewingrange))/(16384.0*65536.0*65536.0*5.0*1024.0); - guy = 0; //guo calculated later - gvx = 0; gvy = vv[1]; gvo = vv[0]; + gdx = 0; gdy = 0; gdo = dd[0]; + gux = gdo*(t*((double)xdimscale)*((double)yxaspect)*((double)viewingrange))/(16384.0*65536.0*65536.0*5.0*1024.0); + guy = 0; //guo calculated later + gvx = 0; gvy = vv[1]; gvo = vv[0]; - i = globalpicnum; r = (cy1-cy0)/(x1-x0); //slope of line - oy = ((double)viewingrange)/(ghalfx*256.0); oz = 1/oy; + i = globalpicnum; r = (cy1-cy0)/(x1-x0); //slope of line + oy = ((double)viewingrange)/(ghalfx*256.0); oz = 1/oy; - y = ((((long)((x0-ghalfx)*oy))+globalang)>>(11-pskybits)); - fx = x0; - do - { - globalpicnum = pskyoff[y&((1<ceilingxpanning) - gux*ghalfx; - y++; - ox = fx; fx = ((double)((y<<(11-pskybits))-globalang))*oz+ghalfx; - if (fx > x1) { fx = x1; i = -1; } - pow2xsplit = 0; domost(fx,(fx-x0)*r+cy0,ox,(ox-x0)*r+cy0); //ceil - } while (i >= 0); - } - else - { //Skybox code for parallax ceiling! - double _xp0, _yp0, _xp1, _yp1, _oxp0, _oyp0, _t0, _t1, _nx0, _ny0, _nx1, _ny1; - double _ryp0, _ryp1, _x0, _x1, _cy0, _fy0, _cy1, _fy1, _ox0, _ox1; - double ncy0, ncy1; - long skywalx[4] = {-512,512,512,-512}, skywaly[4] = {-512,-512,512,512}; + y = ((((long)((x0-ghalfx)*oy))+globalang)>>(11-pskybits)); + fx = x0; + do + { + globalpicnum = pskyoff[y&((1<ceilingxpanning) - gux*ghalfx; + y++; + ox = fx; fx = ((double)((y<<(11-pskybits))-globalang))*oz+ghalfx; + if (fx > x1) { fx = x1; i = -1; } + pow2xsplit = 0; domost(fx,(fx-x0)*r+cy0,ox,(ox-x0)*r+cy0); //ceil + } while (i >= 0); + } + else + { //Skybox code for parallax ceiling! + double _xp0, _yp0, _xp1, _yp1, _oxp0, _oyp0, _t0, _t1, _nx0, _ny0, _nx1, _ny1; + double _ryp0, _ryp1, _x0, _x1, _cy0, _fy0, _cy1, _fy1, _ox0, _ox1; + double ncy0, ncy1; + long skywalx[4] = {-512,512,512,-512}, skywaly[4] = {-512,-512,512,512}; - pow2xsplit = 0; - skyclamphack = 1; + pow2xsplit = 0; + skyclamphack = 1; - for(i=0;i<4;i++) - { - x = skywalx[i&3]; y = skywaly[i&3]; - _xp0 = (double)y*gcosang - (double)x*gsinang; - _yp0 = (double)x*gcosang2 + (double)y*gsinang2; - x = skywalx[(i+1)&3]; y = skywaly[(i+1)&3]; - _xp1 = (double)y*gcosang - (double)x*gsinang; - _yp1 = (double)x*gcosang2 + (double)y*gsinang2; + for(i=0;i<4;i++) + { + x = skywalx[i&3]; y = skywaly[i&3]; + _xp0 = (double)y*gcosang - (double)x*gsinang; + _yp0 = (double)x*gcosang2 + (double)y*gsinang2; + x = skywalx[(i+1)&3]; y = skywaly[(i+1)&3]; + _xp1 = (double)y*gcosang - (double)x*gsinang; + _yp1 = (double)x*gcosang2 + (double)y*gsinang2; - _oxp0 = _xp0; _oyp0 = _yp0; + _oxp0 = _xp0; _oyp0 = _yp0; - //Clip to close parallel-screen plane - if (_yp0 < SCISDIST) - { - if (_yp1 < SCISDIST) continue; - _t0 = (SCISDIST-_yp0)/(_yp1-_yp0); _xp0 = (_xp1-_xp0)*_t0+_xp0; _yp0 = SCISDIST; - _nx0 = (skywalx[(i+1)&3]-skywalx[i&3])*_t0+skywalx[i&3]; - _ny0 = (skywaly[(i+1)&3]-skywaly[i&3])*_t0+skywaly[i&3]; - } - else { _t0 = 0.f; _nx0 = skywalx[i&3]; _ny0 = skywaly[i&3]; } - if (_yp1 < SCISDIST) - { - _t1 = (SCISDIST-_oyp0)/(_yp1-_oyp0); _xp1 = (_xp1-_oxp0)*_t1+_oxp0; _yp1 = SCISDIST; - _nx1 = (skywalx[(i+1)&3]-skywalx[i&3])*_t1+skywalx[i&3]; - _ny1 = (skywaly[(i+1)&3]-skywaly[i&3])*_t1+skywaly[i&3]; - } - else { _t1 = 1.f; _nx1 = skywalx[(i+1)&3]; _ny1 = skywaly[(i+1)&3]; } + //Clip to close parallel-screen plane + if (_yp0 < SCISDIST) + { + if (_yp1 < SCISDIST) continue; + _t0 = (SCISDIST-_yp0)/(_yp1-_yp0); _xp0 = (_xp1-_xp0)*_t0+_xp0; _yp0 = SCISDIST; + _nx0 = (skywalx[(i+1)&3]-skywalx[i&3])*_t0+skywalx[i&3]; + _ny0 = (skywaly[(i+1)&3]-skywaly[i&3])*_t0+skywaly[i&3]; + } + else { _t0 = 0.f; _nx0 = skywalx[i&3]; _ny0 = skywaly[i&3]; } + if (_yp1 < SCISDIST) + { + _t1 = (SCISDIST-_oyp0)/(_yp1-_oyp0); _xp1 = (_xp1-_oxp0)*_t1+_oxp0; _yp1 = SCISDIST; + _nx1 = (skywalx[(i+1)&3]-skywalx[i&3])*_t1+skywalx[i&3]; + _ny1 = (skywaly[(i+1)&3]-skywaly[i&3])*_t1+skywaly[i&3]; + } + else { _t1 = 1.f; _nx1 = skywalx[(i+1)&3]; _ny1 = skywaly[(i+1)&3]; } - _ryp0 = 1.f/_yp0; _ryp1 = 1.f/_yp1; + _ryp0 = 1.f/_yp0; _ryp1 = 1.f/_yp1; - //Generate screen coordinates for front side of wall - _x0 = ghalfx*_xp0*_ryp0 + ghalfx; - _x1 = ghalfx*_xp1*_ryp1 + ghalfx; - if (_x1 <= _x0) continue; - if ((_x0 >= x1) || (x0 >= _x1)) continue; + //Generate screen coordinates for front side of wall + _x0 = ghalfx*_xp0*_ryp0 + ghalfx; + _x1 = ghalfx*_xp1*_ryp1 + ghalfx; + if (_x1 <= _x0) continue; + if ((_x0 >= x1) || (x0 >= _x1)) continue; - _ryp0 *= gyxscale; _ryp1 *= gyxscale; + _ryp0 *= gyxscale; _ryp1 *= gyxscale; - _cy0 = -8192.f*_ryp0 + ghoriz; - _fy0 = 8192.f*_ryp0 + ghoriz; - _cy1 = -8192.f*_ryp1 + ghoriz; - _fy1 = 8192.f*_ryp1 + ghoriz; + _cy0 = -8192.f*_ryp0 + ghoriz; + _fy0 = 8192.f*_ryp0 + ghoriz; + _cy1 = -8192.f*_ryp1 + ghoriz; + _fy1 = 8192.f*_ryp1 + ghoriz; - _ox0 = _x0; _ox1 = _x1; + _ox0 = _x0; _ox1 = _x1; - //Make sure: x0<=_x0<_x1<=_x1 - ncy0 = cy0; ncy1 = cy1; - if (_x0 < x0) - { - t = (x0-_x0)/(_x1-_x0); - _cy0 += (_cy1-_cy0)*t; - _fy0 += (_fy1-_fy0)*t; - _x0 = x0; - } - else if (_x0 > x0) ncy0 += (_x0-x0)*(cy1-cy0)/(x1-x0); - if (_x1 > x1) - { - t = (x1-_x1)/(_x1-_x0); - _cy1 += (_cy1-_cy0)*t; - _fy1 += (_fy1-_fy0)*t; - _x1 = x1; - } - else if (_x1 < x1) ncy1 += (_x1-x1)*(cy1-cy0)/(x1-x0); + //Make sure: x0<=_x0<_x1<=_x1 + ncy0 = cy0; ncy1 = cy1; + if (_x0 < x0) + { + t = (x0-_x0)/(_x1-_x0); + _cy0 += (_cy1-_cy0)*t; + _fy0 += (_fy1-_fy0)*t; + _x0 = x0; + } + else if (_x0 > x0) ncy0 += (_x0-x0)*(cy1-cy0)/(x1-x0); + if (_x1 > x1) + { + t = (x1-_x1)/(_x1-_x0); + _cy1 += (_cy1-_cy0)*t; + _fy1 += (_fy1-_fy0)*t; + _x1 = x1; + } + else if (_x1 < x1) ncy1 += (_x1-x1)*(cy1-cy0)/(x1-x0); - // (skybox ceiling) - //(_x0,_cy0)-(_x1,_cy1) - // (skybox wall) - //(_x0,_fy0)-(_x1,_fy1) - // (skybox floor) - //(_x0,ncy0)-(_x1,ncy1) + // (skybox ceiling) + //(_x0,_cy0)-(_x1,_cy1) + // (skybox wall) + //(_x0,_fy0)-(_x1,_fy1) + // (skybox floor) + //(_x0,ncy0)-(_x1,ncy1) - //ceiling of skybox + //ceiling of skybox #ifdef USE_OPENGL - drawingskybox = 5; //ceiling/5th texture/index 4 of skybox + drawingskybox = 5; //ceiling/5th texture/index 4 of skybox #endif - ft[0] = 512/16; ft[1] = -512/-16; - ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); - ft[3] = ((float)singlobalang)*(1.f/2147483648.f); - gdx = 0; - gdy = gxyaspect*-(1.f/4194304.f); - gdo = -ghoriz*gdy; - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; - if ((_cy0 < ncy0) && (_cy1 < ncy1)) domost(_x1,_cy1,_x0,_cy0); - else if ((_cy0 < ncy0) != (_cy1 < ncy1)) - { - //(ox,oy) is intersection of: (_x0,_cy0)-(_x1,_cy1) - // (_x0,ncy0)-(_x1,ncy1) - //ox = _x0 + (_x1-_x0)*t - //oy = _cy0 + (_cy1-_cy0)*t - //oy = ncy0 + (ncy1-ncy0)*t - t = (_cy0-ncy0)/(ncy1-ncy0-_cy1+_cy0); - ox = _x0 + (_x1-_x0)*t; - oy = _cy0 + (_cy1-_cy0)*t; - if (ncy0 < _cy0) { domost(ox,oy,_x0,ncy0); domost(_x1,_cy1,ox,oy); } - else { domost(ox,oy,_x0,_cy0); domost(_x1,ncy1,ox,oy); } - } else domost(_x1,ncy1,_x0,ncy0); + ft[0] = 512/16; ft[1] = -512/-16; + ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); + ft[3] = ((float)singlobalang)*(1.f/2147483648.f); + gdx = 0; + gdy = gxyaspect*-(1.f/4194304.f); + gdo = -ghoriz*gdy; + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; + if ((_cy0 < ncy0) && (_cy1 < ncy1)) domost(_x1,_cy1,_x0,_cy0); + else if ((_cy0 < ncy0) != (_cy1 < ncy1)) + { + //(ox,oy) is intersection of: (_x0,_cy0)-(_x1,_cy1) + // (_x0,ncy0)-(_x1,ncy1) + //ox = _x0 + (_x1-_x0)*t + //oy = _cy0 + (_cy1-_cy0)*t + //oy = ncy0 + (ncy1-ncy0)*t + t = (_cy0-ncy0)/(ncy1-ncy0-_cy1+_cy0); + ox = _x0 + (_x1-_x0)*t; + oy = _cy0 + (_cy1-_cy0)*t; + if (ncy0 < _cy0) { domost(ox,oy,_x0,ncy0); domost(_x1,_cy1,ox,oy); } + else { domost(ox,oy,_x0,_cy0); domost(_x1,ncy1,ox,oy); } + } else domost(_x1,ncy1,_x0,ncy0); - //wall of skybox + //wall of skybox #ifdef USE_OPENGL - drawingskybox = i+1; //i+1th texture/index i of skybox + drawingskybox = i+1; //i+1th texture/index i of skybox #endif - gdx = (_ryp0-_ryp1)*gxyaspect*(1.f/512.f) / (_ox0-_ox1); - gdy = 0; - gdo = _ryp0*gxyaspect*(1.f/512.f) - gdx*_ox0; - gux = (_t0*_ryp0 - _t1*_ryp1)*gxyaspect*(64.f/512.f) / (_ox0-_ox1); - guo = _t0*_ryp0*gxyaspect*(64.f/512.f) - gux*_ox0; - guy = 0; - _t0 = -8192.0*_ryp0 + ghoriz; - _t1 = -8192.0*_ryp1 + ghoriz; - t = ((gdx*_ox0 + gdo)*8.f) / ((_ox1-_ox0) * _ryp0 * 2048.f); - gvx = (_t0-_t1)*t; - gvy = (_ox1-_ox0)*t; - gvo = -gvx*_ox0 - gvy*_t0; - if ((_fy0 < ncy0) && (_fy1 < ncy1)) domost(_x1,_fy1,_x0,_fy0); - else if ((_fy0 < ncy0) != (_fy1 < ncy1)) - { - //(ox,oy) is intersection of: (_x0,_fy0)-(_x1,_fy1) - // (_x0,ncy0)-(_x1,ncy1) - //ox = _x0 + (_x1-_x0)*t - //oy = _fy0 + (_fy1-_fy0)*t - //oy = ncy0 + (ncy1-ncy0)*t - t = (_fy0-ncy0)/(ncy1-ncy0-_fy1+_fy0); - ox = _x0 + (_x1-_x0)*t; - oy = _fy0 + (_fy1-_fy0)*t; - if (ncy0 < _fy0) { domost(ox,oy,_x0,ncy0); domost(_x1,_fy1,ox,oy); } - else { domost(ox,oy,_x0,_fy0); domost(_x1,ncy1,ox,oy); } - } else domost(_x1,ncy1,_x0,ncy0); - } + gdx = (_ryp0-_ryp1)*gxyaspect*(1.f/512.f) / (_ox0-_ox1); + gdy = 0; + gdo = _ryp0*gxyaspect*(1.f/512.f) - gdx*_ox0; + gux = (_t0*_ryp0 - _t1*_ryp1)*gxyaspect*(64.f/512.f) / (_ox0-_ox1); + guo = _t0*_ryp0*gxyaspect*(64.f/512.f) - gux*_ox0; + guy = 0; + _t0 = -8192.0*_ryp0 + ghoriz; + _t1 = -8192.0*_ryp1 + ghoriz; + t = ((gdx*_ox0 + gdo)*8.f) / ((_ox1-_ox0) * _ryp0 * 2048.f); + gvx = (_t0-_t1)*t; + gvy = (_ox1-_ox0)*t; + gvo = -gvx*_ox0 - gvy*_t0; + if ((_fy0 < ncy0) && (_fy1 < ncy1)) domost(_x1,_fy1,_x0,_fy0); + else if ((_fy0 < ncy0) != (_fy1 < ncy1)) + { + //(ox,oy) is intersection of: (_x0,_fy0)-(_x1,_fy1) + // (_x0,ncy0)-(_x1,ncy1) + //ox = _x0 + (_x1-_x0)*t + //oy = _fy0 + (_fy1-_fy0)*t + //oy = ncy0 + (ncy1-ncy0)*t + t = (_fy0-ncy0)/(ncy1-ncy0-_fy1+_fy0); + ox = _x0 + (_x1-_x0)*t; + oy = _fy0 + (_fy1-_fy0)*t; + if (ncy0 < _fy0) { domost(ox,oy,_x0,ncy0); domost(_x1,_fy1,ox,oy); } + else { domost(ox,oy,_x0,_fy0); domost(_x1,ncy1,ox,oy); } + } else domost(_x1,ncy1,_x0,ncy0); + } - //Floor of skybox + //Floor of skybox #ifdef USE_OPENGL - drawingskybox = 6; //floor/6th texture/index 5 of skybox + drawingskybox = 6; //floor/6th texture/index 5 of skybox #endif - ft[0] = 512/16; ft[1] = 512/-16; - ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); - ft[3] = ((float)singlobalang)*(1.f/2147483648.f); - gdx = 0; - gdy = gxyaspect*(1.f/4194304.f); - gdo = -ghoriz*gdy; - gux = (double)ft[3]*((double)viewingrange)/-65536.0; - gvx = (double)ft[2]*((double)viewingrange)/-65536.0; - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]-gux)*ghalfx; - gvo -= (double)(ft[3]+gvx)*ghalfx; - gvx = -gvx; gvy = -gvy; gvo = -gvo; //y-flip skybox floor - domost(x1,cy1,x0,cy0); + ft[0] = 512/16; ft[1] = 512/-16; + ft[2] = ((float)cosglobalang)*(1.f/2147483648.f); + ft[3] = ((float)singlobalang)*(1.f/2147483648.f); + gdx = 0; + gdy = gxyaspect*(1.f/4194304.f); + gdo = -ghoriz*gdy; + gux = (double)ft[3]*((double)viewingrange)/-65536.0; + gvx = (double)ft[2]*((double)viewingrange)/-65536.0; + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]-gux)*ghalfx; + gvo -= (double)(ft[3]+gvx)*ghalfx; + gvx = -gvx; gvy = -gvy; gvo = -gvo; //y-flip skybox floor + domost(x1,cy1,x0,cy0); - skyclamphack = 0; + skyclamphack = 0; #ifdef USE_OPENGL - drawingskybox = 0; + drawingskybox = 0; #endif - } + } #ifdef USE_OPENGL - if (rendmode == 3) - { - skyclamphack = 0; - if (!nofog) { - bglEnable(GL_FOG); - //bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); - } - } + if (rendmode == 3) + { + skyclamphack = 0; + if (!nofog) { + bglEnable(GL_FOG); + //bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); + } + } #endif - } + } - //(x0,cy0) == (u= 0,v=0,d=) - //(x1,cy0) == (u=wal->xrepeat*8,v=0) - //(x0,fy0) == (u= 0,v=v) - // u = (gux*sx + guy*sy + guo) / (gdx*sx + gdy*sy + gdo) - // v = (gvx*sx + gvy*sy + gvo) / (gdx*sx + gdy*sy + gdo) - // 0 = (gux*x0 + guy*cy0 + guo) / (gdx*x0 + gdy*cy0 + gdo) - //wal->xrepeat*8 = (gux*x1 + guy*cy0 + guo) / (gdx*x1 + gdy*cy0 + gdo) - // 0 = (gvx*x0 + gvy*cy0 + gvo) / (gdx*x0 + gdy*cy0 + gdo) - // v = (gvx*x0 + gvy*fy0 + gvo) / (gdx*x0 + gdy*fy0 + gdo) - //sx = x0, u = t0*wal->xrepeat*8, d = yp0; - //sx = x1, u = t1*wal->xrepeat*8, d = yp1; - //d = gdx*sx + gdo - //u = (gux*sx + guo) / (gdx*sx + gdo) - //yp0 = gdx*x0 + gdo - //yp1 = gdx*x1 + gdo - //t0*wal->xrepeat*8 = (gux*x0 + guo) / (gdx*x0 + gdo) - //t1*wal->xrepeat*8 = (gux*x1 + guo) / (gdx*x1 + gdo) - //gdx*x0 + gdo = yp0 - //gdx*x1 + gdo = yp1 - gdx = (ryp0-ryp1)*gxyaspect / (x0-x1); - gdy = 0; - gdo = ryp0*gxyaspect - gdx*x0; + //(x0,cy0) == (u= 0,v=0,d=) + //(x1,cy0) == (u=wal->xrepeat*8,v=0) + //(x0,fy0) == (u= 0,v=v) + // u = (gux*sx + guy*sy + guo) / (gdx*sx + gdy*sy + gdo) + // v = (gvx*sx + gvy*sy + gvo) / (gdx*sx + gdy*sy + gdo) + // 0 = (gux*x0 + guy*cy0 + guo) / (gdx*x0 + gdy*cy0 + gdo) + //wal->xrepeat*8 = (gux*x1 + guy*cy0 + guo) / (gdx*x1 + gdy*cy0 + gdo) + // 0 = (gvx*x0 + gvy*cy0 + gvo) / (gdx*x0 + gdy*cy0 + gdo) + // v = (gvx*x0 + gvy*fy0 + gvo) / (gdx*x0 + gdy*fy0 + gdo) + //sx = x0, u = t0*wal->xrepeat*8, d = yp0; + //sx = x1, u = t1*wal->xrepeat*8, d = yp1; + //d = gdx*sx + gdo + //u = (gux*sx + guo) / (gdx*sx + gdo) + //yp0 = gdx*x0 + gdo + //yp1 = gdx*x1 + gdo + //t0*wal->xrepeat*8 = (gux*x0 + guo) / (gdx*x0 + gdo) + //t1*wal->xrepeat*8 = (gux*x1 + guo) / (gdx*x1 + gdo) + //gdx*x0 + gdo = yp0 + //gdx*x1 + gdo = yp1 + gdx = (ryp0-ryp1)*gxyaspect / (x0-x1); + gdy = 0; + gdo = ryp0*gxyaspect - gdx*x0; - //gux*x0 + guo = t0*wal->xrepeat*8*yp0 - //gux*x1 + guo = t1*wal->xrepeat*8*yp1 - gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)wal->xrepeat*8.f / (x0-x1); - guo = t0*ryp0*gxyaspect*(float)wal->xrepeat*8.f - gux*x0; - guo += (float)wal->xpanning*gdo; - gux += (float)wal->xpanning*gdx; - guy = 0; - //Derivation for u: - // (gvx*x0 + gvy*cy0 + gvo) / (gdx*x0 + gdy*cy0 + gdo) = 0 - // (gvx*x1 + gvy*cy1 + gvo) / (gdx*x1 + gdy*cy1 + gdo) = 0 - // (gvx*x0 + gvy*fy0 + gvo) / (gdx*x0 + gdy*fy0 + gdo) = v - // (gvx*x1 + gvy*fy1 + gvo) / (gdx*x1 + gdy*fy1 + gdo) = v - // (gvx*x0 + gvy*cy0 + gvo*1) = 0 - // (gvx*x1 + gvy*cy1 + gvo*1) = 0 - // (gvx*x0 + gvy*fy0 + gvo*1) = t - ogux = gux; oguy = guy; oguo = guo; + //gux*x0 + guo = t0*wal->xrepeat*8*yp0 + //gux*x1 + guo = t1*wal->xrepeat*8*yp1 + gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)wal->xrepeat*8.f / (x0-x1); + guo = t0*ryp0*gxyaspect*(float)wal->xrepeat*8.f - gux*x0; + guo += (float)wal->xpanning*gdo; + gux += (float)wal->xpanning*gdx; + guy = 0; + //Derivation for u: + // (gvx*x0 + gvy*cy0 + gvo) / (gdx*x0 + gdy*cy0 + gdo) = 0 + // (gvx*x1 + gvy*cy1 + gvo) / (gdx*x1 + gdy*cy1 + gdo) = 0 + // (gvx*x0 + gvy*fy0 + gvo) / (gdx*x0 + gdy*fy0 + gdo) = v + // (gvx*x1 + gvy*fy1 + gvo) / (gdx*x1 + gdy*fy1 + gdo) = v + // (gvx*x0 + gvy*cy0 + gvo*1) = 0 + // (gvx*x1 + gvy*cy1 + gvo*1) = 0 + // (gvx*x0 + gvy*fy0 + gvo*1) = t + ogux = gux; oguy = guy; oguo = guo; - if (nextsectnum >= 0) - { - getzsofslope(nextsectnum,(long)nx0,(long)ny0,&cz,&fz); - ocy0 = ((float)(cz-globalposz))*ryp0 + ghoriz; - ofy0 = ((float)(fz-globalposz))*ryp0 + ghoriz; - getzsofslope(nextsectnum,(long)nx1,(long)ny1,&cz,&fz); - ocy1 = ((float)(cz-globalposz))*ryp1 + ghoriz; - ofy1 = ((float)(fz-globalposz))*ryp1 + ghoriz; + if (nextsectnum >= 0) + { + getzsofslope(nextsectnum,(long)nx0,(long)ny0,&cz,&fz); + ocy0 = ((float)(cz-globalposz))*ryp0 + ghoriz; + ofy0 = ((float)(fz-globalposz))*ryp0 + ghoriz; + getzsofslope(nextsectnum,(long)nx1,(long)ny1,&cz,&fz); + ocy1 = ((float)(cz-globalposz))*ryp1 + ghoriz; + ofy1 = ((float)(fz-globalposz))*ryp1 + ghoriz; - if ((wal->cstat&48) == 16) maskwall[maskwallcnt++] = z; + if ((wal->cstat&48) == 16) maskwall[maskwallcnt++] = z; - if (((cy0 < ocy0) || (cy1 < ocy1)) && (!((sec->ceilingstat§or[nextsectnum].ceilingstat)&1))) - { - globalpicnum = wal->picnum; globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); + if (((cy0 < ocy0) || (cy1 < ocy1)) && (!((sec->ceilingstat§or[nextsectnum].ceilingstat)&1))) + { + globalpicnum = wal->picnum; globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); - if (!(wal->cstat&4)) i = sector[nextsectnum].ceilingz; else i = sec->ceilingz; - t0 = ((float)(i-globalposz))*ryp0 + ghoriz; - t1 = ((float)(i-globalposz))*ryp1 + ghoriz; - t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); - i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; - fy = (float)wal->ypanning * ((float)i) / 256.0; - gvx = (t0-t1)*t; - gvy = (x1-x0)*t; - gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; + if (!(wal->cstat&4)) i = sector[nextsectnum].ceilingz; else i = sec->ceilingz; + t0 = ((float)(i-globalposz))*ryp0 + ghoriz; + t1 = ((float)(i-globalposz))*ryp1 + ghoriz; + t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); + i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; + fy = (float)wal->ypanning * ((float)i) / 256.0; + gvx = (t0-t1)*t; + gvy = (x1-x0)*t; + gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; - if (wal->cstat&8) //xflip - { - t = (float)(wal->xrepeat*8 + wal->xpanning*2); - gux = gdx*t - gux; - guy = gdy*t - guy; - guo = gdo*t - guo; - } - if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip + if (wal->cstat&8) //xflip + { + t = (float)(wal->xrepeat*8 + wal->xpanning*2); + gux = gdx*t - gux; + guy = gdy*t - guy; + guo = gdo*t - guo; + } + if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip - pow2xsplit = 1; domost(x1,ocy1,x0,ocy0); + pow2xsplit = 1; domost(x1,ocy1,x0,ocy0); - if (wal->cstat&8) { gux = ogux; guy = oguy; guo = oguo; } - } - if (((ofy0 < fy0) || (ofy1 < fy1)) && (!((sec->floorstat§or[nextsectnum].floorstat)&1))) - { - if (!(wal->cstat&2)) nwal = wal; - else - { - nwal = &wall[wal->nextwall]; - guo += (float)(nwal->xpanning-wal->xpanning)*gdo; - gux += (float)(nwal->xpanning-wal->xpanning)*gdx; - guy += (float)(nwal->xpanning-wal->xpanning)*gdy; - } - globalpicnum = nwal->picnum; globalshade = nwal->shade; globalpal = (long)((unsigned char)nwal->pal); - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); + if (wal->cstat&8) { gux = ogux; guy = oguy; guo = oguo; } + } + if (((ofy0 < fy0) || (ofy1 < fy1)) && (!((sec->floorstat§or[nextsectnum].floorstat)&1))) + { + if (!(wal->cstat&2)) nwal = wal; + else + { + nwal = &wall[wal->nextwall]; + guo += (float)(nwal->xpanning-wal->xpanning)*gdo; + gux += (float)(nwal->xpanning-wal->xpanning)*gdx; + guy += (float)(nwal->xpanning-wal->xpanning)*gdy; + } + globalpicnum = nwal->picnum; globalshade = nwal->shade; globalpal = (long)((unsigned char)nwal->pal); + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); - if (!(nwal->cstat&4)) i = sector[nextsectnum].floorz; else i = sec->ceilingz; - t0 = ((float)(i-globalposz))*ryp0 + ghoriz; - t1 = ((float)(i-globalposz))*ryp1 + ghoriz; - t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); - i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; - fy = (float)nwal->ypanning * ((float)i) / 256.0; - gvx = (t0-t1)*t; - gvy = (x1-x0)*t; - gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; + if (!(nwal->cstat&4)) i = sector[nextsectnum].floorz; else i = sec->ceilingz; + t0 = ((float)(i-globalposz))*ryp0 + ghoriz; + t1 = ((float)(i-globalposz))*ryp1 + ghoriz; + t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); + i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; + fy = (float)nwal->ypanning * ((float)i) / 256.0; + gvx = (t0-t1)*t; + gvy = (x1-x0)*t; + gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; - if (wal->cstat&8) //xflip - { - t = (float)(wal->xrepeat*8 + nwal->xpanning*2); - gux = gdx*t - gux; - guy = gdy*t - guy; - guo = gdo*t - guo; - } - if (nwal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip + if (wal->cstat&8) //xflip + { + t = (float)(wal->xrepeat*8 + nwal->xpanning*2); + gux = gdx*t - gux; + guy = gdy*t - guy; + guo = gdo*t - guo; + } + if (nwal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip - pow2xsplit = 1; domost(x0,ofy0,x1,ofy1); + pow2xsplit = 1; domost(x0,ofy0,x1,ofy1); - if (wal->cstat&(2+8)) { guo = oguo; gux = ogux; guy = oguy; } - } - } + if (wal->cstat&(2+8)) { guo = oguo; gux = ogux; guy = oguy; } + } + } - if ((nextsectnum < 0) || (wal->cstat&32)) //White/1-way wall - { - if (nextsectnum < 0) globalpicnum = wal->picnum; else globalpicnum = wal->overpicnum; - globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); + if ((nextsectnum < 0) || (wal->cstat&32)) //White/1-way wall + { + if (nextsectnum < 0) globalpicnum = wal->picnum; else globalpicnum = wal->overpicnum; + globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); - if (nextsectnum >= 0) { if (!(wal->cstat&4)) i = nextsec->ceilingz; else i = sec->ceilingz; } - else { if (!(wal->cstat&4)) i = sec->ceilingz; else i = sec->floorz; } - t0 = ((float)(i-globalposz))*ryp0 + ghoriz; - t1 = ((float)(i-globalposz))*ryp1 + ghoriz; - t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); - i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; - fy = (float)wal->ypanning * ((float)i) / 256.0; - gvx = (t0-t1)*t; - gvy = (x1-x0)*t; - gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; + if (nextsectnum >= 0) { if (!(wal->cstat&4)) i = nextsec->ceilingz; else i = sec->ceilingz; } + else { if (!(wal->cstat&4)) i = sec->ceilingz; else i = sec->floorz; } + t0 = ((float)(i-globalposz))*ryp0 + ghoriz; + t1 = ((float)(i-globalposz))*ryp1 + ghoriz; + t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); + i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; + fy = (float)wal->ypanning * ((float)i) / 256.0; + gvx = (t0-t1)*t; + gvy = (x1-x0)*t; + gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; - if (wal->cstat&8) //xflip - { - t = (float)(wal->xrepeat*8 + wal->xpanning*2); - gux = gdx*t - gux; - guy = gdy*t - guy; - guo = gdo*t - guo; - } - if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip - pow2xsplit = 1; domost(x0,-10000,x1,-10000); - } + if (wal->cstat&8) //xflip + { + t = (float)(wal->xrepeat*8 + wal->xpanning*2); + gux = gdx*t - gux; + guy = gdy*t - guy; + guo = gdo*t - guo; + } + if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip + pow2xsplit = 1; domost(x0,-10000,x1,-10000); + } - if (nextsectnum >= 0) - if ((!(gotsector[nextsectnum>>3]&pow2char[nextsectnum&7])) && (testvisiblemost(x0,x1))) - polymost_scansector(nextsectnum); - } + if (nextsectnum >= 0) + if ((!(gotsector[nextsectnum>>3]&pow2char[nextsectnum&7])) && (testvisiblemost(x0,x1))) + polymost_scansector(nextsectnum); + } } static long wallfront(long, long); static long polymost_bunchfront (long b1, long b2) { - double x1b1, x1b2, x2b1, x2b2; - long b1f, b2f, i; + double x1b1, x1b2, x2b1, x2b2; + long b1f, b2f, i; - b1f = bunchfirst[b1]; x1b1 = dxb1[b1f]; x2b2 = dxb2[bunchlast[b2]]; if (x1b1 >= x2b2) return(-1); - b2f = bunchfirst[b2]; x1b2 = dxb1[b2f]; x2b1 = dxb2[bunchlast[b1]]; if (x1b2 >= x2b1) return(-1); + b1f = bunchfirst[b1]; x1b1 = dxb1[b1f]; x2b2 = dxb2[bunchlast[b2]]; if (x1b1 >= x2b2) return(-1); + b2f = bunchfirst[b2]; x1b2 = dxb1[b2f]; x2b1 = dxb2[bunchlast[b1]]; if (x1b2 >= x2b1) return(-1); - if (x1b1 >= x1b2) - { - for(i=b2f;dxb2[i]<=x1b1;i=p2[i]); - return(wallfront(b1f,i)); - } - for(i=b1f;dxb2[i]<=x1b2;i=p2[i]); - return(wallfront(i,b2f)); + if (x1b1 >= x1b2) + { + for(i=b2f;dxb2[i]<=x1b1;i=p2[i]); + return(wallfront(b1f,i)); + } + for(i=b1f;dxb2[i]<=x1b2;i=p2[i]); + return(wallfront(i,b2f)); } static void polymost_scansector (long sectnum) { - double d, xp1, yp1, xp2, yp2; - walltype *wal, *wal2; - spritetype *spr; - long z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst, nextsectnum; - long xs, ys, x1, y1, x2, y2; + double d, xp1, yp1, xp2, yp2; + walltype *wal, *wal2; + spritetype *spr; + long z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst, nextsectnum; + long xs, ys, x1, y1, x2, y2; - if (sectnum < 0) return; - if (automapping) show2dsector[sectnum>>3] |= pow2char[sectnum&7]; + if (sectnum < 0) return; + if (automapping) show2dsector[sectnum>>3] |= pow2char[sectnum&7]; - sectorborder[0] = sectnum, sectorbordercnt = 1; - do - { - sectnum = sectorborder[--sectorbordercnt]; + sectorborder[0] = sectnum, sectorbordercnt = 1; + do + { + sectnum = sectorborder[--sectorbordercnt]; - for(z=headspritesect[sectnum];z>=0;z=nextspritesect[z]) - { - spr = &sprite[z]; - if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) && - (spr->xrepeat > 0) && (spr->yrepeat > 0) && - (spritesortcnt < MAXSPRITESONSCREEN)) - { - xs = spr->x-globalposx; ys = spr->y-globalposy; - if ((spr->cstat&48) || (xs*gcosang+ys*gsinang > 0)) - { - copybufbyte(spr,&tsprite[spritesortcnt],sizeof(spritetype)); - tsprite[spritesortcnt++].owner = z; - } - } - } + for(z=headspritesect[sectnum];z>=0;z=nextspritesect[z]) + { + spr = &sprite[z]; + if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) && + (spr->xrepeat > 0) && (spr->yrepeat > 0) && + (spritesortcnt < MAXSPRITESONSCREEN)) + { + xs = spr->x-globalposx; ys = spr->y-globalposy; + if ((spr->cstat&48) || (xs*gcosang+ys*gsinang > 0)) + { + copybufbyte(spr,&tsprite[spritesortcnt],sizeof(spritetype)); + tsprite[spritesortcnt++].owner = z; + } + } + } - gotsector[sectnum>>3] |= pow2char[sectnum&7]; + gotsector[sectnum>>3] |= pow2char[sectnum&7]; - bunchfrst = numbunches; - numscansbefore = numscans; + bunchfrst = numbunches; + numscansbefore = numscans; - startwall = sector[sectnum].wallptr; endwall = sector[sectnum].wallnum+startwall; - scanfirst = numscans; - xp2 = 0; yp2 = 0; - for(z=startwall,wal=&wall[z];zpoint2]; - x1 = wal->x-globalposx; y1 = wal->y-globalposy; - x2 = wal2->x-globalposx; y2 = wal2->y-globalposy; + startwall = sector[sectnum].wallptr; endwall = sector[sectnum].wallnum+startwall; + scanfirst = numscans; + xp2 = 0; yp2 = 0; + for(z=startwall,wal=&wall[z];zpoint2]; + x1 = wal->x-globalposx; y1 = wal->y-globalposy; + x2 = wal2->x-globalposx; y2 = wal2->y-globalposy; - nextsectnum = wal->nextsector; //Scan close sectors - if ((nextsectnum >= 0) && (!(wal->cstat&32)) && (!(gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]))) - { - d = (double)x1*(double)y2 - (double)x2*(double)y1; xp1 = (double)(x2-x1); yp1 = (double)(y2-y1); - if (d*d <= (xp1*xp1 + yp1*yp1)*(SCISDIST*SCISDIST*260.0)) - sectorborder[sectorbordercnt++] = nextsectnum; - } + nextsectnum = wal->nextsector; //Scan close sectors + if ((nextsectnum >= 0) && (!(wal->cstat&32)) && (!(gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]))) + { + d = (double)x1*(double)y2 - (double)x2*(double)y1; xp1 = (double)(x2-x1); yp1 = (double)(y2-y1); + if (d*d <= (xp1*xp1 + yp1*yp1)*(SCISDIST*SCISDIST*260.0)) + sectorborder[sectorbordercnt++] = nextsectnum; + } - if ((z == startwall) || (wall[z-1].point2 != z)) - { - xp1 = ((double)y1*(double)cosglobalang - (double)x1*(double)singlobalang )/64.0; - yp1 = ((double)x1*(double)cosviewingrangeglobalang + (double)y1*(double)sinviewingrangeglobalang)/64.0; - } - else { xp1 = xp2; yp1 = yp2; } - xp2 = ((double)y2*(double)cosglobalang - (double)x2*(double)singlobalang )/64.0; - yp2 = ((double)x2*(double)cosviewingrangeglobalang + (double)y2*(double)sinviewingrangeglobalang)/64.0; - if ((yp1 >= SCISDIST) || (yp2 >= SCISDIST)) - if ((double)xp1*(double)yp2 < (double)xp2*(double)yp1) //if wall is facing you... - { - if (yp1 >= SCISDIST) - dxb1[numscans] = (double)xp1*ghalfx/(double)yp1 + ghalfx; - else dxb1[numscans] = -1e32; + if ((z == startwall) || (wall[z-1].point2 != z)) + { + xp1 = ((double)y1*(double)cosglobalang - (double)x1*(double)singlobalang )/64.0; + yp1 = ((double)x1*(double)cosviewingrangeglobalang + (double)y1*(double)sinviewingrangeglobalang)/64.0; + } + else { xp1 = xp2; yp1 = yp2; } + xp2 = ((double)y2*(double)cosglobalang - (double)x2*(double)singlobalang )/64.0; + yp2 = ((double)x2*(double)cosviewingrangeglobalang + (double)y2*(double)sinviewingrangeglobalang)/64.0; + if ((yp1 >= SCISDIST) || (yp2 >= SCISDIST)) + if ((double)xp1*(double)yp2 < (double)xp2*(double)yp1) //if wall is facing you... + { + if (yp1 >= SCISDIST) + dxb1[numscans] = (double)xp1*ghalfx/(double)yp1 + ghalfx; + else dxb1[numscans] = -1e32; - if (yp2 >= SCISDIST) - dxb2[numscans] = (double)xp2*ghalfx/(double)yp2 + ghalfx; - else dxb2[numscans] = 1e32; + if (yp2 >= SCISDIST) + dxb2[numscans] = (double)xp2*ghalfx/(double)yp2 + ghalfx; + else dxb2[numscans] = 1e32; - if (dxb1[numscans] < dxb2[numscans]) - { thesector[numscans] = sectnum; thewall[numscans] = z; p2[numscans] = numscans+1; numscans++; } - } + if (dxb1[numscans] < dxb2[numscans]) + { thesector[numscans] = sectnum; thewall[numscans] = z; p2[numscans] = numscans+1; numscans++; } + } - if ((wall[z].point2 < z) && (scanfirst < numscans)) - { p2[numscans-1] = scanfirst; scanfirst = numscans; } - } + if ((wall[z].point2 < z) && (scanfirst < numscans)) + { p2[numscans-1] = scanfirst; scanfirst = numscans; } + } - for(z=numscansbefore;z dxb1[p2[z]])) - { bunchfirst[numbunches++] = p2[z]; p2[z] = -1; } + for(z=numscansbefore;z dxb1[p2[z]])) + { bunchfirst[numbunches++] = p2[z]; p2[z] = -1; } - for(z=bunchfrst;z=0;zz=p2[zz]); - bunchlast[z] = zz; - } - } while (sectorbordercnt > 0); + for(z=bunchfrst;z=0;zz=p2[zz]); + bunchlast[z] = zz; + } + } while (sectorbordercnt > 0); } void polymost_drawrooms () { - long i, j, k, n, n2, closest; - double ox, oy, oz, ox2, oy2, oz2, r, px[6], py[6], pz[6], px2[6], py2[6], pz2[6], sx[6], sy[6]; + long i, j, k, n, n2, closest; + double ox, oy, oz, ox2, oy2, oz2, r, px[6], py[6], pz[6], px2[6], py2[6], pz2[6], sx[6], sy[6]; - if (!rendmode) return; + if (!rendmode) return; - begindrawing(); - frameoffset = frameplace + windowy1*bytesperline + windowx1; + begindrawing(); + frameoffset = frameplace + windowy1*bytesperline + windowx1; #ifdef USE_OPENGL - if (rendmode == 3) - { - resizeglcheck(); + if (rendmode == 3) + { + resizeglcheck(); - //bglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - bglEnable(GL_TEXTURE_2D); - //bglTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); //default anyway - bglEnable(GL_DEPTH_TEST); - bglDepthFunc(GL_ALWAYS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS + //bglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + bglEnable(GL_TEXTURE_2D); + //bglTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); //default anyway + bglEnable(GL_DEPTH_TEST); + bglDepthFunc(GL_ALWAYS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS - //bglPolygonOffset(1,1); //Supposed to make sprites pasted on walls or floors not disappear - bglDepthRange(0.00001,1.0); //<- this is more widely supported than glPolygonOffset + //bglPolygonOffset(1,1); //Supposed to make sprites pasted on walls or floors not disappear + bglDepthRange(0.00001,1.0); //<- this is more widely supported than glPolygonOffset - //Enable this for OpenGL red-blue glasses mode :) - if (glredbluemode) - { - float m[4][4]; - static int grbfcnt = 0; grbfcnt++; - if (redblueclearcnt < numpages) { redblueclearcnt++; bglColorMask(1,1,1,1); bglClear(GL_COLOR_BUFFER_BIT); } - if (grbfcnt&1) - { - bglViewport(windowx1-16,yres-(windowy2+1),windowx2-(windowx1-16)+1,windowy2-windowy1+1); - bglColorMask(1,0,0,1); - globalposx += singlobalang/1024; - globalposy -= cosglobalang/1024; - } - else - { - bglViewport(windowx1,yres-(windowy2+1),windowx2+16-windowx1+1,windowy2-windowy1+1); - bglColorMask(0,1,1,1); - globalposx -= singlobalang/1024; - globalposy += cosglobalang/1024; - } - } - } + //Enable this for OpenGL red-blue glasses mode :) + if (glredbluemode) + { + float m[4][4]; + static int grbfcnt = 0; grbfcnt++; + if (redblueclearcnt < numpages) { redblueclearcnt++; bglColorMask(1,1,1,1); bglClear(GL_COLOR_BUFFER_BIT); } + if (grbfcnt&1) + { + bglViewport(windowx1-16,yres-(windowy2+1),windowx2-(windowx1-16)+1,windowy2-windowy1+1); + bglColorMask(1,0,0,1); + globalposx += singlobalang/1024; + globalposy -= cosglobalang/1024; + } + else + { + bglViewport(windowx1,yres-(windowy2+1),windowx2+16-windowx1+1,windowy2-windowy1+1); + bglColorMask(0,1,1,1); + globalposx -= singlobalang/1024; + globalposy += cosglobalang/1024; + } + } + } #endif - //Polymost supports true look up/down :) Here, we convert horizon to angle. - //gchang&gshang are cos&sin of this angle (respectively) - gyxscale = ((double)xdimenscale)/131072.0; - gxyaspect = ((double)xyaspect*(double)viewingrange)*(5.0/(65536.0*262144.0)); - gviewxrange = ((double)viewingrange)*((double)xdimen)/(32768.0*1024.0); - gcosang = ((double)cosglobalang)/262144.0; - gsinang = ((double)singlobalang)/262144.0; - gcosang2 = gcosang*((double)viewingrange)/65536.0; - gsinang2 = gsinang*((double)viewingrange)/65536.0; - ghalfx = (double)halfxdimen; grhalfxdown10 = 1.0/(((double)ghalfx)*1024); - ghoriz = (double)globalhoriz; + //Polymost supports true look up/down :) Here, we convert horizon to angle. + //gchang&gshang are cos&sin of this angle (respectively) + gyxscale = ((double)xdimenscale)/131072.0; + gxyaspect = ((double)xyaspect*(double)viewingrange)*(5.0/(65536.0*262144.0)); + gviewxrange = ((double)viewingrange)*((double)xdimen)/(32768.0*1024.0); + gcosang = ((double)cosglobalang)/262144.0; + gsinang = ((double)singlobalang)/262144.0; + gcosang2 = gcosang*((double)viewingrange)/65536.0; + gsinang2 = gsinang*((double)viewingrange)/65536.0; + ghalfx = (double)halfxdimen; grhalfxdown10 = 1.0/(((double)ghalfx)*1024); + ghoriz = (double)globalhoriz; - gvisibility = ((float)globalvisibility)*gxyaspect*FOGSCALE; + gvisibility = ((float)globalvisibility)*gxyaspect*FOGSCALE; - //global cos/sin height angle - r = (double)((ydimen>>1)-ghoriz); - gshang = r/sqrt(r*r+ghalfx*ghalfx); - gchang = sqrt(1.0-gshang*gshang); - ghoriz = (double)(ydimen>>1); + //global cos/sin height angle + r = (double)((ydimen>>1)-ghoriz); + gshang = r/sqrt(r*r+ghalfx*ghalfx); + gchang = sqrt(1.0-gshang*gshang); + ghoriz = (double)(ydimen>>1); - //global cos/sin tilt angle - gctang = cos(gtang); - gstang = sin(gtang); - if (fabs(gstang) < .001) //This hack avoids nasty precision bugs in domost() - { gstang = 0; if (gctang > 0) gctang = 1.0; else gctang = -1.0; } + //global cos/sin tilt angle + gctang = cos(gtang); + gstang = sin(gtang); + if (fabs(gstang) < .001) //This hack avoids nasty precision bugs in domost() + { gstang = 0; if (gctang > 0) gctang = 1.0; else gctang = -1.0; } - if (inpreparemirror) - gstang = -gstang; + if (inpreparemirror) + gstang = -gstang; - //Generate viewport trapezoid (for handling screen up/down) - px[0] = px[3] = 0-1; px[1] = px[2] = windowx2+1-windowx1+2; - py[0] = py[1] = 0-1; py[2] = py[3] = windowy2+1-windowy1+2; n = 4; - for(i=0;i= n) j = 0; - if (pz[i] >= SCISDIST) { px2[n2] = px[i]; py2[n2] = py[i]; pz2[n2] = pz[i]; n2++; } - if ((pz[i] >= SCISDIST) != (pz[j] >= SCISDIST)) - { - r = (SCISDIST-pz[i])/(pz[j]-pz[i]); - px2[n2] = (px[j]-px[i])*r + px[i]; - py2[n2] = (py[j]-py[i])*r + py[i]; - pz2[n2] = SCISDIST; n2++; - } - } - if (n2 < 3) { enddrawing(); return; } - for(i=0;i= n) j = 0; + if (pz[i] >= SCISDIST) { px2[n2] = px[i]; py2[n2] = py[i]; pz2[n2] = pz[i]; n2++; } + if ((pz[i] >= SCISDIST) != (pz[j] >= SCISDIST)) + { + r = (SCISDIST-pz[i])/(pz[j]-pz[i]); + px2[n2] = (px[j]-px[i])*r + px[i]; + py2[n2] = (py[j]-py[i])*r + py[i]; + pz2[n2] = SCISDIST; n2++; + } + } + if (n2 < 3) { enddrawing(); return; } + for(i=0;i>12,vy>>12,vz>>8,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,0xffff0030); - hitallsprites = 0; + hitallsprites = 1; + hitscan(globalposx,globalposy,globalposz,globalcursectnum, //Start position + vx>>12,vy>>12,vz>>8,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,0xffff0030); + hitallsprites = 0; - searchsector = hitsect; - if (hitwall >= 0) - { - searchwall = hitwall; searchstat = 0; - if (wall[hitwall].nextwall >= 0) - { - long cz, fz; - getzsofslope(wall[hitwall].nextsector,hitx,hity,&cz,&fz); - if (hitz > fz) - { - if (wall[hitwall].cstat&2) //'2' bottoms of walls - searchwall = wall[hitwall].nextwall; - } - else if ((hitz > cz) && (wall[hitwall].cstat&(16+32))) //masking or 1-way - searchstat = 4; - } - } - else if (hitsprite >= 0) { searchwall = hitsprite; searchstat = 3; } - else - { - long cz, fz; - getzsofslope(hitsect,hitx,hity,&cz,&fz); - if ((hitz<<1) < cz+fz) searchstat = 1; else searchstat = 2; - //if (vz < 0) searchstat = 1; else searchstat = 2; //Won't work for slopes :/ - } - searchit = 0; - } + searchsector = hitsect; + if (hitwall >= 0) + { + searchwall = hitwall; searchstat = 0; + if (wall[hitwall].nextwall >= 0) + { + long cz, fz; + getzsofslope(wall[hitwall].nextsector,hitx,hity,&cz,&fz); + if (hitz > fz) + { + if (wall[hitwall].cstat&2) //'2' bottoms of walls + searchwall = wall[hitwall].nextwall; + } + else if ((hitz > cz) && (wall[hitwall].cstat&(16+32))) //masking or 1-way + searchstat = 4; + } + } + else if (hitsprite >= 0) { searchwall = hitsprite; searchstat = 3; } + else + { + long cz, fz; + getzsofslope(hitsect,hitx,hity,&cz,&fz); + if ((hitz<<1) < cz+fz) searchstat = 1; else searchstat = 2; + //if (vz < 0) searchstat = 1; else searchstat = 2; //Won't work for slopes :/ + } + searchit = 0; + } - numscans = numbunches = 0; + numscans = numbunches = 0; - if (globalcursectnum >= MAXSECTORS) - globalcursectnum -= MAXSECTORS; - else - { - i = globalcursectnum; - updatesector(globalposx,globalposy,&globalcursectnum); - if (globalcursectnum < 0) globalcursectnum = i; - } + if (globalcursectnum >= MAXSECTORS) + globalcursectnum -= MAXSECTORS; + else + { + i = globalcursectnum; + updatesector(globalposx,globalposy,&globalcursectnum); + if (globalcursectnum < 0) globalcursectnum = i; + } - polymost_scansector(globalcursectnum); + polymost_scansector(globalcursectnum); - if (inpreparemirror) - { - grhalfxdown10x = -grhalfxdown10; - inpreparemirror = 0; - polymost_drawalls(0); - numbunches--; - bunchfirst[0] = bunchfirst[numbunches]; - bunchlast[0] = bunchlast[numbunches]; - } - else - grhalfxdown10x = grhalfxdown10; + if (inpreparemirror) + { + grhalfxdown10x = -grhalfxdown10; + inpreparemirror = 0; + polymost_drawalls(0); + numbunches--; + bunchfirst[0] = bunchfirst[numbunches]; + bunchlast[0] = bunchlast[numbunches]; + } + else + grhalfxdown10x = grhalfxdown10; - while (numbunches > 0) - { - memset(tempbuf,0,numbunches+3); tempbuf[0] = 1; + while (numbunches > 0) + { + memset(tempbuf,0,numbunches+3); tempbuf[0] = 1; - closest = 0; //Almost works, but not quite :( - for(i=1;ipoint2]; - sectnum = thesector[z]; sec = §or[sectnum]; - nsec = §or[wal->nextsector]; - z1 = max(nsec->ceilingz,sec->ceilingz); - z2 = min(nsec->floorz,sec->floorz); + z = maskwall[damaskwallcnt]; + wal = &wall[thewall[z]]; wal2 = &wall[wal->point2]; + sectnum = thesector[z]; sec = §or[sectnum]; + nsec = §or[wal->nextsector]; + z1 = max(nsec->ceilingz,sec->ceilingz); + z2 = min(nsec->floorz,sec->floorz); - globalpicnum = wal->overpicnum; if ((unsigned long)globalpicnum >= MAXTILES) globalpicnum = 0; - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)thewall[z]+16384); - globalshade = (long)wal->shade; - globalpal = (long)((unsigned char)wal->pal); - globalorientation = (long)wal->cstat; + globalpicnum = wal->overpicnum; if ((unsigned long)globalpicnum >= MAXTILES) globalpicnum = 0; + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)thewall[z]+16384); + globalshade = (long)wal->shade; + globalpal = (long)((unsigned char)wal->pal); + globalorientation = (long)wal->cstat; - sx0 = (float)(wal->x-globalposx); sx1 = (float)(wal2->x-globalposx); - sy0 = (float)(wal->y-globalposy); sy1 = (float)(wal2->y-globalposy); - yp0 = sx0*gcosang2 + sy0*gsinang2; - yp1 = sx1*gcosang2 + sy1*gsinang2; - if ((yp0 < SCISDIST) && (yp1 < SCISDIST)) return; - xp0 = sy0*gcosang - sx0*gsinang; - xp1 = sy1*gcosang - sx1*gsinang; + sx0 = (float)(wal->x-globalposx); sx1 = (float)(wal2->x-globalposx); + sy0 = (float)(wal->y-globalposy); sy1 = (float)(wal2->y-globalposy); + yp0 = sx0*gcosang2 + sy0*gsinang2; + yp1 = sx1*gcosang2 + sy1*gsinang2; + if ((yp0 < SCISDIST) && (yp1 < SCISDIST)) return; + xp0 = sy0*gcosang - sx0*gsinang; + xp1 = sy1*gcosang - sx1*gsinang; - //Clip to close parallel-screen plane - oxp0 = xp0; oyp0 = yp0; - if (yp0 < SCISDIST) { t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; } - else t0 = 0.f; - if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; } - else { t1 = 1.f; } + //Clip to close parallel-screen plane + oxp0 = xp0; oyp0 = yp0; +if (yp0 < SCISDIST) { t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; } + else t0 = 0.f; +if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; } + else { t1 = 1.f; } - getzsofslope(sectnum,(long)((wal2->x-wal->x)*t0+wal->x),(long)((wal2->y-wal->y)*t0+wal->y),&cz[0],&fz[0]); - getzsofslope(wal->nextsector,(long)((wal2->x-wal->x)*t0+wal->x),(long)((wal2->y-wal->y)*t0+wal->y),&cz[1],&fz[1]); - getzsofslope(sectnum,(long)((wal2->x-wal->x)*t1+wal->x),(long)((wal2->y-wal->y)*t1+wal->y),&cz[2],&fz[2]); - getzsofslope(wal->nextsector,(long)((wal2->x-wal->x)*t1+wal->x),(long)((wal2->y-wal->y)*t1+wal->y),&cz[3],&fz[3]); + getzsofslope(sectnum,(long)((wal2->x-wal->x)*t0+wal->x),(long)((wal2->y-wal->y)*t0+wal->y),&cz[0],&fz[0]); + getzsofslope(wal->nextsector,(long)((wal2->x-wal->x)*t0+wal->x),(long)((wal2->y-wal->y)*t0+wal->y),&cz[1],&fz[1]); + getzsofslope(sectnum,(long)((wal2->x-wal->x)*t1+wal->x),(long)((wal2->y-wal->y)*t1+wal->y),&cz[2],&fz[2]); + getzsofslope(wal->nextsector,(long)((wal2->x-wal->x)*t1+wal->x),(long)((wal2->y-wal->y)*t1+wal->y),&cz[3],&fz[3]); - ryp0 = 1.f/yp0; ryp1 = 1.f/yp1; + ryp0 = 1.f/yp0; ryp1 = 1.f/yp1; - //Generate screen coordinates for front side of wall - x0 = ghalfx*xp0*ryp0 + ghalfx; - x1 = ghalfx*xp1*ryp1 + ghalfx; - if (x1 <= x0) return; + //Generate screen coordinates for front side of wall + x0 = ghalfx*xp0*ryp0 + ghalfx; + x1 = ghalfx*xp1*ryp1 + ghalfx; + if (x1 <= x0) return; - ryp0 *= gyxscale; ryp1 *= gyxscale; + ryp0 *= gyxscale; ryp1 *= gyxscale; - gdx = (ryp0-ryp1)*gxyaspect / (x0-x1); - gdy = 0; - gdo = ryp0*gxyaspect - gdx*x0; + gdx = (ryp0-ryp1)*gxyaspect / (x0-x1); + gdy = 0; + gdo = ryp0*gxyaspect - gdx*x0; - //gux*x0 + guo = t0*wal->xrepeat*8*yp0 - //gux*x1 + guo = t1*wal->xrepeat*8*yp1 - gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)wal->xrepeat*8.f / (x0-x1); - guo = t0*ryp0*gxyaspect*(float)wal->xrepeat*8.f - gux*x0; - guo += (float)wal->xpanning*gdo; - gux += (float)wal->xpanning*gdx; - guy = 0; + //gux*x0 + guo = t0*wal->xrepeat*8*yp0 + //gux*x1 + guo = t1*wal->xrepeat*8*yp1 + gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)wal->xrepeat*8.f / (x0-x1); + guo = t0*ryp0*gxyaspect*(float)wal->xrepeat*8.f - gux*x0; + guo += (float)wal->xpanning*gdo; + gux += (float)wal->xpanning*gdx; + guy = 0; - if (!(wal->cstat&4)) i = z1; else i = z2; - i -= globalposz; - t0 = ((float)i)*ryp0 + ghoriz; - t1 = ((float)i)*ryp1 + ghoriz; - t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); - i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; - fy = (float)wal->ypanning * ((float)i) / 256.0; - gvx = (t0-t1)*t; - gvy = (x1-x0)*t; - gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; + if (!(wal->cstat&4)) i = z1; else i = z2; + i -= globalposz; + t0 = ((float)i)*ryp0 + ghoriz; + t1 = ((float)i)*ryp1 + ghoriz; + t = ((gdx*x0 + gdo) * (float)wal->yrepeat) / ((x1-x0) * ryp0 * 2048.f); + i = (1<<(picsiz[globalpicnum]>>4)); if (i < tilesizy[globalpicnum]) i <<= 1; + fy = (float)wal->ypanning * ((float)i) / 256.0; + gvx = (t0-t1)*t; + gvy = (x1-x0)*t; + gvo = -gvx*x0 - gvy*t0 + fy*gdo; gvx += fy*gdx; gvy += fy*gdy; - if (wal->cstat&8) //xflip - { - t = (float)(wal->xrepeat*8 + wal->xpanning*2); - gux = gdx*t - gux; - guy = gdy*t - guy; - guo = gdo*t - guo; - } - if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip + if (wal->cstat&8) //xflip + { + t = (float)(wal->xrepeat*8 + wal->xpanning*2); + gux = gdx*t - gux; + guy = gdy*t - guy; + guo = gdo*t - guo; + } + if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip - method = 1; pow2xsplit = 1; - if (wal->cstat&128) { if (!(wal->cstat&512)) method = 2; else method = 3; } + method = 1; pow2xsplit = 1; + if (wal->cstat&128) { if (!(wal->cstat&512)) method = 2; else method = 3; } #ifdef USE_OPENGL - if (!nofog) { - if (rendmode == 3) { - float col[4]; - col[0] = (float)palookupfog[sec->floorpal].r / 63.f; - col[1] = (float)palookupfog[sec->floorpal].g / 63.f; - col[2] = (float)palookupfog[sec->floorpal].b / 63.f; - col[3] = 0; - bglFogfv(GL_FOG_COLOR,col); - bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); - } - } + if (!nofog) { + if (rendmode == 3) { + float col[4]; + col[0] = (float)palookupfog[sec->floorpal].r / 63.f; + col[1] = (float)palookupfog[sec->floorpal].g / 63.f; + col[2] = (float)palookupfog[sec->floorpal].b / 63.f; + col[3] = 0; + bglFogfv(GL_FOG_COLOR,col); + bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sec->visibility+16)))); + } + } #endif - for(i=0;i<2;i++) - { - csy[i] = ((float)(cz[i]-globalposz))*ryp0 + ghoriz; - fsy[i] = ((float)(fz[i]-globalposz))*ryp0 + ghoriz; - csy[i+2] = ((float)(cz[i+2]-globalposz))*ryp1 + ghoriz; - fsy[i+2] = ((float)(fz[i+2]-globalposz))*ryp1 + ghoriz; - } + for(i=0;i<2;i++) + { + csy[i] = ((float)(cz[i]-globalposz))*ryp0 + ghoriz; + fsy[i] = ((float)(fz[i]-globalposz))*ryp0 + ghoriz; + csy[i+2] = ((float)(cz[i+2]-globalposz))*ryp1 + ghoriz; + fsy[i+2] = ((float)(fz[i+2]-globalposz))*ryp1 + ghoriz; + } - //Clip 2 quadrilaterals - // /csy3 - // / | - // csy0------/----csy2 - // | /xxxxxxx| - // | /xxxxxxxxx| - // csy1/xxxxxxxxxxx| - // |xxxxxxxxxxx/fsy3 - // |xxxxxxxxx/ | - // |xxxxxxx/ | - // fsy0----/------fsy2 - // | / - // fsy1/ + //Clip 2 quadrilaterals + // /csy3 + // / | + // csy0------/----csy2 + // | /xxxxxxx| + // | /xxxxxxxxx| + // csy1/xxxxxxxxxxx| + // |xxxxxxxxxxx/fsy3 + // |xxxxxxxxx/ | + // |xxxxxxx/ | + // fsy0----/------fsy2 + // | / + // fsy1/ - dpx[0] = x0; dpy[0] = csy[1]; - dpx[1] = x1; dpy[1] = csy[3]; - dpx[2] = x1; dpy[2] = fsy[3]; - dpx[3] = x0; dpy[3] = fsy[1]; - n = 4; + dpx[0] = x0; dpy[0] = csy[1]; + dpx[1] = x1; dpy[1] = csy[3]; + dpx[2] = x1; dpy[2] = fsy[3]; + dpx[3] = x0; dpy[3] = fsy[1]; + n = 4; - //Clip to (x0,csy[0])-(x1,csy[2]) - n2 = 0; t1 = -((dpx[0]-x0)*(csy[2]-csy[0]) - (dpy[0]-csy[0])*(x1-x0)); - for(i=0;i= n) j = 0; + //Clip to (x0,csy[0])-(x1,csy[2]) + n2 = 0; t1 = -((dpx[0]-x0)*(csy[2]-csy[0]) - (dpy[0]-csy[0])*(x1-x0)); + for(i=0;i= n) j = 0; - t0 = t1; t1 = -((dpx[j]-x0)*(csy[2]-csy[0]) - (dpy[j]-csy[0])*(x1-x0)); - if (t0 >= 0) { dpx2[n2] = dpx[i]; dpy2[n2] = dpy[i]; n2++; } - if ((t0 >= 0) != (t1 >= 0)) - { - r = t0/(t0-t1); - dpx2[n2] = (dpx[j]-dpx[i])*r + dpx[i]; - dpy2[n2] = (dpy[j]-dpy[i])*r + dpy[i]; - n2++; - } - } - if (n2 < 3) return; + t0 = t1; t1 = -((dpx[j]-x0)*(csy[2]-csy[0]) - (dpy[j]-csy[0])*(x1-x0)); + if (t0 >= 0) { dpx2[n2] = dpx[i]; dpy2[n2] = dpy[i]; n2++; } + if ((t0 >= 0) != (t1 >= 0)) + { + r = t0/(t0-t1); + dpx2[n2] = (dpx[j]-dpx[i])*r + dpx[i]; + dpy2[n2] = (dpy[j]-dpy[i])*r + dpy[i]; + n2++; + } + } + if (n2 < 3) return; - //Clip to (x1,fsy[2])-(x0,fsy[0]) - n = 0; t1 = -((dpx2[0]-x1)*(fsy[0]-fsy[2]) - (dpy2[0]-fsy[2])*(x0-x1)); - for(i=0;i= n2) j = 0; + //Clip to (x1,fsy[2])-(x0,fsy[0]) + n = 0; t1 = -((dpx2[0]-x1)*(fsy[0]-fsy[2]) - (dpy2[0]-fsy[2])*(x0-x1)); + for(i=0;i= n2) j = 0; - t0 = t1; t1 = -((dpx2[j]-x1)*(fsy[0]-fsy[2]) - (dpy2[j]-fsy[2])*(x0-x1)); - if (t0 >= 0) { dpx[n] = dpx2[i]; dpy[n] = dpy2[i]; n++; } - if ((t0 >= 0) != (t1 >= 0)) - { - r = t0/(t0-t1); - dpx[n] = (dpx2[j]-dpx2[i])*r + dpx2[i]; - dpy[n] = (dpy2[j]-dpy2[i])*r + dpy2[i]; - n++; - } - } - if (n < 3) return; + t0 = t1; t1 = -((dpx2[j]-x1)*(fsy[0]-fsy[2]) - (dpy2[j]-fsy[2])*(x0-x1)); + if (t0 >= 0) { dpx[n] = dpx2[i]; dpy[n] = dpy2[i]; n++; } + if ((t0 >= 0) != (t1 >= 0)) + { + r = t0/(t0-t1); + dpx[n] = (dpx2[j]-dpx2[i])*r + dpx2[i]; + dpy[n] = (dpy2[j]-dpy2[i])*r + dpy2[i]; + n++; + } + } + if (n < 3) return; - drawpoly(dpx,dpy,n,method); + drawpoly(dpx,dpy,n,method); } void polymost_drawsprite (long snum) { - double px[6], py[6]; - float f, r, c, s, fx, fy, sx0, sy0, sx1, sy1, xp0, yp0, xp1, yp1, oxp0, oyp0, ryp0, ryp1, ft[4]; - float x0, y0, x1, y1, sc0, sf0, sc1, sf1, px2[6], py2[6], xv, yv, t0, t1; - long i, j, spritenum, xoff=0, yoff=0, method, npoints; - spritetype *tspr; + double px[6], py[6]; + float f, r, c, s, fx, fy, sx0, sy0, sx1, sy1, xp0, yp0, xp1, yp1, oxp0, oyp0, ryp0, ryp1, ft[4]; + float x0, y0, x1, y1, sc0, sf0, sc1, sf1, px2[6], py2[6], xv, yv, t0, t1; + long i, j, spritenum, xoff=0, yoff=0, method, npoints; + spritetype *tspr; - tspr = tspriteptr[snum]; - if (tspr->owner < 0 || tspr->picnum < 0) return; + tspr = tspriteptr[snum]; + if (tspr->owner < 0 || tspr->picnum < 0) return; - globalpicnum = tspr->picnum; - globalshade = tspr->shade; - globalpal = tspr->pal; - globalorientation = tspr->cstat; - spritenum = tspr->owner; + globalpicnum = tspr->picnum; + globalshade = tspr->shade; + globalpal = tspr->pal; + globalorientation = tspr->cstat; + spritenum = tspr->owner; - if ((globalorientation&48) != 48) { // only non-voxel sprites should do this - if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,spritenum+32768); + if ((globalorientation&48) != 48) { // only non-voxel sprites should do this + if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,spritenum+32768); - xoff = (long)((signed char)((picanm[globalpicnum]>>8)&255))+((long)tspr->xoffset); - yoff = (long)((signed char)((picanm[globalpicnum]>>16)&255))+((long)tspr->yoffset); - } + xoff = (long)((signed char)((picanm[globalpicnum]>>8)&255))+((long)tspr->xoffset); + yoff = (long)((signed char)((picanm[globalpicnum]>>16)&255))+((long)tspr->yoffset); + } - method = 1+4; - if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } + method = 1+4; +if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } #ifdef USE_OPENGL - if (!nofog && rendmode == 3) { - float col[4]; - col[0] = (float)palookupfog[sector[tspr->sectnum].floorpal].r / 63.f; - col[1] = (float)palookupfog[sector[tspr->sectnum].floorpal].g / 63.f; - col[2] = (float)palookupfog[sector[tspr->sectnum].floorpal].b / 63.f; - col[3] = 0; - bglFogfv(GL_FOG_COLOR,col); //default is 0,0,0,0 - bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sector[tspr->sectnum].visibility+16)))); - } + if (!nofog && rendmode == 3) { + float col[4]; + col[0] = (float)palookupfog[sector[tspr->sectnum].floorpal].r / 63.f; + col[1] = (float)palookupfog[sector[tspr->sectnum].floorpal].g / 63.f; + col[2] = (float)palookupfog[sector[tspr->sectnum].floorpal].b / 63.f; + col[3] = 0; + bglFogfv(GL_FOG_COLOR,col); //default is 0,0,0,0 + bglFogf(GL_FOG_DENSITY,gvisibility*((float)((unsigned char)(sector[tspr->sectnum].visibility+16)))); + } - while (rendmode == 3 && !(spriteext[tspr->owner].flags&SPREXT_NOTMD)) { - if (usemodels && tile2model[tspr->picnum].modelid >= 0 && tile2model[tspr->picnum].framenum >= 0) { - if (mddraw(tspr)) return; - break; // else, render as flat sprite - } - if (usevoxels && (tspr->cstat&48)!=48 && tiletovox[tspr->picnum] >= 0 && voxmodels[ tiletovox[tspr->picnum] ]) { - if (voxdraw(voxmodels[ tiletovox[tspr->picnum] ], tspr)) return; - break; // else, render as flat sprite - } - if ((tspr->cstat&48)==48 && voxmodels[ tspr->picnum ]) { - voxdraw(voxmodels[ tspr->picnum ], tspr); - return; - } - break; - } + while (rendmode == 3 && !(spriteext[tspr->owner].flags&SPREXT_NOTMD)) { + if (usemodels && tile2model[tspr->picnum].modelid >= 0 && tile2model[tspr->picnum].framenum >= 0) { + if (mddraw(tspr)) return; + break; // else, render as flat sprite + } + if (usevoxels && (tspr->cstat&48)!=48 && tiletovox[tspr->picnum] >= 0 && voxmodels[ tiletovox[tspr->picnum] ]) { + if (voxdraw(voxmodels[ tiletovox[tspr->picnum] ], tspr)) return; + break; // else, render as flat sprite + } + if ((tspr->cstat&48)==48 && voxmodels[ tspr->picnum ]) { + voxdraw(voxmodels[ tspr->picnum ], tspr); + return; + } + break; + } #endif - switch((globalorientation>>4)&3) - { - case 0: //Face sprite + switch((globalorientation>>4)&3) + { + case 0: //Face sprite - //Project 3D to 2D - sx0 = (float)(tspr->x-globalposx); - sy0 = (float)(tspr->y-globalposy); - xp0 = sy0*gcosang - sx0*gsinang; - yp0 = sx0*gcosang2 + sy0*gsinang2; - if (yp0 <= SCISDIST) return; - ryp0 = 1/yp0; - sx0 = ghalfx*xp0*ryp0 + ghalfx; - sy0 = ((float)(tspr->z-globalposz))*gyxscale*ryp0 + ghoriz; + //Project 3D to 2D + sx0 = (float)(tspr->x-globalposx); + sy0 = (float)(tspr->y-globalposy); + xp0 = sy0*gcosang - sx0*gsinang; + yp0 = sx0*gcosang2 + sy0*gsinang2; + if (yp0 <= SCISDIST) return; + ryp0 = 1/yp0; + sx0 = ghalfx*xp0*ryp0 + ghalfx; + sy0 = ((float)(tspr->z-globalposz))*gyxscale*ryp0 + ghoriz; - f = ryp0*(float)xdimen/160.0; - fx = ((float)tspr->xrepeat)*f; - fy = ((float)tspr->yrepeat)*f*((float)yxaspect/65536.0); - sx0 -= fx*(float)xoff; if (tilesizx[globalpicnum]&1) sx0 += fx*.5; - sy0 -= fy*(float)yoff; - fx *= ((float)tilesizx[globalpicnum]); - fy *= ((float)tilesizy[globalpicnum]); + f = ryp0*(float)xdimen/160.0; + fx = ((float)tspr->xrepeat)*f; + fy = ((float)tspr->yrepeat)*f*((float)yxaspect/65536.0); + sx0 -= fx*(float)xoff; if (tilesizx[globalpicnum]&1) sx0 += fx*.5; + sy0 -= fy*(float)yoff; + fx *= ((float)tilesizx[globalpicnum]); + fy *= ((float)tilesizy[globalpicnum]); - px[0] = px[3] = sx0-fx*.5; px[1] = px[2] = sx0+fx*.5; - if (!(globalorientation&128)) { py[0] = py[1] = sy0-fy; py[2] = py[3] = sy0; } - else { py[0] = py[1] = sy0-fy*.5; py[2] = py[3] = sy0+fy*.5; } + px[0] = px[3] = sx0-fx*.5; px[1] = px[2] = sx0+fx*.5; + if (!(globalorientation&128)) { py[0] = py[1] = sy0-fy; py[2] = py[3] = sy0; } + else { py[0] = py[1] = sy0-fy*.5; py[2] = py[3] = sy0+fy*.5; } - gdx = gdy = guy = gvx = 0; gdo = ryp0*gviewxrange; - if (!(globalorientation&4)) - { gux = (float)tilesizx[globalpicnum]*gdo/(px[1]-px[0]+.002); guo = -gux*(px[0]-.001); } - else { gux = (float)tilesizx[globalpicnum]*gdo/(px[0]-px[1]-.002); guo = -gux*(px[1]+.001); } - if (!(globalorientation&8)) - { gvy = (float)tilesizy[globalpicnum]*gdo/(py[3]-py[0]+.002); gvo = -gvy*(py[0]-.001); } - else { gvy = (float)tilesizy[globalpicnum]*gdo/(py[0]-py[3]-.002); gvo = -gvy*(py[3]+.001); } + gdx = gdy = guy = gvx = 0; gdo = ryp0*gviewxrange; + if (!(globalorientation&4)) + { gux = (float)tilesizx[globalpicnum]*gdo/(px[1]-px[0]+.002); guo = -gux*(px[0]-.001); } + else { gux = (float)tilesizx[globalpicnum]*gdo/(px[0]-px[1]-.002); guo = -gux*(px[1]+.001); } + if (!(globalorientation&8)) + { gvy = (float)tilesizy[globalpicnum]*gdo/(py[3]-py[0]+.002); gvo = -gvy*(py[0]-.001); } + else { gvy = (float)tilesizy[globalpicnum]*gdo/(py[0]-py[3]-.002); gvo = -gvy*(py[3]+.001); } - //Clip sprites to ceilings/floors when no parallaxing and not sloped - if (!(sector[tspr->sectnum].ceilingstat&3)) - { - sy0 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*gyxscale*ryp0 + ghoriz; - if (py[0] < sy0) py[0] = py[1] = sy0; - } - if (!(sector[tspr->sectnum].floorstat&3)) - { - sy0 = ((float)(sector[tspr->sectnum].floorz-globalposz))*gyxscale*ryp0 + ghoriz; - if (py[2] > sy0) py[2] = py[3] = sy0; - } + //Clip sprites to ceilings/floors when no parallaxing and not sloped + if (!(sector[tspr->sectnum].ceilingstat&3)) + { + sy0 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*gyxscale*ryp0 + ghoriz; + if (py[0] < sy0) py[0] = py[1] = sy0; + } + if (!(sector[tspr->sectnum].floorstat&3)) + { + sy0 = ((float)(sector[tspr->sectnum].floorz-globalposz))*gyxscale*ryp0 + ghoriz; + if (py[2] > sy0) py[2] = py[3] = sy0; + } - pow2xsplit = 0; drawpoly(px,py,4,method); - break; - case 1: //Wall sprite - - //Project 3D to 2D - if (globalorientation&4) xoff = -xoff; - if (globalorientation&8) yoff = -yoff; + pow2xsplit = 0; drawpoly(px,py,4,method); + break; + case 1: //Wall sprite - xv = (float)tspr->xrepeat * (float)sintable[(tspr->ang )&2047] / 65536.0; - yv = (float)tspr->xrepeat * (float)sintable[(tspr->ang+1536)&2047] / 65536.0; - f = (float)(tilesizx[globalpicnum]>>1) + (float)xoff; - x0 = (float)(tspr->x-globalposx) - xv*f; x1 = xv*(float)tilesizx[globalpicnum] + x0; - y0 = (float)(tspr->y-globalposy) - yv*f; y1 = yv*(float)tilesizx[globalpicnum] + y0; + //Project 3D to 2D + if (globalorientation&4) xoff = -xoff; + if (globalorientation&8) yoff = -yoff; - yp0 = x0*gcosang2 + y0*gsinang2; - yp1 = x1*gcosang2 + y1*gsinang2; - if ((yp0 <= SCISDIST) && (yp1 <= SCISDIST)) return; - xp0 = y0*gcosang - x0*gsinang; - xp1 = y1*gcosang - x1*gsinang; + xv = (float)tspr->xrepeat * (float)sintable[(tspr->ang )&2047] / 65536.0; + yv = (float)tspr->xrepeat * (float)sintable[(tspr->ang+1536)&2047] / 65536.0; + f = (float)(tilesizx[globalpicnum]>>1) + (float)xoff; + x0 = (float)(tspr->x-globalposx) - xv*f; x1 = xv*(float)tilesizx[globalpicnum] + x0; + y0 = (float)(tspr->y-globalposy) - yv*f; y1 = yv*(float)tilesizx[globalpicnum] + y0; - //Clip to close parallel-screen plane - oxp0 = xp0; oyp0 = yp0; - if (yp0 < SCISDIST) { t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; } - else { t0 = 0.f; } - if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; } - else { t1 = 1.f; } + yp0 = x0*gcosang2 + y0*gsinang2; + yp1 = x1*gcosang2 + y1*gsinang2; + if ((yp0 <= SCISDIST) && (yp1 <= SCISDIST)) return; + xp0 = y0*gcosang - x0*gsinang; + xp1 = y1*gcosang - x1*gsinang; - f = ((float)tspr->yrepeat) * (float)tilesizy[globalpicnum] * 4; + //Clip to close parallel-screen plane + oxp0 = xp0; oyp0 = yp0; + if (yp0 < SCISDIST) { t0 = (SCISDIST-yp0)/(yp1-yp0); xp0 = (xp1-xp0)*t0+xp0; yp0 = SCISDIST; } + else { t0 = 0.f; } + if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; yp1 = SCISDIST; } + else { t1 = 1.f; } - ryp0 = 1.0/yp0; - ryp1 = 1.0/yp1; - sx0 = ghalfx*xp0*ryp0 + ghalfx; - sx1 = ghalfx*xp1*ryp1 + ghalfx; - ryp0 *= gyxscale; - ryp1 *= gyxscale; + f = ((float)tspr->yrepeat) * (float)tilesizy[globalpicnum] * 4; - tspr->z -= ((yoff*tspr->yrepeat)<<2); - if (globalorientation&128) - { - tspr->z += ((tilesizy[globalpicnum]*tspr->yrepeat)<<1); - if (tilesizy[globalpicnum]&1) tspr->z += (tspr->yrepeat<<1); //Odd yspans - } + ryp0 = 1.0/yp0; + ryp1 = 1.0/yp1; + sx0 = ghalfx*xp0*ryp0 + ghalfx; + sx1 = ghalfx*xp1*ryp1 + ghalfx; + ryp0 *= gyxscale; + ryp1 *= gyxscale; - sc0 = ((float)(tspr->z-globalposz-f))*ryp0 + ghoriz; - sc1 = ((float)(tspr->z-globalposz-f))*ryp1 + ghoriz; - sf0 = ((float)(tspr->z-globalposz))*ryp0 + ghoriz; - sf1 = ((float)(tspr->z-globalposz))*ryp1 + ghoriz; + tspr->z -= ((yoff*tspr->yrepeat)<<2); + if (globalorientation&128) + { + tspr->z += ((tilesizy[globalpicnum]*tspr->yrepeat)<<1); + if (tilesizy[globalpicnum]&1) tspr->z += (tspr->yrepeat<<1); //Odd yspans + } - gdx = (ryp0-ryp1)*gxyaspect / (sx0-sx1); - gdy = 0; - gdo = ryp0*gxyaspect - gdx*sx0; + sc0 = ((float)(tspr->z-globalposz-f))*ryp0 + ghoriz; + sc1 = ((float)(tspr->z-globalposz-f))*ryp1 + ghoriz; + sf0 = ((float)(tspr->z-globalposz))*ryp0 + ghoriz; + sf1 = ((float)(tspr->z-globalposz))*ryp1 + ghoriz; - //Original equations: - //(gux*sx0 + guo)/(gdx*sx1 + gdo) = tilesizx[globalpicnum]*t0 - //(gux*sx1 + guo)/(gdx*sx1 + gdo) = tilesizx[globalpicnum]*t1 - // - // gvx*sx0 + gvy*sc0 + gvo = 0 - // gvy*sx1 + gvy*sc1 + gvo = 0 - //(gvx*sx0 + gvy*sf0 + gvo)/(gdx*sx0 + gdo) = tilesizy[globalpicnum] - //(gvx*sx1 + gvy*sf1 + gvo)/(gdx*sx1 + gdo) = tilesizy[globalpicnum] + gdx = (ryp0-ryp1)*gxyaspect / (sx0-sx1); + gdy = 0; + gdo = ryp0*gxyaspect - gdx*sx0; - //gux*sx0 + guo = t0*tilesizx[globalpicnum]*yp0 - //gux*sx1 + guo = t1*tilesizx[globalpicnum]*yp1 - if (globalorientation&4) { t0 = 1.f-t0; t1 = 1.f-t1; } - gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)tilesizx[globalpicnum] / (sx0-sx1); - guy = 0; - guo = t0*ryp0*gxyaspect*(float)tilesizx[globalpicnum] - gux*sx0; + //Original equations: + //(gux*sx0 + guo)/(gdx*sx1 + gdo) = tilesizx[globalpicnum]*t0 + //(gux*sx1 + guo)/(gdx*sx1 + gdo) = tilesizx[globalpicnum]*t1 + // + // gvx*sx0 + gvy*sc0 + gvo = 0 + // gvy*sx1 + gvy*sc1 + gvo = 0 + //(gvx*sx0 + gvy*sf0 + gvo)/(gdx*sx0 + gdo) = tilesizy[globalpicnum] + //(gvx*sx1 + gvy*sf1 + gvo)/(gdx*sx1 + gdo) = tilesizy[globalpicnum] - //gvx*sx0 + gvy*sc0 + gvo = 0 - //gvx*sx1 + gvy*sc1 + gvo = 0 - //gvx*sx0 + gvy*sf0 + gvo = tilesizy[globalpicnum]*(gdx*sx0 + gdo) - f = ((float)tilesizy[globalpicnum])*(gdx*sx0 + gdo) / ((sx0-sx1)*(sc0-sf0)); - if (!(globalorientation&8)) - { - gvx = (sc0-sc1)*f; - gvy = (sx1-sx0)*f; - gvo = -gvx*sx0 - gvy*sc0; - } - else - { - gvx = (sf1-sf0)*f; - gvy = (sx0-sx1)*f; - gvo = -gvx*sx0 - gvy*sf0; - } + //gux*sx0 + guo = t0*tilesizx[globalpicnum]*yp0 + //gux*sx1 + guo = t1*tilesizx[globalpicnum]*yp1 + if (globalorientation&4) { t0 = 1.f-t0; t1 = 1.f-t1; } + gux = (t0*ryp0 - t1*ryp1)*gxyaspect*(float)tilesizx[globalpicnum] / (sx0-sx1); + guy = 0; + guo = t0*ryp0*gxyaspect*(float)tilesizx[globalpicnum] - gux*sx0; - //Clip sprites to ceilings/floors when no parallaxing - if (!(sector[tspr->sectnum].ceilingstat&1)) - { - f = ((float)tspr->yrepeat) * (float)tilesizy[globalpicnum] * 4; - if (sector[tspr->sectnum].ceilingz > tspr->z-f) - { - sc0 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*ryp0 + ghoriz; - sc1 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*ryp1 + ghoriz; - } - } - if (!(sector[tspr->sectnum].floorstat&1)) - { - if (sector[tspr->sectnum].floorz < tspr->z) - { - sf0 = ((float)(sector[tspr->sectnum].floorz-globalposz))*ryp0 + ghoriz; - sf1 = ((float)(sector[tspr->sectnum].floorz-globalposz))*ryp1 + ghoriz; - } - } - - if (sx0 > sx1) - { - if (globalorientation&64) return; //1-sided sprite - f = sx0; sx0 = sx1; sx1 = f; - f = sc0; sc0 = sc1; sc1 = f; - f = sf0; sf0 = sf1; sf1 = f; - } + //gvx*sx0 + gvy*sc0 + gvo = 0 + //gvx*sx1 + gvy*sc1 + gvo = 0 + //gvx*sx0 + gvy*sf0 + gvo = tilesizy[globalpicnum]*(gdx*sx0 + gdo) + f = ((float)tilesizy[globalpicnum])*(gdx*sx0 + gdo) / ((sx0-sx1)*(sc0-sf0)); + if (!(globalorientation&8)) + { + gvx = (sc0-sc1)*f; + gvy = (sx1-sx0)*f; + gvo = -gvx*sx0 - gvy*sc0; + } + else + { + gvx = (sf1-sf0)*f; + gvy = (sx0-sx1)*f; + gvo = -gvx*sx0 - gvy*sf0; + } - px[0] = sx0; py[0] = sc0; - px[1] = sx1; py[1] = sc1; - px[2] = sx1; py[2] = sf1; - px[3] = sx0; py[3] = sf0; - pow2xsplit = 0; drawpoly(px,py,4,method); - break; - case 2: //Floor sprite - - if ((globalorientation&64) != 0) - if ((globalposz > tspr->z) == (!(globalorientation&8))) - return; - if ((globalorientation&4) > 0) xoff = -xoff; - if ((globalorientation&8) > 0) yoff = -yoff; + //Clip sprites to ceilings/floors when no parallaxing + if (!(sector[tspr->sectnum].ceilingstat&1)) + { + f = ((float)tspr->yrepeat) * (float)tilesizy[globalpicnum] * 4; + if (sector[tspr->sectnum].ceilingz > tspr->z-f) + { + sc0 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*ryp0 + ghoriz; + sc1 = ((float)(sector[tspr->sectnum].ceilingz-globalposz))*ryp1 + ghoriz; + } + } + if (!(sector[tspr->sectnum].floorstat&1)) + { + if (sector[tspr->sectnum].floorz < tspr->z) + { + sf0 = ((float)(sector[tspr->sectnum].floorz-globalposz))*ryp0 + ghoriz; + sf1 = ((float)(sector[tspr->sectnum].floorz-globalposz))*ryp1 + ghoriz; + } + } - i = (tspr->ang&2047); - c = sintable[(i+512)&2047]/65536.0; - s = sintable[i]/65536.0; - x0 = ((tilesizx[globalpicnum]>>1)-xoff)*tspr->xrepeat; - y0 = ((tilesizy[globalpicnum]>>1)-yoff)*tspr->yrepeat; - x1 = ((tilesizx[globalpicnum]>>1)+xoff)*tspr->xrepeat; - y1 = ((tilesizy[globalpicnum]>>1)+yoff)*tspr->yrepeat; + if (sx0 > sx1) + { + if (globalorientation&64) return; //1-sided sprite + f = sx0; sx0 = sx1; sx1 = f; + f = sc0; sc0 = sc1; sc1 = f; + f = sf0; sf0 = sf1; sf1 = f; + } - //Project 3D to 2D - for(j=0;j<4;j++) - { - sx0 = (float)(tspr->x-globalposx); - sy0 = (float)(tspr->y-globalposy); - if ((j+0)&2) { sy0 -= s*y0; sx0 -= c*y0; } else { sy0 += s*y1; sx0 += c*y1; } - if ((j+1)&2) { sx0 -= s*x0; sy0 += c*x0; } else { sx0 += s*x1; sy0 -= c*x1; } - px[j] = sy0*gcosang - sx0*gsinang; - py[j] = sx0*gcosang2 + sy0*gsinang2; - } + px[0] = sx0; py[0] = sc0; + px[1] = sx1; py[1] = sc1; + px[2] = sx1; py[2] = sf1; + px[3] = sx0; py[3] = sf0; + pow2xsplit = 0; drawpoly(px,py,4,method); + break; + case 2: //Floor sprite - if (tspr->z < globalposz) //if floor sprite is above you, reverse order of points - { - f = px[0]; px[0] = px[1]; px[1] = f; - f = py[0]; py[0] = py[1]; py[1] = f; - f = px[2]; px[2] = px[3]; px[3] = f; - f = py[2]; py[2] = py[3]; py[3] = f; - } + if ((globalorientation&64) != 0) + if ((globalposz > tspr->z) == (!(globalorientation&8))) + return; + if ((globalorientation&4) > 0) xoff = -xoff; + if ((globalorientation&8) > 0) yoff = -yoff; - //Clip to SCISDIST plane - npoints = 0; - for(i=0;i<4;i++) - { - j = ((i+1)&3); - if (py[i] >= SCISDIST) { px2[npoints] = px[i]; py2[npoints] = py[i]; npoints++; } - if ((py[i] >= SCISDIST) != (py[j] >= SCISDIST)) - { - f = (SCISDIST-py[i])/(py[j]-py[i]); - px2[npoints] = (px[j]-px[i])*f + px[i]; - py2[npoints] = (py[j]-py[i])*f + py[i]; npoints++; - } - } - if (npoints < 3) return; + i = (tspr->ang&2047); + c = sintable[(i+512)&2047]/65536.0; + s = sintable[i]/65536.0; + x0 = ((tilesizx[globalpicnum]>>1)-xoff)*tspr->xrepeat; + y0 = ((tilesizy[globalpicnum]>>1)-yoff)*tspr->yrepeat; + x1 = ((tilesizx[globalpicnum]>>1)+xoff)*tspr->xrepeat; + y1 = ((tilesizy[globalpicnum]>>1)+yoff)*tspr->yrepeat; - //Project rotated 3D points to screen - f = ((float)(tspr->z-globalposz))*gyxscale; - for(j=0;jx-globalposx); + sy0 = (float)(tspr->y-globalposy); + if ((j+0)&2) { sy0 -= s*y0; sx0 -= c*y0; } else { sy0 += s*y1; sx0 += c*y1; } + if ((j+1)&2) { sx0 -= s*x0; sy0 += c*x0; } else { sx0 += s*x1; sy0 -= c*x1; } + px[j] = sy0*gcosang - sx0*gsinang; + py[j] = sx0*gcosang2 + sy0*gsinang2; + } - //gd? Copied from floor rendering code - gdx = 0; - gdy = gxyaspect / (double)(tspr->z-globalposz); - gdo = -ghoriz*gdy; - //copied&modified from relative alignment - xv = (float)tspr->x + s*x1 + c*y1; fx = (double)-(x0+x1)*s; - yv = (float)tspr->y + s*y1 - c*x1; fy = (double)+(x0+x1)*c; - f = 1.0/sqrt(fx*fx+fy*fy); fx *= f; fy *= f; - ft[2] = singlobalang*fy + cosglobalang*fx; - ft[3] = singlobalang*fx - cosglobalang*fy; - ft[0] = ((double)(globalposy-yv))*fy + ((double)(globalposx-xv))*fx; - ft[1] = ((double)(globalposx-xv))*fy - ((double)(globalposy-yv))*fx; - gux = (double)ft[3]*((double)viewingrange)/(-65536.0*262144.0); - gvx = (double)ft[2]*((double)viewingrange)/(-65536.0*262144.0); - guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; - guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; - guo += (double)(ft[2]/262144.0-gux)*ghalfx; - gvo -= (double)(ft[3]/262144.0+gvx)*ghalfx; - f = 4.0/(float)tspr->xrepeat; gux *= f; guy *= f; guo *= f; - f =-4.0/(float)tspr->yrepeat; gvx *= f; gvy *= f; gvo *= f; - if (globalorientation&4) - { - gux = ((float)tilesizx[globalpicnum])*gdx - gux; - guy = ((float)tilesizx[globalpicnum])*gdy - guy; - guo = ((float)tilesizx[globalpicnum])*gdo - guo; - } + if (tspr->z < globalposz) //if floor sprite is above you, reverse order of points + { + f = px[0]; px[0] = px[1]; px[1] = f; + f = py[0]; py[0] = py[1]; py[1] = f; + f = px[2]; px[2] = px[3]; px[3] = f; + f = py[2]; py[2] = py[3]; py[3] = f; + } - pow2xsplit = 0; drawpoly(px,py,npoints,method); - break; + //Clip to SCISDIST plane + npoints = 0; + for(i=0;i<4;i++) + { + j = ((i+1)&3); + if (py[i] >= SCISDIST) { px2[npoints] = px[i]; py2[npoints] = py[i]; npoints++; } + if ((py[i] >= SCISDIST) != (py[j] >= SCISDIST)) + { + f = (SCISDIST-py[i])/(py[j]-py[i]); + px2[npoints] = (px[j]-px[i])*f + px[i]; + py2[npoints] = (py[j]-py[i])*f + py[i]; npoints++; + } + } + if (npoints < 3) return; - case 3: //Voxel sprite - break; - } + //Project rotated 3D points to screen + f = ((float)(tspr->z-globalposz))*gyxscale; + for(j=0;jz-globalposz); + gdo = -ghoriz*gdy; + //copied&modified from relative alignment + xv = (float)tspr->x + s*x1 + c*y1; fx = (double)-(x0+x1)*s; + yv = (float)tspr->y + s*y1 - c*x1; fy = (double)+(x0+x1)*c; + f = 1.0/sqrt(fx*fx+fy*fy); fx *= f; fy *= f; + ft[2] = singlobalang*fy + cosglobalang*fx; + ft[3] = singlobalang*fx - cosglobalang*fy; + ft[0] = ((double)(globalposy-yv))*fy + ((double)(globalposx-xv))*fx; + ft[1] = ((double)(globalposx-xv))*fy - ((double)(globalposy-yv))*fx; + gux = (double)ft[3]*((double)viewingrange)/(-65536.0*262144.0); + gvx = (double)ft[2]*((double)viewingrange)/(-65536.0*262144.0); + guy = (double)ft[0]*gdy; gvy = (double)ft[1]*gdy; + guo = (double)ft[0]*gdo; gvo = (double)ft[1]*gdo; + guo += (double)(ft[2]/262144.0-gux)*ghalfx; + gvo -= (double)(ft[3]/262144.0+gvx)*ghalfx; + f = 4.0/(float)tspr->xrepeat; gux *= f; guy *= f; guo *= f; + f =-4.0/(float)tspr->yrepeat; gvx *= f; gvy *= f; gvo *= f; + if (globalorientation&4) + { + gux = ((float)tilesizx[globalpicnum])*gdx - gux; + guy = ((float)tilesizx[globalpicnum])*gdy - guy; + guo = ((float)tilesizx[globalpicnum])*gdo - guo; + } + + pow2xsplit = 0; drawpoly(px,py,npoints,method); + break; + + case 3: //Voxel sprite + break; + } } - //sx,sy center of sprite; screen coods*65536 - //z zoom*65536. > is zoomed in - //a angle (0 is default) - //dastat&1 1:translucence - //dastat&2 1:auto-scale mode (use 320*200 coordinates) - //dastat&4 1:y-flip - //dastat&8 1:don't clip to startumost/startdmost - //dastat&16 1:force point passed to be top-left corner, 0:Editart center - //dastat&32 1:reverse translucence - //dastat&64 1:non-masked, 0:masked - //dastat&128 1:draw all pages (permanent) - //cx1,... clip window (actual screen coords) +//sx,sy center of sprite; screen coods*65536 +//z zoom*65536. > is zoomed in +//a angle (0 is default) +//dastat&1 1:translucence +//dastat&2 1:auto-scale mode (use 320*200 coordinates) +//dastat&4 1:y-flip +//dastat&8 1:don't clip to startumost/startdmost +//dastat&16 1:force point passed to be top-left corner, 0:Editart center +//dastat&32 1:reverse translucence +//dastat&64 1:non-masked, 0:masked +//dastat&128 1:draw all pages (permanent) +//cx1,... clip window (actual screen coords) void polymost_dorotatesprite (long sx, long sy, long z, short a, short picnum, - signed char dashade, char dapalnum, char dastat, long cx1, long cy1, long cx2, long cy2, long uniqid) + signed char dashade, char dapalnum, char dastat, long cx1, long cy1, long cx2, long cy2, long uniqid) { - static long onumframes = 0; - long i, n, nn, x, zz, xoff, yoff, xsiz, ysiz, method; - long ogpicnum, ogshade, ogpal, ofoffset, oxdimen, oydimen, oldviewingrange; - double ogxyaspect; - double ogchang, ogshang, ogctang, ogstang, oghalfx, oghoriz, fx, fy, x1, y1, z1, x2, y2; - double ogrhalfxdown10, ogrhalfxdown10x; - double d, cosang, sinang, cosang2, sinang2, px[8], py[8], px2[8], py2[8]; - float m[4][4]; + static long onumframes = 0; + long i, n, nn, x, zz, xoff, yoff, xsiz, ysiz, method; + long ogpicnum, ogshade, ogpal, ofoffset, oxdimen, oydimen, oldviewingrange; + double ogxyaspect; + double ogchang, ogshang, ogctang, ogstang, oghalfx, oghoriz, fx, fy, x1, y1, z1, x2, y2; + double ogrhalfxdown10, ogrhalfxdown10x; + double d, cosang, sinang, cosang2, sinang2, px[8], py[8], px2[8], py2[8]; + float m[4][4]; float ratioratio = 1.0; int fovcorrect; #ifdef USE_OPENGL - if (rendmode == 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) - { - if ((tile2model[picnum].modelid >= 0) && (tile2model[picnum].framenum >= 0)) - { - spritetype tspr; - memset(&tspr,0,sizeof(spritetype)); + if (rendmode == 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) + { + if ((tile2model[picnum].modelid >= 0) && (tile2model[picnum].framenum >= 0)) + { + spritetype tspr; + memset(&tspr,0,sizeof(spritetype)); - if (hudmem[(dastat&4)>>2][picnum].flags&1) return; //"HIDE" is specified in DEF + if (hudmem[(dastat&4)>>2][picnum].flags&1) return; //"HIDE" is specified in DEF - ogchang = gchang; gchang = 1.0; - ogshang = gshang; gshang = 0.0; d = (double)z/(65536.0*16384.0); - ogctang = gctang; gctang = (double)sintable[(a+512)&2047]*d; - ogstang = gstang; gstang = (double)sintable[a&2047]*d; - ogshade = globalshade; globalshade = dashade; - ogpal = globalpal; globalpal = (long)((unsigned char)dapalnum); - ogxyaspect = gxyaspect; gxyaspect = 1.0; - oldviewingrange = viewingrange; viewingrange = 65536; + ogchang = gchang; gchang = 1.0; + ogshang = gshang; gshang = 0.0; d = (double)z/(65536.0*16384.0); + ogctang = gctang; gctang = (double)sintable[(a+512)&2047]*d; + ogstang = gstang; gstang = (double)sintable[a&2047]*d; + ogshade = globalshade; globalshade = dashade; + ogpal = globalpal; globalpal = (long)((unsigned char)dapalnum); + ogxyaspect = gxyaspect; gxyaspect = 1.0; + oldviewingrange = viewingrange; viewingrange = 65536; - x1 = hudmem[(dastat&4)>>2][picnum].xadd; - y1 = hudmem[(dastat&4)>>2][picnum].yadd; - z1 = hudmem[(dastat&4)>>2][picnum].zadd; - if (!(hudmem[(dastat&4)>>2][picnum].flags&2)) //"NOBOB" is specified in DEF - { - fx = ((double)sx)*(1.0/65536.0); - fy = ((double)sy)*(1.0/65536.0); + x1 = hudmem[(dastat&4)>>2][picnum].xadd; + y1 = hudmem[(dastat&4)>>2][picnum].yadd; + z1 = hudmem[(dastat&4)>>2][picnum].zadd; + if (!(hudmem[(dastat&4)>>2][picnum].flags&2)) //"NOBOB" is specified in DEF + { + fx = ((double)sx)*(1.0/65536.0); + fy = ((double)sy)*(1.0/65536.0); - if (dastat&16) - { - xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum]; - xoff = (long)((signed char)((picanm[picnum]>>8)&255))+(xsiz>>1); - yoff = (long)((signed char)((picanm[picnum]>>16)&255))+(ysiz>>1); + if (dastat&16) + { + xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum]; + xoff = (long)((signed char)((picanm[picnum]>>8)&255))+(xsiz>>1); + yoff = (long)((signed char)((picanm[picnum]>>16)&255))+(ysiz>>1); - d = (double)z/(65536.0*16384.0); - cosang2 = cosang = (double)sintable[(a+512)&2047]*d; - sinang2 = sinang = (double)sintable[a&2047]*d; - if ((dastat&2) || (!(dastat&8))) //Don't aspect unscaled perms - { d = (double)xyaspect/65536.0; cosang2 *= d; sinang2 *= d; } - fx += -(double)xoff*cosang2+ (double)yoff*sinang2; - fy += -(double)xoff*sinang - (double)yoff*cosang; - } + d = (double)z/(65536.0*16384.0); + cosang2 = cosang = (double)sintable[(a+512)&2047]*d; + sinang2 = sinang = (double)sintable[a&2047]*d; + if ((dastat&2) || (!(dastat&8))) //Don't aspect unscaled perms + { d = (double)xyaspect/65536.0; cosang2 *= d; sinang2 *= d; } + fx += -(double)xoff*cosang2+ (double)yoff*sinang2; + fy += -(double)xoff*sinang - (double)yoff*cosang; + } - if (!(dastat&2)) - { - x1 += fx/((double)(xdim<<15))-1.0; //-1: left of screen, +1: right of screen - y1 += fy/((double)(ydim<<15))-1.0; //-1: top of screen, +1: bottom of screen - } - else - { - x1 += fx/160.0-1.0; //-1: left of screen, +1: right of screen - y1 += fy/100.0-1.0; //-1: top of screen, +1: bottom of screen - } - } - tspr.ang = hudmem[(dastat&4)>>2][picnum].angadd+globalang; - tspr.xrepeat = tspr.yrepeat = 32; + if (!(dastat&2)) + { + x1 += fx/((double)(xdim<<15))-1.0; //-1: left of screen, +1: right of screen + y1 += fy/((double)(ydim<<15))-1.0; //-1: top of screen, +1: bottom of screen + } + else + { + x1 += fx/160.0-1.0; //-1: left of screen, +1: right of screen + y1 += fy/100.0-1.0; //-1: top of screen, +1: bottom of screen + } + } + tspr.ang = hudmem[(dastat&4)>>2][picnum].angadd+globalang; + tspr.xrepeat = tspr.yrepeat = 32; - if (dastat&4) { x1 = -x1; y1 = -y1; } - tspr.x = (long)(((double)gcosang*z1 - (double)gsinang*x1)*16384.0 + globalposx); - tspr.y = (long)(((double)gsinang*z1 + (double)gcosang*x1)*16384.0 + globalposy); - tspr.z = (long)(globalposz + y1*16384.0*0.8); - tspr.picnum = picnum; - tspr.shade = dashade; - tspr.pal = dapalnum; - tspr.owner = uniqid+MAXSPRITES; - globalorientation = (dastat&1)+((dastat&32)<<4)+((dastat&4)<<1); + if (dastat&4) { x1 = -x1; y1 = -y1; } + tspr.x = (long)(((double)gcosang*z1 - (double)gsinang*x1)*16384.0 + globalposx); + tspr.y = (long)(((double)gsinang*z1 + (double)gcosang*x1)*16384.0 + globalposy); + tspr.z = (long)(globalposz + y1*16384.0*0.8); + tspr.picnum = picnum; + tspr.shade = dashade; + tspr.pal = dapalnum; + tspr.owner = uniqid+MAXSPRITES; + globalorientation = (dastat&1)+((dastat&32)<<4)+((dastat&4)<<1); - if ((dastat&10) == 2) - { - ratioratio = 1.6 / (((float)(windowx2-windowx1+1)) / (windowy2-windowy1)); // computes the ratio between 16/10 and current resolution ratio - fovcorrect = (ratioratio > 1) ? (((windowx2-windowx1+1) * ratioratio) - windowx2-windowx1+1) * ((float)glratiocorrection / 63) * 2 : 0; - bglViewport(windowx1 - (fovcorrect / 2),yres-(windowy2+1),windowx2-windowx1+1 + fovcorrect,windowy2-windowy1+1); - } - else - { - bglViewport(0,0,xdim,ydim); - glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) - } + if ((dastat&10) == 2) + { + ratioratio = 1.6 / (((float)(windowx2-windowx1+1)) / (windowy2-windowy1)); // computes the ratio between 16/10 and current resolution ratio + fovcorrect = (ratioratio > 1) ? (((windowx2-windowx1+1) * ratioratio) - windowx2-windowx1+1) * ((float)glratiocorrection / 63) * 2 : 0; + bglViewport(windowx1 - (fovcorrect / 2),yres-(windowy2+1),windowx2-windowx1+1 + fovcorrect,windowy2-windowy1+1); + } + else + { + bglViewport(0,0,xdim,ydim); + glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) + } - bglMatrixMode(GL_PROJECTION); - memset(m,0,sizeof(m)); - if ((dastat&10) == 2) - { - m[0][0] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); m[0][2] = 1.0; - m[1][1] = (float)xdimen; m[1][2] = 1.0; - m[2][2] = 1.0; m[2][3] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); - m[3][2] =-1.0; - } - else { m[0][0] = m[2][3] = 1.0; m[1][1] = ((float)xdim)/((float)ydim); m[2][2] = 1.0001; m[3][2] = 1-m[2][2]; } - bglLoadMatrixf(&m[0][0]); - bglMatrixMode(GL_MODELVIEW); - bglLoadIdentity(); + bglMatrixMode(GL_PROJECTION); + memset(m,0,sizeof(m)); + if ((dastat&10) == 2) + { + m[0][0] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); m[0][2] = 1.0; + m[1][1] = (float)xdimen; m[1][2] = 1.0; + m[2][2] = 1.0; m[2][3] = (float)ydimen / (1 + (glratiocorrection / (63 / (ratioratio - 1)))); + m[3][2] =-1.0; + } + else { m[0][0] = m[2][3] = 1.0; m[1][1] = ((float)xdim)/((float)ydim); m[2][2] = 1.0001; m[3][2] = 1-m[2][2]; } + bglLoadMatrixf(&m[0][0]); + bglMatrixMode(GL_MODELVIEW); + bglLoadIdentity(); - if (hudmem[(dastat&4)>>2][picnum].flags&8) //NODEPTH flag - bglDisable(GL_DEPTH_TEST); - else - { - bglEnable(GL_DEPTH_TEST); - if (onumframes != numframes) - { - onumframes = numframes; - bglClear(GL_DEPTH_BUFFER_BIT); - } - } + if (hudmem[(dastat&4)>>2][picnum].flags&8) //NODEPTH flag + bglDisable(GL_DEPTH_TEST); + else + { + bglEnable(GL_DEPTH_TEST); + if (onumframes != numframes) + { + onumframes = numframes; + bglClear(GL_DEPTH_BUFFER_BIT); + } + } - mddraw(&tspr); + mddraw(&tspr); - viewingrange = oldviewingrange; - gxyaspect = ogxyaspect; - globalshade = ogshade; - globalpal = ogpal; - gchang = ogchang; - gshang = ogshang; - gctang = ogctang; - gstang = ogstang; - return; - } - } + viewingrange = oldviewingrange; + gxyaspect = ogxyaspect; + globalshade = ogshade; + globalpal = ogpal; + gchang = ogchang; + gshang = ogshang; + gctang = ogctang; + gstang = ogstang; + return; + } + } #endif - ogpicnum = globalpicnum; globalpicnum = picnum; - ogshade = globalshade; globalshade = dashade; - ogpal = globalpal; globalpal = (long)((unsigned char)dapalnum); - oghalfx = ghalfx; ghalfx = (double)(xdim>>1); - ogrhalfxdown10 = grhalfxdown10; grhalfxdown10 = 1.0/(((double)ghalfx)*1024); - ogrhalfxdown10x = grhalfxdown10x; grhalfxdown10x = grhalfxdown10; - oghoriz = ghoriz; ghoriz = (double)(ydim>>1); - ofoffset = frameoffset; frameoffset = frameplace; - oxdimen = xdimen; xdimen = xdim; - oydimen = ydimen; ydimen = ydim; - ogchang = gchang; gchang = 1.0; - ogshang = gshang; gshang = 0.0; - ogctang = gctang; gctang = 1.0; - ogstang = gstang; gstang = 0.0; + ogpicnum = globalpicnum; globalpicnum = picnum; + ogshade = globalshade; globalshade = dashade; + ogpal = globalpal; globalpal = (long)((unsigned char)dapalnum); + oghalfx = ghalfx; ghalfx = (double)(xdim>>1); + ogrhalfxdown10 = grhalfxdown10; grhalfxdown10 = 1.0/(((double)ghalfx)*1024); + ogrhalfxdown10x = grhalfxdown10x; grhalfxdown10x = grhalfxdown10; + oghoriz = ghoriz; ghoriz = (double)(ydim>>1); + ofoffset = frameoffset; frameoffset = frameplace; + oxdimen = xdimen; xdimen = xdim; + oydimen = ydimen; ydimen = ydim; + ogchang = gchang; gchang = 1.0; + ogshang = gshang; gshang = 0.0; + ogctang = gctang; gctang = 1.0; + ogstang = gstang; gstang = 0.0; #ifdef USE_OPENGL - if (rendmode == 3) - { - bglViewport(0,0,xdim,ydim); glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) - bglMatrixMode(GL_PROJECTION); - memset(m,0,sizeof(m)); - m[0][0] = m[2][3] = 1.0; m[1][1] = ((float)xdim)/((float)ydim); m[2][2] = 1.0001; m[3][2] = 1-m[2][2]; - bglPushMatrix(); bglLoadMatrixf(&m[0][0]); - bglMatrixMode(GL_MODELVIEW); - bglLoadIdentity(); + if (rendmode == 3) + { + bglViewport(0,0,xdim,ydim); glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) + bglMatrixMode(GL_PROJECTION); + memset(m,0,sizeof(m)); + m[0][0] = m[2][3] = 1.0; m[1][1] = ((float)xdim)/((float)ydim); m[2][2] = 1.0001; m[3][2] = 1-m[2][2]; + bglPushMatrix(); bglLoadMatrixf(&m[0][0]); + bglMatrixMode(GL_MODELVIEW); + bglLoadIdentity(); - bglDisable(GL_DEPTH_TEST); - bglDisable(GL_ALPHA_TEST); - bglEnable(GL_TEXTURE_2D); - } + bglDisable(GL_DEPTH_TEST); + bglDisable(GL_ALPHA_TEST); + bglEnable(GL_TEXTURE_2D); + } #endif - method = 0; - if (!(dastat&64)) - { - method = 1; - if (dastat&1) { if (!(dastat&32)) method = 2; else method = 3; } - } - method |= 4; //Use OpenGL clamping - dorotatesprite never repeats + method = 0; + if (!(dastat&64)) + { + method = 1; + if (dastat&1) { if (!(dastat&32)) method = 2; else method = 3; } + } + method |= 4; //Use OpenGL clamping - dorotatesprite never repeats - xsiz = tilesizx[globalpicnum]; ysiz = tilesizy[globalpicnum]; - if (dastat&16) { xoff = 0; yoff = 0; } - else - { - xoff = (long)((signed char)((picanm[globalpicnum]>>8)&255))+(xsiz>>1); - yoff = (long)((signed char)((picanm[globalpicnum]>>16)&255))+(ysiz>>1); - } - if (dastat&4) yoff = ysiz-yoff; + xsiz = tilesizx[globalpicnum]; ysiz = tilesizy[globalpicnum]; +if (dastat&16) { xoff = 0; yoff = 0; } + else + { + xoff = (long)((signed char)((picanm[globalpicnum]>>8)&255))+(xsiz>>1); + yoff = (long)((signed char)((picanm[globalpicnum]>>16)&255))+(ysiz>>1); + } + if (dastat&4) yoff = ysiz-yoff; - if (dastat&2) //Auto window size scaling - { - if (!(dastat&8)) - { - x = xdimenscale; //= scale(xdimen,yxaspect,320); - sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),oxdimen,320); - sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x); - } - else - { - //If not clipping to startmosts, & auto-scaling on, as a - //hard-coded bonus, scale to full screen instead - x = scale(xdim,yxaspect,320); - sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); - sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); - } - z = mulscale16(z,x); - } + if (dastat&2) //Auto window size scaling + { + if (!(dastat&8)) + { + x = xdimenscale; //= scale(xdimen,yxaspect,320); + sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),oxdimen,320); + sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x); + } + else + { + //If not clipping to startmosts, & auto-scaling on, as a + //hard-coded bonus, scale to full screen instead + x = scale(xdim,yxaspect,320); + sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); + sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); + } + z = mulscale16(z,x); + } - d = (double)z/(65536.0*16384.0); - cosang2 = cosang = (double)sintable[(a+512)&2047]*d; - sinang2 = sinang = (double)sintable[a&2047]*d; - if ((dastat&2) || (!(dastat&8))) //Don't aspect unscaled perms - { d = (double)xyaspect/65536.0; cosang2 *= d; sinang2 *= d; } - px[0] = (double)sx/65536.0 - (double)xoff*cosang2+ (double)yoff*sinang2; - py[0] = (double)sy/65536.0 - (double)xoff*sinang - (double)yoff*cosang; - px[1] = px[0] + (double)xsiz*cosang2; - py[1] = py[0] + (double)xsiz*sinang; - px[3] = px[0] - (double)ysiz*sinang2; - py[3] = py[0] + (double)ysiz*cosang; - px[2] = px[1]+px[3]-px[0]; - py[2] = py[1]+py[3]-py[0]; - n = 4; + d = (double)z/(65536.0*16384.0); + cosang2 = cosang = (double)sintable[(a+512)&2047]*d; + sinang2 = sinang = (double)sintable[a&2047]*d; + if ((dastat&2) || (!(dastat&8))) //Don't aspect unscaled perms + { d = (double)xyaspect/65536.0; cosang2 *= d; sinang2 *= d; } + px[0] = (double)sx/65536.0 - (double)xoff*cosang2+ (double)yoff*sinang2; + py[0] = (double)sy/65536.0 - (double)xoff*sinang - (double)yoff*cosang; + px[1] = px[0] + (double)xsiz*cosang2; + py[1] = py[0] + (double)xsiz*sinang; + px[3] = px[0] - (double)ysiz*sinang2; + py[3] = py[0] + (double)ysiz*cosang; + px[2] = px[1]+px[3]-px[0]; + py[2] = py[1]+py[3]-py[0]; + n = 4; - gdx = 0; gdy = 0; gdo = 1.0; - //px[0]*gux + py[0]*guy + guo = 0 - //px[1]*gux + py[1]*guy + guo = xsiz-.0001 - //px[3]*gux + py[3]*guy + guo = 0 - d = 1.0/(px[0]*(py[1]-py[3]) + px[1]*(py[3]-py[0]) + px[3]*(py[0]-py[1])); - gux = (py[3]-py[0])*((double)xsiz-.0001)*d; - guy = (px[0]-px[3])*((double)xsiz-.0001)*d; - guo = 0 - px[0]*gux - py[0]*guy; + gdx = 0; gdy = 0; gdo = 1.0; + //px[0]*gux + py[0]*guy + guo = 0 + //px[1]*gux + py[1]*guy + guo = xsiz-.0001 + //px[3]*gux + py[3]*guy + guo = 0 + d = 1.0/(px[0]*(py[1]-py[3]) + px[1]*(py[3]-py[0]) + px[3]*(py[0]-py[1])); + gux = (py[3]-py[0])*((double)xsiz-.0001)*d; + guy = (px[0]-px[3])*((double)xsiz-.0001)*d; + guo = 0 - px[0]*gux - py[0]*guy; - if (!(dastat&4)) - { //px[0]*gvx + py[0]*gvy + gvo = 0 - //px[1]*gvx + py[1]*gvy + gvo = 0 - //px[3]*gvx + py[3]*gvy + gvo = ysiz-.0001 - gvx = (py[0]-py[1])*((double)ysiz-.0001)*d; - gvy = (px[1]-px[0])*((double)ysiz-.0001)*d; - gvo = 0 - px[0]*gvx - py[0]*gvy; - } - else - { //px[0]*gvx + py[0]*gvy + gvo = ysiz-.0001 - //px[1]*gvx + py[1]*gvy + gvo = ysiz-.0001 - //px[3]*gvx + py[3]*gvy + gvo = 0 - gvx = (py[1]-py[0])*((double)ysiz-.0001)*d; - gvy = (px[0]-px[1])*((double)ysiz-.0001)*d; - gvo = (double)ysiz-.0001 - px[0]*gvx - py[0]*gvy; - } + if (!(dastat&4)) + { //px[0]*gvx + py[0]*gvy + gvo = 0 + //px[1]*gvx + py[1]*gvy + gvo = 0 + //px[3]*gvx + py[3]*gvy + gvo = ysiz-.0001 + gvx = (py[0]-py[1])*((double)ysiz-.0001)*d; + gvy = (px[1]-px[0])*((double)ysiz-.0001)*d; + gvo = 0 - px[0]*gvx - py[0]*gvy; + } + else + { //px[0]*gvx + py[0]*gvy + gvo = ysiz-.0001 + //px[1]*gvx + py[1]*gvy + gvo = ysiz-.0001 + //px[3]*gvx + py[3]*gvy + gvo = 0 + gvx = (py[1]-py[0])*((double)ysiz-.0001)*d; + gvy = (px[0]-px[1])*((double)ysiz-.0001)*d; + gvo = (double)ysiz-.0001 - px[0]*gvx - py[0]*gvy; + } - cx2++; cy2++; - //Clippoly4 (converted from long to double) - nn = z = 0; - do - { - zz = z+1; if (zz == n) zz = 0; - x1 = px[z]; x2 = px[zz]-x1; if ((cx1 <= x1) && (x1 <= cx2)) { px2[nn] = x1; py2[nn] = py[z]; nn++; } - if (x2 <= 0) fx = cx2; else fx = cx1; d = fx-x1; - if ((d < x2) != (d < 0)) { px2[nn] = fx; py2[nn] = (py[zz]-py[z])*d/x2 + py[z]; nn++; } - if (x2 <= 0) fx = cx1; else fx = cx2; d = fx-x1; - if ((d < x2) != (d < 0)) { px2[nn] = fx; py2[nn] = (py[zz]-py[z])*d/x2 + py[z]; nn++; } - z = zz; - } while (z); - if (nn >= 3) - { - n = z = 0; - do - { - zz = z+1; if (zz == nn) zz = 0; - y1 = py2[z]; y2 = py2[zz]-y1; if ((cy1 <= y1) && (y1 <= cy2)) { py[n] = y1; px[n] = px2[z]; n++; } - if (y2 <= 0) fy = cy2; else fy = cy1; d = fy-y1; - if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; } - if (y2 <= 0) fy = cy1; else fy = cy2; d = fy-y1; - if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; } - z = zz; - } while (z); - pow2xsplit = 0; drawpoly(px,py,n,method); - } + cx2++; cy2++; + //Clippoly4 (converted from long to double) + nn = z = 0; + do + { + zz = z+1; if (zz == n) zz = 0; + x1 = px[z]; x2 = px[zz]-x1; if ((cx1 <= x1) && (x1 <= cx2)) { px2[nn] = x1; py2[nn] = py[z]; nn++; } + if (x2 <= 0) fx = cx2; else fx = cx1; d = fx-x1; + if ((d < x2) != (d < 0)) { px2[nn] = fx; py2[nn] = (py[zz]-py[z])*d/x2 + py[z]; nn++; } + if (x2 <= 0) fx = cx1; else fx = cx2; d = fx-x1; + if ((d < x2) != (d < 0)) { px2[nn] = fx; py2[nn] = (py[zz]-py[z])*d/x2 + py[z]; nn++; } + z = zz; + } while (z); + if (nn >= 3) + { + n = z = 0; + do + { + zz = z+1; if (zz == nn) zz = 0; + y1 = py2[z]; y2 = py2[zz]-y1; if ((cy1 <= y1) && (y1 <= cy2)) { py[n] = y1; px[n] = px2[z]; n++; } + if (y2 <= 0) fy = cy2; else fy = cy1; d = fy-y1; + if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; } + if (y2 <= 0) fy = cy1; else fy = cy2; d = fy-y1; + if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; } + z = zz; + } while (z); + pow2xsplit = 0; drawpoly(px,py,n,method); + } #ifdef USE_OPENGL - if (rendmode == 3) { - bglMatrixMode(GL_PROJECTION); bglPopMatrix(); - } + if (rendmode == 3) { + bglMatrixMode(GL_PROJECTION); bglPopMatrix(); + } #endif - globalpicnum = ogpicnum; - globalshade = ogshade; - globalpal = ogpal; - ghalfx = oghalfx; - grhalfxdown10 = ogrhalfxdown10; - grhalfxdown10x = ogrhalfxdown10x; - ghoriz = oghoriz; - frameoffset = ofoffset; - xdimen = oxdimen; - ydimen = oydimen; - gchang = ogchang; - gshang = ogshang; - gctang = ogctang; - gstang = ogstang; + globalpicnum = ogpicnum; + globalshade = ogshade; + globalpal = ogpal; + ghalfx = oghalfx; + grhalfxdown10 = ogrhalfxdown10; + grhalfxdown10x = ogrhalfxdown10x; + ghoriz = oghoriz; + frameoffset = ofoffset; + xdimen = oxdimen; + ydimen = oydimen; + gchang = ogchang; + gshang = ogshang; + gctang = ogctang; + gstang = ogstang; } #ifdef USE_OPENGL static float trapextx[2]; static void drawtrap (float x0, float x1, float y0, float x2, float x3, float y1) { - float px[4], py[4]; - long i, n; + float px[4], py[4]; + long i, n; - if (y0 == y1) return; - px[0] = x0; py[0] = y0; py[2] = y1; - if (x0 == x1) { px[1] = x3; py[1] = y1; px[2] = x2; n = 3; } - else if (x2 == x3) { px[1] = x1; py[1] = y0; px[2] = x3; n = 3; } - else { px[1] = x1; py[1] = y0; px[2] = x3; px[3] = x2; py[3] = y1; n = 4; } + if (y0 == y1) return; + px[0] = x0; py[0] = y0; py[2] = y1; +if (x0 == x1) { px[1] = x3; py[1] = y1; px[2] = x2; n = 3; } + else if (x2 == x3) { px[1] = x1; py[1] = y0; px[2] = x3; n = 3; } + else { px[1] = x1; py[1] = y0; px[2] = x3; px[3] = x2; py[3] = y1; n = 4; } - bglBegin(GL_TRIANGLE_FAN); - for(i=0;i allocpoints) //16 for safety - { - allocpoints = numpoints+16; - rst = (raster*)realloc(rst,allocpoints*sizeof(raster)); - slist = (long*)realloc(slist,allocpoints*sizeof(long)); - npoint2 = (long*)realloc(npoint2,allocpoints*sizeof(long)); - } + static long allocpoints = 0, *slist = 0, *npoint2 = 0; + typedef struct { float x, y, xi; long i; } raster; + static raster *rst = 0; + if (numpoints+16 > allocpoints) //16 for safety + { + allocpoints = numpoints+16; + rst = (raster*)realloc(rst,allocpoints*sizeof(raster)); + slist = (long*)realloc(slist,allocpoints*sizeof(long)); + npoint2 = (long*)realloc(npoint2,allocpoints*sizeof(long)); + } - //Remove unnecessary collinear points: - for(i=0;i m1) { z |= 2; continue; } - npoint2[i] = k; npoint2[j] = -1; npoints--; i--; //collinear - } - if (!z) return; - trapextx[0] = trapextx[1] = px[0]; - for(i=j=0;i trapextx[1]) trapextx[1] = px[i]; - slist[j++] = i; - } - if (z != 3) //Simple polygon... early out - { - bglBegin(GL_TRIANGLE_FAN); - for(i=0;i m1) { z |= 2; continue; } + npoint2[i] = k; npoint2[j] = -1; npoints--; i--; //collinear + } + if (!z) return; + trapextx[0] = trapextx[1] = px[0]; + for(i=j=0;i trapextx[1]) trapextx[1] = px[i]; + slist[j++] = i; + } + if (z != 3) //Simple polygon... early out + { + bglBegin(GL_TRIANGLE_FAN); + for(i=0;i>1);gap;gap>>=1) - for(i=0;i=0;j-=gap) - { - if (py[npoint2[slist[j]]] <= py[npoint2[slist[j+gap]]]) break; - k = slist[j]; slist[j] = slist[j+gap]; slist[j+gap] = k; - } + //Sort points by y's + for(gap=(npoints>>1);gap;gap>>=1) + for(i=0;i=0;j-=gap) + { + if (py[npoint2[slist[j]]] <= py[npoint2[slist[j+gap]]]) break; + k = slist[j]; slist[j] = slist[j+gap]; slist[j+gap] = k; + } - numrst = 0; - for(z=0;z0;i--) - { - if (rst[i-1].xi*(py[i1]-rst[i-1].y) + rst[i-1].x < px[i1]) break; - rst[i+1] = rst[i-1]; - } - numrst += 2; + if ((py[i1] < py[i0]) && (py[i2] < py[i3])) //Insert raster + { + for(i=numrst;i>0;i--) + { + if (rst[i-1].xi*(py[i1]-rst[i-1].y) + rst[i-1].x < px[i1]) break; + rst[i+1] = rst[i-1]; + } + numrst += 2; - if (i&1) //split inside area - { - j = i-1; + if (i&1) //split inside area + { + j = i-1; - x0 = (py[i1] - rst[j ].y)*rst[j ].xi + rst[j ].x; - x1 = (py[i1] - rst[j+1].y)*rst[j+1].xi + rst[j+1].x; - drawtrap(rst[j].x,rst[j+1].x,rst[j].y,x0,x1,py[i1]); - rst[j ].x = x0; rst[j ].y = py[i1]; - rst[j+3].x = x1; rst[j+3].y = py[i1]; - } + x0 = (py[i1] - rst[j ].y)*rst[j ].xi + rst[j ].x; + x1 = (py[i1] - rst[j+1].y)*rst[j+1].xi + rst[j+1].x; + drawtrap(rst[j].x,rst[j+1].x,rst[j].y,x0,x1,py[i1]); + rst[j ].x = x0; rst[j ].y = py[i1]; + rst[j+3].x = x1; rst[j+3].y = py[i1]; + } - m0 = (px[i0]-px[i1]) / (py[i0]-py[i1]); - m1 = (px[i3]-px[i2]) / (py[i3]-py[i2]); - j = ((px[i1] > px[i2]) || ((i1 == i2) && (m0 >= m1))) + i; - k = (i<<1)+1 - j; - rst[j].i = i0; rst[j].xi = m0; rst[j].x = px[i1]; rst[j].y = py[i1]; - rst[k].i = i3; rst[k].xi = m1; rst[k].x = px[i2]; rst[k].y = py[i2]; - } - else - { //NOTE:don't count backwards! - if (i1 == i2) { for(i=0;i px[i2]) || ((i1 == i2) && (m0 >= m1))) + i; + k = (i<<1)+1 - j; + rst[j].i = i0; rst[j].xi = m0; rst[j].x = px[i1]; rst[j].y = py[i1]; + rst[k].i = i3; rst[k].xi = m1; rst[k].x = px[i2]; rst[k].y = py[i2]; + } + else + { //NOTE:don't count backwards! + if (i1 == i2) { for(i=0;i py[i0]) && (py[i2] > py[i3])) //Delete raster - { - for(;j<=i+1;j+=2) - { - x0 = (py[i1] - rst[j ].y)*rst[j ].xi + rst[j ].x; - if ((i == j) && (i1 == i2)) x1 = x0; else x1 = (py[i1] - rst[j+1].y)*rst[j+1].xi + rst[j+1].x; - drawtrap(rst[j].x,rst[j+1].x,rst[j].y,x0,x1,py[i1]); - rst[j ].x = x0; rst[j ].y = py[i1]; - rst[j+1].x = x1; rst[j+1].y = py[i1]; - } - numrst -= 2; for(;i py[i0]) && (py[i2] > py[i3])) //Delete raster + { + for(;j<=i+1;j+=2) + { + x0 = (py[i1] - rst[j ].y)*rst[j ].xi + rst[j ].x; + if ((i == j) && (i1 == i2)) x1 = x0; else x1 = (py[i1] - rst[j+1].y)*rst[j+1].xi + rst[j+1].x; + drawtrap(rst[j].x,rst[j+1].x,rst[j].y,x0,x1,py[i1]); + rst[j ].x = x0; rst[j ].y = py[i1]; + rst[j+1].x = x1; rst[j+1].y = py[i1]; + } + numrst -= 2; for(;i=0;i--) - { - ((float *)rx1)[i] = ((float)rx1[i])/4096.0; - ((float *)ry1)[i] = ((float)ry1[i])/4096.0; - } + //Convert long to float (in-place) + for(i=npoints-1;i>=0;i--) + { + ((float *)rx1)[i] = ((float)rx1[i])/4096.0; + ((float *)ry1)[i] = ((float)ry1[i])/4096.0; + } - if (gloy1 != -1) setpolymost2dview(); //disables blending, texturing, and depth testing - bglEnable(GL_ALPHA_TEST); - bglEnable(GL_TEXTURE_2D); - pth = gltexcache(globalpicnum,globalpal,0); - bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + if (gloy1 != -1) setpolymost2dview(); //disables blending, texturing, and depth testing + bglEnable(GL_ALPHA_TEST); + bglEnable(GL_TEXTURE_2D); + pth = gltexcache(globalpicnum,globalpal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); - f = ((float)(numpalookups-min(max(globalshade,0),numpalookups)))/((float)numpalookups); - switch ((globalorientation>>7)&3) { - case 0: - case 1: a = 1.0; bglDisable(GL_BLEND); break; - case 2: a = 0.66; bglEnable(GL_BLEND); break; - case 3: a = 0.33; bglEnable(GL_BLEND); break; - } - bglColor4f(f,f,f,a); + f = ((float)(numpalookups-min(max(globalshade,0),numpalookups)))/((float)numpalookups); + switch ((globalorientation>>7)&3) { + case 0: + case 1: a = 1.0; bglDisable(GL_BLEND); break; + case 2: a = 0.66; bglEnable(GL_BLEND); break; + case 3: a = 0.33; bglEnable(GL_BLEND); break; + } + bglColor4f(f,f,f,a); - tessectrap((float *)rx1,(float *)ry1,xb1,npoints); + tessectrap((float *)rx1,(float *)ry1,xb1,npoints); } #endif long polymost_drawtilescreen (long tilex, long tiley, long wallnum, long dimen) { #ifdef USE_OPENGL - float xdime, ydime, xdimepad, ydimepad, scx, scy; - long i; - pthtyp *pth; + float xdime, ydime, xdimepad, ydimepad, scx, scy; + long i; + pthtyp *pth; - if ((rendmode != 3) || (qsetmode != 200)) return(-1); + if ((rendmode != 3) || (qsetmode != 200)) return(-1); - if (!glinfo.texnpot) { - i = (1<<(picsiz[wallnum]&15)); if (i < tilesizx[wallnum]) i += i; xdimepad = (float)i; - i = (1<<(picsiz[wallnum]>>4)); if (i < tilesizy[wallnum]) i += i; ydimepad = (float)i; - } else { - xdimepad = (float)tilesizx[wallnum]; - ydimepad = (float)tilesizy[wallnum]; - } - xdime = (float)tilesizx[wallnum]; xdimepad = xdime/xdimepad; - ydime = (float)tilesizy[wallnum]; ydimepad = ydime/ydimepad; + if (!glinfo.texnpot) { + i = (1<<(picsiz[wallnum]&15)); if (i < tilesizx[wallnum]) i += i; xdimepad = (float)i; + i = (1<<(picsiz[wallnum]>>4)); if (i < tilesizy[wallnum]) i += i; ydimepad = (float)i; + } else { + xdimepad = (float)tilesizx[wallnum]; + ydimepad = (float)tilesizy[wallnum]; + } + xdime = (float)tilesizx[wallnum]; xdimepad = xdime/xdimepad; + ydime = (float)tilesizy[wallnum]; ydimepad = ydime/ydimepad; - if ((xdime <= dimen) && (ydime <= dimen)) - { - scx = xdime; - scy = ydime; - } - else - { - scx = (float)dimen; - scy = (float)dimen; - if (xdime < ydime) scx *= xdime/ydime; else scy *= ydime/xdime; - } + if ((xdime <= dimen) && (ydime <= dimen)) + { + scx = xdime; + scy = ydime; + } + else + { + scx = (float)dimen; + scy = (float)dimen; + if (xdime < ydime) scx *= xdime/ydime; else scy *= ydime/xdime; + } - pth = gltexcache(wallnum,0,4); - bglBindTexture(GL_TEXTURE_2D,pth ? pth->glpic : 0); + pth = gltexcache(wallnum,0,4); + bglBindTexture(GL_TEXTURE_2D,pth ? pth->glpic : 0); - bglDisable(GL_ALPHA_TEST); + bglDisable(GL_ALPHA_TEST); - if (!pth || (pth->flags & 8)) { - bglDisable(GL_TEXTURE_2D); - bglBegin(GL_TRIANGLE_FAN); - if (gammabrightness) - bglColor4f((float)curpalette[255].r/255.0, - (float)curpalette[255].g/255.0, - (float)curpalette[255].b/255.0, - 1); - else - bglColor4f((float)britable[curbrightness][ curpalette[255].r ] / 255.0, - (float)britable[curbrightness][ curpalette[255].g ] / 255.0, - (float)britable[curbrightness][ curpalette[255].b ] / 255.0, - 1); - bglVertex2f((float)tilex ,(float)tiley ); - bglVertex2f((float)tilex+scx,(float)tiley ); - bglVertex2f((float)tilex+scx,(float)tiley+scy); - bglVertex2f((float)tilex ,(float)tiley+scy); - bglEnd(); - } + if (!pth || (pth->flags & 8)) { + bglDisable(GL_TEXTURE_2D); + bglBegin(GL_TRIANGLE_FAN); + if (gammabrightness) + bglColor4f((float)curpalette[255].r/255.0, + (float)curpalette[255].g/255.0, + (float)curpalette[255].b/255.0, + 1); + else + bglColor4f((float)britable[curbrightness][ curpalette[255].r ] / 255.0, + (float)britable[curbrightness][ curpalette[255].g ] / 255.0, + (float)britable[curbrightness][ curpalette[255].b ] / 255.0, + 1); + bglVertex2f((float)tilex ,(float)tiley ); + bglVertex2f((float)tilex+scx,(float)tiley ); + bglVertex2f((float)tilex+scx,(float)tiley+scy); + bglVertex2f((float)tilex ,(float)tiley+scy); + bglEnd(); + } - bglColor4f(1,1,1,1); - bglEnable(GL_TEXTURE_2D); - bglEnable(GL_BLEND); - bglBegin(GL_TRIANGLE_FAN); - bglTexCoord2f( 0, 0); bglVertex2f((float)tilex ,(float)tiley ); - bglTexCoord2f(xdimepad, 0); bglVertex2f((float)tilex+scx,(float)tiley ); - bglTexCoord2f(xdimepad,ydimepad); bglVertex2f((float)tilex+scx,(float)tiley+scy); - bglTexCoord2f( 0,ydimepad); bglVertex2f((float)tilex ,(float)tiley+scy); - bglEnd(); - - return(0); + bglColor4f(1,1,1,1); + bglEnable(GL_TEXTURE_2D); + bglEnable(GL_BLEND); + bglBegin(GL_TRIANGLE_FAN); + bglTexCoord2f( 0, 0); bglVertex2f((float)tilex ,(float)tiley ); + bglTexCoord2f(xdimepad, 0); bglVertex2f((float)tilex+scx,(float)tiley ); + bglTexCoord2f(xdimepad,ydimepad); bglVertex2f((float)tilex+scx,(float)tiley+scy); + bglTexCoord2f( 0,ydimepad); bglVertex2f((float)tilex ,(float)tiley+scy); + bglEnd(); + + return(0); #else - return -1; + return -1; #endif } long polymost_printext256(long xpos, long ypos, short col, short backcol, char *name, char fontsize) { #ifndef USE_OPENGL - return -1; + return -1; #else - GLfloat tx, ty, txc, tyc; - int c; - palette_t p,b; - - if (gammabrightness) { - p = curpalette[col]; - b = curpalette[backcol]; - } else { - p.r = britable[curbrightness][ curpalette[col].r ]; - p.g = britable[curbrightness][ curpalette[col].g ]; - p.b = britable[curbrightness][ curpalette[col].b ]; - b.r = britable[curbrightness][ curpalette[backcol].r ]; - b.g = britable[curbrightness][ curpalette[backcol].g ]; - b.b = britable[curbrightness][ curpalette[backcol].b ]; - } + GLfloat tx, ty, txc, tyc; + int c; + palette_t p,b; - if ((rendmode != 3) || (qsetmode != 200)) return(-1); + if (gammabrightness) { + p = curpalette[col]; + b = curpalette[backcol]; + } else { + p.r = britable[curbrightness][ curpalette[col].r ]; + p.g = britable[curbrightness][ curpalette[col].g ]; + p.b = britable[curbrightness][ curpalette[col].b ]; + b.r = britable[curbrightness][ curpalette[backcol].r ]; + b.g = britable[curbrightness][ curpalette[backcol].g ]; + b.b = britable[curbrightness][ curpalette[backcol].b ]; + } - if (!polymosttext) { - // construct a 256x128 8-bit alpha-only texture for the font glyph matrix - unsigned char *tbuf, *cptr, *tptr; - int h,i,j,l; + if ((rendmode != 3) || (qsetmode != 200)) return(-1); - bglGenTextures(1,&polymosttext); - if (!polymosttext) return -1; + if (!polymosttext) { + // construct a 256x128 8-bit alpha-only texture for the font glyph matrix + unsigned char *tbuf, *cptr, *tptr; + int h,i,j,l; - tbuf = (unsigned char *)Bmalloc(256*128); - if (!tbuf) { - bglDeleteTextures(1,&polymosttext); - polymosttext = 0; - return -1; - } - Bmemset(tbuf, 0, 256*128); + bglGenTextures(1,&polymosttext); + if (!polymosttext) return -1; - cptr = (unsigned char*)textfont; - for (h=0;h<256;h++) { - tptr = tbuf + (h%32)*8 + (h/32)*256*8; - for (i=0;i<8;i++) { - for (j=0;j<8;j++) { - if (cptr[h*8+i] & pow2char[7-j]) tptr[j] = 255; - } - tptr += 256; - } - } - - cptr = (unsigned char*)smalltextfont; - for (h=0;h<256;h++) { - tptr = tbuf + 256*64 + (h%32)*8 + (h/32)*256*8; - for (i=1;i<7;i++) { - for (j=2;j<6;j++) { - if (cptr[h*8+i] & pow2char[7-j]) tptr[j-2] = 255; - } - tptr += 256; - } - } + tbuf = (unsigned char *)Bmalloc(256*128); + if (!tbuf) { + bglDeleteTextures(1,&polymosttext); + polymosttext = 0; + return -1; + } + Bmemset(tbuf, 0, 256*128); - bglBindTexture(GL_TEXTURE_2D, polymosttext); - bglTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,256,128,0,GL_ALPHA,GL_UNSIGNED_BYTE,(GLvoid*)tbuf); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - free(tbuf); - } - else bglBindTexture(GL_TEXTURE_2D, polymosttext); + cptr = (unsigned char*)textfont; + for (h=0;h<256;h++) { + tptr = tbuf + (h%32)*8 + (h/32)*256*8; + for (i=0;i<8;i++) { + for (j=0;j<8;j++) { + if (cptr[h*8+i] & pow2char[7-j]) tptr[j] = 255; + } + tptr += 256; + } + } - setpolymost2dview(); // disables blending, texturing, and depth testing - bglDisable(GL_ALPHA_TEST); - bglDepthMask(GL_FALSE); // disable writing to the z-buffer + cptr = (unsigned char*)smalltextfont; + for (h=0;h<256;h++) { + tptr = tbuf + 256*64 + (h%32)*8 + (h/32)*256*8; + for (i=1;i<7;i++) { + for (j=2;j<6;j++) { + if (cptr[h*8+i] & pow2char[7-j]) tptr[j-2] = 255; + } + tptr += 256; + } + } - if (backcol >= 0) { - bglColor4ub(b.r,b.g,b.b,255); - c = Bstrlen(name); - - bglBegin(GL_QUADS); - bglVertex2i(xpos,ypos); - bglVertex2i(xpos,ypos+(fontsize?6:8)); - bglVertex2i(xpos+(c<<(3-fontsize)),ypos+(fontsize?6:8)); - bglVertex2i(xpos+(c<<(3-fontsize)),ypos); - bglEnd(); - } + bglBindTexture(GL_TEXTURE_2D, polymosttext); + bglTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,256,128,0,GL_ALPHA,GL_UNSIGNED_BYTE,(GLvoid*)tbuf); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + free(tbuf); + } + else bglBindTexture(GL_TEXTURE_2D, polymosttext); - bglEnable(GL_TEXTURE_2D); - bglEnable(GL_BLEND); - bglColor4ub(p.r,p.g,p.b,255); - txc = fontsize ? (4.0/256.0) : (8.0/256.0); - tyc = fontsize ? (6.0/128.0) : (8.0/128.0); - bglBegin(GL_QUADS); - for (c=0; name[c]; c++) { - tx = (float)(name[c]%32)/32.0; - ty = (float)((name[c]/32) + (fontsize*8))/16.0; + setpolymost2dview(); // disables blending, texturing, and depth testing + bglDisable(GL_ALPHA_TEST); + bglDepthMask(GL_FALSE); // disable writing to the z-buffer - bglTexCoord2f(tx,ty); bglVertex2i(xpos,ypos); - bglTexCoord2f(tx+txc,ty); bglVertex2i(xpos+(8>>fontsize),ypos); - bglTexCoord2f(tx+txc,ty+tyc); bglVertex2i(xpos+(8>>fontsize),ypos+(fontsize?6:8)); - bglTexCoord2f(tx,ty+tyc); bglVertex2i(xpos,ypos+(fontsize?6:8)); - - xpos += (8>>fontsize); - } - bglEnd(); + if (backcol >= 0) { + bglColor4ub(b.r,b.g,b.b,255); + c = Bstrlen(name); - bglDepthMask(GL_TRUE); // re-enable writing to the z-buffer - - return 0; + bglBegin(GL_QUADS); + bglVertex2i(xpos,ypos); + bglVertex2i(xpos,ypos+(fontsize?6:8)); + bglVertex2i(xpos+(c<<(3-fontsize)),ypos+(fontsize?6:8)); + bglVertex2i(xpos+(c<<(3-fontsize)),ypos); + bglEnd(); + } + + bglEnable(GL_TEXTURE_2D); + bglEnable(GL_BLEND); + bglColor4ub(p.r,p.g,p.b,255); + txc = fontsize ? (4.0/256.0) : (8.0/256.0); + tyc = fontsize ? (6.0/128.0) : (8.0/128.0); + bglBegin(GL_QUADS); + for (c=0; name[c]; c++) { + tx = (float)(name[c]%32)/32.0; + ty = (float)((name[c]/32) + (fontsize*8))/16.0; + + bglTexCoord2f(tx,ty); bglVertex2i(xpos,ypos); + bglTexCoord2f(tx+txc,ty); bglVertex2i(xpos+(8>>fontsize),ypos); + bglTexCoord2f(tx+txc,ty+tyc); bglVertex2i(xpos+(8>>fontsize),ypos+(fontsize?6:8)); + bglTexCoord2f(tx,ty+tyc); bglVertex2i(xpos,ypos+(fontsize?6:8)); + + xpos += (8>>fontsize); + } + bglEnd(); + + bglDepthMask(GL_TRUE); // re-enable writing to the z-buffer + + return 0; #endif } @@ -4635,235 +4635,235 @@ long polymost_printext256(long xpos, long ypos, short col, short backcol, char * #ifdef USE_OPENGL static int gltexturemode(const osdfuncparm_t *parm) { - int m; - const char *p; + int m; + const char *p; - if (parm->numparms != 1) { - OSD_Printf("Current texturing mode is %s\n", glfiltermodes[gltexfiltermode].name); - OSD_Printf(" Vaild modes are:\n"); - for (m = 0; m < (int)numglfiltermodes; m++) - OSD_Printf(" %d - %s\n",m,glfiltermodes[m].name); + if (parm->numparms != 1) { + OSD_Printf("Current texturing mode is %s\n", glfiltermodes[gltexfiltermode].name); + OSD_Printf(" Vaild modes are:\n"); + for (m = 0; m < (int)numglfiltermodes; m++) + OSD_Printf(" %d - %s\n",m,glfiltermodes[m].name); - return OSDCMD_OK; - } + return OSDCMD_OK; + } - m = Bstrtoul(parm->parms[0], (char **)&p, 10); - if (p == parm->parms[0]) { - // string - for (m = 0; m < (int)numglfiltermodes; m++) { - if (!Bstrcasecmp(parm->parms[0], glfiltermodes[m].name)) break; - } - if (m == numglfiltermodes) m = gltexfiltermode; // no change - } else { - if (m < 0) m = 0; - else if (m >= (int)numglfiltermodes) m = numglfiltermodes - 1; - } + m = Bstrtoul(parm->parms[0], (char **)&p, 10); + if (p == parm->parms[0]) { + // string + for (m = 0; m < (int)numglfiltermodes; m++) { + if (!Bstrcasecmp(parm->parms[0], glfiltermodes[m].name)) break; + } + if (m == numglfiltermodes) m = gltexfiltermode; // no change + } else { + if (m < 0) m = 0; + else if (m >= (int)numglfiltermodes) m = numglfiltermodes - 1; + } - if (m != gltexfiltermode) { - gltexfiltermode = m; - gltexapplyprops(); - } + if (m != gltexfiltermode) { + gltexfiltermode = m; + gltexapplyprops(); + } - OSD_Printf("Texture filtering mode changed to %s\n", glfiltermodes[gltexfiltermode].name ); + OSD_Printf("Texture filtering mode changed to %s\n", glfiltermodes[gltexfiltermode].name ); - return OSDCMD_OK; + return OSDCMD_OK; } static int gltextureanisotropy(const osdfuncparm_t *parm) { - long l; - const char *p; + long l; + const char *p; - if (parm->numparms != 1) { - OSD_Printf("Current texture anisotropy is %d\n", glanisotropy); - OSD_Printf(" Maximum is %d\n", (long)glinfo.maxanisotropy); + if (parm->numparms != 1) { + OSD_Printf("Current texture anisotropy is %d\n", glanisotropy); + OSD_Printf(" Maximum is %d\n", (long)glinfo.maxanisotropy); - return OSDCMD_OK; - } + return OSDCMD_OK; + } - l = Bstrtoul(parm->parms[0], (char **)&p, 10); - if (l < 0 || l > (long)glinfo.maxanisotropy) l = 0; + l = Bstrtoul(parm->parms[0], (char **)&p, 10); + if (l < 0 || l > (long)glinfo.maxanisotropy) l = 0; - if (l != gltexfiltermode) { - glanisotropy = l; - gltexapplyprops(); - } + if (l != gltexfiltermode) { + glanisotropy = l; + gltexapplyprops(); + } - OSD_Printf("Texture anisotropy changed to %d\n", glanisotropy ); + OSD_Printf("Texture anisotropy changed to %d\n", glanisotropy ); - return OSDCMD_OK; + return OSDCMD_OK; } #endif static int osdcmd_polymostvars(const osdfuncparm_t *parm) { - int showval = (parm->numparms < 1), val = 0; - - if (!showval) val = atoi(parm->parms[0]); - if (!Bstrcasecmp(parm->name, "usemodels")) { - if (showval) { OSD_Printf("usemodels is %d\n", usemodels); } - else usemodels = (val != 0); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "usehightile")) { - if (showval) { OSD_Printf("usehightile is %d\n", usehightile); } - else usehightile = (val != 0); - return OSDCMD_OK; - } + int showval = (parm->numparms < 1), val = 0; + + if (!showval) val = atoi(parm->parms[0]); + if (!Bstrcasecmp(parm->name, "usemodels")) { + if (showval) { OSD_Printf("usemodels is %d\n", usemodels); } + else usemodels = (val != 0); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "usehightile")) { + if (showval) { OSD_Printf("usehightile is %d\n", usehightile); } + else usehightile = (val != 0); + return OSDCMD_OK; + } #ifdef USE_OPENGL - else if (!Bstrcasecmp(parm->name, "glusetexcompr")) { - if (showval) { OSD_Printf("glusetexcompr is %d\n", glusetexcompr); } - else glusetexcompr = (val != 0); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glredbluemode")) { - if (showval) { OSD_Printf("glredbluemode is %d\n", glredbluemode); } - else glredbluemode = (val != 0); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "gltexturemaxsize")) { - if (showval) { OSD_Printf("gltexturemaxsize is %d\n", gltexmaxsize); } - else gltexmaxsize = val; - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "gltexturemiplevel")) { - if (showval) { OSD_Printf("gltexturemiplevel is %d\n", gltexmiplevel); } - else gltexmiplevel = val; - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "usegoodalpha")) { - OSD_Printf("usegoodalpha is obsolete\n"); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glpolygonmode")) { - if (showval) { OSD_Printf("glpolygonmode is %d\n", glpolygonmode); } - else glpolygonmode = val; - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glusetexcache")) { - if (showval) { OSD_Printf("glusetexcache is %d\n", glusetexcache); } - else glusetexcache = (val != 0); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glusetexcachecompression")) { - if (showval) { OSD_Printf("glusetexcachecompression is %d\n", glusetexcachecompression); } - else glusetexcachecompression = (val != 0); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glmultisample")) { - if (showval) { OSD_Printf("glmultisample is %d\n", glmultisample); } - else glmultisample = max(0,val); - return OSDCMD_OK; - } - else if (!Bstrcasecmp(parm->name, "glnvmultisamplehint")) { - if (showval) { OSD_Printf("glnvmultisamplehint is %d\n", glnvmultisamplehint); } - else glnvmultisamplehint = (val != 0); - return OSDCMD_OK; - } + else if (!Bstrcasecmp(parm->name, "glusetexcompr")) { + if (showval) { OSD_Printf("glusetexcompr is %d\n", glusetexcompr); } + else glusetexcompr = (val != 0); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glredbluemode")) { + if (showval) { OSD_Printf("glredbluemode is %d\n", glredbluemode); } + else glredbluemode = (val != 0); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "gltexturemaxsize")) { + if (showval) { OSD_Printf("gltexturemaxsize is %d\n", gltexmaxsize); } + else gltexmaxsize = val; + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "gltexturemiplevel")) { + if (showval) { OSD_Printf("gltexturemiplevel is %d\n", gltexmiplevel); } + else gltexmiplevel = val; + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "usegoodalpha")) { + OSD_Printf("usegoodalpha is obsolete\n"); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glpolygonmode")) { + if (showval) { OSD_Printf("glpolygonmode is %d\n", glpolygonmode); } + else glpolygonmode = val; + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glusetexcache")) { + if (showval) { OSD_Printf("glusetexcache is %d\n", glusetexcache); } + else glusetexcache = (val != 0); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glusetexcachecompression")) { + if (showval) { OSD_Printf("glusetexcachecompression is %d\n", glusetexcachecompression); } + else glusetexcachecompression = (val != 0); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glmultisample")) { + if (showval) { OSD_Printf("glmultisample is %d\n", glmultisample); } + else glmultisample = max(0,val); + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "glnvmultisamplehint")) { + if (showval) { OSD_Printf("glnvmultisamplehint is %d\n", glnvmultisamplehint); } + else glnvmultisamplehint = (val != 0); + return OSDCMD_OK; + } #endif - return OSDCMD_SHOWHELP; + return OSDCMD_SHOWHELP; } #if 0 // because I'm lazy static int dumptexturedefs(const osdfuncparm_t *parm) { - hicreplctyp *hr; - int i; - - if (!hicfirstinit) return OSDCMD_OK; - - initprintf("// Begin Texture Dump\n"); - for (i=0;inext) { - if (!hr->filename) continue; - initprintf(" pal %d { name \"%s\" ", hr->palnum, hr->filename); - if (hr->alphacut >= 0.0) initprintf("alphacut %g ", hr->alphacut); - initprintf("}\n"); - } - initprintf("}\n"); - } - initprintf("// End Texture Dump\n"); - - return OSDCMD_OK; // no replacement found + hicreplctyp *hr; + int i; + + if (!hicfirstinit) return OSDCMD_OK; + + initprintf("// Begin Texture Dump\n"); + for (i=0;inext) { + if (!hr->filename) continue; + initprintf(" pal %d { name \"%s\" ", hr->palnum, hr->filename); + if (hr->alphacut >= 0.0) initprintf("alphacut %g ", hr->alphacut); + initprintf("}\n"); + } + initprintf("}\n"); + } + initprintf("// End Texture Dump\n"); + + return OSDCMD_OK; // no replacement found } #endif void polymost_initosdfuncs(void) { #ifdef USE_OPENGL - OSD_RegisterFunction("glusetexcompr","glusetexcompr: enable/disable OpenGL texture compression",osdcmd_polymostvars); - OSD_RegisterFunction("glredbluemode","glredbluemode: enable/disable experimental OpenGL red-blue glasses mode",osdcmd_polymostvars); - OSD_RegisterFunction("gltexturemode", "gltexturemode: changes the texture filtering settings", gltexturemode); - OSD_RegisterFunction("gltextureanisotropy", "gltextureanisotropy: changes the OpenGL texture anisotropy setting", gltextureanisotropy); - OSD_RegisterFunction("gltexturemaxsize","gltexturemaxsize: changes the maximum OpenGL texture size limit",osdcmd_polymostvars); - OSD_RegisterFunction("gltexturemiplevel","gltexturemiplevel: changes the highest OpenGL mipmap level used",osdcmd_polymostvars); - OSD_RegisterFunction("usegoodalpha","usegoodalpha: [OBSOLETE] enable/disable better looking OpenGL alpha hack",osdcmd_polymostvars); - OSD_RegisterFunction("glpolygonmode","glpolygonmode: debugging feature",osdcmd_polymostvars); //FUK - OSD_RegisterFunction("glusetexcache","glusetexcache: enable/disable OpenGL compressed texture cache",osdcmd_polymostvars); - OSD_RegisterFunction("glusetexcachecompression","usetexcachecompression: enable/disable compression of files in the OpenGL compressed texture cache",osdcmd_polymostvars); - OSD_RegisterFunction("glmultisample","glmultisample: sets the number of samples used for antialiasing (0 = off)",osdcmd_polymostvars); - OSD_RegisterFunction("glnvmultisamplehint","glnvmultisamplehint: enable/disable Nvidia multisampling hinting",osdcmd_polymostvars); + OSD_RegisterFunction("glusetexcompr","glusetexcompr: enable/disable OpenGL texture compression",osdcmd_polymostvars); + OSD_RegisterFunction("glredbluemode","glredbluemode: enable/disable experimental OpenGL red-blue glasses mode",osdcmd_polymostvars); + OSD_RegisterFunction("gltexturemode", "gltexturemode: changes the texture filtering settings", gltexturemode); + OSD_RegisterFunction("gltextureanisotropy", "gltextureanisotropy: changes the OpenGL texture anisotropy setting", gltextureanisotropy); + OSD_RegisterFunction("gltexturemaxsize","gltexturemaxsize: changes the maximum OpenGL texture size limit",osdcmd_polymostvars); + OSD_RegisterFunction("gltexturemiplevel","gltexturemiplevel: changes the highest OpenGL mipmap level used",osdcmd_polymostvars); + OSD_RegisterFunction("usegoodalpha","usegoodalpha: [OBSOLETE] enable/disable better looking OpenGL alpha hack",osdcmd_polymostvars); + OSD_RegisterFunction("glpolygonmode","glpolygonmode: debugging feature",osdcmd_polymostvars); //FUK + OSD_RegisterFunction("glusetexcache","glusetexcache: enable/disable OpenGL compressed texture cache",osdcmd_polymostvars); + OSD_RegisterFunction("glusetexcachecompression","usetexcachecompression: enable/disable compression of files in the OpenGL compressed texture cache",osdcmd_polymostvars); + OSD_RegisterFunction("glmultisample","glmultisample: sets the number of samples used for antialiasing (0 = off)",osdcmd_polymostvars); + OSD_RegisterFunction("glnvmultisamplehint","glnvmultisamplehint: enable/disable Nvidia multisampling hinting",osdcmd_polymostvars); #endif - OSD_RegisterFunction("usemodels","usemodels: enable/disable model rendering in >8-bit mode",osdcmd_polymostvars); - OSD_RegisterFunction("usehightile","usehightile: enable/disable hightile texture rendering in >8-bit mode",osdcmd_polymostvars); - //OSD_RegisterFunction("dumptexturedefs","dumptexturedefs: dumps all texture definitions in the new style",dumptexturedefs); + OSD_RegisterFunction("usemodels","usemodels: enable/disable model rendering in >8-bit mode",osdcmd_polymostvars); + OSD_RegisterFunction("usehightile","usehightile: enable/disable hightile texture rendering in >8-bit mode",osdcmd_polymostvars); + //OSD_RegisterFunction("dumptexturedefs","dumptexturedefs: dumps all texture definitions in the new style",dumptexturedefs); } void polymost_precache(long dapicnum, long dapalnum, long datype) { #ifdef USE_OPENGL - // dapicnum and dapalnum are like you'd expect - // datype is 0 for a wall/floor/ceiling and 1 for a sprite - // basically this just means walls are repeating - // while sprites are clamped - int mid; + // dapicnum and dapalnum are like you'd expect + // datype is 0 for a wall/floor/ceiling and 1 for a sprite + // basically this just means walls are repeating + // while sprites are clamped + int mid; - if (rendmode < 3) return; - - if (!palookup[dapalnum]) return;//dapalnum = 0; + if (rendmode < 3) return; - //OSD_Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); - hicprecaching = 1; - gltexcache(dapicnum, dapalnum, (datype & 1) << 2); - hicprecaching = 0; + if (!palookup[dapalnum]) return;//dapalnum = 0; - if (datype == 0) return; + //OSD_Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); + hicprecaching = 1; + gltexcache(dapicnum, dapalnum, (datype & 1) << 2); + hicprecaching = 0; - mid = md_tilehasmodel(dapicnum); - if (mid < 0 || models[mid]->mdnum < 2) return; + if (datype == 0) return; - { - int i,j=0; + mid = md_tilehasmodel(dapicnum); + if (mid < 0 || models[mid]->mdnum < 2) return; - if (models[mid]->mdnum == 3) - j = ((md3model *)models[mid])->head.numsurfs; + { + int i,j=0; - for (i=0;i<=j;i++) - mdloadskin((md2model*)models[mid], 0, dapalnum, i); - } + if (models[mid]->mdnum == 3) + j = ((md3model *)models[mid])->head.numsurfs; + + for (i=0;i<=j;i++) + mdloadskin((md2model*)models[mid], 0, dapalnum, i); + } #endif } static unsigned short hicosub (unsigned short c) { - long r, g, b; - g = ((c>> 5)&63); - r = ((c>>11)-(g>>1))&31; - b = ((c>> 0)-(g>>1))&31; - return((r<<11)+(g<<5)+b); + long r, g, b; + g = ((c>> 5)&63); + r = ((c>>11)-(g>>1))&31; + b = ((c>> 0)-(g>>1))&31; + return((r<<11)+(g<<5)+b); } static unsigned short hicoadd (unsigned short c) { - long r, g, b; - g = ((c>> 5)&63); - r = ((c>>11)+(g>>1))&31; - b = ((c>> 0)+(g>>1))&31; - return((r<<11)+(g<<5)+b); + long r, g, b; + g = ((c>> 5)&63); + r = ((c>>11)+(g>>1))&31; + b = ((c>> 0)+(g>>1))&31; + return((r<<11)+(g<<5)+b); } /* @@ -4906,216 +4906,216 @@ Description of Ken's filter to improve LZW compression of DXT1 format by ~15%: ( int dxtfilter(int fil, texcachepicture *pict, char *pic, void *midbuf, char *packbuf, unsigned long miplen) { - void *writebuf; + void *writebuf; #if (USEKENFILTER == 0) - unsigned long cleng,j; - if (glusetexcachecompression) { + unsigned long cleng,j; + if (glusetexcachecompression) { #ifdef USELZF - cleng = lzf_compress(pic, miplen, packbuf, miplen-1); - if (cleng == 0) { - // failed to compress - cleng = miplen; - writebuf = pic; - } else writebuf = packbuf; + cleng = lzf_compress(pic, miplen, packbuf, miplen-1); + if (cleng == 0) { + // failed to compress + cleng = miplen; + writebuf = pic; + } else writebuf = packbuf; #else - cleng = lzwcompress(pic,miplen,packbuf); - writebuf = packbuf; + cleng = lzwcompress(pic,miplen,packbuf); + writebuf = packbuf; #endif - } else { - cleng = miplen; - writebuf = pic; - } - if (cleng < 0) return -1; j = B_LITTLE32(cleng); - if (Bwrite(fil, &j, sizeof(unsigned long)) != sizeof(unsigned long)) return -1; - if (Bwrite(fil, writebuf, cleng) != cleng) return -1; + } else { + cleng = miplen; + writebuf = pic; + } + if (cleng < 0) return -1; j = B_LITTLE32(cleng); + if (Bwrite(fil, &j, sizeof(unsigned long)) != sizeof(unsigned long)) return -1; + if (Bwrite(fil, writebuf, cleng) != cleng) return -1; #else - unsigned long j, k, offs, stride, cleng; - char *cptr; - - if ((pict->format == B_LITTLE32(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)) || - (pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT))) { offs = 0; stride = 8; } - else if ((pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)) || - (pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT))) { offs = 8; stride = 16; } - else { offs = 0; stride = 8; } - - if (stride == 16) //If DXT3... - { - //alpha_4x4 - cptr = midbuf; - for(k=0;k<8;k++) *cptr++ = pic[k]; - for(j=stride;(unsigned)jformat == B_LITTLE32(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)) || + (pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT))) { offs = 0; stride = 8; } + else if ((pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)) || + (pict->format == B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT))) { offs = 8; stride = 16; } + else { offs = 0; stride = 8; } + + if (stride == 16) //If DXT3... + { + //alpha_4x4 + cptr = midbuf; + for(k=0;k<8;k++) *cptr++ = pic[k]; + for(j=stride;(unsigned)j>0)&3) + (((c2[1]>>0)&3)<<2) + (((c2[2]>>0)&3)<<4) + (((c2[3]>>0)&3)<<6); - cptr[1] = ((c2[0]>>2)&3) + (((c2[1]>>2)&3)<<2) + (((c2[2]>>2)&3)<<4) + (((c2[3]>>2)&3)<<6); - cptr[2] = ((c2[0]>>4)&3) + (((c2[1]>>4)&3)<<2) + (((c2[2]>>4)&3)<<4) + (((c2[3]>>4)&3)<<6); - cptr[3] = ((c2[0]>>6)&3) + (((c2[1]>>6)&3)<<2) + (((c2[2]>>6)&3)<<4) + (((c2[3]>>6)&3)<<6); - cptr += 4; - } - if (glusetexcachecompression) { + } else { + cleng = (miplen/stride)*4; + writebuf = midbuf; + } + j = B_LITTLE32(cleng); + Bwrite(fil,&j,4); + Bwrite(fil,writebuf,cleng); + + //index_4x4 + cptr = midbuf; + for(j=0;(unsigned)j>0)&3) + (((c2[1]>>0)&3)<<2) + (((c2[2]>>0)&3)<<4) + (((c2[3]>>0)&3)<<6); + cptr[1] = ((c2[0]>>2)&3) + (((c2[1]>>2)&3)<<2) + (((c2[2]>>2)&3)<<4) + (((c2[3]>>2)&3)<<6); + cptr[2] = ((c2[0]>>4)&3) + (((c2[1]>>4)&3)<<2) + (((c2[2]>>4)&3)<<4) + (((c2[3]>>4)&3)<<6); + cptr[3] = ((c2[0]>>6)&3) + (((c2[1]>>6)&3)<<2) + (((c2[2]>>6)&3)<<4) + (((c2[3]>>6)&3)<<6); + cptr += 4; + } + if (glusetexcachecompression) { #ifdef USELZF - j = (miplen/stride)*4; - cleng = lzf_compress(midbuf,j,packbuf,j-1); - if (cleng == 0) { - cleng = j; - writebuf = midbuf; - } else writebuf = packbuf; + j = (miplen/stride)*4; + cleng = lzf_compress(midbuf,j,packbuf,j-1); + if (cleng == 0) { + cleng = j; + writebuf = midbuf; + } else writebuf = packbuf; #else - cleng = lzwcompress(midbuf,(miplen/stride)*4,packbuf); - writebuf = packbuf; + cleng = lzwcompress(midbuf,(miplen/stride)*4,packbuf); + writebuf = packbuf; #endif - } else { - cleng = (miplen/stride)*4; - writebuf = midbuf; - } - j = B_LITTLE32(cleng); - Bwrite(fil,&j,4); - Bwrite(fil,writebuf,cleng); + } else { + cleng = (miplen/stride)*4; + writebuf = midbuf; + } + j = B_LITTLE32(cleng); + Bwrite(fil,&j,4); + Bwrite(fil,writebuf,cleng); #endif - return 0; + return 0; } int dedxtfilter(int fil, texcachepicture *pict, char *pic, void *midbuf, char *packbuf, int ispacked) { - void *inbuf; + void *inbuf; #if (USEKENFILTER == 0) - unsigned long cleng; - if (kread(fil, &cleng, sizeof(unsigned long)) != sizeof(unsigned long)) return -1; cleng = B_LITTLE32(cleng); + unsigned long cleng; + if (kread(fil, &cleng, sizeof(unsigned long)) != sizeof(unsigned long)) return -1; cleng = B_LITTLE32(cleng); #ifdef USELZF - if (ispacked && cleng < pict->size) inbuf = packbuf; else inbuf = pic; - if (kread(fil, inbuf, cleng) != cleng) return -1; - if (ispacked && cleng < pict->size) - if (lzf_decompress(packbuf, cleng, pic, pict->size) == 0) return -1; + if (ispacked && cleng < pict->size) inbuf = packbuf; else inbuf = pic; + if (kread(fil, inbuf, cleng) != cleng) return -1; + if (ispacked && cleng < pict->size) + if (lzf_decompress(packbuf, cleng, pic, pict->size) == 0) return -1; #else - if (ispacked) inbuf = packbuf; else inbuf = pic; - if (kread(fil, inbuf, cleng) != cleng) return -1; - if (ispacked && lzwuncompress(packbuf, cleng, pic, pict->size) != pict->size) return -1; + if (ispacked) inbuf = packbuf; else inbuf = pic; + if (kread(fil, inbuf, cleng) != cleng) return -1; + if (ispacked && lzwuncompress(packbuf, cleng, pic, pict->size) != pict->size) return -1; #endif #else - long j, k, offs, stride, cleng; - char *cptr; + long j, k, offs, stride, cleng; + char *cptr; - if (ispacked) inbuf = packbuf; else inbuf = midbuf; + if (ispacked) inbuf = packbuf; else inbuf = midbuf; - if ((pict->format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) || - (pict->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)) { offs = 0; stride = 8; } - else if ((pict->format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) || - (pict->format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) { offs = 8; stride = 16; } - else { offs = 0; stride = 8; } - - if (stride == 16) //If DXT3... - { - //alpha_4x4 - if (kread(fil,&cleng,4) < 4) return -1; cleng = B_LITTLE32(cleng); - j = (pict->size/stride)*8; + if ((pict->format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) || + (pict->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)) { offs = 0; stride = 8; } + else if ((pict->format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) || + (pict->format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) { offs = 8; stride = 16; } + else { offs = 0; stride = 8; } + + if (stride == 16) //If DXT3... + { + //alpha_4x4 + if (kread(fil,&cleng,4) < 4) return -1; cleng = B_LITTLE32(cleng); + j = (pict->size/stride)*8; #ifdef USELZF - if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && cleng < j) - if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; + if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && cleng < j) + if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; #else - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; #endif - cptr = midbuf; - for(k=0;k<8;k++) pic[k] = *cptr++; - for(j=stride;jsize;j+=stride) - for(k=0;k<8;k++) pic[j+k] = (*cptr++); - } - - //rgb0,rgb1 - if (kread(fil,&cleng,4) < 4) return -1; cleng = B_LITTLE32(cleng); - j = (pict->size/stride)*4; -#ifdef USELZF - if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && cleng < j) - if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; -#else - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; -#endif - cptr = midbuf; - for(k=0;k<=2;k+=2) - for(j=0;jsize;j+=stride) - { - *(short *)(&pic[offs+j+k]) = hicoadd(*(short *)cptr); - cptr += 2; - } - - //index_4x4: + cptr = midbuf; + for(k=0;k<8;k++) pic[k] = *cptr++; + for(j=stride;jsize;j+=stride) + for(k=0;k<8;k++) pic[j+k] = (*cptr++); + } + + //rgb0,rgb1 if (kread(fil,&cleng,4) < 4) return -1; cleng = B_LITTLE32(cleng); - j = (pict->size/stride)*4; + j = (pict->size/stride)*4; #ifdef USELZF - if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && cleng < j) - if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; + if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && cleng < j) + if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; #else - if (kread(fil,inbuf,cleng) < cleng) return -1; - if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; #endif - cptr = midbuf; - for(j=0;jsize;j+=stride) - { - pic[j+offs+4] = ((cptr[0]>>0)&3) + (((cptr[1]>>0)&3)<<2) + (((cptr[2]>>0)&3)<<4) + (((cptr[3]>>0)&3)<<6); - pic[j+offs+5] = ((cptr[0]>>2)&3) + (((cptr[1]>>2)&3)<<2) + (((cptr[2]>>2)&3)<<4) + (((cptr[3]>>2)&3)<<6); - pic[j+offs+6] = ((cptr[0]>>4)&3) + (((cptr[1]>>4)&3)<<2) + (((cptr[2]>>4)&3)<<4) + (((cptr[3]>>4)&3)<<6); - pic[j+offs+7] = ((cptr[0]>>6)&3) + (((cptr[1]>>6)&3)<<2) + (((cptr[2]>>6)&3)<<4) + (((cptr[3]>>6)&3)<<6); - cptr += 4; - } + cptr = midbuf; + for(k=0;k<=2;k+=2) + for(j=0;jsize;j+=stride) + { + *(short *)(&pic[offs+j+k]) = hicoadd(*(short *)cptr); + cptr += 2; + } + + //index_4x4: + if (kread(fil,&cleng,4) < 4) return -1; cleng = B_LITTLE32(cleng); + j = (pict->size/stride)*4; +#ifdef USELZF + if (ispacked && cleng < j) inbuf = packbuf; else inbuf = midbuf; + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && cleng < j) + if (lzf_decompress(packbuf,cleng,midbuf,j) == 0) return -1; +#else + if (kread(fil,inbuf,cleng) < cleng) return -1; + if (ispacked && lzwuncompress(packbuf,cleng,midbuf,j) != j) return -1; #endif - return 0; + cptr = midbuf; + for(j=0;jsize;j+=stride) + { + pic[j+offs+4] = ((cptr[0]>>0)&3) + (((cptr[1]>>0)&3)<<2) + (((cptr[2]>>0)&3)<<4) + (((cptr[3]>>0)&3)<<6); + pic[j+offs+5] = ((cptr[0]>>2)&3) + (((cptr[1]>>2)&3)<<2) + (((cptr[2]>>2)&3)<<4) + (((cptr[3]>>2)&3)<<6); + pic[j+offs+6] = ((cptr[0]>>4)&3) + (((cptr[1]>>4)&3)<<2) + (((cptr[2]>>4)&3)<<4) + (((cptr[3]>>4)&3)<<6); + pic[j+offs+7] = ((cptr[0]>>6)&3) + (((cptr[1]>>6)&3)<<2) + (((cptr[2]>>6)&3)<<4) + (((cptr[3]>>6)&3)<<6); + cptr += 4; + } +#endif + return 0; } // vim:ts=4:sw=4: diff --git a/polymer/build/src/pragmas.c b/polymer/build/src/pragmas.c index 6b29640bb..5b8edbf70 100644 --- a/polymer/build/src/pragmas.c +++ b/polymer/build/src/pragmas.c @@ -32,50 +32,50 @@ void qinterpolatedown16short(long bufptr, long num, long val, long add) void clearbuf(void *d, long c, long a) { - long *p = (long*)d; - while ((c--) > 0) *(p++) = a; + long *p = (long*)d; + while ((c--) > 0) *(p++) = a; } void copybuf(void *s, void *d, long c) { - long *p = (long*)s, *q = (long*)d; - while ((c--) > 0) *(q++) = *(p++); + long *p = (long*)s, *q = (long*)d; + while ((c--) > 0) *(q++) = *(p++); } void swapbuf4(void *a, void *b, long c) { - long *p = (long*)a, *q = (long*)b; - long x, y; - while ((c--) > 0) { - x = *q; - y = *p; - *(q++) = y; - *(p++) = x; - } + long *p = (long*)a, *q = (long*)b; + long x, y; + while ((c--) > 0) { + x = *q; + y = *p; + *(q++) = y; + *(p++) = x; + } } void clearbufbyte(void *D, long c, long a) { // Cringe City - char *p = (char*)D; - long m[4] = { 0xffl,0xff00l,0xff0000l,0xff000000l }; - long n[4] = { 0,8,16,24 }; - long z=0; - while ((c--) > 0) { - *(p++) = (char)((a & m[z])>>n[z]); - z=(z+1)&3; - } + char *p = (char*)D; + long m[4] = { 0xffl,0xff00l,0xff0000l,0xff000000l }; + long n[4] = { 0,8,16,24 }; + long z=0; + while ((c--) > 0) { + *(p++) = (char)((a & m[z])>>n[z]); + z=(z+1)&3; + } } void copybufbyte(void *S, void *D, long c) { - char *p = (char*)S, *q = (char*)D; - while((c--) > 0) *(q++) = *(p++); + char *p = (char*)S, *q = (char*)D; + while((c--) > 0) *(q++) = *(p++); } void copybufreverse(void *S, void *D, long c) { - char *p = (char*)S, *q = (char*)D; - while((c--) > 0) *(q++) = *(p--); + char *p = (char*)S, *q = (char*)D; + while((c--) > 0) *(q++) = *(p--); } #elif defined(__GNUC__) && defined(__i386__) // NOASM @@ -89,144 +89,144 @@ void copybufreverse(void *S, void *D, long c) long boundmulscale(long a, long b, long c) { - ASM ( - "imull %%ebx\n\t" - "movl %%edx, %%ebx\n\t" // mov ebx, edx - "shrdl %%cl, %%edx, %%eax\n\t" // mov eax, edx, cl - "sarl %%cl, %%edx\n\t" // sar edx, cl - "xorl %%eax, %%edx\n\t" // xor edx, eax - "js 0f\n\t" // js checkit - "xorl %%eax, %%edx\n\t" // xor edx, eax - "jz 1f\n\t" // js skipboundit - "cmpl $0xffffffff, %%edx\n\t" // cmp edx, 0xffffffff - "je 1f\n\t" // je skipboundit - "0:\n\t" // checkit: - "movl %%ebx, %%eax\n\t" // mov eax, ebx - "sarl $31, %%eax\n\t" // sar eax, 31 - "xorl $0x7fffffff, %%eax\n\t" // xor eax, 0x7fffffff - "1:" // skipboundit: - : "+a" (a), "+b" (b), "+c" (c) // input eax ebx ecx - : - : "edx", "cc" - ); - return a; + ASM ( + "imull %%ebx\n\t" + "movl %%edx, %%ebx\n\t" // mov ebx, edx + "shrdl %%cl, %%edx, %%eax\n\t" // mov eax, edx, cl + "sarl %%cl, %%edx\n\t" // sar edx, cl + "xorl %%eax, %%edx\n\t" // xor edx, eax + "js 0f\n\t" // js checkit + "xorl %%eax, %%edx\n\t" // xor edx, eax + "jz 1f\n\t" // js skipboundit + "cmpl $0xffffffff, %%edx\n\t" // cmp edx, 0xffffffff + "je 1f\n\t" // je skipboundit + "0:\n\t" // checkit: + "movl %%ebx, %%eax\n\t" // mov eax, ebx + "sarl $31, %%eax\n\t" // sar eax, 31 + "xorl $0x7fffffff, %%eax\n\t" // xor eax, 0x7fffffff + "1:" // skipboundit: + : "+a" (a), "+b" (b), "+c" (c) // input eax ebx ecx + : + : "edx", "cc" + ); + return a; } void clearbufbyte(void *D, long c, long a) { - ASM ( - "cmpl $4, %%ecx\n\t" - "jae 1f\n\t" - "testb $1, %%cl\n\t" - "jz 0f\n\t" // jz preskip - "stosb\n\t" - "0:\n\t" // preskip: - "shrl $1, %%ecx\n\t" - "rep\n\t" - "stosw\n\t" - "jmp 5f\n\t" // jmp endit - "1:\n\t" // intcopy: - "testl $1, %%edi\n\t" - "jz 2f\n\t" // jz skip1 - "stosb\n\t" - "decl %%ecx\n\t" - "2:\n\t" // skip1: - "testl $2, %%edi\n\t" - "jz 3f\n\t" // jz skip2 - "stosw\n\t" - "subl $2, %%ecx\n\t" - "3:\n\t" // skip2: - "movl %%ecx, %%ebx\n\t" - "shrl $2, %%ecx\n\t" - "rep\n\t" - "stosl\n\t" - "testb $2, %%bl\n\t" - "jz 4f\n\t" // jz skip3 - "stosw\n\t" - "4:\n\t" // skip3: - "testb $1, %%bl\n\t" - "jz 5f\n\t" // jz endit - "stosb\n\t" - "5:" // endit - : "+D" (D), "+c" (c), "+a" (a) : - : "ebx", "memory", "cc" - ); + ASM ( + "cmpl $4, %%ecx\n\t" + "jae 1f\n\t" + "testb $1, %%cl\n\t" + "jz 0f\n\t" // jz preskip + "stosb\n\t" + "0:\n\t" // preskip: + "shrl $1, %%ecx\n\t" + "rep\n\t" + "stosw\n\t" + "jmp 5f\n\t" // jmp endit + "1:\n\t" // intcopy: + "testl $1, %%edi\n\t" + "jz 2f\n\t" // jz skip1 + "stosb\n\t" + "decl %%ecx\n\t" + "2:\n\t" // skip1: + "testl $2, %%edi\n\t" + "jz 3f\n\t" // jz skip2 + "stosw\n\t" + "subl $2, %%ecx\n\t" + "3:\n\t" // skip2: + "movl %%ecx, %%ebx\n\t" + "shrl $2, %%ecx\n\t" + "rep\n\t" + "stosl\n\t" + "testb $2, %%bl\n\t" + "jz 4f\n\t" // jz skip3 + "stosw\n\t" + "4:\n\t" // skip3: + "testb $1, %%bl\n\t" + "jz 5f\n\t" // jz endit + "stosb\n\t" + "5:" // endit + : "+D" (D), "+c" (c), "+a" (a) : + : "ebx", "memory", "cc" + ); } void copybufbyte(void *S, void *D, long c) { - ASM ( - "cmpl $4, %%ecx\n\t" // cmp ecx, 4 - "jae 1f\n\t" - "testb $1, %%cl\n\t" // test cl, 1 - "jz 0f\n\t" - "movsb\n\t" - "0:\n\t" // preskip: - "shrl $1, %%ecx\n\t" // shr ecx, 1 - "rep\n\t" - "movsw\n\t" - "jmp 5f\n\t" - "1:\n\t" // intcopy: - "testl $1, %%edi\n\t" // test edi, 1 - "jz 2f\n\t" - "movsb\n\t" - "decl %%ecx\n\t" - "2:\n\t" // skip1: - "testl $2, %%edi\n\t" // test edi, 2 - "jz 3f\n\t" - "movsw\n\t" - "subl $2, %%ecx\n\t" // sub ecx, 2 - "3:\n\t" // skip2: - "movl %%ecx, %%ebx\n\t" // mov ebx, ecx - "shrl $2, %%ecx\n\t" // shr ecx ,2 - "rep\n\t" - "movsl\n\t" - "testb $2, %%bl\n\t" // test bl, 2 - "jz 4f\n\t" - "movsw\n\t" - "4:\n\t" // skip3: - "testb $1, %%bl\n\t" // test bl, 1 - "jz 5f\n\t" - "movsb\n\t" - "5:" // endit: - : "+c" (c), "+S" (S), "+D" (D) : - : "ebx", "memory", "cc" - ); + ASM ( + "cmpl $4, %%ecx\n\t" // cmp ecx, 4 + "jae 1f\n\t" + "testb $1, %%cl\n\t" // test cl, 1 + "jz 0f\n\t" + "movsb\n\t" + "0:\n\t" // preskip: + "shrl $1, %%ecx\n\t" // shr ecx, 1 + "rep\n\t" + "movsw\n\t" + "jmp 5f\n\t" + "1:\n\t" // intcopy: + "testl $1, %%edi\n\t" // test edi, 1 + "jz 2f\n\t" + "movsb\n\t" + "decl %%ecx\n\t" + "2:\n\t" // skip1: + "testl $2, %%edi\n\t" // test edi, 2 + "jz 3f\n\t" + "movsw\n\t" + "subl $2, %%ecx\n\t" // sub ecx, 2 + "3:\n\t" // skip2: + "movl %%ecx, %%ebx\n\t" // mov ebx, ecx + "shrl $2, %%ecx\n\t" // shr ecx ,2 + "rep\n\t" + "movsl\n\t" + "testb $2, %%bl\n\t" // test bl, 2 + "jz 4f\n\t" + "movsw\n\t" + "4:\n\t" // skip3: + "testb $1, %%bl\n\t" // test bl, 1 + "jz 5f\n\t" + "movsb\n\t" + "5:" // endit: + : "+c" (c), "+S" (S), "+D" (D) : + : "ebx", "memory", "cc" + ); } void copybufreverse(void *S, void *D, long c) { - ASM ( - "shrl $1, %%ecx\n\t" - "jnc 0f\n\t" // jnc skipit1 - "movb (%%esi), %%al\n\t" - "decl %%esi\n\t" - "movb %%al, (%%edi)\n\t" - "incl %%edi\n\t" - "0:\n\t" // skipit1: - "shrl $1, %%ecx\n\t" - "jnc 1f\n\t" // jnc skipit2 - "movw -1(%%esi), %%ax\n\t" - "subl $2, %%esi\n\t" - "rorw $8, %%ax\n\t" - "movw %%ax, (%%edi)\n\t" - "addl $2, %%edi\n\t" - "1:\n\t" // skipit2 - "testl %%ecx, %%ecx\n\t" - "jz 3f\n\t" // jz endloop - "2:\n\t" // begloop - "movl -3(%%esi), %%eax\n\t" - "subl $4, %%esi\n\t" - "bswapl %%eax\n\t" - "movl %%eax, (%%edi)\n\t" - "addl $4, %%edi\n\t" - "decl %%ecx\n\t" - "jnz 2b\n\t" // jnz begloop - "3:" - : "+S" (S), "+D" (D), "+c" (c) : - : "eax", "memory", "cc" - ); + ASM ( + "shrl $1, %%ecx\n\t" + "jnc 0f\n\t" // jnc skipit1 + "movb (%%esi), %%al\n\t" + "decl %%esi\n\t" + "movb %%al, (%%edi)\n\t" + "incl %%edi\n\t" + "0:\n\t" // skipit1: + "shrl $1, %%ecx\n\t" + "jnc 1f\n\t" // jnc skipit2 + "movw -1(%%esi), %%ax\n\t" + "subl $2, %%esi\n\t" + "rorw $8, %%ax\n\t" + "movw %%ax, (%%edi)\n\t" + "addl $2, %%edi\n\t" + "1:\n\t" // skipit2 + "testl %%ecx, %%ecx\n\t" + "jz 3f\n\t" // jz endloop + "2:\n\t" // begloop + "movl -3(%%esi), %%eax\n\t" + "subl $4, %%esi\n\t" + "bswapl %%eax\n\t" + "movl %%eax, (%%edi)\n\t" + "addl $4, %%edi\n\t" + "decl %%ecx\n\t" + "jnz 2b\n\t" // jnz begloop + "3:" + : "+S" (S), "+D" (D), "+c" (c) : + : "eax", "memory", "cc" + ); } #elif defined(__WATCOMC__) // __GNUC__ && __i386__ diff --git a/polymer/build/src/scriptfile.c b/polymer/build/src/scriptfile.c index c7cb9d1d8..deb6b1d03 100644 --- a/polymer/build/src/scriptfile.c +++ b/polymer/build/src/scriptfile.c @@ -18,307 +18,307 @@ static void skipovertoken(scriptfile *sf) { while ((sf->textptr < sf->eof) && (s char *scriptfile_gettoken(scriptfile *sf) { - char *start; + char *start; - skipoverws(sf); - if (sf->textptr >= sf->eof) return NULL; + skipoverws(sf); + if (sf->textptr >= sf->eof) return NULL; - start = sf->ltextptr = sf->textptr; - skipovertoken(sf); - return start; + start = sf->ltextptr = sf->textptr; + skipovertoken(sf); + return start; } int scriptfile_getstring(scriptfile *sf, char **retst) { - (*retst) = scriptfile_gettoken(sf); - if (*retst == NULL) - { - initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); - return(-2); - } - return(0); + (*retst) = scriptfile_gettoken(sf); + if (*retst == NULL) + { + initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); + return(-2); + } + return(0); } int scriptfile_getnumber(scriptfile *sf, int *num) { - skipoverws(sf); - if (sf->textptr >= sf->eof) - { - initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); - return -1; - } + skipoverws(sf); + if (sf->textptr >= sf->eof) + { + initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); + return -1; + } - while ((sf->textptr[0] == '0') && (sf->textptr[1] >= '0') && (sf->textptr[1] <= '9')) - sf->textptr++; //hack to treat octal numbers like decimal - - sf->ltextptr = sf->textptr; - (*num) = strtol((const char *)sf->textptr,&sf->textptr,0); - if (!ISWS(*sf->textptr) && *sf->textptr) { - char *p = sf->textptr; - skipovertoken(sf); - initprintf("Error on line %s:%d: expecting int, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); - return -2; - } - return 0; + while ((sf->textptr[0] == '0') && (sf->textptr[1] >= '0') && (sf->textptr[1] <= '9')) + sf->textptr++; //hack to treat octal numbers like decimal + + sf->ltextptr = sf->textptr; + (*num) = strtol((const char *)sf->textptr,&sf->textptr,0); + if (!ISWS(*sf->textptr) && *sf->textptr) { + char *p = sf->textptr; + skipovertoken(sf); + initprintf("Error on line %s:%d: expecting int, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); + return -2; + } + return 0; } static double parsedouble(char *ptr, char **end) { - int beforedecimal = 1, negative = 0, dig; - int exposgn = 0, expo = 0; - double num = 0.0, decpl = 0.1; - char *p; - - p = ptr; - if (*p == '-') negative = 1, p++; - else if (*p == '+') p++; - for (;; p++) { - if (*p >= '0' && *p <= '9') { - dig = *p - '0'; - if (beforedecimal) num = num * 10.0 + dig; - else if (exposgn) expo = expo*10 + dig; - else { - num += (double)dig * decpl; - decpl /= 10.0; - } - } else if (*p == '.') { - if (beforedecimal) beforedecimal = 0; - else break; - } else if ((*p == 'E') || (*p == 'e')) { - exposgn = 1; - if (p[1] == '-') { exposgn = -1; p++; } - else if (p[1] == '+') p++; - } else break; - } - - if (end) *end = p; - if (exposgn) num *= pow(10.0,(double)(expo*exposgn)); - return negative ? -num : num; + int beforedecimal = 1, negative = 0, dig; + int exposgn = 0, expo = 0; + double num = 0.0, decpl = 0.1; + char *p; + + p = ptr; + if (*p == '-') negative = 1, p++; + else if (*p == '+') p++; + for (;; p++) { + if (*p >= '0' && *p <= '9') { + dig = *p - '0'; + if (beforedecimal) num = num * 10.0 + dig; + else if (exposgn) expo = expo*10 + dig; + else { + num += (double)dig * decpl; + decpl /= 10.0; + } + } else if (*p == '.') { + if (beforedecimal) beforedecimal = 0; + else break; + } else if ((*p == 'E') || (*p == 'e')) { + exposgn = 1; + if (p[1] == '-') { exposgn = -1; p++; } + else if (p[1] == '+') p++; + } else break; + } + + if (end) *end = p; + if (exposgn) num *= pow(10.0,(double)(expo*exposgn)); + return negative ? -num : num; } int scriptfile_getdouble(scriptfile *sf, double *num) { - skipoverws(sf); - if (sf->textptr >= sf->eof) - { - initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); - return -1; - } - - sf->ltextptr = sf->textptr; + skipoverws(sf); + if (sf->textptr >= sf->eof) + { + initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); + return -1; + } - // On Linux, locale settings interfere with interpreting x.y format numbers - //(*num) = strtod((const char *)sf->textptr,&sf->textptr); - (*num) = parsedouble(sf->textptr, &sf->textptr); - - if (!ISWS(*sf->textptr) && *sf->textptr) { - char *p = sf->textptr; - skipovertoken(sf); - initprintf("Error on line %s:%d: expecting float, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); - return -2; - } - return 0; + sf->ltextptr = sf->textptr; + + // On Linux, locale settings interfere with interpreting x.y format numbers + //(*num) = strtod((const char *)sf->textptr,&sf->textptr); + (*num) = parsedouble(sf->textptr, &sf->textptr); + + if (!ISWS(*sf->textptr) && *sf->textptr) { + char *p = sf->textptr; + skipovertoken(sf); + initprintf("Error on line %s:%d: expecting float, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); + return -2; + } + return 0; } int scriptfile_getsymbol(scriptfile *sf, int *num) { - char *t, *e; - int v; + char *t, *e; + int v; - t = scriptfile_gettoken(sf); - if (!t) return -1; + t = scriptfile_gettoken(sf); + if (!t) return -1; - v = Bstrtol(t, &e, 10); - if (*e) { - // looks like a string, so find it in the symbol table - if (scriptfile_getsymbolvalue(t, num)) return 0; - initprintf("Error on line %s:%d: expecting symbol, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),t); - return -2; // not found - } + v = Bstrtol(t, &e, 10); + if (*e) { + // looks like a string, so find it in the symbol table + if (scriptfile_getsymbolvalue(t, num)) return 0; + initprintf("Error on line %s:%d: expecting symbol, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),t); + return -2; // not found + } - *num = v; - return 0; + *num = v; + return 0; } int scriptfile_getbraces(scriptfile *sf, char **braceend) { - int bracecnt; - char *bracestart; + int bracecnt; + char *bracestart; - skipoverws(sf); - if (sf->textptr >= sf->eof) - { - initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); - return -1; - } + skipoverws(sf); + if (sf->textptr >= sf->eof) + { + initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); + return -1; + } - if (sf->textptr[0] != '{') { - initprintf("Error on line %s:%d: expecting '{'\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); - return -1; - } - bracestart = ++sf->textptr; bracecnt = 1; - while (1) - { - if (sf->textptr >= sf->eof) return(0); - if (sf->textptr[0] == '{') bracecnt++; - if (sf->textptr[0] == '}') { bracecnt--; if (!bracecnt) break; } - sf->textptr++; - } - (*braceend) = sf->textptr; - sf->textptr = bracestart; - return 0; + if (sf->textptr[0] != '{') { + initprintf("Error on line %s:%d: expecting '{'\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); + return -1; + } + bracestart = ++sf->textptr; bracecnt = 1; + while (1) + { + if (sf->textptr >= sf->eof) return(0); + if (sf->textptr[0] == '{') bracecnt++; + if (sf->textptr[0] == '}') { bracecnt--; if (!bracecnt) break; } + sf->textptr++; + } + (*braceend) = sf->textptr; + sf->textptr = bracestart; + return 0; } int scriptfile_getlinum (scriptfile *sf, char *ptr) { - int i, stp, ind; + int i, stp, ind; - //for(i=0;ilinenum;i++) if (sf->lineoffs[i] >= ind) return(i+1); //brute force algo + //for(i=0;ilinenum;i++) if (sf->lineoffs[i] >= ind) return(i+1); //brute force algo - ind = ((long)ptr) - ((long)sf->textbuf); + ind = ((long)ptr) - ((long)sf->textbuf); - for(stp=1;stp+stplinenum;stp+=stp); //stp = highest power of 2 less than sf->linenum - for(i=0;stp;stp>>=1) - if ((i+stp < sf->linenum) && (sf->lineoffs[i+stp] < ind)) i += stp; - return(i+1); //i = index to highest lineoffs which is less than ind; convert to 1-based line numbers + for(stp=1;stp+stplinenum;stp+=stp); //stp = highest power of 2 less than sf->linenum + for(i=0;stp;stp>>=1) + if ((i+stp < sf->linenum) && (sf->lineoffs[i+stp] < ind)) i += stp; + return(i+1); //i = index to highest lineoffs which is less than ind; convert to 1-based line numbers } void scriptfile_preparse (scriptfile *sf, char *tx, long flen) { - long i, cr, numcr, nflen, ws, cs, inquote; + long i, cr, numcr, nflen, ws, cs, inquote; - //Count number of lines - numcr = 1; - for(i=0;ilinenum = numcr; - sf->lineoffs = (long *)malloc(sf->linenum*sizeof(long)); + sf->linenum = numcr; + sf->lineoffs = (long *)malloc(sf->linenum*sizeof(long)); - //Preprocess file for comments (// and /*...*/, and convert all whitespace to single spaces) - nflen = 0; ws = 0; cs = 0; numcr = 0; inquote = 0; - for(i=0;ilineoffs[numcr++] = nflen; - if (cs == 1) cs = 0; - ws = 1; continue; //strip CR/LF - } + //Preprocess file for comments (// and /*...*/, and convert all whitespace to single spaces) + nflen = 0; ws = 0; cs = 0; numcr = 0; inquote = 0; + for(i=0;ilineoffs[numcr++] = nflen; + if (cs == 1) cs = 0; + ws = 1; continue; //strip CR/LF + } - if ((!inquote) && ((tx[i] == ' ') || (tx[i] == '\t'))) { ws = 1; continue; } //strip Space/Tab - if ((tx[i] == '/') && (tx[i+1] == '/') && (!cs)) cs = 1; - if ((tx[i] == '/') && (tx[i+1] == '*') && (!cs)) { ws = 1; cs = 2; } - if ((tx[i] == '*') && (tx[i+1] == '/') && (cs == 2)) { cs = 0; i++; continue; } - if (cs) continue; + if ((!inquote) && ((tx[i] == ' ') || (tx[i] == '\t'))) { ws = 1; continue; } //strip Space/Tab + if ((tx[i] == '/') && (tx[i+1] == '/') && (!cs)) cs = 1; + if ((tx[i] == '/') && (tx[i+1] == '*') && (!cs)) { ws = 1; cs = 2; } + if ((tx[i] == '*') && (tx[i+1] == '/') && (cs == 2)) { cs = 0; i++; continue; } + if (cs) continue; - if (ws) { tx[nflen++] = 0; ws = 0; } + if (ws) { tx[nflen++] = 0; ws = 0; } - //quotes inside strings: \" - if ((tx[i] == '\\') && (tx[i+1] == '\"')) { i++; tx[nflen++] = '\"'; continue; } - if (tx[i] == '\"') { inquote ^= 1; continue; } - tx[nflen++] = tx[i]; - } - tx[nflen++] = 0; sf->lineoffs[numcr] = nflen; - tx[nflen++] = 0; + //quotes inside strings: \" + if ((tx[i] == '\\') && (tx[i+1] == '\"')) { i++; tx[nflen++] = '\"'; continue; } + if (tx[i] == '\"') { inquote ^= 1; continue; } + tx[nflen++] = tx[i]; + } + tx[nflen++] = 0; sf->lineoffs[numcr] = nflen; + tx[nflen++] = 0; #if 0 - //for debugging only: - printf("pre-parsed file:flen=%d,nflen=%d\n",flen,nflen); - for(i=0;ilinenum); - for(i=0;ilinenum;i++) printf("line %d = byte %d\n",i,sf->lineoffs[i]); + //for debugging only: + printf("pre-parsed file:flen=%d,nflen=%d\n",flen,nflen); + for(i=0;ilinenum); + for(i=0;ilinenum;i++) printf("line %d = byte %d\n",i,sf->lineoffs[i]); #endif - flen = nflen; + flen = nflen; - sf->textbuf = sf->textptr = tx; - sf->textlength = nflen; - sf->eof = &sf->textbuf[nflen-1]; + sf->textbuf = sf->textptr = tx; + sf->textlength = nflen; + sf->eof = &sf->textbuf[nflen-1]; } scriptfile *scriptfile_fromfile(char *fn) { - int fp; - scriptfile *sf; - char *tx; - unsigned int flen; + int fp; + scriptfile *sf; + char *tx; + unsigned int flen; - fp = kopen4load(fn,0); - if (fp<0) return NULL; + fp = kopen4load(fn,0); + if (fp<0) return NULL; - flen = kfilelength(fp); - tx = (char *) malloc(flen + 2); - if (!tx) { - kclose(fp); - return NULL; - } + flen = kfilelength(fp); + tx = (char *) malloc(flen + 2); + if (!tx) { + kclose(fp); + return NULL; + } - sf = (scriptfile*) malloc(sizeof(scriptfile)); - if (!sf) { - kclose(fp); - free(tx); - return NULL; - } + sf = (scriptfile*) malloc(sizeof(scriptfile)); + if (!sf) { + kclose(fp); + free(tx); + return NULL; + } - kread(fp, tx, flen); - tx[flen] = tx[flen+1] = 0; + kread(fp, tx, flen); + tx[flen] = tx[flen+1] = 0; - kclose(fp); + kclose(fp); - scriptfile_preparse(sf,tx,flen); - sf->filename = strdup(fn); + scriptfile_preparse(sf,tx,flen); + sf->filename = strdup(fn); - return sf; + return sf; } scriptfile *scriptfile_fromstring(char *string) { - scriptfile *sf; - char *tx; - unsigned int flen; + scriptfile *sf; + char *tx; + unsigned int flen; - if (!string) return NULL; + if (!string) return NULL; - flen = strlen(string); + flen = strlen(string); - tx = (char *) malloc(flen + 2); - if (!tx) return NULL; + tx = (char *) malloc(flen + 2); + if (!tx) return NULL; - sf = (scriptfile*) malloc(sizeof(scriptfile)); - if (!sf) { - free(tx); - return NULL; - } + sf = (scriptfile*) malloc(sizeof(scriptfile)); + if (!sf) { + free(tx); + return NULL; + } - memcpy(tx, string, flen); - tx[flen] = tx[flen+1] = 0; + memcpy(tx, string, flen); + tx[flen] = tx[flen+1] = 0; - scriptfile_preparse(sf,tx,flen); - sf->filename = NULL; + scriptfile_preparse(sf,tx,flen); + sf->filename = NULL; - return sf; + return sf; } void scriptfile_close(scriptfile *sf) { - if (!sf) return; - if (sf->lineoffs) free(sf->lineoffs); - if (sf->textbuf) free(sf->textbuf); - if (sf->filename) free(sf->filename); - sf->textbuf = NULL; - sf->filename = NULL; - free(sf); + if (!sf) return; + if (sf->lineoffs) free(sf->lineoffs); + if (sf->textbuf) free(sf->textbuf); + if (sf->filename) free(sf->filename); + sf->textbuf = NULL; + sf->filename = NULL; + free(sf); } @@ -328,68 +328,68 @@ static char *symbtab = NULL; static char * getsymbtabspace(int reqd) { - char *pos,*np; - int i; + char *pos,*np; + int i; - if (symbtablength + reqd > symbtaballoclength) - { - for(i=max(symbtaballoclength,SYMBTABSTARTSIZE);symbtablength+reqd>i;i<<=1); - np = (char *)realloc(symbtab, i); if (!np) return NULL; - symbtab = np; symbtaballoclength = i; - } + if (symbtablength + reqd > symbtaballoclength) + { + for(i=max(symbtaballoclength,SYMBTABSTARTSIZE);symbtablength+reqd>i;i<<=1); + np = (char *)realloc(symbtab, i); if (!np) return NULL; + symbtab = np; symbtaballoclength = i; + } - pos = &symbtab[symbtablength]; - symbtablength += reqd; - return pos; + pos = &symbtab[symbtablength]; + symbtablength += reqd; + return pos; } int scriptfile_getsymbolvalue(char *name, int *val) { - char *scanner = symbtab; + char *scanner = symbtab; - if (!symbtab) return 0; - while (scanner - symbtab < symbtablength) { - if (!Bstrcasecmp(name, scanner)) { - *val = *(int*)(scanner + strlen(scanner) + 1); - return 1; - } + if (!symbtab) return 0; + while (scanner - symbtab < symbtablength) { + if (!Bstrcasecmp(name, scanner)) { + *val = *(int*)(scanner + strlen(scanner) + 1); + return 1; + } - scanner += strlen(scanner) + 1 + sizeof(int); - } + scanner += strlen(scanner) + 1 + sizeof(int); + } - return 0; + return 0; } int scriptfile_addsymbolvalue(char *name, int val) { - int x; - char *sp; -// if (scriptfile_getsymbolvalue(name, &x)) return -1; // already exists + int x; + char *sp; + // if (scriptfile_getsymbolvalue(name, &x)) return -1; // already exists - if (symbtab) { - char *scanner = symbtab; - while (scanner - symbtab < symbtablength) { - if (!Bstrcasecmp(name, scanner)) { - *(int*)(scanner + strlen(scanner) + 1) = val; - return 1; - } + if (symbtab) { + char *scanner = symbtab; + while (scanner - symbtab < symbtablength) { + if (!Bstrcasecmp(name, scanner)) { + *(int*)(scanner + strlen(scanner) + 1) = val; + return 1; + } - scanner += strlen(scanner) + 1 + sizeof(int); - } - } - - sp = getsymbtabspace(strlen(name) + 1 + sizeof(int)); - if (!sp) return 0; - strcpy(sp, name); - sp += strlen(name)+1; - *(int*)sp = val; - return 1; // added + scanner += strlen(scanner) + 1 + sizeof(int); + } + } + + sp = getsymbtabspace(strlen(name) + 1 + sizeof(int)); + if (!sp) return 0; + strcpy(sp, name); + sp += strlen(name)+1; + *(int*)sp = val; + return 1; // added } void scriptfile_clearsymbols(void) { - if (symbtab) free(symbtab); - symbtab = NULL; - symbtablength = 0; - symbtaballoclength = 0; + if (symbtab) free(symbtab); + symbtab = NULL; + symbtablength = 0; + symbtaballoclength = 0; } diff --git a/polymer/build/src/sdlayer.c b/polymer/build/src/sdlayer.c index 2bccd9cbb..f5ead1424 100644 --- a/polymer/build/src/sdlayer.c +++ b/polymer/build/src/sdlayer.c @@ -78,60 +78,60 @@ static SDL_Surface * loadappicon(void); int wm_msgbox(char *name, char *fmt, ...) { - char buf[1000]; - va_list va; + char buf[1000]; + va_list va; - va_start(va,fmt); - vsprintf(buf,fmt,va); - va_end(va); + va_start(va,fmt); + vsprintf(buf,fmt,va); + va_end(va); #if defined(__APPLE__) - return osx_msgbox(name, buf); + return osx_msgbox(name, buf); #elif defined HAVE_GTK2 - if (gtkbuild_msgbox(name, buf) >= 0) return 1; + if (gtkbuild_msgbox(name, buf) >= 0) return 1; #endif - puts(buf); - puts(" (press Return or Enter to continue)"); - getchar(); + puts(buf); + puts(" (press Return or Enter to continue)"); + getchar(); - return 0; + return 0; } int wm_ynbox(char *name, char *fmt, ...) { - char buf[1000]; - char c; - va_list va; - int r; + char buf[1000]; + char c; + va_list va; + int r; - va_start(va,fmt); - vsprintf(buf,fmt,va); - va_end(va); + va_start(va,fmt); + vsprintf(buf,fmt,va); + va_end(va); #if defined __APPLE__ - return osx_ynbox(name, buf); + return osx_ynbox(name, buf); #elif defined HAVE_GTK2 - if ((r = gtkbuild_ynbox(name, buf)) >= 0) return r; + if ((r = gtkbuild_ynbox(name, buf)) >= 0) return r; #endif - puts(buf); - puts(" (type 'Y' or 'N', and press Return or Enter to continue)"); - do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n'); - if (c == 'Y' || c == 'y') return 1; + puts(buf); + puts(" (type 'Y' or 'N', and press Return or Enter to continue)"); + do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n'); + if (c == 'Y' || c == 'y') return 1; - return 0; + return 0; } void wm_setapptitle(char *name) { - if (name) { - Bstrncpy(apptitle, name, sizeof(apptitle)-1); - apptitle[ sizeof(apptitle)-1 ] = 0; - } + if (name) { + Bstrncpy(apptitle, name, sizeof(apptitle)-1); + apptitle[ sizeof(apptitle)-1 ] = 0; + } - SDL_WM_SetCaption(apptitle, NULL); + SDL_WM_SetCaption(apptitle, NULL); #ifdef HAVE_GTK2 - gtkbuild_settitle_startwin(apptitle); + gtkbuild_settitle_startwin(apptitle); #endif } @@ -148,28 +148,28 @@ void wm_setapptitle(char *name) int main(int argc, char *argv[]) { - int r; - - buildkeytranslationtable(); - -#ifdef HAVE_GTK2 - gtkbuild_init(&argc, &argv); - gtkbuild_create_startwin(); -#endif + int r; - _buildargc = argc; - _buildargv = (char**)argv; - //_buildargv = (char**)malloc(argc * sizeof(char*)); - //memcpy(_buildargv, argv, sizeof(char*)*argc); - - baselayer_init(); - r = app_main(argc, argv); + buildkeytranslationtable(); #ifdef HAVE_GTK2 - gtkbuild_close_startwin(); - gtkbuild_exit(r); + gtkbuild_init(&argc, &argv); + gtkbuild_create_startwin(); #endif - return r; + + _buildargc = argc; + _buildargv = (char**)argv; + //_buildargv = (char**)malloc(argc * sizeof(char*)); + //memcpy(_buildargv, argv, sizeof(char*)*argc); + + baselayer_init(); + r = app_main(argc, argv); + +#ifdef HAVE_GTK2 + gtkbuild_close_startwin(); + gtkbuild_exit(r); +#endif + return r; } @@ -178,71 +178,71 @@ int main(int argc, char *argv[]) // int initsystem(void) { - const SDL_VideoInfo *vid; - const SDL_version *linked = SDL_Linked_Version(); - SDL_version compiled; - char drvname[32]; + const SDL_VideoInfo *vid; + const SDL_version *linked = SDL_Linked_Version(); + SDL_version compiled; + char drvname[32]; - SDL_VERSION(&compiled); + SDL_VERSION(&compiled); - initprintf("Initialising SDL system interface " - "(compiled with SDL version %d.%d.%d, DLL version %d.%d.%d)\n", - linked->major, linked->minor, linked->patch, - compiled.major, compiled.minor, compiled.patch); + initprintf("Initialising SDL system interface " + "(compiled with SDL version %d.%d.%d, DLL version %d.%d.%d)\n", + linked->major, linked->minor, linked->patch, + compiled.major, compiled.minor, compiled.patch); - if (SDL_Init(SDL_INIT_VIDEO //| SDL_INIT_TIMER + if (SDL_Init(SDL_INIT_VIDEO //| SDL_INIT_TIMER #ifdef NOSDLPARACHUTE - | SDL_INIT_NOPARACHUTE + | SDL_INIT_NOPARACHUTE #endif - )) { - initprintf("Initialisation failed! (%s)\n", SDL_GetError()); - return -1; - } + )) { + initprintf("Initialisation failed! (%s)\n", SDL_GetError()); + return -1; + } - atexit(uninitsystem); + atexit(uninitsystem); - frameplace = 0; - lockcount = 0; + frameplace = 0; + lockcount = 0; #ifdef USE_OPENGL - if (loadgldriver(getenv("BUILD_GLDRV"))) { - initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); - nogl = 1; - } + if (loadgldriver(getenv("BUILD_GLDRV"))) { + initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); + nogl = 1; + } #endif #ifndef __APPLE__ - { - SDL_Surface *icon; - //icon = loadtarga("icon.tga"); - icon = loadappicon(); - if (icon) { - SDL_WM_SetIcon(icon, 0); - SDL_FreeSurface(icon); - } - } + { + SDL_Surface *icon; + //icon = loadtarga("icon.tga"); + icon = loadappicon(); + if (icon) { + SDL_WM_SetIcon(icon, 0); + SDL_FreeSurface(icon); + } + } #endif - if (SDL_VideoDriverName(drvname, 32)) - initprintf("Using \"%s\" video driver\n", drvname); + if (SDL_VideoDriverName(drvname, 32)) + initprintf("Using \"%s\" video driver\n", drvname); - // dump a quick summary of the graphics hardware + // dump a quick summary of the graphics hardware #ifdef DEBUGGINGAIDS - vid = SDL_GetVideoInfo(); - initprintf("Video device information:\n"); - initprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No"); - initprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No"); - initprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No"); - initprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No"); - initprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No"); - initprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No"); - initprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No"); - initprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No"); - initprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No"); - initprintf(" Total video memory: %dKB\n", vid->video_mem); + vid = SDL_GetVideoInfo(); + initprintf("Video device information:\n"); + initprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No"); + initprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No"); + initprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No"); + initprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No"); + initprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No"); + initprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No"); + initprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No"); + initprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No"); + initprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No"); + initprintf(" Total video memory: %dKB\n", vid->video_mem); #endif - return 0; + return 0; } @@ -251,14 +251,14 @@ int initsystem(void) // void uninitsystem(void) { - uninitinput(); - uninitmouse(); - uninittimer(); + uninitinput(); + uninitmouse(); + uninittimer(); - SDL_Quit(); + SDL_Quit(); #ifdef USE_OPENGL - unloadgldriver(); + unloadgldriver(); #endif } @@ -268,21 +268,21 @@ void uninitsystem(void) // void initprintf(const char *f, ...) { - va_list va; - char buf[1024]; - - va_start(va, f); - vprintf(f,va); - va_end(va); + va_list va; + char buf[1024]; - va_start(va, f); - Bvsnprintf(buf, 1024, f, va); - va_end(va); - OSD_Printf(buf); + va_start(va, f); + vprintf(f,va); + va_end(va); + + va_start(va, f); + Bvsnprintf(buf, 1024, f, va); + va_end(va); + OSD_Printf(buf); #ifdef HAVE_GTK2 - gtkbuild_puts_startwin(buf); - gtkbuild_update_startwin(); + gtkbuild_puts_startwin(buf); + gtkbuild_update_startwin(); #endif } @@ -293,11 +293,11 @@ void initprintf(const char *f, ...) void debugprintf(const char *f, ...) { #ifdef DEBUGGINGAIDS - va_list va; + va_list va; - va_start(va,f); - Bvfprintf(stderr, f, va); - va_end(va); + va_start(va,f); + Bvfprintf(stderr, f, va); + va_end(va); #endif } @@ -321,45 +321,45 @@ static SDL_Joystick *joydev = NULL; // int initinput(void) { - int i,j; - + int i,j; + #ifdef __APPLE__ - // force OS X to operate in >1 button mouse mode so that LMB isn't adulterated - if (!getenv("SDL_HAS3BUTTONMOUSE")) putenv("SDL_HAS3BUTTONMOUSE=1"); + // force OS X to operate in >1 button mouse mode so that LMB isn't adulterated + if (!getenv("SDL_HAS3BUTTONMOUSE")) putenv("SDL_HAS3BUTTONMOUSE=1"); #endif - - if (SDL_EnableKeyRepeat(250, 30)) initprintf("Error enabling keyboard repeat.\n"); - inputdevices = 1|2; // keyboard (1) and mouse (2) - mouseacquired = 0; - SDL_EnableUNICODE(1); // let's hope this doesn't hit us too hard + if (SDL_EnableKeyRepeat(250, 30)) initprintf("Error enabling keyboard repeat.\n"); + inputdevices = 1|2; // keyboard (1) and mouse (2) + mouseacquired = 0; - memset(keynames,0,sizeof(keynames)); - for (i=0; i= 256) return NULL; - return keynames[num]; + if ((unsigned)num >= 256) return NULL; + return keynames[num]; } const unsigned char *getjoyname(int what, int num) { - static char tmp[64]; + static char tmp[64]; - switch (what) { - case 0: // axis - if ((unsigned)num > (unsigned)joynumaxes) return NULL; - sprintf(tmp,"Axis %d",num); - return tmp; + switch (what) { + case 0: // axis + if ((unsigned)num > (unsigned)joynumaxes) return NULL; + sprintf(tmp,"Axis %d",num); + return tmp; - case 1: // button - if ((unsigned)num > (unsigned)joynumbuttons) return NULL; - sprintf(tmp,"Button %d",num); - return tmp; + case 1: // button + if ((unsigned)num > (unsigned)joynumbuttons) return NULL; + sprintf(tmp,"Button %d",num); + return tmp; - case 2: // hat - if ((unsigned)num > (unsigned)joynumhats) return NULL; - sprintf(tmp,"Hat %d",num); - return tmp; + case 2: // hat + if ((unsigned)num > (unsigned)joynumhats) return NULL; + sprintf(tmp,"Hat %d",num); + return tmp; - default: - return NULL; - } + default: + return NULL; + } } // @@ -411,21 +411,21 @@ const unsigned char *getjoyname(int what, int num) // unsigned char bgetchar(void) { - unsigned char c; - if (keyasciififoplc == keyasciififoend) return 0; - c = keyasciififo[keyasciififoplc]; - keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1)); - return c; + unsigned char c; + if (keyasciififoplc == keyasciififoend) return 0; + c = keyasciififo[keyasciififoplc]; + keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1)); + return c; } int bkbhit(void) { - return (keyasciififoplc != keyasciififoend); + return (keyasciififoplc != keyasciififoend); } void bflushchars(void) { - keyasciififoplc = keyasciififoend = 0; + keyasciififoplc = keyasciififoend = 0; } @@ -441,9 +441,9 @@ void setjoypresscallback(void (*callback)(long, long)) { joypresscallback = call // int initmouse(void) { - moustat=1; - grabmouse(1); - return 0; + moustat=1; + grabmouse(1); + return 0; } // @@ -451,8 +451,8 @@ int initmouse(void) // void uninitmouse(void) { - grabmouse(0); - moustat=0; + grabmouse(0); + moustat=0; } @@ -461,23 +461,23 @@ void uninitmouse(void) // void grabmouse(char a) { - if (appactive && moustat) { - if (a != mouseacquired) { + if (appactive && moustat) { + if (a != mouseacquired) { #ifndef DEBUGGINGAIDS - SDL_GrabMode g; - - g = SDL_WM_GrabInput( a ? SDL_GRAB_ON : SDL_GRAB_OFF ); - mouseacquired = (g == SDL_GRAB_ON); + SDL_GrabMode g; - SDL_ShowCursor(mouseacquired ? SDL_DISABLE : SDL_ENABLE); + g = SDL_WM_GrabInput( a ? SDL_GRAB_ON : SDL_GRAB_OFF ); + mouseacquired = (g == SDL_GRAB_ON); + + SDL_ShowCursor(mouseacquired ? SDL_DISABLE : SDL_ENABLE); #else - mouseacquired = a; + mouseacquired = a; #endif - } - } else { - mouseacquired = a; - } - mousex = mousey = 0; + } + } else { + mouseacquired = a; + } + mousex = mousey = 0; } @@ -486,10 +486,10 @@ void grabmouse(char a) // void readmousexy(long *x, long *y) { - if (!mouseacquired || !appactive || !moustat) { *x = *y = 0; return; } - *x = mousex; - *y = mousey; - mousex = mousey = 0; + if (!mouseacquired || !appactive || !moustat) { *x = *y = 0; return; } + *x = mousex; + *y = mousey; + mousex = mousey = 0; } // @@ -497,8 +497,8 @@ void readmousexy(long *x, long *y) // void readmousebstatus(long *b) { - if (!mouseacquired || !appactive || !moustat) *b = 0; - else *b = mouseb; + if (!mouseacquired || !appactive || !moustat) *b = 0; + else *b = mouseb; } // @@ -514,7 +514,7 @@ void setjoydeadzone(int axis, unsigned short dead, unsigned short satur) // void getjoydeadzone(int axis, unsigned short *dead, unsigned short *satur) { - *dead = *satur = 0; + *dead = *satur = 0; } @@ -547,17 +547,17 @@ static void (*usertimercallback)(void) = NULL; // int inittimer(int tickspersecond) { - if (timerfreq) return 0; // already installed + if (timerfreq) return 0; // already installed - initprintf("Initialising timer\n"); + initprintf("Initialising timer\n"); - timerfreq = 1000; - timerticspersec = tickspersecond; - timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq; + timerfreq = 1000; + timerticspersec = tickspersecond; + timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq; - usertimercallback = NULL; + usertimercallback = NULL; - return 0; + return 0; } // @@ -565,9 +565,9 @@ int inittimer(int tickspersecond) // void uninittimer(void) { - if (!timerfreq) return; + if (!timerfreq) return; - timerfreq=0; + timerfreq=0; } // @@ -575,19 +575,19 @@ void uninittimer(void) // void sampletimer(void) { - Uint32 i; - long n; - - if (!timerfreq) return; - - i = SDL_GetTicks(); - n = (long)(i * timerticspersec / timerfreq) - timerlastsample; - if (n>0) { - totalclock += n; - timerlastsample += n; - } + Uint32 i; + long n; - if (usertimercallback) for (; n>0; n--) usertimercallback(); + if (!timerfreq) return; + + i = SDL_GetTicks(); + n = (long)(i * timerticspersec / timerfreq) - timerlastsample; + if (n>0) { + totalclock += n; + timerlastsample += n; + } + + if (usertimercallback) for (; n>0; n--) usertimercallback(); } // @@ -595,7 +595,7 @@ void sampletimer(void) // unsigned long getticks(void) { - return (unsigned long)SDL_GetTicks(); + return (unsigned long)SDL_GetTicks(); } @@ -604,7 +604,7 @@ unsigned long getticks(void) // int gettimerfreq(void) { - return timerticspersec; + return timerticspersec; } @@ -613,12 +613,12 @@ int gettimerfreq(void) // void (*installusertimercallback(void (*callback)(void)))(void) { - void (*oldtimercallback)(void); + void (*oldtimercallback)(void); - oldtimercallback = usertimercallback; - usertimercallback = callback; + oldtimercallback = usertimercallback; + usertimercallback = callback; - return oldtimercallback; + return oldtimercallback; } @@ -631,7 +631,7 @@ void (*installusertimercallback(void (*callback)(void)))(void) // // --------------------------------------- // -// +// // @@ -639,36 +639,36 @@ void (*installusertimercallback(void (*callback)(void)))(void) // static int sortmodes(const struct validmode_t *a, const struct validmode_t *b) { - int x; + int x; - if ((x = a->fs - b->fs) != 0) return x; - if ((x = a->bpp - b->bpp) != 0) return x; - if ((x = a->xdim - b->xdim) != 0) return x; - if ((x = a->ydim - b->ydim) != 0) return x; + if ((x = a->fs - b->fs) != 0) return x; + if ((x = a->bpp - b->bpp) != 0) return x; + if ((x = a->xdim - b->xdim) != 0) return x; + if ((x = a->ydim - b->ydim) != 0) return x; - return 0; + return 0; } static char modeschecked=0; void getvalidmodes(void) { - static int cdepths[] = { - 8, + static int cdepths[] = { + 8, #ifdef USE_OPENGL - 16,24,32, + 16,24,32, #endif - 0 }; - static int defaultres[][2] = { - {1280,1024},{1280,960},{1152,864},{1024,768},{800,600},{640,480}, - {640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0} - }; - SDL_Rect **modes; - SDL_PixelFormat pf = { NULL, 8, 1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 }; - int i, j, maxx=0, maxy=0; + 0 }; + static int defaultres[][2] = { + {1280,1024},{1280,960},{1152,864},{1024,768},{800,600},{640,480}, + {640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0} + }; + SDL_Rect **modes; + SDL_PixelFormat pf = { NULL, 8, 1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 }; + int i, j, maxx=0, maxy=0; - if (modeschecked) return; + if (modeschecked) return; - validmodecnt=0; - initprintf("Detecting video modes:\n"); + validmodecnt=0; + initprintf("Detecting video modes:\n"); #define ADDMODE(x,y,c,f) if (validmodecnt> 3; + // do fullscreen modes first + for (j=0; cdepths[j]; j++) { + pf.BitsPerPixel = cdepths[j]; + pf.BytesPerPixel = cdepths[j] >> 3; - modes = SDL_ListModes(&pf, SURFACE_FLAGS | SDL_FULLSCREEN); - if (modes == (SDL_Rect **)0) { - if (cdepths[j] > 8) cdepths[j] = -1; - continue; - } + modes = SDL_ListModes(&pf, SURFACE_FLAGS | SDL_FULLSCREEN); + if (modes == (SDL_Rect **)0) { + if (cdepths[j] > 8) cdepths[j] = -1; + continue; + } - if (modes == (SDL_Rect **)-1) { - for (i=0; defaultres[i][0]; i++) - ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1) - } else { - for (i=0; modes[i]; i++) { - if ((modes[i]->w > MAXXDIM) || (modes[i]->h > MAXYDIM)) continue; + if (modes == (SDL_Rect **)-1) { + for (i=0; defaultres[i][0]; i++) + ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1) + } else { + for (i=0; modes[i]; i++) { + if ((modes[i]->w > MAXXDIM) || (modes[i]->h > MAXYDIM)) continue; - ADDMODE(modes[i]->w, modes[i]->h, cdepths[j], 1) + ADDMODE(modes[i]->w, modes[i]->h, cdepths[j], 1) - if ((modes[i]->w > maxx) && (modes[i]->h > maxy)) { - maxx = modes[i]->w; - maxy = modes[i]->h; - } - } - } - } + if ((modes[i]->w > maxx) && (modes[i]->h > maxy)) { + maxx = modes[i]->w; + maxy = modes[i]->h; + } + } + } + } - if (maxx == 0 && maxy == 0) { - initprintf("No fullscreen modes available!\n"); - maxx = MAXXDIM; maxy = MAXYDIM; - } + if (maxx == 0 && maxy == 0) { + initprintf("No fullscreen modes available!\n"); + maxx = MAXXDIM; maxy = MAXYDIM; + } - // add windowed modes next - for (j=0; cdepths[j]; j++) { - if (cdepths[j] < 0) continue; - for (i=0; defaultres[i][0]; i++) - CHECK(defaultres[i][0],defaultres[i][1]) - ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],0) - } + // add windowed modes next + for (j=0; cdepths[j]; j++) { + if (cdepths[j] < 0) continue; + for (i=0; defaultres[i][0]; i++) + CHECK(defaultres[i][0],defaultres[i][1]) + ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],0) + } #undef CHECK #undef ADDMODE - qsort((void*)validmode, validmodecnt, sizeof(struct validmode_t), (int(*)(const void*,const void*))sortmodes); + qsort((void*)validmode, validmodecnt, sizeof(struct validmode_t), (int(*)(const void*,const void*))sortmodes); - modeschecked=1; + modeschecked=1; } @@ -742,53 +742,53 @@ void getvalidmodes(void) // int checkvideomode(int *x, int *y, int c, int fs) { - int i, nearest=-1, dx, dy, odx=9999, ody=9999; + int i, nearest=-1, dx, dy, odx=9999, ody=9999; - getvalidmodes(); + getvalidmodes(); - if (c>8 + if (c>8 #ifdef USE_OPENGL - && nogl + && nogl #endif - ) return -1; + ) return -1; - // fix up the passed resolution values to be multiples of 8 - // and at least 320x200 or at most MAXXDIMxMAXYDIM - if (*x < 320) *x = 320; - if (*y < 200) *y = 200; - if (*x > MAXXDIM) *x = MAXXDIM; - if (*y > MAXYDIM) *y = MAXYDIM; - *x &= 0xfffffff8l; + // fix up the passed resolution values to be multiples of 8 + // and at least 320x200 or at most MAXXDIMxMAXYDIM + if (*x < 320) *x = 320; + if (*y < 200) *y = 200; + if (*x > MAXXDIM) *x = MAXXDIM; + if (*y > MAXYDIM) *y = MAXYDIM; + *x &= 0xfffffff8l; + + for (i=0; i 8 && sdl_surface) polymost_glreset(); + if (bpp > 8 && sdl_surface) polymost_glreset(); #endif - // restore gamma before we change video modes if it was changed - if (sdl_surface && gammabrightness) { - SDL_SetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]); - gammabrightness = 0; // redetect on next mode switch - } - + // restore gamma before we change video modes if it was changed + if (sdl_surface && gammabrightness) { + SDL_SetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]); + gammabrightness = 0; // redetect on next mode switch + } + #if defined(USE_OPENGL) - if (c > 8) { - int i, j, multisamplecheck = (glmultisample > 0); - struct { - SDL_GLattr attr; - int value; - } attributes[] = { + if (c > 8) { + int i, j, multisamplecheck = (glmultisample > 0); + struct { + SDL_GLattr attr; + int value; + } attributes[] = { #if 0 - { SDL_GL_RED_SIZE, 8 }, - { SDL_GL_GREEN_SIZE, 8 }, - { SDL_GL_BLUE_SIZE, 8 }, - { SDL_GL_ALPHA_SIZE, 8 }, - { SDL_GL_BUFFER_SIZE, c }, - { SDL_GL_STENCIL_SIZE, 0 }, - { SDL_GL_ACCUM_RED_SIZE, 0 }, - { SDL_GL_ACCUM_GREEN_SIZE, 0 }, - { SDL_GL_ACCUM_BLUE_SIZE, 0 }, - { SDL_GL_ACCUM_ALPHA_SIZE, 0 }, - { SDL_GL_DEPTH_SIZE, 24 }, + { SDL_GL_RED_SIZE, 8 }, + { SDL_GL_GREEN_SIZE, 8 }, + { SDL_GL_BLUE_SIZE, 8 }, + { SDL_GL_ALPHA_SIZE, 8 }, + { SDL_GL_BUFFER_SIZE, c }, + { SDL_GL_STENCIL_SIZE, 0 }, + { SDL_GL_ACCUM_RED_SIZE, 0 }, + { SDL_GL_ACCUM_GREEN_SIZE, 0 }, + { SDL_GL_ACCUM_BLUE_SIZE, 0 }, + { SDL_GL_ACCUM_ALPHA_SIZE, 0 }, + { SDL_GL_DEPTH_SIZE, 24 }, #endif - { SDL_GL_DOUBLEBUFFER, 1 }, - { SDL_GL_MULTISAMPLEBUFFERS, glmultisample > 0 }, - { SDL_GL_MULTISAMPLESAMPLES, glmultisample }, - }; + { SDL_GL_DOUBLEBUFFER, 1 }, + { SDL_GL_MULTISAMPLEBUFFERS, glmultisample > 0 }, + { SDL_GL_MULTISAMPLESAMPLES, glmultisample }, + }; - if (nogl) return -1; - - initprintf("Setting video mode %dx%d (%d-bpp %s)\n", - x,y,c, ((fs&1) ? "fullscreen" : "windowed")); - do { - for (i=0; i < (int)(sizeof(attributes)/sizeof(attributes[0])); i++) { - j = attributes[i].value; - if (!multisamplecheck && - (attributes[i].attr == SDL_GL_MULTISAMPLEBUFFERS || - attributes[i].attr == SDL_GL_MULTISAMPLESAMPLES) - ) { - j = 0; - } - SDL_GL_SetAttribute(attributes[i].attr, j); - } + if (nogl) return -1; - sdl_surface = SDL_SetVideoMode(x, y, c, SDL_OPENGL | ((fs&1)?SDL_FULLSCREEN:0)); - if (!sdl_surface) { - if (multisamplecheck) { - initprintf("Multisample mode not possible. Retrying without multisampling.\n"); - glmultisample = 0; - continue; - } - initprintf("Unable to set video mode!\n"); - return -1; - } - } while (multisamplecheck--); - } else + initprintf("Setting video mode %dx%d (%d-bpp %s)\n", + x,y,c, ((fs&1) ? "fullscreen" : "windowed")); + do { + for (i=0; i < (int)(sizeof(attributes)/sizeof(attributes[0])); i++) { + j = attributes[i].value; + if (!multisamplecheck && + (attributes[i].attr == SDL_GL_MULTISAMPLEBUFFERS || + attributes[i].attr == SDL_GL_MULTISAMPLESAMPLES) + ) { + j = 0; + } + SDL_GL_SetAttribute(attributes[i].attr, j); + } + + sdl_surface = SDL_SetVideoMode(x, y, c, SDL_OPENGL | ((fs&1)?SDL_FULLSCREEN:0)); + if (!sdl_surface) { + if (multisamplecheck) { + initprintf("Multisample mode not possible. Retrying without multisampling.\n"); + glmultisample = 0; + continue; + } + initprintf("Unable to set video mode!\n"); + return -1; + } + } while (multisamplecheck--); + } else #endif - { - initprintf("Setting video mode %dx%d (%d-bpp %s)\n", - x,y,c, ((fs&1) ? "fullscreen" : "windowed")); - sdl_surface = SDL_SetVideoMode(x, y, c, SURFACE_FLAGS | ((fs&1)?SDL_FULLSCREEN:0)); - if (!sdl_surface) { - initprintf("Unable to set video mode!\n"); - return -1; - } - } + { + initprintf("Setting video mode %dx%d (%d-bpp %s)\n", + x,y,c, ((fs&1) ? "fullscreen" : "windowed")); + sdl_surface = SDL_SetVideoMode(x, y, c, SURFACE_FLAGS | ((fs&1)?SDL_FULLSCREEN:0)); + if (!sdl_surface) { + initprintf("Unable to set video mode!\n"); + return -1; + } + } #if 0 - { - char flags[512] = ""; + { + char flags[512] = ""; #define FLAG(x,y) if ((sdl_surface->flags & x) == x) { strcat(flags, y); strcat(flags, " "); } - FLAG(SDL_HWSURFACE, "HWSURFACE") else - FLAG(SDL_SWSURFACE, "SWSURFACE") - FLAG(SDL_ASYNCBLIT, "ASYNCBLIT") - FLAG(SDL_ANYFORMAT, "ANYFORMAT") - FLAG(SDL_HWPALETTE, "HWPALETTE") - FLAG(SDL_DOUBLEBUF, "DOUBLEBUF") - FLAG(SDL_FULLSCREEN, "FULLSCREEN") - FLAG(SDL_OPENGL, "OPENGL") - FLAG(SDL_OPENGLBLIT, "OPENGLBLIT") - FLAG(SDL_RESIZABLE, "RESIZABLE") - FLAG(SDL_HWACCEL, "HWACCEL") - FLAG(SDL_SRCCOLORKEY, "SRCCOLORKEY") - FLAG(SDL_RLEACCEL, "RLEACCEL") - FLAG(SDL_SRCALPHA, "SRCALPHA") - FLAG(SDL_PREALLOC, "PREALLOC") + FLAG(SDL_HWSURFACE, "HWSURFACE") else + FLAG(SDL_SWSURFACE, "SWSURFACE") + FLAG(SDL_ASYNCBLIT, "ASYNCBLIT") + FLAG(SDL_ANYFORMAT, "ANYFORMAT") + FLAG(SDL_HWPALETTE, "HWPALETTE") + FLAG(SDL_DOUBLEBUF, "DOUBLEBUF") + FLAG(SDL_FULLSCREEN, "FULLSCREEN") + FLAG(SDL_OPENGL, "OPENGL") + FLAG(SDL_OPENGLBLIT, "OPENGLBLIT") + FLAG(SDL_RESIZABLE, "RESIZABLE") + FLAG(SDL_HWACCEL, "HWACCEL") + FLAG(SDL_SRCCOLORKEY, "SRCCOLORKEY") + FLAG(SDL_RLEACCEL, "RLEACCEL") + FLAG(SDL_SRCALPHA, "SRCALPHA") + FLAG(SDL_PREALLOC, "PREALLOC") #undef FLAG - initprintf("SDL Surface flags: %s\n", flags); - } + initprintf("SDL Surface flags: %s\n", flags); + } #endif - { - //static char t[384]; - //sprintf(t, "%s (%dx%d %s)", apptitle, x, y, ((fs) ? "fullscreen" : "windowed")); - SDL_WM_SetCaption(apptitle, 0); - } + { + //static char t[384]; + //sprintf(t, "%s (%dx%d %s)", apptitle, x, y, ((fs) ? "fullscreen" : "windowed")); + SDL_WM_SetCaption(apptitle, 0); + } #ifdef USE_OPENGL - if (c > 8) { - GLubyte *p,*p2,*p3; - int i; + if (c > 8) { + GLubyte *p,*p2,*p3; + int i; - polymost_glreset(); - - bglEnable(GL_TEXTURE_2D); - bglShadeModel(GL_SMOOTH); //GL_FLAT - bglClearColor(0,0,0,0.5); //Black Background - bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! - bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); - bglDisable(GL_DITHER); - - glinfo.vendor = bglGetString(GL_VENDOR); - glinfo.renderer = bglGetString(GL_RENDERER); - glinfo.version = bglGetString(GL_VERSION); - glinfo.extensions = bglGetString(GL_EXTENSIONS); - - glinfo.maxanisotropy = 1.0; - glinfo.bgra = 0; - glinfo.texcompr = 0; + polymost_glreset(); - // process the extensions string and flag stuff we recognize - p = Bstrdup(glinfo.extensions); - p3 = p; - while ((p2 = Bstrtoken(p3==p?p:NULL, " ", (char**)&p3, 1)) != NULL) { - if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { - // supports anisotropy. get the maximum anisotropy level - bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); - } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || - !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { - // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS - glinfo.clamptoedge = 1; - } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { - // support bgra textures - glinfo.bgra = 1; - } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { - // support texture compression - glinfo.texcompr = 1; - } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { - // support non-power-of-two texture sizes - glinfo.texnpot = 1; - } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { - // 3dfx cards have issues with fog - nofog = 1; - if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); - warnonce |= 1; - } else if (!Bstrcmp(p2, "GL_ARB_multisample")) { - // supports multisampling - glinfo.multisample = 1; - } else if (!Bstrcmp(p2, "GL_NV_multisample_filter_hint")) { - // supports nvidia's multisample hint extension - glinfo.nvmultisamplehint = 1; - } - } - Bfree(p); - } + bglEnable(GL_TEXTURE_2D); + bglShadeModel(GL_SMOOTH); //GL_FLAT + bglClearColor(0,0,0,0.5); //Black Background + bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! + bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); + bglDisable(GL_DITHER); + + glinfo.vendor = bglGetString(GL_VENDOR); + glinfo.renderer = bglGetString(GL_RENDERER); + glinfo.version = bglGetString(GL_VERSION); + glinfo.extensions = bglGetString(GL_EXTENSIONS); + + glinfo.maxanisotropy = 1.0; + glinfo.bgra = 0; + glinfo.texcompr = 0; + + // process the extensions string and flag stuff we recognize + p = Bstrdup(glinfo.extensions); + p3 = p; + while ((p2 = Bstrtoken(p3==p?p:NULL, " ", (char**)&p3, 1)) != NULL) { + if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { + // supports anisotropy. get the maximum anisotropy level + bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); + } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || + !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { + // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS + glinfo.clamptoedge = 1; + } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { + // support bgra textures + glinfo.bgra = 1; + } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { + // support texture compression + glinfo.texcompr = 1; + } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { + // support non-power-of-two texture sizes + glinfo.texnpot = 1; + } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { + // 3dfx cards have issues with fog + nofog = 1; + if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); + warnonce |= 1; + } else if (!Bstrcmp(p2, "GL_ARB_multisample")) { + // supports multisampling + glinfo.multisample = 1; + } else if (!Bstrcmp(p2, "GL_NV_multisample_filter_hint")) { + // supports nvidia's multisample hint extension + glinfo.nvmultisamplehint = 1; + } + } + Bfree(p); + } #endif - - xres = x; - yres = y; - bpp = c; - fullscreen = fs; - //bytesperline = sdl_surface->pitch; - //imageSize = bytesperline*yres; - numpages = c>8?2:1; - frameplace = 0; - lockcount = 0; - modechange=1; - videomodereset = 0; - OSD_ResizeDisplay(xres,yres); - - // save the current system gamma to determine if gamma is available - if (!gammabrightness) { - float f = 1.0 + ((float)curbrightness / 10.0); - if (SDL_GetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]) >= 0) - gammabrightness = 1; - // see if gamma really is working by trying to set the brightness - if (gammabrightness && SDL_SetGamma(f,f,f) < 0) - gammabrightness = 0; // nope - } + xres = x; + yres = y; + bpp = c; + fullscreen = fs; + //bytesperline = sdl_surface->pitch; + //imageSize = bytesperline*yres; + numpages = c>8?2:1; + frameplace = 0; + lockcount = 0; + modechange=1; + videomodereset = 0; + OSD_ResizeDisplay(xres,yres); - // setpalettefade will set the palette according to whether gamma worked - setpalettefade(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); - - //if (c==8) setpalette(0,256,0); - //baselayer_onvideomodechange(c>8); - - if (regrab) grabmouse(1); + // save the current system gamma to determine if gamma is available + if (!gammabrightness) { + float f = 1.0 + ((float)curbrightness / 10.0); + if (SDL_GetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]) >= 0) + gammabrightness = 1; - return 0; + // see if gamma really is working by trying to set the brightness + if (gammabrightness && SDL_SetGamma(f,f,f) < 0) + gammabrightness = 0; // nope + } + + // setpalettefade will set the palette according to whether gamma worked + setpalettefade(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); + + //if (c==8) setpalette(0,256,0); + //baselayer_onvideomodechange(c>8); + + if (regrab) grabmouse(1); + + return 0; } @@ -1024,8 +1024,8 @@ int setvideomode(int x, int y, int c, int fs) // void resetvideomode(void) { - videomodereset = 1; - modeschecked = 0; + videomodereset = 1; + modeschecked = 0; } @@ -1034,35 +1034,35 @@ void resetvideomode(void) // void begindrawing(void) { - long i,j; + long i,j; - if (bpp > 8) { - if (offscreenrendering) return; - frameplace = 0; - bytesperline = 0; - imageSize = 0; - modechange = 0; - return; - } + if (bpp > 8) { + if (offscreenrendering) return; + frameplace = 0; + bytesperline = 0; + imageSize = 0; + modechange = 0; + return; + } - // lock the frame - if (lockcount++ > 0) - return; + // lock the frame + if (lockcount++ > 0) + return; - if (offscreenrendering) return; - - if (SDL_MUSTLOCK(sdl_surface)) SDL_LockSurface(sdl_surface); - frameplace = (long)sdl_surface->pixels; - - if (sdl_surface->pitch != bytesperline || modechange) { - bytesperline = sdl_surface->pitch; - imageSize = bytesperline*yres; - setvlinebpl(bytesperline); + if (offscreenrendering) return; - j = 0; - for(i=0;i<=ydim;i++) ylookup[i] = j, j += bytesperline; - modechange=0; - } + if (SDL_MUSTLOCK(sdl_surface)) SDL_LockSurface(sdl_surface); + frameplace = (long)sdl_surface->pixels; + + if (sdl_surface->pitch != bytesperline || modechange) { + bytesperline = sdl_surface->pitch; + imageSize = bytesperline*yres; + setvlinebpl(bytesperline); + + j = 0; + for(i=0;i<=ydim;i++) ylookup[i] = j, j += bytesperline; + modechange=0; + } } @@ -1071,20 +1071,20 @@ void begindrawing(void) // void enddrawing(void) { - if (bpp > 8) { - if (!offscreenrendering) frameplace = 0; - return; - } + if (bpp > 8) { + if (!offscreenrendering) frameplace = 0; + return; + } - if (!frameplace) return; - if (lockcount > 1) { lockcount--; return; } - if (!offscreenrendering) frameplace = 0; - if (lockcount == 0) return; - lockcount = 0; + if (!frameplace) return; +if (lockcount > 1) { lockcount--; return; } + if (!offscreenrendering) frameplace = 0; + if (lockcount == 0) return; + lockcount = 0; - if (offscreenrendering) return; + if (offscreenrendering) return; - if (SDL_MUSTLOCK(sdl_surface)) SDL_UnlockSurface(sdl_surface); + if (SDL_MUSTLOCK(sdl_surface)) SDL_UnlockSurface(sdl_surface); } @@ -1093,52 +1093,52 @@ void enddrawing(void) // void showframe(int w) { - long i,j; + long i,j; #ifdef USE_OPENGL - if (bpp > 8) { - if (palfadedelta) { - bglMatrixMode(GL_PROJECTION); - bglPushMatrix(); - bglLoadIdentity(); - bglMatrixMode(GL_MODELVIEW); - bglPushMatrix(); - bglLoadIdentity(); + if (bpp > 8) { + if (palfadedelta) { + bglMatrixMode(GL_PROJECTION); + bglPushMatrix(); + bglLoadIdentity(); + bglMatrixMode(GL_MODELVIEW); + bglPushMatrix(); + bglLoadIdentity(); - bglDisable(GL_ALPHA_TEST); - bglDisable(GL_DEPTH_TEST); - bglDisable(GL_ALPHA_TEST); - bglDisable(GL_TEXTURE_2D); + bglDisable(GL_ALPHA_TEST); + bglDisable(GL_DEPTH_TEST); + bglDisable(GL_ALPHA_TEST); + bglDisable(GL_TEXTURE_2D); - bglEnable(GL_BLEND); - bglColor4ub(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); + bglEnable(GL_BLEND); + bglColor4ub(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); - bglBegin(GL_QUADS); - bglVertex2i(-1, -1); - bglVertex2i(1, -1); - bglVertex2i(1, 1); - bglVertex2i(-1, 1); - bglEnd(); - - bglMatrixMode(GL_MODELVIEW); - bglPopMatrix(); - bglMatrixMode(GL_PROJECTION); - bglPopMatrix(); - } + bglBegin(GL_QUADS); + bglVertex2i(-1, -1); + bglVertex2i(1, -1); + bglVertex2i(1, 1); + bglVertex2i(-1, 1); + bglEnd(); - SDL_GL_SwapBuffers(); - return; - } + bglMatrixMode(GL_MODELVIEW); + bglPopMatrix(); + bglMatrixMode(GL_PROJECTION); + bglPopMatrix(); + } + + SDL_GL_SwapBuffers(); + return; + } #endif - - if (offscreenrendering) return; - if (lockcount) { - printf("Frame still locked %ld times when showframe() called.\n", lockcount); - while (lockcount) enddrawing(); - } + if (offscreenrendering) return; - SDL_Flip(sdl_surface); + if (lockcount) { + printf("Frame still locked %ld times when showframe() called.\n", lockcount); + while (lockcount) enddrawing(); + } + + SDL_Flip(sdl_surface); } @@ -1147,25 +1147,25 @@ void showframe(int w) // int setpalette(int start, int num, char *dapal) { - SDL_Color pal[256]; - int i,n; + SDL_Color pal[256]; + int i,n; - if (bpp > 8) return 0; // no palette in opengl + if (bpp > 8) return 0; // no palette in opengl - copybuf(curpalettefaded, pal, 256); - - for (i=start, n=num; n>0; i++, n--) { - /* - pal[i].b = dapal[0] << 2; - pal[i].g = dapal[1] << 2; - pal[i].r = dapal[2] << 2; - */ - curpalettefaded[i].f = pal[i].unused = 0; - dapal += 4; - } + copybuf(curpalettefaded, pal, 256); - //return SDL_SetPalette(sdl_surface, SDL_LOGPAL|SDL_PHYSPAL, pal, 0, 256); - return SDL_SetColors(sdl_surface, pal, 0, 256); + for (i=start, n=num; n>0; i++, n--) { + /* + pal[i].b = dapal[0] << 2; + pal[i].g = dapal[1] << 2; + pal[i].r = dapal[2] << 2; + */ + curpalettefaded[i].f = pal[i].unused = 0; + dapal += 4; + } + + //return SDL_SetPalette(sdl_surface, SDL_LOGPAL|SDL_PHYSPAL, pal, 0, 256); + return SDL_SetColors(sdl_surface, pal, 0, 256); } // @@ -1196,20 +1196,20 @@ int getpalette(int start, int num, char *dapal) // int setgamma(float ro, float go, float bo) { - return SDL_SetGamma(ro,go,bo); + return SDL_SetGamma(ro,go,bo); } #ifndef __APPLE__ extern struct sdlappicon sdlappicon; static SDL_Surface * loadappicon(void) { - SDL_Surface *surf; + SDL_Surface *surf; - surf = SDL_CreateRGBSurfaceFrom((void*)sdlappicon.pixels, - sdlappicon.width, sdlappicon.height, 32, sdlappicon.width*4, - 0xffl,0xff00l,0xff0000l,0xff000000l); + surf = SDL_CreateRGBSurfaceFrom((void*)sdlappicon.pixels, + sdlappicon.width, sdlappicon.height, 32, sdlappicon.width*4, + 0xffl,0xff00l,0xff0000l,0xff000000l); - return surf; + return surf; } #endif @@ -1221,7 +1221,7 @@ static SDL_Surface * loadappicon(void) // // --------------------------------------- // -// +// // @@ -1230,8 +1230,8 @@ static SDL_Surface * loadappicon(void) // int handleevents(void) { - int code, rv=0, j; - SDL_Event ev; + int code, rv=0, j; + SDL_Event ev; #define SetKey(key,state) { \ keystatus[key] = state; \ @@ -1242,270 +1242,270 @@ int handleevents(void) } \ } - while (SDL_PollEvent(&ev)) { - switch (ev.type) { - case SDL_KEYDOWN: - case SDL_KEYUP: - code = keytranslation[ev.key.keysym.sym]; + while (SDL_PollEvent(&ev)) { + switch (ev.type) { + case SDL_KEYDOWN: + case SDL_KEYUP: + code = keytranslation[ev.key.keysym.sym]; - if (ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && - (ev.key.keysym.unicode & 0xff80) == 0 && - ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { - keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; - keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); - } + if (ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && + (ev.key.keysym.unicode & 0xff80) == 0 && + ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { + keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; + keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); + } - // hook in the osd - if (OSD_HandleKey(code, (ev.key.type == SDL_KEYDOWN)) == 0) - break; + // hook in the osd + if (OSD_HandleKey(code, (ev.key.type == SDL_KEYDOWN)) == 0) + break; - if (ev.key.type == SDL_KEYDOWN) { - if (!keystatus[code]) { - SetKey(code, 1); - if (keypresscallback) - keypresscallback(code, 1); - } - } else { - SetKey(code, 0); - if (keypresscallback) - keypresscallback(code, 0); - } - break; + if (ev.key.type == SDL_KEYDOWN) { + if (!keystatus[code]) { + SetKey(code, 1); + if (keypresscallback) + keypresscallback(code, 1); + } + } else { + SetKey(code, 0); + if (keypresscallback) + keypresscallback(code, 0); + } + break; - case SDL_ACTIVEEVENT: - if (ev.active.state & SDL_APPINPUTFOCUS) { - appactive = ev.active.gain; - if (mouseacquired && moustat) { - if (appactive) { - SDL_WM_GrabInput(SDL_GRAB_ON); - SDL_ShowCursor(SDL_DISABLE); - } else { - SDL_WM_GrabInput(SDL_GRAB_OFF); - SDL_ShowCursor(SDL_ENABLE); - } - } - rv=-1; - } - break; + case SDL_ACTIVEEVENT: + if (ev.active.state & SDL_APPINPUTFOCUS) { + appactive = ev.active.gain; + if (mouseacquired && moustat) { + if (appactive) { + SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_ShowCursor(SDL_DISABLE); + } else { + SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_ShowCursor(SDL_ENABLE); + } + } + rv=-1; + } + break; - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - switch (ev.button.button) { - case SDL_BUTTON_LEFT: j = 0; break; - case SDL_BUTTON_RIGHT: j = 1; break; - case SDL_BUTTON_MIDDLE: j = 2; break; - default: j = -1; break; - } - if (j<0) break; - - if (ev.button.state == SDL_PRESSED) - mouseb |= (1< 48000) dasamplerate = 48000; + if (fmod_inited) return; + fmod_inited = 0; - musicstat = damusistat; - - printOSD("Initialising FMOD...\n"); - printOSD(" Linked version: %.02f\n", FMOD_VERSION); - printOSD(" DLL version: %.02f\n", FSOUND_GetVersion()); + if (dasamplerate < 6000) dasamplerate = 6000; + else if (dasamplerate > 48000) dasamplerate = 48000; - if (FSOUND_GetVersion() < FMOD_VERSION) { - printOSD(" ... Failure: FMOD DLL too old! Sound disabled.\n"); - return; - } - - printOSD(" Samplerate: %d hz\n", dasamplerate); + musicstat = damusistat; - //FSOUND_SetOutput(FSOUND_OUTPUT_ASIO); + printOSD("Initialising FMOD...\n"); + printOSD(" Linked version: %.02f\n", FMOD_VERSION); + printOSD(" DLL version: %.02f\n", FSOUND_GetVersion()); - if (FSOUND_Init(dasamplerate, NUMCHANNELS, 0)) { - printOSD(" ... Success\n"); - fmod_inited = 1; - } else { - printOSD(" ... Failure: %s\n", FMOD_ErrorString(FSOUND_GetError())); - } + if (FSOUND_GetVersion() < FMOD_VERSION) { + printOSD(" ... Failure: FMOD DLL too old! Sound disabled.\n"); + return; + } - switch (FSOUND_GetOutput()) { - case FSOUND_OUTPUT_NOSOUND: s = "No Sound"; break; - case FSOUND_OUTPUT_WINMM: s = "WINMM"; break; - case FSOUND_OUTPUT_DSOUND: s = "DirectSound"; break; - case FSOUND_OUTPUT_OSS: s = "OSS"; break; - case FSOUND_OUTPUT_ESD: s = "ESound"; break; - case FSOUND_OUTPUT_ALSA: s = "ALSA"; break; - case FSOUND_OUTPUT_ASIO: s = "ASIO"; break; - default: s = "Other"; break; - } - printOSD("Using FMOD \"%s\" output driver\n", s); + printOSD(" Samplerate: %d hz\n", dasamplerate); - FSOUND_File_SetCallbacks( - (FSOUND_OPENCALLBACK)f_open, - (FSOUND_CLOSECALLBACK)f_close, - (FSOUND_READCALLBACK)f_read, - (FSOUND_SEEKCALLBACK)f_seek, - (FSOUND_TELLCALLBACK)f_tell); - //FSOUND_SetMemorySystem(fmod_cache, fmod_cachelen, NULL, NULL, NULL); + //FSOUND_SetOutput(FSOUND_OUTPUT_ASIO); - loadwaves(); + if (FSOUND_Init(dasamplerate, NUMCHANNELS, 0)) { + printOSD(" ... Success\n"); + fmod_inited = 1; + } else { + printOSD(" ... Failure: %s\n", FMOD_ErrorString(FSOUND_GetError())); + } - for (i=0; i=0;wavnum--) { - bad = 0; + for (wavnum=numwaves-1;wavnum>=0;wavnum--) { + bad = 0; - i = 0; - while ((dafilename[i] > 0) && (i < 16)) - { - ch1 = dafilename[i]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32; - ch2 = instname[wavnum][i]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32; - if (ch1 != ch2) {bad = 1; break;} - i++; - } - if (bad != 0) continue; + i = 0; + while ((dafilename[i] > 0) && (i < 16)) + { + ch1 = dafilename[i]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32; + ch2 = instname[wavnum][i]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32; + if (ch1 != ch2) {bad = 1; break;} + i++; + } + if (bad != 0) continue; - for (i=0; i oldestpos) { - oldest = i; - oldestpos = FSOUND_GetCurrentPosition(channels[i]); - } - } + for (i=0; i oldestpos) { + oldest = i; + oldestpos = FSOUND_GetCurrentPosition(channels[i]); + } + } - chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[wavnum], NULL, 1); - if (chan == -1) return; - FSOUND_SetFrequency(chan, dafreq*11025/4096); - FSOUND_SetVolume(chan, davol); - - FSOUND_SetPaused(chan, 0); - - channels[free] = chan; - return; - } + if (free < 0) { + FSOUND_StopSound(channels[oldest]); + free = oldest; + } + + chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[wavnum], NULL, 1); + if (chan == -1) return; + FSOUND_SetFrequency(chan, dafreq*11025/4096); + FSOUND_SetVolume(chan, davol); + + FSOUND_SetPaused(chan, 0); + + channels[free] = chan; + return; + } } void wsay(char *dafilename, long dafreq, long volume1, long volume2) { - unsigned char ch1, ch2; - long i, j, bad, free=-1, oldest=0; - unsigned int oldestpos=0; - int chan; + unsigned char ch1, ch2; + long i, j, bad, free=-1, oldest=0; + unsigned int oldestpos=0; + int chan; - if (fmod_inited == 0) return; + if (fmod_inited == 0) return; - i = numwaves-1; - do - { - bad = 0; + i = numwaves-1; + do + { + bad = 0; - j = 0; - while ((dafilename[j] > 0) && (j < 16)) - { - ch1 = dafilename[j]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32; - ch2 = instname[i][j]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32; - if (ch1 != ch2) {bad = 1; break;} - j++; - } - if (bad == 0) - { - for (j=0; j oldestpos) { - oldest = j; - oldestpos = FSOUND_GetCurrentPosition(channels[j]); - } - } + j = 0; + while ((dafilename[j] > 0) && (j < 16)) + { + ch1 = dafilename[j]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32; + ch2 = instname[i][j]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32; + if (ch1 != ch2) {bad = 1; break;} + j++; + } + if (bad == 0) + { + for (j=0; j oldestpos) { + oldest = j; + oldestpos = FSOUND_GetCurrentPosition(channels[j]); + } + } - chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[i], NULL, 1); - if (chan == -1) return; - FSOUND_SetFrequency(chan, dafreq*11025/4096); - FSOUND_SetVolume(chan, (volume1*volume2)>>1); - // set pan - FSOUND_SetPaused(chan, 0); + if (free < 0) { + FSOUND_StopSound(channels[oldest]); + free = oldest; + } - channels[free] = chan; - - return; - } + chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[i], NULL, 1); + if (chan == -1) return; + FSOUND_SetFrequency(chan, dafreq*11025/4096); + FSOUND_SetVolume(chan, (volume1*volume2)>>1); + // set pan + FSOUND_SetPaused(chan, 0); - i--; - } while (i >= 0); + channels[free] = chan; + + return; + } + + i--; + } while (i >= 0); } void loadwaves(void) { - long fil, dawaversionum, i, tmp; - long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES]; - char *p; + long fil, dawaversionum, i, tmp; + long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES]; + char *p; - fil = kopen4load("WAVES.KWV", 0); + fil = kopen4load("WAVES.KWV", 0); - if (fil != -1) { - kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum); - if (dawaversionum != 0) { kclose(fil); return; } + if (fil != -1) { + kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum); + if (dawaversionum != 0) { kclose(fil); return; } - kread(fil, &numwaves, 4); numwaves = B_LITTLE32(numwaves); - for (i=0; inumparms == 0) { - if (maxrefreshfreq == 0) - OSD_Printf("maxrefreshfreq = No maximum\n"); - else - OSD_Printf("maxrefreshfreq = %d Hz\n",maxrefreshfreq); - return OSDCMD_OK; - } - if (parm->numparms != 1) return OSDCMD_SHOWHELP; - - freq = Batol(parm->parms[0]); - if (freq < 0) return OSDCMD_SHOWHELP; + int freq; + if (parm->numparms == 0) { + if (maxrefreshfreq == 0) + OSD_Printf("maxrefreshfreq = No maximum\n"); + else + OSD_Printf("maxrefreshfreq = %d Hz\n",maxrefreshfreq); + return OSDCMD_OK; + } + if (parm->numparms != 1) return OSDCMD_SHOWHELP; - maxrefreshfreq = (unsigned)freq; - modeschecked = 0; + freq = Batol(parm->parms[0]); + if (freq < 0) return OSDCMD_SHOWHELP; - return OSDCMD_OK; + maxrefreshfreq = (unsigned)freq; + modeschecked = 0; + + return OSDCMD_OK; } // @@ -546,43 +546,43 @@ static int set_maxrefreshfreq(const osdfuncparm_t *parm) // int initsystem(void) { - DEVMODE desktopmode; + DEVMODE desktopmode; - initprintf("Initialising Windows DirectX/GDI system interface\n"); + initprintf("Initialising Windows DirectX/GDI system interface\n"); - // get the desktop dimensions before anything changes them - ZeroMemory(&desktopmode, sizeof(DEVMODE)); - desktopmode.dmSize = sizeof(DEVMODE); - EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&desktopmode); + // get the desktop dimensions before anything changes them + ZeroMemory(&desktopmode, sizeof(DEVMODE)); + desktopmode.dmSize = sizeof(DEVMODE); + EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&desktopmode); - desktopxdim = desktopmode.dmPelsWidth; - desktopydim = desktopmode.dmPelsHeight; - desktopbpp = desktopmode.dmBitsPerPel; + desktopxdim = desktopmode.dmPelsWidth; + desktopydim = desktopmode.dmPelsHeight; + desktopbpp = desktopmode.dmBitsPerPel; - if (desktopbpp <= 8) - // save the system colours - SaveSystemColours(); + if (desktopbpp <= 8) + // save the system colours + SaveSystemColours(); - memset(curpalette, 0, sizeof(palette_t) * 256); + memset(curpalette, 0, sizeof(palette_t) * 256); - atexit(uninitsystem); + atexit(uninitsystem); - frameplace=0; - lockcount=0; + frameplace=0; + lockcount=0; #if defined(USE_OPENGL) && defined(POLYMOST) - if (loadgldriver(getenv("BUILD_GLDRV"))) { - initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); - nogl = 1; - } + if (loadgldriver(getenv("BUILD_GLDRV"))) { + initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); + nogl = 1; + } #endif - // try and start DirectDraw - if (InitDirectDraw()) - initprintf("DirectDraw initialisation failed. Fullscreen modes will be unavailable.\n"); + // try and start DirectDraw + if (InitDirectDraw()) + initprintf("DirectDraw initialisation failed. Fullscreen modes will be unavailable.\n"); - OSD_RegisterFunction("maxrefreshfreq", "maxrefreshfreq: maximum display frequency to set for OpenGL Polymost modes (0=no maximum)", set_maxrefreshfreq); - return 0; + OSD_RegisterFunction("maxrefreshfreq", "maxrefreshfreq: maximum display frequency to set for OpenGL Polymost modes (0=no maximum)", set_maxrefreshfreq); + return 0; } @@ -591,19 +591,19 @@ int initsystem(void) // void uninitsystem(void) { - DestroyAppWindow(); + DestroyAppWindow(); - if (startupdlg) { - DestroyWindow(startupdlg); - } + if (startupdlg) { + DestroyWindow(startupdlg); + } - uninitinput(); - uninittimer(); + uninitinput(); + uninittimer(); - win_allowtaskswitching(1); + win_allowtaskswitching(1); #if defined(USE_OPENGL) && defined(POLYMOST) - unloadgldriver(); + unloadgldriver(); #endif } @@ -613,60 +613,60 @@ void uninitsystem(void) // void initprintf(const char *f, ...) { - va_list va; - char buf[1024],*p=NULL,*q=NULL,workbuf[1024]; - //int i = 0; + va_list va; + char buf[1024],*p=NULL,*q=NULL,workbuf[1024]; + //int i = 0; - static int newline = 0;//1; -// int overwriteline = -1; - - va_start(va, f); - Bvsnprintf(buf, 1024, f, va); - va_end(va); - OSD_Printf(buf); - if (!startupdlg) return; + static int newline = 0;//1; + // int overwriteline = -1; - { - int curlen, linesbefore, linesafter; - HWND edctl; + va_start(va, f); + Bvsnprintf(buf, 1024, f, va); + va_end(va); + OSD_Printf(buf); + if (!startupdlg) return; - edctl = GetDlgItem(startupdlg,102); - if (!edctl) return; + { + int curlen, linesbefore, linesafter; + HWND edctl; - SendMessage(edctl, WM_SETREDRAW, FALSE,0); - curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); - SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); - linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - p = buf; - while (*p) { - if (newline) { - SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); - newline = 0; - } - q = p; - while (*q && *q != '\n') q++; - memcpy(workbuf, p, q-p); - if (*q == '\n') { - if (!q[1]) { - newline = 1; - workbuf[q-p] = 0; - } else { - workbuf[q-p] = '\r'; - workbuf[q-p+1] = '\n'; - workbuf[q-p+2] = 0; - } - p = q+1; - } else { - workbuf[q-p] = 0; - p = q; - } - SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); - } - linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); - SendMessage(edctl, WM_SETREDRAW, TRUE,0); - } - handleevents(); + edctl = GetDlgItem(startupdlg,102); + if (!edctl) return; + + SendMessage(edctl, WM_SETREDRAW, FALSE,0); + curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); + SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); + linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); + p = buf; + while (*p) { + if (newline) { + SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); + newline = 0; + } + q = p; + while (*q && *q != '\n') q++; + memcpy(workbuf, p, q-p); + if (*q == '\n') { + if (!q[1]) { + newline = 1; + workbuf[q-p] = 0; + } else { + workbuf[q-p] = '\r'; + workbuf[q-p+1] = '\n'; + workbuf[q-p+2] = 0; + } + p = q+1; + } else { + workbuf[q-p] = 0; + p = q; + } + SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); + } + linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); + SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); + SendMessage(edctl, WM_SETREDRAW, TRUE,0); + } + handleevents(); } @@ -676,16 +676,16 @@ void initprintf(const char *f, ...) void debugprintf(const char *f, ...) { #ifdef DEBUGGINGAIDS - va_list va; - char buf[1024]; + va_list va; + char buf[1024]; - if (!IsDebuggerPresent()) return; + if (!IsDebuggerPresent()) return; - va_start(va,f); - Bvsnprintf(buf, 1024, f, va); - va_end(va); + va_start(va,f); + Bvsnprintf(buf, 1024, f, va); + va_end(va); - OutputDebugString(buf); + OutputDebugString(buf); #endif } @@ -696,36 +696,36 @@ void debugprintf(const char *f, ...) // int handleevents(void) { - int rv=0; - MSG msg; + int rv=0; + MSG msg; - //if (frameplace && fullscreen) printf("Offscreen buffer is locked!\n"); + //if (frameplace && fullscreen) printf("Offscreen buffer is locked!\n"); - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - if (msg.message == WM_QUIT) - quitevent = 1; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) + quitevent = 1; - if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) continue; - - TranslateMessage(&msg); - DispatchMessage(&msg); - } + if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) continue; - ProcessInputDevices(); + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + ProcessInputDevices(); #ifdef DEBUGGINGAIDS - // break to the debugger if KP- is pressed - if (IsDebuggerPresent() && keystatus[0x4a]) { - keystatus[0x4a] = 0; - DebugBreak(); - } + // break to the debugger if KP- is pressed + if (IsDebuggerPresent() && keystatus[0x4a]) { + keystatus[0x4a] = 0; + DebugBreak(); + } #endif - if (!appactive || quitevent) rv = -1; + if (!appactive || quitevent) rv = -1; - sampletimer(); + sampletimer(); - return rv; + return rv; } @@ -756,48 +756,48 @@ static long joyblast=0; static char moustat = 0, mousegrab = 0; static struct { - char *name; - LPDIRECTINPUTDEVICE2A *did; - const DIDATAFORMAT *df; + char *name; + LPDIRECTINPUTDEVICE2A *did; + const DIDATAFORMAT *df; } devicedef[NUM_INPUTS] = { - { "keyboard", &lpDID[KEYBOARD], &c_dfDIKeyboard }, - { "mouse", &lpDID[MOUSE], &c_dfDIMouse }, - { "joystick", &lpDID[JOYSTICK], &c_dfDIJoystick } -}; + { "keyboard", &lpDID[KEYBOARD], &c_dfDIKeyboard }, + { "mouse", &lpDID[MOUSE], &c_dfDIMouse }, + { "joystick", &lpDID[JOYSTICK], &c_dfDIJoystick } + }; static struct _joydef { - const char *name; - unsigned ofs; // directinput 'dwOfs' value + const char *name; + unsigned ofs; // directinput 'dwOfs' value } *axisdefs = NULL, *buttondefs = NULL, *hatdefs = NULL; struct _joydevicefeature { - unsigned int ofs; - const char *name; + unsigned int ofs; + const char *name; }; struct _joydevicedefn { - unsigned long devid; // is the value of DIDEVICEINSTANCE.guidProduct.Data1 - int nfeatures; - struct _joydevicefeature *features; + unsigned long devid; // is the value of DIDEVICEINSTANCE.guidProduct.Data1 + int nfeatures; + struct _joydevicefeature *features; }; // This is to give more realistic names to the buttons, axes, etc on a controller than // those the driver reports. Curse inconsistency. struct _joydevicefeature joyfeatures_C20A046D[] = { // Logitech WingMan RumblePad USB - { 0, "Left Stick X" }, { 4, "Left Stick Y" }, { 8, "Right Stick X" }, - { 20, "Right Stick Y" }, { 24, "Throttle" }, -}; + { 0, "Left Stick X" }, { 4, "Left Stick Y" }, { 8, "Right Stick X" }, + { 20, "Right Stick Y" }, { 24, "Throttle" }, + }; struct _joydevicefeature joyfeatures_C218046D[] = { // Logitech RumblePad 2 USB - { 0, "Left Stick X" }, { 4, "Left Stick Y" }, { 8, "Right Stick X" }, - { 20, "Right Stick Y" }, { 32, "D-Pad" }, { 48, "Button 1" }, - { 49, "Button 2" }, { 50, "Button 3" }, { 51, "Button 4" }, - { 52, "Button 5" }, { 53, "Button 6" }, { 54, "Button 7" }, - { 55, "Button 8" }, { 56, "Button 9" }, { 57, "Button 10" }, - { 58, "Left Stick Press" }, { 59, "Right Stick Press" }, -}; + { 0, "Left Stick X" }, { 4, "Left Stick Y" }, { 8, "Right Stick X" }, + { 20, "Right Stick Y" }, { 32, "D-Pad" }, { 48, "Button 1" }, + { 49, "Button 2" }, { 50, "Button 3" }, { 51, "Button 4" }, + { 52, "Button 5" }, { 53, "Button 6" }, { 54, "Button 7" }, + { 55, "Button 8" }, { 56, "Button 9" }, { 57, "Button 10" }, + { 58, "Left Stick Press" }, { 59, "Right Stick Press" }, + }; #define featurecount(x) (sizeof(x)/sizeof(struct _joydevicefeature)) static struct _joydevicedefn *thisjoydef = NULL, joyfeatures[] = { - { 0xC20A046D, featurecount(joyfeatures_C20A046D), joyfeatures_C20A046D }, // Logitech WingMan RumblePad USB - { 0xC218046D, featurecount(joyfeatures_C218046D), joyfeatures_C218046D }, // Logitech RumblePad 2 USB -}; + { 0xC20A046D, featurecount(joyfeatures_C20A046D), joyfeatures_C20A046D }, // Logitech WingMan RumblePad USB + { 0xC218046D, featurecount(joyfeatures_C218046D), joyfeatures_C218046D }, // Logitech RumblePad 2 USB + }; #undef featurecount // I don't see any pressing need to store the key-up events yet @@ -816,18 +816,18 @@ static struct _joydevicedefn *thisjoydef = NULL, joyfeatures[] = { // int initinput(void) { - moustat=0; - memset(keystatus, 0, sizeof(keystatus)); - keyfifoplc = keyfifoend = 0; - keyasciififoplc = keyasciififoend = 0; + moustat=0; + memset(keystatus, 0, sizeof(keystatus)); + keyfifoplc = keyfifoend = 0; + keyasciififoplc = keyasciififoend = 0; - inputdevices = 0; - joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0; + inputdevices = 0; + joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0; - if (InitDirectInput()) - return -1; + if (InitDirectInput()) + return -1; - return 0; + return 0; } @@ -836,8 +836,8 @@ int initinput(void) // void uninitinput(void) { - uninitmouse(); - UninitDirectInput(); + uninitmouse(); + UninitDirectInput(); } @@ -846,21 +846,21 @@ void uninitinput(void) // unsigned char bgetchar(void) { - unsigned char c; - if (keyasciififoplc == keyasciififoend) return 0; - c = keyasciififo[keyasciififoplc]; - keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1)); - return c; + unsigned char c; + if (keyasciififoplc == keyasciififoend) return 0; + c = keyasciififo[keyasciififoplc]; + keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1)); + return c; } int bkbhit(void) { - return (keyasciififoplc != keyasciififoend); + return (keyasciififoplc != keyasciififoend); } void bflushchars(void) { - keyasciififoplc = keyasciififoend = 0; + keyasciififoplc = keyasciififoend = 0; } @@ -877,15 +877,15 @@ void setjoypresscallback(void (*callback)(long, long)) { joypresscallback = call // int initmouse(void) { - if (moustat) return 0; + if (moustat) return 0; - initprintf("Initialising mouse\n"); + initprintf("Initialising mouse\n"); - // grab input - moustat=1; - grabmouse(1); + // grab input + moustat=1; + grabmouse(1); - return 0; + return 0; } @@ -894,10 +894,10 @@ int initmouse(void) // void uninitmouse(void) { - if (!moustat) return; + if (!moustat) return; - grabmouse(0); - moustat=mousegrab=0; + grabmouse(0); + moustat=mousegrab=0; } @@ -906,14 +906,14 @@ void uninitmouse(void) // void grabmouse(char a) { - if (!moustat) return; + if (!moustat) return; - mousegrab = a; - AcquireInputDevices(a,MOUSE); // only release or grab the mouse + mousegrab = a; + AcquireInputDevices(a,MOUSE); // only release or grab the mouse - mousex = 0; - mousey = 0; - mouseb = 0; + mousex = 0; + mousey = 0; + mouseb = 0; } @@ -922,11 +922,11 @@ void grabmouse(char a) // void readmousexy(long *x, long *y) { - if (!moustat || !devacquired[MOUSE] || !mousegrab) { *x = *y = 0; return; } - *x = mousex; - *y = mousey; - mousex = 0; - mousey = 0; + if (!moustat || !devacquired[MOUSE] || !mousegrab) { *x = *y = 0; return; } + *x = mousex; + *y = mousey; + mousex = 0; + mousey = 0; } @@ -935,8 +935,8 @@ void readmousexy(long *x, long *y) // void readmousebstatus(long *b) { - if (!moustat || !devacquired[MOUSE] || !mousegrab) *b = 0; - else *b = mouseb; + if (!moustat || !devacquired[MOUSE] || !mousegrab) *b = 0; + else *b = mouseb; } @@ -945,43 +945,43 @@ void readmousebstatus(long *b) // void setjoydeadzone(int axis, unsigned short dead, unsigned short satur) { - DIPROPDWORD dipdw; - HRESULT result; + DIPROPDWORD dipdw; + HRESULT result; - if (!lpDID[JOYSTICK]) return; + if (!lpDID[JOYSTICK]) return; - if (dead > 10000) dead = 10000; - if (satur > 10000) satur = 10000; - if (dead >= satur) dead = satur-100; - if (axis >= joynumaxes) return; + if (dead > 10000) dead = 10000; + if (satur > 10000) satur = 10000; + if (dead >= satur) dead = satur-100; + if (axis >= joynumaxes) return; - memset(&dipdw, 0, sizeof(dipdw)); - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - if (axis < 0) { - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - } else { - dipdw.diph.dwObj = axisdefs[axis].ofs; - dipdw.diph.dwHow = DIPH_BYOFFSET; - } - dipdw.dwData = dead; + memset(&dipdw, 0, sizeof(dipdw)); + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); + if (axis < 0) { + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + } else { + dipdw.diph.dwObj = axisdefs[axis].ofs; + dipdw.diph.dwHow = DIPH_BYOFFSET; + } + dipdw.dwData = dead; - result = IDirectInputDevice2_SetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph); - if FAILED(result) { - //ShowDInputErrorBox("Failed setting joystick dead zone", result); - initprintf("Failed setting joystick dead zone: %s\n", GetDInputError(result)); - return; - } - - dipdw.dwData = satur; + result = IDirectInputDevice2_SetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph); + if FAILED(result) { + //ShowDInputErrorBox("Failed setting joystick dead zone", result); + initprintf("Failed setting joystick dead zone: %s\n", GetDInputError(result)); + return; + } - result = IDirectInputDevice2_SetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph); - if FAILED(result) { - //ShowDInputErrorBox("Failed setting joystick saturation point", result); - initprintf("Failed setting joystick saturation point: %s\n", GetDInputError(result)); - return; - } + dipdw.dwData = satur; + + result = IDirectInputDevice2_SetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph); + if FAILED(result) { + //ShowDInputErrorBox("Failed setting joystick saturation point", result); + initprintf("Failed setting joystick saturation point: %s\n", GetDInputError(result)); + return; + } } @@ -990,74 +990,74 @@ void setjoydeadzone(int axis, unsigned short dead, unsigned short satur) // void getjoydeadzone(int axis, unsigned short *dead, unsigned short *satur) { - DIPROPDWORD dipdw; - HRESULT result; + DIPROPDWORD dipdw; + HRESULT result; - if (!dead || !satur) return; - if (!lpDID[JOYSTICK]) { *dead = *satur = 0; return; } - if (axis >= joynumaxes) { *dead = *satur = 0; return; } + if (!dead || !satur) return; +if (!lpDID[JOYSTICK]) { *dead = *satur = 0; return; } + if (axis >= joynumaxes) { *dead = *satur = 0; return; } - memset(&dipdw, 0, sizeof(dipdw)); - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - if (axis < 0) { - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - } else { - dipdw.diph.dwObj = axisdefs[axis].ofs; - dipdw.diph.dwHow = DIPH_BYOFFSET; - } + memset(&dipdw, 0, sizeof(dipdw)); + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); + if (axis < 0) { + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + } else { + dipdw.diph.dwObj = axisdefs[axis].ofs; + dipdw.diph.dwHow = DIPH_BYOFFSET; + } - result = IDirectInputDevice2_GetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph); - if FAILED(result) { - //ShowDInputErrorBox("Failed getting joystick dead zone", result); - initprintf("Failed getting joystick dead zone: %s\n", GetDInputError(result)); - return; - } + result = IDirectInputDevice2_GetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph); + if FAILED(result) { + //ShowDInputErrorBox("Failed getting joystick dead zone", result); + initprintf("Failed getting joystick dead zone: %s\n", GetDInputError(result)); + return; + } - *dead = dipdw.dwData; - - result = IDirectInputDevice2_GetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph); - if FAILED(result) { - //ShowDInputErrorBox("Failed getting joystick saturation point", result); - initprintf("Failed getting joystick saturation point: %s\n", GetDInputError(result)); - return; - } + *dead = dipdw.dwData; - *satur = dipdw.dwData; + result = IDirectInputDevice2_GetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph); + if FAILED(result) { + //ShowDInputErrorBox("Failed getting joystick saturation point", result); + initprintf("Failed getting joystick saturation point: %s\n", GetDInputError(result)); + return; + } + + *satur = dipdw.dwData; } void releaseallbuttons(void) { - int i; - - if (mousepresscallback) { - if (mouseb & 1) mousepresscallback(1, 0); - if (mouseb & 2) mousepresscallback(2, 0); - if (mouseb & 4) mousepresscallback(3, 0); - if (mouseb & 8) mousepresscallback(4, 0); - if (mousewheel[0]>0) mousepresscallback(5,0); - if (mousewheel[1]>0) mousepresscallback(6,0); - } - mousewheel[0]=mousewheel[1]=0; - mouseb = 0; + int i; - if (joypresscallback) { - for (i=0;i<32;i++) - if (joyb & (1<0) mousepresscallback(5,0); + if (mousewheel[1]>0) mousepresscallback(6,0); + } + mousewheel[0]=mousewheel[1]=0; + mouseb = 0; - for (i=0;i<256;i++) { - //if (!keystatus[i]) continue; - //if (OSD_HandleKey(i, 0) != 0) { - OSD_HandleKey(i, 0); - SetKey(i, 0); - if (keypresscallback) keypresscallback(i, 0); - //} - } - lastKeyDown = lastKeyTime = 0; + if (joypresscallback) { + for (i=0;i<32;i++) + if (joyb & (1<dwDevType&0xff) { - case DIDEVTYPE_KEYBOARD: - inputdevices |= (1<guidInstance); - break; - case DIDEVTYPE_MOUSE: - inputdevices |= (1<guidInstance); - break; - case DIDEVTYPE_JOYSTICK: - inputdevices |= (1<dwDevType & (DIDEVTYPEJOYSTICK_GAMEPAD<<8)) != 0); - d = joyisgamepad ? "GAMEPAD" : "JOYSTICK"; - COPYGUID(guidDevs[JOYSTICK],lpddi->guidInstance); - thisjoydef = NULL; - for (i=0; i<(int)(sizeof(joyfeatures)/sizeof(joyfeatures[0])); i++) { - if (lpddi->guidProduct.Data1 == joyfeatures[i].devid) { - thisjoydef = &joyfeatures[i]; - break; - } - } + switch (lpddi->dwDevType&0xff) { + case DIDEVTYPE_KEYBOARD: + inputdevices |= (1<guidInstance); + break; + case DIDEVTYPE_MOUSE: + inputdevices |= (1<guidInstance); + break; + case DIDEVTYPE_JOYSTICK: + inputdevices |= (1<dwDevType & (DIDEVTYPEJOYSTICK_GAMEPAD<<8)) != 0); + d = joyisgamepad ? "GAMEPAD" : "JOYSTICK"; + COPYGUID(guidDevs[JOYSTICK],lpddi->guidInstance); - // Outputs the GUID of the joystick to the console - /* - initprintf("GUID = {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n", - lpddi->guidProduct.Data1, - lpddi->guidProduct.Data2, lpddi->guidProduct.Data3, - lpddi->guidProduct.Data4[0], lpddi->guidProduct.Data4[1], - lpddi->guidProduct.Data4[2], lpddi->guidProduct.Data4[3], - lpddi->guidProduct.Data4[4], lpddi->guidProduct.Data4[5], - lpddi->guidProduct.Data4[6], lpddi->guidProduct.Data4[7] - ); - */ - break; - default: d = "OTHER"; break; - } - - initprintf(" * %s: %s\n", d, lpddi->tszProductName); + thisjoydef = NULL; + for (i=0; i<(int)(sizeof(joyfeatures)/sizeof(joyfeatures[0])); i++) { + if (lpddi->guidProduct.Data1 == joyfeatures[i].devid) { + thisjoydef = &joyfeatures[i]; + break; + } + } - return DIENUM_CONTINUE; + // Outputs the GUID of the joystick to the console + /* + initprintf("GUID = {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n", + lpddi->guidProduct.Data1, + lpddi->guidProduct.Data2, lpddi->guidProduct.Data3, + lpddi->guidProduct.Data4[0], lpddi->guidProduct.Data4[1], + lpddi->guidProduct.Data4[2], lpddi->guidProduct.Data4[3], + lpddi->guidProduct.Data4[4], lpddi->guidProduct.Data4[5], + lpddi->guidProduct.Data4[6], lpddi->guidProduct.Data4[7] + ); + */ + break; + default: d = "OTHER"; break; + } + + initprintf(" * %s: %s\n", d, lpddi->tszProductName); + + return DIENUM_CONTINUE; } static const char *joyfindnameforofs(int ofs) { - int i; - if (!thisjoydef) return NULL; - for (i=0;infeatures;i++) { - if (ofs == (int)thisjoydef->features[i].ofs) - return Bstrdup(thisjoydef->features[i].name); - } - return NULL; + int i; + if (!thisjoydef) return NULL; + for (i=0;infeatures;i++) { + if (ofs == (int)thisjoydef->features[i].ofs) + return Bstrdup(thisjoydef->features[i].name); + } + return NULL; } static BOOL CALLBACK InitDirectInput_enumobjects(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { - unsigned i; - long *typecounts = (long*)pvRef; + unsigned i; + long *typecounts = (long*)pvRef; - if (lpddoi->dwType & DIDFT_AXIS) { - //initprintf(" Axis: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); + if (lpddoi->dwType & DIDFT_AXIS) { + //initprintf(" Axis: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); - axisdefs[ typecounts[0] ].name = joyfindnameforofs(lpddoi->dwOfs); - if (!axisdefs[ typecounts[0] ].name) - axisdefs[ typecounts[0] ].name = Bstrdup(lpddoi->tszName); - axisdefs[ typecounts[0] ].ofs = lpddoi->dwOfs; + axisdefs[ typecounts[0] ].name = joyfindnameforofs(lpddoi->dwOfs); + if (!axisdefs[ typecounts[0] ].name) + axisdefs[ typecounts[0] ].name = Bstrdup(lpddoi->tszName); + axisdefs[ typecounts[0] ].ofs = lpddoi->dwOfs; - typecounts[0]++; - } else if (lpddoi->dwType & DIDFT_BUTTON) { - //initprintf(" Button: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); + typecounts[0]++; + } else if (lpddoi->dwType & DIDFT_BUTTON) { + //initprintf(" Button: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); - buttondefs[ typecounts[1] ].name = joyfindnameforofs(lpddoi->dwOfs); - if (!buttondefs[ typecounts[1] ].name) - buttondefs[ typecounts[1] ].name = Bstrdup(lpddoi->tszName); - buttondefs[ typecounts[1] ].ofs = lpddoi->dwOfs; + buttondefs[ typecounts[1] ].name = joyfindnameforofs(lpddoi->dwOfs); + if (!buttondefs[ typecounts[1] ].name) + buttondefs[ typecounts[1] ].name = Bstrdup(lpddoi->tszName); + buttondefs[ typecounts[1] ].ofs = lpddoi->dwOfs; - typecounts[1]++; - } else if (lpddoi->dwType & DIDFT_POV) { - //initprintf(" POV: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); + typecounts[1]++; + } else if (lpddoi->dwType & DIDFT_POV) { + //initprintf(" POV: %s (dwOfs=%d)\n", lpddoi->tszName, lpddoi->dwOfs); - hatdefs[ typecounts[2] ].name = joyfindnameforofs(lpddoi->dwOfs); - if (!hatdefs[ typecounts[2] ].name) - hatdefs[ typecounts[2] ].name = Bstrdup(lpddoi->tszName); - hatdefs[ typecounts[2] ].ofs = lpddoi->dwOfs; + hatdefs[ typecounts[2] ].name = joyfindnameforofs(lpddoi->dwOfs); + if (!hatdefs[ typecounts[2] ].name) + hatdefs[ typecounts[2] ].name = Bstrdup(lpddoi->tszName); + hatdefs[ typecounts[2] ].ofs = lpddoi->dwOfs; - typecounts[2]++; - } + typecounts[2]++; + } - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } #define HorribleDInputDeath( x, y ) \ @@ -1173,132 +1173,132 @@ static BOOL CALLBACK InitDirectInput_enumobjects(LPCDIDEVICEOBJECTINSTANCE lpddo static BOOL InitDirectInput(void) { - HRESULT result; - HRESULT (WINAPI *aDirectInputCreateA)(HINSTANCE, DWORD, LPDIRECTINPUTA *, LPUNKNOWN); - DIPROPDWORD dipdw; - LPDIRECTINPUTDEVICEA dev; - LPDIRECTINPUTDEVICE2A dev2; - DIDEVCAPS didc; + HRESULT result; + HRESULT (WINAPI *aDirectInputCreateA)(HINSTANCE, DWORD, LPDIRECTINPUTA *, LPUNKNOWN); + DIPROPDWORD dipdw; + LPDIRECTINPUTDEVICEA dev; + LPDIRECTINPUTDEVICE2A dev2; + DIDEVCAPS didc; - int devn,i; + int devn,i; - if (bDInputInited) return FALSE; + if (bDInputInited) return FALSE; - initprintf("Initialising DirectInput...\n"); + initprintf("Initialising DirectInput...\n"); - // load up the DirectInput DLL - if (!hDInputDLL) { - initprintf(" - Loading DINPUT.DLL\n"); - hDInputDLL = LoadLibrary("DINPUT.DLL"); - if (!hDInputDLL) { - ShowErrorBox("Error loading DINPUT.DLL"); - return TRUE; - } - } + // load up the DirectInput DLL + if (!hDInputDLL) { + initprintf(" - Loading DINPUT.DLL\n"); + hDInputDLL = LoadLibrary("DINPUT.DLL"); + if (!hDInputDLL) { + ShowErrorBox("Error loading DINPUT.DLL"); + return TRUE; + } + } - // get the pointer to DirectInputCreate - aDirectInputCreateA = (void *)GetProcAddress(hDInputDLL, "DirectInputCreateA"); - if (!aDirectInputCreateA) ShowErrorBox("Error fetching DirectInputCreateA()"); + // get the pointer to DirectInputCreate + aDirectInputCreateA = (void *)GetProcAddress(hDInputDLL, "DirectInputCreateA"); + if (!aDirectInputCreateA) ShowErrorBox("Error fetching DirectInputCreateA()"); - // create a new DirectInput object - initprintf(" - Creating DirectInput object\n"); - result = aDirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &lpDI, NULL); - if FAILED(result) { HorribleDInputDeath("DirectInputCreateA() failed", result); } - else if (result != DI_OK) initprintf(" Created DirectInput object with warning: %s\n",GetDInputError(result)); + // create a new DirectInput object + initprintf(" - Creating DirectInput object\n"); + result = aDirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &lpDI, NULL); +if FAILED(result) { HorribleDInputDeath("DirectInputCreateA() failed", result); } + else if (result != DI_OK) initprintf(" Created DirectInput object with warning: %s\n",GetDInputError(result)); - // enumerate devices to make us look fancy - initprintf(" - Enumerating attached input devices\n"); - inputdevices = 0; - result = IDirectInput_EnumDevices(lpDI, 0, InitDirectInput_enum, NULL, DIEDFL_ATTACHEDONLY); - if FAILED(result) { HorribleDInputDeath("Failed enumerating attached input devices", result); } - else if (result != DI_OK) initprintf(" Enumerated input devices with warning: %s\n",GetDInputError(result)); - if (!(inputdevices & (1<=0; i--) if (axisdefs[i].name) free((void*)axisdefs[i].name); - free(axisdefs); axisdefs = NULL; - } - if (buttondefs) { - for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) free((void*)buttondefs[i].name); - free(buttondefs); buttondefs = NULL; - } - if (hatdefs) { - for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) free((void*)hatdefs[i].name); - free(hatdefs); hatdefs = NULL; - } - - for (devn = 0; devn < NUM_INPUTS; devn++) { - if (*devicedef[devn].did) { - initprintf(" - Releasing %s device\n", devicedef[devn].name); - - if (devn != JOYSTICK) IDirectInputDevice2_SetEventNotification(*devicedef[devn].did, NULL); + AcquireInputDevices(0,-1); - IDirectInputDevice2_Release(*devicedef[devn].did); - *devicedef[devn].did = NULL; - } - if (inputevt[devn]) { - CloseHandle(inputevt[devn]); - inputevt[devn] = NULL; - } - } + if (axisdefs) { + for (i=joynumaxes-1; i>=0; i--) if (axisdefs[i].name) free((void*)axisdefs[i].name); + free(axisdefs); axisdefs = NULL; + } + if (buttondefs) { + for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) free((void*)buttondefs[i].name); + free(buttondefs); buttondefs = NULL; + } + if (hatdefs) { + for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) free((void*)hatdefs[i].name); + free(hatdefs); hatdefs = NULL; + } - if (lpDI) { - initprintf(" - Releasing DirectInput object\n"); - IDirectInput_Release(lpDI); - lpDI = NULL; - } + for (devn = 0; devn < NUM_INPUTS; devn++) { + if (*devicedef[devn].did) { + initprintf(" - Releasing %s device\n", devicedef[devn].name); - if (hDInputDLL) { - initprintf(" - Unloading DINPUT.DLL\n"); - FreeLibrary(hDInputDLL); - hDInputDLL = NULL; - } + if (devn != JOYSTICK) IDirectInputDevice2_SetEventNotification(*devicedef[devn].did, NULL); - bDInputInited = FALSE; + IDirectInputDevice2_Release(*devicedef[devn].did); + *devicedef[devn].did = NULL; + } + if (inputevt[devn]) { + CloseHandle(inputevt[devn]); + inputevt[devn] = NULL; + } + } + + if (lpDI) { + initprintf(" - Releasing DirectInput object\n"); + IDirectInput_Release(lpDI); + lpDI = NULL; + } + + if (hDInputDLL) { + initprintf(" - Unloading DINPUT.DLL\n"); + FreeLibrary(hDInputDLL); + hDInputDLL = NULL; + } + + bDInputInited = FALSE; } @@ -1363,48 +1363,48 @@ static void UninitDirectInput(void) // static void GetKeyNames(void) { - int i; - DIDEVICEOBJECTINSTANCE key; - HRESULT res; - char tbuf[MAX_PATH]; - - memset(keynames,0,sizeof(keynames)); - for (i=0;i<256;i++) { - ZeroMemory(&key,sizeof(key)); - key.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); + int i; + DIDEVICEOBJECTINSTANCE key; + HRESULT res; + char tbuf[MAX_PATH]; - res = IDirectInputDevice_GetObjectInfo(*devicedef[KEYBOARD].did, &key, i, DIPH_BYOFFSET); - if (FAILED(res)) continue; + memset(keynames,0,sizeof(keynames)); + for (i=0;i<256;i++) { + ZeroMemory(&key,sizeof(key)); + key.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); - CharToOem(key.tszName, tbuf); - strncpy(keynames[i], tbuf, sizeof(keynames[i])-1); - } + res = IDirectInputDevice_GetObjectInfo(*devicedef[KEYBOARD].did, &key, i, DIPH_BYOFFSET); + if (FAILED(res)) continue; + + CharToOem(key.tszName, tbuf); + strncpy(keynames[i], tbuf, sizeof(keynames[i])-1); + } } const unsigned char *getkeyname(int num) { - if ((unsigned)num >= 256) return NULL; - return keynames[num]; + if ((unsigned)num >= 256) return NULL; + return keynames[num]; } const unsigned char *getjoyname(int what, int num) { - switch (what) { - case 0: // axis - if ((unsigned)num > (unsigned)joynumaxes) return NULL; - return axisdefs[num].name; + switch (what) { + case 0: // axis + if ((unsigned)num > (unsigned)joynumaxes) return NULL; + return axisdefs[num].name; - case 1: // button - if ((unsigned)num > (unsigned)joynumbuttons) return NULL; - return buttondefs[num].name; + case 1: // button + if ((unsigned)num > (unsigned)joynumbuttons) return NULL; + return buttondefs[num].name; - case 2: // hat - if ((unsigned)num > (unsigned)joynumhats) return NULL; - return hatdefs[num].name; + case 2: // hat + if ((unsigned)num > (unsigned)joynumhats) return NULL; + return hatdefs[num].name; - default: - return NULL; - } + default: + return NULL; + } } // @@ -1412,52 +1412,52 @@ const unsigned char *getjoyname(int what, int num) // static void AcquireInputDevices(char acquire, signed char device) { - DWORD flags; - HRESULT result; - int i; + DWORD flags; + HRESULT result; + int i; - if (!bDInputInited) return; - if (!hWindow) return; + if (!bDInputInited) return; + if (!hWindow) return; - if (acquire) { - if (!appactive) return; // why acquire when inactive? - for (i=0; i 0 && t - mousewheel[0] > MouseWheelFakePressTime) { - if (mousepresscallback) mousepresscallback(5,0); - mousewheel[0] = 0; mouseb &= ~16; - } - if (mousewheel[1] > 0 && t - mousewheel[1] > MouseWheelFakePressTime) { - if (mousepresscallback) mousepresscallback(6,0); - mousewheel[1] = 0; mouseb &= ~32; - } - } + if (devacquired[t]) { + waithnds[numdevs] = inputevt[t]; + idevnums[numdevs] = t; + numdevs++; + } + } + } - if (numdevs == 0) return; // nothing to do + t = getticks(); - // use event objects so that we can quickly get indication of when data is ready - // to be read and input events processed - ev = MsgWaitForMultipleObjects(numdevs, waithnds, FALSE, 0, 0); - if (/*(ev >= WAIT_OBJECT_0) &&*/ (ev < (WAIT_OBJECT_0+numdevs))) { - switch (idevnums[ev - WAIT_OBJECT_0]) { - case KEYBOARD: // keyboard - if (!lpDID[KEYBOARD]) break; - result = IDirectInputDevice2_GetDeviceData(lpDID[KEYBOARD], sizeof(DIDEVICEOBJECTDATA), - (LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0); - if (result == DI_OK) { - DWORD k, numlockon = FALSE; - static DWORD shiftkey = 0, shiftkeycount = 0; - - numlockon = (GetKeyState(VK_NUMLOCK) & 1); - - // process the key events - for (i=0; i 0 && t - mousewheel[0] > MouseWheelFakePressTime) { + if (mousepresscallback) mousepresscallback(5,0); + mousewheel[0] = 0; mouseb &= ~16; + } + if (mousewheel[1] > 0 && t - mousewheel[1] > MouseWheelFakePressTime) { + if (mousepresscallback) mousepresscallback(6,0); + mousewheel[1] = 0; mouseb &= ~32; + } + } + + if (numdevs == 0) return; // nothing to do + + // use event objects so that we can quickly get indication of when data is ready + // to be read and input events processed + ev = MsgWaitForMultipleObjects(numdevs, waithnds, FALSE, 0, 0); + if (/*(ev >= WAIT_OBJECT_0) &&*/ (ev < (WAIT_OBJECT_0+numdevs))) { + switch (idevnums[ev - WAIT_OBJECT_0]) { + case KEYBOARD: // keyboard + if (!lpDID[KEYBOARD]) break; + result = IDirectInputDevice2_GetDeviceData(lpDID[KEYBOARD], sizeof(DIDEVICEOBJECTDATA), + (LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0); + if (result == DI_OK) { + DWORD k, numlockon = FALSE; + static DWORD shiftkey = 0, shiftkeycount = 0; + + numlockon = (GetKeyState(VK_NUMLOCK) & 1); + + // process the key events + for (i=0; i shiftkey=1, shiftkeycount=0\n"); - } - } else { - if ((thiskey == (SHIFT|UP)) && (nextkey == (NUMPAD|DOWN))) { - shiftkeycount--; - initprintf("shift is up and next key is numpad and down, shiftkeycount=%d\n", - shiftkeycount); - continue; - } else if (thiskey & SHIFT) { - if (thiskey & DOWN) { - shiftkeycount++; - initprintf("shift key down, shiftkeycount=%d\n", shiftkeycount); - continue; - } else { - if (shiftkeycount == 0) { - shiftkey = 0; - initprintf("shift key up and shiftkeycount == 0, shiftkey=0\n"); - } else { - shiftkeycount--; - initprintf("shift key up and shiftkeycount=%d\n",shiftkeycount); - continue; - } - } - } - } + DWORD j, thiskey = 0, nextkey = 0; + for (j=i; j<=min(i+1,dwElements-1); j++) { + switch (didod[j].dwOfs) { + case DIK_NUMPAD1: case DIK_NUMPAD2: case DIK_NUMPAD3: + case DIK_NUMPAD4: case DIK_NUMPAD5: case DIK_NUMPAD6: + case DIK_NUMPAD7: case DIK_NUMPAD8: case DIK_NUMPAD9: + case DIK_NUMPAD0: case DIK_PERIOD: + if (j==i) thiskey = NUMPAD | ((didod[j].dwData&128)?DOWN:UP); + else nextkey = NUMPAD | ((didod[j].dwData&128)?DOWN:UP); + break; + case DIK_LSHIFT: case DIK_RSHIFT: + if (j==i) thiskey = SHIFT | ((didod[j].dwData&128)?DOWN:UP); + else nextkey = SHIFT | ((didod[j].dwData&128)?DOWN:UP); + break; + default: break; + } + } + if (!shiftkey) { + if (thiskey == (SHIFT|DOWN)) { + shiftkey = 1, shiftkeycount = 0; + initprintf("shift is down --> shiftkey=1, shiftkeycount=0\n"); + } + } else { + if ((thiskey == (SHIFT|UP)) && (nextkey == (NUMPAD|DOWN))) { + shiftkeycount--; + initprintf("shift is up and next key is numpad and down, shiftkeycount=%d\n", + shiftkeycount); + continue; + } else if (thiskey & SHIFT) { + if (thiskey & DOWN) { + shiftkeycount++; + initprintf("shift key down, shiftkeycount=%d\n", shiftkeycount); + continue; + } else { + if (shiftkeycount == 0) { + shiftkey = 0; + initprintf("shift key up and shiftkeycount == 0, shiftkey=0\n"); + } else { + shiftkeycount--; + initprintf("shift key up and shiftkeycount=%d\n",shiftkeycount); + continue; + } + } + } + } #undef NUMPAD #undef SHIFT #undef UP #undef DOWN - } + } #endif - - if (k == DIK_PAUSE) continue; // fucking pause - - // hook in the osd - if (OSD_HandleKey(k, (didod[i].dwData & 0x80)) != 0) { - SetKey(k, (didod[i].dwData & 0x80) == 0x80); - if (keypresscallback) - keypresscallback(k, (didod[i].dwData & 0x80) == 0x80); - } + if (k == DIK_PAUSE) continue; // fucking pause - if (((lastKeyDown & 0x7fffffffl) == k) && !(didod[i].dwData & 0x80)) - lastKeyDown = 0; - else if (didod[i].dwData & 0x80) { - lastKeyDown = k; - lastKeyTime = t; - } - } - } - break; - - case MOUSE: // mouse - if (!lpDID[MOUSE]) break; - result = IDirectInputDevice2_GetDeviceData(lpDID[MOUSE], sizeof(DIDEVICEOBJECTDATA), - (LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0); + // hook in the osd + if (OSD_HandleKey(k, (didod[i].dwData & 0x80)) != 0) { + SetKey(k, (didod[i].dwData & 0x80) == 0x80); - if (!mousegrab) break; + if (keypresscallback) + keypresscallback(k, (didod[i].dwData & 0x80) == 0x80); + } - if (result == DI_OK) { - // process the mouse events - mousex=0; - mousey=0; - for (i=0; i 0) { // wheel up - if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0); - mousewheel[1] = t; - mouseb |= 32; if (mousepresscallback) mousepresscallback(6, 1); - } - else if ((int)didod[i].dwData < 0) { // wheel down - if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0); - mousewheel[0] = t; - mouseb |= 16; if (mousepresscallback) mousepresscallback(5, 1); - } - break; - } - } - } - break; - case JOYSTICK: // joystick - if (!lpDID[JOYSTICK]) break; - result = IDirectInputDevice2_GetDeviceData(lpDID[JOYSTICK], sizeof(DIDEVICEOBJECTDATA), - (LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0); - if (result == DI_OK) { - int j; - - for (i=0; i 0) { - u = (1000 + t - lastKeyTime)%1000; - if ((u >= 250) && !(lastKeyDown&0x80000000l)) { - if (OSD_HandleKey(lastKeyDown, 1) != 0) - SetKey(lastKeyDown, 1); - lastKeyDown |= 0x80000000l; - lastKeyTime = t; - } else if ((u >= 30) && (lastKeyDown&0x80000000l)) { - if (OSD_HandleKey(lastKeyDown&(0x7fffffffl), 1) != 0) - SetKey(lastKeyDown&(0x7fffffffl), 1); - lastKeyTime = t; - } - } + if (result == DI_OK) { + // process the mouse events + mousex=0; + mousey=0; + for (i=0; i 0) { // wheel up + if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0); + mousewheel[1] = t; + mouseb |= 32; if (mousepresscallback) mousepresscallback(6, 1); + } + else if ((int)didod[i].dwData < 0) { // wheel down + if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0); + mousewheel[0] = t; + mouseb |= 16; if (mousepresscallback) mousepresscallback(5, 1); + } + break; + } + } + } + break; + case JOYSTICK: // joystick + if (!lpDID[JOYSTICK]) break; + result = IDirectInputDevice2_GetDeviceData(lpDID[JOYSTICK], sizeof(DIDEVICEOBJECTDATA), + (LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0); + if (result == DI_OK) { + int j; + + for (i=0; i 0) { + u = (1000 + t - lastKeyTime)%1000; + if ((u >= 250) && !(lastKeyDown&0x80000000l)) { + if (OSD_HandleKey(lastKeyDown, 1) != 0) + SetKey(lastKeyDown, 1); + lastKeyDown |= 0x80000000l; + lastKeyTime = t; + } else if ((u >= 30) && (lastKeyDown&0x80000000l)) { + if (OSD_HandleKey(lastKeyDown&(0x7fffffffl), 1) != 0) + SetKey(lastKeyDown&(0x7fffffffl), 1); + lastKeyTime = t; + } + } } @@ -1739,10 +1739,10 @@ static void ProcessInputDevices(void) // static void ShowDInputErrorBox(const char *m, HRESULT r) { - TCHAR msg[1024]; + TCHAR msg[1024]; - wsprintf(msg, "%s: %s", m, GetDInputError(r)); - MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP); + wsprintf(msg, "%s: %s", m, GetDInputError(r)); + MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP); } @@ -1752,43 +1752,43 @@ static void ShowDInputErrorBox(const char *m, HRESULT r) // static const char * GetDInputError(HRESULT code) { - switch (code) { - case DI_OK: return "DI_OK"; - case DI_BUFFEROVERFLOW: return "DI_BUFFEROVERFLOW"; - case DI_DOWNLOADSKIPPED: return "DI_DOWNLOADSKIPPED"; - case DI_EFFECTRESTARTED: return "DI_EFFECTRESTARTED"; - case DI_POLLEDDEVICE: return "DI_POLLEDDEVICE"; - case DI_TRUNCATED: return "DI_TRUNCATED"; - case DI_TRUNCATEDANDRESTARTED: return "DI_TRUNCATEDANDRESTARTED"; - case DIERR_ACQUIRED: return "DIERR_ACQUIRED"; - case DIERR_ALREADYINITIALIZED: return "DIERR_ALREADYINITIALIZED"; - case DIERR_BADDRIVERVER: return "DIERR_BADDRIVERVER"; - case DIERR_BETADIRECTINPUTVERSION: return "DIERR_BETADIRECTINPUTVERSION"; - case DIERR_DEVICEFULL: return "DIERR_DEVICEFULL"; - case DIERR_DEVICENOTREG: return "DIERR_DEVICENOTREG"; - case DIERR_EFFECTPLAYING: return "DIERR_EFFECTPLAYING"; - case DIERR_HASEFFECTS: return "DIERR_HASEFFECTS"; - case DIERR_GENERIC: return "DIERR_GENERIC"; - case DIERR_HANDLEEXISTS: return "DIERR_HANDLEEXISTS"; - case DIERR_INCOMPLETEEFFECT: return "DIERR_INCOMPLETEEFFECT"; - case DIERR_INPUTLOST: return "DIERR_INPUTLOST"; - case DIERR_INVALIDPARAM: return "DIERR_INVALIDPARAM"; - case DIERR_MOREDATA: return "DIERR_MOREDATA"; - case DIERR_NOAGGREGATION: return "DIERR_NOAGGREGATION"; - case DIERR_NOINTERFACE: return "DIERR_NOINTERFACE"; - case DIERR_NOTACQUIRED: return "DIERR_NOTACQUIRED"; - case DIERR_NOTBUFFERED: return "DIERR_NOTBUFFERED"; - case DIERR_NOTDOWNLOADED: return "DIERR_NOTDOWNLOADED"; - case DIERR_NOTEXCLUSIVEACQUIRED: return "DIERR_NOTEXCLUSIVEACQUIRED"; - case DIERR_NOTFOUND: return "DIERR_NOTFOUND"; - case DIERR_NOTINITIALIZED: return "DIERR_NOTINITIALIZED"; - case DIERR_OLDDIRECTINPUTVERSION: return "DIERR_OLDDIRECTINPUTVERSION"; - case DIERR_OUTOFMEMORY: return "DIERR_OUTOFMEMORY"; - case DIERR_UNSUPPORTED: return "DIERR_UNSUPPORTED"; - case E_PENDING: return "E_PENDING"; - default: break; - } - return "Unknown error"; + switch (code) { + case DI_OK: return "DI_OK"; + case DI_BUFFEROVERFLOW: return "DI_BUFFEROVERFLOW"; + case DI_DOWNLOADSKIPPED: return "DI_DOWNLOADSKIPPED"; + case DI_EFFECTRESTARTED: return "DI_EFFECTRESTARTED"; + case DI_POLLEDDEVICE: return "DI_POLLEDDEVICE"; + case DI_TRUNCATED: return "DI_TRUNCATED"; + case DI_TRUNCATEDANDRESTARTED: return "DI_TRUNCATEDANDRESTARTED"; + case DIERR_ACQUIRED: return "DIERR_ACQUIRED"; + case DIERR_ALREADYINITIALIZED: return "DIERR_ALREADYINITIALIZED"; + case DIERR_BADDRIVERVER: return "DIERR_BADDRIVERVER"; + case DIERR_BETADIRECTINPUTVERSION: return "DIERR_BETADIRECTINPUTVERSION"; + case DIERR_DEVICEFULL: return "DIERR_DEVICEFULL"; + case DIERR_DEVICENOTREG: return "DIERR_DEVICENOTREG"; + case DIERR_EFFECTPLAYING: return "DIERR_EFFECTPLAYING"; + case DIERR_HASEFFECTS: return "DIERR_HASEFFECTS"; + case DIERR_GENERIC: return "DIERR_GENERIC"; + case DIERR_HANDLEEXISTS: return "DIERR_HANDLEEXISTS"; + case DIERR_INCOMPLETEEFFECT: return "DIERR_INCOMPLETEEFFECT"; + case DIERR_INPUTLOST: return "DIERR_INPUTLOST"; + case DIERR_INVALIDPARAM: return "DIERR_INVALIDPARAM"; + case DIERR_MOREDATA: return "DIERR_MOREDATA"; + case DIERR_NOAGGREGATION: return "DIERR_NOAGGREGATION"; + case DIERR_NOINTERFACE: return "DIERR_NOINTERFACE"; + case DIERR_NOTACQUIRED: return "DIERR_NOTACQUIRED"; + case DIERR_NOTBUFFERED: return "DIERR_NOTBUFFERED"; + case DIERR_NOTDOWNLOADED: return "DIERR_NOTDOWNLOADED"; + case DIERR_NOTEXCLUSIVEACQUIRED: return "DIERR_NOTEXCLUSIVEACQUIRED"; + case DIERR_NOTFOUND: return "DIERR_NOTFOUND"; + case DIERR_NOTINITIALIZED: return "DIERR_NOTINITIALIZED"; + case DIERR_OLDDIRECTINPUTVERSION: return "DIERR_OLDDIRECTINPUTVERSION"; + case DIERR_OUTOFMEMORY: return "DIERR_OUTOFMEMORY"; + case DIERR_UNSUPPORTED: return "DIERR_UNSUPPORTED"; + case E_PENDING: return "E_PENDING"; + default: break; + } + return "Unknown error"; } @@ -1810,12 +1810,12 @@ static void (*usertimercallback)(void) = NULL; // void (*installusertimercallback(void (*callback)(void)))(void) { - void (*oldtimercallback)(void); + void (*oldtimercallback)(void); - oldtimercallback = usertimercallback; - usertimercallback = callback; + oldtimercallback = usertimercallback; + usertimercallback = callback; - return oldtimercallback; + return oldtimercallback; } @@ -1824,27 +1824,27 @@ void (*installusertimercallback(void (*callback)(void)))(void) // int inittimer(int tickspersecond) { - int64 t; - - if (timerfreq) return 0; // already installed + int64 t; - initprintf("Initialising timer\n"); + if (timerfreq) return 0; // already installed - // OpenWatcom seems to want us to query the value into a local variable - // instead of the global 'timerfreq' or else it gets pissed with an - // access violation - if (!QueryPerformanceFrequency((LARGE_INTEGER*)&t)) { - ShowErrorBox("Failed fetching timer frequency"); - return -1; - } - timerfreq = t; - timerticspersec = tickspersecond; - QueryPerformanceCounter((LARGE_INTEGER*)&t); - timerlastsample = (long)(t*timerticspersec / timerfreq); + initprintf("Initialising timer\n"); - usertimercallback = NULL; + // OpenWatcom seems to want us to query the value into a local variable + // instead of the global 'timerfreq' or else it gets pissed with an + // access violation + if (!QueryPerformanceFrequency((LARGE_INTEGER*)&t)) { + ShowErrorBox("Failed fetching timer frequency"); + return -1; + } + timerfreq = t; + timerticspersec = tickspersecond; + QueryPerformanceCounter((LARGE_INTEGER*)&t); + timerlastsample = (long)(t*timerticspersec / timerfreq); - return 0; + usertimercallback = NULL; + + return 0; } // @@ -1852,10 +1852,10 @@ int inittimer(int tickspersecond) // void uninittimer(void) { - if (!timerfreq) return; + if (!timerfreq) return; - timerfreq=0; - timerticspersec = 0; + timerfreq=0; + timerticspersec = 0; } // @@ -1863,19 +1863,19 @@ void uninittimer(void) // void sampletimer(void) { - int64 i; - long n; - - if (!timerfreq) return; + int64 i; + long n; - QueryPerformanceCounter((LARGE_INTEGER*)&i); - n = (long)(i*timerticspersec / timerfreq) - timerlastsample; - if (n>0) { - totalclock += n; - timerlastsample += n; - } + if (!timerfreq) return; - if (usertimercallback) for (; n>0; n--) usertimercallback(); + QueryPerformanceCounter((LARGE_INTEGER*)&i); + n = (long)(i*timerticspersec / timerfreq) - timerlastsample; + if (n>0) { + totalclock += n; + timerlastsample += n; + } + + if (usertimercallback) for (; n>0; n--) usertimercallback(); } @@ -1884,10 +1884,10 @@ void sampletimer(void) // unsigned long getticks(void) { - int64 i; - if (timerfreq == 0) return 0; - QueryPerformanceCounter((LARGE_INTEGER*)&i); - return (unsigned long)(i*longlong(1000)/timerfreq); + int64 i; + if (timerfreq == 0) return 0; + QueryPerformanceCounter((LARGE_INTEGER*)&i); + return (unsigned long)(i*longlong(1000)/timerfreq); } @@ -1896,7 +1896,7 @@ unsigned long getticks(void) // int gettimerfreq(void) { - return timerticspersec; + return timerticspersec; } @@ -1925,32 +1925,32 @@ static VOID *lpPixels = NULL; #define NUM_SYS_COLOURS 25 static int syscolouridx[NUM_SYS_COLOURS] = { - COLOR_SCROLLBAR, // 1 - COLOR_BACKGROUND, - COLOR_ACTIVECAPTION, - COLOR_INACTIVECAPTION, - COLOR_MENU, - COLOR_WINDOW, - COLOR_WINDOWFRAME, - COLOR_MENUTEXT, - COLOR_WINDOWTEXT, - COLOR_CAPTIONTEXT, // 10 - COLOR_ACTIVEBORDER, - COLOR_INACTIVEBORDER, - COLOR_APPWORKSPACE, - COLOR_HIGHLIGHT, - COLOR_HIGHLIGHTTEXT, - COLOR_BTNFACE, - COLOR_BTNSHADOW, - COLOR_GRAYTEXT, - COLOR_BTNTEXT, - COLOR_INACTIVECAPTIONTEXT, // 20 - COLOR_BTNHIGHLIGHT, - COLOR_3DDKSHADOW, - COLOR_3DLIGHT, - COLOR_INFOTEXT, - COLOR_INFOBK // 25 -}; + COLOR_SCROLLBAR, // 1 + COLOR_BACKGROUND, + COLOR_ACTIVECAPTION, + COLOR_INACTIVECAPTION, + COLOR_MENU, + COLOR_WINDOW, + COLOR_WINDOWFRAME, + COLOR_MENUTEXT, + COLOR_WINDOWTEXT, + COLOR_CAPTIONTEXT, // 10 + COLOR_ACTIVEBORDER, + COLOR_INACTIVEBORDER, + COLOR_APPWORKSPACE, + COLOR_HIGHLIGHT, + COLOR_HIGHLIGHTTEXT, + COLOR_BTNFACE, + COLOR_BTNSHADOW, + COLOR_GRAYTEXT, + COLOR_BTNTEXT, + COLOR_INACTIVECAPTIONTEXT, // 20 + COLOR_BTNHIGHLIGHT, + COLOR_3DDKSHADOW, + COLOR_3DLIGHT, + COLOR_INFOTEXT, + COLOR_INFOBK // 25 + }; static DWORD syscolours[NUM_SYS_COLOURS]; static char system_colours_saved = 0, bw_colours_set = 0; @@ -1962,52 +1962,52 @@ static int getgammaramp(WORD gt[3][256]); // int checkvideomode(int *x, int *y, int c, int fs) { - int i, nearest=-1, dx, dy, odx=9999, ody=9999; + int i, nearest=-1, dx, dy, odx=9999, ody=9999; - getvalidmodes(); + getvalidmodes(); - // fix up the passed resolution values to be multiples of 8 - // and at least 320x200 or at most MAXXDIMxMAXYDIM - if (*x < 320) *x = 320; - if (*y < 200) *y = 200; - if (*x > MAXXDIM) *x = MAXXDIM; - if (*y > MAXYDIM) *y = MAXYDIM; - *x &= 0xfffffff8l; + // fix up the passed resolution values to be multiples of 8 + // and at least 320x200 or at most MAXXDIMxMAXYDIM + if (*x < 320) *x = 320; + if (*y < 200) *y = 200; + if (*x > MAXXDIM) *x = MAXXDIM; + if (*y > MAXYDIM) *y = MAXYDIM; + *x &= 0xfffffff8l; + + for (i=0; i= 0) gammabrightness = 1; - if (gammabrightness && setgamma(f,f,f) < 0) gammabrightness = 0; - } + if (CreateAppWindow(modenum, apptitle)) return -1; - for (i=0;i8); + if (!gammabrightness) { + float f = 1.0 + ((float)curbrightness / 10.0); + if (getgammaramp(sysgamma) >= 0) gammabrightness = 1; + if (gammabrightness && setgamma(f,f,f) < 0) gammabrightness = 0; + } - return 0; + for (i=0;i8); + + return 0; } @@ -2080,123 +2080,123 @@ int setvideomode(int x, int y, int c, int fs) #if defined(USE_OPENGL) && defined(POLYMOST) static void cdsenummodes(void) { - DEVMODE dm; - int i = 0, j = 0; + DEVMODE dm; + int i = 0, j = 0; - struct { unsigned x,y,bpp,freq; } modes[MAXVALIDMODES]; - int nmodes=0; - unsigned maxx = MAXXDIM, maxy = MAXYDIM; - + struct { unsigned x,y,bpp,freq; } modes[MAXVALIDMODES]; + int nmodes=0; + unsigned maxx = MAXXDIM, maxy = MAXYDIM; - ZeroMemory(&dm,sizeof(DEVMODE)); - dm.dmSize = sizeof(DEVMODE); - while (EnumDisplaySettings(NULL, j, &dm)) { - if (dm.dmBitsPerPel > 8) { - for (i=0;i modes[i].freq && maxrefreshfreq > 0) || - (dm.dmDisplayFrequency > modes[i].freq && maxrefreshfreq == 0)) { - if (i==nmodes) nmodes++; - modes[i].x = dm.dmPelsWidth; - modes[i].y = dm.dmPelsHeight; - modes[i].bpp = dm.dmBitsPerPel; - modes[i].freq = dm.dmDisplayFrequency; - } - } - - j++; - ZeroMemory(&dm,sizeof(DEVMODE)); - dm.dmSize = sizeof(DEVMODE); - } + ZeroMemory(&dm,sizeof(DEVMODE)); + dm.dmSize = sizeof(DEVMODE); + while (EnumDisplaySettings(NULL, j, &dm)) { + if (dm.dmBitsPerPel > 8) { + for (i=0;i modes[i].freq && maxrefreshfreq > 0) || + (dm.dmDisplayFrequency > modes[i].freq && maxrefreshfreq == 0)) { + if (i==nmodes) nmodes++; - for (i=0;iddpfPixelFormat.dwRGBBitCount == 8) { - CHECK(ddsd->dwWidth, ddsd->dwHeight) - ADDMODE(ddsd->dwWidth, ddsd->dwHeight, ddsd->ddpfPixelFormat.dwRGBBitCount, 1,-1); - } - - return(DDENUMRET_OK); + unsigned maxx = MAXXDIM, maxy = MAXYDIM; + + if (ddsd->ddpfPixelFormat.dwRGBBitCount == 8) { + CHECK(ddsd->dwWidth, ddsd->dwHeight) + ADDMODE(ddsd->dwWidth, ddsd->dwHeight, ddsd->ddpfPixelFormat.dwRGBBitCount, 1,-1); + } + + return(DDENUMRET_OK); } static int sortmodes(const struct validmode_t *a, const struct validmode_t *b) { - int x; + int x; - if ((x = a->fs - b->fs) != 0) return x; - if ((x = a->bpp - b->bpp) != 0) return x; - if ((x = a->xdim - b->xdim) != 0) return x; - if ((x = a->ydim - b->ydim) != 0) return x; + if ((x = a->fs - b->fs) != 0) return x; + if ((x = a->bpp - b->bpp) != 0) return x; + if ((x = a->xdim - b->xdim) != 0) return x; + if ((x = a->ydim - b->ydim) != 0) return x; - return 0; + return 0; } void getvalidmodes(void) { - static int defaultres[][2] = { - {1280,1024},{1280,960},{1152,864},{1024,768},{800,600},{640,480}, - {640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0} - }; - int cdepths[2] = { 8, 0 }; - int i, j, maxx=0, maxy=0; - HRESULT result; + static int defaultres[][2] = { + {1280,1024},{1280,960},{1152,864},{1024,768},{800,600},{640,480}, + {640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0} + }; + int cdepths[2] = { 8, 0 }; + int i, j, maxx=0, maxy=0; + HRESULT result; #if defined(USE_OPENGL) && defined(POLYMOST) - if (desktopbpp > 8) cdepths[1] = desktopbpp; + if (desktopbpp > 8) cdepths[1] = desktopbpp; #endif - if (modeschecked) return; + if (modeschecked) return; - validmodecnt=0; - initprintf("Detecting video modes:\n"); + validmodecnt=0; + initprintf("Detecting video modes:\n"); - if (bDDrawInited) { - // if DirectDraw initialisation didn't fail enumerate fullscreen modes + if (bDDrawInited) { + // if DirectDraw initialisation didn't fail enumerate fullscreen modes - result = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, getvalidmodes_enum); - if (result != DD_OK) { - initprintf("Unable to enumerate fullscreen modes. Using default list.\n"); - for (j=0; j < 2; j++) { - if (cdepths[j] == 0) continue; - for (i=0; defaultres[i][0]; i++) - ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1,-1) - } - } - } + result = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, getvalidmodes_enum); + if (result != DD_OK) { + initprintf("Unable to enumerate fullscreen modes. Using default list.\n"); + for (j=0; j < 2; j++) { + if (cdepths[j] == 0) continue; + for (i=0; defaultres[i][0]; i++) + ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1,-1) + } + } + } #if defined(USE_OPENGL) && defined(POLYMOST) - cdsenummodes(); + cdsenummodes(); #endif - // windowed modes cant be bigger than the current desktop resolution - maxx = desktopxdim-1; - maxy = desktopydim-1; + // windowed modes cant be bigger than the current desktop resolution + maxx = desktopxdim-1; + maxy = desktopydim-1; - // add windowed modes next - for (j=0; j < 2; j++) { - if (cdepths[j] == 0) continue; - for (i=0; defaultres[i][0]; i++) - CHECK(defaultres[i][0],defaultres[i][1]) - ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],0,-1) - } + // add windowed modes next + for (j=0; j < 2; j++) { + if (cdepths[j] == 0) continue; + for (i=0; defaultres[i][0]; i++) + CHECK(defaultres[i][0],defaultres[i][1]) + ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],0,-1) + } - qsort((void*)validmode, validmodecnt, sizeof(struct validmode_t), (int(*)(const void*,const void*))sortmodes); + qsort((void*)validmode, validmodecnt, sizeof(struct validmode_t), (int(*)(const void*,const void*))sortmodes); - modeschecked=1; + modeschecked=1; } #undef CHECK @@ -2208,8 +2208,8 @@ void getvalidmodes(void) // void resetvideomode(void) { - videomodereset = 1; - modeschecked = 0; + videomodereset = 1; + modeschecked = 0; } @@ -2218,42 +2218,42 @@ void resetvideomode(void) // void begindrawing(void) { - long i,j; + long i,j; - if (bpp > 8) { - if (offscreenrendering) return; - frameplace = 0; - bytesperline = 0; - imageSize = 0; - modechange = 0; - return; - } + if (bpp > 8) { + if (offscreenrendering) return; + frameplace = 0; + bytesperline = 0; + imageSize = 0; + modechange = 0; + return; + } - if (lockcount++ > 0) - return; // already locked + if (lockcount++ > 0) + return; // already locked - if (offscreenrendering) return; - - if (!fullscreen) { - frameplace = (long)lpPixels; - } else { - frameplace = (long)lpOffscreen; - } + if (offscreenrendering) return; - if (!modechange) return; + if (!fullscreen) { + frameplace = (long)lpPixels; + } else { + frameplace = (long)lpOffscreen; + } - if (!fullscreen) { - bytesperline = xres|4; - } else { - bytesperline = xres|1; - } - - imageSize = bytesperline*yres; - setvlinebpl(bytesperline); - - j = 0; - for(i=0;i<=ydim;i++) ylookup[i] = j, j += bytesperline; - modechange=0; + if (!modechange) return; + + if (!fullscreen) { + bytesperline = xres|4; + } else { + bytesperline = xres|1; + } + + imageSize = bytesperline*yres; + setvlinebpl(bytesperline); + + j = 0; + for(i=0;i<=ydim;i++) ylookup[i] = j, j += bytesperline; + modechange=0; } @@ -2262,15 +2262,15 @@ void begindrawing(void) // void enddrawing(void) { - if (bpp > 8) { - if (!offscreenrendering) frameplace = 0; - return; - } - - if (!frameplace) return; - if (lockcount > 1) { lockcount--; return; } - if (!offscreenrendering) frameplace = 0; - lockcount = 0; + if (bpp > 8) { + if (!offscreenrendering) frameplace = 0; + return; + } + + if (!frameplace) return; +if (lockcount > 1) { lockcount--; return; } + if (!offscreenrendering) frameplace = 0; + lockcount = 0; } @@ -2279,112 +2279,112 @@ void enddrawing(void) // void showframe(int w) { - HRESULT result; - DDSURFACEDESC ddsd; - char *p,*q; - int i,j; + HRESULT result; + DDSURFACEDESC ddsd; + char *p,*q; + int i,j; #if defined(USE_OPENGL) && defined(POLYMOST) - if (bpp > 8) { - if (palfadedelta) { - bglMatrixMode(GL_PROJECTION); - bglPushMatrix(); - bglLoadIdentity(); - bglMatrixMode(GL_MODELVIEW); - bglPushMatrix(); - bglLoadIdentity(); + if (bpp > 8) { + if (palfadedelta) { + bglMatrixMode(GL_PROJECTION); + bglPushMatrix(); + bglLoadIdentity(); + bglMatrixMode(GL_MODELVIEW); + bglPushMatrix(); + bglLoadIdentity(); - bglDisable(GL_DEPTH_TEST); - bglDisable(GL_ALPHA_TEST); - bglDisable(GL_TEXTURE_2D); + bglDisable(GL_DEPTH_TEST); + bglDisable(GL_ALPHA_TEST); + bglDisable(GL_TEXTURE_2D); - bglEnable(GL_BLEND); - bglColor4ub(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); + bglEnable(GL_BLEND); + bglColor4ub(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); - bglBegin(GL_QUADS); - bglVertex2i(-1, -1); - bglVertex2i(1, -1); - bglVertex2i(1, 1); - bglVertex2i(-1, 1); - bglEnd(); - - bglMatrixMode(GL_MODELVIEW); - bglPopMatrix(); - bglMatrixMode(GL_PROJECTION); - bglPopMatrix(); - } + bglBegin(GL_QUADS); + bglVertex2i(-1, -1); + bglVertex2i(1, -1); + bglVertex2i(1, 1); + bglVertex2i(-1, 1); + bglEnd(); - bwglSwapBuffers(hDC); - return; - } + bglMatrixMode(GL_MODELVIEW); + bglPopMatrix(); + bglMatrixMode(GL_PROJECTION); + bglPopMatrix(); + } + + bwglSwapBuffers(hDC); + return; + } #endif - w = 1; // wait regardless. ken thinks it's better to do so. + w = 1; // wait regardless. ken thinks it's better to do so. - if (offscreenrendering) return; + if (offscreenrendering) return; - if (lockcount) { - initprintf("Frame still locked %ld times when showframe() called.\n", lockcount); - while (lockcount) enddrawing(); - } - - if (!fullscreen) { - BitBlt(hDC, 0, 0, xres, yres, hDCSection, 0, 0, SRCCOPY); - } else { - if (!w) { - if ((result = IDirectDrawSurface_GetBltStatus(lpDDSBack, DDGBS_CANBLT)) == DDERR_WASSTILLDRAWING) - return; + if (lockcount) { + initprintf("Frame still locked %ld times when showframe() called.\n", lockcount); + while (lockcount) enddrawing(); + } - if ((result = IDirectDrawSurface_GetFlipStatus(lpDDSPrimary, DDGFS_CANFLIP)) == DDERR_WASSTILLDRAWING) - return; - } + if (!fullscreen) { + BitBlt(hDC, 0, 0, xres, yres, hDCSection, 0, 0, SRCCOPY); + } else { + if (!w) { + if ((result = IDirectDrawSurface_GetBltStatus(lpDDSBack, DDGBS_CANBLT)) == DDERR_WASSTILLDRAWING) + return; - // lock the backbuffer surface - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); + if ((result = IDirectDrawSurface_GetFlipStatus(lpDDSPrimary, DDGFS_CANFLIP)) == DDERR_WASSTILLDRAWING) + return; + } - result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); - if (result == DDERR_SURFACELOST) { - if (!appactive) - return; // not in a position to restore display anyway + // lock the backbuffer surface + memset(&ddsd, 0, sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); - IDirectDrawSurface_Restore(lpDDSPrimary); - result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); - } - if (result != DD_OK) { - if (result != DDERR_WASSTILLDRAWING) - initprintf("Failed locking back-buffer surface: %s\n", GetDDrawError(result)); - return; - } + result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); + if (result == DDERR_SURFACELOST) { + if (!appactive) + return; // not in a position to restore display anyway - // copy each scanline - p = (char *)ddsd.lpSurface; - q = (char *)lpOffscreen; - j = xres >> 2; + IDirectDrawSurface_Restore(lpDDSPrimary); + result = IDirectDrawSurface_Lock(lpDDSBack, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); + } + if (result != DD_OK) { + if (result != DDERR_WASSTILLDRAWING) + initprintf("Failed locking back-buffer surface: %s\n", GetDDrawError(result)); + return; + } - for (i=0; i> 2; - // unlock the backbuffer surface - result = IDirectDrawSurface_Unlock(lpDDSBack, NULL); - if (result != DD_OK) { - initprintf("Failed unlocking back-buffer surface: %s\n", GetDDrawError(result)); - return; - } + for (i=0; i0; i++, n--) { - /* - lpal.palPalEntry[i].peBlue = dapal[0] << 2; - lpal.palPalEntry[i].peGreen = dapal[1] << 2; - lpal.palPalEntry[i].peRed = dapal[2] << 2; - */ - curpalettefaded[i].f = lpal.palPalEntry[i].peFlags = PC_RESERVED | PC_NOCOLLAPSE; - //dapal += 4; - } + copybuf(curpalettefaded, lpal.palPalEntry, 256); + + for (i=start, n=num; n>0; i++, n--) { + /* + lpal.palPalEntry[i].peBlue = dapal[0] << 2; + lpal.palPalEntry[i].peGreen = dapal[1] << 2; + lpal.palPalEntry[i].peRed = dapal[2] << 2; + */ + curpalettefaded[i].f = lpal.palPalEntry[i].peFlags = PC_RESERVED | PC_NOCOLLAPSE; + //dapal += 4; + } - if (bpp > 8) return 0; // no palette in opengl + if (bpp > 8) return 0; // no palette in opengl - if (!fullscreen) { - if (num > 0) { - rgb = (RGBQUAD *)Bmalloc(sizeof(RGBQUAD)*num); - for (i=start, n=0; n 0) { + rgb = (RGBQUAD *)Bmalloc(sizeof(RGBQUAD)*num); + for (i=start, n=0; n 8) return 0; // only if an 8bit desktop do we do what follows + if (desktopbpp > 8) return 0; // only if an 8bit desktop do we do what follows - // set 0 and 255 to black and white - lpal.palVersion = 0x300; - lpal.palNumEntries = 256; - lpal.palPalEntry[0].peBlue = 0; - lpal.palPalEntry[0].peGreen = 0; - lpal.palPalEntry[0].peRed = 0; - lpal.palPalEntry[0].peFlags = 0; - lpal.palPalEntry[255].peBlue = 255; - lpal.palPalEntry[255].peGreen = 255; - lpal.palPalEntry[255].peRed = 255; - lpal.palPalEntry[255].peFlags = 0; + // set 0 and 255 to black and white + lpal.palVersion = 0x300; + lpal.palNumEntries = 256; + lpal.palPalEntry[0].peBlue = 0; + lpal.palPalEntry[0].peGreen = 0; + lpal.palPalEntry[0].peRed = 0; + lpal.palPalEntry[0].peFlags = 0; + lpal.palPalEntry[255].peBlue = 255; + lpal.palPalEntry[255].peGreen = 255; + lpal.palPalEntry[255].peRed = 255; + lpal.palPalEntry[255].peFlags = 0; - if (SetSystemPaletteUse(hDC, SYSPAL_NOSTATIC) == SYSPAL_ERROR) { - initprintf("Problem setting system palette use.\n"); - return -1; - } + if (SetSystemPaletteUse(hDC, SYSPAL_NOSTATIC) == SYSPAL_ERROR) { + initprintf("Problem setting system palette use.\n"); + return -1; + } - if (hPalette) { - if (num == 0) { start = 0; num = 256; } // refreshing the palette only - SetPaletteEntries(hPalette, start, num, lpal.palPalEntry+start); - } else { - hPalette = CreatePalette((LOGPALETTE *)lpal.palPalEntry); - if (!hPalette) { - initprintf("Problem creating palette.\n"); - return -1; - } - } + if (hPalette) { + if (num == 0) { start = 0; num = 256; } // refreshing the palette only + SetPaletteEntries(hPalette, start, num, lpal.palPalEntry+start); + } else { + hPalette = CreatePalette((LOGPALETTE *)lpal.palPalEntry); + if (!hPalette) { + initprintf("Problem creating palette.\n"); + return -1; + } + } - if (SelectPalette(hDC, hPalette, FALSE) == NULL) { - initprintf("Problem selecting palette.\n"); - return -1; - } + if (SelectPalette(hDC, hPalette, FALSE) == NULL) { + initprintf("Problem selecting palette.\n"); + return -1; + } - if (RealizePalette(hDC) == GDI_ERROR) { - initprintf("Failure realizing palette.\n"); - return -1; - } + if (RealizePalette(hDC) == GDI_ERROR) { + initprintf("Failure realizing palette.\n"); + return -1; + } - SetBWSystemColours(); - - } else { - if (!lpDDPalette) return -1; - result = IDirectDrawPalette_SetEntries(lpDDPalette, 0, start, num, (PALETTEENTRY*)&lpal.palPalEntry[start]); - if (result != DD_OK) { - initprintf("Palette set failed: %s\n", GetDDrawError(result)); - return -1; - } - } + SetBWSystemColours(); - return 0; + } else { + if (!lpDDPalette) return -1; + result = IDirectDrawPalette_SetEntries(lpDDPalette, 0, start, num, (PALETTEENTRY*)&lpal.palPalEntry[start]); + if (result != DD_OK) { + initprintf("Palette set failed: %s\n", GetDDrawError(result)); + return -1; + } + } + + return 0; } // @@ -2513,87 +2513,87 @@ int getpalette(int start, int num, char *dapal) // static int setgammaramp(WORD gt[3][256]) { - if (!fullscreen || bpp > 8) { - // GL and windowed mode use DIB method - int i; - HDC hDC = GetDC(hWindow); - i = SetDeviceGammaRamp(hDC, gt) ? 0 : -1; - ReleaseDC(hWindow, hDC); - return i; - } else { - // fullscreen uses DirectX - LPDIRECTDRAWGAMMACONTROL gam; - HRESULT hr; + if (!fullscreen || bpp > 8) { + // GL and windowed mode use DIB method + int i; + HDC hDC = GetDC(hWindow); + i = SetDeviceGammaRamp(hDC, gt) ? 0 : -1; + ReleaseDC(hWindow, hDC); + return i; + } else { + // fullscreen uses DirectX + LPDIRECTDRAWGAMMACONTROL gam; + HRESULT hr; - if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1; - - hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, &IID_IDirectDrawGammaControl, (LPVOID)&gam); - if (hr != DD_OK) { - ShowDDrawErrorBox("Error querying gamma control", hr); - return -1; - } + if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1; - hr = IDirectDrawGammaControl_SetGammaRamp(gam, 0, (LPDDGAMMARAMP)gt); - if (hr != DD_OK) { - IDirectDrawGammaControl_Release(gam); - ShowDDrawErrorBox("Error setting gamma ramp", hr); - return -1; - } + hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, &IID_IDirectDrawGammaControl, (LPVOID)&gam); + if (hr != DD_OK) { + ShowDDrawErrorBox("Error querying gamma control", hr); + return -1; + } - IDirectDrawGammaControl_Release(gam); - return 0; - } + hr = IDirectDrawGammaControl_SetGammaRamp(gam, 0, (LPDDGAMMARAMP)gt); + if (hr != DD_OK) { + IDirectDrawGammaControl_Release(gam); + ShowDDrawErrorBox("Error setting gamma ramp", hr); + return -1; + } + + IDirectDrawGammaControl_Release(gam); + return 0; + } } int setgamma(float ro, float go, float bo) { - int i; - WORD gt[3][256]; - - if (!hWindow) return -1; - - ro = 1.0 / ro; go = 1.0 / go; bo = 1.0 / bo; - for (i=0;i<256;i++) { - gt[0][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, ro) * 65535.0 + 0.5))); - gt[1][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5))); - gt[2][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5))); - } + int i; + WORD gt[3][256]; - return setgammaramp(gt); + if (!hWindow) return -1; + + ro = 1.0 / ro; go = 1.0 / go; bo = 1.0 / bo; + for (i=0;i<256;i++) { + gt[0][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, ro) * 65535.0 + 0.5))); + gt[1][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5))); + gt[2][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5))); + } + + return setgammaramp(gt); } static int getgammaramp(WORD gt[3][256]) { - if (!hWindow) return -1; - if (!fullscreen || bpp > 8) { - int i; - HDC hDC = GetDC(hWindow); - i = GetDeviceGammaRamp(hDC, gt) ? 0 : -1; - ReleaseDC(hWindow, hDC); - return i; - } else { - LPDIRECTDRAWGAMMACONTROL gam; - HRESULT hr; + if (!hWindow) return -1; + if (!fullscreen || bpp > 8) { + int i; + HDC hDC = GetDC(hWindow); + i = GetDeviceGammaRamp(hDC, gt) ? 0 : -1; + ReleaseDC(hWindow, hDC); + return i; + } else { + LPDIRECTDRAWGAMMACONTROL gam; + HRESULT hr; - if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1; + if (!(DDdwCaps2 & DDCAPS2_PRIMARYGAMMA)) return -1; - hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, &IID_IDirectDrawGammaControl, (LPVOID)&gam); - if (hr != DD_OK) { - ShowDDrawErrorBox("Error querying gamma control", hr); - return -1; - } + hr = IDirectDrawSurface_QueryInterface(lpDDSPrimary, &IID_IDirectDrawGammaControl, (LPVOID)&gam); + if (hr != DD_OK) { + ShowDDrawErrorBox("Error querying gamma control", hr); + return -1; + } - hr = IDirectDrawGammaControl_GetGammaRamp(gam, 0, (LPDDGAMMARAMP)gt); - if (hr != DD_OK) { - IDirectDrawGammaControl_Release(gam); - ShowDDrawErrorBox("Error getting gamma ramp", hr); - return -1; - } + hr = IDirectDrawGammaControl_GetGammaRamp(gam, 0, (LPDDGAMMARAMP)gt); + if (hr != DD_OK) { + IDirectDrawGammaControl_Release(gam); + ShowDDrawErrorBox("Error getting gamma ramp", hr); + return -1; + } - IDirectDrawGammaControl_Release(gam); + IDirectDrawGammaControl_Release(gam); - return 0; - } + return 0; + } } // @@ -2603,74 +2603,74 @@ static int getgammaramp(WORD gt[3][256]) // device enumerator static BOOL WINAPI InitDirectDraw_enum(GUID *lpGUID, LPSTR lpDesc, LPSTR lpName, LPVOID lpContext) { - initprintf(" * %s\n", lpDesc); - return 1; + initprintf(" * %s\n", lpDesc); + return 1; } static BOOL InitDirectDraw(void) { - HRESULT result; - HRESULT (WINAPI *aDirectDrawCreate)(GUID *, LPDIRECTDRAW *, IUnknown *); - HRESULT (WINAPI *aDirectDrawEnumerate)(LPDDENUMCALLBACK, LPVOID); - DDCAPS ddcaps; + HRESULT result; + HRESULT (WINAPI *aDirectDrawCreate)(GUID *, LPDIRECTDRAW *, IUnknown *); + HRESULT (WINAPI *aDirectDrawEnumerate)(LPDDENUMCALLBACK, LPVOID); + DDCAPS ddcaps; - if (bDDrawInited) return FALSE; + if (bDDrawInited) return FALSE; - initprintf("Initialising DirectDraw...\n"); + initprintf("Initialising DirectDraw...\n"); - // load up the DirectDraw DLL - if (!hDDrawDLL) { - initprintf(" - Loading DDRAW.DLL\n"); - hDDrawDLL = LoadLibrary("DDRAW.DLL"); - if (!hDDrawDLL) { - ShowErrorBox("Error loading DDRAW.DLL"); - return TRUE; - } - } + // load up the DirectDraw DLL + if (!hDDrawDLL) { + initprintf(" - Loading DDRAW.DLL\n"); + hDDrawDLL = LoadLibrary("DDRAW.DLL"); + if (!hDDrawDLL) { + ShowErrorBox("Error loading DDRAW.DLL"); + return TRUE; + } + } - // get the pointer to DirectDrawEnumerate - aDirectDrawEnumerate = (void *)GetProcAddress(hDDrawDLL, "DirectDrawEnumerateA"); - if (!aDirectDrawEnumerate) { - ShowErrorBox("Error fetching DirectDrawEnumerate()"); - UninitDirectDraw(); - return TRUE; - } + // get the pointer to DirectDrawEnumerate + aDirectDrawEnumerate = (void *)GetProcAddress(hDDrawDLL, "DirectDrawEnumerateA"); + if (!aDirectDrawEnumerate) { + ShowErrorBox("Error fetching DirectDrawEnumerate()"); + UninitDirectDraw(); + return TRUE; + } - // enumerate the devices to make us look fancy - initprintf(" - Enumerating display devices\n"); - aDirectDrawEnumerate(InitDirectDraw_enum, NULL); + // enumerate the devices to make us look fancy + initprintf(" - Enumerating display devices\n"); + aDirectDrawEnumerate(InitDirectDraw_enum, NULL); - // get the pointer to DirectDrawCreate - aDirectDrawCreate = (void *)GetProcAddress(hDDrawDLL, "DirectDrawCreate"); - if (!aDirectDrawCreate) { - ShowErrorBox("Error fetching DirectDrawCreate()"); - UninitDirectDraw(); - return TRUE; - } + // get the pointer to DirectDrawCreate + aDirectDrawCreate = (void *)GetProcAddress(hDDrawDLL, "DirectDrawCreate"); + if (!aDirectDrawCreate) { + ShowErrorBox("Error fetching DirectDrawCreate()"); + UninitDirectDraw(); + return TRUE; + } - // create a new DirectDraw object - initprintf(" - Creating DirectDraw object\n"); - result = aDirectDrawCreate(NULL, &lpDD, NULL); - if (result != DD_OK) { - ShowDDrawErrorBox("DirectDrawCreate() failed", result); - UninitDirectDraw(); - return TRUE; - } + // create a new DirectDraw object + initprintf(" - Creating DirectDraw object\n"); + result = aDirectDrawCreate(NULL, &lpDD, NULL); + if (result != DD_OK) { + ShowDDrawErrorBox("DirectDrawCreate() failed", result); + UninitDirectDraw(); + return TRUE; + } - // fetch capabilities - initprintf(" - Checking capabilities\n"); - ddcaps.dwSize = sizeof(DDCAPS); - result = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL); - if (result != DD_OK) { - initprintf(" Unable to get capabilities.\n"); - } else { - DDdwCaps = ddcaps.dwCaps; - DDdwCaps2 = ddcaps.dwCaps2; - } + // fetch capabilities + initprintf(" - Checking capabilities\n"); + ddcaps.dwSize = sizeof(DDCAPS); + result = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL); + if (result != DD_OK) { + initprintf(" Unable to get capabilities.\n"); + } else { + DDdwCaps = ddcaps.dwCaps; + DDdwCaps2 = ddcaps.dwCaps2; + } - bDDrawInited = TRUE; + bDDrawInited = TRUE; - return FALSE; + return FALSE; } @@ -2679,25 +2679,25 @@ static BOOL InitDirectDraw(void) // static void UninitDirectDraw(void) { - if (bDDrawInited) initprintf("Uninitialising DirectDraw...\n"); + if (bDDrawInited) initprintf("Uninitialising DirectDraw...\n"); - ReleaseDirectDrawSurfaces(); + ReleaseDirectDrawSurfaces(); - RestoreDirectDrawMode(); + RestoreDirectDrawMode(); - if (lpDD) { - initprintf(" - Releasing DirectDraw object\n"); - IDirectDraw_Release(lpDD); - lpDD = NULL; - } + if (lpDD) { + initprintf(" - Releasing DirectDraw object\n"); + IDirectDraw_Release(lpDD); + lpDD = NULL; + } - if (hDDrawDLL) { - initprintf(" - Unloading DDRAW.DLL\n"); - FreeLibrary(hDDrawDLL); - hDDrawDLL = NULL; - } + if (hDDrawDLL) { + initprintf(" - Unloading DDRAW.DLL\n"); + FreeLibrary(hDDrawDLL); + hDDrawDLL = NULL; + } - bDDrawInited = FALSE; + bDDrawInited = FALSE; } @@ -2706,30 +2706,30 @@ static void UninitDirectDraw(void) // static int RestoreDirectDrawMode(void) { - HRESULT result; + HRESULT result; - if (fullscreen == 0 || /*bpp > 8 ||*/ !bDDrawInited) return FALSE; - - if (modesetusing == 1) ChangeDisplaySettings(NULL,0); - else if (modesetusing == 0) { - // restore previous display mode and set to normal cooperative level - result = IDirectDraw_RestoreDisplayMode(lpDD); - if (result != DD_OK) { - ShowDDrawErrorBox("Error restoring display mode", result); - UninitDirectDraw(); - return TRUE; - } + if (fullscreen == 0 || /*bpp > 8 ||*/ !bDDrawInited) return FALSE; - result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_NORMAL); - if (result != DD_OK) { - ShowDDrawErrorBox("Error setting cooperative level", result); - UninitDirectDraw(); - return TRUE; - } - } - modesetusing = -1; + if (modesetusing == 1) ChangeDisplaySettings(NULL,0); + else if (modesetusing == 0) { + // restore previous display mode and set to normal cooperative level + result = IDirectDraw_RestoreDisplayMode(lpDD); + if (result != DD_OK) { + ShowDDrawErrorBox("Error restoring display mode", result); + UninitDirectDraw(); + return TRUE; + } - return FALSE; + result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_NORMAL); + if (result != DD_OK) { + ShowDDrawErrorBox("Error setting cooperative level", result); + UninitDirectDraw(); + return TRUE; + } + } + modesetusing = -1; + + return FALSE; } @@ -2738,29 +2738,29 @@ static int RestoreDirectDrawMode(void) // static void ReleaseDirectDrawSurfaces(void) { - if (lpDDPalette) { - initprintf(" - Releasing palette\n"); - IDirectDrawPalette_Release(lpDDPalette); - lpDDPalette = NULL; - } + if (lpDDPalette) { + initprintf(" - Releasing palette\n"); + IDirectDrawPalette_Release(lpDDPalette); + lpDDPalette = NULL; + } - if (lpDDSBack) { - initprintf(" - Releasing back-buffer surface\n"); - IDirectDrawSurface_Release(lpDDSBack); - lpDDSBack = NULL; - } - - if (lpDDSPrimary) { - initprintf(" - Releasing primary surface\n"); - IDirectDrawSurface_Release(lpDDSPrimary); - lpDDSPrimary = NULL; - } + if (lpDDSBack) { + initprintf(" - Releasing back-buffer surface\n"); + IDirectDrawSurface_Release(lpDDSBack); + lpDDSBack = NULL; + } - if (lpOffscreen) { - initprintf(" - Freeing offscreen buffer\n"); - free(lpOffscreen); - lpOffscreen = NULL; - } + if (lpDDSPrimary) { + initprintf(" - Releasing primary surface\n"); + IDirectDrawSurface_Release(lpDDSPrimary); + lpDDSPrimary = NULL; + } + + if (lpOffscreen) { + initprintf(" - Freeing offscreen buffer\n"); + free(lpOffscreen); + lpOffscreen = NULL; + } } @@ -2769,61 +2769,61 @@ static void ReleaseDirectDrawSurfaces(void) // static int SetupDirectDraw(int width, int height) { - HRESULT result; - DDSURFACEDESC ddsd; + HRESULT result; + DDSURFACEDESC ddsd; - // now create the DirectDraw surfaces - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; - ddsd.dwBackBufferCount = 2; // triple-buffer + // now create the DirectDraw surfaces + ZeroMemory(&ddsd, sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; + ddsd.dwBackBufferCount = 2; // triple-buffer - initprintf(" - Creating primary surface\n"); - result = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL); - if (result != DD_OK) { - ShowDDrawErrorBox("Failure creating primary surface", result); - UninitDirectDraw(); - return TRUE; - } + initprintf(" - Creating primary surface\n"); + result = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL); + if (result != DD_OK) { + ShowDDrawErrorBox("Failure creating primary surface", result); + UninitDirectDraw(); + return TRUE; + } - ZeroMemory(&ddsd.ddsCaps, sizeof(ddsd.ddsCaps)); - ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; - numpages = 1; // KJS 20031225 + ZeroMemory(&ddsd.ddsCaps, sizeof(ddsd.ddsCaps)); + ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; + numpages = 1; // KJS 20031225 - initprintf(" - Getting back buffer\n"); - result = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddsd.ddsCaps, &lpDDSBack); - if (result != DD_OK) { - ShowDDrawErrorBox("Failure fetching back-buffer surface", result); - UninitDirectDraw(); - return TRUE; - } + initprintf(" - Getting back buffer\n"); + result = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddsd.ddsCaps, &lpDDSBack); + if (result != DD_OK) { + ShowDDrawErrorBox("Failure fetching back-buffer surface", result); + UninitDirectDraw(); + return TRUE; + } - initprintf(" - Allocating offscreen buffer\n"); - lpOffscreen = (char *)malloc((width|1)*height); - if (!lpOffscreen) { - ShowErrorBox("Failure allocating offscreen buffer"); - UninitDirectDraw(); - return TRUE; - } + initprintf(" - Allocating offscreen buffer\n"); + lpOffscreen = (char *)malloc((width|1)*height); + if (!lpOffscreen) { + ShowErrorBox("Failure allocating offscreen buffer"); + UninitDirectDraw(); + return TRUE; + } - // attach a palette to the primary surface - initprintf(" - Creating palette\n"); - result = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256, (PALETTEENTRY*)curpalette, &lpDDPalette, NULL); - if (result != DD_OK) { - ShowDDrawErrorBox("Failure creating palette", result); - UninitDirectDraw(); - return TRUE; - } + // attach a palette to the primary surface + initprintf(" - Creating palette\n"); + result = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256, (PALETTEENTRY*)curpalette, &lpDDPalette, NULL); + if (result != DD_OK) { + ShowDDrawErrorBox("Failure creating palette", result); + UninitDirectDraw(); + return TRUE; + } - result = IDirectDrawSurface_SetPalette(lpDDSPrimary, lpDDPalette); - if (result != DD_OK) { - ShowDDrawErrorBox("Failure setting palette", result); - UninitDirectDraw(); - return TRUE; - } + result = IDirectDrawSurface_SetPalette(lpDDSPrimary, lpDDPalette); + if (result != DD_OK) { + ShowDDrawErrorBox("Failure setting palette", result); + UninitDirectDraw(); + return TRUE; + } - return FALSE; + return FALSE; } @@ -2832,28 +2832,28 @@ static int SetupDirectDraw(int width, int height) // static void UninitDIB(void) { - if (desktopbpp <= 8) - RestoreSystemColours(); + if (desktopbpp <= 8) + RestoreSystemColours(); - if (hPalette) { - DeleteObject(hPalette); - hPalette = NULL; - } + if (hPalette) { + DeleteObject(hPalette); + hPalette = NULL; + } - if (hDCSection) { - DeleteDC(hDCSection); - hDCSection = NULL; - } + if (hDCSection) { + DeleteDC(hDCSection); + hDCSection = NULL; + } - if (hDIBSection) { - DeleteObject(hDIBSection); - hDIBSection = NULL; - } + if (hDIBSection) { + DeleteObject(hDIBSection); + hDIBSection = NULL; + } - if (hDC) { - ReleaseDC(hWindow, hDC); - hDC = NULL; - } + if (hDC) { + ReleaseDC(hWindow, hDC); + hDC = NULL; + } } @@ -2862,81 +2862,81 @@ static void UninitDIB(void) // static int SetupDIB(int width, int height) { - struct binfo { - BITMAPINFOHEADER header; - RGBQUAD colours[256]; - } dibsect; - int i; + struct binfo { + BITMAPINFOHEADER header; + RGBQUAD colours[256]; + } dibsect; + int i; - if (!hDC) { - hDC = GetDC(hWindow); - if (!hDC) { - ShowErrorBox("Error getting device context"); - return TRUE; - } - } + if (!hDC) { + hDC = GetDC(hWindow); + if (!hDC) { + ShowErrorBox("Error getting device context"); + return TRUE; + } + } - if (hDCSection) { - DeleteDC(hDCSection); - hDCSection = NULL; - } + if (hDCSection) { + DeleteDC(hDCSection); + hDCSection = NULL; + } - // destroy the previous DIB section if it existed - if (hDIBSection) { - DeleteObject(hDIBSection); - hDIBSection = NULL; - } + // destroy the previous DIB section if it existed + if (hDIBSection) { + DeleteObject(hDIBSection); + hDIBSection = NULL; + } - // create the new DIB section - memset(&dibsect, 0, sizeof(dibsect)); - numpages = 1; // KJS 20031225 - dibsect.header.biSize = sizeof(dibsect.header); - dibsect.header.biWidth = width|1; // Ken did this - dibsect.header.biHeight = -height; - dibsect.header.biPlanes = 1; - dibsect.header.biBitCount = 8; - dibsect.header.biCompression = BI_RGB; - dibsect.header.biClrUsed = 256; - dibsect.header.biClrImportant = 256; - for (i=0; i<256; i++) { - dibsect.colours[i].rgbBlue = curpalette[i].b; - dibsect.colours[i].rgbGreen = curpalette[i].g; - dibsect.colours[i].rgbRed = curpalette[i].r; - } + // create the new DIB section + memset(&dibsect, 0, sizeof(dibsect)); + numpages = 1; // KJS 20031225 + dibsect.header.biSize = sizeof(dibsect.header); + dibsect.header.biWidth = width|1; // Ken did this + dibsect.header.biHeight = -height; + dibsect.header.biPlanes = 1; + dibsect.header.biBitCount = 8; + dibsect.header.biCompression = BI_RGB; + dibsect.header.biClrUsed = 256; + dibsect.header.biClrImportant = 256; + for (i=0; i<256; i++) { + dibsect.colours[i].rgbBlue = curpalette[i].b; + dibsect.colours[i].rgbGreen = curpalette[i].g; + dibsect.colours[i].rgbRed = curpalette[i].r; + } - hDIBSection = CreateDIBSection(hDC, (BITMAPINFO *)&dibsect, DIB_RGB_COLORS, &lpPixels, NULL, 0); - if (!hDIBSection) { - ReleaseDC(hWindow, hDC); - hDC = NULL; + hDIBSection = CreateDIBSection(hDC, (BITMAPINFO *)&dibsect, DIB_RGB_COLORS, &lpPixels, NULL, 0); + if (!hDIBSection) { + ReleaseDC(hWindow, hDC); + hDC = NULL; - ShowErrorBox("Error creating DIB section"); - return TRUE; - } + ShowErrorBox("Error creating DIB section"); + return TRUE; + } - memset(lpPixels, 0, width*height); + memset(lpPixels, 0, width*height); - // create a compatible memory DC - hDCSection = CreateCompatibleDC(hDC); - if (!hDCSection) { - ReleaseDC(hWindow, hDC); - hDC = NULL; + // create a compatible memory DC + hDCSection = CreateCompatibleDC(hDC); + if (!hDCSection) { + ReleaseDC(hWindow, hDC); + hDC = NULL; - ShowErrorBox("Error creating compatible DC"); - return TRUE; - } + ShowErrorBox("Error creating compatible DC"); + return TRUE; + } - // select the DIB section into the memory DC - if (!SelectObject(hDCSection, hDIBSection)) { - ReleaseDC(hWindow, hDC); - hDC = NULL; - DeleteDC(hDCSection); - hDCSection = NULL; + // select the DIB section into the memory DC + if (!SelectObject(hDCSection, hDIBSection)) { + ReleaseDC(hWindow, hDC); + hDC = NULL; + DeleteDC(hDCSection); + hDCSection = NULL; - ShowErrorBox("Error creating compatible DC"); - return TRUE; - } + ShowErrorBox("Error creating compatible DC"); + return TRUE; + } - return FALSE; + return FALSE; } #if defined(USE_OPENGL) && defined(POLYMOST) @@ -2948,21 +2948,21 @@ static HWND hGLWindow = NULL; static void ReleaseOpenGL(void) { - if (hGLRC) { - polymost_glreset(); - if (!bwglMakeCurrent(0,0)) { } - if (!bwglDeleteContext(hGLRC)) { } - hGLRC = NULL; - } - if (hGLWindow) { - if (hDC) { - ReleaseDC(hGLWindow, hDC); - hDC = NULL; - } + if (hGLRC) { + polymost_glreset(); + if (!bwglMakeCurrent(0,0)) { } + if (!bwglDeleteContext(hGLRC)) { } + hGLRC = NULL; + } + if (hGLWindow) { + if (hDC) { + ReleaseDC(hGLWindow, hDC); + hDC = NULL; + } - DestroyWindow(hGLWindow); - hGLWindow = NULL; - } + DestroyWindow(hGLWindow); + hGLWindow = NULL; + } } @@ -2971,7 +2971,7 @@ static void ReleaseOpenGL(void) // static void UninitOpenGL(void) { - ReleaseOpenGL(); + ReleaseOpenGL(); } @@ -2980,138 +2980,138 @@ static void UninitOpenGL(void) // static int SetupOpenGL(int width, int height, int bitspp) { - PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), - 1, //Version Number - PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, //Must Support these - PFD_TYPE_RGBA, //Request An RGBA Format - 0, //Select Our Color Depth - 0,0,0,0,0,0, //Color Bits Ignored - 0, //No Alpha Buffer - 0, //Shift Bit Ignored - 0, //No Accumulation Buffer - 0,0,0,0, //Accumulation Bits Ignored - 32, //16/24/32 Z-Buffer depth - 0, //No Stencil Buffer - 0, //No Auxiliary Buffer - PFD_MAIN_PLANE, //Main Drawing Layer - 0, //Reserved - 0,0,0 //Layer Masks Ignored - }; - GLuint PixelFormat; - int minidriver; - int err; - static int warnonce = 0; - pfd.cColorBits = bitspp; + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), + 1, //Version Number + PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, //Must Support these + PFD_TYPE_RGBA, //Request An RGBA Format + 0, //Select Our Color Depth + 0,0,0,0,0,0, //Color Bits Ignored + 0, //No Alpha Buffer + 0, //Shift Bit Ignored + 0, //No Accumulation Buffer + 0,0,0,0, //Accumulation Bits Ignored + 32, //16/24/32 Z-Buffer depth + 0, //No Stencil Buffer + 0, //No Auxiliary Buffer + PFD_MAIN_PLANE, //Main Drawing Layer + 0, //Reserved + 0,0,0 //Layer Masks Ignored + }; + GLuint PixelFormat; + int minidriver; + int err; + static int warnonce = 0; + pfd.cColorBits = bitspp; - hGLWindow = CreateWindow( - WindowClass, - "OpenGL Window", - WS_CHILD|WS_VISIBLE, - 0,0, - width,height, - hWindow, - (HMENU)1, - hInstance, - NULL); - if (!hGLWindow) { - ShowErrorBox("Error creating OpenGL child window."); - return TRUE; - } + hGLWindow = CreateWindow( + WindowClass, + "OpenGL Window", + WS_CHILD|WS_VISIBLE, + 0,0, + width,height, + hWindow, + (HMENU)1, + hInstance, + NULL); + if (!hGLWindow) { + ShowErrorBox("Error creating OpenGL child window."); + return TRUE; + } - hDC = GetDC(hGLWindow); - if (!hDC) { - ReleaseOpenGL(); - ShowErrorBox("Error getting device context"); - return TRUE; - } + hDC = GetDC(hGLWindow); + if (!hDC) { + ReleaseOpenGL(); + ShowErrorBox("Error getting device context"); + return TRUE; + } - minidriver = Bstrcasecmp(gldriver,"opengl32.dll"); + minidriver = Bstrcasecmp(gldriver,"opengl32.dll"); - if (minidriver) PixelFormat = bwglChoosePixelFormat(hDC,&pfd); - else PixelFormat = ChoosePixelFormat(hDC,&pfd); - if (!PixelFormat) { - ReleaseOpenGL(); - ShowErrorBox("Can't choose pixel format"); - return TRUE; - } + if (minidriver) PixelFormat = bwglChoosePixelFormat(hDC,&pfd); + else PixelFormat = ChoosePixelFormat(hDC,&pfd); + if (!PixelFormat) { + ReleaseOpenGL(); + ShowErrorBox("Can't choose pixel format"); + return TRUE; + } - if (minidriver) err = bwglSetPixelFormat(hDC, PixelFormat, &pfd); - else err = SetPixelFormat(hDC, PixelFormat, &pfd); - if (!err) { - ReleaseOpenGL(); - ShowErrorBox("Can't set pixel format"); - return TRUE; - } + if (minidriver) err = bwglSetPixelFormat(hDC, PixelFormat, &pfd); + else err = SetPixelFormat(hDC, PixelFormat, &pfd); + if (!err) { + ReleaseOpenGL(); + ShowErrorBox("Can't set pixel format"); + return TRUE; + } - hGLRC = bwglCreateContext(hDC); - if (!hGLRC) { - ReleaseOpenGL(); - ShowErrorBox("Can't create GL RC"); - return TRUE; - } + hGLRC = bwglCreateContext(hDC); + if (!hGLRC) { + ReleaseOpenGL(); + ShowErrorBox("Can't create GL RC"); + return TRUE; + } - if (!bwglMakeCurrent(hDC, hGLRC)) { - ReleaseOpenGL(); - ShowErrorBox("Can't activate GL RC"); - return TRUE; - } + if (!bwglMakeCurrent(hDC, hGLRC)) { + ReleaseOpenGL(); + ShowErrorBox("Can't activate GL RC"); + return TRUE; + } - polymost_glreset(); + polymost_glreset(); - bglEnable(GL_TEXTURE_2D); - bglShadeModel(GL_SMOOTH); //GL_FLAT - bglClearColor(0,0,0,0.5); //Black Background - bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! - bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); - bglHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST); - bglDisable(GL_DITHER); - - { - GLubyte *p,*p2,*p3; - int i; + bglEnable(GL_TEXTURE_2D); + bglShadeModel(GL_SMOOTH); //GL_FLAT + bglClearColor(0,0,0,0.5); //Black Background + bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! + bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); + bglHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST); + bglDisable(GL_DITHER); - glinfo.vendor = bglGetString(GL_VENDOR); - glinfo.renderer = bglGetString(GL_RENDERER); - glinfo.version = bglGetString(GL_VERSION); - glinfo.extensions = bglGetString(GL_EXTENSIONS); - - glinfo.maxanisotropy = 1.0; - glinfo.bgra = 0; - glinfo.texcompr = 0; + { + GLubyte *p,*p2,*p3; + int i; - // process the extensions string and flag stuff we recognize - p = Bstrdup(glinfo.extensions); - p3 = p; - while ((p2 = Bstrtoken(p3==p?p:NULL, " ", (char**)&p3, 1)) != NULL) { - if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { - // supports anisotropy. get the maximum anisotropy level - bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); - } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || - !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { - // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS - glinfo.clamptoedge = 1; - } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { - // support bgra textures - glinfo.bgra = 1; - } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { - // support texture compression - glinfo.texcompr = 1; - } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { - // support non-power-of-two texture sizes - glinfo.texnpot = 1; - } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { - // 3dfx cards have issues with fog - nofog = 1; - if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); - warnonce |= 1; - } - } - Bfree(p); - } - numpages = 2; // KJS 20031225: tell rotatesprite that it's double buffered! + glinfo.vendor = bglGetString(GL_VENDOR); + glinfo.renderer = bglGetString(GL_RENDERER); + glinfo.version = bglGetString(GL_VERSION); + glinfo.extensions = bglGetString(GL_EXTENSIONS); - return FALSE; + glinfo.maxanisotropy = 1.0; + glinfo.bgra = 0; + glinfo.texcompr = 0; + + // process the extensions string and flag stuff we recognize + p = Bstrdup(glinfo.extensions); + p3 = p; + while ((p2 = Bstrtoken(p3==p?p:NULL, " ", (char**)&p3, 1)) != NULL) { + if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { + // supports anisotropy. get the maximum anisotropy level + bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); + } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || + !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { + // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS + glinfo.clamptoedge = 1; + } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { + // support bgra textures + glinfo.bgra = 1; + } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { + // support texture compression + glinfo.texcompr = 1; + } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { + // support non-power-of-two texture sizes + glinfo.texnpot = 1; + } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { + // 3dfx cards have issues with fog + nofog = 1; + if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); + warnonce |= 1; + } + } + Bfree(p); + } + numpages = 2; // KJS 20031225: tell rotatesprite that it's double buffered! + + return FALSE; } #endif @@ -3120,222 +3120,222 @@ static int SetupOpenGL(int width, int height, int bitspp) // static BOOL CreateAppWindow(int modenum, char *wtitle) { - RECT rect; - int w, h, x, y, stylebits = 0, stylebitsex = 0; - int width, height, fs, bitspp; + RECT rect; + int w, h, x, y, stylebits = 0, stylebitsex = 0; + int width, height, fs, bitspp; - HRESULT result; + HRESULT result; - if (modenum == 0x7fffffff) { - width = customxdim; - height = customydim; - fs = customfs; - bitspp = custombpp; - } else { - width = validmode[modenum].xdim; - height = validmode[modenum].ydim; - fs = validmode[modenum].fs; - bitspp = validmode[modenum].bpp; - } + if (modenum == 0x7fffffff) { + width = customxdim; + height = customydim; + fs = customfs; + bitspp = custombpp; + } else { + width = validmode[modenum].xdim; + height = validmode[modenum].ydim; + fs = validmode[modenum].fs; + bitspp = validmode[modenum].bpp; + } - if (width == xres && height == yres && fs == fullscreen && bitspp == bpp && !videomodereset) return FALSE; + if (width == xres && height == yres && fs == fullscreen && bitspp == bpp && !videomodereset) return FALSE; - if (hWindow) { - if (bpp > 8) { + if (hWindow) { + if (bpp > 8) { #if defined(USE_OPENGL) && defined(POLYMOST) - ReleaseOpenGL(); // release opengl + ReleaseOpenGL(); // release opengl #endif - } else { - ReleaseDirectDrawSurfaces(); // releases directdraw surfaces - } + } else { + ReleaseDirectDrawSurfaces(); // releases directdraw surfaces + } - if (!fs && fullscreen) { - // restore previous display mode and set to normal cooperative level - RestoreDirectDrawMode(); + if (!fs && fullscreen) { + // restore previous display mode and set to normal cooperative level + RestoreDirectDrawMode(); #if defined(USE_OPENGL) && defined(POLYMOST) - } else if (fs && fullscreen) { - // using CDS for GL modes, so restore from DirectDraw - if (bpp != bitspp) RestoreDirectDrawMode(); + } else if (fs && fullscreen) { + // using CDS for GL modes, so restore from DirectDraw + if (bpp != bitspp) RestoreDirectDrawMode(); #endif - } - + } - ShowWindow(hWindow, SW_HIDE); // so Windows redraws what's behind if the window shrinks - } - if (fs) { - stylebitsex = WS_EX_TOPMOST; - stylebits = WS_POPUP; - } else { - stylebitsex = 0; - stylebits = WINDOW_STYLE; - } + ShowWindow(hWindow, SW_HIDE); // so Windows redraws what's behind if the window shrinks + } - if (!hWindow) { - hWindow = CreateWindowEx( - stylebitsex, - "buildapp", - apptitle, - stylebits, - CW_USEDEFAULT, - CW_USEDEFAULT, - 320, - 200, - NULL, - NULL, - hInstance, - 0); - if (!hWindow) { - ShowErrorBox("Unable to create window"); - return TRUE; - } + if (fs) { + stylebitsex = WS_EX_TOPMOST; + stylebits = WS_POPUP; + } else { + stylebitsex = 0; + stylebits = WINDOW_STYLE; + } - if (startupdlg) { - DestroyWindow(startupdlg); - } - } else { - SetWindowLong(hWindow,GWL_EXSTYLE,stylebitsex); - SetWindowLong(hWindow,GWL_STYLE,stylebits); - } + if (!hWindow) { + hWindow = CreateWindowEx( + stylebitsex, + "buildapp", + apptitle, + stylebits, + CW_USEDEFAULT, + CW_USEDEFAULT, + 320, + 200, + NULL, + NULL, + hInstance, + 0); + if (!hWindow) { + ShowErrorBox("Unable to create window"); + return TRUE; + } - // resize the window - if (!fs) { - rect.left = 0; - rect.top = 0; - rect.right = width-1; - rect.bottom = height-1; - AdjustWindowRect(&rect, stylebits, FALSE); + if (startupdlg) { + DestroyWindow(startupdlg); + } + } else { + SetWindowLong(hWindow,GWL_EXSTYLE,stylebitsex); + SetWindowLong(hWindow,GWL_STYLE,stylebits); + } - w = (rect.right - rect.left); - h = (rect.bottom - rect.top); - x = (desktopxdim - w) / 2; - y = (desktopydim - h) / 2; - } else { - x=y=0; - w=width; - h=height; - } - SetWindowPos(hWindow, HWND_TOP, x, y, w, h, 0); + // resize the window + if (!fs) { + rect.left = 0; + rect.top = 0; + rect.right = width-1; + rect.bottom = height-1; + AdjustWindowRect(&rect, stylebits, FALSE); - SetWindowText(hWindow, wtitle); - ShowWindow(hWindow, SW_SHOWNORMAL); - SetForegroundWindow(hWindow); - SetFocus(hWindow); + w = (rect.right - rect.left); + h = (rect.bottom - rect.top); + x = (desktopxdim - w) / 2; + y = (desktopydim - h) / 2; + } else { + x=y=0; + w=width; + h=height; + } + SetWindowPos(hWindow, HWND_TOP, x, y, w, h, 0); - // fullscreen? - if (!fs) { - if (bitspp > 8) { + SetWindowText(hWindow, wtitle); + ShowWindow(hWindow, SW_SHOWNORMAL); + SetForegroundWindow(hWindow); + SetFocus(hWindow); + + // fullscreen? + if (!fs) { + if (bitspp > 8) { #if defined(USE_OPENGL) && defined(POLYMOST) - // yes, start up opengl - if (SetupOpenGL(width,height,bitspp)) { - return TRUE; - } + // yes, start up opengl + if (SetupOpenGL(width,height,bitspp)) { + return TRUE; + } #endif - } else { - // no, use DIB section - if (SetupDIB(width,height)) { - return TRUE; - } - } + } else { + // no, use DIB section + if (SetupDIB(width,height)) { + return TRUE; + } + } - modesetusing = -1; + modesetusing = -1; - } else { - // yes, set up DirectDraw + } else { + // yes, set up DirectDraw - // clean up after the DIB renderer if it was being used - UninitDIB(); + // clean up after the DIB renderer if it was being used + UninitDIB(); - if (!bDDrawInited) { - DestroyWindow(hWindow); - hWindow = NULL; - return TRUE; - } + if (!bDDrawInited) { + DestroyWindow(hWindow); + hWindow = NULL; + return TRUE; + } #if defined(USE_OPENGL) && defined(POLYMOST) - if (bitspp > 8) { - DEVMODE dmScreenSettings; + if (bitspp > 8) { + DEVMODE dmScreenSettings; - ZeroMemory(&dmScreenSettings, sizeof(DEVMODE)); - dmScreenSettings.dmSize = sizeof(DEVMODE); - dmScreenSettings.dmPelsWidth = width; - dmScreenSettings.dmPelsHeight = height; - dmScreenSettings.dmBitsPerPel = bitspp; - dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; - if (modenum != 0x7fffffff) { - dmScreenSettings.dmDisplayFrequency = validmode[modenum].extra; - dmScreenSettings.dmFields |= DM_DISPLAYFREQUENCY; - } + ZeroMemory(&dmScreenSettings, sizeof(DEVMODE)); + dmScreenSettings.dmSize = sizeof(DEVMODE); + dmScreenSettings.dmPelsWidth = width; + dmScreenSettings.dmPelsHeight = height; + dmScreenSettings.dmBitsPerPel = bitspp; + dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; + if (modenum != 0x7fffffff) { + dmScreenSettings.dmDisplayFrequency = validmode[modenum].extra; + dmScreenSettings.dmFields |= DM_DISPLAYFREQUENCY; + } - if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { - ShowErrorBox("Video mode not supported"); - return TRUE; - } + if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { + ShowErrorBox("Video mode not supported"); + return TRUE; + } - ShowWindow(hWindow, SW_SHOWNORMAL); - SetForegroundWindow(hWindow); - SetFocus(hWindow); + ShowWindow(hWindow, SW_SHOWNORMAL); + SetForegroundWindow(hWindow); + SetFocus(hWindow); - modesetusing = 1; - } else + modesetusing = 1; + } else #endif - { - // set exclusive cooperative level - result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN); - if (result != DD_OK) { - ShowDDrawErrorBox("Error setting cooperative level", result); - UninitDirectDraw(); - return TRUE; - } + { + // set exclusive cooperative level + result = IDirectDraw_SetCooperativeLevel(lpDD, hWindow, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN); + if (result != DD_OK) { + ShowDDrawErrorBox("Error setting cooperative level", result); + UninitDirectDraw(); + return TRUE; + } - result = IDirectDraw_SetDisplayMode(lpDD, width, height, bitspp); - if (result != DD_OK) { - ShowDDrawErrorBox("Error setting display mode", result); - UninitDirectDraw(); - return TRUE; - } + result = IDirectDraw_SetDisplayMode(lpDD, width, height, bitspp); + if (result != DD_OK) { + ShowDDrawErrorBox("Error setting display mode", result); + UninitDirectDraw(); + return TRUE; + } - modesetusing = 0; - } - - if (bitspp > 8) { + modesetusing = 0; + } + + if (bitspp > 8) { #if defined(USE_OPENGL) && defined(POLYMOST) - // we want an opengl mode - if (SetupOpenGL(width,height,bitspp)) { - return TRUE; - } + // we want an opengl mode + if (SetupOpenGL(width,height,bitspp)) { + return TRUE; + } #endif - } else { - // we want software - if (SetupDirectDraw(width,height)) { - return TRUE; - } - } - } - + } else { + // we want software + if (SetupDirectDraw(width,height)) { + return TRUE; + } + } + } + #if defined(USE_OPENGL) && defined(POLYMOST) - if (bitspp > 8) loadglextensions(); + if (bitspp > 8) loadglextensions(); #endif - xres = width; - yres = height; - bpp = bitspp; - fullscreen = fs; - curvidmode = modenum; + xres = width; + yres = height; + bpp = bitspp; + fullscreen = fs; + curvidmode = modenum; - frameplace = 0; - lockcount = 0; + frameplace = 0; + lockcount = 0; - // bytesperline is set when framebuffer is locked - //bytesperline = width; - //imageSize = bytesperline*yres; + // bytesperline is set when framebuffer is locked + //bytesperline = width; + //imageSize = bytesperline*yres; - modechange = 1; - OSD_ResizeDisplay(xres,yres); + modechange = 1; + OSD_ResizeDisplay(xres,yres); - UpdateWindow(hWindow); + UpdateWindow(hWindow); - return FALSE; + return FALSE; } @@ -3344,21 +3344,21 @@ static BOOL CreateAppWindow(int modenum, char *wtitle) // static void DestroyAppWindow(void) { - if (hWindow && gammabrightness) { - setgammaramp(sysgamma); - gammabrightness = 0; - } + if (hWindow && gammabrightness) { + setgammaramp(sysgamma); + gammabrightness = 0; + } #if defined(USE_OPENGL) && defined(POLYMOST) - UninitOpenGL(); + UninitOpenGL(); #endif - UninitDirectDraw(); - UninitDIB(); + UninitDirectDraw(); + UninitDIB(); - if (hWindow) { - DestroyWindow(hWindow); - hWindow = NULL; - } + if (hWindow) { + DestroyWindow(hWindow); + hWindow = NULL; + } } @@ -3367,14 +3367,14 @@ static void DestroyAppWindow(void) // static void SaveSystemColours(void) { - int i; + int i; - if (system_colours_saved) return; + if (system_colours_saved) return; - for (i=0; iscuba_amount+63)>>6); break; case 7: i = (p->boot_amount>>1); break; } - invennum(284-30-o,200-6,(char)i,0,10+permbit); - if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit + 256); - else if ((unsigned long)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit + 256); - if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit + 256); + invennum(284-30-o,200-6,(char)i,0,10+permbit); + if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit + 256); + else if ((unsigned long)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit + 256); + if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit + 256); } return; }