diff --git a/src/system/atlas.c b/src/system/atlas.c index 6c2777e..2e91ae3 100644 --- a/src/system/atlas.c +++ b/src/system/atlas.c @@ -61,6 +61,59 @@ AtlasImage *getAtlasImage(char *filename) return NULL; } +char **getAtlasFileList(char *dir, int *count) +{ + AtlasImage *a; + int i, bucket; + char **filenames; + + i = 0; + filenames = NULL; + + for (bucket = 0 ; bucket < NUM_ATLAS_BUCKETS ; bucket++) + { + for (a = atlases[bucket].next ; a != NULL ; a = a->next) + { + if (strncmp(dir, a->filename, strlen(dir)) == 0) + { + i++; + } + } + } + + if (i > 0) + { + filenames = malloc(sizeof(char*) * i); + memset(filenames, 0, sizeof(char*) * i); + + i = 0; + + for (bucket = 0 ; bucket < NUM_ATLAS_BUCKETS ; bucket++) + { + for (a = atlases[bucket].next ; a != NULL ; a = a->next) + { + if (strncmp(dir, a->filename, strlen(dir)) == 0) + { + filenames[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH); + + STRNCPY(filenames[i], a->filename, MAX_FILENAME_LENGTH); + + i++; + } + } + } + } + + *count = i; + + if (filenames) + { + qsort(filenames, i, sizeof(char*), stringComparator); + } + + return filenames; +} + static void loadAtlasData(void) { AtlasImage *atlasImage, *a; diff --git a/src/system/atlas.h b/src/system/atlas.h index 42d63b7..0e23481 100644 --- a/src/system/atlas.h +++ b/src/system/atlas.h @@ -24,3 +24,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern SDL_Texture *getTexture(const char *filename); extern unsigned long hashcode(const char *str); extern char *readFile(const char *filename); +extern int stringComparator(const void *a, const void *b); diff --git a/src/system/init.h b/src/system/init.h index e796f1e..b754d25 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -66,7 +66,6 @@ extern void initStars(void); extern void initStats(void); extern void initTrophies(void); extern void initWidgets(void); -extern void updateCustomResolutionOption(void); extern void loadCapitalShipDefs(void); extern void loadFighterDefs(void); extern void loadItemDefs(void); @@ -75,6 +74,7 @@ extern void prepareScene(void); extern void presentScene(void); extern char *readFile(char *filename); extern void setLanguage(char *applicationName, char *languageCode); +extern void updateCustomResolutionOption(void); extern int writeFile(char *filename, char *data); extern App app; diff --git a/src/system/io.c b/src/system/io.c index f223c27..d1550c5 100644 --- a/src/system/io.c +++ b/src/system/io.c @@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "io.h" -static int stringComparator(const void *a, const void *b); - int fileExists(char *filename) { struct stat buffer; @@ -148,10 +146,3 @@ char **getFileList(char *dir, int *count) return filenames; } - -static int stringComparator(const void *a, const void *b) -{ - char **s1 = (char **)a; - char **s2 = (char **)b; - return strcmp(*s1, *s2); -} diff --git a/src/system/io.h b/src/system/io.h index 7ce80e4..34e9d67 100644 --- a/src/system/io.h +++ b/src/system/io.h @@ -23,4 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "sys/stat.h" #include "dirent.h" +extern int stringComparator(const void *a, const void *b); + extern App app; diff --git a/src/system/resources.c b/src/system/resources.c index b24f560..3b0b9f0 100644 --- a/src/system/resources.c +++ b/src/system/resources.c @@ -49,13 +49,13 @@ void initResources(void) free(filenames); - filenames = getFileList("gfx/planets", &numPlanets); + filenames = getAtlasFileList("gfx/planets", &numPlanets); planets = malloc(sizeof(char*) * numPlanets); for (i = 0 ; i < numPlanets ; i++) { planets[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH); - sprintf(planets[i], "gfx/planets/%s", filenames[i]); + strcpy(planets[i], filenames[i]); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]); diff --git a/src/system/resources.h b/src/system/resources.h index 3b4d776..8a29f47 100644 --- a/src/system/resources.h +++ b/src/system/resources.h @@ -20,4 +20,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" +extern char **getAtlasFileList(char *dir, int *count); extern char **getFileList(char *dir, int *count); diff --git a/src/system/util.c b/src/system/util.c index d07b9d6..e3d67f7 100644 --- a/src/system/util.c +++ b/src/system/util.c @@ -186,3 +186,10 @@ unsigned long hashcode(const char *str) return hash; } + +int stringComparator(const void *a, const void *b) +{ + char **s1 = (char **)a; + char **s2 = (char **)b; + return strcmp(*s1, *s2); +}