Skip to content

Commit

Permalink
Move all sound init to init_game
Browse files Browse the repository at this point in the history
This allows fixing sound_null to enable the game (although it will be
broken in a few ways, particularly when it comes to ranged weapons.
These should probably rely on time values rather than sound effects.).
  • Loading branch information
lheckemann committed Oct 18, 2017
1 parent cc64584 commit 662bed6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 61 deletions.
54 changes: 0 additions & 54 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,42 +430,6 @@ int initApp(const char* title, int fullscreen)

GO_SwapBuffers(screen);

// load sound effects
printlog("loading sounds...\n");
fp = openDataFile("sound/sounds.txt", "r");
for ( numsounds = 0; !feof(fp); numsounds++ )
{
while ( fgetc(fp) != '\n' ) if ( feof(fp) )
{
break;
}
}
if ( numsounds == 0 )
{
printlog("failed to identify any sounds in sounds.txt\n");
fclose(fp);
return 10;
}
sounds = (Sound**) malloc(sizeof(Sound*)*numsounds);
rewind(fp);
for ( c = 0; !feof(fp); c++ )
{
fscanf(fp, "%s", name);
while ( fgetc(fp) != '\n' )
if ( feof(fp) )
break;
sounds[c] = createSound(name);
if (!sounds[c])
{
printlog("warning: failed to load sound '%s' at line %d in sounds.txt", name, c+1);
}
//TODO: set sound volume? Or otherwise handle sound volume.
}
fclose(fp);
ChannelGroup_SetVolume(sound_group, sfxvolume / 128.0);
// set 3d settings?
//FMOD_System_Set3DSettings(fmod_system, 1.0, 2.0, 1.0);

return 0;
}

Expand Down Expand Up @@ -1911,24 +1875,6 @@ int deinitApp()
free(polymodels);
}

// free sounds
printlog("freeing sounds...\n");
if ( sounds != NULL )
{
for ( c = 0; c < numsounds; c++ )
{
if (sounds[c] != NULL)
{
if (sounds[c] != NULL)
{
Sound_Release(sounds[c]); //Free the sound's FMOD sound.
}
//free(sounds[c]); //Then free the sound itself.
}
}
free(sounds); //Then free the sound array.
}

// delete opengl buffers
if ( allsurfaces != NULL )
{
Expand Down
55 changes: 55 additions & 0 deletions src/init_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,43 @@ int initGame()
}
}

// load sound effects
printlog("loading sounds...\n");
fp = openDataFile("sound/sounds.txt", "r");
for ( numsounds = 0; !feof(fp); numsounds++ )
{
while ( fgetc(fp) != '\n' ) if ( feof(fp) )
{
break;
}
}
if ( numsounds == 0 )
{
printlog("failed to identify any sounds in sounds.txt\n");
fclose(fp);
return 10;
}
sounds = (Sound**) malloc(sizeof(Sound*)*numsounds);
rewind(fp);
for ( c = 0; !feof(fp); c++ )
{
fscanf(fp, "%s", name);
while ( fgetc(fp) != '\n' )
if ( feof(fp) )
break;
sounds[c] = createSound(name);
if (!sounds[c])
{
printlog("warning: failed to load sound '%s' at line %d in sounds.txt", name, c+1);
}
//TODO: set sound volume? Or otherwise handle sound volume.
}
fclose(fp);
ChannelGroup_SetVolume(sound_group, sfxvolume / 128.0);
// set 3d settings?
//FMOD_System_Set3DSettings(fmod_system, 1.0, 2.0, 1.0);


// load music
#ifdef SOUND

Expand Down Expand Up @@ -660,6 +697,24 @@ void deinitGame()
list_FreeAll(&safePacketsReceived[c]);
}
#ifdef SOUND
// free sounds
printlog("freeing sounds...\n");
if ( sounds != NULL )
{
for ( c = 0; c < numsounds; c++ )
{
if (sounds[c] != NULL)
{
if (sounds[c] != NULL)
{
Sound_Release(sounds[c]); //Free the sound's FMOD sound.
}
//free(sounds[c]); //Then free the sound itself.
}
}
free(sounds); //Then free the sound array.
}

Channel_Stop(music_channel);
Channel_Stop(music_channel2);
Sound_Release(intromusic);
Expand Down
15 changes: 8 additions & 7 deletions src/sound_null.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "sound.hpp"

Channel *playSoundPlayer(int, Uint32, int) {return NULL;}
Channel *playSoundPos(real_t, real_t, Uint32) {return NULL;}
Channel* playSoundPosLocal(real_t x, real_t y, Uint32 snd, int vol) {return NULL;}
Channel* playSoundEntity(Entity* entity, Uint32 snd, int vol) {return NULL;}
Channel* playSoundEntityLocal(Entity* entity, Uint32 snd, int vol) {return NULL;}
Channel* playSound(Uint32 snd, int vol) {return NULL;}
Channel* playSoundVelocity() {return NULL;}
Uint32 numsounds = 0;
Sound** sounds = NULL;
ChannelGroup *sound_group = NULL;
bool levelmusicplaying;
Sound* CreateMusic(const char* name) {return NULL;}
void playmusic(Sound* sound, bool loop, bool crossfade, bool resume) {}
unsigned int Channel_GetPosition(Channel*) {return 0;}
void ChannelGroup_Stop(ChannelGroup*) {}
bool Channel_IsPlaying(Channel*) {return false;}
void Channel_Stop(Channel*) {}
unsigned int Sound_GetLength(Sound*) {return 0;}
void sound_update() {}
void ChannelGroup_SetVolume(ChannelGroup*, float) {}
void initSound() {}
void deinitSound() {}
Expand Down

0 comments on commit 662bed6

Please sign in to comment.