This commit is contained in:
jsalmon3 2003-10-01 23:11:34 +00:00
parent cd36be16a1
commit 42b272f0d5
3 changed files with 286 additions and 278 deletions

View file

@ -76,6 +76,7 @@ local ccl_smob_type_t SiodSoundTag;
local SCM sound_id_ccl(SoundId id)
{
SCM sound_id;
sound_id = CclMakeSmobObj(SiodSoundTag, id);
return sound_id;
}
@ -91,8 +92,8 @@ local SCM CclSoundForName(SCM name)
SoundId id;
char* sound_name;
sound_name=gh_scm2newstr(name,NULL);
id=SoundIdForName(sound_name);
sound_name = gh_scm2newstr(name, NULL);
id = SoundIdForName(sound_name);
free(sound_name);
return sound_id_ccl(id);
@ -156,8 +157,8 @@ local SCM CclMakeSound(SCM name, SCM file)
c_name = gh_scm2newstr(name, NULL);
DebugLevel3("Making sound `%s'\n" _C_ c_name);
nb = gh_length(file);
c_files = (char **)malloc(sizeof(char *) * nb);
for (i = 0; i < nb; i++) {
c_files = (char**)malloc(sizeof(char*) * nb);
for (i = 0; i < nb; ++i) {
a_file = gh_car(file);
if (!gh_string_p(name)) {
fprintf(stderr, "string expected\n");
@ -170,7 +171,7 @@ local SCM CclMakeSound(SCM name, SCM file)
}
//FIXME: check size before casting
id = MakeSound(c_name, c_files, (unsigned char)nb);
for (i = 0; i < nb; i++) {
for (i = 0; i < nb; ++i) {
free(c_files[i]);
}
free(c_name);
@ -238,8 +239,8 @@ local SCM CclMapSound(SCM name, SCM sound)
local SCM CclPlaySound(SCM sound) {
SoundId id;
id=CclGetSoundId(sound);
PlayGameSound(id,MaxSampleVolume);
id = CclGetSoundId(sound);
PlayGameSound(id, MaxSampleVolume);
return SCM_UNSPECIFIED;
}
@ -289,94 +290,94 @@ local SCM CclDefineGameSounds(SCM list)
char* str;
int i;
while( !gh_null_p(list) ) {
while (!gh_null_p(list)) {
value=gh_car(list);
list=gh_cdr(list);
if( !gh_symbol_p(value) ) {
value = gh_car(list);
list = gh_cdr(list);
if (!gh_symbol_p(value)) {
PrintFunction();
fprintf(stdout,"Symbol expected\n");
fprintf(stdout, "Symbol expected\n");
return list;
}
// prepare for next iteration
// let's handle now the different cases
if( gh_eq_p(value,gh_symbol2scm("click")) ) {
data=gh_car(list);
list=gh_cdr(list);
if( !CCL_SOUNDP(data) ) {
fprintf(stderr,"Sound id expected\n");
if (gh_eq_p(value, gh_symbol2scm("click"))) {
data = gh_car(list);
list = gh_cdr(list);
if (!CCL_SOUNDP(data)) {
fprintf(stderr, "Sound id expected\n");
return list;
}
GameSounds.Click.Sound=CCL_SOUND_ID(data);
} else if( gh_eq_p(value,gh_symbol2scm("placement-error")) ) {
data=gh_car(list);
list=gh_cdr(list);
if( !CCL_SOUNDP(data) ) {
fprintf(stderr,"Sound id expected\n");
GameSounds.Click.Sound = CCL_SOUND_ID(data);
} else if (gh_eq_p(value, gh_symbol2scm("placement-error"))) {
data = gh_car(list);
list = gh_cdr(list);
if (!CCL_SOUNDP(data)) {
fprintf(stderr, "Sound id expected\n");
return list;
}
GameSounds.PlacementError.Sound=CCL_SOUND_ID(data);
} else if( gh_eq_p(value,gh_symbol2scm("placement-success")) ) {
data=gh_car(list);
list=gh_cdr(list);
if( !CCL_SOUNDP(data) ) {
fprintf(stderr,"Sound id expected\n");
GameSounds.PlacementError.Sound = CCL_SOUND_ID(data);
} else if (gh_eq_p(value, gh_symbol2scm("placement-success"))) {
data = gh_car(list);
list = gh_cdr(list);
if (!CCL_SOUNDP(data)) {
fprintf(stderr, "Sound id expected\n");
return list;
}
GameSounds.PlacementSuccess.Sound=CCL_SOUND_ID(data);
} else if( gh_eq_p(value,gh_symbol2scm("work-complete")) ) {
sublist=gh_car(list);
list=gh_cdr(list);
str=gh_scm2newstr(gh_car(sublist),NULL);
for( i=0; i<PlayerRaces.Count; ++i ) {
if( !strcmp(PlayerRaces.Name[i],str) ) {
GameSounds.PlacementSuccess.Sound = CCL_SOUND_ID(data);
} else if (gh_eq_p(value,gh_symbol2scm("work-complete"))) {
sublist = gh_car(list);
list = gh_cdr(list);
str = gh_scm2newstr(gh_car(sublist), NULL);
for (i = 0; i < PlayerRaces.Count; ++i) {
if (!strcmp(PlayerRaces.Name[i], str)) {
break;
}
}
free(str);
if( i==PlayerRaces.Count ) {
fprintf(stderr,"Unknown race: %s\n",str);
if (i == PlayerRaces.Count) {
fprintf(stderr, "Unknown race: %s\n", str);
ExitFatal(1);
}
sublist=gh_cdr(sublist);
data=gh_car(sublist);
if( !CCL_SOUNDP(data) ) {
fprintf(stderr,"Sound id expected\n");
sublist = gh_cdr(sublist);
data = gh_car(sublist);
if (!CCL_SOUNDP(data)) {
fprintf(stderr, "Sound id expected\n");
ExitFatal(1);
}
GameSounds.WorkComplete[i].Sound=CCL_SOUND_ID(data);
} else if( gh_eq_p(value,gh_symbol2scm("repair")) ) {
data=gh_car(list);
list=gh_cdr(list);
if( !CCL_SOUNDP(data) ) {
GameSounds.Repair.Sound=(void*)-1;
GameSounds.WorkComplete[i].Sound = CCL_SOUND_ID(data);
} else if (gh_eq_p(value,gh_symbol2scm("repair"))) {
data = gh_car(list);
list = gh_cdr(list);
if (!CCL_SOUNDP(data)) {
GameSounds.Repair.Sound = (void*)-1;
} else {
GameSounds.Repair.Sound=CCL_SOUND_ID(data);
GameSounds.Repair.Sound = CCL_SOUND_ID(data);
}
} else if( gh_eq_p(value,gh_symbol2scm("rescue")) ) {
sublist=gh_car(list);
list=gh_cdr(list);
str=gh_scm2newstr(gh_car(sublist),NULL);
for( i=0; i<PlayerRaces.Count; ++i ) {
if( !strcmp(PlayerRaces.Name[i],str) ) {
} else if (gh_eq_p(value,gh_symbol2scm("rescue"))) {
sublist = gh_car(list);
list = gh_cdr(list);
str = gh_scm2newstr(gh_car(sublist), NULL);
for (i = 0; i < PlayerRaces.Count; ++i) {
if (!strcmp(PlayerRaces.Name[i], str)) {
break;
}
}
free(str);
if( i==PlayerRaces.Count ) {
fprintf(stderr,"Unknown race: %s\n",str);
if (i == PlayerRaces.Count) {
fprintf(stderr, "Unknown race: %s\n", str);
ExitFatal(1);
}
sublist=gh_cdr(sublist);
data=gh_car(sublist);
if( !CCL_SOUNDP(data) ) {
fprintf(stderr,"Sound id expected\n");
sublist = gh_cdr(sublist);
data = gh_car(sublist);
if (!CCL_SOUNDP(data)) {
fprintf(stderr, "Sound id expected\n");
ExitFatal(1);
}
GameSounds.Rescue[i].Sound=CCL_SOUND_ID(data);
GameSounds.Rescue[i].Sound = CCL_SOUND_ID(data);
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
return list;
}
}
@ -415,17 +416,17 @@ local SCM CclSetCdMode(SCM mode)
#ifdef USE_CDAUDIO
CDModes cdmode;
if( gh_eq_p(mode,gh_symbol2scm("all")) ) {
cdmode=CDModeAll;
} else if( gh_eq_p(mode,gh_symbol2scm("random")) ) {
cdmode=CDModeRandom;
} else if( gh_eq_p(mode,gh_symbol2scm("defined")) ) {
cdmode=CDModeDefined;
} else if ( gh_eq_p(mode,gh_symbol2scm("off")) ) {
cdmode=CDModeOff;
if (gh_eq_p(mode, gh_symbol2scm("all"))) {
cdmode = CDModeAll;
} else if (gh_eq_p(mode, gh_symbol2scm("random"))) {
cdmode = CDModeRandom;
} else if (gh_eq_p(mode, gh_symbol2scm("defined"))) {
cdmode = CDModeDefined;
} else if (gh_eq_p(mode, gh_symbol2scm("off"))) {
cdmode = CDModeOff;
} else {
cdmode=CDModeOff;
errl("Unsupported tag",mode);
cdmode = CDModeOff;
errl("Unsupported tag", mode);
}
PlayCDRom(cdmode);
@ -440,102 +441,102 @@ local SCM CclDefinePlaySections(SCM list)
{
SCM value;
SCM sublist;
PlaySection *p;
PlaySection* p;
int i;
++NumPlaySections;
PlaySections=realloc(PlaySections,NumPlaySections*sizeof(PlaySection));
p=PlaySections+NumPlaySections-1;
memset(p,0,sizeof(PlaySection));
PlaySections = realloc(PlaySections, NumPlaySections * sizeof(PlaySection));
p = PlaySections + NumPlaySections - 1;
memset(p, 0, sizeof(PlaySection));
while( !gh_null_p(list) ) {
value=gh_car(list);
list=gh_cdr(list);
if( gh_eq_p(value,gh_symbol2scm("race")) ) {
value=gh_car(list);
list=gh_cdr(list);
p->Race=gh_scm2newstr(value,NULL);
} else if( gh_eq_p(value,gh_symbol2scm("type")) ) {
value=gh_car(list);
list=gh_cdr(list);
if( gh_eq_p(value, gh_symbol2scm("game")) ) {
p->Type=PlaySectionGame;
} else if( gh_eq_p(value,gh_symbol2scm("briefing")) ) {
p->Type=PlaySectionBriefing;
} else if( gh_eq_p(value,gh_symbol2scm("stats-victory")) ) {
p->Type=PlaySectionStatsVictory;
} else if( gh_eq_p(value,gh_symbol2scm("stats-defeat")) ) {
p->Type=PlaySectionStatsDefeat;
} else if( gh_eq_p(value,gh_symbol2scm("main-menu")) ) {
p->Type=PlaySectionMainMenu;
while (!gh_null_p(list)) {
value = gh_car(list);
list = gh_cdr(list);
if (gh_eq_p(value, gh_symbol2scm("race"))) {
value = gh_car(list);
list = gh_cdr(list);
p->Race = gh_scm2newstr(value, NULL);
} else if (gh_eq_p(value, gh_symbol2scm("type"))) {
value = gh_car(list);
list = gh_cdr(list);
if (gh_eq_p(value, gh_symbol2scm("game"))) {
p->Type = PlaySectionGame;
} else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
p->Type = PlaySectionBriefing;
} else if (gh_eq_p(value, gh_symbol2scm("stats-victory"))) {
p->Type = PlaySectionStatsVictory;
} else if (gh_eq_p(value, gh_symbol2scm("stats-defeat"))) {
p->Type = PlaySectionStatsDefeat;
} else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
p->Type = PlaySectionMainMenu;
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
} else if( gh_eq_p(value,gh_symbol2scm("cd")) ) {
sublist=gh_car(list);
list=gh_cdr(list);
while( !gh_null_p(sublist) ) {
value=gh_car(sublist);
sublist=gh_cdr(sublist);
if( gh_eq_p(value,gh_symbol2scm("order")) ) {
value=gh_car(sublist);
sublist=gh_cdr(sublist);
if( gh_eq_p(value,gh_symbol2scm("all")) ) {
p->CDOrder=PlaySectionOrderAll;
} else if( gh_eq_p(value,gh_symbol2scm("random")) ) {
p->CDOrder=PlaySectionOrderRandom;
} else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
sublist = gh_car(list);
list = gh_cdr(list);
while (!gh_null_p(sublist)) {
value = gh_car(sublist);
sublist = gh_cdr(sublist);
if (gh_eq_p(value, gh_symbol2scm("order"))) {
value = gh_car(sublist);
sublist = gh_cdr(sublist);
if (gh_eq_p(value, gh_symbol2scm("all"))) {
p->CDOrder = PlaySectionOrderAll;
} else if (gh_eq_p(value, gh_symbol2scm("random"))) {
p->CDOrder = PlaySectionOrderRandom;
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
} else if( gh_eq_p(value,gh_symbol2scm("tracks")) ) {
} else if (gh_eq_p(value, gh_symbol2scm("tracks"))) {
SCM temp;
value=gh_car(sublist);
sublist=gh_cdr(sublist);
for( i=0; i<gh_vector_length(value); ++i ) {
temp=gh_vector_ref(value,gh_int2scm(i));
p->CDTracks|=(1<<gh_scm2int(temp));
value = gh_car(sublist);
sublist = gh_cdr(sublist);
for (i = 0; i < gh_vector_length(value); ++i) {
temp=gh_vector_ref(value, gh_int2scm(i));
p->CDTracks |= (1 << gh_scm2int(temp));
}
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
}
} else if( gh_eq_p(value,gh_symbol2scm("no-cd")) ) {
sublist=gh_car(list);
list=gh_cdr(list);
while( !gh_null_p(sublist) ) {
value=gh_car(sublist);
sublist=gh_cdr(sublist);
if( gh_eq_p(value,gh_symbol2scm("order")) ) {
value=gh_car(sublist);
sublist=gh_cdr(sublist);
if( gh_eq_p(value,gh_symbol2scm("all")) ) {
p->FileOrder=PlaySectionOrderAll;
} else if( gh_eq_p(value,gh_symbol2scm("random")) ) {
p->FileOrder=PlaySectionOrderRandom;
} else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
sublist = gh_car(list);
list = gh_cdr(list);
while (!gh_null_p(sublist)) {
value = gh_car(sublist);
sublist = gh_cdr(sublist);
if (gh_eq_p(value, gh_symbol2scm("order"))) {
value = gh_car(sublist);
sublist = gh_cdr(sublist);
if (gh_eq_p(value, gh_symbol2scm("all"))) {
p->FileOrder = PlaySectionOrderAll;
} else if (gh_eq_p(value, gh_symbol2scm("random"))) {
p->FileOrder = PlaySectionOrderRandom;
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
} else if( gh_eq_p(value,gh_symbol2scm("files")) ) {
} else if (gh_eq_p(value, gh_symbol2scm("files"))) {
SCM sublist2;
sublist2=gh_car(sublist);
sublist=gh_cdr(sublist);
i=0;
while( !gh_null_p(sublist2) ) {
value=gh_car(sublist2);
sublist2=gh_cdr(sublist2);
sublist2 = gh_car(sublist);
sublist = gh_cdr(sublist);
i = 0;
while (!gh_null_p(sublist2)) {
value = gh_car(sublist2);
sublist2 = gh_cdr(sublist2);
++i;
p->Files=realloc(p->Files,(i+1)*sizeof(char*));
p->Files[i-1]=gh_scm2newstr(value,NULL);
p->Files[i]=NULL;
p->Files = realloc(p->Files, (i + 1) * sizeof(char*));
p->Files[i - 1] = gh_scm2newstr(value, NULL);
p->Files[i] = NULL;
}
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
}
} else {
errl("Unsupported tag",value);
errl("Unsupported tag", value);
}
}
@ -547,7 +548,7 @@ local SCM CclDefinePlaySections(SCM list)
*/
local SCM CclSoundOff(void)
{
SoundOff=1;
SoundOff = 1;
return SCM_UNSPECIFIED;
}
@ -562,7 +563,7 @@ local SCM CclSoundOn(void)
if (SoundFildes != -1) {
return SCM_BOOL_T;
}
SoundOff=0;
SoundOff = 0;
return SCM_BOOL_F;
}
@ -572,7 +573,7 @@ local SCM CclSoundOn(void)
local SCM CclMusicOff(void)
{
StopMusic();
MusicOff=1;
MusicOff = 1;
return SCM_UNSPECIFIED;
}
@ -584,7 +585,7 @@ local SCM CclMusicOff(void)
*/
local SCM CclMusicOn(void)
{
MusicOff=0;
MusicOff = 0;
return SCM_UNSPECIFIED;
}
@ -595,10 +596,11 @@ local SCM CclMusicOn(void)
*/
local SCM CclSetGlobalSoundRange(SCM distance) {
int d;
//FIXME check for errors
d=gh_scm2int(distance);
if (d>0) {
DistanceSilent=d;
d = gh_scm2int(distance);
if (d > 0) {
DistanceSilent = d;
}
return distance;
}
@ -609,7 +611,7 @@ local SCM CclSetGlobalSoundRange(SCM distance) {
local SCM CclSoundThread(void)
{
#ifdef USE_THREAD
WithSoundThread=1;
WithSoundThread = 1;
#endif
return SCM_UNSPECIFIED;
}
@ -620,23 +622,23 @@ local SCM CclSoundThread(void)
** @param sound the sound id or name of the sound
** @param range the new range for this sound
*/
local SCM CclSetSoundRange(SCM sound,SCM range) {
local SCM CclSetSoundRange(SCM sound, SCM range) {
//FIXME check for errors
unsigned char TheRange;
unsigned char theRange;
int tmp;
SoundId id;
tmp=gh_scm2int(range);
if(tmp<0) {
TheRange=0;
} else if (tmp>255) {
TheRange=255;
tmp = gh_scm2int(range);
if (tmp < 0) {
theRange = 0;
} else if (tmp > 255) {
theRange = 255;
} else {
TheRange=(unsigned char)tmp;
theRange = (unsigned char)tmp;
}
DebugLevel3("Range: %u (%d)\n" _C_ TheRange _C_ tmp);
id=CclGetSoundId(sound);
SetSoundRange(id,TheRange);
id = CclGetSoundId(sound);
SetSoundRange(id, theRange);
return sound;
}
@ -649,7 +651,7 @@ local SCM CclPlayMusic(SCM name)
{
char* music_name;
music_name=gh_scm2newstr(name,NULL);
music_name = gh_scm2newstr(name, NULL);
PlayMusic(music_name);
free(music_name);
@ -665,7 +667,7 @@ local SCM CclPlayFile(SCM name)
{
char* filename;
filename=gh_scm2newstr(name,NULL);
filename = gh_scm2newstr(name, NULL);
PlayFile(filename);
free(filename);
@ -689,30 +691,30 @@ global void SoundCclRegister(void)
{
SiodSoundTag = CclMakeSmobType("Sound");
gh_new_procedure1_0("set-sound-volume!",CclSetSoundVolume);
gh_new_procedure1_0("set-music-volume!",CclSetMusicVolume);
gh_new_procedure1_0("set-cd-mode!",CclSetCdMode);
gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
gh_new_procedureN("define-play-sections",CclDefinePlaySections);
gh_new_procedureN("define-play-sections", CclDefinePlaySections);
gh_new_procedure0_0("sound-off",CclSoundOff);
gh_new_procedure0_0("sound-on",CclSoundOn);
gh_new_procedure0_0("music-off",CclMusicOff);
gh_new_procedure0_0("music-on",CclMusicOn);
gh_new_procedure0_0("sound-thread",CclSoundThread);
gh_new_procedure1_0("set-global-sound-range!",CclSetGlobalSoundRange);
gh_new_procedureN("define-game-sounds",CclDefineGameSounds);
gh_new_procedure0_0("display-sounds",CclDisplaySounds);
gh_new_procedure2_0("map-sound",CclMapSound);
gh_new_procedure1_0("sound-for-name",CclSoundForName);
gh_new_procedure2_0("set-sound-range!",CclSetSoundRange);
gh_new_procedure2_0("make-sound",CclMakeSound);
gh_new_procedure3_0("make-sound-group",CclMakeSoundGroup);
gh_new_procedure1_0("play-sound",CclPlaySound);
gh_new_procedure0_0("sound-off", CclSoundOff);
gh_new_procedure0_0("sound-on", CclSoundOn);
gh_new_procedure0_0("music-off", CclMusicOff);
gh_new_procedure0_0("music-on", CclMusicOn);
gh_new_procedure0_0("sound-thread", CclSoundThread);
gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
gh_new_procedure0_0("display-sounds", CclDisplaySounds);
gh_new_procedure2_0("map-sound", CclMapSound);
gh_new_procedure1_0("sound-for-name", CclSoundForName);
gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
gh_new_procedure2_0("make-sound", CclMakeSound);
gh_new_procedure3_0("make-sound-group", CclMakeSoundGroup);
gh_new_procedure1_0("play-sound", CclPlaySound);
gh_new_procedure1_0("play-music",CclPlayMusic);
gh_new_procedure1_0("play-file",CclPlayFile);
gh_new_procedure0_0("stop-music",CclStopMusic);
gh_new_procedure1_0("play-music", CclPlayMusic);
gh_new_procedure1_0("play-file", CclPlayFile);
gh_new_procedure0_0("stop-music", CclStopMusic);
}
#else // }{ WITH_SOUND
@ -803,7 +805,7 @@ local SCM CclSetGlobalSoundRange(SCM distance)
** @param sound the sound id or name of the sound
** @param range the new range for this sound
*/
local SCM CclSetSoundRange(SCM sound,SCM range __attribute__((unused)))
local SCM CclSetSoundRange(SCM sound, SCM range __attribute__((unused)))
{
return sound;
}
@ -852,7 +854,7 @@ local SCM CclDefineGameSounds(SCM list __attribute__((unused)))
**
** @return the sound object
*/
local SCM CclMapSound(SCM name __attribute__((unused)),SCM sound)
local SCM CclMapSound(SCM name __attribute__((unused)), SCM sound)
{
return sound;
}
@ -882,23 +884,23 @@ local SCM CclPlayFile(SCM name __attribute__((unused)))
*/
global void SoundCclRegister(void)
{
gh_new_procedure1_0("set-sound-volume!",CclSetSoundVolume);
gh_new_procedure1_0("set-music-volume!",CclSetMusicVolume);
gh_new_procedure1_0("set-cd-mode!",CclSetCdMode);
gh_new_procedure0_0("sound-off",CclSoundOff);
gh_new_procedure0_0("sound-on",CclSoundOn);
gh_new_procedure0_0("music-off",CclMusicOff);
gh_new_procedure0_0("music-on",CclMusicOn);
gh_new_procedure0_0("sound-thread",CclSoundThread);
gh_new_procedure1_0("set-global-sound-range!",CclSetGlobalSoundRange);
gh_new_procedureN("define-game-sounds",CclDefineGameSounds);
gh_new_procedure0_0("display-sounds",CclDisplaySounds);
gh_new_procedure2_0("map-sound",CclMapSound);
gh_new_procedure1_0("sound-for-name",CclSoundForName);
gh_new_procedure2_0("set-sound-range!",CclSetSoundRange);
gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
gh_new_procedure0_0("sound-off", CclSoundOff);
gh_new_procedure0_0("sound-on", CclSoundOn);
gh_new_procedure0_0("music-off", CclMusicOff);
gh_new_procedure0_0("music-on", CclMusicOn);
gh_new_procedure0_0("sound-thread", CclSoundThread);
gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
gh_new_procedure0_0("display-sounds", CclDisplaySounds);
gh_new_procedure2_0("map-sound", CclMapSound);
gh_new_procedure1_0("sound-for-name", CclSoundForName);
gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
gh_new_procedure1_0("play-music",CclPlayMusic);
gh_new_procedure1_0("play-file",CclPlayFile);
gh_new_procedure1_0("play-music", CclPlayMusic);
gh_new_procedure1_0("play-file", CclPlayFile);
}
#endif // } !WITH_SOUND

View file

@ -62,8 +62,8 @@
** sound identifier.
*/
typedef struct _simple_sound_ {
char *Name; /// name of the sound
char *File; /// corresponding sound file
char* Name; /// name of the sound
char* File; /// corresponding sound file
} SimpleSound;
/**
@ -139,8 +139,8 @@ local int NbSoundsInGroup(char* const* const group)
{
int i;
for(i=0;i<MaxSimpleGroups;i++) {
if ( !group[i] ) {
for (i = 0;i < MaxSimpleGroups; ++i) {
if (!group[i]) {
return i;
}
}
@ -155,9 +155,9 @@ local void LoadSimpleSounds(void)
{
int i;
if( SimpleSounds ) {
for(i=0;SimpleSounds[i].Name;i++) {
MakeSound(SimpleSounds[i].Name,&(SimpleSounds[i].File),1);
if (SimpleSounds) {
for (i = 0; SimpleSounds[i].Name; ++i) {
MakeSound(SimpleSounds[i].Name, &(SimpleSounds[i].File), 1);
}
}
}
@ -170,18 +170,18 @@ local void LoadSoundGroups(void)
{
int i;
if( SoundGroups ) {
for(i=0;SoundGroups[i].Name;i++) {
MakeSound(SoundGroups[i].Name,SoundGroups[i].Sounds,
NbSoundsInGroup(SoundGroups[i].Sounds));
if (SoundGroups) {
for (i = 0; SoundGroups[i].Name; ++i) {
MakeSound(SoundGroups[i].Name, SoundGroups[i].Sounds,
NbSoundsInGroup(SoundGroups[i].Sounds));
}
}
if( SelectionGroups ) {
for(i=0;SelectionGroups[i].Name;i++) {
if (SelectionGroups) {
for (i = 0; SelectionGroups[i].Name; ++i) {
//FIXME: might be more efficient
MakeSoundGroup(SelectionGroups[i].Name,
SoundIdForName(SelectionGroups[i].First),
SoundIdForName(SelectionGroups[i].Second));
SoundIdForName(SelectionGroups[i].First),
SoundIdForName(SelectionGroups[i].Second));
}
}
}
@ -194,11 +194,11 @@ local void RemapSounds(void)
{
int i;
if( SoundRemaps ) {
for(i=0;SoundRemaps[i].NewName;i++) {
if (SoundRemaps) {
for (i = 0; SoundRemaps[i].NewName; ++i) {
//FIXME: should be more efficient
MapSound(SoundRemaps[i].NewName,
SoundIdForName(SoundRemaps[i].BaseName));
SoundIdForName(SoundRemaps[i].BaseName));
}
}
@ -206,33 +206,33 @@ local void RemapSounds(void)
// Make some general sounds.
//
// FIXME: move to config CCL
MapSound("gold-mine-help",SoundIdForName("basic orc voices help 1"));
MapSound("gold-mine-help", SoundIdForName("basic orc voices help 1"));
// critter mapping FIXME: must support more terrains.
switch( TheMap.Terrain ) {
case TilesetSummer:
MakeSoundGroup("critter-selected",
SoundIdForName("sheep selected"),
SoundIdForName("sheep annoyed"));
break;
case TilesetWinter:
MakeSoundGroup("critter-selected",
SoundIdForName("seal selected"),
SoundIdForName("seal annoyed"));
break;
case TilesetWasteland:
MakeSoundGroup("critter-selected",
SoundIdForName("pig selected"),
SoundIdForName("pig annoyed"));
break;
case TilesetSwamp:
MakeSoundGroup("critter-selected",
SoundIdForName("warthog selected"),
SoundIdForName("warthog annoyed"));
break;
default:
DebugLevel2("Unknown Terrain %d\n" _C_ TheMap.Terrain);
switch (TheMap.Terrain) {
case TilesetSummer:
MakeSoundGroup("critter-selected",
SoundIdForName("sheep selected"),
SoundIdForName("sheep annoyed"));
break;
case TilesetWinter:
MakeSoundGroup("critter-selected",
SoundIdForName("seal selected"),
SoundIdForName("seal annoyed"));
break;
case TilesetWasteland:
MakeSoundGroup("critter-selected",
SoundIdForName("pig selected"),
SoundIdForName("pig annoyed"));
break;
case TilesetSwamp:
MakeSoundGroup("critter-selected",
SoundIdForName("warthog selected"),
SoundIdForName("warthog annoyed"));
break;
default:
DebugLevel2("Unknown Terrain %d\n" _C_ TheMap.Terrain);
}
}
@ -241,7 +241,7 @@ local void RemapSounds(void)
*/
global void LoadUnitSounds(void)
{
if( SoundFildes!=-1 ) {
if (SoundFildes != -1) {
LoadSimpleSounds();
LoadSoundGroups();
RemapSounds();
@ -258,49 +258,49 @@ global void MapUnitSounds(void)
UnitType* type;
int i;
if( SoundFildes!=-1 ) {
SetSoundRange(SoundIdForName("tree chopping"),32);
if (SoundFildes != -1) {
SetSoundRange(SoundIdForName("tree chopping"), 32);
//
// Parse all units sounds.
//
for( i=0; i<NumUnitTypes; ++i ) {
for (i = 0; i < NumUnitTypes; ++i) {
type = UnitTypes[i];
if( type->Sound.Selected.Name ) {
type->Sound.Selected.Sound=
SoundIdForName(type->Sound.Selected.Name);
if (type->Sound.Selected.Name) {
type->Sound.Selected.Sound =
SoundIdForName(type->Sound.Selected.Name);
}
if( type->Sound.Acknowledgement.Name ) {
type->Sound.Acknowledgement.Sound=
SoundIdForName(type->Sound.Acknowledgement.Name);
if (type->Sound.Acknowledgement.Name) {
type->Sound.Acknowledgement.Sound =
SoundIdForName(type->Sound.Acknowledgement.Name);
/*
// Acknowledge sounds have infinite range
SetSoundRange(type->Sound.Acknowledgement.Sound,
INFINITE_SOUND_RANGE);
INFINITE_SOUND_RANGE);
*/
}
if( type->Sound.Ready.Name ) {
type->Sound.Ready.Sound=
if (type->Sound.Ready.Name) {
type->Sound.Ready.Sound =
SoundIdForName(type->Sound.Ready.Name);
// Ready sounds have infinite range
SetSoundRange(type->Sound.Ready.Sound,
INFINITE_SOUND_RANGE);
INFINITE_SOUND_RANGE);
}
// FIXME: will be modified, attack sound be moved to missile/weapon
if( type->Weapon.Attack.Name ) {
type->Weapon.Attack.Sound=
SoundIdForName(type->Weapon.Attack.Name);
if (type->Weapon.Attack.Name) {
type->Weapon.Attack.Sound =
SoundIdForName(type->Weapon.Attack.Name);
}
if( type->Sound.Help.Name ) {
type->Sound.Help.Sound=
SoundIdForName(type->Sound.Help.Name);
if (type->Sound.Help.Name) {
type->Sound.Help.Sound =
SoundIdForName(type->Sound.Help.Name);
// Help sounds have infinite range
SetSoundRange(type->Sound.Help.Sound,
INFINITE_SOUND_RANGE);
INFINITE_SOUND_RANGE);
}
if( type->Sound.Dead.Name ) {
type->Sound.Dead.Sound=
SoundIdForName(type->Sound.Dead.Name);
if (type->Sound.Dead.Name) {
type->Sound.Dead.Sound =
SoundIdForName(type->Sound.Dead.Name);
}
}
}

View file

@ -66,7 +66,7 @@ typedef struct _wav_data_ {
-- Functions
----------------------------------------------------------------------------*/
local int WavReadStream(Sample *sample, void *buf, int len)
local int WavReadStream(Sample* sample, void* buf, int len)
{
WavData* data;
char sndbuf[WAV_BUFFER_SIZE];
@ -78,7 +78,7 @@ local int WavReadStream(Sample *sample, void *buf, int len)
int samplesize; // number of bytes per sample
int divide;
data = (WavData*) sample->User;
data = (WavData*)sample->User;
if (data->PointerInBuffer - sample->Data + len > sample->Length) {
// need to read new data
@ -92,7 +92,7 @@ local int WavReadStream(Sample *sample, void *buf, int len)
samplesize = sample->SampleSize / 8;
brratio = 4 / (samplesize * sample->Channels);
chanratio = 2 / sample->Channels;
divide = freqratio*brratio/chanratio;
divide = freqratio * brratio / chanratio;
comp = CLread(data->WavFile, sndbuf, unc/divide);
@ -111,11 +111,13 @@ local int WavReadStream(Sample *sample, void *buf, int len)
return len;
}
local void WavFreeStream(Sample *sample)
local void WavFreeStream(Sample* sample)
{
WavData* data;
IfDebug( AllocatedSoundMemory -= sizeof(*sample) + WAV_BUFFER_SIZE);
#ifdef DEBUG
AllocatedSoundMemory -= sizeof(*sample) + WAV_BUFFER_SIZE;
#endif
data = (WavData*)sample->User;
@ -276,12 +278,14 @@ global Sample* LoadWav(const char* name, int flags __attribute__((unused)))
CLread(f, &chunk, sizeof(chunk));
DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + WAV_BUFFER_SIZE);
IfDebug( AllocatedSoundMemory += sizeof(*sample) + WAV_BUFFER_SIZE);
#ifdef DEBUG
AllocatedSoundMemory += sizeof(*sample) + WAV_BUFFER_SIZE;
#endif
} else {
for (;;) {
if ((i = CLread(f, &chunk, sizeof(chunk))) != sizeof(chunk)) {
// FIXME: have 1 byte remaining, wrong wav or wrong code?
// if( i ) printf("Rest: %d\n",i);
// if (i) { printf("Rest: %d\n", i); }
break;
}
chunk.Magic = ConvertLE32(chunk.Magic);
@ -316,7 +320,9 @@ global Sample* LoadWav(const char* name, int flags __attribute__((unused)))
CLclose(f);
IfDebug( AllocatedSoundMemory += sample->Length; );
#ifdef DEBUG
AllocatedSoundMemory += sample->Length;
#endif
}
return sample;