chunksize arg, cleanups

This commit is contained in:
p.kosyh 2011-03-30 07:28:26 +00:00
parent df30104d88
commit df07d0668b
8 changed files with 42 additions and 8 deletions

2
debian/changelog vendored
View file

@ -3,9 +3,11 @@ instead (1.3.5) unstable; urgency=low
* bug fix in imgl/imgr;
* bug fix in xact;
* bug fix in jump to pos logic;
* bug fix lags in sound;
* global dir is now readdir;
* multichannal sound system (add_sound, stop_sound);
* -appdata parameter;
* -chunksize parameter;
* show dir to be deleted while remove game;
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 29 Mar 2011 14:08:00 +0300

View file

@ -78,6 +78,12 @@ Install game from zip archive
.B -quit
Quit :)
.TP
.B -appdata [fullpath]
Store saves and settings in appdata path. Path must exist!
.TP
.B -chunksize [size in bytes]
Size for audio buffer. Try this if sound lags.
.TP
.B -version
Show version and exit.
.PP

View file

@ -11,6 +11,7 @@
#define KBD_MAX 3
extern char *appdata_sw;
extern int chunksize_sw;
extern int opt_fsize;
extern int opt_fs;

View file

@ -1381,9 +1381,11 @@ static int _play_combined_snd(char *filename, int chan, int loop)
p = strip(p);
while (*p) {
int c = chan, l = loop;
int at = 0;
ep = p + strcspn(p, ";@");
if (*ep == '@') {
at = 1;
*ep = 0; ep ++;
sscanf(ep, "%d,%d", &c, &l);
ep += strcspn(ep, ";");
@ -1400,7 +1402,7 @@ static int _play_combined_snd(char *filename, int chan, int loop)
w = sound_add(p);
if (w)
snd_play(w, c, l - 1);
else
else if (at || c != -1) /* if @ or specific channel */
snd_halt_chan(c, 500);
p = ep;
}

View file

@ -22,6 +22,7 @@ int nostdgames_sw = 0;
int nostdthemes_sw = 0;
int version_sw = 0;
int nopause_sw = 0;
int chunksize_sw = 0;
char *game_sw = NULL;
char *games_sw = NULL;
char *theme_sw = NULL;
@ -153,11 +154,18 @@ int main(int argc, char *argv[])
theme_sw = "";
} else if (!strcmp(argv[i], "-nostdgames")) {
nostdgames_sw = 1;
#ifdef _LOCAL_APPDATA
} else if (!strcmp(argv[i], "-appdata")) {
if ((i + 1) < argc)
appdata_sw = argv[++i];
else
appdata_sw = "";
#endif
} else if (!strcmp(argv[i], "-chunksize")) {
if ((i + 1) < argc)
chunksize_sw = atoi(argv[++i]);
else
chunksize_sw = DEFAULT_CHUNKSIZE;
} else if (!strcmp(argv[i], "-gamespath")) {
if ((i + 1) < argc)
games_sw = argv[++i];

View file

@ -77,6 +77,7 @@ void snd_pause(int on)
int snd_init(int hz)
{
int chunk;
if (nosound_sw)
return -1;
if (!hz)
@ -84,10 +85,10 @@ int snd_init(int hz)
else
audio_rate = hz;
audio_buffers = (audio_rate / 11025) * 4096;
if (!audio_buffers) /* wrong parameter? */
audio_buffers = 8192;
chunk = (chunksize_sw>0)?chunksize_sw:DEFAULT_CHUNKSIZE;
audio_buffers = (audio_rate / 11025) * chunk;
if (audio_buffers <=0) /* wrong parameter? */
audio_buffers = DEFAULT_CHUNKSIZE;
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Unable to init audio!\n");
return -1;

View file

@ -4,6 +4,12 @@
typedef void* wav_t;
typedef struct _mus_t *mus_t;
#ifdef _WIN32
#define DEFAULT_CHUNKSIZE 1024
#else
#define DEFAULT_CHUNKSIZE 2048
#endif
//extern mus_t snd_load_mus(const char *path);
extern void snd_free_mus(mus_t mus);
extern int snd_init(int hz);

View file

@ -1778,8 +1778,8 @@ end
function gamefile(file, forget)
stead.clearargs()
if forget then
set_music();
set_sound();
stead.stop_music();
stead.stop_sound();
timer:stop();
if type(variables) == 'table' then
local k,v
@ -2029,6 +2029,7 @@ iface = {
local cmd;
RAW_TEXT = nil
PLAYER_MOVED = nil
stead.set_sound(); -- empty sound
cmd,a = stead.getcmd(inp);
if cmd == '' then cmd = 'look' end
-- me():tag();
@ -2573,7 +2574,6 @@ end
function restore_music(s)
set_music(s.__old_music__, s.__old_loop__);
end
function dec_music_loop()
if game._music_loop == 0 then
return 0
@ -2593,10 +2593,12 @@ function set_music(s, count)
game._music_loop = tonumber(count);
end
end
stead.set_music = set_music
function stop_music()
set_music(nil, -1);
end
stead.stop_music = stop_music
function is_music()
return game._music ~= nil and game._music_loop ~= -1
@ -2626,14 +2628,17 @@ end
function get_sound()
return game._sound, game._sound_channel, game._sound_loop;
end
stead.get_sound = get_sound
function get_sound_chan()
return game._sound_channel
end
stead.get_sound_chan = get_sound_chan
function get_sound_loop()
return game._sound_loop
end
stead.get_sound_loop = get_sound_loop
function stop_sound(chan)
if not tonumber(chan) then
@ -2642,6 +2647,7 @@ function stop_sound(chan)
end
set_sound('@'..tostring(chan));
end
stead.stop_sound = stop_sound
function add_sound(s, chan, loop)
if type(s) ~= 'string' then
@ -2659,6 +2665,7 @@ function add_sound(s, chan, loop)
set_sound(s, chan, loop);
end
end
stead.add_sound = add_sound
function set_sound(s, chan, loop)
game._sound = s;
@ -2674,6 +2681,7 @@ function set_sound(s, chan, loop)
game._sound_channel = tonumber(chan);
end
end
stead.set_sound = set_sound
function change_pl(p)
local o = ref(p);