sound looping

This commit is contained in:
p.kosyh 2009-11-11 20:16:26 +00:00
parent 14d36f312c
commit 9adc1222ac
4 changed files with 25 additions and 8 deletions

View file

@ -1105,6 +1105,7 @@ void game_sound_player(void)
wav_t w;
char *snd;
int chan = -1;
int loop = 1;
if (!snd_volume_mus(-1))
return;
@ -1113,6 +1114,12 @@ void game_sound_player(void)
chan = atoi(snd);
free(snd);
}
snd = instead_eval("return get_sound_loop()");
if (snd) {
loop = atoi(snd);
free(snd);
}
snd = instead_eval("return get_sound()");
if (!snd) {
@ -1135,7 +1142,7 @@ void game_sound_player(void)
free(snd);
if (!w)
return;
snd_play(w, chan);
snd_play(w, chan, loop - 1);
}
char *horiz_inv(char *invstr)
@ -1658,7 +1665,7 @@ int game_click(int x, int y, int action, int filter)
if (mouse_filter(filter))
return 0;
if (opt_click)
snd_play(game_theme.click, -1);
snd_play(game_theme.click, -1, 0);
game_cmd(buf);
return 1;
@ -1681,7 +1688,7 @@ int game_click(int x, int y, int action, int filter)
disable_use();
if (opt_click)
snd_play(game_theme.click, -1);
snd_play(game_theme.click, -1, 0);
game_cmd(buf);
return 1;

View file

@ -188,7 +188,7 @@ void snd_free_mus(mus_t mus)
Mix_FreeMusic((Mix_Music*) mus);
}
void snd_play(void *chunk, int channel)
void snd_play(void *chunk, int channel, int loop)
{
if (!sound_on)
return;
@ -198,7 +198,7 @@ void snd_play(void *chunk, int channel)
channel %= MIX_CHANNELS;
if (channel < 0)
channel = -1;
Mix_PlayChannel(channel, (Mix_Chunk*)chunk, 0);
Mix_PlayChannel(channel, (Mix_Chunk*)chunk, loop);
}
void snd_done(void)

View file

@ -16,7 +16,7 @@ typedef void* mus_t;
extern void snd_free_mus(mus_t mus);
extern int snd_init(int hz);
extern int snd_hz(void);
extern void snd_play(wav_t chunk, int channel);
extern void snd_play(wav_t chunk, int channel, int loop);
extern void snd_halt_chan(int han);
extern void snd_free_wav(wav_t chunk);

View file

@ -2067,8 +2067,18 @@ function get_sound_chan()
return game._sound_channel
end
function set_sound(s, chan)
game._sound = s;
function get_sound_loop()
return game._sound_loop
end
function set_sound(s, chan, loop)
game._sound = s;
if not tonumber(loop) then
game._sound_loop = 1;
else
game._sound_loop = tonumber(loop);
end
if not tonumber(chan) then
game._sound_channel = -1;
else