[Moeng-cvs] BBRpg/src rpg.cpp,1.6,1.7 script.cpp,1.12,1.13 sound.cpp,1.6,1.7 sound.h,1.4,1.5
Status: Alpha
Brought to you by:
b_lindeijer
From: <b_l...@us...> - 2004-01-03 21:56:26
|
Update of /cvsroot/moeng/BBRpg/src In directory sc8-pr-cvs1:/tmp/cvs-serv23984/src Modified Files: rpg.cpp script.cpp sound.cpp sound.h Log Message: Now samples can always be played even if alogg is not available. Index: rpg.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/rpg.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** rpg.cpp 3 Jan 2004 00:16:32 -0000 1.6 --- rpg.cpp 3 Jan 2004 21:56:19 -0000 1.7 *************** *** 27,31 **** END_OF_FUNCTION(handle_fps_counter); ! #ifdef ENABLE_SOUND int sound_counter = 0; #endif --- 27,31 ---- END_OF_FUNCTION(handle_fps_counter); ! #ifdef ENABLE_MUSIC int sound_counter = 0; #endif *************** *** 108,114 **** bVSync = get_config_int("Video", "VSync", 0); ! #ifdef ENABLE_SOUND sound_enabled = (get_config_int("Sound", "EnableMusic", 1)) ? 1 : 0; ! #endif // Screen initialisation --- 108,115 ---- bVSync = get_config_int("Video", "VSync", 0); ! #ifdef ENABLE_MUSIC sound_enabled = (get_config_int("Sound", "EnableMusic", 1)) ? 1 : 0; ! #endif ! sfx_enabled = (get_config_int("Sound", "EnableSfx", 1)) ? 1 : 0; // Screen initialisation *************** *** 173,182 **** initScripting(); ! #ifdef ENABLE_SOUND ! if (sound_enabled) { console.log(CON_LOG, CON_ALWAYS, "Initialising sound..."); init_sound(); } - #endif console.log(CON_LOG, CON_ALWAYS, "Installing timers..."); --- 174,181 ---- initScripting(); ! if (sound_enabled || sfx_enabled) { console.log(CON_LOG, CON_ALWAYS, "Initialising sound..."); init_sound(); } console.log(CON_LOG, CON_ALWAYS, "Installing timers..."); *************** *** 246,250 **** console.update(); ! #ifdef ENABLE_SOUND if (sound_enabled && sound_counter == 0) { poll_sound(); --- 245,249 ---- console.update(); ! #ifdef ENABLE_MUSIC if (sound_enabled && sound_counter == 0) { poll_sound(); *************** *** 252,256 **** } sound_counter--; ! #endif } --- 251,255 ---- } sound_counter--; ! #endif } *************** *** 310,319 **** unload_datafile(bitmap_data); ! #ifdef ENABLE_SOUND ! if (sound_enabled) { console.log(CON_LOG, CON_ALWAYS, "Deinitializing sound..."); exit_sound(); } - #endif console.log(CON_LOG, CON_ALWAYS, "Destroying screen buffer..."); --- 309,316 ---- unload_datafile(bitmap_data); ! if (sound_enabled || sfx_enabled) { console.log(CON_LOG, CON_ALWAYS, "Deinitializing sound..."); exit_sound(); } console.log(CON_LOG, CON_ALWAYS, "Destroying screen buffer..."); Index: script.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/script.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** script.cpp 2 Jan 2004 00:03:01 -0000 1.12 --- script.cpp 3 Jan 2004 21:56:19 -0000 1.13 *************** *** 169,185 **** lua_register(L, "m_make_noise", l_make_noise); ! #ifdef ENABLE_SOUND 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); ! lua_register(L, "m_play_sample", l_play_sample); ! #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); lua_register(L, "m_get_number_of_channels", l_dummy); ! lua_register(L, "m_play_sample", l_dummy); ! #endif lua_register(L, "m_quit_game", l_quit_game); --- 169,184 ---- lua_register(L, "m_make_noise", l_make_noise); ! 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); lua_register(L, "m_get_number_of_channels", l_dummy); ! #endif lua_register(L, "m_quit_game", l_quit_game); Index: sound.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sound.cpp 3 Jan 2004 16:31:15 -0000 1.6 --- sound.cpp 3 Jan 2004 21:56:19 -0000 1.7 *************** *** 10,19 **** */ - #ifdef ENABLE_SOUND - #define ALOGG_DLL #include <allegro.h> - #include <alogg/alogg.h> #include "shared/console.h" #include "sound.h" --- 10,16 ---- *************** *** 22,28 **** #include "common.h" ! int sound_enabled = 1; // Currently playing OGG file struct { --- 19,31 ---- #include "common.h" ! #ifdef ENABLE_MUSIC ! #include <alogg/alogg.h> ! #endif ! + int sound_enabled = 1; + int sfx_enabled = 1; + #ifdef ENABLE_MUSIC // Currently playing OGG file struct { *************** *** 33,36 **** --- 36,40 ---- char filename[128]; } channels[CHANNELS]; + #endif char *error; *************** *** 47,51 **** --- 51,57 ---- // Initialize alogg + #ifdef ENABLE_MUSIC alogg_init(); + #endif // Install sound driver *************** *** 55,58 **** --- 61,65 ---- } + #ifdef ENABLE_MUSIC // Initialize channels to NULL for (int i = 0; i < CHANNELS; i++) { *************** *** 62,68 **** --- 69,78 ---- channels[i].ass = NULL; } + #endif } + #ifdef ENABLE_MUSIC + /* play_music(filename, channel) */ *************** *** 161,188 **** ! /* play_sample(filename) ! */ ! int l_play_sample(lua_State *L) { ! char* name; ! getLuaArguments(L, "s", &name); ! ! if (sound_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, 255, 128, 1000, 0); ! } else { ! return luaL_error(L, "Error: Cannot find requested sample (%s)!", name); } } - - return 0; } - void stop_music(int channel) { --- 171,195 ---- ! 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; ! } } } } void stop_music(int channel) { *************** *** 221,247 **** } ! 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; ! } } } } void exit_sound() { for (int i = 0; i < CHANNELS; i++) { stop_music(i); --- 228,260 ---- } ! #endif ! ! ! /* play_sample(filename) ! */ ! int l_play_sample(lua_State *L) { ! char* name; ! getLuaArguments(L, "s", &name); ! ! 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, 255, 128, 1000, 0); ! } else { ! return luaL_error(L, "Error: Cannot find requested sample (%s)!", name); } } + + return 0; } void exit_sound() { + #ifdef ENABLE_MUSIC for (int i = 0; i < CHANNELS; i++) { stop_music(i); *************** *** 249,253 **** alogg_exit(); } - - #endif // #ifdef ENABLE_SOUND --- 262,265 ---- alogg_exit(); + #endif } Index: sound.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sound.h 2 Jan 2004 00:03:01 -0000 1.4 --- sound.h 3 Jan 2004 21:56:19 -0000 1.5 *************** *** 13,23 **** #define _INCLUDED_SOUND_H_ - #ifdef ENABLE_SOUND - #include <allegro.h> - #include <alogg/alogg.h> #include "script.h" extern int sound_enabled; //#define DATASZ (1 << 15) /* (32768) amount of data to read from disk each time */ --- 13,26 ---- #define _INCLUDED_SOUND_H_ #include <allegro.h> #include "script.h" + #ifdef ENABLE_MUSIC + #include <alogg/alogg.h> + #endif + + extern int sound_enabled; + extern int sfx_enabled; //#define DATASZ (1 << 15) /* (32768) amount of data to read from disk each time */ *************** *** 27,43 **** void init_sound(); ! void poll_sound(); ! void play_music(const char *filename); ! void stop_music(int channel); void exit_sound(); ! ! int l_play_sample(lua_State *L); int l_play_music(lua_State *L); int l_stop_music(lua_State *L); int l_adjust_channel(lua_State *L); ! int l_get_number_of_channels(lua_State *L); - #endif // #ifdef ENABLE_SOUND #endif // #ifndef _INCLUDED_SOUND_H_ --- 30,46 ---- void init_sound(); ! int l_play_sample(lua_State *L); 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); ! #endif #endif // #ifndef _INCLUDED_SOUND_H_ |