From 0b5de0800a8b5b2d14ad5947295ee6961806e8b2 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 26 Jun 2010 08:51:42 +0000 Subject: [PATCH] Final round (I hope!) of sound fixes. Should also fix the crash on exit on Windows and the REACTOR sprite size bug. git-svn-id: https://svn.eduke32.com/eduke32@1662 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/mdsprite.c | 3 +- polymer/eduke32/eduke32.vcxproj | 1 + polymer/eduke32/eduke32.vcxproj.filters | 3 + polymer/eduke32/source/duke3d.h | 1 + polymer/eduke32/source/game.c | 75 +++++++----------- polymer/eduke32/source/gamedef.c | 7 -- .../eduke32/source/jaudiolib/include/music.h | 2 +- polymer/eduke32/source/jaudiolib/src/mix.c | 8 +- .../eduke32/source/jaudiolib/src/multivoc.c | 6 +- polymer/eduke32/source/macros.h | 4 +- polymer/eduke32/source/midi.c | 4 +- polymer/eduke32/source/music.c | 2 +- polymer/eduke32/source/sdlmusic.c | 2 +- polymer/eduke32/source/sounds.c | 79 ++++++++++++++----- 14 files changed, 111 insertions(+), 86 deletions(-) diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 511dfd08d..3c9425999 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -2269,6 +2269,7 @@ static void md3free(md3model_t *m) if (s->shaders) Bfree(s->shaders); if (s->uv) Bfree(s->uv); if (s->xyzn) Bfree(s->xyzn); + if (s->geometry) Bfree(s->geometry); } } Bfree(m->head.surfs); @@ -3191,7 +3192,7 @@ int32_t mddraw(spritetype *tspr) void mdfree(mdmodel_t *vm) { if (vm->mdnum == 1) { voxfree((voxmodel_t *)vm); return; } - if (vm->mdnum == 3) { md3free((md3model_t *)vm); return; } + if (vm->mdnum == 2 || vm->mdnum == 3) { md3free((md3model_t *)vm); return; } } #endif diff --git a/polymer/eduke32/eduke32.vcxproj b/polymer/eduke32/eduke32.vcxproj index 71be91dc2..4cacfe0d3 100644 --- a/polymer/eduke32/eduke32.vcxproj +++ b/polymer/eduke32/eduke32.vcxproj @@ -99,6 +99,7 @@ + diff --git a/polymer/eduke32/eduke32.vcxproj.filters b/polymer/eduke32/eduke32.vcxproj.filters index 3ccc2cb7c..bcaeaecca 100644 --- a/polymer/eduke32/eduke32.vcxproj.filters +++ b/polymer/eduke32/eduke32.vcxproj.filters @@ -318,6 +318,9 @@ build\headers + + build\headers + diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index d0d937158..dc78eaa8e 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -1090,6 +1090,7 @@ extern hashtable_t h_gamevars; extern hashtable_t h_arrays; extern hashtable_t h_keywords; extern hashtable_t h_gamefuncs; +extern hashtable_t h_labels; enum DukePacket_t { diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index e2ca87917..d251f8629 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3664,10 +3664,6 @@ void G_GameExit(const char *t) if (*t != 0) { - //setvmode(0x3); // JBF - //binscreen(); - // if(*t == ' ' && *(t+1) == 0) *t = 0; - //printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); if (!(t[0] == ' ' && t[1] == 0)) { char titlebuf[256]; @@ -3678,8 +3674,6 @@ void G_GameExit(const char *t) uninitgroupfile(); - //unlink("duke3d.tmp"); - exit(0); } @@ -6589,6 +6583,13 @@ int32_t A_Spawn(int32_t j, int32_t pn) case REACTOR2__STATIC: case REACTOR__STATIC: sp->extra = g_impactDamage; + CS |= 257; + sp->pal = 0; + SS = -17; + + changespritestat(i, STAT_ZOMBIEACTOR); + break; + case HEAVYHBOMB__STATIC: if (j >= 0) sp->owner = j; @@ -6612,22 +6613,22 @@ int32_t A_Spawn(int32_t j, int32_t pn) case RECON__STATIC: - if (sp->lotag > ud.player_skill) - { - sp->xrepeat = sp->yrepeat = 0; - changespritestat(i,5); - goto SPAWN_END; - } - g_player[myconnectindex].ps->max_actors_killed++; - actor[i].t_data[5] = 0; - if (ud.monsters_off == 1) - { - sp->xrepeat = sp->yrepeat = 0; - changespritestat(i,5); - break; - } - sp->extra = 130; - CS |= 256; // Make it hitable + if (sp->lotag > ud.player_skill) + { + sp->xrepeat = sp->yrepeat = 0; + changespritestat(i,5); + goto SPAWN_END; + } + g_player[myconnectindex].ps->max_actors_killed++; + actor[i].t_data[5] = 0; + if (ud.monsters_off == 1) + { + sp->xrepeat = sp->yrepeat = 0; + changespritestat(i,5); + break; + } + sp->extra = 130; + CS |= 256; // Make it hitable if ((!g_netServer && ud.multimode < 2) && sp->pal != 0) { @@ -10637,24 +10638,7 @@ static void G_DisplayLogo(void) clearview(0L); } -/* -static void loadtmb(void) -{ - char tmb[8000]; - int32_t fil, l; - - fil = kopen4load("d3dtimbr.tmb",0); - if (fil == -1) return; - l = kfilelength(fil); - kread(fil,(char *)tmb,l); - MUSIC_RegisterTimbreBank(tmb); - kclose(fil); -} -*/ - -extern void C_FreeHashes(); - -static void G_FreeMemory(void) +static void G_Cleanup(void) { int32_t i; extern char *bitptr; @@ -10693,7 +10677,9 @@ static void G_FreeMemory(void) // if (MusicPtr != NULL) Bfree(MusicPtr); - // C_FreeHashes(); + hash_free(&h_gamevars); + hash_free(&h_arrays); + hash_free(&h_labels); hash_free(&h_gamefuncs); } @@ -10707,14 +10693,13 @@ static void G_FreeMemory(void) void G_Shutdown(void) { + CONFIG_WriteSetup(); S_SoundShutdown(); S_MusicShutdown(); - uninittimer(); CONTROL_Shutdown(); - CONFIG_WriteSetup(); KB_Shutdown(); - G_FreeMemory(); uninitengine(); + G_Cleanup(); } /* @@ -10871,7 +10856,7 @@ static void G_Startup(void) { wm_msgbox("Build Engine Initialization Error", "There was a problem initializing the Build engine: %s", engineerrstr); - G_FreeMemory(); + G_Cleanup(); exit(1); } diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 0c3769acb..175489dbf 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1005,13 +1005,6 @@ void C_InitHashes() for (i=0; TsprLabels[i].lId >= 0; i++) hash_add(&tspriteH,TsprLabels[i].name,i); } -void C_FreeHashes(void) -{ - hash_free(&h_gamevars); - hash_free(&h_arrays); - hash_free(&h_labels); -} - // "magic" number for { and }, overrides line number in compiled code for later detection #define IFELSE_MAGIC 31337 static int32_t g_ifElseAborted; diff --git a/polymer/eduke32/source/jaudiolib/include/music.h b/polymer/eduke32/source/jaudiolib/include/music.h index e63af97f2..1d85f4284 100644 --- a/polymer/eduke32/source/jaudiolib/include/music.h +++ b/polymer/eduke32/source/jaudiolib/include/music.h @@ -85,7 +85,7 @@ void MUSIC_GetSongLength( songposition *pos ); int32_t MUSIC_FadeVolume( int32_t tovolume, int32_t milliseconds ); int32_t MUSIC_FadeActive( void ); void MUSIC_StopFade( void ); -void MUSIC_RerouteMidiChannel( int32_t channel, int32_t ( *function )( int32_t event, int32_t c1, int32_t c2 ) ); +void MUSIC_RerouteMidiChannel( int32_t channel, int32_t ( *function )( int32_t, int32_t, int32_t ) ); void MUSIC_RegisterTimbreBank( char *timbres ); void MUSIC_Update(void); diff --git a/polymer/eduke32/source/jaudiolib/src/mix.c b/polymer/eduke32/source/jaudiolib/src/mix.c index 24afcafb6..82ee3f214 100644 --- a/polymer/eduke32/source/jaudiolib/src/mix.c +++ b/polymer/eduke32/source/jaudiolib/src/mix.c @@ -307,7 +307,7 @@ void MV_16BitReverb( char *src, char *dest, VOLUME16 *volume, int32_t count ) input++; output++; - } while (count-- > 0); + } while (--count > 0); } void MV_8BitReverb( int8_t *src, int8_t *dest, VOLUME16 *volume, int32_t count ) @@ -320,7 +320,7 @@ void MV_8BitReverb( int8_t *src, int8_t *dest, VOLUME16 *volume, int32_t count ) input++; output++; - } while (count-- > 0); + } while (--count > 0); } void MV_16BitReverbFast( char *src, char *dest, int32_t count, int32_t shift ) @@ -333,7 +333,7 @@ void MV_16BitReverbFast( char *src, char *dest, int32_t count, int32_t shift ) input++; output++; - } while (count-- > 0); + } while (--count > 0); } void MV_8BitReverbFast( int8_t *src, int8_t *dest, int32_t count, int32_t shift ) @@ -348,6 +348,6 @@ void MV_8BitReverbFast( int8_t *src, int8_t *dest, int32_t count, int32_t shift src++; dest++; - } while (count-- > 0); + } while (--count > 0); } diff --git a/polymer/eduke32/source/jaudiolib/src/multivoc.c b/polymer/eduke32/source/jaudiolib/src/multivoc.c index 52add6b8b..7af46e1b3 100644 --- a/polymer/eduke32/source/jaudiolib/src/multivoc.c +++ b/polymer/eduke32/source/jaudiolib/src/multivoc.c @@ -2634,8 +2634,7 @@ int32_t MV_Init { status = MV_ErrorCode; - if (MV_Voices) - free(MV_Voices); + free(MV_Voices); MV_Voices = NULL; MV_HarshClipTable = NULL; MV_TotalMemory = 0; @@ -2714,8 +2713,7 @@ int32_t MV_Shutdown SoundDriver_Shutdown(); // Free any voices we allocated - if (MV_Voices) - free(MV_Voices); + free(MV_Voices); MV_Voices = NULL; MV_TotalMemory = 0; diff --git a/polymer/eduke32/source/macros.h b/polymer/eduke32/source/macros.h index 60ed0c8a8..b5a146b4b 100644 --- a/polymer/eduke32/source/macros.h +++ b/polymer/eduke32/source/macros.h @@ -24,8 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define GTFLAGS(x) (GametypeFlags[ud.coop] & x) -#define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); (n) = nextspritesect[o], (o) != -1; (o) = (n)) -#define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); (n) = nextspritestat[o], (o) != -1; (o) = (n)) +#define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); ((o) != -1) && ((n) = nextspritesect[o]); (o) = (n)) +#define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); ((o) != -1) && ((n) = nextspritestat[o]); (o) = (n)) #define TRAVERSE_CONNECT(i) for (i = 0; i != -1; i = connectpoint2[i]) #define TEST(flags,mask) ((flags) & (mask)) diff --git a/polymer/eduke32/source/midi.c b/polymer/eduke32/source/midi.c index 78dfc25cf..f72643d55 100644 --- a/polymer/eduke32/source/midi.c +++ b/polymer/eduke32/source/midi.c @@ -50,7 +50,7 @@ static const int32_t _MIDI_CommandLengths[ NUM_MIDI_CHANNELS ] = 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0 }; -static int32_t (*_MIDI_RerouteFunctions[ NUM_MIDI_CHANNELS ])(int32_t event, int32_t c1, int32_t c2); +static int32_t (*_MIDI_RerouteFunctions[ NUM_MIDI_CHANNELS ])(int32_t, int32_t, int32_t); static track *_MIDI_TrackPtr = NULL; static int32_t _MIDI_TrackMemSize; @@ -736,7 +736,7 @@ static int32_t _MIDI_SendControlChange void MIDI_RerouteMidiChannel ( int32_t channel, - int32_t(*function)(int32_t event, int32_t c1, int32_t c2) + int32_t(*function)(int32_t, int32_t, int32_t) ) { diff --git a/polymer/eduke32/source/music.c b/polymer/eduke32/source/music.c index ea2688bfb..19693141a 100644 --- a/polymer/eduke32/source/music.c +++ b/polymer/eduke32/source/music.c @@ -566,7 +566,7 @@ void MUSIC_StopFade void MUSIC_RerouteMidiChannel ( int32_t channel, - int32_t(*function)(int32_t event, int32_t c1, int32_t c2) + int32_t(*function)(int32_t, int32_t, int32_t) ) { diff --git a/polymer/eduke32/source/sdlmusic.c b/polymer/eduke32/source/sdlmusic.c index 5b3fb42fe..4747e848c 100644 --- a/polymer/eduke32/source/sdlmusic.c +++ b/polymer/eduke32/source/sdlmusic.c @@ -349,7 +349,7 @@ void MUSIC_StopFade(void) } // MUSIC_StopFade -void MUSIC_RerouteMidiChannel(int32_t channel, int32_t (*function)(int32_t event, int32_t c1, int32_t c2)) +void MUSIC_RerouteMidiChannel(int32_t channel, int32_t (*function)(int32_t, int32_t, int32_t)) { UNREFERENCED_PARAMETER(channel); UNREFERENCED_PARAMETER(function); diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 6386ff37b..8e6926bba 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -613,25 +613,34 @@ int32_t A_PlaySound(uint32_t num, int32_t i) void S_StopSound(int32_t num) { + int32_t iter = 0; + if (num < 0 || num > g_maxSoundPos || g_sounds[num].num <= 0) return; - retry: +retry: + + if (iter > MAXSOUNDINSTANCES) { int32_t j=MAXSOUNDINSTANCES-1; + initprintf(OSD_ERROR "S_StopSound(): too many iterations! The following IDs are still active for sound %d:\n", num); + for (; j>=0; j--) + if (g_sounds[num].SoundOwner[j].voice) + initprintf("slot %d, voice %d, sprite %d\n", j, g_sounds[num].SoundOwner[j].voice, g_sounds[num].SoundOwner[j].i); + return; + } + + { + int32_t j=MAXSOUNDINSTANCES-1; + + iter++; + for (; j>=0; j--) { if (g_sounds[num].SoundOwner[j].voice) { - if (g_sounds[num].SoundOwner[j].voice > FX_Ok && g_sounds[num].SoundOwner[j].voice <= ud.config.NumVoices) - { - if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice)) - FX_StopSound(g_sounds[num].SoundOwner[j].voice); - S_Cleanup(); - goto retry; - } - else + if (g_sounds[num].SoundOwner[j].voice <= FX_Ok || g_sounds[num].SoundOwner[j].voice > ud.config.NumVoices) { initprintf(OSD_ERROR "S_StopSound(): bad voice %d for sound ID %d index %d!\n", g_sounds[num].SoundOwner[j].voice, num, j); mutex_lock(&s_mutex); @@ -640,6 +649,17 @@ void S_StopSound(int32_t num) S_Cleanup(); goto retry; } + + if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice)) + FX_StopSound(g_sounds[num].SoundOwner[j].voice); + else + { + mutex_lock(&s_mutex); + dq[dnum++] = (num * MAXSOUNDINSTANCES) + j; + mutex_unlock(&s_mutex); + } + S_Cleanup(); + goto retry; } } } @@ -647,25 +667,33 @@ void S_StopSound(int32_t num) void S_StopEnvSound(int32_t num,int32_t i) { + int32_t iter = 0; + if (num < 0 || num > g_maxSoundPos || g_sounds[num].num <= 0) return; - retry: +retry: + if (iter > MAXSOUNDINSTANCES) { int32_t j=MAXSOUNDINSTANCES-1; + initprintf(OSD_ERROR "S_StopEnvSound(): too many iterations! The following IDs are still active for sound %d:\n", num); + for (; j>=0; j--) + if (g_sounds[num].SoundOwner[j].i == i) + initprintf("slot %d, voice %d, sprite %d\n", j, g_sounds[num].SoundOwner[j].voice, g_sounds[num].SoundOwner[j].i); + return; + } + + { + int32_t j=MAXSOUNDINSTANCES-1; + + iter++; + for (; j>=0; j--) { if (g_sounds[num].SoundOwner[j].i == i) { - if (g_sounds[num].SoundOwner[j].voice > FX_Ok && g_sounds[num].SoundOwner[j].voice <= ud.config.NumVoices) - { - if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice)) - FX_StopSound(g_sounds[num].SoundOwner[j].voice); - S_Cleanup(); - goto retry; - } - else + if (g_sounds[num].SoundOwner[j].voice <= FX_Ok || g_sounds[num].SoundOwner[j].voice > ud.config.NumVoices) { initprintf(OSD_ERROR "S_StopEnvSound(): bad voice %d for sound ID %d index %d!\n", g_sounds[num].SoundOwner[j].voice, num, j); mutex_lock(&s_mutex); @@ -674,6 +702,21 @@ void S_StopEnvSound(int32_t num,int32_t i) S_Cleanup(); goto retry; } + + if (FX_SoundActive(g_sounds[num].SoundOwner[j].voice)) + FX_StopSound(g_sounds[num].SoundOwner[j].voice); + else + { + // FX_SoundActive returning false could mean one of two things: we asked to stop the sound + // right when it was done playing, or we lost track of a voice somewhere (didn't get the callback) + // the first scenario resolves itself, and this addresses the second + + mutex_lock(&s_mutex); + dq[dnum++] = (num * MAXSOUNDINSTANCES) + j; + mutex_unlock(&s_mutex); + } + S_Cleanup(); + goto retry; } } }