[Moeng-cvs] BBRpg/src rpg.cpp,1.8,1.9 script.cpp,1.13,1.14 sound.cpp,1.8,1.9 sound.h,1.6,1.7
Status: Alpha
Brought to you by:
b_lindeijer
From: <b_l...@us...> - 2004-01-13 16:32:39
|
Update of /cvsroot/moeng/BBRpg/src In directory sc8-pr-cvs1:/tmp/cvs-serv20640/src Modified Files: rpg.cpp script.cpp sound.cpp sound.h Log Message: Merged bbrpg branch. Index: rpg.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/rpg.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** rpg.cpp 3 Jan 2004 22:41:02 -0000 1.8 --- rpg.cpp 13 Jan 2004 16:32:35 -0000 1.9 *************** *** 108,115 **** bVSync = get_config_int("Video", "VSync", 0); ! sound_enabled = (get_config_int("Sound", "EnableMusic", 1)) ? 1 : 0; ! sfx_enabled = (get_config_int("Sound", "EnableSfx", 1)) ? 1 : 0; music_vol = get_config_int("Sound", "MusicVolume", 255); sfx_vol = get_config_int("Sound", "SfxVolume", 255); // Screen initialisation --- 108,117 ---- bVSync = get_config_int("Video", "VSync", 0); ! sound_enabled = (get_config_int("Sound", "MusicEnabled", 1)) ? 1 : 0; ! sfx_enabled = (get_config_int("Sound", "SfxEnabled", 1)) ? 1 : 0; music_vol = get_config_int("Sound", "MusicVolume", 255); sfx_vol = get_config_int("Sound", "SfxVolume", 255); + music_format = (strcmp(get_config_string("Sound", "MusicFormat", "MIDI"), "MIDI") == 0) ? MUSIC_MIDI : MUSIC_OGG; + console.enableLogfile = (get_config_int("Engine", "LogEnabled", 1)); // Screen initialisation *************** *** 170,177 **** } - // Lua initialisation - console.log(CON_LOG, CON_ALWAYS, "Initialising Lua scripting environment..."); - initScripting(); - if (sound_enabled || sfx_enabled) { console.log(CON_LOG, CON_ALWAYS, "Initialising sound..."); --- 172,175 ---- *************** *** 179,182 **** --- 177,184 ---- } + // Lua initialisation + console.log(CON_LOG, CON_ALWAYS, "Initialising Lua scripting environment..."); + initScripting(); + console.log(CON_LOG, CON_ALWAYS, "Installing timers..."); LOCK_VARIABLE(frames_to_do); // Game speed handler Index: script.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/script.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** script.cpp 3 Jan 2004 21:56:19 -0000 1.13 --- script.cpp 13 Jan 2004 16:32:35 -0000 1.14 *************** *** 170,180 **** lua_register(L, "m_play_sample", l_play_sample); - #ifdef ENABLE_MUSIC lua_register(L, "m_play_music", l_play_music); lua_register(L, "m_stop_music", l_stop_music); lua_register(L, "m_adjust_channel", l_adjust_channel); lua_register(L, "m_get_number_of_channels", l_get_number_of_channels); #else - lua_register(L, "m_play_music", l_dummy); lua_register(L, "m_stop_music", l_dummy); lua_register(L, "m_adjust_channel", l_dummy); --- 170,179 ---- lua_register(L, "m_play_sample", l_play_sample); lua_register(L, "m_play_music", l_play_music); + #ifdef ENABLE_MUSIC lua_register(L, "m_stop_music", l_stop_music); lua_register(L, "m_adjust_channel", l_adjust_channel); lua_register(L, "m_get_number_of_channels", l_get_number_of_channels); #else lua_register(L, "m_stop_music", l_dummy); lua_register(L, "m_adjust_channel", l_dummy); Index: sound.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** sound.cpp 3 Jan 2004 22:41:02 -0000 1.8 --- sound.cpp 13 Jan 2004 16:32:35 -0000 1.9 *************** *** 28,34 **** int sfx_vol = 255; int music_vol = 255; - #ifdef ENABLE_MUSIC // Currently playing OGG file struct { --- 28,34 ---- int sfx_vol = 255; int music_vol = 255; + int music_format = 0; // Currently playing OGG file struct { *************** *** 39,43 **** char filename[128]; } channels[CHANNELS]; - #endif char *error; --- 39,42 ---- *************** *** 46,63 **** void init_sound() { - // Read config variables - //ChunkSize = (get_config_int("Sound", "StreamChunkSize", 1<<15)); - //BufferSize = (get_config_int("Sound", "BufferSize", 1<<16)); - // To achieve the max possible volume set_volume_per_voice(0); // Initialize alogg #ifdef ENABLE_MUSIC ! alogg_init(); #endif // Install sound driver ! if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0) { console.log(CON_LOG, CON_ALWAYS, "Error initialising sound system: %s", allegro_error); return; --- 45,68 ---- void init_sound() { // To achieve the max possible volume set_volume_per_voice(0); // Initialize alogg + + int midi_driver = MIDI_NONE; + int sound_driver = DIGI_NONE; + + if (music_format == MUSIC_MIDI) { + midi_driver = MIDI_AUTODETECT; + } + if (sfx_enabled || (sound_enabled && music_format != MUSIC_MIDI)) { #ifdef ENABLE_MUSIC ! alogg_init(); #endif + sound_driver = DIGI_AUTODETECT; + } // Install sound driver ! if (install_sound(sound_driver, midi_driver, NULL) != 0) { console.log(CON_LOG, CON_ALWAYS, "Error initialising sound system: %s", allegro_error); return; *************** *** 76,80 **** - #ifdef ENABLE_MUSIC /* play_music(filename, channel) --- 81,84 ---- *************** *** 88,111 **** error = NULL; ! if (sound_enabled) { ! // Stop currently playing music ! stop_music(channel); ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! else if (!exists(filename)) {error = "file does not exist";} ! ! if (error == NULL) { ! /* ! channels[channel].sample = alogg_load_ogg(filename); ! if (!channels[channel].sample) { ! fprintf(stderr,"Error loading %s (%d)\n", filename, alogg_error_code); ! alogg_exit(); ! exit(1); } ! */ strncpy(channels[channel].filename, filename, 128); channels[channel].stream = alogg_start_streaming(channels[channel].filename, BLOCK_SIZE); if (!channels[channel].stream) { ! fprintf(stderr,"Error opening %s\n", filename); alogg_exit(); exit(1); --- 92,119 ---- error = NULL; ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! if (sound_enabled && error == NULL) { ! if (music_format == MUSIC_MIDI) { ! replace_extension(channels[channel].filename, get_filename(filename), "mid", 128); ! ! DATAFILE *found_object = find_datafile_object(bitmap_data, channels[channel].filename); ! if (found_object) { ! play_looped_midi((MIDI*)found_object->dat, 0, -1); ! } else { ! console.log(CON_QUIT, CON_ALWAYS, "Could not find MIDI file in datafile (%s)", channels[channel].filename); } ! } else { ! #ifdef ENABLE_MUSIC ! // Stop currently playing music ! stop_music(channel); ! ! if (!exists(filename)) {error = "file does not exist";} ! strncpy(channels[channel].filename, filename, 128); + channels[channel].stream = alogg_start_streaming(channels[channel].filename, BLOCK_SIZE); if (!channels[channel].stream) { ! fprintf(stderr,"Error opening %s\n", channels[channel].filename); alogg_exit(); exit(1); *************** *** 113,142 **** channels[channel].ass = alogg_get_audio_stream(channels[channel].stream); voice_set_volume(channels[channel].ass->voice, music_vol); ! } ! ! /* ! channels[channel].voice = allocate_voice(channels[channel].sample); ! if (channels[channel].voice == -1) { ! error = "unable to allocate a voice"; ! } ! */ ! ! if (error == NULL) { ! /* ! voice_start(channels[channel].voice); ! release_voice(channels[channel].voice); ! channels[channel].voice = 0; ! channels[channel].sample = NULL; ! */ ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Playing OGG file (%s)", filename); ! } ! else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error playing OGG file \"%s\" (%s)", filename, error); } } ! return 0; } /* adjust_channel(channel, volume, panning, speed) */ --- 121,141 ---- channels[channel].ass = alogg_get_audio_stream(channels[channel].stream); voice_set_volume(channels[channel].ass->voice, music_vol); ! #endif } } ! ! if (error == NULL) { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Playing music file (%s)", filename); ! } ! else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error playing music file \"%s\" (%s)", filename, error); ! } ! return 0; } + + #ifdef ENABLE_MUSIC + /* adjust_channel(channel, volume, panning, speed) */ *************** *** 148,152 **** error = NULL; ! if (sound_enabled) { if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} else if (!channels[channel].ass) {error = "no music on this channel to adjust";} --- 147,151 ---- error = NULL; ! if (sound_enabled && music_format != MUSIC_MIDI) { if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} else if (!channels[channel].ass) {error = "no music on this channel to adjust";} *************** *** 157,161 **** if (error == NULL) { voice_set_volume(channels[channel].ass->voice, int(vol * (float(music_vol) / 255.0f))); - //alogg_adjust_oggstream(ogg[channel]->s, vol, pan, speed); //console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Adjusted channel parameters (%d, %d, %d, %d)", channel, vol, pan, speed); } else { --- 156,159 ---- *************** *** 177,194 **** void poll_sound() { ! for (int i = 0; i < CHANNELS; i++) { ! if (channels[i].stream) { ! int ret = alogg_update_streaming(channels[i].stream); ! if (ret == 0) { ! // Loop song ! stop_music(i); ! channels[i].stream = alogg_start_streaming(channels[i].filename, BLOCK_SIZE); ! if (!channels[i].stream) { ! fprintf(stderr,"Error opening %s\n", channels[i].filename); ! alogg_exit(); ! exit(1); } - channels[i].ass = alogg_get_audio_stream(channels[i].stream); - break; } } --- 175,194 ---- void poll_sound() { ! if (music_format != MUSIC_MIDI) { ! for (int i = 0; i < CHANNELS; i++) { ! if (channels[i].stream) { ! int ret = alogg_update_streaming(channels[i].stream); ! if (ret == 0) { ! // Loop song ! stop_music(i); ! channels[i].stream = alogg_start_streaming(channels[i].filename, BLOCK_SIZE); ! if (!channels[i].stream) { ! fprintf(stderr,"Error opening %s\n", channels[i].filename); ! alogg_exit(); ! exit(1); ! } ! channels[i].ass = alogg_get_audio_stream(channels[i].stream); ! break; } } } *************** *** 206,210 **** } */ ! if (channels[channel].stream) { alogg_stop_streaming(channels[channel].stream); channels[channel].stream = NULL; --- 206,210 ---- } */ ! if (music_format != MUSIC_MIDI && channels[channel].stream) { alogg_stop_streaming(channels[channel].stream); channels[channel].stream = NULL; *************** *** 243,252 **** if (sfx_enabled) { - console.log(CON_LOG, CON_ALWAYS, "Trying to play sample: %s", name); - DATAFILE *found_object = find_datafile_object(bitmap_data, name); if (found_object) { ! //int play_sample(const SAMPLE *spl, int vol, int pan, int freq, int loop); play_sample((SAMPLE*)found_object->dat, sfx_vol, 128, 1000, 0); } else { --- 243,250 ---- if (sfx_enabled) { DATAFILE *found_object = find_datafile_object(bitmap_data, name); if (found_object) { ! console.log(CON_LOG, CON_ALWAYS, "Playing sample: %s", name); play_sample((SAMPLE*)found_object->dat, sfx_vol, 128, 1000, 0); } else { *************** *** 265,269 **** } ! alogg_exit(); #endif } --- 263,269 ---- } ! if (sound_enabled && music_format != MUSIC_MIDI) { ! alogg_exit(); ! } #endif } Index: sound.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sound.h 3 Jan 2004 22:41:02 -0000 1.6 --- sound.h 13 Jan 2004 16:32:35 -0000 1.7 *************** *** 25,31 **** extern int sfx_vol; extern int music_vol; - //#define DATASZ (1 << 15) /* (32768) amount of data to read from disk each time */ - //#define BUFSZ (1 << 16) /* (65536) size of audiostream buffer */ #define CHANNELS (1 << 1) /* (2) number of channels */ #define BLOCK_SIZE 40960 --- 25,34 ---- extern int sfx_vol; extern int music_vol; + extern int music_format; + + #define MUSIC_MIDI 0 + #define MUSIC_OGG 1 + #define CHANNELS (1 << 1) /* (2) number of channels */ #define BLOCK_SIZE 40960 *************** *** 35,44 **** void exit_sound(); - #ifdef ENABLE_MUSIC void play_music(const char *filename); void stop_music(int channel); void poll_sound(); int l_get_number_of_channels(lua_State *L); - int l_play_music(lua_State *L); int l_stop_music(lua_State *L); int l_adjust_channel(lua_State *L); --- 38,48 ---- void exit_sound(); void play_music(const char *filename); + int l_play_music(lua_State *L); + + #ifdef ENABLE_MUSIC void stop_music(int channel); void poll_sound(); int l_get_number_of_channels(lua_State *L); int l_stop_music(lua_State *L); int l_adjust_channel(lua_State *L); |