X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=2a86f2be07706c0380ea7ad7a13494f401a1ca39;hb=512f7bbfa113ed92bebc8a3a7d436b38c0227d59;hp=599bff5d462d0ca5a833be648578530340fce06d;hpb=4cd59cef0737229da365e385a8762e681a5e471f;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 599bff5d..2a86f2be 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -18,11 +18,6 @@ #include "platform.h" -#if !defined(PLATFORM_WIN32) -#include -#include -#endif - #include "setup.h" #include "joystick.h" #include "text.h" @@ -1361,19 +1356,19 @@ void dumpTreeInfo(TreeInfo *node, int depth) { int i; - printf("Dumping TreeInfo:\n"); + Debug("tree", "Dumping TreeInfo:"); while (node) { for (i = 0; i < (depth + 1) * 3; i++) - printf(" "); + DebugContinued("", " "); - printf("'%s' / '%s'\n", node->identifier, node->name); + DebugContinued("tree", "'%s' / '%s'\n", node->identifier, node->name); /* // use for dumping artwork info tree - printf("subdir == '%s' ['%s', '%s'] [%d])\n", - node->subdir, node->fullpath, node->basepath, node->in_user_dir); + Debug("tree", "subdir == '%s' ['%s', '%s'] [%d])", + node->subdir, node->fullpath, node->basepath, node->in_user_dir); */ if (node->node_group != NULL) @@ -1504,10 +1499,10 @@ char *getHomeDir(void) { if ((dir = getenv("HOME")) == NULL) { - struct passwd *pwd; + dir = getUnixHomeDir(); - if ((pwd = getpwuid(getuid())) != NULL) - dir = getStringCopy(pwd->pw_dir); + if (dir != NULL) + dir = getStringCopy(dir); else dir = "."; } @@ -1830,8 +1825,8 @@ static void printSetupFileList(SetupFileList *list) if (!list) return; - printf("token: '%s'\n", list->token); - printf("value: '%s'\n", list->value); + Debug("setup:printSetupFileList", "token: '%s'", list->token); + Debug("setup:printSetupFileList", "value: '%s'", list->value); printSetupFileList(list->next); } @@ -1891,7 +1886,7 @@ SetupFileHash *newSetupFileHash(void) create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal); if (new_hash == NULL) - Error(ERR_EXIT, "create_hashtable() failed -- out of memory"); + Fail("create_hashtable() failed -- out of memory"); return new_hash; } @@ -1924,7 +1919,7 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value) // change value; if it does not exist, insert it as new if (!change_hash_entry(hash, token, value_copy)) if (!insert_hash_entry(hash, getStringCopy(token), value_copy)) - Error(ERR_EXIT, "cannot insert into hash -- aborting"); + Fail("cannot insert into hash -- aborting"); } char *removeHashEntry(SetupFileHash *hash, char *token) @@ -1941,8 +1936,8 @@ static void printSetupFileHash(SetupFileHash *hash) { BEGIN_HASH_ITERATION(hash, itr) { - printf("token: '%s'\n", HASH_ITERATION_TOKEN(itr)); - printf("value: '%s'\n", HASH_ITERATION_VALUE(itr)); + Debug("setup:printSetupFileHash", "token: '%s'", HASH_ITERATION_TOKEN(itr)); + Debug("setup:printSetupFileHash", "value: '%s'", HASH_ITERATION_VALUE(itr)); } END_HASH_ITERATION(hash, itr) } @@ -3540,7 +3535,7 @@ void LoadLevelInfo(void) leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); if (leveldir_first == NULL) - Error(ERR_EXIT, "cannot find any valid level series in any directory"); + Fail("cannot find any valid level series in any directory"); sortTreeInfo(&leveldir_first); @@ -3766,6 +3761,34 @@ static TreeInfo *getDummyArtworkInfo(int type) return artwork_new; } +void SetCurrentArtwork(int type) +{ + ArtworkDirTree **current_ptr = ARTWORK_CURRENT_PTR(artwork, type); + ArtworkDirTree *first_node = ARTWORK_FIRST_NODE(artwork, type); + char *setup_set = SETUP_ARTWORK_SET(setup, type); + char *default_subdir = ARTWORK_DEFAULT_SUBDIR(type); + + // set current artwork to artwork configured in setup menu + *current_ptr = getTreeInfoFromIdentifier(first_node, setup_set); + + // if not found, set current artwork to default artwork + if (*current_ptr == NULL) + *current_ptr = getTreeInfoFromIdentifier(first_node, default_subdir); + + // if not found, set current artwork to first artwork in tree + if (*current_ptr == NULL) + *current_ptr = getFirstValidTreeInfoEntry(first_node); +} + +void ChangeCurrentArtworkIfNeeded(int type) +{ + char *current_identifier = ARTWORK_CURRENT_IDENTIFIER(artwork, type); + char *setup_set = SETUP_ARTWORK_SET(setup, type); + + if (!strEqual(current_identifier, setup_set)) + SetCurrentArtwork(type); +} + void LoadArtworkInfo(void) { LoadArtworkInfoCache(); @@ -3801,38 +3824,21 @@ void LoadArtworkInfo(void) artwork.mus_first = getDummyArtworkInfo(TREE_TYPE_MUSIC_DIR); // before sorting, the first entries will be from the user directory - artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set); - if (artwork.gfx_current == NULL) - artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, GFX_DEFAULT_SUBDIR); - if (artwork.gfx_current == NULL) - artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first); - - artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set); - if (artwork.snd_current == NULL) - artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, SND_DEFAULT_SUBDIR); - if (artwork.snd_current == NULL) - artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first); - - artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set); - if (artwork.mus_current == NULL) - artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, MUS_DEFAULT_SUBDIR); - if (artwork.mus_current == NULL) - artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first); + SetCurrentArtwork(ARTWORK_TYPE_GRAPHICS); + SetCurrentArtwork(ARTWORK_TYPE_SOUNDS); + SetCurrentArtwork(ARTWORK_TYPE_MUSIC); artwork.gfx_current_identifier = artwork.gfx_current->identifier; artwork.snd_current_identifier = artwork.snd_current->identifier; artwork.mus_current_identifier = artwork.mus_current->identifier; #if ENABLE_UNUSED_CODE - printf("graphics set == %s\n\n", artwork.gfx_current_identifier); - printf("sounds set == %s\n\n", artwork.snd_current_identifier); - printf("music set == %s\n\n", artwork.mus_current_identifier); + Debug("setup:LoadArtworkInfo", "graphics set == %s", + artwork.gfx_current_identifier); + Debug("setup:LoadArtworkInfo", "sounds set == %s", + artwork.snd_current_identifier); + Debug("setup:LoadArtworkInfo", "music set == %s", + artwork.mus_current_identifier); #endif sortTreeInfo(&artwork.gfx_first); @@ -3922,39 +3928,9 @@ void LoadLevelArtworkInfo(void) print_timestamp_time("SaveArtworkInfoCache"); // needed for reloading level artwork not known at ealier stage - - if (!strEqual(artwork.gfx_current_identifier, setup.graphics_set)) - { - artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set); - if (artwork.gfx_current == NULL) - artwork.gfx_current = - getTreeInfoFromIdentifier(artwork.gfx_first, GFX_DEFAULT_SUBDIR); - if (artwork.gfx_current == NULL) - artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first); - } - - if (!strEqual(artwork.snd_current_identifier, setup.sounds_set)) - { - artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set); - if (artwork.snd_current == NULL) - artwork.snd_current = - getTreeInfoFromIdentifier(artwork.snd_first, SND_DEFAULT_SUBDIR); - if (artwork.snd_current == NULL) - artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first); - } - - if (!strEqual(artwork.mus_current_identifier, setup.music_set)) - { - artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set); - if (artwork.mus_current == NULL) - artwork.mus_current = - getTreeInfoFromIdentifier(artwork.mus_first, MUS_DEFAULT_SUBDIR); - if (artwork.mus_current == NULL) - artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first); - } + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS); + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS); + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC); print_timestamp_time("getTreeInfoFromIdentifier"); @@ -4050,7 +4026,7 @@ void AddTreeSetToTreeInfo(TreeInfo *tree_node, char *tree_dir, char *tree_subdir_new, int type) { if (!AddTreeSetToTreeInfoExt(tree_node, tree_dir, tree_subdir_new, type)) - Error(ERR_EXIT, "internal tree info structure corrupted -- aborting"); + Fail("internal tree info structure corrupted -- aborting"); } void AddUserLevelSetToLevelInfo(char *level_subdir_new) @@ -4092,7 +4068,7 @@ TreeInfo *getArtworkTreeInfoForUserLevelSet(int type) ti = getTreeInfoFromIdentifier(artwork_first_node, ARTWORK_DEFAULT_SUBDIR(type)); if (ti == NULL) - Error(ERR_EXIT, "cannot find default graphics -- should not happen"); + Fail("cannot find default graphics -- should not happen"); } return ti;