From d826db409e2427122d26c93e654e0731c2081a94 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 4 Jul 2006 05:46:38 +0000 Subject: [PATCH] git-svn-id: https://svn.eduke32.com/eduke32@208 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/polymost.c | 18 +++++---- polymer/eduke32/Makefile | 2 +- polymer/eduke32/source/jfaud_sounds.cpp | 54 +++++++++++++++++-------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 159a5ebe7..7fea52754 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -71,7 +71,9 @@ long usemodels=1, usehightile=1; float foggymcfogfogger; -float fogtable[] = { 0.132, 0.165, 0.198, 0.231, 0.264, 0.297, 0.330, 0.363, 0.396, 0.429, 0.462, 0.495, 0.528, 0.561, 0.594, 0.627, 0.660, 0.693, 0.726, 0.759, 0.792, 0.825, 0.858, 0.891, 0.924, 0.957, 1.023, 1.056, 1.089, 1.122, 1.155, 1.188 }; +// float fogtable[] = { 0.132, 0.165, 0.198, 0.231, 0.264, 0.297, 0.330, 0.363, 0.396, 0.429, 0.462, 0.495, 0.528, 0.561, 0.594, 0.627, 0.660, 0.693, 0.726, 0.759, 0.792, 0.825, 0.858, 0.891, 0.924, 0.957, 1.023, 1.056, 1.089, 1.122, 1.155, 1.188 }; + +float fogtable[] = { 0.125, 0.150, 0.175, 0.200, 0.225, 0.250, 0.275, 0.300, 0.325, 0.350, 0.375, 0.400, 0.425, 0.450, 0.475, 0.500, 0.525, 0.550, 0.575, 0.600, 0.625, 0.650, 0.675, 0.700, 0.725, 0.750, 0.775, 0.800, 0.825, 0.850, 0.875, 0.900 }; #include //<-important! typedef struct { float x, cy[2], fy[2]; long n, p, tag, ctag, ftag; } vsptyp; @@ -2374,7 +2376,7 @@ static void polymost_drawalls (long bunch) { int i = klabs(sec->floorshade); if(i > 30) i = 30; - bglFogf(GL_FOG_DENSITY,gvisibility/(sec->floorshade<0?klabs(sec->floorshade):1)*(sec->floorshade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(sec->floorshade<0?i<<1:1)*(sec->floorshade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); } pow2xsplit = 0; domost(x0,fy0,x1,fy1); //flor bglFogf(GL_FOG_DENSITY,foggymcfogfogger); @@ -2734,7 +2736,7 @@ static void polymost_drawalls (long bunch) { int i = klabs(sec->ceilingshade); if(i > 30) i = 30; - bglFogf(GL_FOG_DENSITY,gvisibility/(sec->ceilingshade<0?klabs(sec->ceilingshade):1)*(sec->ceilingshade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(sec->ceilingshade<0?i<<1:1)*(sec->ceilingshade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); } pow2xsplit = 0; domost(x1,cy1,x0,cy0); //ceil bglFogf(GL_FOG_DENSITY,foggymcfogfogger); @@ -3066,7 +3068,7 @@ static void polymost_drawalls (long bunch) int i = klabs(wal->shade); if(i > 30) i = 30; bglGetFloatv(GL_FOG_DENSITY,&foggymcfogfogger); - bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?klabs(wal->shade):1)*(wal->shade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?i<<1:1)*(wal->shade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); pow2xsplit = 1; domost(x1,ocy1,x0,ocy0); bglFogf(GL_FOG_DENSITY,foggymcfogfogger); } @@ -3109,7 +3111,7 @@ static void polymost_drawalls (long bunch) int i = klabs(nwal->shade); if(i > 30) i = 30; bglGetFloatv(GL_FOG_DENSITY,&foggymcfogfogger); - bglFogf(GL_FOG_DENSITY,gvisibility/(nwal->shade<0?klabs(nwal->shade):1)*(nwal->shade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(nwal->shade<0?i<<1:1)*(nwal->shade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); pow2xsplit = 1; domost(x0,ofy0,x1,ofy1); bglFogf(GL_FOG_DENSITY,foggymcfogfogger); } @@ -3148,7 +3150,7 @@ static void polymost_drawalls (long bunch) int i = klabs(wal->shade); if(i > 30) i = 30; bglGetFloatv(GL_FOG_DENSITY,&foggymcfogfogger); - bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?klabs(wal->shade):1)*(wal->shade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?i<<1:1)*(wal->shade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); pow2xsplit = 1; domost(x0,-10000,x1,-10000); bglFogf(GL_FOG_DENSITY,foggymcfogfogger); } @@ -3606,7 +3608,7 @@ if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; { int i = klabs(wal->shade); if(i > 30) i = 30; - bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?klabs(wal->shade):1)*(wal->shade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(wal->shade<0?i<<1:1)*(wal->shade<0?1:fogtable[i]*3.5)*((float)((unsigned char)(sec->visibility+16)))); } } } @@ -3717,7 +3719,7 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } { int i = klabs(globalshade); if(i > 30) i = 30; - bglFogf(GL_FOG_DENSITY,gvisibility/(globalshade<0?klabs(globalshade):1)*(globalshade<0?fogtable[0]:fogtable[i]*3.5)*((float)((unsigned char)(sector[tspr->sectnum].visibility+16)))); + bglFogf(GL_FOG_DENSITY,gvisibility/(globalshade<0?i<<1:1)*(globalshade<0?1:fogtable[i]*2.5)*((float)((unsigned char)(sector[tspr->sectnum].visibility+16)))); } } diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 6aa0affdc..69e258d41 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -37,7 +37,7 @@ CXX=g++ # -Werror-implicit-function-declaration OURCFLAGS=$(debug) -W -Wall -Wimplicit -Wno-char-subscripts -Wunused \ -funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -DNOCOPYPROTECT \ - -I$(INC:/=) -I$(EINC:/=) -I$(SRC)jmact -I$(SRC)jaudiolib -I../jfaud/src + -I$(INC:/=) -I$(EINC:/=) -I$(SRC)jmact -I$(SRC)jaudiolib -I../jfaud/inc OURCXXFLAGS=-fno-exceptions -fno-rtti LIBS=-lm ifneq (0,$(JFAUD)) diff --git a/polymer/eduke32/source/jfaud_sounds.cpp b/polymer/eduke32/source/jfaud_sounds.cpp index 803224fbf..bcd3b197a 100644 --- a/polymer/eduke32/source/jfaud_sounds.cpp +++ b/polymer/eduke32/source/jfaud_sounds.cpp @@ -46,7 +46,11 @@ typedef uint64 uint64_t; #define SOUNDM_NICE 64 // Added for JFDuke3D so JFAud doesn't use nearest filtering for the sound #define SOUNDM_PLAYER 128 -#define UNITSPERMETRE 512.0 +#define UNITSPERMETRE 1024.0 +#define DEFAULTREFDIST 6.5 // in the original code, ((255-150)<<6) == 6720 +#define DEFAULTMAXDIST 30.0 // in the original code, 31444 +#define DEFAULTROLLOFF 1.0//0.75 +#define OCCLUDEDFACTOR 0.8 #include @@ -314,7 +318,7 @@ int isspritemakingsound(short i, int num) // if num<0, check if making any sound return n; } -int issoundplaying(int num) +int issoundplaying(short i, int num) { int j,n=0; @@ -331,7 +335,7 @@ int xyzsound(short num, short i, long x, long y, long z) { JFAudMixerChannel *chan; int r, global = 0; - float gain = 1.0, pitch = 1.0; + float gain = 1.0, pitch = 1.0, refdist = DEFAULTREFDIST, maxdist = DEFAULTMAXDIST, rolloff = DEFAULTROLLOFF; if (!jfaud || !havewave || num >= NUM_SOUNDS || @@ -360,7 +364,12 @@ int xyzsound(short num, short i, long x, long y, long z) } } - // XXX: here goes musicandsfx ranging. This will change the refdist. + if( i >= 0 && !(soundm[num] & SOUNDM_GLOBAL) && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9) { + float d = (float)SHT/UNITSPERMETRE; + refdist = d / 2.0; + maxdist = d; + rolloff = 1.0; + } { int ps = soundps[num], pe = soundpe[num], cx; @@ -371,11 +380,15 @@ int xyzsound(short num, short i, long x, long y, long z) } else pitch = translatepitch(ps); } - //gain += soundvo[num]; + { + float d = 1.0-(float)soundvo[num]/(12.0*1024.0); + maxdist *= d; + refdist *= d; + } if (PN != MUSICANDSFX && - !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), - ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) - gain *= 1.0/32.0; + !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), + ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) + gain *= OCCLUDEDFACTOR; switch(num) { @@ -409,8 +422,10 @@ int xyzsound(short num, short i, long x, long y, long z) chan->SetGain(gain); chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); + chan->SetLoop((soundm[num] & SOUNDM_LOOP) == SOUNDM_LOOP); if (soundm[num] & SOUNDM_GLOBAL) global = 1; + chan->SetRefDist(refdist); + chan->SetMaxDist(maxdist); chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); if (PN == APLAYER && sprite[i].yvel == screenpeek) { @@ -418,11 +433,12 @@ int xyzsound(short num, short i, long x, long y, long z) chan->SetFollowListener(true); chan->SetPosition(0.0, 0.0, 0.0); } else { - chan->SetRolloff(global ? 0.0 : 1.0); + chan->SetRolloff(global ? 0.0 : rolloff); chan->SetFollowListener(false); chan->SetPosition((float)x/UNITSPERMETRE, (float)(-z>>4)/UNITSPERMETRE, (float)y/UNITSPERMETRE); } - + initprintf("%d gain=%g ptch=%g loop=%d glob=%d refd=%g maxd=%g\n",num,gain,pitch, + (soundm[num] & SOUNDM_LOOP) == SOUNDM_LOOP, global, refdist, maxdist); r = keephandle(chan, num, i); if (r >= 0) chan->SetStopCallback(stopcallback, r); chan->Play(); @@ -457,8 +473,9 @@ void sound(short num) chan->SetGain(1.0); chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); + chan->SetLoop((soundm[num] & SOUNDM_LOOP) == SOUNDM_LOOP); chan->SetRolloff(0.0); + chan->SetRefDist(DEFAULTREFDIST); chan->SetFollowListener(true); chan->SetPosition(0.0, 0.0, 0.0); chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); @@ -524,7 +541,7 @@ void pan3dsound(void) short i; long cx, cy, cz, sx,sy,sz; short ca,cs; - float gain; + float gain, rolloff; numenvsnds = 0; if (!jfaud || !havewave) return; @@ -556,17 +573,20 @@ void pan3dsound(void) global = 0; gain = 1.0; + rolloff = DEFAULTROLLOFF; i = chans[j].owner; sx = sprite[i].x; sy = sprite[i].y; sz = sprite[i].z; - //gain += soundvo[num]; if (PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT) ) - gain *= 1.0/32.0; + gain *= OCCLUDEDFACTOR; - if(PN == MUSICANDSFX && SLT < 999) numenvsnds++; + if(PN == MUSICANDSFX && SLT < 999) { + numenvsnds++; + rolloff = 1.0; + } if( soundm[ chans[j].soundnum ]&SOUNDM_GLOBAL ) global = 1; switch(chans[j].soundnum) { @@ -592,7 +612,7 @@ void pan3dsound(void) chans[j].chan->SetFollowListener(true); chans[j].chan->SetPosition(0.0, 0.0, 0.0); } else { - chans[j].chan->SetRolloff(global ? 0.0 : 1.0); + chans[j].chan->SetRolloff(global ? 0.0 : rolloff); chans[j].chan->SetFollowListener(false); chans[j].chan->SetPosition((float)sx/UNITSPERMETRE, (float)(-sz>>4)/UNITSPERMETRE, (float)sy/UNITSPERMETRE); }