From: Holger Schemel Date: Sat, 24 Aug 2002 20:57:01 +0000 (+0200) Subject: rnd-20020824-2-src X-Git-Tag: 3.0.0^2~258 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=87f531efe267aa3d6a27cc3a68c68c1a4df7b18b;p=rocksndiamonds.git rnd-20020824-2-src --- diff --git a/src/conftime.h b/src/conftime.h index 6ad4d766..ca2edc0d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-08-24 13:38]" +#define COMPILE_DATE_STRING "[2002-08-24 22:54]" diff --git a/src/init.c b/src/init.c index ccf0ef13..38aec9ae 100644 --- a/src/init.c +++ b/src/init.c @@ -416,6 +416,11 @@ void ReloadCustomArtwork() static boolean last_override_level_sounds = FALSE; static boolean last_override_level_music = FALSE; + /* identifier for new artwork; default: artwork configured in setup */ + char *gfx_new_identifier = artwork.gfx_current->identifier; + char *snd_new_identifier = artwork.snd_current->identifier; + char *mus_new_identifier = artwork.mus_current->identifier; + #if 0 printf("graphics --> '%s' ('%s')\n", artwork.gfx_current_identifier, artwork.gfx_current->filename); @@ -425,19 +430,27 @@ void ReloadCustomArtwork() artwork.mus_current_identifier, artwork.mus_current->filename); #endif + /* leveldir_current may be invalid (level group, parent link) */ + if (!validLevelSeries(leveldir_current)) + return; + +#if 0 + printf("--> '%s'\n", artwork.gfx_current_identifier); +#endif + + /* when a new level series was selected, check if there was a change + in custom artwork stored in level series directory */ if (leveldir_current_identifier != leveldir_current->identifier) { char *identifier_old = leveldir_current_identifier; char *identifier_new = leveldir_current->identifier; - /* force reload of custom artwork after new level series was selected, - but reload only that part of the artwork that really has changed */ if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) != getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new)) - artwork.gfx_current_identifier = NULL; + gfx_new_identifier = identifier_new; if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) != getTreeInfoFromIdentifier(artwork.snd_first, identifier_new)) - artwork.snd_current_identifier = NULL; + snd_new_identifier = identifier_new; if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) != getTreeInfoFromIdentifier(artwork.mus_first, identifier_new)) artwork.mus_current_identifier = NULL; @@ -445,7 +458,39 @@ void ReloadCustomArtwork() leveldir_current_identifier = leveldir_current->identifier; } - if (artwork.gfx_current_identifier != artwork.gfx_current->identifier || + /* custom level artwork configured in level series configuration file + always overrides custom level artwork stored in level series directory + and (level independant) custom artwork configured in setup menue + (the path entry is needed to send it to the sound child process) */ + if (leveldir_current->graphics_set != NULL) + { + if (leveldir_current->graphics_path) + free(leveldir_current->graphics_path); + leveldir_current->graphics_path = NULL; + leveldir_current->graphics_path = + getStringCopy(getLevelArtworkDir(artwork.gfx_first)); + gfx_new_identifier = leveldir_current->graphics_set; + } + if (leveldir_current->sounds_set != NULL) + { + if (leveldir_current->sounds_path) + free(leveldir_current->sounds_path); + leveldir_current->sounds_path = NULL; + leveldir_current->sounds_path = + getStringCopy(getLevelArtworkDir(artwork.snd_first)); + snd_new_identifier = leveldir_current->sounds_set; + } + if (leveldir_current->music_set != NULL) + { + if (leveldir_current->music_path) + free(leveldir_current->music_path); + leveldir_current->music_path = NULL; + leveldir_current->music_path = + getStringCopy(getLevelArtworkDir(artwork.mus_first)); + mus_new_identifier = leveldir_current->music_set; + } + + if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 || last_override_level_graphics != setup.override_level_graphics) { int i; @@ -466,27 +511,31 @@ void ReloadCustomArtwork() SetDoorState(DOOR_OPEN_ALL); CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY); - artwork.gfx_current_identifier = artwork.gfx_current->identifier; + artwork.gfx_current_identifier = gfx_new_identifier; last_override_level_graphics = setup.override_level_graphics; } - if (artwork.snd_current_identifier != artwork.snd_current->identifier || + if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 || last_override_level_sounds != setup.override_level_sounds) { - InitReloadSounds(artwork.snd_current->identifier); + InitReloadSounds(snd_new_identifier); - artwork.snd_current_identifier = artwork.snd_current->identifier; + artwork.snd_current_identifier = snd_new_identifier; last_override_level_sounds = setup.override_level_sounds; } - if (artwork.mus_current_identifier != artwork.mus_current->identifier || + if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 || last_override_level_music != setup.override_level_music) { - InitReloadMusic(artwork.mus_current->identifier); + InitReloadMusic(mus_new_identifier); - artwork.mus_current_identifier = artwork.mus_current->identifier; + artwork.mus_current_identifier = mus_new_identifier; last_override_level_music = setup.override_level_music; } + +#if 0 + printf("<-- '%s'\n", artwork.gfx_current_identifier); +#endif } void InitGadgets() diff --git a/src/libgame/setup.c b/src/libgame/setup.c index add159b9..e69e5926 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -297,6 +297,49 @@ static char *getUserMusicDir() return usermusic_dir; } +static char *getSetupArtworkDir(TreeInfo *ti) +{ + static char *artwork_dir = NULL; + + if (artwork_dir != NULL) + free(artwork_dir); + + artwork_dir = getPath2(ti->basepath, ti->fullpath); + + return artwork_dir; +} + +char *getLevelArtworkDir(TreeInfo *ti) +{ + char *artwork_path, *artwork_set; + + if (ti == NULL || leveldir_current == NULL) + return NOT_AVAILABLE; + + artwork_path = + (ti->type == TREE_TYPE_GRAPHICS_DIR ? leveldir_current->graphics_path : + ti->type == TREE_TYPE_SOUNDS_DIR ? leveldir_current->sounds_path : + ti->type == TREE_TYPE_MUSIC_DIR ? leveldir_current->music_path : NULL); + + if (artwork_path != NULL) + return artwork_path; + + artwork_set = + (ti->type == TREE_TYPE_GRAPHICS_DIR ? leveldir_current->graphics_set : + ti->type == TREE_TYPE_SOUNDS_DIR ? leveldir_current->sounds_set : + ti->type == TREE_TYPE_MUSIC_DIR ? leveldir_current->music_set : NULL); + + if (artwork_set != NULL) + { + TreeInfo *level_artwork = getTreeInfoFromIdentifier(ti, artwork_set); + + if (level_artwork != NULL) + return getSetupArtworkDir(level_artwork); + } + + return NOT_AVAILABLE; +} + char *getLevelFilename(int nr) { static char *filename = NULL; @@ -351,18 +394,6 @@ char *getSetupFilename() return filename; } -static char *getSetupArtworkDir(TreeInfo *ti) -{ - static char *artwork_dir = NULL; - - if (artwork_dir != NULL) - free(artwork_dir); - - artwork_dir = getPath2(ti->basepath, ti->fullpath); - - return artwork_dir; -} - static char *getCorrectedImageBasename(char *basename) { char *result = basename; @@ -400,23 +431,28 @@ char *getCustomImageFilename(char *basename) if (!setup.override_level_graphics) { - /* 1st try: look for special artwork in current level series directory */ + /* 1st try: look for special artwork configured in level series config */ + filename = getPath2(getLevelArtworkDir(artwork.gfx_first), basename); + if (fileExists(filename)) + return filename; + + /* 2nd try: look for special artwork in current level series directory */ filename = getPath3(getCurrentLevelDir(), GRAPHICS_DIRECTORY, basename); if (fileExists(filename)) return filename; } - /* 2nd try: look for special artwork in configured artwork directory */ + /* 3rd try: look for special artwork in configured artwork directory */ filename = getPath2(getSetupArtworkDir(artwork.gfx_current), basename); if (fileExists(filename)) return filename; - /* 3rd try: look for default artwork in new default artwork directory */ + /* 4th try: look for default artwork in new default artwork directory */ filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename); if (fileExists(filename)) return filename; - /* 4th try: look for default artwork in old default artwork directory */ + /* 5th try: look for default artwork in old default artwork directory */ filename = getPath2(options.graphics_directory, basename); if (fileExists(filename)) return filename; @@ -433,23 +469,30 @@ char *getCustomSoundFilename(char *basename) if (!setup.override_level_sounds) { - /* 1st try: look for special artwork in current level series directory */ +#if 1 + /* 1st try: look for special artwork configured in level series config */ + filename = getPath2(getLevelArtworkDir(artwork.snd_first), basename); + if (fileExists(filename)) + return filename; +#endif + + /* 2nd try: look for special artwork in current level series directory */ filename = getPath3(getCurrentLevelDir(), SOUNDS_DIRECTORY, basename); if (fileExists(filename)) return filename; } - /* 2nd try: look for special artwork in configured artwork directory */ + /* 3rd try: look for special artwork in configured artwork directory */ filename = getPath2(getSetupArtworkDir(artwork.snd_current), basename); if (fileExists(filename)) return filename; - /* 3rd try: look for default artwork in new default artwork directory */ + /* 4th try: look for default artwork in new default artwork directory */ filename = getPath2(getDefaultSoundsDir(SOUNDS_SUBDIR), basename); if (fileExists(filename)) return filename; - /* 4th try: look for default artwork in old default artwork directory */ + /* 5th try: look for default artwork in old default artwork directory */ filename = getPath2(options.sounds_directory, basename); if (fileExists(filename)) return filename; @@ -471,23 +514,35 @@ char *getCustomMusicDirectory(void) if (!setup.override_level_music) { - /* 1st try: look for special artwork in current level series directory */ +#if 1 + /* 1st try: look for special artwork configured in level series config */ + directory = getStringCopy(getLevelArtworkDir(artwork.mus_first)); + if (fileExists(directory)) + return directory; +#endif + + /* 2nd try: look for special artwork in current level series directory */ directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY); if (fileExists(directory)) return directory; } - /* 2nd try: look for special artwork in configured artwork directory */ + /* 3rd try: look for special artwork in configured artwork directory */ directory = getStringCopy(getSetupArtworkDir(artwork.mus_current)); + +#if 1 + printf("DEBUG: checking directory '%s' ...\n", directory); +#endif + if (fileExists(directory)) return directory; - /* 3rd try: look for default artwork in new default artwork directory */ + /* 4th try: look for default artwork in new default artwork directory */ directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR)); if (fileExists(directory)) return directory; - /* 4th try: look for default artwork in old default artwork directory */ + /* 5th try: look for default artwork in old default artwork directory */ directory = getStringCopy(options.music_directory); if (fileExists(directory)) return directory; @@ -1178,8 +1233,11 @@ void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, #define LEVELINFO_TOKEN_SORT_PRIORITY 7 #define LEVELINFO_TOKEN_LEVEL_GROUP 8 #define LEVELINFO_TOKEN_READONLY 9 +#define LEVELINFO_TOKEN_GRAPHICS_SET 10 +#define LEVELINFO_TOKEN_SOUNDS_SET 11 +#define LEVELINFO_TOKEN_MUSIC_SET 12 -#define NUM_LEVELINFO_TOKENS 10 +#define NUM_LEVELINFO_TOKENS 13 static LevelDirTree ldi; @@ -1195,7 +1253,10 @@ static struct TokenInfo levelinfo_tokens[] = { TYPE_INTEGER, &ldi.first_level, "first_level" }, { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, { TYPE_BOOLEAN, &ldi.level_group, "level_group" }, - { TYPE_BOOLEAN, &ldi.readonly, "readonly" } + { TYPE_BOOLEAN, &ldi.readonly, "readonly" }, + { TYPE_STRING, &ldi.graphics_set, "graphics_set" }, + { TYPE_STRING, &ldi.sounds_set, "sounds_set" }, + { TYPE_STRING, &ldi.music_set, "music_set" } }; static void setTreeInfoToDefaults(TreeInfo *ldi, int type) @@ -1232,6 +1293,12 @@ static void setTreeInfoToDefaults(TreeInfo *ldi, int type) if (ldi->type == TREE_TYPE_LEVEL_DIR) { ldi->imported_from = NULL; + ldi->graphics_set = NULL; + ldi->sounds_set = NULL; + ldi->music_set = NULL; + ldi->graphics_path = getStringCopy(NOT_AVAILABLE); + ldi->sounds_path = getStringCopy(NOT_AVAILABLE); + ldi->music_path = getStringCopy(NOT_AVAILABLE); ldi->levels = 0; ldi->first_level = 0; ldi->last_level = 0; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 3f61ab84..67f42611 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -171,6 +171,7 @@ struct TokenInfo ARTWORKCLASS_UNDEFINED) +char *getLevelArtworkDir(TreeInfo *); char *getLevelFilename(int); char *getTapeFilename(int); char *getScoreFilename(int); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index e98c42a2..a2427131 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -273,6 +273,12 @@ static boolean ForkAudioProcess(void) return FALSE; } +#if 0 + printf("PID: %d [%s]\n", getpid(), + (IS_CHILD_PROCESS(audio.mixer_pid) ? "child" : "parent")); + Delay(10000 * 0); +#endif + if (IS_CHILD_PROCESS(audio.mixer_pid)) Mixer_Main(); /* this function never returns */ else @@ -498,8 +504,10 @@ static void WriteReloadInfoToPipe(char *set_identifier, int type) TreeInfo *ti = (type == SND_CTRL_RELOAD_SOUNDS ? artwork.snd_current : artwork.mus_current); unsigned long str_size1 = strlen(leveldir_current->fullpath) + 1; - unsigned long str_size2 = strlen(ti->basepath) + 1; - unsigned long str_size3 = strlen(ti->fullpath) + 1; + unsigned long str_size2 = strlen(leveldir_current->sounds_path) + 1; + unsigned long str_size3 = strlen(leveldir_current->music_path) + 1; + unsigned long str_size4 = strlen(ti->basepath) + 1; + unsigned long str_size5 = strlen(ti->fullpath) + 1; boolean override_level_artwork = (type == SND_CTRL_RELOAD_SOUNDS ? setup.override_level_sounds : setup.override_level_music); @@ -530,12 +538,20 @@ static void WriteReloadInfoToPipe(char *set_identifier, int type) sizeof(unsigned long)) < 0 || write(audio.mixer_pipe[1], &str_size3, sizeof(unsigned long)) < 0 || + write(audio.mixer_pipe[1], &str_size4, + sizeof(unsigned long)) < 0 || + write(audio.mixer_pipe[1], &str_size5, + sizeof(unsigned long)) < 0 || write(audio.mixer_pipe[1], leveldir_current->fullpath, str_size1) < 0 || - write(audio.mixer_pipe[1], ti->basepath, + write(audio.mixer_pipe[1], leveldir_current->sounds_path, str_size2) < 0 || + write(audio.mixer_pipe[1], leveldir_current->music_path, + str_size3) < 0 || + write(audio.mixer_pipe[1], ti->basepath, + str_size4) < 0 || write(audio.mixer_pipe[1], ti->fullpath, - str_size3) < 0) + str_size5) < 0) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); audio.sound_available = audio.sound_enabled = FALSE; @@ -548,7 +564,7 @@ static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl) TreeInfo **ti_ptr = ((snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS) ? &artwork.snd_current : &artwork.mus_current); TreeInfo *ti = *ti_ptr; - unsigned long str_size1, str_size2, str_size3; + unsigned long str_size1, str_size2, str_size3, str_size4, str_size5; static char *set_identifier = NULL; boolean *override_level_artwork = (snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS ? &setup.override_level_sounds : @@ -561,10 +577,15 @@ static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl) if (leveldir_current == NULL) leveldir_current = checked_calloc(sizeof(TreeInfo)); + if (ti == NULL) ti = *ti_ptr = checked_calloc(sizeof(TreeInfo)); if (leveldir_current->fullpath != NULL) free(leveldir_current->fullpath); + if (leveldir_current->sounds_path != NULL) + free(leveldir_current->sounds_path); + if (leveldir_current->music_path != NULL) + free(leveldir_current->music_path); if (ti->basepath != NULL) free(ti->basepath); if (ti->fullpath != NULL) @@ -583,19 +604,29 @@ static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl) read(audio.mixer_pipe[0], &str_size2, sizeof(unsigned long)) != sizeof(unsigned long) || read(audio.mixer_pipe[0], &str_size3, + sizeof(unsigned long)) != sizeof(unsigned long) || + read(audio.mixer_pipe[0], &str_size4, + sizeof(unsigned long)) != sizeof(unsigned long) || + read(audio.mixer_pipe[0], &str_size5, sizeof(unsigned long)) != sizeof(unsigned long)) Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); leveldir_current->fullpath = checked_calloc(str_size1); - ti->basepath = checked_calloc(str_size2); - ti->fullpath = checked_calloc(str_size3); + leveldir_current->sounds_path = checked_calloc(str_size2); + leveldir_current->music_path = checked_calloc(str_size3); + ti->basepath = checked_calloc(str_size4); + ti->fullpath = checked_calloc(str_size5); if (read(audio.mixer_pipe[0], leveldir_current->fullpath, str_size1) != str_size1 || - read(audio.mixer_pipe[0], ti->basepath, + read(audio.mixer_pipe[0], leveldir_current->sounds_path, str_size2) != str_size2 || + read(audio.mixer_pipe[0], leveldir_current->music_path, + str_size3) != str_size3 || + read(audio.mixer_pipe[0], ti->basepath, + str_size4) != str_size4 || read(audio.mixer_pipe[0], ti->fullpath, - str_size3) != str_size3) + str_size5) != str_size5) Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); if (snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS) @@ -1861,7 +1892,9 @@ void LoadCustomMusic(void) strcmp(last_music_directory, music_directory) == 0) return; /* old and new music directory are the same */ - last_music_directory = music_directory; + if (last_music_directory != NULL) + free(last_music_directory); + last_music_directory = getStringCopy(music_directory); FreeAllMusic(); @@ -1881,6 +1914,10 @@ void LoadCustomMusic(void) char *filename = getPath2(music_directory, basename); MusicInfo *mus_info = NULL; +#if 0 + printf("DEBUG: loading music '%s' ...\n", basename); +#endif + if (draw_init_text) DrawInitText(basename, 150, FC_YELLOW); @@ -2135,7 +2172,7 @@ static void ReloadCustomSounds() int i; #if 0 - printf("DEBUG: reloading sounds '%s' ...\n",artwork.sounds_set_current_name); + printf("DEBUG: reloading sounds '%s' ...\n",artwork.snd_current_identifier); #endif LoadSoundsInfo(); @@ -2172,7 +2209,7 @@ static void ReloadCustomSounds() static void ReloadCustomMusic() { #if 0 - printf("DEBUG: reloading music '%s' ...\n", artwork.music_set_current_name); + printf("DEBUG: reloading music '%s' ...\n", artwork.mus_current_identifier); #endif #if 0 diff --git a/src/libgame/system.h b/src/libgame/system.h index 68a540b3..920e464c 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -386,6 +386,13 @@ struct TreeInfo char *author; /* level or artwork author name */ char *imported_from; /* optional comment for imported levels or artwork */ + char *graphics_set; /* optional custom graphics set (level tree only) */ + char *sounds_set; /* optional custom sounds set (level tree only) */ + char *music_set; /* optional custom music set (level tree only) */ + char *graphics_path; /* path to optional custom graphics set (level only) */ + char *sounds_path; /* path to optional custom sounds set (level only) */ + char *music_path; /* path to optional custom music set (level only) */ + int levels; /* number of levels in level series */ int first_level; /* first level number (to allow start with 0 or 1) */ int last_level; /* last level number (automatically calculated) */