From: Holger Schemel Date: Sat, 17 Oct 2020 15:46:15 +0000 (+0200) Subject: improved code to set or change current artwork X-Git-Tag: 4.2.1.0~55 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=512f7bbfa113ed92bebc8a3a7d436b38c0227d59;p=rocksndiamonds.git improved code to set or change current artwork --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index f1b87e17..2a86f2be 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -3761,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(); @@ -3796,29 +3824,9 @@ 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; @@ -3920,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"); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 9a8f2d5f..59173924 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -326,6 +326,9 @@ char *ExtractZipFileIntoDirectory(char *, char *, int); boolean AdjustGraphicsForEMC(void); boolean AdjustSoundsForEMC(void); +void SetCurrentArtwork(int); +void ChangeCurrentArtworkIfNeeded(int); + void LoadLevelInfo(void); void LoadArtworkInfo(void); void LoadLevelArtworkInfo(void); diff --git a/src/libgame/system.h b/src/libgame/system.h index c1eb58d8..68a94cec 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -866,6 +866,20 @@ (artwork).snd_first : \ (artwork).mus_first) +#define ARTWORK_CURRENT_PTR(artwork, type) \ + ((type) == ARTWORK_TYPE_GRAPHICS ? \ + &(artwork).gfx_current : \ + (type) == ARTWORK_TYPE_SOUNDS ? \ + &(artwork).snd_current : \ + &(artwork).mus_current) + +#define ARTWORK_CURRENT(artwork, type) \ + ((type) == ARTWORK_TYPE_GRAPHICS ? \ + (artwork).gfx_current : \ + (type) == ARTWORK_TYPE_SOUNDS ? \ + (artwork).snd_current : \ + (artwork).mus_current) + #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type) \ ((type) == ARTWORK_TYPE_GRAPHICS ? \ &(artwork).gfx_current_identifier : \