projects
/
rocksndiamonds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
moved drawing cave tile for BD engine to separate function
[rocksndiamonds.git]
/
src
/
libgame
/
sound.c
diff --git
a/src/libgame/sound.c
b/src/libgame/sound.c
index 2375c06f98f57c4bdb0fb0e2f00435b665ad3b42..5f497c386c56c6dda9088ecfd87940cd3bcfd36c 100644
(file)
--- a/
src/libgame/sound.c
+++ b/
src/libgame/sound.c
@@
-48,10
+48,10
@@
#define SOUND_VOLUME_LEFT(x) (stereo_volume[x])
#define SOUND_VOLUME_RIGHT(x) (stereo_volume[SOUND_MAX_LEFT2RIGHT-x])
#define SOUND_VOLUME_LEFT(x) (stereo_volume[x])
#define SOUND_VOLUME_RIGHT(x) (stereo_volume[SOUND_MAX_LEFT2RIGHT-x])
-#define SAME_SOUND_NR(x,
y)
((x).nr == (y).nr)
-#define SAME_SOUND_DATA(x,
y)
((x).data_ptr == (y).data_ptr)
+#define SAME_SOUND_NR(x,
y)
((x).nr == (y).nr)
+#define SAME_SOUND_DATA(x,
y)
((x).data_ptr == (y).data_ptr)
-#define SOUND_VOLUME_FROM_PERCENT(v,
p)
((p) < 0 ? SOUND_MIN_VOLUME : \
+#define SOUND_VOLUME_FROM_PERCENT(v,
p)
((p) < 0 ? SOUND_MIN_VOLUME : \
(p) > 100 ? (v) : \
(p) * (v) / 100)
(p) > 100 ? (v) : \
(p) * (v) / 100)
@@
-59,7
+59,7
@@
#define SOUND_VOLUME_LOOPS(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops)
#define SOUND_VOLUME_MUSIC(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music)
#define SOUND_VOLUME_LOOPS(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops)
#define SOUND_VOLUME_MUSIC(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music)
-#define SETUP_SOUND_VOLUME(v,
s)
((s) & SND_CTRL_MUSIC ? \
+#define SETUP_SOUND_VOLUME(v,
s)
((s) & SND_CTRL_MUSIC ? \
SOUND_VOLUME_MUSIC(v) : \
(s) & SND_CTRL_LOOP ? \
SOUND_VOLUME_LOOPS(v) : \
SOUND_VOLUME_MUSIC(v) : \
(s) & SND_CTRL_LOOP ? \
SOUND_VOLUME_LOOPS(v) : \
@@
-141,6
+141,15
@@
static MusicInfo *getMusicInfoEntryFromMusicID(int);
// mixer functions
// ----------------------------------------------------------------------------
// mixer functions
// ----------------------------------------------------------------------------
+static void Mixer_ChannelFinished(int channel)
+{
+ if (!mixer[channel].active)
+ return;
+
+ mixer[channel].active = FALSE;
+ mixer_active_channels--;
+}
+
void Mixer_InitChannels(void)
{
int i;
void Mixer_InitChannels(void)
{
int i;
@@
-148,6
+157,8
@@
void Mixer_InitChannels(void)
for (i = 0; i < audio.num_channels; i++)
mixer[i].active = FALSE;
mixer_active_channels = 0;
for (i = 0; i < audio.num_channels; i++)
mixer[i].active = FALSE;
mixer_active_channels = 0;
+
+ Mix_ChannelFinished(Mixer_ChannelFinished);
}
static void Mixer_ResetChannelExpiration(int channel)
}
static void Mixer_ResetChannelExpiration(int channel)
@@
-166,8
+177,8
@@
static boolean Mixer_ChannelExpired(int channel)
if (expire_loop_sounds &&
IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) &&
if (expire_loop_sounds &&
IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) &&
- DelayReached(&mixer[channel].playing_starttime,
-
SOUND_LOOP_EXPIRATION_TIME
))
+ DelayReached
Ext2
(&mixer[channel].playing_starttime,
+
SOUND_LOOP_EXPIRATION_TIME, Counter()
))
return TRUE;
if (!Mix_Playing(channel))
return TRUE;
if (!Mix_Playing(channel))
@@
-233,7
+244,7
@@
static void Mixer_PlayMusicChannel(void)
Mix_VolumeMusic(mixer[audio.music_channel].volume);
Mix_FadeInMusic(mixer[audio.music_channel].data_ptr, loops, 100);
Mix_VolumeMusic(mixer[audio.music_channel].volume);
Mix_FadeInMusic(mixer[audio.music_channel].data_ptr, loops, 100);
-#if defined(PLATFORM_WIN
32
)
+#if defined(PLATFORM_WIN
DOWS
)
// playing MIDI music is broken since Windows Vista, as it sets the volume
// for MIDI music also for all other sounds and music, which cannot be set
// back to normal unless playing MIDI music again with that desired volume
// playing MIDI music is broken since Windows Vista, as it sets the volume
// for MIDI music also for all other sounds and music, which cannot be set
// back to normal unless playing MIDI music again with that desired volume
@@
-247,13
+258,7
@@
static void Mixer_PlayMusicChannel(void)
static void Mixer_StopChannel(int channel)
{
static void Mixer_StopChannel(int channel)
{
- if (!mixer[channel].active)
- return;
-
Mix_HaltChannel(channel);
Mix_HaltChannel(channel);
-
- mixer[channel].active = FALSE;
- mixer_active_channels--;
}
static void Mixer_StopMusicChannel(void)
}
static void Mixer_StopMusicChannel(void)
@@
-281,7
+286,7
@@
static void Mixer_FadeMusicChannel(void)
Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
-#if defined(PLATFORM_WIN
32
)
+#if defined(PLATFORM_WIN
DOWS
)
// playing MIDI music is broken since Windows Vista, as it sets the volume
// for MIDI music also for all other sounds and music, which cannot be set
// back to normal unless playing MIDI music again with that desired volume
// playing MIDI music is broken since Windows Vista, as it sets the volume
// for MIDI music also for all other sounds and music, which cannot be set
// back to normal unless playing MIDI music again with that desired volume
@@
-519,6
+524,17
@@
void StartMixer(void)
(int)sqrt((float)(SOUND_MAX_LEFT2RIGHT * SOUND_MAX_LEFT2RIGHT - i * i));
}
(int)sqrt((float)(SOUND_MAX_LEFT2RIGHT * SOUND_MAX_LEFT2RIGHT - i * i));
}
+boolean isSoundPlaying(int nr)
+{
+ int i;
+
+ for (i = audio.first_sound_channel; i < audio.num_channels; i++)
+ if (mixer[i].active && mixer[i].nr == nr)
+ return TRUE;
+
+ return FALSE;
+}
+
// THE STUFF ABOVE IS ONLY USED BY THE SOUND SERVER CHILD PROCESS
// ============================================================================
// THE STUFF ABOVE IS ONLY USED BY THE SOUND SERVER CHILD PROCESS
// ============================================================================
@@
-587,11
+603,19
@@
static void *Load_WAV_or_MOD(char *filename)
return NULL;
}
return NULL;
}
+static int compareMusicInfo(const void *object1, const void *object2)
+{
+ const MusicInfo *mi1 = *((MusicInfo **)object1);
+ const MusicInfo *mi2 = *((MusicInfo **)object2);
+
+ return strcmp(mi1->source_filename, mi2->source_filename);
+}
+
static void LoadCustomMusic_NoConf(void)
{
static boolean draw_init_text = TRUE; // only draw at startup
static char *last_music_directory = NULL;
static void LoadCustomMusic_NoConf(void)
{
static boolean draw_init_text = TRUE; // only draw at startup
static char *last_music_directory = NULL;
- char *music_directory = getCustomMusicDirectory();
+ char *music_directory = getCustomMusicDirectory
_NoConf
();
Directory *dir;
DirectoryEntry *dir_entry;
int num_music = getMusicListSize();
Directory *dir;
DirectoryEntry *dir_entry;
int num_music = getMusicListSize();
@@
-609,17
+633,21
@@
static void LoadCustomMusic_NoConf(void)
FreeAllMusic_NoConf();
FreeAllMusic_NoConf();
- if (
(dir = openDirectory(music_directory))
== NULL)
+ if (
music_directory
== NULL)
{
{
- Warn("cannot
read music directory '%s'", music_directory
);
+ Warn("cannot
find music directory with unconfigured music"
);
- audio.music_available = FALSE;
+ return;
+ }
+ else if ((dir = openDirectory(music_directory)) == NULL)
+ {
+ Warn("cannot read music directory '%s'", music_directory);
return;
}
if (draw_init_text)
return;
}
if (draw_init_text)
- DrawInitText
("Loading music", 120, FC_GREEN
);
+ DrawInitText
Head("Loading music"
);
while ((dir_entry = readDirectory(dir)) != NULL) // loop all entries
{
while ((dir_entry = readDirectory(dir)) != NULL) // loop all entries
{
@@
-644,7
+672,7
@@
static void LoadCustomMusic_NoConf(void)
continue;
if (draw_init_text)
continue;
if (draw_init_text)
- DrawInitText
(basename, 150, FC_YELLOW
);
+ DrawInitText
Item(basename
);
if (FileIsMusic(dir_entry->filename))
mus_info = Load_WAV_or_MOD(dir_entry->filename);
if (FileIsMusic(dir_entry->filename))
mus_info = Load_WAV_or_MOD(dir_entry->filename);
@@
-660,6
+688,9
@@
static void LoadCustomMusic_NoConf(void)
closeDirectory(dir);
closeDirectory(dir);
+ // sort music files by filename
+ qsort(Music_NoConf, num_music_noconf, sizeof(MusicInfo *), compareMusicInfo);
+
draw_init_text = FALSE;
}
draw_init_text = FALSE;
}
@@
-675,6
+706,11
@@
int getMusicListSize(void)
music_info->num_dynamic_file_list_entries);
}
music_info->num_dynamic_file_list_entries);
}
+int getMusicListSize_NoConf(void)
+{
+ return num_music_noconf;
+}
+
struct FileInfo *getSoundListEntry(int pos)
{
int num_sounds = getSoundListSize();
struct FileInfo *getSoundListEntry(int pos)
{
int num_sounds = getSoundListSize();
@@
-741,6
+777,16
@@
static MusicInfo *getMusicInfoEntryFromMusicID(int pos)
return mus_info[list_pos];
}
return mus_info[list_pos];
}
+char *getSoundInfoEntryFilename(int pos)
+{
+ SoundInfo *snd_info = getSoundInfoEntryFromSoundID(pos);
+
+ if (snd_info == NULL)
+ return NULL;
+
+ return getBaseNamePtr(snd_info->source_filename);
+}
+
char *getMusicInfoEntryFilename(int pos)
{
MusicInfo *mus_info = getMusicInfoEntryFromMusicID(pos);
char *getMusicInfoEntryFilename(int pos)
{
MusicInfo *mus_info = getMusicInfoEntryFromMusicID(pos);
@@
-1103,7
+1149,7
@@
static void ReloadCustomMusic(void)
LoadCustomMusic_NoConf();
}
LoadCustomMusic_NoConf();
}
-void InitReloadCustomSounds(
char *set_identifier
)
+void InitReloadCustomSounds(
void
)
{
if (!audio.sound_available)
return;
{
if (!audio.sound_available)
return;
@@
-1111,7
+1157,7
@@
void InitReloadCustomSounds(char *set_identifier)
ReloadCustomSounds();
}
ReloadCustomSounds();
}
-void InitReloadCustomMusic(
char *set_identifier
)
+void InitReloadCustomMusic(
void
)
{
if (!audio.music_available)
return;
{
if (!audio.music_available)
return;