From bcb3453f710b95ec98b188b95574bea9ab336e96 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 2 Apr 2002 02:04:41 +0200 Subject: [PATCH] rnd-20020402-1-src --- src/init.c | 7 + src/libgame/misc.c | 34 ++++ src/libgame/misc.h | 4 + src/libgame/setup.c | 471 ++++++++++++++++++++++++++++++++++--------- src/libgame/setup.h | 27 +-- src/libgame/sound.c | 19 +- src/libgame/system.c | 4 +- src/libgame/system.h | 51 +++-- src/network.c | 4 +- src/screens.c | 40 ++-- src/timestamp.h | 2 +- 11 files changed, 502 insertions(+), 161 deletions(-) diff --git a/src/init.c b/src/init.c index e03d2ae2..fe585257 100644 --- a/src/init.c +++ b/src/init.c @@ -43,6 +43,7 @@ static char *image_filename[NUM_PICTURES] = static void InitSetup(void); static void InitPlayerInfo(void); static void InitLevelInfo(void); +static void InitArtworkInfo(void); static void InitNetworkServer(void); static void InitSound(void); static void InitGfx(void); @@ -82,6 +83,7 @@ void OpenAll(void) InitEventFilter(FilterMouseMotionEvents); + InitArtworkInfo(); InitGfx(); InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ @@ -121,6 +123,11 @@ void InitLevelInfo() LoadLevelSetup_SeriesInfo(); /* last played level info */ } +void InitArtworkInfo() +{ + LoadArtworkInfo(); +} + void InitNetworkServer() { #if defined(PLATFORM_UNIX) diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 6992ff23..6fe6949b 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1159,6 +1159,40 @@ char getCharFromKey(Key key) } +/* ========================================================================= */ +/* functions for checking filenames */ +/* ========================================================================= */ + +boolean FileIsGraphic(char *filename) +{ + if (strlen(filename) > 4 && + strcmp(&filename[strlen(filename) - 4], ".pcx") == 0) + return TRUE; + + return FALSE; +} + +boolean FileIsSound(char *filename) +{ + if (strlen(filename) > 4 && + strcmp(&filename[strlen(filename) - 4], ".wav") == 0) + return TRUE; + + return FALSE; +} + +boolean FileIsMusic(char *filename) +{ + if (strlen(filename) > 4 && + (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || + strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || + strncmp(filename, "mod.", 4) == 0 || + strncmp(filename, "MOD.", 4) == 0)) + return TRUE; + + return FALSE; +} + /* ========================================================================= */ /* functions only needed for non-Unix (non-command-line) systems */ /* ========================================================================= */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 6d8f0666..84a3f1b2 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -98,6 +98,10 @@ Key getKeyFromKeyName(char *); Key getKeyFromX11KeyName(char *); char getCharFromKey(Key); +boolean FileIsGraphic(char *); +boolean FileIsSound(char *); +boolean FileIsMusic(char *); + #if !defined(PLATFORM_UNIX) void initErrorFile(); FILE *openErrorFile(); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 9d4aed61..edfa4d35 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -27,6 +27,9 @@ #define SETUP_FILENAME "setup.conf" #define LEVELSETUP_FILENAME "levelsetup.conf" #define LEVELINFO_FILENAME "levelinfo.conf" +#define GRAPHICSINFO_FILENAME "graphicsinfo.conf" +#define SOUNDSINFO_FILENAME "soundsinfo.conf" +#define MUSICINFO_FILENAME "musicinfo.conf" #define LEVELFILE_EXTENSION "level" #define TAPEFILE_EXTENSION "tape" #define SCOREFILE_EXTENSION "score" @@ -35,6 +38,9 @@ #define SETUP_FILENAME "setup.cnf" #define LEVELSETUP_FILENAME "lvlsetup.cnf" #define LEVELINFO_FILENAME "lvlinfo.cnf" +#define GRAPHICSINFO_FILENAME "gfxinfo.cnf" +#define SOUNDSINFO_FILENAME "sndinfo.cnf" +#define MUSICINFO_FILENAME "musinfo.cnf" #define LEVELFILE_EXTENSION "lvl" #define TAPEFILE_EXTENSION "tap" #define SCOREFILE_EXTENSION "sco" @@ -82,7 +88,7 @@ static char *levelclass_desc[NUM_LEVELCLASS_DESC] = /* file functions */ /* ------------------------------------------------------------------------- */ -char *getLevelClassDescription(struct LevelDirInfo *ldi) +static char *getLevelClassDescription(TreeInfo *ldi) { int position = ldi->sort_priority / 100; @@ -101,7 +107,7 @@ static char *getUserLevelDir(char *level_subdir) if (userlevel_dir) free(userlevel_dir); - if (strlen(level_subdir) > 0) + if (level_subdir != NULL) userlevel_dir = getPath3(data_dir, userlevel_subdir, level_subdir); else userlevel_dir = getPath2(data_dir, userlevel_subdir); @@ -118,7 +124,7 @@ static char *getTapeDir(char *level_subdir) if (tape_dir) free(tape_dir); - if (strlen(level_subdir) > 0) + if (level_subdir != NULL) tape_dir = getPath3(data_dir, tape_subdir, level_subdir); else tape_dir = getPath2(data_dir, tape_subdir); @@ -135,7 +141,7 @@ static char *getScoreDir(char *level_subdir) if (score_dir) free(score_dir); - if (strlen(level_subdir) > 0) + if (level_subdir != NULL) score_dir = getPath3(data_dir, score_subdir, level_subdir); else score_dir = getPath2(data_dir, score_subdir); @@ -152,7 +158,7 @@ static char *getLevelSetupDir(char *level_subdir) if (levelsetup_dir) free(levelsetup_dir); - if (strlen(level_subdir) > 0) + if (level_subdir != NULL) levelsetup_dir = getPath3(data_dir, levelsetup_subdir, level_subdir); else levelsetup_dir = getPath2(data_dir, levelsetup_subdir); @@ -160,6 +166,57 @@ static char *getLevelSetupDir(char *level_subdir) return levelsetup_dir; } +static char *getUserGraphicsDir(char *graphics_subdir) +{ + static char *usergraphics_dir = NULL; + char *data_dir = getUserDataDir(); + char *usergraphics_subdir = GRAPHICS_DIRECTORY; + + if (usergraphics_dir) + free(usergraphics_dir); + + if (graphics_subdir != NULL) + usergraphics_dir = getPath3(data_dir, usergraphics_subdir,graphics_subdir); + else + usergraphics_dir = getPath2(data_dir, usergraphics_subdir); + + return usergraphics_dir; +} + +static char *getUserSoundsDir(char *sounds_subdir) +{ + static char *usersounds_dir = NULL; + char *data_dir = getUserDataDir(); + char *usersounds_subdir = SOUNDS_DIRECTORY; + + if (usersounds_dir) + free(usersounds_dir); + + if (sounds_subdir != NULL) + usersounds_dir = getPath3(data_dir, usersounds_subdir,sounds_subdir); + else + usersounds_dir = getPath2(data_dir, usersounds_subdir); + + return usersounds_dir; +} + +static char *getUserMusicDir(char *music_subdir) +{ + static char *usermusic_dir = NULL; + char *data_dir = getUserDataDir(); + char *usermusic_subdir = MUSIC_DIRECTORY; + + if (usermusic_dir) + free(usermusic_dir); + + if (music_subdir != NULL) + usermusic_dir = getPath3(data_dir, usermusic_subdir,music_subdir); + else + usermusic_dir = getPath2(data_dir, usermusic_subdir); + + return usermusic_dir; +} + char *getLevelFilename(int nr) { static char *filename = NULL; @@ -170,7 +227,7 @@ char *getLevelFilename(int nr) sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); filename = getPath3((leveldir_current->user_defined ? - getUserLevelDir("") : + getUserLevelDir(NULL) : options.level_directory), leveldir_current->fullpath, basename); @@ -268,13 +325,13 @@ char *getCustomImageFilename(char *basename) void InitTapeDirectory(char *level_subdir) { createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); - createDirectory(getTapeDir(""), "main tape", PERMS_PRIVATE); + createDirectory(getTapeDir(NULL), "main tape", PERMS_PRIVATE); createDirectory(getTapeDir(level_subdir), "level tape", PERMS_PRIVATE); } void InitScoreDirectory(char *level_subdir) { - createDirectory(getScoreDir(""), "main score", PERMS_PUBLIC); + createDirectory(getScoreDir(NULL), "main score", PERMS_PUBLIC); createDirectory(getScoreDir(level_subdir), "level score", PERMS_PUBLIC); } @@ -285,7 +342,7 @@ void InitUserLevelDirectory(char *level_subdir) if (access(getUserLevelDir(level_subdir), F_OK) != 0) { createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); - createDirectory(getUserLevelDir(""), "main user level", PERMS_PRIVATE); + createDirectory(getUserLevelDir(NULL), "main user level", PERMS_PRIVATE); createDirectory(getUserLevelDir(level_subdir), "user level",PERMS_PRIVATE); SaveUserLevelInfo(); @@ -295,7 +352,7 @@ void InitUserLevelDirectory(char *level_subdir) void InitLevelSetupDirectory(char *level_subdir) { createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); - createDirectory(getLevelSetupDir(""), "main level setup", PERMS_PRIVATE); + createDirectory(getLevelSetupDir(NULL), "main level setup", PERMS_PRIVATE); createDirectory(getLevelSetupDir(level_subdir), "level setup",PERMS_PRIVATE); } @@ -348,19 +405,18 @@ void WriteChunk_VERS(FILE *file, int file_version, int game_version) /* some functions to handle lists of level directories */ /* ------------------------------------------------------------------------- */ -struct LevelDirInfo *newLevelDirInfo() +TreeInfo *newTreeInfo() { - return checked_calloc(sizeof(struct LevelDirInfo)); + return checked_calloc(sizeof(TreeInfo)); } -void pushLevelDirInfo(struct LevelDirInfo **node_first, - struct LevelDirInfo *node_new) +void pushTreeInfo(TreeInfo **node_first, TreeInfo *node_new) { node_new->next = *node_first; *node_first = node_new; } -int numLevelDirInfo(struct LevelDirInfo *node) +int numTreeInfo(TreeInfo *node) { int num = 0; @@ -373,12 +429,12 @@ int numLevelDirInfo(struct LevelDirInfo *node) return num; } -boolean validLevelSeries(struct LevelDirInfo *node) +boolean validLevelSeries(TreeInfo *node) { return (node != NULL && !node->node_group && !node->parent_link); } -struct LevelDirInfo *getFirstValidLevelSeries(struct LevelDirInfo *node) +TreeInfo *getFirstValidLevelSeries(TreeInfo *node) { if (node == NULL) { @@ -400,7 +456,7 @@ struct LevelDirInfo *getFirstValidLevelSeries(struct LevelDirInfo *node) return node; } -struct LevelDirInfo *getLevelDirInfoFirstGroupEntry(struct LevelDirInfo *node) +TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *node) { if (node == NULL) return NULL; @@ -411,14 +467,14 @@ struct LevelDirInfo *getLevelDirInfoFirstGroupEntry(struct LevelDirInfo *node) return node->node_parent->node_group; } -int numLevelDirInfoInGroup(struct LevelDirInfo *node) +int numTreeInfoInGroup(TreeInfo *node) { - return numLevelDirInfo(getLevelDirInfoFirstGroupEntry(node)); + return numTreeInfo(getTreeInfoFirstGroupEntry(node)); } -int posLevelDirInfo(struct LevelDirInfo *node) +int posTreeInfo(TreeInfo *node) { - struct LevelDirInfo *node_cmp = getLevelDirInfoFirstGroupEntry(node); + TreeInfo *node_cmp = getTreeInfoFirstGroupEntry(node); int pos = 0; while (node_cmp) @@ -433,9 +489,9 @@ int posLevelDirInfo(struct LevelDirInfo *node) return 0; } -struct LevelDirInfo *getLevelDirInfoFromPos(struct LevelDirInfo *node, int pos) +TreeInfo *getTreeInfoFromPos(TreeInfo *node, int pos) { - struct LevelDirInfo *node_default = node; + TreeInfo *node_default = node; int pos_cmp = 0; while (node) @@ -450,8 +506,7 @@ struct LevelDirInfo *getLevelDirInfoFromPos(struct LevelDirInfo *node, int pos) return node_default; } -struct LevelDirInfo *getLevelDirInfoFromFilenameExt(struct LevelDirInfo *node, - char *filename) +TreeInfo *getTreeInfoFromFilenameExt(TreeInfo *node, char *filename) { if (filename == NULL) return NULL; @@ -460,9 +515,9 @@ struct LevelDirInfo *getLevelDirInfoFromFilenameExt(struct LevelDirInfo *node, { if (node->node_group) { - struct LevelDirInfo *node_group; + TreeInfo *node_group; - node_group = getLevelDirInfoFromFilenameExt(node->node_group, filename); + node_group = getTreeInfoFromFilenameExt(node->node_group, filename); if (node_group) return node_group; @@ -479,12 +534,12 @@ struct LevelDirInfo *getLevelDirInfoFromFilenameExt(struct LevelDirInfo *node, return NULL; } -struct LevelDirInfo *getLevelDirInfoFromFilename(char *filename) +TreeInfo *getTreeInfoFromFilename(char *filename) { - return getLevelDirInfoFromFilenameExt(leveldir_first, filename); + return getTreeInfoFromFilenameExt(leveldir_first, filename); } -void dumpLevelDirInfo(struct LevelDirInfo *node, int depth) +void dumpTreeInfo(TreeInfo *node, int depth) { int i; @@ -493,28 +548,28 @@ void dumpLevelDirInfo(struct LevelDirInfo *node, int depth) for (i=0; ifilename); + printf("filename == '%s' [%s]\n", node->filename, node->name); if (node->node_group != NULL) - dumpLevelDirInfo(node->node_group, depth + 1); + dumpTreeInfo(node->node_group, depth + 1); node = node->next; } } -void sortLevelDirInfo(struct LevelDirInfo **node_first, - int (*compare_function)(const void *, const void *)) +void sortTreeInfo(TreeInfo **node_first, + int (*compare_function)(const void *, const void *)) { - int num_nodes = numLevelDirInfo(*node_first); - struct LevelDirInfo **sort_array; - struct LevelDirInfo *node = *node_first; + int num_nodes = numTreeInfo(*node_first); + TreeInfo **sort_array; + TreeInfo *node = *node_first; int i = 0; if (num_nodes == 0) return; /* allocate array for sorting structure pointers */ - sort_array = checked_calloc(num_nodes * sizeof(struct LevelDirInfo *)); + sort_array = checked_calloc(num_nodes * sizeof(TreeInfo *)); /* writing structure pointers to sorting array */ while (i < num_nodes && node) /* double boundary check... */ @@ -526,7 +581,7 @@ void sortLevelDirInfo(struct LevelDirInfo **node_first, } /* sorting the structure pointers in the sorting array */ - qsort(sort_array, num_nodes, sizeof(struct LevelDirInfo *), + qsort(sort_array, num_nodes, sizeof(TreeInfo *), compare_function); /* update the linkage of list elements with the sorted node array */ @@ -544,7 +599,7 @@ void sortLevelDirInfo(struct LevelDirInfo **node_first, while (node) { if (node->node_group != NULL) - sortLevelDirInfo(&node->node_group, compare_function); + sortTreeInfo(&node->node_group, compare_function); node = node->next; } @@ -1002,7 +1057,7 @@ void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, #define NUM_LEVELINFO_TOKENS 10 -static struct LevelDirInfo ldi; +static LevelDirTree ldi; static struct TokenInfo levelinfo_tokens[] = { @@ -1019,8 +1074,17 @@ static struct TokenInfo levelinfo_tokens[] = { TYPE_BOOLEAN, &ldi.readonly, "readonly" } }; -static void setLevelDirInfoToDefaults(struct LevelDirInfo *ldi) +static void setTreeInfoToDefaults(TreeInfo *ldi) { + ldi->node_parent = NULL; + ldi->node_group = NULL; + ldi->next = NULL; + + ldi->cl_first = -1; + ldi->cl_cursor = -1; + + ldi->type = TREE_TYPE_GENERIC; + ldi->filename = NULL; ldi->fullpath = NULL; ldi->basepath = NULL; @@ -1040,20 +1104,14 @@ static void setLevelDirInfoToDefaults(struct LevelDirInfo *ldi) ldi->color = 0; ldi->class_desc = NULL; ldi->handicap_level = 0; - ldi->cl_first = -1; - ldi->cl_cursor = -1; - - ldi->node_parent = NULL; - ldi->node_group = NULL; - ldi->next = NULL; } -static void setLevelDirInfoToDefaultsFromParent(struct LevelDirInfo *ldi, - struct LevelDirInfo *parent) +static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, + TreeInfo *parent) { if (parent == NULL) { - setLevelDirInfoToDefaults(ldi); + setTreeInfoToDefaults(ldi); return; } @@ -1124,10 +1182,10 @@ void setSetupInfo(struct TokenInfo *token_info, } } -static int compareLevelDirInfoEntries(const void *object1, const void *object2) +static int compareTreeInfoEntries(const void *object1, const void *object2) { - const struct LevelDirInfo *entry1 = *((struct LevelDirInfo **)object1); - const struct LevelDirInfo *entry2 = *((struct LevelDirInfo **)object2); + const TreeInfo *entry1 = *((TreeInfo **)object1); + const TreeInfo *entry2 = *((TreeInfo **)object2); int compare_result; if (entry1->parent_link || entry2->parent_link) @@ -1150,11 +1208,11 @@ static int compareLevelDirInfoEntries(const void *object1, const void *object2) return compare_result; } -static void createParentLevelDirNode(struct LevelDirInfo *node_parent) +static void createParentTreeInfoNode(TreeInfo *node_parent) { - struct LevelDirInfo *leveldir_new = newLevelDirInfo(); + TreeInfo *leveldir_new = newTreeInfo(); - setLevelDirInfoToDefaults(leveldir_new); + setTreeInfoToDefaults(leveldir_new); leveldir_new->node_parent = node_parent; leveldir_new->parent_link = TRUE; @@ -1169,23 +1227,21 @@ static void createParentLevelDirNode(struct LevelDirInfo *node_parent) leveldir_new->sort_priority = node_parent->sort_priority; leveldir_new->class_desc = getLevelClassDescription(leveldir_new); - pushLevelDirInfo(&node_parent->node_group, leveldir_new); + pushTreeInfo(&node_parent->node_group, leveldir_new); } -/* forward declaration for recursive call by "LoadLevelInfoFromSetupFile()" */ -static void LoadLevelInfoFromLevelGroupDir(struct LevelDirInfo **, - struct LevelDirInfo *, - char *); +/* forward declaration for recursive call by "LoadLevelInfoFromLevelDir()" */ +static void LoadLevelInfoFromLevelDir(TreeInfo **, TreeInfo *, char *); -static boolean LoadLevelInfoFromLevelDir(struct LevelDirInfo **node_first, - struct LevelDirInfo *node_parent, - char *level_directory, - char *directory_name) +static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, + TreeInfo *node_parent, + char *level_directory, + char *directory_name) { char *directory_path = getPath2(level_directory, directory_name); char *filename = getPath2(directory_path, LEVELINFO_FILENAME); struct SetupFileList *setup_file_list = loadSetupFileList(filename); - struct LevelDirInfo *leveldir_new = NULL; + LevelDirTree *leveldir_new = NULL; int i; if (setup_file_list == NULL) @@ -1198,10 +1254,10 @@ static boolean LoadLevelInfoFromLevelDir(struct LevelDirInfo **node_first, return FALSE; } - leveldir_new = newLevelDirInfo(); + leveldir_new = newTreeInfo(); checkSetupFileListIdentifier(setup_file_list, getCookie("LEVELINFO")); - setLevelDirInfoToDefaultsFromParent(leveldir_new, node_parent); + setTreeInfoToDefaultsFromParent(leveldir_new, node_parent); /* set all structure fields according to the token/value pairs */ ldi = *leveldir_new; @@ -1228,8 +1284,7 @@ static boolean LoadLevelInfoFromLevelDir(struct LevelDirInfo **node_first, else /* sub level group */ { leveldir_new->basepath = node_parent->basepath; - leveldir_new->fullpath = getPath2(node_parent->fullpath, - directory_name); + leveldir_new->fullpath = getPath2(node_parent->fullpath, directory_name); } if (leveldir_new->levels < 1) @@ -1249,18 +1304,18 @@ static boolean LoadLevelInfoFromLevelDir(struct LevelDirInfo **node_first, leveldir_new->last_level : leveldir_new->first_level); - pushLevelDirInfo(node_first, leveldir_new); + pushTreeInfo(node_first, leveldir_new); freeSetupFileList(setup_file_list); if (leveldir_new->level_group) { /* create node to link back to current level directory */ - createParentLevelDirNode(leveldir_new); + createParentTreeInfoNode(leveldir_new); /* step into sub-directory and look for more level series */ - LoadLevelInfoFromLevelGroupDir(&leveldir_new->node_group, - leveldir_new, directory_path); + LoadLevelInfoFromLevelDir(&leveldir_new->node_group, + leveldir_new, directory_path); } free(directory_path); @@ -1269,9 +1324,9 @@ static boolean LoadLevelInfoFromLevelDir(struct LevelDirInfo **node_first, return TRUE; } -static void LoadLevelInfoFromLevelGroupDir(struct LevelDirInfo **node_first, - struct LevelDirInfo *node_parent, - char *level_directory) +static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, + TreeInfo *node_parent, + char *level_directory) { DIR *dir; struct dirent *dir_entry; @@ -1307,9 +1362,9 @@ static void LoadLevelInfoFromLevelGroupDir(struct LevelDirInfo **node_first, free(directory_path); - valid_entry_found |= LoadLevelInfoFromLevelDir(node_first, node_parent, - level_directory, - directory_name); + valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, + level_directory, + directory_name); } closedir(dir); @@ -1317,8 +1372,8 @@ static void LoadLevelInfoFromLevelGroupDir(struct LevelDirInfo **node_first, if (!valid_entry_found) { /* check if this directory directly contains a file "levelinfo.conf" */ - valid_entry_found |= LoadLevelInfoFromLevelDir(node_first, node_parent, - level_directory, "."); + valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, + level_directory, "."); } if (!valid_entry_found) @@ -1332,19 +1387,251 @@ void LoadLevelInfo() DrawInitText("Loading level series:", 120, FC_GREEN); - /* check if this directory directly contains a file "levelinfo.conf" */ - LoadLevelInfoFromLevelGroupDir(&leveldir_first,NULL,options.level_directory); - LoadLevelInfoFromLevelGroupDir(&leveldir_first,NULL,getUserLevelDir("")); + LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory); + LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL)); leveldir_current = getFirstValidLevelSeries(leveldir_first); if (leveldir_first == NULL) Error(ERR_EXIT, "cannot find any valid level series in any directory"); - sortLevelDirInfo(&leveldir_first, compareLevelDirInfoEntries); + sortTreeInfo(&leveldir_first, compareTreeInfoEntries); + +#if 0 + dumpTreeInfo(leveldir_first, 0); +#endif +} + +/* declaration for recursive call by "LoadArtworkInfoFromArtworkConf()" */ +static void LoadArtworkInfoFromArtworkDir(TreeInfo **, TreeInfo *, char *,int); + +static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, + TreeInfo *node_parent, + char *base_directory, + char *directory_name, int type) +{ + char *directory_path = getPath2(base_directory, directory_name); + char *filename = + getPath2(directory_path, + (type == TREE_TYPE_GRAPHICS_DIR ? GRAPHICSINFO_FILENAME : + type == TREE_TYPE_SOUNDS_DIR ? SOUNDSINFO_FILENAME : + type == TREE_TYPE_MUSIC_DIR ? MUSICINFO_FILENAME : "")); + struct SetupFileList *setup_file_list = NULL; + TreeInfo *artwork_new = NULL; + char *check_dir = NULL; + int i; + + if (access(getUserLevelDir(filename), F_OK) == 0) /* file exists */ + loadSetupFileList(filename); + + if (setup_file_list == NULL) /* no config file -- look for artwork files */ + { + DIR *dir; + struct dirent *dir_entry; + boolean valid_file_found = FALSE; + + if ((dir = opendir(base_directory)) != NULL) + { + while ((dir_entry = readdir(dir)) != NULL) + { + char *entry_name = dir_entry->d_name; + + if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(entry_name)) || + (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(entry_name)) || + (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(entry_name))) + { + valid_file_found = TRUE; + break; + } + } + + closedir(dir); + } + + if (!valid_file_found) + { + Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory); + + free(directory_path); + free(filename); + + return FALSE; + } + } + + artwork_new = newTreeInfo(); + setTreeInfoToDefaultsFromParent(artwork_new, node_parent); + + artwork_new->filename = getStringCopy(directory_name); + + if (setup_file_list) + { +#if 0 + checkSetupFileListIdentifier(setup_file_list, getCookie("...")); +#endif + + /* set all structure fields according to the token/value pairs */ + ldi = *artwork_new; + for (i=0; iname, 150, FC_YELLOW); + + if (artwork_new->name_short == NULL) + artwork_new->name_short = getStringCopy(artwork_new->name); + + if (artwork_new->name_sorting == NULL) + artwork_new->name_sorting = getStringCopy(artwork_new->name); + } + else + { + if (artwork_new->name != NULL) + free(artwork_new->name); + + if (strcmp(artwork_new->filename, ".") == 0) + artwork_new->name = getStringCopy("default"); + else + artwork_new->name = getStringCopy(artwork_new->filename); + + artwork_new->name_short = getStringCopy(artwork_new->name); + artwork_new->name_sorting = getStringCopy(artwork_new->name); + } + + if (node_parent == NULL) /* top level group */ + { + artwork_new->basepath = base_directory; + artwork_new->fullpath = artwork_new->filename; + } + else /* sub level group */ + { + artwork_new->basepath = node_parent->basepath; + artwork_new->fullpath = getPath2(node_parent->fullpath, directory_name); + } + + check_dir = (type == TREE_TYPE_GRAPHICS_DIR ? options.graphics_directory : + type == TREE_TYPE_SOUNDS_DIR ? options.sounds_directory : + type == TREE_TYPE_MUSIC_DIR ? options.music_directory : ""); + artwork_new->user_defined = + (artwork_new->basepath == check_dir ? FALSE : TRUE); + +#if 0 + artwork_new->color = LEVELCOLOR(artwork_new); + artwork_new->class_desc = getLevelClassDescription(artwork_new); +#endif + + pushTreeInfo(node_first, artwork_new); + + freeSetupFileList(setup_file_list); + + free(directory_path); + free(filename); + + return TRUE; +} + +static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, + TreeInfo *node_parent, + char *base_directory, int type) +{ + DIR *dir; + struct dirent *dir_entry; + boolean valid_entry_found = FALSE; + + if ((dir = opendir(base_directory)) == NULL) + { + if ((type == TREE_TYPE_GRAPHICS_DIR && + base_directory == options.graphics_directory) || + (type == TREE_TYPE_SOUNDS_DIR && + base_directory == options.sounds_directory) || + (type == TREE_TYPE_MUSIC_DIR && + base_directory == options.music_directory)) + Error(ERR_WARN, "cannot read directory '%s'", base_directory); + return; + } + + while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ + { + struct stat file_status; + char *directory_name = dir_entry->d_name; + char *directory_path = getPath2(base_directory, directory_name); + + /* skip entries for current and parent directory */ + if (strcmp(directory_name, ".") == 0 || + strcmp(directory_name, "..") == 0) + { + free(directory_path); + continue; + } + + /* find out if directory entry is itself a directory */ + if (stat(directory_path, &file_status) != 0 || /* cannot stat file */ + (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */ + { + free(directory_path); + continue; + } + + free(directory_path); + + valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent, + base_directory, + directory_name, type); + } + + closedir(dir); + + if (!valid_entry_found) + { + /* check if this directory directly contains an artwork config file */ + valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent, + base_directory, ".", + type); + } + + if (!valid_entry_found) + Error(ERR_WARN, "cannot find any valid artwork in directory '%s'", + base_directory); +} + +void LoadArtworkInfo() +{ + DrawInitText("Looking for custom artwork:", 120, FC_GREEN); + + LoadArtworkInfoFromArtworkDir(&artwork.gfx_first, NULL, + options.graphics_directory, + TREE_TYPE_GRAPHICS_DIR); + LoadArtworkInfoFromArtworkDir(&artwork.gfx_first, NULL, + getUserGraphicsDir(NULL), + TREE_TYPE_GRAPHICS_DIR); + + LoadArtworkInfoFromArtworkDir(&artwork.snd_first, NULL, + options.sounds_directory, + TREE_TYPE_SOUNDS_DIR); + LoadArtworkInfoFromArtworkDir(&artwork.snd_first, NULL, + getUserSoundsDir(NULL), + TREE_TYPE_SOUNDS_DIR); + + LoadArtworkInfoFromArtworkDir(&artwork.mus_first, NULL, + options.music_directory, + TREE_TYPE_MUSIC_DIR); + LoadArtworkInfoFromArtworkDir(&artwork.mus_first, NULL, + getUserMusicDir(NULL), + TREE_TYPE_MUSIC_DIR); + + artwork.gfx_current = artwork.gfx_first; + artwork.snd_current = artwork.snd_first; + artwork.mus_current = artwork.mus_first; + + sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries); + sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries); + sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries); #if 0 - dumpLevelDirInfo(leveldir_first, 0); + dumpTreeInfo(artwork.gfx_first, 0); + dumpTreeInfo(artwork.snd_first, 0); + dumpTreeInfo(artwork.mus_first, 0); #endif } @@ -1364,7 +1651,7 @@ static void SaveUserLevelInfo() } /* always start with reliable default values */ - setLevelDirInfoToDefaults(&ldi); + setTreeInfoToDefaults(&ldi); ldi.name = getLoginName(); ldi.author = getRealName(); @@ -1486,7 +1773,7 @@ void LoadLevelSetup_LastSeries() char *last_level_series = getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES); - leveldir_current = getLevelDirInfoFromFilename(last_level_series); + leveldir_current = getTreeInfoFromFilename(last_level_series); if (leveldir_current == NULL) leveldir_current = leveldir_first; @@ -1541,7 +1828,7 @@ static void checkSeriesInfo() /* check for more levels besides the 'levels' field of 'levelinfo.conf' */ level_directory = getPath2((leveldir_current->user_defined ? - getUserLevelDir("") : + getUserLevelDir(NULL) : options.level_directory), leveldir_current->fullpath); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index e0372617..44dd664f 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -149,19 +149,19 @@ void InitLevelSetupDirectory(char *); void ReadChunk_VERS(FILE *, int *, int *); void WriteChunk_VERS(FILE *, int, int); -struct LevelDirInfo *newLevelDirInfo(); -void pushLevelDirInfo(struct LevelDirInfo **, struct LevelDirInfo *); -int numLevelDirInfo(struct LevelDirInfo *); -boolean validLevelSeries(struct LevelDirInfo *); -struct LevelDirInfo *getFirstValidLevelSeries(struct LevelDirInfo *); -struct LevelDirInfo *getLevelDirInfoFirstGroupEntry(struct LevelDirInfo *); -int numLevelDirInfoInGroup(struct LevelDirInfo *); -int posLevelDirInfo(struct LevelDirInfo *); -struct LevelDirInfo *getLevelDirInfoFromPos(struct LevelDirInfo *, int); -struct LevelDirInfo *getLevelDirInfoFromFilename(char *); -void dumpLevelDirInfo(struct LevelDirInfo *, int); -void sortLevelDirInfo(struct LevelDirInfo **, - int (*compare_function)(const void *, const void *)); +TreeInfo *newTreeInfo(); +void pushTreeInfo(TreeInfo **, TreeInfo *); +int numTreeInfo(TreeInfo *); +boolean validLevelSeries(TreeInfo *); +TreeInfo *getFirstValidLevelSeries(TreeInfo *); +TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *); +int numTreeInfoInGroup(TreeInfo *); +int posTreeInfo(TreeInfo *); +TreeInfo *getTreeInfoFromPos(TreeInfo *, int); +TreeInfo *getTreeInfoFromFilename(char *); +void dumpTreeInfo(TreeInfo *, int); +void sortTreeInfo(TreeInfo **, + int (*compare_function)(const void *, const void *)); char *getUserDataDir(void); char *getSetupDir(void); @@ -183,6 +183,7 @@ char *getSetupValue(int, void *); char *getSetupLine(struct TokenInfo *, char *, int); void LoadLevelInfo(void); +void LoadArtworkInfo(void); void LoadLevelSetup_LastSeries(void); void SaveLevelSetup_LastSeries(void); void LoadLevelSetup_SeriesInfo(void); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 220dfde6..d10f0f2b 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -1080,21 +1080,10 @@ int LoadMusic(void) { char *filename = dir_entry->d_name; - if (strlen(filename) > 4 && - strcmp(&filename[strlen(filename) - 4], ".wav") == 0) - { - if (LoadSoundExt(filename, TRUE)) - num_wav_music++; - } - else if (strlen(filename) > 4 && - (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || - strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || - strncmp(filename, "mod.", 4) == 0 || - strncmp(filename, "MOD.", 4) == 0)) - { - if (LoadMod(filename)) - num_mod_music++; - } + if (FileIsSound(filename) && LoadSoundExt(filename, TRUE)) + num_wav_music++; + else if (FileIsMusic(filename) && LoadMod(filename)) + num_mod_music++; } closedir(dir); diff --git a/src/libgame/system.c b/src/libgame/system.c index 497f7e0b..79623455 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -40,8 +40,8 @@ struct ArtworkInfo artwork; struct JoystickInfo joystick; struct SetupInfo setup; -struct LevelDirInfo *leveldir_first = NULL; -struct LevelDirInfo *leveldir_current = NULL; +LevelDirTree *leveldir_first = NULL; +LevelDirTree *leveldir_current = NULL; int level_nr; Display *display = NULL; diff --git a/src/libgame/system.h b/src/libgame/system.h index 801fb44b..701df603 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -246,14 +246,6 @@ struct GfxInfo boolean draw_deactivation_mask; }; -struct ArtworkInfo -{ - char *custom_artwork; - char *custom_graphics; - char *custom_sounds; - char *custom_music; -}; - struct JoystickInfo { int status; @@ -318,8 +310,25 @@ struct SetupInfo struct SetupInputInfo input[MAX_PLAYERS]; }; -struct LevelDirInfo +#define TREE_TYPE_GENERIC 0 +#define TREE_TYPE_LEVEL_DIR 1 +#define TREE_TYPE_GRAPHICS_DIR 2 +#define TREE_TYPE_SOUNDS_DIR 3 +#define TREE_TYPE_MUSIC_DIR 4 + +struct TreeInfo { + struct TreeInfo *node_parent; /* parent level directory info */ + struct TreeInfo *node_group; /* level group sub-directory info */ + struct TreeInfo *next; /* next level series structure node */ + + int cl_first; /* internal control field for setup screen */ + int cl_cursor; /* internal control field for setup screen */ + + int type; /* type of tree content */ + + /* fields for "type == TREE_TYPE_LEVEL_DIR" */ + char *filename; /* level series single directory name */ char *fullpath; /* complete path relative to level directory */ char *basepath; /* absolute base path of level directory */ @@ -339,12 +348,22 @@ struct LevelDirInfo int color; /* color to use on selection screen for this level */ char *class_desc; /* description of level series class */ int handicap_level; /* number of the lowest unsolved level */ - int cl_first; /* internal control field for "choose level" screen */ - int cl_cursor; /* internal control field for "choose level" screen */ +}; - struct LevelDirInfo *node_parent; /* parent level directory info */ - struct LevelDirInfo *node_group; /* level group sub-directory info */ - struct LevelDirInfo *next; /* next level series structure node */ +typedef struct TreeInfo TreeInfo; +typedef struct TreeInfo LevelDirTree; +typedef struct TreeInfo GraphicsDirTree; +typedef struct TreeInfo SoundsDirTree; +typedef struct TreeInfo MusicDirTree; + +struct ArtworkInfo +{ + GraphicsDirTree *gfx_first; + GraphicsDirTree *gfx_current; + SoundsDirTree *snd_first; + SoundsDirTree *snd_current; + MusicDirTree *mus_first; + MusicDirTree *mus_current; }; @@ -361,8 +380,8 @@ extern struct ArtworkInfo artwork; extern struct JoystickInfo joystick; extern struct SetupInfo setup; -extern struct LevelDirInfo *leveldir_first; -extern struct LevelDirInfo *leveldir_current; +extern LevelDirTree *leveldir_first; +extern LevelDirTree *leveldir_current; extern int level_nr; extern Display *display; diff --git a/src/network.c b/src/network.c index 159ef458..946a94d8 100644 --- a/src/network.c +++ b/src/network.c @@ -415,7 +415,7 @@ static void Handle_OP_PLAYER_DISCONNECTED() static void Handle_OP_START_PLAYING() { - struct LevelDirInfo *new_leveldir; + LevelDirTree *new_leveldir; int new_level_nr; int dummy; /* !!! HAS NO MEANING ANYMORE !!! */ unsigned long new_random_seed; @@ -427,7 +427,7 @@ static void Handle_OP_START_PLAYING() (buffer[6] << 24) | (buffer[7] << 16) | (buffer[8] << 8) | (buffer[9]); new_leveldir_filename = (char *)&buffer[10]; - new_leveldir = getLevelDirInfoFromFilename(new_leveldir_filename); + new_leveldir = getTreeInfoFromFilename(new_leveldir_filename); if (new_leveldir == NULL) { Error(ERR_WARN, "no such level directory: '%s'", new_leveldir_filename); diff --git a/src/screens.c b/src/screens.c index 9310b5f1..d1d8e119 100644 --- a/src/screens.c +++ b/src/screens.c @@ -122,7 +122,7 @@ static void ToggleFullscreenIfNeeded() void DrawMainMenu() { - static struct LevelDirInfo *leveldir_last_valid = NULL; + static LevelDirTree *leveldir_last_valid = NULL; int i; char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:"); @@ -236,8 +236,8 @@ static void gotoTopLevelDir() /* write a "path" into level tree for easy navigation to last level */ if (leveldir_current->node_parent->node_group->cl_first == -1) { - int num_leveldirs = numLevelDirInfoInGroup(leveldir_current); - int leveldir_pos = posLevelDirInfo(leveldir_current); + int num_leveldirs = numTreeInfoInGroup(leveldir_current); + int leveldir_pos = posTreeInfo(leveldir_current); int num_page_entries; int cl_first, cl_cursor; @@ -935,7 +935,7 @@ static void AdjustChooseLevelScrollbar(int id, int first_entry) struct GadgetInfo *gi = screen_gadget[id]; int items_max, items_visible, item_position; - items_max = numLevelDirInfoInGroup(leveldir_current); + items_max = numTreeInfoInGroup(leveldir_current); items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1; item_position = first_entry; @@ -951,7 +951,7 @@ static void drawChooseLevelList(int first_entry, int num_page_entries) int i; char buffer[SCR_FIELDX * 2]; int max_buffer_len = (SCR_FIELDX - 2) * 2; - int num_leveldirs = numLevelDirInfoInGroup(leveldir_current); + int num_leveldirs = numTreeInfoInGroup(leveldir_current); ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE); redraw_mask |= REDRAW_FIELD; @@ -960,12 +960,12 @@ static void drawChooseLevelList(int first_entry, int num_page_entries) for(i=0; iname , max_buffer_len); buffer[max_buffer_len] = '\0'; @@ -989,11 +989,11 @@ static void drawChooseLevelList(int first_entry, int num_page_entries) static void drawChooseLevelInfo(int leveldir_pos) { - struct LevelDirInfo *node, *node_first; + LevelDirTree *node, *node_first; int x, last_redraw_mask = redraw_mask; - node_first = getLevelDirInfoFirstGroupEntry(leveldir_current); - node = getLevelDirInfoFromPos(node_first, leveldir_pos); + node_first = getTreeInfoFirstGroupEntry(leveldir_current); + node = getTreeInfoFromPos(node_first, leveldir_pos); ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32); @@ -1017,7 +1017,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) int x = 0; int y = leveldir_current->cl_cursor; int step = (button == 1 ? 1 : button == 2 ? 5 : 10); - int num_leveldirs = numLevelDirInfoInGroup(leveldir_current); + int num_leveldirs = numTreeInfoInGroup(leveldir_current); int num_page_entries; if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN) @@ -1027,7 +1027,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) if (button == MB_MENU_INITIALIZE) { - int leveldir_pos = posLevelDirInfo(leveldir_current); + int leveldir_pos = posTreeInfo(leveldir_current); if (leveldir_current->cl_first == -1) { @@ -1120,11 +1120,11 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) if (dx == 1) { - struct LevelDirInfo *node_first, *node_cursor; + LevelDirTree *node_first, *node_cursor; int leveldir_pos = leveldir_current->cl_first + y; - node_first = getLevelDirInfoFirstGroupEntry(leveldir_current); - node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos); + node_first = getTreeInfoFirstGroupEntry(leveldir_current); + node_cursor = getTreeInfoFromPos(node_first, leveldir_pos); if (node_cursor->node_group) { @@ -1156,11 +1156,11 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) } else { - struct LevelDirInfo *node_first, *node_cursor; + LevelDirTree *node_first, *node_cursor; int leveldir_pos = leveldir_current->cl_first + y; - node_first = getLevelDirInfoFirstGroupEntry(leveldir_current); - node_cursor = getLevelDirInfoFromPos(node_first, leveldir_pos); + node_first = getTreeInfoFirstGroupEntry(leveldir_current); + node_cursor = getTreeInfoFromPos(node_first, leveldir_pos); if (node_cursor->node_group) { @@ -2451,7 +2451,7 @@ void CreateScreenGadgets() void MapChooseLevelGadgets() { - int num_leveldirs = numLevelDirInfoInGroup(leveldir_current); + int num_leveldirs = numTreeInfoInGroup(leveldir_current); int i; if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN) diff --git a/src/timestamp.h b/src/timestamp.h index ecb53d5c..a8481f46 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-04-01 20:50]" +#define COMPILE_DATE_STRING "[2002-04-02 01:43]" -- 2.34.1