Search for planets in texture atlas when creating resource list.
This commit is contained in:
parent
984a551c80
commit
f015f83425
|
@ -61,6 +61,59 @@ AtlasImage *getAtlasImage(char *filename)
|
||||||
return NULL;
|
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)
|
static void loadAtlasData(void)
|
||||||
{
|
{
|
||||||
AtlasImage *atlasImage, *a;
|
AtlasImage *atlasImage, *a;
|
||||||
|
|
|
@ -24,3 +24,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
extern SDL_Texture *getTexture(const char *filename);
|
extern SDL_Texture *getTexture(const char *filename);
|
||||||
extern unsigned long hashcode(const char *str);
|
extern unsigned long hashcode(const char *str);
|
||||||
extern char *readFile(const char *filename);
|
extern char *readFile(const char *filename);
|
||||||
|
extern int stringComparator(const void *a, const void *b);
|
||||||
|
|
|
@ -66,7 +66,6 @@ extern void initStars(void);
|
||||||
extern void initStats(void);
|
extern void initStats(void);
|
||||||
extern void initTrophies(void);
|
extern void initTrophies(void);
|
||||||
extern void initWidgets(void);
|
extern void initWidgets(void);
|
||||||
extern void updateCustomResolutionOption(void);
|
|
||||||
extern void loadCapitalShipDefs(void);
|
extern void loadCapitalShipDefs(void);
|
||||||
extern void loadFighterDefs(void);
|
extern void loadFighterDefs(void);
|
||||||
extern void loadItemDefs(void);
|
extern void loadItemDefs(void);
|
||||||
|
@ -75,6 +74,7 @@ extern void prepareScene(void);
|
||||||
extern void presentScene(void);
|
extern void presentScene(void);
|
||||||
extern char *readFile(char *filename);
|
extern char *readFile(char *filename);
|
||||||
extern void setLanguage(char *applicationName, char *languageCode);
|
extern void setLanguage(char *applicationName, char *languageCode);
|
||||||
|
extern void updateCustomResolutionOption(void);
|
||||||
extern int writeFile(char *filename, char *data);
|
extern int writeFile(char *filename, char *data);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
|
|
@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
static int stringComparator(const void *a, const void *b);
|
|
||||||
|
|
||||||
int fileExists(char *filename)
|
int fileExists(char *filename)
|
||||||
{
|
{
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
|
@ -148,10 +146,3 @@ char **getFileList(char *dir, int *count)
|
||||||
|
|
||||||
return filenames;
|
return filenames;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stringComparator(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
char **s1 = (char **)a;
|
|
||||||
char **s2 = (char **)b;
|
|
||||||
return strcmp(*s1, *s2);
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,4 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
#include "dirent.h"
|
#include "dirent.h"
|
||||||
|
|
||||||
|
extern int stringComparator(const void *a, const void *b);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
|
|
@ -49,13 +49,13 @@ void initResources(void)
|
||||||
|
|
||||||
free(filenames);
|
free(filenames);
|
||||||
|
|
||||||
filenames = getFileList("gfx/planets", &numPlanets);
|
filenames = getAtlasFileList("gfx/planets", &numPlanets);
|
||||||
planets = malloc(sizeof(char*) * numPlanets);
|
planets = malloc(sizeof(char*) * numPlanets);
|
||||||
|
|
||||||
for (i = 0 ; i < numPlanets ; i++)
|
for (i = 0 ; i < numPlanets ; i++)
|
||||||
{
|
{
|
||||||
planets[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
|
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]);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
extern char **getAtlasFileList(char *dir, int *count);
|
||||||
extern char **getFileList(char *dir, int *count);
|
extern char **getFileList(char *dir, int *count);
|
||||||
|
|
|
@ -186,3 +186,10 @@ unsigned long hashcode(const char *str)
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stringComparator(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
char **s1 = (char **)a;
|
||||||
|
char **s2 = (char **)b;
|
||||||
|
return strcmp(*s1, *s2);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue