tbftss/src/system/resources.c

122 lines
2.8 KiB
C
Raw Normal View History

/*
Copyright (C) 2015-2019,2022 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
2022-07-31 11:43:20 +02:00
#include "../system/atlas.h"
#include "../system/io.h"
2022-07-31 11:43:20 +02:00
#include "resources.h"
char **backgrounds;
char **planets;
char **musicFiles;
2022-07-31 11:43:20 +02:00
int numBackgrounds;
int numPlanets;
int numMusicFiles;
void initResources(void)
{
char **filenames;
2022-07-31 11:43:20 +02:00
int i;
numBackgrounds = numPlanets = numMusicFiles = 0;
filenames = getFileList("gfx/backgrounds", &numBackgrounds);
2022-07-31 11:43:20 +02:00
backgrounds = malloc(sizeof(char *) * numBackgrounds);
2022-07-31 11:43:20 +02:00
for (i = 0; i < numBackgrounds; i++)
{
backgrounds[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
sprintf(backgrounds[i], "gfx/backgrounds/%s", filenames[i]);
2016-03-04 23:11:13 +01:00
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
2019-11-07 09:13:57 +01:00
free(filenames[i]);
}
free(filenames);
filenames = getAtlasFileList("gfx/planets", &numPlanets);
2022-07-31 11:43:20 +02:00
planets = malloc(sizeof(char *) * numPlanets);
2022-07-31 11:43:20 +02:00
for (i = 0; i < numPlanets; i++)
{
planets[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
strcpy(planets[i], filenames[i]);
2019-11-07 09:13:57 +01:00
2016-03-04 23:11:13 +01:00
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
2019-11-07 09:13:57 +01:00
free(filenames[i]);
}
free(filenames);
filenames = getFileList("music/battle/", &numMusicFiles);
2022-07-31 11:43:20 +02:00
musicFiles = malloc(sizeof(char *) * numMusicFiles);
2022-07-31 11:43:20 +02:00
for (i = 0; i < numMusicFiles; i++)
{
musicFiles[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
sprintf(musicFiles[i], "music/battle/%s", filenames[i]);
2019-11-07 09:13:57 +01:00
2016-03-04 23:11:13 +01:00
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
2019-11-07 09:13:57 +01:00
free(filenames[i]);
}
free(filenames);
}
2016-05-15 09:19:26 +02:00
char *getBackgroundTextureName(unsigned long i)
{
return backgrounds[i % numBackgrounds];
}
2016-05-15 09:19:26 +02:00
char *getPlanetTextureName(unsigned long i)
{
return planets[i % numPlanets];
}
2016-05-15 09:19:26 +02:00
char *getMusicFilename(unsigned long i)
{
return musicFiles[i % numMusicFiles];
}
void destroyResources(void)
{
2016-03-12 19:22:48 +01:00
int i;
2019-11-07 09:13:57 +01:00
2022-07-31 11:43:20 +02:00
for (i = 0; i < numBackgrounds; i++)
2016-03-12 19:22:48 +01:00
{
free(backgrounds[i]);
}
2019-11-07 09:13:57 +01:00
2022-07-31 11:43:20 +02:00
for (i = 0; i < numPlanets; i++)
2016-03-12 19:22:48 +01:00
{
free(planets[i]);
}
2019-11-07 09:13:57 +01:00
2022-07-31 11:43:20 +02:00
for (i = 0; i < numMusicFiles; i++)
2016-03-12 19:22:48 +01:00
{
free(musicFiles[i]);
}
}